001: // Copyright 2004, 2005 The Apache Software Foundation
002: //
003: // Licensed under the Apache License, Version 2.0 (the "License");
004: // you may not use this file except in compliance with the License.
005: // You may obtain a copy of the License at
006: //
007: // http://www.apache.org/licenses/LICENSE-2.0
008: //
009: // Unless required by applicable law or agreed to in writing, software
010: // distributed under the License is distributed on an "AS IS" BASIS,
011: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: // See the License for the specific language governing permissions and
013: // limitations under the License.
014:
015: package org.apache.hivemind.parse;
016:
017: import java.util.ArrayList;
018: import java.util.Collection;
019: import java.util.Collections;
020: import java.util.HashMap;
021: import java.util.List;
022: import java.util.Map;
023:
024: import org.apache.commons.logging.Log;
025: import org.apache.commons.logging.LogFactory;
026: import org.apache.hivemind.ClassResolver;
027: import org.apache.hivemind.ErrorHandler;
028: import org.apache.hivemind.schema.Schema;
029: import org.apache.hivemind.schema.impl.SchemaImpl;
030: import org.apache.hivemind.util.ToStringBuilder;
031:
032: /**
033: * Representation of a HiveMind module descriptor, as parsed by
034: * {@link org.apache.hivemind.parse.DescriptorParser}. Corresponds to the root <module>
035: * element.
036: *
037: * @author Howard Lewis Ship
038: */
039: public final class ModuleDescriptor extends BaseAnnotationHolder {
040: /** @since 1.1 */
041: private static final Log LOG = LogFactory
042: .getLog(ModuleDescriptor.class);
043:
044: private String _moduleId;
045:
046: private String _version;
047:
048: /** @since 1.1 */
049:
050: private String _packageName;
051:
052: private List _servicePoints;
053:
054: private List _implementations;
055:
056: private List _configurationPoints;
057:
058: private List _contributions;
059:
060: private List _subModules;
061:
062: private List _dependencies;
063:
064: /** @since 1.1 */
065: private Map _schemas;
066:
067: private ClassResolver _resolver;
068:
069: /** @since 1.1 */
070: private ErrorHandler _errorHandler;
071:
072: public ModuleDescriptor(ClassResolver resolver,
073: ErrorHandler errorHandler) {
074: _resolver = resolver;
075: _errorHandler = errorHandler;
076: }
077:
078: public String toString() {
079: ToStringBuilder builder = new ToStringBuilder(this );
080:
081: builder.append("moduleId", _moduleId);
082: builder.append("version", _version);
083:
084: return builder.toString();
085: }
086:
087: public void addServicePoint(ServicePointDescriptor service) {
088: if (_servicePoints == null)
089: _servicePoints = new ArrayList();
090:
091: _servicePoints.add(service);
092: }
093:
094: public List getServicePoints() {
095: return _servicePoints;
096: }
097:
098: public void addImplementation(ImplementationDescriptor descriptor) {
099: if (_implementations == null)
100: _implementations = new ArrayList();
101:
102: _implementations.add(descriptor);
103: }
104:
105: public List getImplementations() {
106: return _implementations;
107: }
108:
109: public void addConfigurationPoint(
110: ConfigurationPointDescriptor descriptor) {
111: if (_configurationPoints == null)
112: _configurationPoints = new ArrayList();
113:
114: _configurationPoints.add(descriptor);
115: }
116:
117: public List getConfigurationPoints() {
118: return _configurationPoints;
119: }
120:
121: public void addContribution(ContributionDescriptor descriptor) {
122: if (_contributions == null)
123: _contributions = new ArrayList();
124:
125: _contributions.add(descriptor);
126: }
127:
128: public List getContributions() {
129: return _contributions;
130: }
131:
132: public void addSubModule(SubModuleDescriptor subModule) {
133: if (_subModules == null)
134: _subModules = new ArrayList();
135:
136: _subModules.add(subModule);
137: }
138:
139: public List getSubModules() {
140: return _subModules;
141: }
142:
143: public void addDependency(DependencyDescriptor dependency) {
144: if (_dependencies == null)
145: _dependencies = new ArrayList();
146:
147: _dependencies.add(dependency);
148: }
149:
150: public List getDependencies() {
151: return _dependencies;
152: }
153:
154: /**
155: * Adds a schema to this module descriptor. If a schema with the same id already has been added,
156: * an error is reported and the given schema is ignored.
157: *
158: * @since 1.1
159: */
160: public void addSchema(SchemaImpl schema) {
161: if (_schemas == null)
162: _schemas = new HashMap();
163:
164: String schemaId = schema.getId();
165:
166: Schema existing = getSchema(schemaId);
167:
168: if (existing != null) {
169: _errorHandler.error(LOG, ParseMessages.duplicateSchema(
170: _moduleId + '.' + schemaId, existing), schema
171: .getLocation(), null);
172: return;
173: }
174:
175: _schemas.put(schemaId, schema);
176: }
177:
178: /** @since 1.1 */
179: public Schema getSchema(String id) {
180: return _schemas == null ? null : (Schema) _schemas.get(id);
181: }
182:
183: /**
184: * Returns a Collection of {@link org.apache.hivemind.schema.impl.SchemaImpl}.
185: *
186: * @since 1.1
187: */
188: public Collection getSchemas() {
189: return _schemas != null ? _schemas.values()
190: : Collections.EMPTY_LIST;
191: }
192:
193: public String getModuleId() {
194: return _moduleId;
195: }
196:
197: public String getVersion() {
198: return _version;
199: }
200:
201: public void setModuleId(String string) {
202: _moduleId = string;
203: }
204:
205: public void setVersion(String string) {
206: _version = string;
207: }
208:
209: public ClassResolver getClassResolver() {
210: return _resolver;
211: }
212:
213: /**
214: * Returns the name of the package to search for class names within. By default, the package
215: * name will match the module id, but this can be overridden in the module descriptor.
216: *
217: * @since 1.1
218: */
219:
220: public String getPackageName() {
221: return _packageName;
222: }
223:
224: /** @since 1.1 */
225:
226: public void setPackageName(String packageName) {
227: _packageName = packageName;
228: }
229: }
|