1 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 39 public final class ModuleDescriptor extends BaseAnnotationHolder 40 { 41 42 private static final Log LOG = LogFactory.getLog(ModuleDescriptor.class); 43 44 private String _moduleId; 45 46 private String _version; 47 48 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 65 private Map _schemas; 66 67 private List _schemaAssignments; 68 69 private ClassResolver _resolver; 70 71 72 private ErrorHandler _errorHandler; 73 74 public ModuleDescriptor(ClassResolver resolver, ErrorHandler errorHandler) 75 { 76 _resolver = resolver; 77 _errorHandler = errorHandler; 78 } 79 80 public String 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 (); 94 95 _servicePoints.add(service); 96 } 97 98 public List getServicePoints() 99 { 100 return _servicePoints; 101 } 102 103 public void addImplementation(ImplementationDescriptor descriptor) 104 { 105 if (_implementations == null) 106 _implementations = new ArrayList (); 107 108 _implementations.add(descriptor); 109 } 110 111 public List getImplementations() 112 { 113 return _implementations; 114 } 115 116 public void addConfigurationPoint(ConfigurationPointDescriptor descriptor) 117 { 118 if (_configurationPoints == null) 119 _configurationPoints = new ArrayList (); 120 121 _configurationPoints.add(descriptor); 122 } 123 124 public List getConfigurationPoints() 125 { 126 return _configurationPoints; 127 } 128 129 public void addContribution(ContributionDescriptor descriptor) 130 { 131 if (_contributions == null) 132 _contributions = new ArrayList (); 133 134 _contributions.add(descriptor); 135 } 136 137 public List getContributions() 138 { 139 return _contributions; 140 } 141 142 public void addSubModule(SubModuleDescriptor subModule) 143 { 144 if (_subModules == null) 145 _subModules = new ArrayList (); 146 147 _subModules.add(subModule); 148 } 149 150 public List getSubModules() 151 { 152 return _subModules; 153 } 154 155 public void addDependency(DependencyDescriptor dependency) 156 { 157 if (_dependencies == null) 158 _dependencies = new ArrayList (); 159 160 _dependencies.add(dependency); 161 } 162 163 public List getDependencies() 164 { 165 return _dependencies; 166 } 167 168 174 public void addSchema(SchemaImpl schema) 175 { 176 if (_schemas == null) 177 _schemas = new HashMap (); 178 179 String 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 195 public Schema getSchema(String id) 196 { 197 return _schemas == null ? null : (Schema) _schemas.get(id); 198 } 199 200 205 public Collection getSchemas() 206 { 207 return _schemas != null ? _schemas.values() : Collections.EMPTY_LIST; 208 } 209 210 public String getModuleId() 211 { 212 return _moduleId; 213 } 214 215 public String getVersion() 216 { 217 return _version; 218 } 219 220 public void setModuleId(String string) 221 { 222 _moduleId = string; 223 } 224 225 public void setVersion(String string) 226 { 227 _version = string; 228 } 229 230 public ClassResolver getClassResolver() 231 { 232 return _resolver; 233 } 234 235 241 242 public String getPackageName() 243 { 244 return _packageName; 245 } 246 247 248 249 public void setPackageName(String packageName) 250 { 251 _packageName = packageName; 252 } 253 254 public void addSchemaAssignment(SchemaAssignmentDescriptor sad) 255 { 256 if (_schemaAssignments == null) 257 _schemaAssignments = new ArrayList (); 258 259 _schemaAssignments.add(sad); 260 } 261 262 public List getSchemaAssignment() 263 { 264 return _schemaAssignments; 265 } 266 267 } | Popular Tags |