KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > parse > ModuleDescriptor


1 // Copyright 2004, 2005 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.parse;
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.List JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.hivemind.ClassResolver;
27 import org.apache.hivemind.ErrorHandler;
28 import org.apache.hivemind.schema.Schema;
29 import org.apache.hivemind.schema.impl.SchemaImpl;
30 import org.apache.hivemind.util.ToStringBuilder;
31
32 /**
33  * Representation of a HiveMind module descriptor, as parsed by
34  * {@link org.apache.hivemind.parse.DescriptorParser}. Corresponds to the root <module>
35  * element.
36  *
37  * @author Howard Lewis Ship
38  */

39 public final class ModuleDescriptor extends BaseAnnotationHolder
40 {
41     /** @since 1.1 */
42     private static final Log LOG = LogFactory.getLog(ModuleDescriptor.class);
43
44     private String JavaDoc _moduleId;
45
46     private String JavaDoc _version;
47
48     /** @since 1.1 */
49
50     private String JavaDoc _packageName;
51
52     private List JavaDoc _servicePoints;
53
54     private List JavaDoc _implementations;
55
56     private List JavaDoc _configurationPoints;
57
58     private List JavaDoc _contributions;
59
60     private List JavaDoc _subModules;
61
62     private List JavaDoc _dependencies;
63
64     /** @since 1.1 */
65     private Map JavaDoc _schemas;
66
67     private List JavaDoc _schemaAssignments;
68
69     private ClassResolver _resolver;
70
71     /** @since 1.1 */
72     private ErrorHandler _errorHandler;
73
74     public ModuleDescriptor(ClassResolver resolver, ErrorHandler errorHandler)
75     {
76         _resolver = resolver;
77         _errorHandler = errorHandler;
78     }
79
80     public String JavaDoc toString()
81     {
82         ToStringBuilder builder = new ToStringBuilder(this);
83
84         builder.append("moduleId", _moduleId);
85         builder.append("version", _version);
86
87         return builder.toString();
88     }
89
90     public void addServicePoint(ServicePointDescriptor service)
91     {
92         if (_servicePoints == null)
93             _servicePoints = new ArrayList JavaDoc();
94
95         _servicePoints.add(service);
96     }
97
98     public List JavaDoc getServicePoints()
99     {
100         return _servicePoints;
101     }
102
103     public void addImplementation(ImplementationDescriptor descriptor)
104     {
105         if (_implementations == null)
106             _implementations = new ArrayList JavaDoc();
107
108         _implementations.add(descriptor);
109     }
110
111     public List JavaDoc getImplementations()
112     {
113         return _implementations;
114     }
115
116     public void addConfigurationPoint(ConfigurationPointDescriptor descriptor)
117     {
118         if (_configurationPoints == null)
119             _configurationPoints = new ArrayList JavaDoc();
120
121         _configurationPoints.add(descriptor);
122     }
123
124     public List JavaDoc getConfigurationPoints()
125     {
126         return _configurationPoints;
127     }
128
129     public void addContribution(ContributionDescriptor descriptor)
130     {
131         if (_contributions == null)
132             _contributions = new ArrayList JavaDoc();
133
134         _contributions.add(descriptor);
135     }
136
137     public List JavaDoc getContributions()
138     {
139         return _contributions;
140     }
141
142     public void addSubModule(SubModuleDescriptor subModule)
143     {
144         if (_subModules == null)
145             _subModules = new ArrayList JavaDoc();
146
147         _subModules.add(subModule);
148     }
149
150     public List JavaDoc getSubModules()
151     {
152         return _subModules;
153     }
154
155     public void addDependency(DependencyDescriptor dependency)
156     {
157         if (_dependencies == null)
158             _dependencies = new ArrayList JavaDoc();
159
160         _dependencies.add(dependency);
161     }
162
163     public List JavaDoc getDependencies()
164     {
165         return _dependencies;
166     }
167
168     /**
169      * Adds a schema to this module descriptor. If a schema with the same id already has been added,
170      * an error is reported and the given schema is ignored.
171      *
172      * @since 1.1
173      */

174     public void addSchema(SchemaImpl schema)
175     {
176         if (_schemas == null)
177             _schemas = new HashMap JavaDoc();
178
179         String JavaDoc schemaId = schema.getId();
180
181         Schema existing = getSchema(schemaId);
182
183         if (existing != null)
184         {
185             _errorHandler.error(LOG, ParseMessages.duplicateSchema(
186                     _moduleId + '.' + schemaId,
187                     existing), schema.getLocation(), null);
188             return;
189         }
190
191         _schemas.put(schemaId, schema);
192     }
193
194     /** @since 1.1 */
195     public Schema getSchema(String JavaDoc id)
196     {
197         return _schemas == null ? null : (Schema) _schemas.get(id);
198     }
199
200     /**
201      * Returns a Collection of {@link org.apache.hivemind.schema.impl.SchemaImpl}.
202      *
203      * @since 1.1
204      */

205     public Collection JavaDoc getSchemas()
206     {
207         return _schemas != null ? _schemas.values() : Collections.EMPTY_LIST;
208     }
209
210     public String JavaDoc getModuleId()
211     {
212         return _moduleId;
213     }
214
215     public String JavaDoc getVersion()
216     {
217         return _version;
218     }
219
220     public void setModuleId(String JavaDoc string)
221     {
222         _moduleId = string;
223     }
224
225     public void setVersion(String JavaDoc string)
226     {
227         _version = string;
228     }
229
230     public ClassResolver getClassResolver()
231     {
232         return _resolver;
233     }
234
235     /**
236      * Returns the name of the package to search for class names within. By default, the package
237      * name will match the module id, but this can be overridden in the module descriptor.
238      *
239      * @since 1.1
240      */

241
242     public String JavaDoc getPackageName()
243     {
244         return _packageName;
245     }
246
247     /** @since 1.1 */
248
249     public void setPackageName(String JavaDoc packageName)
250     {
251         _packageName = packageName;
252     }
253
254     public void addSchemaAssignment(SchemaAssignmentDescriptor sad)
255     {
256         if (_schemaAssignments == null)
257             _schemaAssignments = new ArrayList JavaDoc();
258
259         _schemaAssignments.add(sad);
260     }
261
262     public List JavaDoc getSchemaAssignment()
263     {
264         return _schemaAssignments;
265     }
266
267 }
Popular Tags