1 package net.sf.invicta.process; 2 3 import java.util.ArrayList ; 4 import java.util.Iterator ; 5 import java.util.List ; 6 import java.util.Map ; 7 8 import org.apache.commons.collections.SequencedHashMap; 9 10 import net.sf.invicta.InvictaConstants; 11 import net.sf.invicta.InvictaException; 12 import net.sf.invicta.api.DefinedProperty; 13 import net.sf.invicta.api.InvictaComponent; 14 import net.sf.invicta.api.InvictaProject; 15 import net.sf.invicta.api.Product; 16 import net.sf.invicta.api.ProductContainer; 17 import net.sf.invicta.project.BasicProduct; 18 import net.sf.invicta.project.ComponentDefinition; 19 import net.sf.invicta.project.InvictaProjectException; 20 import net.sf.invicta.type.BasicDefinedProperty; 21 import net.sf.invicta.type.TypeDefinition; 22 import net.sf.invicta.type.TypeManager; 23 24 31 public class TypedComponent implements InvictaComponent { 32 protected ComponentDefinition component; 33 protected TypeDefinition type; 34 protected InvictaProjectImpl project; 35 protected Map definedProperties = new SequencedHashMap(); 36 37 48 public TypedComponent(TypeManager typeManager, ComponentDefinition component, 49 InvictaProjectImpl project) throws InvictaException { 50 this.project = project; 51 this.component = component; 52 this.type = typeManager.getTypeDefinition(component.getType()); 53 validateComponent(); 54 createdTiedDefinedProperties(); 55 formatProducts(); 56 } 57 58 64 public List getDependComponentNames() { 65 return component.getDependComponentNames(); 66 } 67 68 69 74 public List getDependItems() { 75 return component.getDependItems(); 76 } 77 78 83 public String getDir() { 84 return component.getDir(); 85 } 86 87 92 public ProductContainer getExportedProducts() { 93 return component.getExportedProducts(); 94 } 95 96 101 public String getName() { 102 return component.getName(); 103 } 104 105 106 112 public ProductContainer getProducts() { 113 return component.getProducts(); 114 } 115 116 122 public ProductContainer getProductsWithoutSelf() { 123 return component.getProductsWithoutSelf(); 124 } 125 126 134 public String getPropertyValue(String propertyName) { 135 DefinedProperty definedProperty = getDefinedProperty(propertyName); 136 if (definedProperty == null) 137 return null; 138 139 return definedProperty.getActualValue(); 140 } 141 142 147 public List getRecursiveDependComponentNames() { 148 return component.getRecursiveDependComponentNames(); 149 } 150 151 156 public Map getRecursiveDependComponentsMap() { 157 return component.getRecursiveDependComponentNamesMap(); 158 } 159 160 167 public ProductContainer getRecursiveProducts() { 168 return component.getRecursiveProducts(); 169 } 170 171 178 public ProductContainer getRecursiveProductsWithoutSelf() { 179 return component.getRecursiveProductsWithoutSelf(); 180 } 181 182 189 public ProductContainer getRecursiveSelfProducts(List productNames) 190 throws InvictaProjectException { 191 return component.getRecursiveSelfProducts(productNames); 192 } 193 194 200 public ProductContainer getSelfProducts(String productName) { 201 return component.getSelfProducts(productName); 202 } 203 204 209 public ProductContainer getSelfProducts() { 210 return component.getSelfProducts(); 211 } 212 213 221 public ProductContainer getRecursiveSelfProducts(String productName) 222 throws InvictaProjectException { 223 return component.getRecursiveSelfProducts(productName); 224 } 225 226 231 public String getTemplate() { 232 return type.getAntTemplateString(); 233 } 234 235 240 public String getTypeName() { 241 return type.getName(); 242 } 243 244 249 public List getDependComponents() { 250 return getComponentsForNames(component.getDependComponentNames()); 251 } 252 253 261 public Product getSelfProduct(String type, String name) { 262 return component.getSelfProduct(type, name); 263 } 264 265 271 public List getRecursiveDependComponents() { 272 return component.getRecursiveDependComponents(); 273 } 274 275 279 public int compareTo(Object object) { 280 return this.component.getName().compareTo(((TypedComponent)object).getName()); 281 } 282 283 287 public InvictaProject getProject() { 288 return this.project; 289 } 290 291 296 public Map getDefinedPropertiesMap() { 297 return this.definedProperties; 298 } 299 300 305 public List getDefinedProperties() { 306 return new ArrayList (this.definedProperties.values()); 307 } 308 309 315 public DefinedProperty getDefinedProperty(String propertyName) { 316 return (DefinedProperty)this.definedProperties.get(propertyName); 317 } 318 326 public String getPropertyReferenceValue(String propertyName) { 327 DefinedProperty property = getDefinedProperty(propertyName); 328 if (property == null) 329 return null; 330 331 return property.getReferenceValue(); 332 } 333 334 335 340 public boolean containsTarget(String targetName) { 341 return type.containsTarget(targetName); 342 } 343 344 349 public String getBuildTarget() { 350 return type.getBuildTarget(); 351 } 352 353 358 public String getCleanTarget() { 359 return type.getCleanTarget(); 360 } 361 362 367 public String getDistTarget() { 368 return type.getDistTarget(); 369 } 370 371 public Map getTargetMap() { 372 return this.type.getTargetMap(); 373 } 374 375 376 379 public List getTargetList() { 380 return this.type.getTargetList(); 381 } 382 383 388 public String getComponentPropertyValue(String name) { 389 return this.component.getPropertyValue(name); 390 } 391 392 395 protected void createdTiedDefinedProperties() throws InvictaException { 396 for (Iterator iter = this.type.getDefinedProperties().values().iterator(); iter.hasNext();) { 398 BasicDefinedProperty property = (BasicDefinedProperty) iter.next(); 399 TiedDefinedProperty tiedProperty = new TiedDefinedProperty(property, this, this.project); 400 this.definedProperties.put(tiedProperty.getName(), tiedProperty); 401 } 402 } 403 404 405 protected void validateComponent() throws InvictaException{ 406 407 for (Iterator iter = this.type.getDefinedProperties().values().iterator(); iter.hasNext();) { 409 BasicDefinedProperty definedProperty = (BasicDefinedProperty) iter.next(); 410 411 if (definedProperty.isComponentType()) { 413 414 if (definedProperty.getDefaultValue() != null) { 415 this.component.setPropertyValue(definedProperty.getName(), definedProperty.getDefaultValue()); 416 } else if (this.component.getPropertyValue(definedProperty.getName()) == null) { 417 throw InvictaProcessException.propertyUndefined( 418 this.type.getName(), this.component.getName(), definedProperty.getName()); 419 } 420 421 } else if (definedProperty.isProjectType()) { 423 424 if (definedProperty.getDefaultValue() != null) { 425 this.project.setProjectProperty(definedProperty.getName(), definedProperty.getDefaultValue(), definedProperty.getDescription()); 426 } else if (this.project.getProjectPropertyValue(definedProperty.getName()) == null) { 427 throw InvictaProcessException.projectPropertyUndefined( 428 this.type.getName(), definedProperty.getName()); 429 } 430 } 431 } 432 433 } 434 435 436 protected void formatProducts() { 437 for (Iterator iter = this.component.getSelfProducts().iterator(); iter.hasNext();) { 438 BasicProduct product = (BasicProduct) iter.next(); 439 440 DefinedProperty property = 441 getDefinedProperty(InvictaConstants.PRODUCT_DIR_PROPERTY); 442 443 if (property != null) { 444 product.setProductDir(property.getActualValue()); 445 } 446 } 447 } 448 449 454 protected List getComponentsForNames(List names) { 455 List components = new ArrayList (); 456 for (Iterator iter = names.iterator(); iter.hasNext();) { 457 String componentName = (String ) iter.next(); 458 components.add(this.project.getComponent(componentName)); 459 } 460 return components; 461 } 462 463 468 public String getInitTarget() { 469 return this.type.getInitTarget(); 470 } 471 472 473 } 474 | Popular Tags |