[Major] refactored ParameterizedElement

ParameterizedElement is now the parent for all objects with Parameters.
ParameterBag is a sub class of ParameterizedElement.

Resource now extends GroupedParameterizedElement which implements the
container for ParameterBags.

Parameters have been moved to package ch.eitchnet.model.parameter
This commit is contained in:
Robert von Burg 2012-11-25 17:23:43 +01:00
parent bf5b83de22
commit bb9087eba9
14 changed files with 456 additions and 348 deletions

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
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 <eitch@eitchnet.ch>
*
*/
public abstract class GroupedParameterizedElement extends AbstractStrolchElement {
private static final long serialVersionUID = 0L;
protected Map<String, ParameterBag> 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 <T> Parameter<T> 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<String, ParameterBag>();
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 <T> Parameter<T> 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<String, ParameterBag>();
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<String> getParameterBagKeySet() {
if (this.parameterBagMap == null)
return Collections.emptySet();
return new HashSet<String>(this.parameterBagMap.keySet());
}
@Override
@SuppressWarnings("unchecked")
public void fromDom(Element element) {
super.fromDom(element);
String type = element.attributeValue("Type");
setType(type);
List<Element> 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());
}
}
}
}

View File

@ -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
*/

View File

@ -99,16 +99,16 @@ public interface Parameter<T> 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

View File

@ -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 <eitch@eitchnet.ch>
*
*/
public class ParameterBag extends AbstractStrolchElement {
private static final long serialVersionUID = 0L;
protected ParameterizedElement parent;
protected Map<String, Parameter<?>> 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<String, Parameter<?>>();
//
}
/**
* 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<String, Parameter<?>>();
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<String, Parameter<?>>();
// add all the parameters
@SuppressWarnings("unchecked")
List<Element> 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> 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 <T> Parameter<T> removeParameter(String key) {
return (Parameter<T>) 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<Parameter<?>> getParameters() {
return new ArrayList<Parameter<?>>(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<String> getParameterKeySet() {
return new HashSet<String>(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();
}
}

View File

@ -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 <eitch@eitchnet.ch>
*
*/
public abstract class ParameterizedElement extends AbstractStrolchElement {
private static final long serialVersionUID = 0L;
protected Map<String, ParameterBag> parameterBagMap = new HashMap<String, ParameterBag>();
protected GroupedParameterizedElement parent;
protected Map<String, Parameter<?>> parameterMap;
protected String type;
/**
* Default constructor
* Empty constructor
*/
protected ParameterizedElement() {
this.parameterBagMap = new HashMap<String, ParameterBag>();
//
}
/**
@ -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<String, ParameterBag>();
}
@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 <T> Parameter<T> 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> 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<String, Parameter<?>>();
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 <T> Parameter<T> removeParameter(String bagKey, String paramKey) {
ParameterBag bag = this.parameterBagMap.get(bagKey);
if (bag == null)
@SuppressWarnings("unchecked")
public <T> Parameter<T> removeParameter(String key) {
if (this.parameterMap == null)
return null;
return bag.removeParameter(paramKey);
return (Parameter<T>) 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<Parameter<?>> getParameters() {
if (this.parameterMap == null)
return Collections.emptyList();
return new ArrayList<Parameter<?>>(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<String> getParameterBagKeySet() {
return new HashSet<String>(this.parameterBagMap.keySet());
public Set<String> getParameterKeySet() {
if (this.parameterMap == null)
return Collections.emptySet();
return new HashSet<String>(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<Element> bags = element.elements("ParameterBag");
for (Element bagElement : bags) {
// add all the parameters
@SuppressWarnings("unchecked")
List<Element> 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();
}
}

View File

@ -30,7 +30,7 @@ import org.dom4j.tree.DefaultElement;
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
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;
}

View File

@ -19,10 +19,14 @@
* along with li.strolch.model. If not, see
* <http://www.gnu.org/licenses/>.
*/
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<T> 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<T> 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;
}

View File

@ -19,9 +19,10 @@
* along with li.strolch.model. If not, see
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model;
package li.strolch.model.parameter;
import li.strolch.exception.StrolchException;
import li.strolch.model.Parameter;
import org.dom4j.Element;

View File

@ -19,11 +19,12 @@
* along with li.strolch.model. If not, see
* <http://www.gnu.org/licenses/>.
*/
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;

View File

@ -19,9 +19,10 @@
* along with li.strolch.model. If not, see
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model;
package li.strolch.model.parameter;
import li.strolch.exception.StrolchException;
import li.strolch.model.Parameter;
import org.dom4j.Element;

View File

@ -19,9 +19,10 @@
* along with li.strolch.model. If not, see
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model;
package li.strolch.model.parameter;
import li.strolch.exception.StrolchException;
import li.strolch.model.Parameter;
import org.dom4j.Element;

View File

@ -19,9 +19,10 @@
* along with li.strolch.model. If not, see
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model;
package li.strolch.model.parameter;
import li.strolch.exception.StrolchException;
import li.strolch.model.Parameter;
import org.dom4j.Element;

View File

@ -19,9 +19,10 @@
* along with li.strolch.model. If not, see
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model;
package li.strolch.model.parameter;
import li.strolch.exception.StrolchException;
import li.strolch.model.Parameter;
import org.dom4j.Element;

View File

@ -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;