From 8307f06a338b1f73f47e83b94aa64c2241e9baa7 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 30 Sep 2014 12:28:42 +0200 Subject: Initial properties can be supplied as a marshalled PropertyArrayList as an optional additional parameter to CreateItem/AgentFromDescription. Each property supplied must be defined in the property description. --- .../c2kernel/property/PropertyDescriptionList.java | 36 ++++++++++++++++------ 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'src/main/java/com/c2kernel/property/PropertyDescriptionList.java') 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 @@ -27,8 +29,7 @@ public class PropertyDescriptionList extends CastorArrayList0) props.append(","); @@ -39,8 +40,7 @@ public class PropertyDescriptionList extends CastorArrayList validatedInitProps = new HashMap(); + 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; } - } -- cgit v1.2.3