|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ModuleDescriptor.java | 80% | 100% | 100% | 95.6% |
|
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;
|
|
18 |
import java.util.Collection;
|
|
19 |
import java.util.Collections;
|
|
20 |
import java.util.HashMap;
|
|
21 |
import java.util.List;
|
|
22 |
import java.util.Map;
|
|
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 _moduleId;
|
|
45 |
|
|
46 |
private String _version;
|
|
47 |
|
|
48 |
/** @since 1.1 */
|
|
49 |
|
|
50 |
private String _packageName;
|
|
51 |
|
|
52 |
private List _servicePoints;
|
|
53 |
|
|
54 |
private List _implementations;
|
|
55 |
|
|
56 |
private List _configurationPoints;
|
|
57 |
|
|
58 |
private List _contributions;
|
|
59 |
|
|
60 |
private List _subModules;
|
|
61 |
|
|
62 |
private List _dependencies;
|
|
63 |
|
|
64 |
/** @since 1.1 */
|
|
65 |
private Map _schemas;
|
|
66 |
|
|
67 |
private ClassResolver _resolver;
|
|
68 |
|
|
69 |
/** @since 1.1 */
|
|
70 |
private ErrorHandler _errorHandler;
|
|
71 |
|
|
72 | 271 |
public ModuleDescriptor(ClassResolver resolver, ErrorHandler errorHandler)
|
73 |
{ |
|
74 | 271 |
_resolver = resolver; |
75 | 271 |
_errorHandler = errorHandler; |
76 |
} |
|
77 |
|
|
78 | 28 |
public String toString()
|
79 |
{ |
|
80 | 28 |
ToStringBuilder builder = new ToStringBuilder(this); |
81 |
|
|
82 | 28 |
builder.append("moduleId", _moduleId);
|
83 | 28 |
builder.append("version", _version);
|
84 |
|
|
85 | 28 |
return builder.toString();
|
86 |
} |
|
87 |
|
|
88 | 2257 |
public void addServicePoint(ServicePointDescriptor service) |
89 |
{ |
|
90 | 2257 |
if (_servicePoints == null) |
91 | 192 |
_servicePoints = new ArrayList();
|
92 |
|
|
93 | 2257 |
_servicePoints.add(service); |
94 |
} |
|
95 |
|
|
96 | 242 |
public List getServicePoints()
|
97 |
{ |
|
98 | 242 |
return _servicePoints;
|
99 |
} |
|
100 |
|
|
101 | 16 |
public void addImplementation(ImplementationDescriptor descriptor) |
102 |
{ |
|
103 | 16 |
if (_implementations == null) |
104 | 16 |
_implementations = new ArrayList();
|
105 |
|
|
106 | 16 |
_implementations.add(descriptor); |
107 |
} |
|
108 |
|
|
109 | 239 |
public List getImplementations()
|
110 |
{ |
|
111 | 239 |
return _implementations;
|
112 |
} |
|
113 |
|
|
114 | 972 |
public void addConfigurationPoint(ConfigurationPointDescriptor descriptor) |
115 |
{ |
|
116 | 972 |
if (_configurationPoints == null) |
117 | 185 |
_configurationPoints = new ArrayList();
|
118 |
|
|
119 | 972 |
_configurationPoints.add(descriptor); |
120 |
} |
|
121 |
|
|
122 | 245 |
public List getConfigurationPoints()
|
123 |
{ |
|
124 | 245 |
return _configurationPoints;
|
125 |
} |
|
126 |
|
|
127 | 641 |
public void addContribution(ContributionDescriptor descriptor) |
128 |
{ |
|
129 | 641 |
if (_contributions == null) |
130 | 179 |
_contributions = new ArrayList();
|
131 |
|
|
132 | 641 |
_contributions.add(descriptor); |
133 |
} |
|
134 |
|
|
135 | 240 |
public List getContributions()
|
136 |
{ |
|
137 | 240 |
return _contributions;
|
138 |
} |
|
139 |
|
|
140 | 3 |
public void addSubModule(SubModuleDescriptor subModule) |
141 |
{ |
|
142 | 3 |
if (_subModules == null) |
143 | 3 |
_subModules = new ArrayList();
|
144 |
|
|
145 | 3 |
_subModules.add(subModule); |
146 |
} |
|
147 |
|
|
148 | 226 |
public List getSubModules()
|
149 |
{ |
|
150 | 226 |
return _subModules;
|
151 |
} |
|
152 |
|
|
153 | 13 |
public void addDependency(DependencyDescriptor dependency) |
154 |
{ |
|
155 | 13 |
if (_dependencies == null) |
156 | 13 |
_dependencies = new ArrayList();
|
157 |
|
|
158 | 13 |
_dependencies.add(dependency); |
159 |
} |
|
160 |
|
|
161 | 240 |
public List getDependencies()
|
162 |
{ |
|
163 | 240 |
return _dependencies;
|
164 |
} |
|
165 |
|
|
166 |
/**
|
|
167 |
* Adds a schema to this module descriptor. If a schema with the same id already has been added,
|
|
168 |
* an error is reported and the given schema is ignored.
|
|
169 |
*
|
|
170 |
* @since 1.1
|
|
171 |
*/
|
|
172 | 306 |
public void addSchema(SchemaImpl schema) |
173 |
{ |
|
174 | 306 |
if (_schemas == null) |
175 | 174 |
_schemas = new HashMap();
|
176 |
|
|
177 | 306 |
String schemaId = schema.getId(); |
178 |
|
|
179 | 306 |
Schema existing = getSchema(schemaId); |
180 |
|
|
181 | 306 |
if (existing != null) |
182 |
{ |
|
183 | 1 |
_errorHandler.error(LOG, ParseMessages.duplicateSchema( |
184 |
_moduleId + '.' + schemaId, |
|
185 |
existing), schema.getLocation(), null);
|
|
186 | 1 |
return;
|
187 |
} |
|
188 |
|
|
189 | 305 |
_schemas.put(schemaId, schema); |
190 |
} |
|
191 |
|
|
192 |
/** @since 1.1 */
|
|
193 | 311 |
public Schema getSchema(String id)
|
194 |
{ |
|
195 | 311 |
return _schemas == null ? null : (Schema) _schemas.get(id); |
196 |
} |
|
197 |
|
|
198 |
/**
|
|
199 |
* Returns a Collection of {@link org.apache.hivemind.schema.impl.SchemaImpl}.
|
|
200 |
*
|
|
201 |
* @since 1.1
|
|
202 |
*/
|
|
203 | 236 |
public Collection getSchemas()
|
204 |
{ |
|
205 | 236 |
return _schemas != null ? _schemas.values() : Collections.EMPTY_LIST; |
206 |
} |
|
207 |
|
|
208 | 1684 |
public String getModuleId()
|
209 |
{ |
|
210 | 1684 |
return _moduleId;
|
211 |
} |
|
212 |
|
|
213 | 9 |
public String getVersion()
|
214 |
{ |
|
215 | 9 |
return _version;
|
216 |
} |
|
217 |
|
|
218 | 270 |
public void setModuleId(String string) |
219 |
{ |
|
220 | 270 |
_moduleId = string; |
221 |
} |
|
222 |
|
|
223 | 261 |
public void setVersion(String string) |
224 |
{ |
|
225 | 261 |
_version = string; |
226 |
} |
|
227 |
|
|
228 | 229 |
public ClassResolver getClassResolver()
|
229 |
{ |
|
230 | 229 |
return _resolver;
|
231 |
} |
|
232 |
|
|
233 |
/**
|
|
234 |
* Returns the name of the package to search for class names within. By default, the package
|
|
235 |
* name will match the module id, but this can be overridden in the module descriptor.
|
|
236 |
*
|
|
237 |
* @since 1.1
|
|
238 |
*/
|
|
239 |
|
|
240 | 2493 |
public String getPackageName()
|
241 |
{ |
|
242 | 2493 |
return _packageName;
|
243 |
} |
|
244 |
|
|
245 |
/** @since 1.1 */
|
|
246 |
|
|
247 | 253 |
public void setPackageName(String packageName) |
248 |
{ |
|
249 | 253 |
_packageName = packageName; |
250 |
} |
|
251 |
} |
|