]> err.no Git - sope/blob - sope-core/NGExtensions/NGExtensions/NGBundleManager.h
NGLogEventFormatter.h was marked as project, not public - fixed
[sope] / sope-core / NGExtensions / NGExtensions / NGBundleManager.h
1 /*
2   Copyright (C) 2000-2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #ifndef __NGExtensions_NGBundleManager_H__
23 #define __NGExtensions_NGBundleManager_H__
24
25 #import <Foundation/NSObject.h>
26 #import <Foundation/NSBundle.h>
27 #import <Foundation/NSMapTable.h>
28 #include <NGExtensions/NGExtensionsDecls.h>
29
30 @class NSString, NSArray, NSMutableArray, NSDictionary, NSMutableSet;
31 @class EOQualifier;
32
33 /*
34   NGBundleManager
35
36   NGBundleManager is a class similiar to a Java class loader. It searches
37   for dynamically loadable bundles in a specified path set.
38
39   The default bundle search path is:
40
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
44
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
48   and provided classes.
49   
50   Example bundle-info.plist:
51     {
52       bundleHandler = "MyBundleManager";
53       
54       provides = {
55         classes = ( { name = MyClass; } );
56       };
57       requires = {
58         bundleManagerVersion = 1;
59         bundles = ( { name = Foundation; type = framework; } );
60         classes = ( { name = NSObject; exact-version = 1; } );
61       };
62     }
63 */
64
65 NGExtensions_EXPORT NSString *NGBundleWasLoadedNotificationName;
66
67 @class NGBundleManager;
68
69 typedef BOOL (*NGBundleResourceSelector)(NSString        *_resourceName,
70                                          NSString        *_resourceType,
71                                          NSString        *_path,
72                                          NSDictionary    *_resourceConfig,
73                                          NGBundleManager *_bundleManager,
74                                          void            *_context);
75
76 @interface NGBundleManager : NSObject
77 {
78 @private
79   NSMutableArray *bundleSearchPaths;
80   NSMapTable     *pathToBundle;
81   NSMapTable     *pathToBundleInfo;
82   NSMapTable     *nameToBundle;
83
84   /* bundles loaded by the manager (NSBundle->BundleManager) */
85   NSMapTable     *loadedBundles;
86
87   /* the following are maintained using NSBundleDidLoadNotification .. */
88   NSMapTable     *classToBundle;
89   NSMapTable     *classNameToBundle;
90   NSMapTable     *categoryNameToBundle;
91
92   // transient
93   NSMutableSet *loadingBundles;
94 }
95
96 + (id)defaultBundleManager;
97
98 /* accessors */
99
100 - (void)setBundleSearchPaths:(NSArray *)_paths;
101 - (NSArray *)bundleSearchPaths;
102
103 /* bundle access */
104
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;
110
111 /* dependencies */
112
113 /* returns the names of the bundles required by the bundle */
114 - (NSArray *)bundlesRequiredByBundle:(NSBundle *)_bundle;
115
116 /* returns the names of the classes provided by the bundle */
117 - (NSArray *)classesProvidedByBundle:(NSBundle *)_bundle;
118
119 /* returns the names of the classes required by the bundle */
120 - (NSArray *)classesRequiredByBundle:(NSBundle *)_bundle;
121
122 /* loading */
123
124 - (id)loadBundle:(NSBundle *)_bundle;
125
126 /* bundle manager object */
127
128 - (id)principalObjectOfBundle:(NSBundle *)_bundle;
129
130 /* resources */
131
132 - (NSDictionary *)configForResource:(id)_resource ofType:(NSString *)_type
133   providedByBundle:(NSBundle *)_bundle;
134
135 - (NSBundle *)bundleProvidingResource:(id)_resourceName
136   ofType:(NSString *)_resourceType;
137
138 - (NSArray *)bundlesProvidingResource:(id)_resourceName
139   ofType:(NSString *)_resourceType;
140
141 - (NSBundle *)bundleProvidingResourceOfType:(NSString *)_resourceType
142   matchingQualifier:(EOQualifier *)_qual;
143 - (NSBundle *)bundlesProvidingResourcesOfType:(NSString *)_resourceType
144   matchingQualifier:(EOQualifier *)_qual;
145
146 /*
147   This returns an array of NSDictionaries describing the provided
148   resources.
149 */
150 - (NSArray *)providedResourcesOfType:(NSString *)_resourceType;
151
152 - (NSString *)pathForBundleProvidingResource:(id)_resourceName
153   ofType:(NSString *)_type
154   resourceSelector:(NGBundleResourceSelector)_selector
155   context:(void *)_context;
156
157 @end /* NGBundleManager */
158
159 @interface NSBundle(NGLanguageResourceExtensions)
160
161 - (NSString *)pathForResource:(NSString *)_name ofType:(NSString *)_ext
162   inDirectory:(NSString *)_directory
163   languages:(NSArray *)_languages;
164
165 - (NSString *)pathForResource:(NSString *)_name ofType:(NSString *)_ext
166   languages:(NSArray *)_languages;
167
168 @end /* NSBundle(NGLanguageResourceExtensions) */
169
170 @interface NSBundle(NGBundleManagerExtensions)
171
172 /* Returns the object managing the bundle (might be the principal class) */
173 - (id)principalObject;
174
175 - (NSArray *)providedResourcesOfType:(NSString *)_resourceType;
176
177 /* Returns the name of the bundle */
178 - (NSString *)bundleName;
179
180 /* Returns the type of the bundle */
181 - (NSString *)bundleType;
182
183 /* Returns the names of the classes provided by the bundle */
184 - (NSArray *)providedClasses;
185
186 /* Returns the names of the classes required by the bundle */
187 - (NSArray *)requiredClasses;
188
189 /* Returns the names of other bundles required for loading this bundle */
190 - (NSArray *)requiredBundles;
191
192 /* Return a NSDictionary with bundle-info configuration of the specified rsrc */
193 - (NSDictionary *)configForResource:(id)_resource ofType:(NSString *)_type;
194
195 @end /* NSBundle(NGBundleManagerExtensions) */
196
197 @interface NSObject(BundleManager)
198
199 - (id)initForBundle:(NSBundle *)_bundle bundleManager:(NGBundleManager *)_mng;
200
201 /*
202   This method is invoked if the bundle was successfully loaded.
203 */
204 - (void)bundleManager:(NGBundleManager *)_manager
205   didLoadBundle:(NSBundle *)_bundle;
206
207 @end /* NSObject(BundleManager) */
208
209 @interface NGBundle : NSBundle
210 @end
211
212 #endif