KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > definition > impl > ModuleDefinitionImpl


1 // Copyright 2007 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.hivemind.definition.impl;
16
17 import java.util.ArrayList JavaDoc;
18 import java.util.Collection JavaDoc;
19 import java.util.Collections JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import org.apache.hivemind.ApplicationRuntimeException;
24 import org.apache.hivemind.ClassResolver;
25 import org.apache.hivemind.Location;
26 import org.apache.hivemind.definition.ConfigurationParserDefinition;
27 import org.apache.hivemind.definition.ConfigurationPointDefinition;
28 import org.apache.hivemind.definition.ContributionDefinition;
29 import org.apache.hivemind.definition.DefinitionMessages;
30 import org.apache.hivemind.definition.ExtensionDefinition;
31 import org.apache.hivemind.definition.ModuleDefinition;
32 import org.apache.hivemind.definition.ImplementationDefinition;
33 import org.apache.hivemind.definition.InterceptorDefinition;
34 import org.apache.hivemind.definition.ServicePointDefinition;
35 import org.apache.hivemind.definition.UnresolvedExtension;
36
37 /**
38  * Default implementation of {@link ExtensionDefinition}.
39  *
40  * @author Achim Huegen
41  */

42 public class ModuleDefinitionImpl implements ModuleDefinition
43 {
44     private String JavaDoc _id;
45
46     private Location _location;
47
48     private String JavaDoc _packageName;
49
50     private ClassResolver _classResolver;
51     
52     private Map JavaDoc _servicePoints = new HashMap JavaDoc();
53     
54     private Map JavaDoc _configurationPoints = new HashMap JavaDoc();
55     
56     private Collection JavaDoc _dependencies = new ArrayList JavaDoc();
57
58     private Collection JavaDoc _unresolvedImplementations = new ArrayList JavaDoc();
59
60     private Collection JavaDoc _unresolvedContributions = new ArrayList JavaDoc();
61
62     private Collection JavaDoc _unresolvedInterceptors = new ArrayList JavaDoc();
63     
64     private Collection JavaDoc _unresolvedConfigurationParsers = new ArrayList JavaDoc();
65     
66     public ModuleDefinitionImpl()
67     {
68     }
69
70     /**
71      * @param id the id of the module
72      * @param location the location of the module
73      * @param resolver the {@link ClassResolver} used to resolve all classes referenced from
74      * elements inside this module.
75      * @param packageName name of the package to search for class names within. If null, it defaults to the id
76      */

77     public ModuleDefinitionImpl(String JavaDoc id, Location location, ClassResolver resolver, String JavaDoc packageName)
78     {
79         _id = id;
80         _location = location;
81         _classResolver = resolver;
82         if (packageName != null)
83             _packageName = packageName;
84         else _packageName = id;
85     }
86
87     /**
88      * @see org.apache.hivemind.definition.ModuleDefinition#getClassResolver()
89      */

90     public ClassResolver getClassResolver()
91     {
92         return _classResolver;
93     }
94
95     /**
96      * Sets the {@link ClassResolver} used to resolve all classes referenced from elements
97      * inside the module.
98      */

99     public void setClassResolver(ClassResolver classResolver)
100     {
101         _classResolver = classResolver;
102     }
103
104     /**
105      * @see org.apache.hivemind.definition.ModuleDefinition#getLocation()
106      */

107     public Location getLocation()
108     {
109         return _location;
110     }
111
112     /**
113      * Sets the location of the module.
114      */

115     public void setLocation(Location location)
116     {
117         _location = location;
118     }
119
120     /**
121      * @see org.apache.hivemind.definition.ModuleDefinition#getId()
122      */

123     public String JavaDoc getId()
124     {
125         return _id;
126     }
127
128     /**
129      * Sets the id of the module.
130      */

131     public void setId(String JavaDoc moduleId)
132     {
133         this._id = moduleId;
134     }
135
136     /**
137      * @see org.apache.hivemind.definition.ModuleDefinition#getPackageName()
138      */

139     public String JavaDoc getPackageName()
140     {
141         return _packageName;
142     }
143
144     /**
145      * Sets the package name of the module.
146      */

147     public void setPackageName(String JavaDoc packageName)
148     {
149         _packageName = packageName;
150     }
151     
152     /**
153      * Adds a service point definition to the module.
154      * @param servicePoint the service point
155      * @throws ApplicationRuntimeException if another service point with the same id has already been defined
156      */

157     public void addServicePoint(ServicePointDefinition servicePoint)
158     {
159         if (_servicePoints.containsKey(servicePoint.getId())) {
160             throw new ApplicationRuntimeException(DefinitionMessages.duplicateServicePointId(servicePoint.getQualifiedId(),
161                     this));
162         }
163         _servicePoints.put(servicePoint.getId(), servicePoint);
164     }
165
166     /**
167      * @see org.apache.hivemind.definition.ModuleDefinition#getServicePoint(java.lang.String)
168      */

169     public ServicePointDefinition getServicePoint(String JavaDoc id)
170     {
171         return (ServicePointDefinition) _servicePoints.get(id);
172     }
173     
174     /**
175      * @see org.apache.hivemind.definition.ModuleDefinition#getServicePoints()
176      */

177     public Collection JavaDoc getServicePoints()
178     {
179         return Collections.unmodifiableCollection(_servicePoints.values());
180     }
181  
182     /**
183      * Adds a configuration point definition to the module.
184      * @param configurationPoint the configuration point
185      * @throws ApplicationRuntimeException if another configuration point with the same id has already been defined
186      */

187     public void addConfigurationPoint(ConfigurationPointDefinition configurationPoint)
188     {
189         if (_configurationPoints.containsKey(configurationPoint.getId())) {
190             throw new ApplicationRuntimeException(DefinitionMessages.duplicateConfigurationPointId(configurationPoint.getId(),
191                     this));
192         }
193         _configurationPoints.put(configurationPoint.getId(), configurationPoint);
194     }
195
196     /**
197      * @see org.apache.hivemind.definition.ModuleDefinition#getConfigurationPoint(java.lang.String)
198      */

199     public ConfigurationPointDefinition getConfigurationPoint(String JavaDoc id)
200     {
201         return (ConfigurationPointDefinition) _configurationPoints.get(id);
202     }
203     
204     /**
205      * @see org.apache.hivemind.definition.ModuleDefinition#getConfigurationPoints()
206      */

207     public Collection JavaDoc getConfigurationPoints()
208     {
209         return Collections.unmodifiableCollection(_configurationPoints.values());
210     }
211
212     /**
213      * @see org.apache.hivemind.definition.ModuleDefinition#getDependencies()
214      */

215     public Collection JavaDoc getDependencies()
216     {
217         return Collections.unmodifiableCollection(_dependencies);
218     }
219     
220     /**
221      * Defines a dependency on another module. The presence of that module
222      * is checked during registry construction.
223      *
224      * @param dependsOnModuleId the id of the module this module depends on
225      */

226     public void addDependency(String JavaDoc dependsOnModuleId)
227     {
228         _dependencies.add(dependsOnModuleId);
229     }
230    
231     /**
232      * Adds a implementation for a service point which can be defined in this
233      * module or another module.
234      *
235      * @param qualifiedServicePointId the fully qualified service point id
236      * @param implementation the implementation definition
237      */

238     public void addImplementation(String JavaDoc qualifiedServicePointId,
239             ImplementationDefinition implementation)
240     {
241         UnresolvedExtension unresolvedExtension = new UnresolvedExtension(implementation,
242                 qualifiedServicePointId);
243         _unresolvedImplementations.add(unresolvedExtension);
244     }
245
246     /**
247      * Adds a interceptor for a service point which can be defined in this
248      * module or another module.
249      *
250      * @param qualifiedServicePointId the fully qualified service point id
251      * @param interceptor the interceptor definition
252      */

253     public void addInterceptor(String JavaDoc qualifiedServicePointId,
254             InterceptorDefinition interceptor)
255     {
256         UnresolvedExtension unresolvedExtension = new UnresolvedExtension(interceptor,
257                 qualifiedServicePointId);
258         _unresolvedInterceptors.add(unresolvedExtension);
259     }
260
261     /**
262      * Adds a contribution for a configuration point which can be defined in this
263      * module or another module.
264      *
265      * @param qualifiedConfigurationPointId the fully qualified configuration point id
266      * @param contribution the contribution definition
267      */

268     public void addContribution(String JavaDoc qualifiedConfigurationPointId,
269             ContributionDefinition contribution)
270     {
271         UnresolvedExtension unresolvedExtension = new UnresolvedExtension(contribution,
272                 qualifiedConfigurationPointId);
273         _unresolvedContributions.add(unresolvedExtension);
274     }
275     
276     /**
277      * Adds a configuration parser for a configuration point which can be defined in this
278      * module or another module.
279      *
280      * @param qualifiedConfigurationPointId the fully qualified configuration point id
281      * @param parser the parser definition
282      */

283     public void addConfigurationParser(String JavaDoc qualifiedConfigurationPointId, ConfigurationParserDefinition parser)
284     {
285         UnresolvedExtension unresolvedExtension = new UnresolvedExtension(parser,
286                 qualifiedConfigurationPointId);
287         _unresolvedConfigurationParsers.add(unresolvedExtension);
288     }
289     
290     /**
291      * @see org.apache.hivemind.definition.ModuleDefinition#getContributions()
292      */

293     public Collection JavaDoc getContributions()
294     {
295         return _unresolvedContributions;
296     }
297
298     /**
299      * @see org.apache.hivemind.definition.ModuleDefinition#getImplementations()
300      */

301     public Collection JavaDoc getImplementations()
302     {
303         return _unresolvedImplementations;
304     }
305
306     /**
307      * @see org.apache.hivemind.definition.ModuleDefinition#getInterceptors()
308      */

309     public Collection JavaDoc getInterceptors()
310     {
311         return _unresolvedInterceptors;
312     }
313
314     /**
315      * @see org.apache.hivemind.definition.ModuleDefinition#getConfigurationParsers()
316      */

317     public Collection JavaDoc getConfigurationParsers()
318     {
319         return _unresolvedConfigurationParsers;
320     }
321
322   
323 }
324
Popular Tags