diff --git a/src/main/java/li/strolch/model/GroupedParameterizedElement.java b/src/main/java/li/strolch/model/GroupedParameterizedElement.java
new file mode 100644
index 000000000..aa381dd6c
--- /dev/null
+++ b/src/main/java/li/strolch/model/GroupedParameterizedElement.java
@@ -0,0 +1,263 @@
+/*
+ * Copyright (c) 2012, Robert von Burg
+ *
+ * All rights reserved.
+ *
+ * This file is part of li.strolch.model.
+ *
+ * li.strolch.model is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * li.strolch.model is distributed in the hope that it will
+ * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with li.strolch.model. If not, see
+ * .
+ */
+package li.strolch.model;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import li.strolch.exception.StrolchException;
+
+import org.dom4j.Element;
+
+import ch.eitchnet.utils.helper.StringHelper;
+
+/**
+ * @author Robert von Burg
+ *
+ */
+public abstract class GroupedParameterizedElement extends AbstractStrolchElement {
+
+ private static final long serialVersionUID = 0L;
+
+ protected Map parameterBagMap;
+ protected String type;
+
+ /**
+ * Default constructor
+ */
+ protected GroupedParameterizedElement() {
+ //
+ }
+
+ /**
+ * @param id
+ * @param name
+ * @param type
+ */
+ protected GroupedParameterizedElement(String id, String name, String type) {
+ setId(id);
+ setName(name);
+ setType(type);
+ }
+
+ @Override
+ public String getType() {
+ return this.type;
+ }
+
+ /**
+ * Sets the type of this {@link GroupedParameterizedElement}
+ *
+ * @param type
+ * the type to set
+ */
+ public void setType(String type) {
+ if (StringHelper.isEmpty(type))
+ throw new StrolchException("Type must be set on element " + getLocator());
+
+ this.type = type;
+ }
+
+ /**
+ * Returns the {@link Parameter} with the given key from the {@link ParameterBag} with the given bagKey, or
+ * null if the {@link Parameter} or the {@link ParameterBag} does not exist
+ *
+ * @param bagKey
+ * the key of the {@link ParameterBag} from which the {@link Parameter} is to be returned
+ * @param paramKey
+ * the key of the {@link Parameter} which is to be returned
+ *
+ * @return the found {@link Parameter} or null if it was not found
+ */
+ public Parameter getParameter(String bagKey, String paramKey) {
+ if (this.parameterBagMap == null)
+ return null;
+ ParameterBag bag = this.parameterBagMap.get(bagKey);
+ if (bag == null)
+ return null;
+
+ return bag.getParameter(paramKey);
+ }
+
+ /**
+ * Adds a new {@link Parameter} to the {@link ParameterBag} with the given key
+ *
+ * @param bagKey
+ * the key of the {@link ParameterBag} to which the {@link Parameter} should be added
+ * @param parameter
+ * the {@link Parameter} to be added to the {@link ParameterBag}
+ *
+ * @throws StrolchException
+ * if the {@link ParameterBag} does not exist
+ */
+ public void addParameter(String bagKey, Parameter> parameter) throws StrolchException {
+ if (this.parameterBagMap == null)
+ this.parameterBagMap = new HashMap();
+ ParameterBag bag = this.parameterBagMap.get(bagKey);
+ if (bag == null) {
+ throw new StrolchException("No parameter bag exists with key " + bagKey);
+ }
+
+ bag.addParameter(parameter);
+ }
+
+ /**
+ * Removes the {@link Parameter} with the given paramKey from the {@link ParameterBag} with the given bagKey
+ *
+ * @param bagKey
+ * the key of the {@link ParameterBag} from which the {@link Parameter} is to be removed
+ * @param paramKey
+ * the key of the {@link Parameter} which is to be removed
+ *
+ * @return the removed {@link Parameter} or null if it did not exist
+ */
+ public Parameter removeParameter(String bagKey, String paramKey) {
+ if (this.parameterBagMap == null)
+ return null;
+ ParameterBag bag = this.parameterBagMap.get(bagKey);
+ if (bag == null)
+ return null;
+
+ return bag.removeParameter(paramKey);
+ }
+
+ /**
+ * Returns the {@link ParameterBag} with the given key, or null if it does not exist
+ *
+ * @param key
+ * the key of the {@link ParameterBag} to return
+ *
+ * @return the {@link ParameterBag} with the given key, or null if it does not exist
+ */
+ public ParameterBag getParameterBag(String key) {
+ if (this.parameterBagMap == null)
+ return null;
+ return this.parameterBagMap.get(key);
+ }
+
+ /**
+ * Adds the given {@link ParameterBag} to this {@link GroupedParameterizedElement}
+ *
+ * @param bag
+ * the {@link ParameterBag} to add
+ */
+ public void addParameterBag(ParameterBag bag) {
+ if (this.parameterBagMap == null)
+ this.parameterBagMap = new HashMap();
+ this.parameterBagMap.put(bag.getId(), bag);
+ bag.setParent(this);
+ }
+
+ /**
+ * Removes the {@link ParameterBag} with the given key
+ *
+ * @param key
+ * the key of the {@link ParameterBag} to remove
+ *
+ * @return the removed {@link ParameterBag}, or null if it does not exist
+ */
+ public ParameterBag removeParameterBag(String key) {
+ if (this.parameterBagMap == null)
+ return null;
+ return this.parameterBagMap.remove(key);
+ }
+
+ /**
+ * Returns true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the
+ * given bagKey
+ *
+ * @param bagKey
+ * the key of the {@link ParameterBag} on which to find the {@link Parameter}
+ * @param paramKey
+ * the key of the {@link Parameter} to be found
+ *
+ * @return true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the
+ * given bagKey. False is returned if the {@link ParameterBag} does not exist, or the
+ * {@link Parameter} does not exist on the {@link ParameterBag}
+ */
+ public boolean hasParameter(String bagKey, String paramKey) {
+ if (this.parameterBagMap == null)
+ return false;
+ ParameterBag bag = this.parameterBagMap.get(bagKey);
+ if (bag == null)
+ return false;
+
+ return bag.hasParameter(paramKey);
+ }
+
+ /**
+ * Returns the {@link Set} of keys for the {@link ParameterBag}s on this {@link GroupedParameterizedElement}
+ *
+ * @return the {@link Set} of keys for the {@link ParameterBag}s on this {@link GroupedParameterizedElement}
+ */
+ public Set getParameterBagKeySet() {
+ if (this.parameterBagMap == null)
+ return Collections.emptySet();
+ return new HashSet(this.parameterBagMap.keySet());
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void fromDom(Element element) {
+ super.fromDom(element);
+
+ String type = element.attributeValue("Type");
+ setType(type);
+
+ List bags = element.elements("ParameterBag");
+ for (Element bagElement : bags) {
+
+ ParameterBag bag = new ParameterBag(bagElement);
+ addParameterBag(bag);
+ }
+ }
+
+ @Override
+ protected void fillElement(Element element) {
+ super.fillElement(element);
+
+ if (this.parameterBagMap != null) {
+ for (ParameterBag bag : this.parameterBagMap.values()) {
+ element.add(bag.toDom());
+ }
+ }
+ }
+
+ /**
+ * Fills {@link GroupedParameterizedElement} properties of this clone
+ *
+ * @param clone
+ */
+ protected void fillClone(GroupedParameterizedElement clone) {
+ super.fillClone(clone);
+
+ if (this.parameterBagMap != null) {
+ for (ParameterBag bag : this.parameterBagMap.values()) {
+ clone.addParameterBag(bag.getClone());
+ }
+ }
+ }
+}
diff --git a/src/main/java/li/strolch/model/Order.java b/src/main/java/li/strolch/model/Order.java
index 55e521a86..aa35ab08d 100644
--- a/src/main/java/li/strolch/model/Order.java
+++ b/src/main/java/li/strolch/model/Order.java
@@ -37,7 +37,7 @@ import org.dom4j.tree.DefaultElement;
* @author eitch
*
*/
-public class Order extends ParameterizedElement {
+public class Order extends GroupedParameterizedElement {
private static final long serialVersionUID = 0L;
@@ -50,11 +50,11 @@ public class Order extends ParameterizedElement {
* Empty constructor
*/
public Order() {
- super();
+ //
}
/**
- * Build an Order
+ * Default constructor for an {@link Order}
*
* @param id
* @param name
@@ -68,7 +68,7 @@ public class Order extends ParameterizedElement {
}
/**
- * Build an Order
+ * Constructor with date and {@link State}
*
* @param id
* @param name
@@ -84,7 +84,7 @@ public class Order extends ParameterizedElement {
}
/**
- * Builds this Order from a Dom4j element
+ * From DOM Constructor
*
* @param element
*/
diff --git a/src/main/java/li/strolch/model/Parameter.java b/src/main/java/li/strolch/model/Parameter.java
index bdb7d2580..25fa427c7 100644
--- a/src/main/java/li/strolch/model/Parameter.java
+++ b/src/main/java/li/strolch/model/Parameter.java
@@ -99,16 +99,16 @@ public interface Parameter extends StrolchElement {
public void setUom(String uom);
/**
- * The {@link ParameterBag} parent to which this {@link Parameter} belongs
+ * The {@link ParameterizedElement} parent to which this {@link Parameter} belongs
*
* @return
*/
- public ParameterBag getParent();
+ public ParameterizedElement getParent();
/**
* Sets the parent for this {@link Parameter}
*/
- public void setParent(ParameterBag parent);
+ public void setParent(ParameterizedElement parent);
/**
* Returns the interpretation of this {@link Parameter}. The interpretation semantic describes what the value of
diff --git a/src/main/java/li/strolch/model/ParameterBag.java b/src/main/java/li/strolch/model/ParameterBag.java
index f4b914abf..2c7c290ec 100644
--- a/src/main/java/li/strolch/model/ParameterBag.java
+++ b/src/main/java/li/strolch/model/ParameterBag.java
@@ -3,7 +3,7 @@
*
* All rights reserved.
*
- * This file is part of li.strolch.model.
+ * This file is part of the XXX.
*
* li.strolch.model is free software: you can redistribute
* it and/or modify it under the terms of the GNU General Public License as
@@ -21,250 +21,56 @@
*/
package li.strolch.model;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import li.strolch.exception.StrolchException;
-import li.strolch.model.Locator.LocatorBuilder;
-
import org.dom4j.Element;
import org.dom4j.tree.DefaultElement;
-import ch.eitchnet.utils.helper.StringHelper;
-
/**
* @author Robert von Burg
- *
*/
-public class ParameterBag extends AbstractStrolchElement {
-
- private static final long serialVersionUID = 0L;
-
- protected ParameterizedElement parent;
- protected Map> parameterMap;
- protected String type;
+public class ParameterBag extends ParameterizedElement {
+ private static final long serialVersionUID = 1L;
/**
- * Empty constructor
+ * Constructor for special cases
*/
public ParameterBag() {
-
- this.parameterMap = new HashMap>();
+ //
}
/**
+ * Default constructor
+ *
* @param id
* @param name
* @param type
*/
public ParameterBag(String id, String name, String type) {
- setId(id);
- setName(name);
- setType(type);
-
- this.parameterMap = new HashMap>();
+ super(id, name, type);
}
/**
- * @param element
+ * Constructor from DOM
+ *
+ * @param bagElement
*/
- public ParameterBag(Element element) {
- super.fromDom(element);
-
- String type = element.attributeValue("Type");
- setType(type);
-
- this.parameterMap = new HashMap>();
-
- // add all the parameters
- @SuppressWarnings("unchecked")
- List parameterElements = element.elements("Parameter");
- for (Object object : parameterElements) {
- Element paramElement = (Element) object;
- String paramtype = paramElement.attributeValue("Type");
-
- if (paramtype.equals(StringParameter.TYPE)) {
- StringParameter param = new StringParameter(paramElement);
- addParameter(param);
- } else if (paramtype.equals(IntegerParameter.TYPE)) {
- IntegerParameter param = new IntegerParameter(paramElement);
- addParameter(param);
- } else if (paramtype.equals(FloatParameter.TYPE)) {
- FloatParameter param = new FloatParameter(paramElement);
- addParameter(param);
- } else if (paramtype.equals(LongParameter.TYPE)) {
- LongParameter param = new LongParameter(paramElement);
- addParameter(param);
- } else if (paramtype.equals(DateParameter.TYPE)) {
- DateParameter param = new DateParameter(paramElement);
- addParameter(param);
- } else if (paramtype.equals(BooleanParameter.TYPE)) {
- BooleanParameter param = new BooleanParameter(paramElement);
- addParameter(param);
- } else {
- throw new StrolchException("What kind of parameter is this: " + paramtype);
- }
- }
+ public ParameterBag(Element bagElement) {
+ super.fromDom(bagElement);
}
@Override
- public String getType() {
- return this.type;
- }
-
- /**
- * Sets the type of this {@link ParameterBag}
- *
- * @param type
- * the type to set
- */
- public void setType(String type) {
- if (StringHelper.isEmpty(type))
- throw new StrolchException("Type must be set on element " + getLocator());
-
- this.type = type;
- }
-
- /**
- * Returns this {@link ParameterBag}'s parent
- *
- * @return the parent
- */
- public ParameterizedElement getParent() {
- return this.parent;
- }
-
- /**
- * Set the parent for this {@link ParameterBag}
- *
- * @param parent
- * the parent to set
- */
- public void setParent(ParameterizedElement parent) {
- this.parent = parent;
- }
-
- /**
- * Returns the {@link Parameter} with the given id, or null if it does not exist
- *
- * @param key
- * the id of the parameter to return
- *
- * @return the {@link Parameter} with the given id, or null if it does not exist
- */
- @SuppressWarnings("unchecked")
- public T getParameter(String key) {
- return (T) this.parameterMap.get(key);
- }
-
- /**
- * Adds the given {@link Parameter} to the {@link ParameterBag}
- *
- * @param parameter
- * the {@link Parameter} to add
- */
- public void addParameter(Parameter> parameter) {
- this.parameterMap.put(parameter.getId(), parameter);
- parameter.setParent(this);
- }
-
- /**
- * Removes the {@link Parameter} with the given key
- *
- * @param key
- * the key of the {@link Parameter} to remove
- *
- * @return the removed {@link Parameter}, or null if it does not exist
- */
- @SuppressWarnings("unchecked")
- public Parameter removeParameter(String key) {
- return (Parameter) this.parameterMap.remove(key);
- }
-
- /**
- * Returns a list of all the {@link Parameter}s in this {@link ParameterBag}
- *
- * @return a list of all the {@link Parameter}s in this {@link ParameterBag}
- */
- public List> getParameters() {
- return new ArrayList>(this.parameterMap.values());
- }
-
- /**
- * Returns true, if the {@link Parameter} exists with the given key, false otherwise
- *
- * @param key
- * the key of the {@link Parameter} to check for
- *
- * @return true, if the {@link Parameter} exists with the given key, false otherwise
- */
- public boolean hasParameter(String key) {
- return this.parameterMap.containsKey(key);
- }
-
- /**
- * Returns a {@link Set} of all the {@link Parameter} keys in this {@link ParameterBag}
- *
- * @return a {@link Set} of all the {@link Parameter} keys in this {@link ParameterBag}
- */
- public Set getParameterKeySet() {
- return new HashSet(this.parameterMap.keySet());
- }
-
- @Override
- protected void fillLocator(LocatorBuilder lb) {
- lb.append("ParameterBag").append(this.id);
- }
-
- @Override
- public Locator getLocator() {
- LocatorBuilder lb = new LocatorBuilder();
- this.parent.fillLocator(lb);
- fillLocator(lb);
- return lb.build();
+ public ParameterBag getClone() {
+ ParameterBag clone = new ParameterBag();
+ super.fillClone(clone);
+ return clone;
}
@Override
public Element toDom() {
Element element = new DefaultElement("ParameterBag");
- fillElement(element);
- for (Parameter> parameter : this.parameterMap.values()) {
- element.add(parameter.toDom());
- }
+ fillElement(element);
return element;
}
-
- @Override
- public ParameterBag getClone() {
- ParameterBag clone = new ParameterBag();
-
- super.fillClone(clone);
-
- clone.setType(this.type);
-
- return clone;
- }
-
- @Override
- public String toString() {
-
- StringBuilder builder = new StringBuilder();
-
- builder.append("ParameterBag [id=");
- builder.append(this.id);
- builder.append(", name=");
- builder.append(this.name);
- builder.append(", type=");
- builder.append(this.type);
- builder.append("]");
-
- return builder.toString();
- }
}
diff --git a/src/main/java/li/strolch/model/ParameterizedElement.java b/src/main/java/li/strolch/model/ParameterizedElement.java
index be339e6d2..1c9585c7e 100644
--- a/src/main/java/li/strolch/model/ParameterizedElement.java
+++ b/src/main/java/li/strolch/model/ParameterizedElement.java
@@ -21,6 +21,8 @@
*/
package li.strolch.model;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -28,6 +30,13 @@ import java.util.Map;
import java.util.Set;
import li.strolch.exception.StrolchException;
+import li.strolch.model.Locator.LocatorBuilder;
+import li.strolch.model.parameter.BooleanParameter;
+import li.strolch.model.parameter.DateParameter;
+import li.strolch.model.parameter.FloatParameter;
+import li.strolch.model.parameter.IntegerParameter;
+import li.strolch.model.parameter.LongParameter;
+import li.strolch.model.parameter.StringParameter;
import org.dom4j.Element;
@@ -35,20 +44,20 @@ import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg
- *
*/
public abstract class ParameterizedElement extends AbstractStrolchElement {
private static final long serialVersionUID = 0L;
- protected Map parameterBagMap = new HashMap();
+ protected GroupedParameterizedElement parent;
+ protected Map> parameterMap;
protected String type;
/**
- * Default constructor
+ * Empty constructor
*/
protected ParameterizedElement() {
- this.parameterBagMap = new HashMap();
+ //
}
/**
@@ -56,12 +65,10 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
* @param name
* @param type
*/
- protected ParameterizedElement(String id, String name, String type) {
+ public ParameterizedElement(String id, String name, String type) {
setId(id);
setName(name);
setType(type);
-
- this.parameterBagMap = new HashMap();
}
@Override
@@ -83,140 +90,151 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
}
/**
- * Returns the {@link Parameter} with the given key from the {@link ParameterBag} with the given bagId, or null if
- * the {@link Parameter} or the {@link ParameterBag} does not exist
+ * Returns this {@link ParameterizedElement}'s parent
*
- * @param bagKey
- * the key of the {@link ParameterBag} from which the {@link Parameter} is to be returned
- * @param paramKey
- * the key of the {@link Parameter} which is to be returned
- *
- * @return the found {@link Parameter} or null if it was not found
+ * @return the parent
*/
- public Parameter getParameter(String bagKey, String paramKey) {
- ParameterBag bag = this.parameterBagMap.get(bagKey);
- if (bag == null)
- return null;
-
- return bag.getParameter(paramKey);
+ public GroupedParameterizedElement getParent() {
+ return this.parent;
}
/**
- * Adds a new {@link Parameter} to the {@link ParameterBag} with the given key
+ * Set the parent for this {@link ParameterizedElement}
+ *
+ * @param parent
+ * the parent to set
+ */
+ public void setParent(GroupedParameterizedElement parent) {
+ this.parent = parent;
+ }
+
+ /**
+ * Returns the {@link Parameter} with the given id, or null if it does not exist
+ *
+ * @param key
+ * the id of the parameter to return
+ *
+ * @return the {@link Parameter} with the given id, or null if it does not exist
+ */
+ @SuppressWarnings("unchecked")
+ public T getParameter(String key) {
+ if (this.parameterMap == null)
+ return null;
+ return (T) this.parameterMap.get(key);
+ }
+
+ /**
+ * Adds the given {@link Parameter} to the {@link ParameterizedElement}
*
- * @param bagKey
- * the key of the {@link ParameterBag} to which the {@link Parameter} should be added
* @param parameter
- * the {@link Parameter} to be added to the {@link ParameterBag}
- *
- * @throws StrolchException
- * if the {@link ParameterBag} does not exist
+ * the {@link Parameter} to add
*/
- public void addParameter(String bagKey, Parameter> parameter) throws StrolchException {
- ParameterBag bag = this.parameterBagMap.get(bagKey);
- if (bag == null) {
- throw new StrolchException("No parameter bag exists with key " + bagKey);
- }
-
- bag.addParameter(parameter);
+ public void addParameter(Parameter> parameter) {
+ if (this.parameterMap == null)
+ this.parameterMap = new HashMap>();
+ this.parameterMap.put(parameter.getId(), parameter);
+ parameter.setParent(this);
}
/**
- * Removes the {@link Parameter} with the given paramKey from the {@link ParameterBag} with the given bagKey
+ * Removes the {@link Parameter} with the given key
*
- * @param bagKey
- * the key of the {@link ParameterBag} from which the {@link Parameter} is to be removed
- * @param paramKey
- * the key of the {@link Parameter} which is to be removed
+ * @param key
+ * the key of the {@link Parameter} to remove
*
- * @return the removed {@link Parameter} or null if it did not exist
+ * @return the removed {@link Parameter}, or null if it does not exist
*/
- public Parameter removeParameter(String bagKey, String paramKey) {
- ParameterBag bag = this.parameterBagMap.get(bagKey);
- if (bag == null)
+ @SuppressWarnings("unchecked")
+ public Parameter removeParameter(String key) {
+ if (this.parameterMap == null)
return null;
-
- return bag.removeParameter(paramKey);
+ return (Parameter) this.parameterMap.remove(key);
}
/**
- * Returns the {@link ParameterBag} with the given key, or null if it does not exist
+ * Returns a list of all the {@link Parameter}s in this {@link ParameterizedElement}
+ *
+ * @return a list of all the {@link Parameter}s in this {@link ParameterizedElement}
+ */
+ public List> getParameters() {
+ if (this.parameterMap == null)
+ return Collections.emptyList();
+ return new ArrayList>(this.parameterMap.values());
+ }
+
+ /**
+ * Returns true, if the {@link Parameter} exists with the given key, false otherwise
*
* @param key
- * the key of the {@link ParameterBag} to return
+ * the key of the {@link Parameter} to check for
*
- * @return the {@link ParameterBag} with the given key, or null if it does not exist
+ * @return true, if the {@link Parameter} exists with the given key, false otherwise
*/
- public ParameterBag getParameterBag(String key) {
- return this.parameterBagMap.get(key);
- }
-
- /**
- * Adds the given {@link ParameterBag} to this {@link ParameterizedElement}
- *
- * @param bag
- * the {@link ParameterBag} to add
- */
- public void addParameterBag(ParameterBag bag) {
- this.parameterBagMap.put(bag.getId(), bag);
- bag.setParent(this);
- }
-
- /**
- * Removes the {@link ParameterBag} with the given key
- *
- * @param key
- * the key of the {@link ParameterBag} to remove
- *
- * @return the removed {@link ParameterBag}, or null if it does not exist
- */
- public ParameterBag removeParameterBag(String key) {
- return this.parameterBagMap.remove(key);
- }
-
- /**
- * Returns true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the given
- * bagKey
- *
- * @param bagKey
- * the key of the {@link ParameterBag} on which to find the {@link Parameter}
- * @param paramKey
- * the key of the {@link Parameter} to be found
- *
- * @return true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the given
- * bagKey. False is returned if the {@link ParameterBag} does not exist, or the {@link Parameter} does not
- * exist on the {@link ParameterBag}
- */
- public boolean hasParameter(String bagKey, String paramKey) {
- ParameterBag bag = this.parameterBagMap.get(bagKey);
- if (bag == null)
+ public boolean hasParameter(String key) {
+ if (this.parameterMap == null)
return false;
-
- return bag.hasParameter(paramKey);
+ return this.parameterMap.containsKey(key);
}
/**
- * Returns the {@link Set} of keys for the {@link ParameterBag}s on this {@link ParameterizedElement}
+ * Returns a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement}
*
- * @return the {@link Set} of keys for the {@link ParameterBag}s on this {@link ParameterizedElement}
+ * @return a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement}
*/
- public Set getParameterBagKeySet() {
- return new HashSet(this.parameterBagMap.keySet());
+ public Set getParameterKeySet() {
+ if (this.parameterMap == null)
+ return Collections.emptySet();
+ return new HashSet(this.parameterMap.keySet());
}
@Override
- @SuppressWarnings("unchecked")
- public void fromDom(Element element) {
+ public void fillLocator(LocatorBuilder lb) {
+ lb.append("ParameterizedElement").append(this.id);
+ }
+
+ @Override
+ public Locator getLocator() {
+ LocatorBuilder lb = new LocatorBuilder();
+ this.parent.fillLocator(lb);
+ fillLocator(lb);
+ return lb.build();
+ }
+
+ @Override
+ protected void fromDom(Element element) {
super.fromDom(element);
String type = element.attributeValue("Type");
setType(type);
- List bags = element.elements("ParameterBag");
- for (Element bagElement : bags) {
+ // add all the parameters
+ @SuppressWarnings("unchecked")
+ List parameterElements = element.elements("Parameter");
+ for (Object object : parameterElements) {
+ Element paramElement = (Element) object;
+ String paramtype = paramElement.attributeValue("Type");
- ParameterBag bag = new ParameterBag(bagElement);
- addParameterBag(bag);
+ if (paramtype.equals(StringParameter.TYPE)) {
+ StringParameter param = new StringParameter(paramElement);
+ addParameter(param);
+ } else if (paramtype.equals(IntegerParameter.TYPE)) {
+ IntegerParameter param = new IntegerParameter(paramElement);
+ addParameter(param);
+ } else if (paramtype.equals(FloatParameter.TYPE)) {
+ FloatParameter param = new FloatParameter(paramElement);
+ addParameter(param);
+ } else if (paramtype.equals(LongParameter.TYPE)) {
+ LongParameter param = new LongParameter(paramElement);
+ addParameter(param);
+ } else if (paramtype.equals(DateParameter.TYPE)) {
+ DateParameter param = new DateParameter(paramElement);
+ addParameter(param);
+ } else if (paramtype.equals(BooleanParameter.TYPE)) {
+ BooleanParameter param = new BooleanParameter(paramElement);
+ addParameter(param);
+ } else {
+ throw new StrolchException("What kind of parameter is this: " + paramtype);
+ }
}
}
@@ -224,21 +242,32 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
protected void fillElement(Element element) {
super.fillElement(element);
- for (ParameterBag bag : this.parameterBagMap.values()) {
- element.add(bag.toDom());
+ if (this.parameterMap != null) {
+ for (Parameter> parameter : this.parameterMap.values()) {
+ element.add(parameter.toDom());
+ }
}
}
- /**
- * Fills {@link ParameterizedElement} properties of this clone
- *
- * @param clone
- */
- protected void fillClone(ParameterizedElement clone) {
+ @Override
+ protected void fillClone(StrolchElement clone) {
super.fillClone(clone);
+ ((ParameterizedElement) clone).setType(this.type);
+ }
- for (ParameterBag bag : this.parameterBagMap.values()) {
- clone.addParameterBag(bag.getClone());
- }
+ @Override
+ public String toString() {
+
+ StringBuilder builder = new StringBuilder();
+
+ builder.append("ParameterizedElement [id=");
+ builder.append(this.id);
+ builder.append(", name=");
+ builder.append(this.name);
+ builder.append(", type=");
+ builder.append(this.type);
+ builder.append("]");
+
+ return builder.toString();
}
}
diff --git a/src/main/java/li/strolch/model/Resource.java b/src/main/java/li/strolch/model/Resource.java
index 288f666e7..41e920777 100644
--- a/src/main/java/li/strolch/model/Resource.java
+++ b/src/main/java/li/strolch/model/Resource.java
@@ -30,7 +30,7 @@ import org.dom4j.tree.DefaultElement;
* @author Robert von Burg
*
*/
-public class Resource extends ParameterizedElement {
+public class Resource extends GroupedParameterizedElement {
private static final long serialVersionUID = 0L;
public static final String PREFIX_RESOURCE = "ResourcePrefix";
@@ -63,7 +63,7 @@ public class Resource extends ParameterizedElement {
public Element toDom() {
Element element = new DefaultElement("Resource");
- fromDom(element);
+ fillElement(element);
return element;
}
diff --git a/src/main/java/li/strolch/model/AbstractParameter.java b/src/main/java/li/strolch/model/parameter/AbstractParameter.java
similarity index 93%
rename from src/main/java/li/strolch/model/AbstractParameter.java
rename to src/main/java/li/strolch/model/parameter/AbstractParameter.java
index bfd4cf2d7..208254e39 100644
--- a/src/main/java/li/strolch/model/AbstractParameter.java
+++ b/src/main/java/li/strolch/model/parameter/AbstractParameter.java
@@ -19,10 +19,14 @@
* along with li.strolch.model. If not, see
* .
*/
-package li.strolch.model;
+package li.strolch.model.parameter;
import li.strolch.exception.StrolchException;
+import li.strolch.model.AbstractStrolchElement;
+import li.strolch.model.Locator;
import li.strolch.model.Locator.LocatorBuilder;
+import li.strolch.model.Parameter;
+import li.strolch.model.ParameterizedElement;
import org.dom4j.Element;
import org.dom4j.tree.DefaultElement;
@@ -42,7 +46,7 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem
protected String interpretation;
protected String uom;
- protected ParameterBag parent;
+ protected ParameterizedElement parent;
@Override
public boolean isHidden() {
@@ -83,12 +87,12 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem
}
@Override
- public ParameterBag getParent() {
+ public ParameterizedElement getParent() {
return this.parent;
}
@Override
- public void setParent(ParameterBag parent) {
+ public void setParent(ParameterizedElement parent) {
this.parent = parent;
}
diff --git a/src/main/java/li/strolch/model/BooleanParameter.java b/src/main/java/li/strolch/model/parameter/BooleanParameter.java
similarity index 96%
rename from src/main/java/li/strolch/model/BooleanParameter.java
rename to src/main/java/li/strolch/model/parameter/BooleanParameter.java
index a1be83d81..bb0f05215 100644
--- a/src/main/java/li/strolch/model/BooleanParameter.java
+++ b/src/main/java/li/strolch/model/parameter/BooleanParameter.java
@@ -19,9 +19,10 @@
* along with li.strolch.model. If not, see
* .
*/
-package li.strolch.model;
+package li.strolch.model.parameter;
import li.strolch.exception.StrolchException;
+import li.strolch.model.Parameter;
import org.dom4j.Element;
diff --git a/src/main/java/li/strolch/model/DateParameter.java b/src/main/java/li/strolch/model/parameter/DateParameter.java
similarity index 97%
rename from src/main/java/li/strolch/model/DateParameter.java
rename to src/main/java/li/strolch/model/parameter/DateParameter.java
index 84a2e6986..e0c677934 100644
--- a/src/main/java/li/strolch/model/DateParameter.java
+++ b/src/main/java/li/strolch/model/parameter/DateParameter.java
@@ -19,11 +19,12 @@
* along with li.strolch.model. If not, see
* .
*/
-package li.strolch.model;
+package li.strolch.model.parameter;
import java.text.DateFormat;
import li.strolch.exception.StrolchException;
+import li.strolch.model.Parameter;
import org.dom4j.Element;
diff --git a/src/main/java/li/strolch/model/FloatParameter.java b/src/main/java/li/strolch/model/parameter/FloatParameter.java
similarity index 96%
rename from src/main/java/li/strolch/model/FloatParameter.java
rename to src/main/java/li/strolch/model/parameter/FloatParameter.java
index 6986e8c17..903eadc88 100644
--- a/src/main/java/li/strolch/model/FloatParameter.java
+++ b/src/main/java/li/strolch/model/parameter/FloatParameter.java
@@ -19,9 +19,10 @@
* along with li.strolch.model. If not, see
* .
*/
-package li.strolch.model;
+package li.strolch.model.parameter;
import li.strolch.exception.StrolchException;
+import li.strolch.model.Parameter;
import org.dom4j.Element;
diff --git a/src/main/java/li/strolch/model/IntegerParameter.java b/src/main/java/li/strolch/model/parameter/IntegerParameter.java
similarity index 96%
rename from src/main/java/li/strolch/model/IntegerParameter.java
rename to src/main/java/li/strolch/model/parameter/IntegerParameter.java
index 83ccc3be9..a2fcc7414 100644
--- a/src/main/java/li/strolch/model/IntegerParameter.java
+++ b/src/main/java/li/strolch/model/parameter/IntegerParameter.java
@@ -19,9 +19,10 @@
* along with li.strolch.model. If not, see
* .
*/
-package li.strolch.model;
+package li.strolch.model.parameter;
import li.strolch.exception.StrolchException;
+import li.strolch.model.Parameter;
import org.dom4j.Element;
diff --git a/src/main/java/li/strolch/model/LongParameter.java b/src/main/java/li/strolch/model/parameter/LongParameter.java
similarity index 96%
rename from src/main/java/li/strolch/model/LongParameter.java
rename to src/main/java/li/strolch/model/parameter/LongParameter.java
index 9edb02709..1f4d8a0a6 100644
--- a/src/main/java/li/strolch/model/LongParameter.java
+++ b/src/main/java/li/strolch/model/parameter/LongParameter.java
@@ -19,9 +19,10 @@
* along with li.strolch.model. If not, see
* .
*/
-package li.strolch.model;
+package li.strolch.model.parameter;
import li.strolch.exception.StrolchException;
+import li.strolch.model.Parameter;
import org.dom4j.Element;
diff --git a/src/main/java/li/strolch/model/StringParameter.java b/src/main/java/li/strolch/model/parameter/StringParameter.java
similarity index 96%
rename from src/main/java/li/strolch/model/StringParameter.java
rename to src/main/java/li/strolch/model/parameter/StringParameter.java
index 917791faf..6aa7ef2dc 100644
--- a/src/main/java/li/strolch/model/StringParameter.java
+++ b/src/main/java/li/strolch/model/parameter/StringParameter.java
@@ -19,9 +19,10 @@
* along with li.strolch.model. If not, see
* .
*/
-package li.strolch.model;
+package li.strolch.model.parameter;
import li.strolch.exception.StrolchException;
+import li.strolch.model.Parameter;
import org.dom4j.Element;
diff --git a/src/test/java/li/strolch/ModelTest.java b/src/test/java/li/strolch/ModelTest.java
index 7a6e5d7f0..f0970ff55 100644
--- a/src/test/java/li/strolch/ModelTest.java
+++ b/src/test/java/li/strolch/ModelTest.java
@@ -1,11 +1,11 @@
package li.strolch;
-import li.strolch.model.FloatParameter;
import li.strolch.model.Order;
import li.strolch.model.Parameter;
import li.strolch.model.ParameterBag;
import li.strolch.model.Resource;
import li.strolch.model.State;
+import li.strolch.model.parameter.FloatParameter;
import org.junit.Test;