2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #ifndef __NGExtensions_NGBundleManager_H__
23 #define __NGExtensions_NGBundleManager_H__
25 #import <Foundation/NSObject.h>
26 #import <Foundation/NSBundle.h>
27 #import <Foundation/NSMapTable.h>
28 #include <NGExtensions/NGExtensionsDecls.h>
30 @class NSString, NSArray, NSMutableArray, NSDictionary, NSMutableSet;
36 NGBundleManager is a class similiar to a Java class loader. It searches
37 for dynamically loadable bundles in a specified path set.
39 The default bundle search path is:
41 1. bundles contained in the main-bundle
42 2. pathes specified by the 'NGBundlePath' user default
43 3. pathes specified by the 'NGBundlePath' environment variable
45 Bundles managed by NGBundleManager can specify load-requirements, this
46 is done via the 'bundle-info.plist' file contained at the root of the
47 bundle directory. The file is a property list file and can specify required
50 Example bundle-info.plist:
52 bundleHandler = "MyBundleManager";
55 classes = ( { name = MyClass; } );
58 bundleManagerVersion = 1;
59 bundles = ( { name = Foundation; type = framework; } );
60 classes = ( { name = NSObject; exact-version = 1; } );
65 NGExtensions_EXPORT NSString *NGBundleWasLoadedNotificationName;
67 @class NGBundleManager;
69 typedef BOOL (*NGBundleResourceSelector)(NSString *_resourceName,
70 NSString *_resourceType,
72 NSDictionary *_resourceConfig,
73 NGBundleManager *_bundleManager,
76 @interface NGBundleManager : NSObject
79 NSMutableArray *bundleSearchPaths;
80 NSMapTable *pathToBundle;
81 NSMapTable *pathToBundleInfo;
82 NSMapTable *nameToBundle;
84 /* bundles loaded by the manager (NSBundle->BundleManager) */
85 NSMapTable *loadedBundles;
87 /* the following are maintained using NSBundleDidLoadNotification .. */
88 NSMapTable *classToBundle;
89 NSMapTable *classNameToBundle;
90 NSMapTable *categoryNameToBundle;
93 NSMutableSet *loadingBundles;
96 + (id)defaultBundleManager;
100 - (void)setBundleSearchPaths:(NSArray *)_paths;
101 - (NSArray *)bundleSearchPaths;
105 - (NSBundle *)bundleWithName:(NSString *)name type:(NSString *)_type;
106 - (NSBundle *)bundleWithName:(NSString *)name; // type=='bundle'
107 - (NSBundle *)bundleForClassNamed:(NSString *)aClassName;
108 - (NSBundle *)bundleForClass:(Class)aClass;
109 - (NSBundle *)bundleWithPath:(NSString *)path;
113 /* returns the names of the bundles required by the bundle */
114 - (NSArray *)bundlesRequiredByBundle:(NSBundle *)_bundle;
116 /* returns the names of the classes provided by the bundle */
117 - (NSArray *)classesProvidedByBundle:(NSBundle *)_bundle;
119 /* returns the names of the classes required by the bundle */
120 - (NSArray *)classesRequiredByBundle:(NSBundle *)_bundle;
124 - (id)loadBundle:(NSBundle *)_bundle;
126 /* bundle manager object */
128 - (id)principalObjectOfBundle:(NSBundle *)_bundle;
132 - (NSDictionary *)configForResource:(id)_resource ofType:(NSString *)_type
133 providedByBundle:(NSBundle *)_bundle;
135 - (NSBundle *)bundleProvidingResource:(id)_resourceName
136 ofType:(NSString *)_resourceType;
138 - (NSArray *)bundlesProvidingResource:(id)_resourceName
139 ofType:(NSString *)_resourceType;
141 - (NSBundle *)bundleProvidingResourceOfType:(NSString *)_resourceType
142 matchingQualifier:(EOQualifier *)_qual;
143 - (NSBundle *)bundlesProvidingResourcesOfType:(NSString *)_resourceType
144 matchingQualifier:(EOQualifier *)_qual;
147 This returns an array of NSDictionaries describing the provided
150 - (NSArray *)providedResourcesOfType:(NSString *)_resourceType;
152 - (NSString *)pathForBundleProvidingResource:(id)_resourceName
153 ofType:(NSString *)_type
154 resourceSelector:(NGBundleResourceSelector)_selector
155 context:(void *)_context;
157 @end /* NGBundleManager */
159 @interface NSBundle(NGLanguageResourceExtensions)
161 - (NSString *)pathForResource:(NSString *)_name ofType:(NSString *)_ext
162 inDirectory:(NSString *)_directory
163 languages:(NSArray *)_languages;
165 - (NSString *)pathForResource:(NSString *)_name ofType:(NSString *)_ext
166 languages:(NSArray *)_languages;
168 @end /* NSBundle(NGLanguageResourceExtensions) */
170 @interface NSBundle(NGBundleManagerExtensions)
172 /* Returns the object managing the bundle (might be the principal class) */
173 - (id)principalObject;
175 - (NSArray *)providedResourcesOfType:(NSString *)_resourceType;
177 /* Returns the name of the bundle */
178 - (NSString *)bundleName;
180 /* Returns the type of the bundle */
181 - (NSString *)bundleType;
183 /* Returns the names of the classes provided by the bundle */
184 - (NSArray *)providedClasses;
186 /* Returns the names of the classes required by the bundle */
187 - (NSArray *)requiredClasses;
189 /* Returns the names of other bundles required for loading this bundle */
190 - (NSArray *)requiredBundles;
192 /* Return a NSDictionary with bundle-info configuration of the specified rsrc */
193 - (NSDictionary *)configForResource:(id)_resource ofType:(NSString *)_type;
195 @end /* NSBundle(NGBundleManagerExtensions) */
197 @interface NSObject(BundleManager)
199 - (id)initForBundle:(NSBundle *)_bundle bundleManager:(NGBundleManager *)_mng;
202 This method is invoked if the bundle was successfully loaded.
204 - (void)bundleManager:(NGBundleManager *)_manager
205 didLoadBundle:(NSBundle *)_bundle;
207 @end /* NSObject(BundleManager) */
209 @interface NGBundle : NSBundle