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.api.DefinedProperty; 11 import net.sf.invicta.api.InvictaComponent; 12 import net.sf.invicta.api.InvictaProject; 13 import net.sf.invicta.api.Property; 14 import net.sf.invicta.project.ProjectDefinition; 15 import net.sf.invicta.project.PropertyImpl; 16 17 22 public class InvictaProjectImpl implements InvictaProject { 23 protected Map generalProperties = new SequencedHashMap(); 24 protected Map components = new SequencedHashMap(); 25 protected ProjectDefinition projectDefinition; 26 27 31 public InvictaProjectImpl(ProjectDefinition projectDefinition) { 32 this.projectDefinition = projectDefinition; 33 } 34 35 42 public void addComponent(InvictaComponent component) throws InvictaProcessException { 43 this.components.put(component.getName(), component); 44 addGeneralProperties(component); 45 } 46 47 51 public List getComponents() { 52 return (List )new ArrayList (this.components.values()); 53 } 54 55 61 public InvictaComponent getComponent(String componentName) { 62 return (InvictaComponent) this.components.get(componentName); 63 } 64 65 69 public String getDir() { 70 return projectDefinition.getDir(); 71 } 72 73 77 public String getName() { 78 return projectDefinition.getName(); 79 } 80 81 85 public Map getProjectPropertiesMap() { 86 return projectDefinition.getProjectPropertiesMap(); 87 } 88 89 93 public List getProjectProperties() { 94 return projectDefinition.getProjectProperties(); 95 } 96 97 102 public String getProjectPropertyValue(String propertyName) { 103 return projectDefinition.getProjectPropertyValue(propertyName); 104 } 105 106 111 public Property getProjectProperty(String propertyName) { 112 return projectDefinition.getProjectProperty(propertyName); 113 } 114 115 120 public void setProjectProperty(String propertyName, String value, String description) { 121 projectDefinition.setProjectProperty(propertyName, value, description); 122 } 123 124 128 public String getVersion() { 129 return projectDefinition.getVersion(); 130 } 131 132 136 public Map getGeneralPropertiesMap() { 137 return this.generalProperties; 138 } 139 140 144 public List getGeneralProperties() { 145 return (List )new ArrayList (this.generalProperties.values()); 146 } 147 148 154 public InvictaComponent getGlobalComponent() { 155 String componentName = this.projectDefinition.getGlobalComponentName(); 156 return this.getComponent(componentName); 157 } 158 159 163 protected void addGeneralProperties(InvictaComponent component) throws InvictaProcessException { 164 165 for (Iterator iter = component.getDefinedProperties().iterator(); iter.hasNext();) { 167 DefinedProperty property = (DefinedProperty) iter.next(); 168 169 if (property.isGeneralType()) { 170 String currentValue = null; 171 Property currentProperty = (Property)this.generalProperties.get(property.getName()); 172 if (currentProperty != null) 173 currentValue = currentProperty.getValue(); 174 175 if ((currentValue != null) && !property.getDefaultValue().equals(currentValue)) 177 throw InvictaProcessException.conflictingGeneralProperties(component.getTypeName(), property.getName()); 178 179 this.generalProperties.put(property.getName(), new PropertyImpl(property.getName(), property.getDefaultValue(), property.getDescription())); 181 } 182 } 183 } 184 } 185 | Popular Tags |