1 package net.sf.invicta.project; 2 3 import java.util.HashMap ; 4 import java.util.Iterator ; 5 import java.util.List ; 6 import java.util.Map ; 7 8 import net.sf.invicta.InvictaConstants; 9 import net.sf.invicta.Logger; 10 import net.sf.invicta.api.Property; 11 12 18 public class ProjectDefinition { 19 protected boolean isResolved = false; 21 22 protected ProjectSettings projectSettings; 24 protected Map components = new HashMap (); protected ComponentDefinition globalComponent; 26 27 30 public ProjectDefinition() { 31 super(); 32 33 } 34 35 40 public void putAll(ProjectDefinition projDef) throws InvictaProjectException { 41 if ((this.projectSettings != null) && 43 (projDef.getProjectSettings() != null)) 44 throw InvictaProjectException.duplicateProjectSettings(); 45 46 if (projDef.projectSettings != null) 48 this.projectSettings = projDef.projectSettings; 49 50 for (Iterator iterator = projDef.getComponentsMap().entrySet().iterator(); iterator.hasNext();) { 53 Map.Entry entry = (Map.Entry )iterator.next(); 54 if (this.components.containsKey(entry.getKey())) 55 throw InvictaProjectException.duplicateComponentDefinition((String )entry.getKey()); 56 this.components.put(entry.getKey(), entry.getValue()); 57 } 58 59 this.isResolved = false; 60 } 61 62 66 public void addComponent(ComponentDefinition component) throws InvictaProjectException { 67 if (this.components.get(component.getName()) != null) 68 throw InvictaProjectException.duplicateComponentDefinition(component.getName()); 69 this.components.put(component.getName(), component); 70 } 71 72 76 public void setProjectSettings(ProjectSettings projectSettings) { 77 this.projectSettings = projectSettings; 78 } 79 80 84 public ProjectSettings getProjectSettings() { 85 return this.projectSettings; 86 } 87 88 93 public Map getComponentsMap() { 94 return this.components; 95 } 96 97 101 public String getName() { 102 return this.projectSettings.getName(); 103 } 104 105 109 public String getDir() { 110 return this.projectSettings.getDir(); 111 } 112 113 117 public String getVersion() { 118 return this.projectSettings.getVersion(); 119 } 120 121 126 public String getProjectPropertyValue(String propertyName) { 127 return this.projectSettings.getPropertyValue(propertyName); 128 } 129 130 135 public Property getProjectProperty(String propertyName) { 136 return this.projectSettings.getProperty(propertyName); 137 } 138 139 145 public void setProjectProperty(String propertyName, String value, String description) { 146 Property previousProperty = 147 this.projectSettings.getProperty(propertyName); 148 if (previousProperty == null) { 149 this.projectSettings.setProperty(propertyName, value, description); 150 } else if (previousProperty.getDescription() == null) { 151 this.projectSettings.setProperty(propertyName, previousProperty.getValue(), description); 152 } 153 } 154 155 159 public Map getProjectPropertiesMap() { 160 return this.projectSettings.getPropertiesMap(); 161 } 162 163 167 public List getProjectProperties() { 168 return this.projectSettings.getProperties(); 169 } 170 171 172 175 public String toString() { 176 return components.toString(); 177 } 178 179 184 public void resolve() throws InvictaProjectException { 185 if (this.isResolved) 186 return; 187 188 resolveGlobalComponent(); 190 191 Logger.info("Resolving components: "); 192 Iterator iterator = this.components.entrySet().iterator(); 194 while(iterator.hasNext()) { 195 Map.Entry entry = (Map.Entry )iterator.next(); 196 String key = (String ) entry.getKey(); 197 ComponentDefinition component = (ComponentDefinition)entry.getValue(); 198 199 component.resolve(this, 0); 201 202 } 203 System.out.print("\n"); 204 this.isResolved = true; 205 } 206 207 215 public ComponentDefinition resolveComponent(String componentName, int level) throws InvictaProjectException { 216 ComponentDefinition component = (ComponentDefinition)this.components.get(componentName); 217 218 if (component == null) 219 throw InvictaProjectException.componentUndefined(componentName); 220 221 return component.resolve(this, level); 222 } 223 224 228 public ComponentDefinition getGlobalComponent() { 229 return this.globalComponent; 230 } 231 232 236 public String getGlobalComponentName() { 237 return this.globalComponent.getName(); 238 } 239 240 243 protected void resolveGlobalComponent() throws InvictaProjectException { 244 String globalComponentName = this.projectSettings.getGlobalComponent(); 247 if (globalComponentName != null) { 248 this.globalComponent = 249 (ComponentDefinition)this.components.get(globalComponentName); 250 251 if (this.globalComponent == null) 252 throw InvictaProjectException.componentUndefined(globalComponentName); 253 } else { 256 this.globalComponent = new ComponentDefinition(); 257 this.globalComponent.setName(this.getName() + 258 InvictaConstants.DEFAULT_GLOBAL_COMPONENT_NAME); 259 this.globalComponent.setType(InvictaConstants.DEFAULT_GLOBAL_COMPONENT_TYPE); 260 this.components.put(globalComponent.getName(), globalComponent); 261 } 262 } 263 264 } 265 | Popular Tags |