summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/property/PropertyDescriptionList.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/c2kernel/property/PropertyDescriptionList.java')
-rw-r--r--src/main/java/com/c2kernel/property/PropertyDescriptionList.java36
1 files changed, 27 insertions, 9 deletions
diff --git a/src/main/java/com/c2kernel/property/PropertyDescriptionList.java b/src/main/java/com/c2kernel/property/PropertyDescriptionList.java
index ed93008..96344a0 100644
--- a/src/main/java/com/c2kernel/property/PropertyDescriptionList.java
+++ b/src/main/java/com/c2kernel/property/PropertyDescriptionList.java
@@ -10,7 +10,9 @@
package com.c2kernel.property;
import java.util.ArrayList;
+import java.util.HashMap;
+import com.c2kernel.common.InvalidDataException;
import com.c2kernel.utils.CastorArrayList;
public class PropertyDescriptionList extends CastorArrayList<PropertyDescription>
@@ -27,8 +29,7 @@ public class PropertyDescriptionList extends CastorArrayList<PropertyDescription
public String getClassProps() {
StringBuffer props = new StringBuffer();
- for (Object name : list) {
- PropertyDescription element = (PropertyDescription)name;
+ for (PropertyDescription element : list) {
if (element.getIsClassIdentifier()) {
if (props.length()>0)
props.append(",");
@@ -39,8 +40,7 @@ public class PropertyDescriptionList extends CastorArrayList<PropertyDescription
}
public boolean setDefaultValue(String name, String value) {
- for (Object name2 : list) {
- PropertyDescription element = (PropertyDescription)name2;
+ for (PropertyDescription element : list) {
if (element.getName().equals(name)) {
element.setDefaultValue(value);
return true;
@@ -49,16 +49,34 @@ public class PropertyDescriptionList extends CastorArrayList<PropertyDescription
return false;
}
- public PropertyArrayList instanciate() {
- PropertyArrayList props = new PropertyArrayList();
+ public boolean definesProperty(String name) {
+ for (PropertyDescription element : list) {
+ if (element.getName().equals(name))
+ return true;
+ }
+ return false;
+ }
+
+ public PropertyArrayList instantiate(PropertyArrayList initProps) throws InvalidDataException {
+ // check that supplied init properties exist in desc list
+ HashMap<String, String> validatedInitProps = new HashMap<String, String>();
+ for (Property initProp : initProps.list) {
+ if (!definesProperty(initProp.getName()))
+ throw new InvalidDataException("Property "+initProp.getName()+" has not been declared in the property descriptions", "");
+ else
+ validatedInitProps.put(initProp.getName(), initProp.getValue());
+ }
+
+ PropertyArrayList propInst = new PropertyArrayList();
for (int i = 0; i < list.size(); i++) {
PropertyDescription pd = list.get(i);
String propName = pd.getName();
String propVal = pd.getDefaultValue();
+ if (validatedInitProps.containsKey(propName))
+ propVal = validatedInitProps.get(propName);
boolean isMutable = pd.getIsMutable();
- props.list.add( new Property(propName, propVal, isMutable));
+ propInst.list.add( new Property(propName, propVal, isMutable));
}
- return props;
+ return propInst;
}
-
}