[Major] Major refactoring of toDom and toSax implementations
- adding Activity and Action - remove methods on model itself and move to visitors
This commit is contained in:
parent
c499f53758
commit
8f7f6aa920
|
@ -1 +1 @@
|
||||||
Subproject commit 1689ff69a93f7fcf491400e36b941c905d368018
|
Subproject commit 9e449e56eedc01ef24b9d4a8a5cbf5c52b013a48
|
|
@ -19,9 +19,6 @@ import java.text.MessageFormat;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Locator.LocatorBuilder;
|
import li.strolch.model.Locator.LocatorBuilder;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
import ch.eitchnet.utils.helper.StringHelper;
|
import ch.eitchnet.utils.helper.StringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -114,31 +111,6 @@ public abstract class AbstractStrolchElement implements StrolchElement {
|
||||||
clone.setName(getName());
|
clone.setName(getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void fillElement(Element element) {
|
|
||||||
element.setAttribute(Tags.ID, getId());
|
|
||||||
element.setAttribute(Tags.NAME, getName());
|
|
||||||
element.setAttribute(Tags.TYPE, getType());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds the fields of this {@link StrolchElement} from a {@link Element}
|
|
||||||
*
|
|
||||||
* @param element
|
|
||||||
*/
|
|
||||||
protected void fromDom(Element element) {
|
|
||||||
String id = element.getAttribute(Tags.ID);
|
|
||||||
String name = element.getAttribute(Tags.NAME);
|
|
||||||
|
|
||||||
if (id != null && name != null) {
|
|
||||||
setId(id);
|
|
||||||
setName(name);
|
|
||||||
} else {
|
|
||||||
String msg = "Check the values of the element: {0} either id or name attribute is null!"; //$NON-NLS-1$
|
|
||||||
msg = MessageFormat.format(msg, element.getNodeName());
|
|
||||||
throw new StrolchException(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
|
|
|
@ -25,10 +25,6 @@ import java.util.Set;
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.exception.StrolchModelException;
|
import li.strolch.exception.StrolchModelException;
|
||||||
import li.strolch.model.parameter.Parameter;
|
import li.strolch.model.parameter.Parameter;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
import ch.eitchnet.utils.helper.StringHelper;
|
import ch.eitchnet.utils.helper.StringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -291,32 +287,6 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
|
||||||
return new HashSet<String>(this.parameterBagMap.keySet());
|
return new HashSet<String>(this.parameterBagMap.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fromDom(Element element) {
|
|
||||||
super.fromDom(element);
|
|
||||||
|
|
||||||
String type = element.getAttribute(Tags.TYPE);
|
|
||||||
setType(type);
|
|
||||||
|
|
||||||
NodeList bags = element.getElementsByTagName(Tags.PARAMETER_BAG);
|
|
||||||
for (int i = 0; i < bags.getLength(); i++) {
|
|
||||||
Element bagElement = (Element) bags.item(i);
|
|
||||||
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.appendChild(bag.toDom(element.getOwnerDocument()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills {@link GroupedParameterizedElement} properties of this clone
|
* Fills {@link GroupedParameterizedElement} properties of this clone
|
||||||
*
|
*
|
||||||
|
|
|
@ -80,6 +80,17 @@ public class ModelStatistics {
|
||||||
return this.nrOfActivities;
|
return this.nrOfActivities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the statistics of the other statistics to this statistics instance
|
||||||
|
*
|
||||||
|
* @param statistics
|
||||||
|
*/
|
||||||
|
public void add(ModelStatistics statistics) {
|
||||||
|
this.nrOfOrders += statistics.nrOfOrders;
|
||||||
|
this.nrOfResources += statistics.nrOfResources;
|
||||||
|
this.nrOfActivities += statistics.nrOfActivities;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
|
@ -19,11 +19,6 @@ import java.util.Date;
|
||||||
|
|
||||||
import li.strolch.model.Locator.LocatorBuilder;
|
import li.strolch.model.Locator.LocatorBuilder;
|
||||||
import li.strolch.model.visitor.StrolchRootElementVisitor;
|
import li.strolch.model.visitor.StrolchRootElementVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
import ch.eitchnet.utils.helper.StringHelper;
|
|
||||||
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
|
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,30 +75,6 @@ public class Order extends GroupedParameterizedElement implements StrolchRootEle
|
||||||
setDate(date);
|
setDate(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* DOM Constructor
|
|
||||||
*
|
|
||||||
* @param element
|
|
||||||
*/
|
|
||||||
public Order(Element element) {
|
|
||||||
super.fromDom(element);
|
|
||||||
|
|
||||||
String date = element.getAttribute(Tags.DATE);
|
|
||||||
String state = element.getAttribute(Tags.STATE);
|
|
||||||
|
|
||||||
if (StringHelper.isEmpty(date)) {
|
|
||||||
setDate(ISO8601FormatFactory.getInstance().getDateFormat().parse("-")); //$NON-NLS-1$
|
|
||||||
} else {
|
|
||||||
setDate(ISO8601FormatFactory.getInstance().getDateFormat().parse(date));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state == null || state.isEmpty()) {
|
|
||||||
setState(State.CREATED);
|
|
||||||
} else {
|
|
||||||
setState(State.valueOf(state));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the date
|
* @return the date
|
||||||
*/
|
*/
|
||||||
|
@ -134,18 +105,6 @@ public class Order extends GroupedParameterizedElement implements StrolchRootEle
|
||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Element toDom(Document doc) {
|
|
||||||
|
|
||||||
Element orderElement = doc.createElement(Tags.ORDER);
|
|
||||||
fillElement(orderElement);
|
|
||||||
|
|
||||||
orderElement.setAttribute(Tags.DATE, ISO8601FormatFactory.getInstance().formatDate(this.date));
|
|
||||||
orderElement.setAttribute(Tags.STATE, this.state.toString());
|
|
||||||
|
|
||||||
return orderElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Order getClone() {
|
public Order getClone() {
|
||||||
Order clone = new Order();
|
Order clone = new Order();
|
||||||
|
|
|
@ -17,9 +17,6 @@ package li.strolch.model;
|
||||||
|
|
||||||
import li.strolch.model.Locator.LocatorBuilder;
|
import li.strolch.model.Locator.LocatorBuilder;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
|
@ -45,15 +42,6 @@ public class ParameterBag extends ParameterizedElement {
|
||||||
super(id, name, type);
|
super(id, name, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* DOM Constructor
|
|
||||||
*
|
|
||||||
* @param bagElement
|
|
||||||
*/
|
|
||||||
public ParameterBag(Element bagElement) {
|
|
||||||
super.fromDom(bagElement);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ParameterBag getClone() {
|
public ParameterBag getClone() {
|
||||||
ParameterBag clone = new ParameterBag();
|
ParameterBag clone = new ParameterBag();
|
||||||
|
@ -68,16 +56,6 @@ public class ParameterBag extends ParameterizedElement {
|
||||||
lb.append(this.id);
|
lb.append(this.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Element toDom(Document doc) {
|
|
||||||
|
|
||||||
Element element = doc.createElement(Tags.PARAMETER_BAG);
|
|
||||||
|
|
||||||
fillElement(element);
|
|
||||||
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isRootElement() {
|
public boolean isRootElement() {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -26,23 +26,7 @@ import java.util.Set;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Locator.LocatorBuilder;
|
import li.strolch.model.Locator.LocatorBuilder;
|
||||||
import li.strolch.model.parameter.BooleanParameter;
|
|
||||||
import li.strolch.model.parameter.DateParameter;
|
|
||||||
import li.strolch.model.parameter.DurationParameter;
|
|
||||||
import li.strolch.model.parameter.FloatListParameter;
|
|
||||||
import li.strolch.model.parameter.FloatParameter;
|
|
||||||
import li.strolch.model.parameter.IntegerListParameter;
|
|
||||||
import li.strolch.model.parameter.IntegerParameter;
|
|
||||||
import li.strolch.model.parameter.LongListParameter;
|
|
||||||
import li.strolch.model.parameter.LongParameter;
|
|
||||||
import li.strolch.model.parameter.Parameter;
|
import li.strolch.model.parameter.Parameter;
|
||||||
import li.strolch.model.parameter.StringListParameter;
|
|
||||||
import li.strolch.model.parameter.StringParameter;
|
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
import ch.eitchnet.utils.dbc.DBC;
|
|
||||||
import ch.eitchnet.utils.helper.StringHelper;
|
import ch.eitchnet.utils.helper.StringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -206,75 +190,6 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
|
||||||
return lb.build();
|
return lb.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO remove the whole fromDom methods from strolch model - we want to use the visitor pattern only!
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void fromDom(Element element) {
|
|
||||||
super.fromDom(element);
|
|
||||||
|
|
||||||
String type = element.getAttribute(Tags.TYPE);
|
|
||||||
setType(type);
|
|
||||||
|
|
||||||
// add all the parameters
|
|
||||||
NodeList parameterElements = element.getElementsByTagName(Tags.PARAMETER);
|
|
||||||
for (int i = 0; i < parameterElements.getLength(); i++) {
|
|
||||||
Element paramElement = (Element) parameterElements.item(i);
|
|
||||||
String paramtype = paramElement.getAttribute(Tags.TYPE);
|
|
||||||
|
|
||||||
DBC.PRE.assertNotEmpty("Type must be set on Parameter for bag with id " + this.id, paramtype);
|
|
||||||
|
|
||||||
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(DurationParameter.TYPE)) {
|
|
||||||
DurationParameter param = new DurationParameter(paramElement);
|
|
||||||
addParameter(param);
|
|
||||||
} else if (paramtype.equals(BooleanParameter.TYPE)) {
|
|
||||||
BooleanParameter param = new BooleanParameter(paramElement);
|
|
||||||
addParameter(param);
|
|
||||||
} else if (paramtype.equals(StringListParameter.TYPE)) {
|
|
||||||
StringListParameter param = new StringListParameter(paramElement);
|
|
||||||
addParameter(param);
|
|
||||||
} else if (paramtype.equals(IntegerListParameter.TYPE)) {
|
|
||||||
IntegerListParameter param = new IntegerListParameter(paramElement);
|
|
||||||
addParameter(param);
|
|
||||||
} else if (paramtype.equals(FloatListParameter.TYPE)) {
|
|
||||||
FloatListParameter param = new FloatListParameter(paramElement);
|
|
||||||
addParameter(param);
|
|
||||||
} else if (paramtype.equals(LongListParameter.TYPE)) {
|
|
||||||
LongListParameter param = new LongListParameter(paramElement);
|
|
||||||
addParameter(param);
|
|
||||||
} else {
|
|
||||||
String msg = "What kind of parameter is this: {0}"; //$NON-NLS-1$
|
|
||||||
msg = MessageFormat.format(msg, paramtype);
|
|
||||||
throw new StrolchException(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void fillElement(Element element) {
|
|
||||||
super.fillElement(element);
|
|
||||||
|
|
||||||
if (this.parameterMap != null) {
|
|
||||||
for (Parameter<?> parameter : this.parameterMap.values()) {
|
|
||||||
element.appendChild(parameter.toDom(element.getOwnerDocument()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void fillClone(StrolchElement clone) {
|
protected void fillClone(StrolchElement clone) {
|
||||||
super.fillClone(clone);
|
super.fillClone(clone);
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model;
|
package li.strolch.model;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -24,22 +23,11 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
|
||||||
import li.strolch.model.Locator.LocatorBuilder;
|
import li.strolch.model.Locator.LocatorBuilder;
|
||||||
import li.strolch.model.timedstate.BooleanTimedState;
|
|
||||||
import li.strolch.model.timedstate.FloatTimedState;
|
|
||||||
import li.strolch.model.timedstate.IntegerTimedState;
|
|
||||||
import li.strolch.model.timedstate.StringSetTimedState;
|
|
||||||
import li.strolch.model.timedstate.StrolchTimedState;
|
import li.strolch.model.timedstate.StrolchTimedState;
|
||||||
import li.strolch.model.timevalue.IValue;
|
import li.strolch.model.timevalue.IValue;
|
||||||
import li.strolch.model.visitor.StrolchRootElementVisitor;
|
import li.strolch.model.visitor.StrolchRootElementVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
import ch.eitchnet.utils.dbc.DBC;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
|
@ -67,41 +55,6 @@ public class Resource extends GroupedParameterizedElement implements StrolchRoot
|
||||||
super(id, name, type);
|
super(id, name, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* DOM Constructor
|
|
||||||
*
|
|
||||||
* @param element
|
|
||||||
*/
|
|
||||||
public Resource(Element element) {
|
|
||||||
super.fromDom(element);
|
|
||||||
|
|
||||||
NodeList timedStateElems = element.getElementsByTagName(Tags.TIMED_STATE);
|
|
||||||
for (int i = 0; i < timedStateElems.getLength(); i++) {
|
|
||||||
Element timedStateElem = (Element) timedStateElems.item(i);
|
|
||||||
String typeS = timedStateElem.getAttribute(Tags.TYPE);
|
|
||||||
|
|
||||||
DBC.PRE.assertNotEmpty("Type must be set on TimedState for resource with id " + this.id, typeS);
|
|
||||||
|
|
||||||
if (typeS.equals(FloatTimedState.TYPE)) {
|
|
||||||
FloatTimedState timedState = new FloatTimedState(timedStateElem);
|
|
||||||
addTimedState(timedState);
|
|
||||||
} else if (typeS.equals(IntegerTimedState.TYPE)) {
|
|
||||||
IntegerTimedState timedState = new IntegerTimedState(timedStateElem);
|
|
||||||
addTimedState(timedState);
|
|
||||||
} else if (typeS.equals(BooleanTimedState.TYPE)) {
|
|
||||||
BooleanTimedState timedState = new BooleanTimedState(timedStateElem);
|
|
||||||
addTimedState(timedState);
|
|
||||||
} else if (typeS.equals(StringSetTimedState.TYPE)) {
|
|
||||||
StringSetTimedState timedState = new StringSetTimedState(timedStateElem);
|
|
||||||
addTimedState(timedState);
|
|
||||||
} else {
|
|
||||||
String msg = "What kind of TimedState is this: {0}"; //$NON-NLS-1$
|
|
||||||
msg = MessageFormat.format(msg, typeS);
|
|
||||||
throw new StrolchException(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void addTimedState(StrolchTimedState<?> strolchTimedState) {
|
public void addTimedState(StrolchTimedState<?> strolchTimedState) {
|
||||||
if (this.timedStateMap == null) {
|
if (this.timedStateMap == null) {
|
||||||
|
@ -150,22 +103,6 @@ public class Resource extends GroupedParameterizedElement implements StrolchRoot
|
||||||
return this.timedStateMap != null && this.timedStateMap.containsKey(id);
|
return this.timedStateMap != null && this.timedStateMap.containsKey(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Element toDom(Document doc) {
|
|
||||||
|
|
||||||
Element element = doc.createElement(Tags.RESOURCE);
|
|
||||||
fillElement(element);
|
|
||||||
|
|
||||||
if (this.timedStateMap != null) {
|
|
||||||
for (StrolchTimedState<?> state : this.timedStateMap.values()) {
|
|
||||||
Element timedStateElem = state.toDom(element.getOwnerDocument());
|
|
||||||
element.appendChild(timedStateElem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Resource getClone() {
|
public Resource getClone() {
|
||||||
Resource clone = new Resource();
|
Resource clone = new Resource();
|
||||||
|
|
|
@ -17,9 +17,6 @@ package li.strolch.model;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
|
@ -76,17 +73,6 @@ public interface StrolchElement extends Serializable, Comparable<StrolchElement>
|
||||||
*/
|
*/
|
||||||
public long getDbid();
|
public long getDbid();
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an {@link Element} object which is an XML representation of this object
|
|
||||||
*
|
|
||||||
* @param doc
|
|
||||||
* the document to which this element is being written. The client must not append to the document, the
|
|
||||||
* caller will perform this as needed
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public Element toDom(Document doc);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the type of this {@link StrolchElement}
|
* Returns the type of this {@link StrolchElement}
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,374 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package li.strolch.model;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
import li.strolch.model.parameter.BooleanParameter;
|
||||||
|
import li.strolch.model.parameter.DateParameter;
|
||||||
|
import li.strolch.model.parameter.DurationParameter;
|
||||||
|
import li.strolch.model.parameter.FloatListParameter;
|
||||||
|
import li.strolch.model.parameter.FloatParameter;
|
||||||
|
import li.strolch.model.parameter.IntegerListParameter;
|
||||||
|
import li.strolch.model.parameter.IntegerParameter;
|
||||||
|
import li.strolch.model.parameter.LongListParameter;
|
||||||
|
import li.strolch.model.parameter.LongParameter;
|
||||||
|
import li.strolch.model.parameter.Parameter;
|
||||||
|
import li.strolch.model.parameter.StringListParameter;
|
||||||
|
import li.strolch.model.parameter.StringParameter;
|
||||||
|
import li.strolch.model.timedstate.BooleanTimedState;
|
||||||
|
import li.strolch.model.timedstate.FloatTimedState;
|
||||||
|
import li.strolch.model.timedstate.IntegerTimedState;
|
||||||
|
import li.strolch.model.timedstate.StringSetTimedState;
|
||||||
|
import li.strolch.model.timedstate.StrolchTimedState;
|
||||||
|
import li.strolch.model.timedstate.TimedState;
|
||||||
|
import li.strolch.model.timevalue.IValue;
|
||||||
|
import li.strolch.model.timevalue.IValueChange;
|
||||||
|
import li.strolch.model.timevalue.impl.BooleanValue;
|
||||||
|
import li.strolch.model.timevalue.impl.FloatValue;
|
||||||
|
import li.strolch.model.timevalue.impl.IntegerValue;
|
||||||
|
import li.strolch.model.timevalue.impl.StringSetValue;
|
||||||
|
|
||||||
|
public enum StrolchValueType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can be used for:<br />
|
||||||
|
* <ul>
|
||||||
|
* <li>{@link Parameter}</li>
|
||||||
|
* <li>{@link TimedState}</li>
|
||||||
|
* <li>{@link IValue}</li>
|
||||||
|
* <li>{@link IValueChange}</li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
BOOLEAN("Boolean") {
|
||||||
|
@Override
|
||||||
|
public Parameter<?> parameterInstance() {
|
||||||
|
return new BooleanParameter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StrolchTimedState<? extends IValue<?>> timedStateInstance() {
|
||||||
|
return new BooleanTimedState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IValue<?> valueInstance(String valueAsString) {
|
||||||
|
return new BooleanValue(valueAsString);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can be used for:<br />
|
||||||
|
* <ul>
|
||||||
|
* <li>{@link Parameter}</li>
|
||||||
|
* <li>{@link TimedState}</li>
|
||||||
|
* <li>{@link IValue}</li>
|
||||||
|
* <li>{@link IValueChange}</li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
INTEGER("Integer") {
|
||||||
|
@Override
|
||||||
|
public Parameter<?> parameterInstance() {
|
||||||
|
return new IntegerParameter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StrolchTimedState<? extends IValue<?>> timedStateInstance() {
|
||||||
|
return new IntegerTimedState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IValue<?> valueInstance(String valueAsString) {
|
||||||
|
return new IntegerValue(valueAsString);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can be used for:<br />
|
||||||
|
* <ul>
|
||||||
|
* <li>{@link Parameter}</li>
|
||||||
|
* <li>{@link TimedState}</li>
|
||||||
|
* <li>{@link IValue}</li>
|
||||||
|
* <li>{@link IValueChange}</li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
FLOAT("Float") {
|
||||||
|
@Override
|
||||||
|
public Parameter<?> parameterInstance() {
|
||||||
|
return new FloatParameter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StrolchTimedState<? extends IValue<?>> timedStateInstance() {
|
||||||
|
return new FloatTimedState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IValue<?> valueInstance(String valueAsString) {
|
||||||
|
return new FloatValue(valueAsString);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can be used for:<br />
|
||||||
|
* <ul>
|
||||||
|
* <li>{@link Parameter}</li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
LONG("Long") {
|
||||||
|
@Override
|
||||||
|
public Parameter<?> parameterInstance() {
|
||||||
|
return new LongParameter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StrolchTimedState<? extends IValue<?>> timedStateInstance() {
|
||||||
|
throw new UnsupportedOperationException(MessageFormat.format(
|
||||||
|
"TimeStates of type {0} are not supported!", getType())); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IValue<?> valueInstance(String valueAsString) {
|
||||||
|
throw new UnsupportedOperationException(MessageFormat.format(
|
||||||
|
"Parameters of type {0} are not supported!", getType())); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can be used for:<br />
|
||||||
|
* <ul>
|
||||||
|
* <li>{@link Parameter}</li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
STRING("String") {
|
||||||
|
@Override
|
||||||
|
public Parameter<?> parameterInstance() {
|
||||||
|
return new StringParameter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StrolchTimedState<? extends IValue<?>> timedStateInstance() {
|
||||||
|
throw new UnsupportedOperationException(MessageFormat.format(
|
||||||
|
"TimeStates of type {0} are not supported!", getType())); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IValue<?> valueInstance(String valueAsString) {
|
||||||
|
throw new UnsupportedOperationException(MessageFormat.format(
|
||||||
|
"Parameters of type {0} are not supported!", getType())); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can be used for:<br />
|
||||||
|
* <ul>
|
||||||
|
* <li>{@link Parameter}</li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
DATE("Date") {
|
||||||
|
@Override
|
||||||
|
public Parameter<?> parameterInstance() {
|
||||||
|
return new DateParameter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StrolchTimedState<? extends IValue<?>> timedStateInstance() {
|
||||||
|
throw new UnsupportedOperationException(MessageFormat.format(
|
||||||
|
"TimeStates of type {0} are not supported!", getType())); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IValue<?> valueInstance(String valueAsString) {
|
||||||
|
throw new UnsupportedOperationException(MessageFormat.format(
|
||||||
|
"Parameters of type {0} are not supported!", getType())); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can be used for:<br />
|
||||||
|
* <ul>
|
||||||
|
* <li>{@link Parameter}</li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
DURATION("Duration") {
|
||||||
|
@Override
|
||||||
|
public Parameter<?> parameterInstance() {
|
||||||
|
return new DurationParameter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StrolchTimedState<? extends IValue<?>> timedStateInstance() {
|
||||||
|
throw new UnsupportedOperationException(MessageFormat.format(
|
||||||
|
"TimeStates of type {0} are not supported!", getType())); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IValue<?> valueInstance(String valueAsString) {
|
||||||
|
throw new UnsupportedOperationException(MessageFormat.format(
|
||||||
|
"Parameters of type {0} are not supported!", getType())); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can be used for:<br />
|
||||||
|
* <ul>
|
||||||
|
* <li>{@link Parameter}</li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
FLOAT_LIST("FloatList") {
|
||||||
|
@Override
|
||||||
|
public Parameter<?> parameterInstance() {
|
||||||
|
return new FloatListParameter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StrolchTimedState<? extends IValue<?>> timedStateInstance() {
|
||||||
|
throw new UnsupportedOperationException(MessageFormat.format(
|
||||||
|
"TimeStates of type {0} are not supported!", getType())); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IValue<?> valueInstance(String valueAsString) {
|
||||||
|
throw new UnsupportedOperationException(MessageFormat.format(
|
||||||
|
"Parameters of type {0} are not supported!", getType())); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can be used for:<br />
|
||||||
|
* <ul>
|
||||||
|
* <li>{@link Parameter}</li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
INTEGER_LIST("IntegerList") {
|
||||||
|
@Override
|
||||||
|
public Parameter<?> parameterInstance() {
|
||||||
|
return new IntegerListParameter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StrolchTimedState<? extends IValue<?>> timedStateInstance() {
|
||||||
|
throw new UnsupportedOperationException(MessageFormat.format(
|
||||||
|
"TimeStates of type {0} are not supported!", getType())); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IValue<?> valueInstance(String valueAsString) {
|
||||||
|
throw new UnsupportedOperationException(MessageFormat.format(
|
||||||
|
"Parameters of type {0} are not supported!", getType())); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can be used for:<br />
|
||||||
|
* <ul>
|
||||||
|
* <li>{@link Parameter}</li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
LONG_LIST("LongList") {
|
||||||
|
@Override
|
||||||
|
public Parameter<?> parameterInstance() {
|
||||||
|
return new LongListParameter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StrolchTimedState<? extends IValue<?>> timedStateInstance() {
|
||||||
|
throw new UnsupportedOperationException(MessageFormat.format(
|
||||||
|
"TimeStates of type {0} are not supported!", getType())); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IValue<?> valueInstance(String valueAsString) {
|
||||||
|
throw new UnsupportedOperationException(MessageFormat.format(
|
||||||
|
"Parameters of type {0} are not supported!", getType())); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can be used for:<br />
|
||||||
|
* <ul>
|
||||||
|
* <li>{@link Parameter}</li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
STRING_LIST("StringList") {
|
||||||
|
@Override
|
||||||
|
public Parameter<?> parameterInstance() {
|
||||||
|
return new StringListParameter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StrolchTimedState<? extends IValue<?>> timedStateInstance() {
|
||||||
|
throw new UnsupportedOperationException(MessageFormat.format(
|
||||||
|
"TimeStates of type {0} are not supported!", getType())); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IValue<?> valueInstance(String valueAsString) {
|
||||||
|
throw new UnsupportedOperationException(MessageFormat.format(
|
||||||
|
"Values of type {0} are not supported!", getType())); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can be used for:<br />
|
||||||
|
* <ul>
|
||||||
|
* <li>{@link TimedState}</li>
|
||||||
|
* <li>{@link IValue}</li>
|
||||||
|
* <li>{@link IValueChange}</li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
STRING_SET("StringSet") {
|
||||||
|
@Override
|
||||||
|
public Parameter<?> parameterInstance() {
|
||||||
|
throw new UnsupportedOperationException(MessageFormat.format(
|
||||||
|
"Parameters of type {0} are not supported!", getType())); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StrolchTimedState<? extends IValue<?>> timedStateInstance() {
|
||||||
|
return new StringSetTimedState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IValue<?> valueInstance(String valueAsString) {
|
||||||
|
return new StringSetValue(valueAsString);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
private StrolchValueType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return this.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StrolchValueType parse(String value) {
|
||||||
|
for (StrolchValueType type : StrolchValueType.values()) {
|
||||||
|
if (type.type.equals(value))
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("Type " + value + " does not exist!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Parameter<?> parameterInstance();
|
||||||
|
|
||||||
|
public abstract StrolchTimedState<? extends IValue<?>> timedStateInstance();
|
||||||
|
|
||||||
|
public abstract IValue<?> valueInstance(String valueAsString);
|
||||||
|
}
|
|
@ -47,13 +47,11 @@ public class Tags {
|
||||||
public static final String START = "Start";
|
public static final String START = "Start";
|
||||||
public static final String END = "End";
|
public static final String END = "End";
|
||||||
public static final String VALUE_CHANGE = "ValueChange";
|
public static final String VALUE_CHANGE = "ValueChange";
|
||||||
public static final String VALUE_CLASS = "Class";
|
|
||||||
public static final String RESOURCE_ID = "ResourceId";
|
public static final String RESOURCE_ID = "ResourceId";
|
||||||
public static final String RESOURCE_TYPE = "ResourceType";
|
public static final String RESOURCE_TYPE = "ResourceType";
|
||||||
public static final String STATE_ID = "StateId";
|
public static final String STATE_ID = "StateId";
|
||||||
|
|
||||||
|
public static class Audit {
|
||||||
public class Audit {
|
|
||||||
public static final String ID = Tags.ID;
|
public static final String ID = Tags.ID;
|
||||||
|
|
||||||
public static final String USERNAME = "Username";
|
public static final String USERNAME = "Username";
|
||||||
|
|
|
@ -18,6 +18,8 @@ package li.strolch.model.activity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import li.strolch.model.GroupedParameterizedElement;
|
import li.strolch.model.GroupedParameterizedElement;
|
||||||
|
@ -27,17 +29,13 @@ import li.strolch.model.Resource;
|
||||||
import li.strolch.model.State;
|
import li.strolch.model.State;
|
||||||
import li.strolch.model.StrolchElement;
|
import li.strolch.model.StrolchElement;
|
||||||
import li.strolch.model.StrolchRootElement;
|
import li.strolch.model.StrolchRootElement;
|
||||||
import li.strolch.model.Tags;
|
import li.strolch.model.timevalue.IValue;
|
||||||
import li.strolch.model.timevalue.IValueChange;
|
import li.strolch.model.timevalue.IValueChange;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link Action} represents a single step within an {@link Activity}, that
|
* An {@link Action} represents a single step within an {@link Activity}, that is, one that is not further decomposed
|
||||||
* is, one that is not further decomposed within the {@link Activity}. A
|
* within the {@link Activity}. A {@link Activity} applies {@link IValueChange} objects at the start and end time of the
|
||||||
* {@link Activity} applies {@link IValueChange} objects at the start and end
|
* {@link Activity}.
|
||||||
* time of the {@link Activity}.
|
|
||||||
*
|
*
|
||||||
* @author Martin Smock <martin.smock@bluewin.ch>
|
* @author Martin Smock <martin.smock@bluewin.ch>
|
||||||
*/
|
*/
|
||||||
|
@ -46,13 +44,20 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
|
||||||
protected static final long serialVersionUID = 1L;
|
protected static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
protected Activity parent;
|
protected Activity parent;
|
||||||
protected String resourceId, resourceType;
|
protected String resourceId;
|
||||||
protected State state = State.CREATED;
|
protected String resourceType;
|
||||||
|
protected State state;
|
||||||
|
|
||||||
protected final List<IValueChange<?>> changes = new ArrayList<>();
|
protected List<IValueChange<? extends IValue<?>>> changes;
|
||||||
|
|
||||||
public Action(String id, String name, String type) {
|
public Action(String id, String name, String type) {
|
||||||
super(id, name, type);
|
super(id, name, type);
|
||||||
|
this.state = State.CREATED;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initChanges() {
|
||||||
|
if (this.changes == null)
|
||||||
|
this.changes = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,8 +91,7 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the type of the <code>Resource</code> this <code>Action</code>
|
* @return the type of the <code>Resource</code> this <code>Action</code> acts on
|
||||||
* acts on
|
|
||||||
*/
|
*/
|
||||||
public String getResourceType() {
|
public String getResourceType() {
|
||||||
return this.resourceType;
|
return this.resourceType;
|
||||||
|
@ -100,25 +104,41 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
|
||||||
this.resourceType = resourceType;
|
this.resourceType = resourceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if this {@link Action} contains any {@link IValueChange changes}, false if not
|
||||||
|
*
|
||||||
|
* @return true if this {@link Action} contains any {@link IValueChange changes}, false if not
|
||||||
|
*/
|
||||||
|
public boolean hasChanges() {
|
||||||
|
return this.changes != null && !this.changes.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param add
|
* @param add
|
||||||
* <code>IValueChange</code> to be applied to the
|
* <code>IValueChange</code> to be applied to the <code>Resource</code>
|
||||||
* <code>Resource</code>
|
|
||||||
*
|
*
|
||||||
* @return <tt>true</tt> (as specified by {@link Collection#add})
|
* @return <tt>true</tt> (as specified by {@link Collection#add})
|
||||||
*/
|
*/
|
||||||
public boolean addChange(IValueChange<?> change) {
|
public boolean addChange(IValueChange<? extends IValue<?>> change) {
|
||||||
|
initChanges();
|
||||||
return changes.add(change);
|
return changes.add(change);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the list of <code>IValueChange</code> attached to the
|
* @return the list of <code>IValueChange</code> attached to the <code>Action</code> start
|
||||||
* <code>Action</code> start
|
|
||||||
*/
|
*/
|
||||||
public List<IValueChange<?>> getChanges() {
|
public List<IValueChange<? extends IValue<?>>> getChanges() {
|
||||||
|
if (this.changes == null)
|
||||||
|
return Collections.emptyList();
|
||||||
return changes;
|
return changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Iterator<IValueChange<? extends IValue<?>>> changesIterator() {
|
||||||
|
if (this.changes == null)
|
||||||
|
return Collections.<IValueChange<? extends IValue<?>>> emptyList().iterator();
|
||||||
|
return this.changes.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StrolchElement getParent() {
|
public StrolchElement getParent() {
|
||||||
return parent;
|
return parent;
|
||||||
|
@ -135,14 +155,16 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StrolchElement getClone() {
|
public Action getClone() {
|
||||||
Action clone = new Action(getId(), getName(), getType());
|
Action clone = new Action(getId(), getName(), getType());
|
||||||
clone.setDbid(getDbid());
|
clone.setDbid(getDbid());
|
||||||
clone.setResourceId(resourceId);
|
clone.setResourceId(resourceId);
|
||||||
clone.setResourceType(resourceType);
|
clone.setResourceType(resourceType);
|
||||||
clone.setState(state);
|
clone.setState(state);
|
||||||
for (IValueChange<?> change : getChanges()) {
|
if (this.changes != null) {
|
||||||
clone.changes.add(change.getClone());
|
for (IValueChange<? extends IValue<?>> change : getChanges()) {
|
||||||
|
clone.addChange(change.getClone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
@ -185,6 +207,8 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
|
||||||
@Override
|
@Override
|
||||||
public Long getStart() {
|
public Long getStart() {
|
||||||
Long start = Long.MAX_VALUE;
|
Long start = Long.MAX_VALUE;
|
||||||
|
if (this.changes == null)
|
||||||
|
return start;
|
||||||
for (IValueChange<?> change : changes) {
|
for (IValueChange<?> change : changes) {
|
||||||
start = Math.min(start, change.getTime());
|
start = Math.min(start, change.getTime());
|
||||||
}
|
}
|
||||||
|
@ -194,23 +218,11 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
|
||||||
@Override
|
@Override
|
||||||
public Long getEnd() {
|
public Long getEnd() {
|
||||||
Long end = 0L;
|
Long end = 0L;
|
||||||
|
if (this.changes == null)
|
||||||
|
return end;
|
||||||
for (IValueChange<?> change : changes) {
|
for (IValueChange<?> change : changes) {
|
||||||
end = Math.max(end, change.getTime());
|
end = Math.max(end, change.getTime());
|
||||||
}
|
}
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Element toDom(Document doc) {
|
|
||||||
Element element = doc.createElement(Tags.ACTION);
|
|
||||||
fillElement(element);
|
|
||||||
element.setAttribute(Tags.STATE, this.state.toString());
|
|
||||||
element.setAttribute(Tags.RESOURCE_ID, this.resourceId);
|
|
||||||
element.setAttribute(Tags.RESOURCE_TYPE, this.resourceType);
|
|
||||||
for (IValueChange<?> change : changes) {
|
|
||||||
element.appendChild(change.toDom(doc));
|
|
||||||
}
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model.activity;
|
package li.strolch.model.activity;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -30,12 +31,9 @@ import li.strolch.model.StrolchRootElement;
|
||||||
import li.strolch.model.Tags;
|
import li.strolch.model.Tags;
|
||||||
import li.strolch.model.visitor.StrolchRootElementVisitor;
|
import li.strolch.model.visitor.StrolchRootElementVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameterized object grouping a collection of {@link Activity} and
|
* Parameterized object grouping a collection of {@link Activity} and {@link Action} objects defining the process to be
|
||||||
* {@link Action} objects defining the process to be scheduled
|
* scheduled
|
||||||
*
|
*
|
||||||
* @author Martin Smock <martin.smock@bluewin.ch>
|
* @author Martin Smock <martin.smock@bluewin.ch>
|
||||||
*/
|
*/
|
||||||
|
@ -45,27 +43,37 @@ public class Activity extends GroupedParameterizedElement implements IActivityEl
|
||||||
|
|
||||||
protected Activity parent;
|
protected Activity parent;
|
||||||
|
|
||||||
|
protected Map<String, IActivityElement> elements;
|
||||||
|
|
||||||
public Activity(String id, String name, String type) {
|
public Activity(String id, String name, String type) {
|
||||||
super(id, name, type);
|
super(id, name, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// use a LinkedHashMap since we will iterate elements in the order added and
|
private void initElements() {
|
||||||
// lookup elements by ID
|
if (this.elements == null) {
|
||||||
protected Map<String, IActivityElement> elements = new LinkedHashMap<String, IActivityElement>();
|
// use a LinkedHashMap since we will iterate elements in the order added and lookup elements by ID
|
||||||
|
elements = new LinkedHashMap<String, IActivityElement>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasElements() {
|
||||||
|
return this.elements != null && !this.elements.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add an activity element to the <code>LinkedHashMap</code> of
|
* add an activity element to the <code>LinkedHashMap</code> of <code>IActivityElements</code>
|
||||||
* <code>IActivityElements</code>
|
|
||||||
*
|
*
|
||||||
* @param activityElement
|
* @param activityElement
|
||||||
* @return the element added
|
* @return the element added
|
||||||
*/
|
*/
|
||||||
public IActivityElement addElement(IActivityElement activityElement) {
|
public IActivityElement addElement(IActivityElement activityElement) {
|
||||||
|
initElements();
|
||||||
String id = activityElement.getId();
|
String id = activityElement.getId();
|
||||||
if (id == null)
|
if (id == null)
|
||||||
throw new StrolchException("Cannot add IActivityElement without id.");
|
throw new StrolchException("Cannot add IActivityElement without id.");
|
||||||
else if (elements.containsKey(id))
|
else if (elements.containsKey(id))
|
||||||
throw new StrolchException("Activiy " + getLocator() + " already contains an activity element with id = " + id);
|
throw new StrolchException("Activiy " + getLocator() + " already contains an activity element with id = "
|
||||||
|
+ id);
|
||||||
else {
|
else {
|
||||||
activityElement.setParent(this);
|
activityElement.setParent(this);
|
||||||
return elements.put(activityElement.getId(), activityElement);
|
return elements.put(activityElement.getId(), activityElement);
|
||||||
|
@ -80,27 +88,33 @@ public class Activity extends GroupedParameterizedElement implements IActivityEl
|
||||||
* @return IActivityElement
|
* @return IActivityElement
|
||||||
*/
|
*/
|
||||||
public IActivityElement getElement(String id) {
|
public IActivityElement getElement(String id) {
|
||||||
|
if (this.elements == null)
|
||||||
|
return null;
|
||||||
return elements.get(id);
|
return elements.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return get the <code>LinkedHashMap</code> of
|
* @return get the <code>LinkedHashMap</code> of <code>IActivityElements</code>
|
||||||
* <code>IActivityElements</code>
|
|
||||||
*/
|
*/
|
||||||
public Map<String, IActivityElement> getElements() {
|
public Map<String, IActivityElement> getElements() {
|
||||||
|
if (this.elements == null)
|
||||||
|
return Collections.emptyMap();
|
||||||
return elements;
|
return elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the iterator for entries, which include the id as key and the
|
* @return the iterator for entries, which include the id as key and the {@link IActivityElement} as value
|
||||||
* {@link IActivityElement} as value
|
|
||||||
*/
|
*/
|
||||||
public Iterator<Entry<String, IActivityElement>> elementIterator() {
|
public Iterator<Entry<String, IActivityElement>> elementIterator() {
|
||||||
|
if (this.elements == null)
|
||||||
|
return Collections.<String, IActivityElement> emptyMap().entrySet().iterator();
|
||||||
return elements.entrySet().iterator();
|
return elements.entrySet().iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getStart() {
|
public Long getStart() {
|
||||||
Long start = Long.MAX_VALUE;
|
Long start = Long.MAX_VALUE;
|
||||||
|
if (this.elements == null)
|
||||||
|
return start;
|
||||||
Iterator<Entry<String, IActivityElement>> elementIterator = elementIterator();
|
Iterator<Entry<String, IActivityElement>> elementIterator = elementIterator();
|
||||||
while (elementIterator.hasNext()) {
|
while (elementIterator.hasNext()) {
|
||||||
IActivityElement action = elementIterator.next().getValue();
|
IActivityElement action = elementIterator.next().getValue();
|
||||||
|
@ -111,6 +125,8 @@ public class Activity extends GroupedParameterizedElement implements IActivityEl
|
||||||
|
|
||||||
public Long getEnd() {
|
public Long getEnd() {
|
||||||
Long end = 0L;
|
Long end = 0L;
|
||||||
|
if (this.elements == null)
|
||||||
|
return end;
|
||||||
Iterator<Entry<String, IActivityElement>> elementIterator = elementIterator();
|
Iterator<Entry<String, IActivityElement>> elementIterator = elementIterator();
|
||||||
while (elementIterator.hasNext()) {
|
while (elementIterator.hasNext()) {
|
||||||
IActivityElement action = elementIterator.next().getValue();
|
IActivityElement action = elementIterator.next().getValue();
|
||||||
|
@ -121,6 +137,8 @@ public class Activity extends GroupedParameterizedElement implements IActivityEl
|
||||||
|
|
||||||
public State getState() {
|
public State getState() {
|
||||||
State state = State.PLANNED;
|
State state = State.PLANNED;
|
||||||
|
if (this.elements == null)
|
||||||
|
return state;
|
||||||
Iterator<Entry<String, IActivityElement>> elementIterator = elementIterator();
|
Iterator<Entry<String, IActivityElement>> elementIterator = elementIterator();
|
||||||
while (elementIterator.hasNext()) {
|
while (elementIterator.hasNext()) {
|
||||||
IActivityElement child = elementIterator.next().getValue();
|
IActivityElement child = elementIterator.next().getValue();
|
||||||
|
@ -144,18 +162,6 @@ public class Activity extends GroupedParameterizedElement implements IActivityEl
|
||||||
locatorBuilder.append(Tags.ACTIVITY).append(getType()).append(getId());
|
locatorBuilder.append(Tags.ACTIVITY).append(getType()).append(getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Element toDom(Document doc) {
|
|
||||||
Element element = doc.createElement(Tags.ACTIVITY);
|
|
||||||
fillElement(element);
|
|
||||||
Iterator<Entry<String, IActivityElement>> elementIterator = elementIterator();
|
|
||||||
while (elementIterator.hasNext()) {
|
|
||||||
IActivityElement activityElement = elementIterator.next().getValue();
|
|
||||||
element.appendChild(activityElement.toDom(doc));
|
|
||||||
}
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StrolchElement getParent() {
|
public StrolchElement getParent() {
|
||||||
return parent;
|
return parent;
|
||||||
|
@ -172,12 +178,12 @@ public class Activity extends GroupedParameterizedElement implements IActivityEl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StrolchElement getClone() {
|
public Activity getClone() {
|
||||||
Activity clone = new Activity(id, name, type);
|
Activity clone = new Activity(id, name, type);
|
||||||
Iterator<Entry<String, IActivityElement>> elementIterator = elementIterator();
|
if (this.elements == null)
|
||||||
while (elementIterator.hasNext()) {
|
return clone;
|
||||||
Entry<String, IActivityElement> next = elementIterator.next();
|
for (IActivityElement element : this.elements.values()) {
|
||||||
clone.elements.put(next.getKey(), (IActivityElement) next.getValue().getClone());
|
clone.addElement(element.getClone());
|
||||||
}
|
}
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
@ -210,5 +216,4 @@ public class Activity extends GroupedParameterizedElement implements IActivityEl
|
||||||
public void setParent(Activity activity) {
|
public void setParent(Activity activity) {
|
||||||
this.parent = activity;
|
this.parent = activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,16 +22,16 @@ import li.strolch.model.StrolchElement;
|
||||||
* Marker for all child elements of {@link Activity} objects
|
* Marker for all child elements of {@link Activity} objects
|
||||||
*
|
*
|
||||||
* @author Martin Smock <martin.smock@bluewin.ch>
|
* @author Martin Smock <martin.smock@bluewin.ch>
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface IActivityElement extends StrolchElement {
|
public interface IActivityElement extends StrolchElement {
|
||||||
|
|
||||||
Long getStart();
|
public Long getStart();
|
||||||
|
|
||||||
Long getEnd();
|
public Long getEnd();
|
||||||
|
|
||||||
State getState();
|
public State getState();
|
||||||
|
|
||||||
void setParent(Activity activity);
|
public void setParent(Activity activity);
|
||||||
|
|
||||||
|
public IActivityElement getClone();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,12 +26,7 @@ import li.strolch.model.Locator;
|
||||||
import li.strolch.model.Locator.LocatorBuilder;
|
import li.strolch.model.Locator.LocatorBuilder;
|
||||||
import li.strolch.model.ParameterizedElement;
|
import li.strolch.model.ParameterizedElement;
|
||||||
import li.strolch.model.StrolchRootElement;
|
import li.strolch.model.StrolchRootElement;
|
||||||
import li.strolch.model.Tags;
|
|
||||||
import li.strolch.model.visitor.ParameterVisitor;
|
import li.strolch.model.visitor.ParameterVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
import ch.eitchnet.utils.helper.StringHelper;
|
import ch.eitchnet.utils.helper.StringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -135,74 +130,6 @@ public abstract class AbstractParameter<T> extends AbstractStrolchElement implem
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Element toDom(Document doc) {
|
|
||||||
Element element = doc.createElement(Tags.PARAMETER);
|
|
||||||
fillElement(element);
|
|
||||||
|
|
||||||
element.setAttribute(Tags.VALUE, getValueAsString());
|
|
||||||
|
|
||||||
if (!this.interpretation.equals(INTERPRETATION_NONE)) {
|
|
||||||
element.setAttribute(Tags.INTERPRETATION, this.interpretation);
|
|
||||||
}
|
|
||||||
if (!this.uom.equals(UOM_NONE)) {
|
|
||||||
element.setAttribute(Tags.UOM, this.uom);
|
|
||||||
}
|
|
||||||
if (this.hidden) {
|
|
||||||
element.setAttribute(Tags.HIDDEN, Boolean.toString(this.hidden));
|
|
||||||
}
|
|
||||||
if (this.index != 0) {
|
|
||||||
element.setAttribute(Tags.INDEX, Integer.toString(this.index));
|
|
||||||
}
|
|
||||||
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fromDom(Element element) {
|
|
||||||
|
|
||||||
super.fromDom(element);
|
|
||||||
|
|
||||||
String typeS = element.getAttribute(Tags.TYPE);
|
|
||||||
if (StringHelper.isEmpty(typeS)) {
|
|
||||||
String msg = "Type must be set on element with id {0}"; //$NON-NLS-1$
|
|
||||||
msg = MessageFormat.format(msg, this.id);
|
|
||||||
throw new StrolchException(msg);
|
|
||||||
} else if (!typeS.equals(getType())) {
|
|
||||||
String msg = "{0} must have type {1}, not: {2}"; //$NON-NLS-1$
|
|
||||||
msg = MessageFormat.format(msg, getClass().getSimpleName(), getType(), typeS);
|
|
||||||
throw new StrolchException(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
String interpretation = element.getAttribute(Tags.INTERPRETATION);
|
|
||||||
String hidden = element.getAttribute(Tags.HIDDEN);
|
|
||||||
String uom = element.getAttribute(Tags.UOM);
|
|
||||||
String index = element.getAttribute(Tags.INDEX);
|
|
||||||
|
|
||||||
setInterpretation(interpretation);
|
|
||||||
setUom(uom);
|
|
||||||
|
|
||||||
if (StringHelper.isEmpty(index)) {
|
|
||||||
this.index = 0;
|
|
||||||
} else {
|
|
||||||
this.index = Integer.valueOf(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (StringHelper.isEmpty(hidden)) {
|
|
||||||
setHidden(false);
|
|
||||||
} else {
|
|
||||||
if (hidden.equalsIgnoreCase(Boolean.TRUE.toString())) {
|
|
||||||
setHidden(true);
|
|
||||||
} else if (hidden.equalsIgnoreCase(Boolean.FALSE.toString())) {
|
|
||||||
setHidden(false);
|
|
||||||
} else {
|
|
||||||
String msg = "Boolean string must be either {0} or {1}"; //$NON-NLS-1$
|
|
||||||
msg = MessageFormat.format(msg, Boolean.TRUE.toString(), Boolean.FALSE.toString());
|
|
||||||
throw new StrolchException(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void fillLocator(LocatorBuilder lb) {
|
protected void fillLocator(LocatorBuilder lb) {
|
||||||
lb.append(this.id);
|
lb.append(this.id);
|
||||||
|
|
|
@ -15,14 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model.parameter;
|
package li.strolch.model.parameter;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import li.strolch.model.StrolchValueType;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
|
||||||
import li.strolch.model.Tags;
|
|
||||||
import li.strolch.model.visitor.ParameterVisitor;
|
import li.strolch.model.visitor.ParameterVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
import ch.eitchnet.utils.helper.StringHelper;
|
import ch.eitchnet.utils.helper.StringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,7 +24,6 @@ import ch.eitchnet.utils.helper.StringHelper;
|
||||||
*/
|
*/
|
||||||
public class BooleanParameter extends AbstractParameter<Boolean> {
|
public class BooleanParameter extends AbstractParameter<Boolean> {
|
||||||
|
|
||||||
public static final String TYPE = "Boolean"; //$NON-NLS-1$
|
|
||||||
private static final long serialVersionUID = 0L;
|
private static final long serialVersionUID = 0L;
|
||||||
|
|
||||||
private Boolean value = Boolean.FALSE;
|
private Boolean value = Boolean.FALSE;
|
||||||
|
@ -54,23 +47,6 @@ public class BooleanParameter extends AbstractParameter<Boolean> {
|
||||||
setValue(value);
|
setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* DOM Constructor
|
|
||||||
*
|
|
||||||
* @param element
|
|
||||||
*/
|
|
||||||
public BooleanParameter(Element element) {
|
|
||||||
super.fromDom(element);
|
|
||||||
|
|
||||||
String valueS = element.getAttribute(Tags.VALUE);
|
|
||||||
if (StringHelper.isEmpty(valueS)) {
|
|
||||||
String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
|
|
||||||
throw new StrolchException(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
setValue(parseFromString(valueS));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValueAsString() {
|
public String getValueAsString() {
|
||||||
return this.value.toString();
|
return this.value.toString();
|
||||||
|
@ -87,9 +63,14 @@ public class BooleanParameter extends AbstractParameter<Boolean> {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValueFromString(String valueAsString) {
|
||||||
|
setValue(parseFromString(valueAsString));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return BooleanParameter.TYPE;
|
return StrolchValueType.BOOLEAN.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,16 +15,10 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model.parameter;
|
package li.strolch.model.parameter;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.model.StrolchValueType;
|
||||||
import li.strolch.model.Tags;
|
|
||||||
import li.strolch.model.visitor.ParameterVisitor;
|
import li.strolch.model.visitor.ParameterVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
import ch.eitchnet.utils.helper.StringHelper;
|
|
||||||
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
|
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,7 +26,6 @@ import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
|
||||||
*/
|
*/
|
||||||
public class DateParameter extends AbstractParameter<Date> {
|
public class DateParameter extends AbstractParameter<Date> {
|
||||||
|
|
||||||
public static final String TYPE = "Date"; //$NON-NLS-1$
|
|
||||||
private static final long serialVersionUID = 0L;
|
private static final long serialVersionUID = 0L;
|
||||||
|
|
||||||
private Date value;
|
private Date value;
|
||||||
|
@ -56,23 +49,6 @@ public class DateParameter extends AbstractParameter<Date> {
|
||||||
setValue(value);
|
setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* DOM Constructor
|
|
||||||
*
|
|
||||||
* @param element
|
|
||||||
*/
|
|
||||||
public DateParameter(Element element) {
|
|
||||||
super.fromDom(element);
|
|
||||||
|
|
||||||
String valueS = element.getAttribute(Tags.VALUE);
|
|
||||||
if (StringHelper.isEmpty(valueS)) {
|
|
||||||
String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
|
|
||||||
throw new StrolchException(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
setValue(parseFromString(valueS));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValueAsString() {
|
public String getValueAsString() {
|
||||||
return ISO8601FormatFactory.getInstance().formatDate(this.value);
|
return ISO8601FormatFactory.getInstance().formatDate(this.value);
|
||||||
|
@ -89,9 +65,14 @@ public class DateParameter extends AbstractParameter<Date> {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValueFromString(String valueAsString) {
|
||||||
|
setValue(parseFromString(valueAsString));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return DateParameter.TYPE;
|
return StrolchValueType.DATE.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,15 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model.parameter;
|
package li.strolch.model.parameter;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import li.strolch.model.StrolchValueType;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
|
||||||
import li.strolch.model.Tags;
|
|
||||||
import li.strolch.model.visitor.ParameterVisitor;
|
import li.strolch.model.visitor.ParameterVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
import ch.eitchnet.utils.helper.StringHelper;
|
|
||||||
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
|
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,7 +24,6 @@ import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
|
||||||
*/
|
*/
|
||||||
public class DurationParameter extends AbstractParameter<Long> {
|
public class DurationParameter extends AbstractParameter<Long> {
|
||||||
|
|
||||||
public static final String TYPE = "Duration"; //$NON-NLS-1$
|
|
||||||
private static final long serialVersionUID = 0L;
|
private static final long serialVersionUID = 0L;
|
||||||
|
|
||||||
private Long value;
|
private Long value;
|
||||||
|
@ -55,23 +47,6 @@ public class DurationParameter extends AbstractParameter<Long> {
|
||||||
setValue(value);
|
setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* DOM Constructor
|
|
||||||
*
|
|
||||||
* @param element
|
|
||||||
*/
|
|
||||||
public DurationParameter(Element element) {
|
|
||||||
super.fromDom(element);
|
|
||||||
|
|
||||||
String valueS = element.getAttribute(Tags.VALUE);
|
|
||||||
if (StringHelper.isEmpty(valueS)) {
|
|
||||||
String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
|
|
||||||
throw new StrolchException(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
setValue(parseFromString(valueS));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValueAsString() {
|
public String getValueAsString() {
|
||||||
return ISO8601FormatFactory.getInstance().formatDuration(this.value);
|
return ISO8601FormatFactory.getInstance().formatDuration(this.value);
|
||||||
|
@ -88,9 +63,14 @@ public class DurationParameter extends AbstractParameter<Long> {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValueFromString(String valueAsString) {
|
||||||
|
setValue(parseFromString(valueAsString));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return DurationParameter.TYPE;
|
return StrolchValueType.DURATION.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,18 +15,13 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model.parameter;
|
package li.strolch.model.parameter;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.model.StrolchValueType;
|
||||||
import li.strolch.model.Tags;
|
|
||||||
import li.strolch.model.visitor.ParameterVisitor;
|
import li.strolch.model.visitor.ParameterVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
import ch.eitchnet.utils.helper.StringHelper;
|
import ch.eitchnet.utils.helper.StringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,7 +29,6 @@ import ch.eitchnet.utils.helper.StringHelper;
|
||||||
*/
|
*/
|
||||||
public class FloatListParameter extends AbstractParameter<List<Double>> implements ListParameter<Double> {
|
public class FloatListParameter extends AbstractParameter<List<Double>> implements ListParameter<Double> {
|
||||||
|
|
||||||
public static final String TYPE = "FloatList"; //$NON-NLS-1$
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
protected List<Double> value;
|
protected List<Double> value;
|
||||||
|
@ -59,23 +53,6 @@ public class FloatListParameter extends AbstractParameter<List<Double>> implemen
|
||||||
setValue(value);
|
setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* DOM Constructor
|
|
||||||
*
|
|
||||||
* @param element
|
|
||||||
*/
|
|
||||||
public FloatListParameter(Element element) {
|
|
||||||
super.fromDom(element);
|
|
||||||
|
|
||||||
String valueS = element.getAttribute(Tags.VALUE);
|
|
||||||
if (StringHelper.isEmpty(valueS)) {
|
|
||||||
String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
|
|
||||||
throw new StrolchException(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
setValue(parseFromString(valueS));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValueAsString() {
|
public String getValueAsString() {
|
||||||
if (this.value.isEmpty()) {
|
if (this.value.isEmpty()) {
|
||||||
|
@ -111,6 +88,11 @@ public class FloatListParameter extends AbstractParameter<List<Double>> implemen
|
||||||
this.value.addAll(value);
|
this.value.addAll(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValueFromString(String valueAsString) {
|
||||||
|
setValue(parseFromString(valueAsString));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addValue(Double value) {
|
public void addValue(Double value) {
|
||||||
this.value.add(value);
|
this.value.add(value);
|
||||||
|
@ -133,7 +115,7 @@ public class FloatListParameter extends AbstractParameter<List<Double>> implemen
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return TYPE;
|
return StrolchValueType.FLOAT_LIST.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,23 +15,15 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model.parameter;
|
package li.strolch.model.parameter;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import li.strolch.model.StrolchValueType;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
|
||||||
import li.strolch.model.Tags;
|
|
||||||
import li.strolch.model.visitor.ParameterVisitor;
|
import li.strolch.model.visitor.ParameterVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
import ch.eitchnet.utils.helper.StringHelper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class FloatParameter extends AbstractParameter<Double> {
|
public class FloatParameter extends AbstractParameter<Double> {
|
||||||
|
|
||||||
public static final String TYPE = "Float"; //$NON-NLS-1$
|
|
||||||
private static final long serialVersionUID = 0L;
|
private static final long serialVersionUID = 0L;
|
||||||
|
|
||||||
private Double value = Double.MAX_VALUE;
|
private Double value = Double.MAX_VALUE;
|
||||||
|
@ -56,23 +48,6 @@ public class FloatParameter extends AbstractParameter<Double> {
|
||||||
setValue(value);
|
setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* DOM Constructor
|
|
||||||
*
|
|
||||||
* @param element
|
|
||||||
*/
|
|
||||||
public FloatParameter(Element element) {
|
|
||||||
super.fromDom(element);
|
|
||||||
|
|
||||||
String valueS = element.getAttribute(Tags.VALUE);
|
|
||||||
if (StringHelper.isEmpty(valueS)) {
|
|
||||||
String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
|
|
||||||
throw new StrolchException(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
setValue(parseFromString(valueS));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValueAsString() {
|
public String getValueAsString() {
|
||||||
return Double.toString(this.value);
|
return Double.toString(this.value);
|
||||||
|
@ -89,9 +64,14 @@ public class FloatParameter extends AbstractParameter<Double> {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValueFromString(String valueAsString) {
|
||||||
|
setValue(parseFromString(valueAsString));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return FloatParameter.TYPE;
|
return StrolchValueType.FLOAT.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,18 +15,13 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model.parameter;
|
package li.strolch.model.parameter;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.model.StrolchValueType;
|
||||||
import li.strolch.model.Tags;
|
|
||||||
import li.strolch.model.visitor.ParameterVisitor;
|
import li.strolch.model.visitor.ParameterVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
import ch.eitchnet.utils.helper.StringHelper;
|
import ch.eitchnet.utils.helper.StringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,7 +29,6 @@ import ch.eitchnet.utils.helper.StringHelper;
|
||||||
*/
|
*/
|
||||||
public class IntegerListParameter extends AbstractParameter<List<Integer>> implements ListParameter<Integer> {
|
public class IntegerListParameter extends AbstractParameter<List<Integer>> implements ListParameter<Integer> {
|
||||||
|
|
||||||
public static final String TYPE = "IntegerList"; //$NON-NLS-1$
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
protected List<Integer> value;
|
protected List<Integer> value;
|
||||||
|
@ -59,23 +53,6 @@ public class IntegerListParameter extends AbstractParameter<List<Integer>> imple
|
||||||
setValue(value);
|
setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* DOM Constructor
|
|
||||||
*
|
|
||||||
* @param element
|
|
||||||
*/
|
|
||||||
public IntegerListParameter(Element element) {
|
|
||||||
super.fromDom(element);
|
|
||||||
|
|
||||||
String valueS = element.getAttribute(Tags.VALUE);
|
|
||||||
if (StringHelper.isEmpty(valueS)) {
|
|
||||||
String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
|
|
||||||
throw new StrolchException(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
setValue(parseFromString(valueS));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValueAsString() {
|
public String getValueAsString() {
|
||||||
if (this.value.isEmpty()) {
|
if (this.value.isEmpty()) {
|
||||||
|
@ -111,6 +88,11 @@ public class IntegerListParameter extends AbstractParameter<List<Integer>> imple
|
||||||
this.value.addAll(value);
|
this.value.addAll(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValueFromString(String valueAsString) {
|
||||||
|
setValue(parseFromString(valueAsString));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addValue(Integer value) {
|
public void addValue(Integer value) {
|
||||||
this.value.add(value);
|
this.value.add(value);
|
||||||
|
@ -133,7 +115,7 @@ public class IntegerListParameter extends AbstractParameter<List<Integer>> imple
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return TYPE;
|
return StrolchValueType.INTEGER_LIST.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,23 +15,15 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model.parameter;
|
package li.strolch.model.parameter;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import li.strolch.model.StrolchValueType;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
|
||||||
import li.strolch.model.Tags;
|
|
||||||
import li.strolch.model.visitor.ParameterVisitor;
|
import li.strolch.model.visitor.ParameterVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
import ch.eitchnet.utils.helper.StringHelper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class IntegerParameter extends AbstractParameter<Integer> {
|
public class IntegerParameter extends AbstractParameter<Integer> {
|
||||||
|
|
||||||
public static final String TYPE = "Integer"; //$NON-NLS-1$
|
|
||||||
private static final long serialVersionUID = 0L;
|
private static final long serialVersionUID = 0L;
|
||||||
|
|
||||||
private Integer value = Integer.MAX_VALUE;
|
private Integer value = Integer.MAX_VALUE;
|
||||||
|
@ -55,26 +47,9 @@ public class IntegerParameter extends AbstractParameter<Integer> {
|
||||||
setValue(value);
|
setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* DOM Constructor
|
|
||||||
*
|
|
||||||
* @param element
|
|
||||||
*/
|
|
||||||
public IntegerParameter(Element element) {
|
|
||||||
super.fromDom(element);
|
|
||||||
|
|
||||||
String valueS = element.getAttribute(Tags.VALUE);
|
|
||||||
if (StringHelper.isEmpty(valueS)) {
|
|
||||||
String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
|
|
||||||
throw new StrolchException(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
setValue(parseFromString(valueS));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return IntegerParameter.TYPE;
|
return StrolchValueType.INTEGER.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -93,6 +68,11 @@ public class IntegerParameter extends AbstractParameter<Integer> {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValueFromString(String valueAsString) {
|
||||||
|
setValue(parseFromString(valueAsString));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IntegerParameter getClone() {
|
public IntegerParameter getClone() {
|
||||||
IntegerParameter clone = new IntegerParameter();
|
IntegerParameter clone = new IntegerParameter();
|
||||||
|
|
|
@ -15,18 +15,13 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model.parameter;
|
package li.strolch.model.parameter;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.model.StrolchValueType;
|
||||||
import li.strolch.model.Tags;
|
|
||||||
import li.strolch.model.visitor.ParameterVisitor;
|
import li.strolch.model.visitor.ParameterVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
import ch.eitchnet.utils.helper.StringHelper;
|
import ch.eitchnet.utils.helper.StringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,7 +29,6 @@ import ch.eitchnet.utils.helper.StringHelper;
|
||||||
*/
|
*/
|
||||||
public class LongListParameter extends AbstractParameter<List<Long>> implements ListParameter<Long> {
|
public class LongListParameter extends AbstractParameter<List<Long>> implements ListParameter<Long> {
|
||||||
|
|
||||||
public static final String TYPE = "LongList"; //$NON-NLS-1$
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
protected List<Long> value;
|
protected List<Long> value;
|
||||||
|
@ -59,23 +53,6 @@ public class LongListParameter extends AbstractParameter<List<Long>> implements
|
||||||
setValue(value);
|
setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* DOM Constructor
|
|
||||||
*
|
|
||||||
* @param element
|
|
||||||
*/
|
|
||||||
public LongListParameter(Element element) {
|
|
||||||
super.fromDom(element);
|
|
||||||
|
|
||||||
String valueS = element.getAttribute(Tags.VALUE);
|
|
||||||
if (StringHelper.isEmpty(valueS)) {
|
|
||||||
String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
|
|
||||||
throw new StrolchException(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
setValue(parseFromString(valueS));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValueAsString() {
|
public String getValueAsString() {
|
||||||
if (this.value.isEmpty()) {
|
if (this.value.isEmpty()) {
|
||||||
|
@ -111,6 +88,11 @@ public class LongListParameter extends AbstractParameter<List<Long>> implements
|
||||||
this.value.addAll(value);
|
this.value.addAll(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValueFromString(String valueAsString) {
|
||||||
|
setValue(parseFromString(valueAsString));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addValue(Long value) {
|
public void addValue(Long value) {
|
||||||
this.value.add(value);
|
this.value.add(value);
|
||||||
|
@ -133,7 +115,7 @@ public class LongListParameter extends AbstractParameter<List<Long>> implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return TYPE;
|
return StrolchValueType.LONG_LIST.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,23 +15,15 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model.parameter;
|
package li.strolch.model.parameter;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import li.strolch.model.StrolchValueType;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
|
||||||
import li.strolch.model.Tags;
|
|
||||||
import li.strolch.model.visitor.ParameterVisitor;
|
import li.strolch.model.visitor.ParameterVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
import ch.eitchnet.utils.helper.StringHelper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class LongParameter extends AbstractParameter<Long> {
|
public class LongParameter extends AbstractParameter<Long> {
|
||||||
|
|
||||||
public static final String TYPE = "Long"; //$NON-NLS-1$
|
|
||||||
private static final long serialVersionUID = 0L;
|
private static final long serialVersionUID = 0L;
|
||||||
|
|
||||||
protected Long value;
|
protected Long value;
|
||||||
|
@ -55,23 +47,6 @@ public class LongParameter extends AbstractParameter<Long> {
|
||||||
setValue(value);
|
setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* DOM Constructor
|
|
||||||
*
|
|
||||||
* @param element
|
|
||||||
*/
|
|
||||||
public LongParameter(Element element) {
|
|
||||||
super.fromDom(element);
|
|
||||||
|
|
||||||
String valueS = element.getAttribute(Tags.VALUE);
|
|
||||||
if (StringHelper.isEmpty(valueS)) {
|
|
||||||
String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
|
|
||||||
throw new StrolchException(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
setValue(parseFromString(valueS));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValueAsString() {
|
public String getValueAsString() {
|
||||||
return this.value.toString();
|
return this.value.toString();
|
||||||
|
@ -88,9 +63,14 @@ public class LongParameter extends AbstractParameter<Long> {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValueFromString(String valueAsString) {
|
||||||
|
setValue(parseFromString(valueAsString));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return LongParameter.TYPE;
|
return StrolchValueType.LONG.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -26,12 +26,20 @@ import li.strolch.model.visitor.ParameterVisitor;
|
||||||
public interface Parameter<T> extends StrolchElement {
|
public interface Parameter<T> extends StrolchElement {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the value of the parameter as string
|
* Returns the value of the parameter as string
|
||||||
*
|
*
|
||||||
* @return String
|
* @return the value as string
|
||||||
*/
|
*/
|
||||||
public String getValueAsString();
|
public String getValueAsString();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the value of the parameter from a string
|
||||||
|
*
|
||||||
|
* @param valueAsString
|
||||||
|
* the string from which to set the value
|
||||||
|
*/
|
||||||
|
public void setValueFromString(String valueAsString);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the value of the parameter
|
* the value of the parameter
|
||||||
*
|
*
|
||||||
|
|
|
@ -15,18 +15,13 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model.parameter;
|
package li.strolch.model.parameter;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.model.StrolchValueType;
|
||||||
import li.strolch.model.Tags;
|
|
||||||
import li.strolch.model.visitor.ParameterVisitor;
|
import li.strolch.model.visitor.ParameterVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
import ch.eitchnet.utils.helper.StringHelper;
|
import ch.eitchnet.utils.helper.StringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,7 +29,6 @@ import ch.eitchnet.utils.helper.StringHelper;
|
||||||
*/
|
*/
|
||||||
public class StringListParameter extends AbstractParameter<List<String>> implements ListParameter<String> {
|
public class StringListParameter extends AbstractParameter<List<String>> implements ListParameter<String> {
|
||||||
|
|
||||||
public static final String TYPE = "StringList"; //$NON-NLS-1$
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
protected List<String> value;
|
protected List<String> value;
|
||||||
|
@ -59,23 +53,6 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
|
||||||
setValue(value);
|
setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* DOM Constructor
|
|
||||||
*
|
|
||||||
* @param element
|
|
||||||
*/
|
|
||||||
public StringListParameter(Element element) {
|
|
||||||
super.fromDom(element);
|
|
||||||
|
|
||||||
String valueS = element.getAttribute(Tags.VALUE);
|
|
||||||
if (StringHelper.isEmpty(valueS)) {
|
|
||||||
String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
|
|
||||||
throw new StrolchException(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
setValue(parseFromString(valueS));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValueAsString() {
|
public String getValueAsString() {
|
||||||
if (this.value.isEmpty()) {
|
if (this.value.isEmpty()) {
|
||||||
|
@ -111,6 +88,11 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
|
||||||
this.value.addAll(value);
|
this.value.addAll(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValueFromString(String valueAsString) {
|
||||||
|
setValue(parseFromString(valueAsString));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addValue(String value) {
|
public void addValue(String value) {
|
||||||
this.value.add(value);
|
this.value.add(value);
|
||||||
|
@ -133,7 +115,7 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return TYPE;
|
return StrolchValueType.STRING_LIST.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,16 +15,9 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model.parameter;
|
package li.strolch.model.parameter;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import li.strolch.model.StrolchValueType;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
|
||||||
import li.strolch.model.Tags;
|
|
||||||
import li.strolch.model.visitor.ParameterVisitor;
|
import li.strolch.model.visitor.ParameterVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
import ch.eitchnet.utils.helper.StringHelper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*
|
*
|
||||||
|
@ -32,7 +25,6 @@ import ch.eitchnet.utils.helper.StringHelper;
|
||||||
public class StringParameter extends AbstractParameter<String> {
|
public class StringParameter extends AbstractParameter<String> {
|
||||||
|
|
||||||
public static final String UNDEFINED_VALUE = "-"; //$NON-NLS-1$
|
public static final String UNDEFINED_VALUE = "-"; //$NON-NLS-1$
|
||||||
public static final String TYPE = "String"; //$NON-NLS-1$
|
|
||||||
private static final long serialVersionUID = 0L;
|
private static final long serialVersionUID = 0L;
|
||||||
|
|
||||||
private String value = UNDEFINED_VALUE;
|
private String value = UNDEFINED_VALUE;
|
||||||
|
@ -57,26 +49,9 @@ public class StringParameter extends AbstractParameter<String> {
|
||||||
setValue(value);
|
setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* DOM Constructor
|
|
||||||
*
|
|
||||||
* @param element
|
|
||||||
*/
|
|
||||||
public StringParameter(Element element) {
|
|
||||||
super.fromDom(element);
|
|
||||||
|
|
||||||
String valueS = element.getAttribute(Tags.VALUE);
|
|
||||||
if (StringHelper.isEmpty(valueS)) {
|
|
||||||
String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
|
|
||||||
throw new StrolchException(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
setValue(valueS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return StringParameter.TYPE;
|
return StrolchValueType.STRING.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -95,6 +70,11 @@ public class StringParameter extends AbstractParameter<String> {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValueFromString(String valueAsString) {
|
||||||
|
setValue(valueAsString);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StringParameter getClone() {
|
public StringParameter getClone() {
|
||||||
StringParameter clone = new StringParameter();
|
StringParameter clone = new StringParameter();
|
||||||
|
|
|
@ -17,10 +17,6 @@ package li.strolch.model.timedstate;
|
||||||
|
|
||||||
import static li.strolch.model.StrolchModelConstants.INTERPRETATION_NONE;
|
import static li.strolch.model.StrolchModelConstants.INTERPRETATION_NONE;
|
||||||
import static li.strolch.model.StrolchModelConstants.UOM_NONE;
|
import static li.strolch.model.StrolchModelConstants.UOM_NONE;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
|
||||||
import li.strolch.model.AbstractStrolchElement;
|
import li.strolch.model.AbstractStrolchElement;
|
||||||
import li.strolch.model.Locator;
|
import li.strolch.model.Locator;
|
||||||
import li.strolch.model.Locator.LocatorBuilder;
|
import li.strolch.model.Locator.LocatorBuilder;
|
||||||
|
@ -33,10 +29,6 @@ import li.strolch.model.timevalue.ITimeVariable;
|
||||||
import li.strolch.model.timevalue.IValue;
|
import li.strolch.model.timevalue.IValue;
|
||||||
import li.strolch.model.timevalue.IValueChange;
|
import li.strolch.model.timevalue.IValueChange;
|
||||||
import li.strolch.model.visitor.TimedStateVisitor;
|
import li.strolch.model.visitor.TimedStateVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
import ch.eitchnet.utils.helper.StringHelper;
|
import ch.eitchnet.utils.helper.StringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -160,72 +152,6 @@ public abstract class AbstractStrolchTimedState<T extends IValue> extends Abstra
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Element toDom(Document doc) {
|
|
||||||
Element element = doc.createElement(Tags.PARAMETER);
|
|
||||||
fillElement(element);
|
|
||||||
|
|
||||||
if (!this.interpretation.equals(INTERPRETATION_NONE)) {
|
|
||||||
element.setAttribute(Tags.INTERPRETATION, this.interpretation);
|
|
||||||
}
|
|
||||||
if (!this.uom.equals(UOM_NONE)) {
|
|
||||||
element.setAttribute(Tags.UOM, this.uom);
|
|
||||||
}
|
|
||||||
if (this.hidden) {
|
|
||||||
element.setAttribute(Tags.HIDDEN, Boolean.toString(this.hidden));
|
|
||||||
}
|
|
||||||
if (this.index != 0) {
|
|
||||||
element.setAttribute(Tags.INDEX, Integer.toString(this.index));
|
|
||||||
}
|
|
||||||
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fromDom(Element element) {
|
|
||||||
|
|
||||||
super.fromDom(element);
|
|
||||||
|
|
||||||
String typeS = element.getAttribute(Tags.TYPE);
|
|
||||||
if (StringHelper.isEmpty(typeS)) {
|
|
||||||
String msg = "Type must be set on element with id {0}"; //$NON-NLS-1$
|
|
||||||
msg = MessageFormat.format(msg, this.id);
|
|
||||||
throw new StrolchException(msg);
|
|
||||||
} else if (!typeS.equals(getType())) {
|
|
||||||
String msg = "{0} must have type {1}, not: {2}"; //$NON-NLS-1$
|
|
||||||
msg = MessageFormat.format(msg, getClass().getSimpleName(), getType(), typeS);
|
|
||||||
throw new StrolchException(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
String interpretation = element.getAttribute(Tags.INTERPRETATION);
|
|
||||||
String hidden = element.getAttribute(Tags.HIDDEN);
|
|
||||||
String uom = element.getAttribute(Tags.UOM);
|
|
||||||
String index = element.getAttribute(Tags.INDEX);
|
|
||||||
|
|
||||||
setInterpretation(interpretation);
|
|
||||||
setUom(uom);
|
|
||||||
|
|
||||||
if (StringHelper.isEmpty(index)) {
|
|
||||||
this.index = 0;
|
|
||||||
} else {
|
|
||||||
this.index = Integer.valueOf(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (StringHelper.isEmpty(hidden)) {
|
|
||||||
setHidden(false);
|
|
||||||
} else {
|
|
||||||
if (hidden.equalsIgnoreCase(Boolean.TRUE.toString())) {
|
|
||||||
setHidden(true);
|
|
||||||
} else if (hidden.equalsIgnoreCase(Boolean.FALSE.toString())) {
|
|
||||||
setHidden(false);
|
|
||||||
} else {
|
|
||||||
String msg = "Boolean string must be either {0} or {1}"; //$NON-NLS-1$
|
|
||||||
msg = MessageFormat.format(msg, Boolean.TRUE.toString(), Boolean.FALSE.toString());
|
|
||||||
throw new StrolchException(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void fillLocator(LocatorBuilder lb) {
|
protected void fillLocator(LocatorBuilder lb) {
|
||||||
lb.append(Tags.STATE);
|
lb.append(Tags.STATE);
|
||||||
|
|
|
@ -15,19 +15,9 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model.timedstate;
|
package li.strolch.model.timedstate;
|
||||||
|
|
||||||
import java.util.Date;
|
import li.strolch.model.StrolchValueType;
|
||||||
import java.util.SortedSet;
|
|
||||||
|
|
||||||
import li.strolch.model.Tags;
|
|
||||||
import li.strolch.model.timevalue.ITimeValue;
|
|
||||||
import li.strolch.model.timevalue.impl.BooleanValue;
|
import li.strolch.model.timevalue.impl.BooleanValue;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
|
@ -35,8 +25,6 @@ public class BooleanTimedState extends AbstractStrolchTimedState<BooleanValue> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public static final String TYPE = "BooleanState";
|
|
||||||
|
|
||||||
public BooleanTimedState() {
|
public BooleanTimedState() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
@ -45,45 +33,14 @@ public class BooleanTimedState extends AbstractStrolchTimedState<BooleanValue> {
|
||||||
super(id, name);
|
super(id, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BooleanTimedState(Element element) {
|
|
||||||
super.fromDom(element);
|
|
||||||
|
|
||||||
this.state = new TimedState<>();
|
|
||||||
|
|
||||||
NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE);
|
|
||||||
for (int i = 0; i < timeValueElems.getLength(); i++) {
|
|
||||||
Element timeValueElem = (Element) timeValueElems.item(i);
|
|
||||||
String timeS = timeValueElem.getAttribute(Tags.TIME);
|
|
||||||
Date date = ISO8601FormatFactory.getInstance().parseDate(timeS);
|
|
||||||
long time = date.getTime();
|
|
||||||
|
|
||||||
Boolean value = Boolean.valueOf(timeValueElem.getAttribute(Tags.VALUE));
|
|
||||||
BooleanValue booleanValue = new BooleanValue(value);
|
|
||||||
this.state.getTimeEvolution().setValueAt(time, booleanValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Element toDom(Document doc) {
|
public void setStateFromStringAt(Long time, String value) {
|
||||||
|
getTimeEvolution().setValueAt(time, new BooleanValue(value));
|
||||||
Element stateElement = doc.createElement(Tags.TIMED_STATE);
|
|
||||||
super.fillElement(stateElement);
|
|
||||||
SortedSet<ITimeValue<BooleanValue>> values = this.state.getTimeEvolution().getValues();
|
|
||||||
for (ITimeValue<BooleanValue> timeValue : values) {
|
|
||||||
Long time = timeValue.getTime();
|
|
||||||
BooleanValue value = timeValue.getValue();
|
|
||||||
Element valueElem = doc.createElement(Tags.VALUE);
|
|
||||||
valueElem.setAttribute(Tags.TIME, ISO8601FormatFactory.getInstance().formatDate(time));
|
|
||||||
valueElem.setAttribute(Tags.VALUE, value.getValue().toString());
|
|
||||||
stateElement.appendChild(valueElem);
|
|
||||||
}
|
|
||||||
|
|
||||||
return stateElement;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return TYPE;
|
return StrolchValueType.BOOLEAN.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,19 +15,9 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model.timedstate;
|
package li.strolch.model.timedstate;
|
||||||
|
|
||||||
import java.util.Date;
|
import li.strolch.model.StrolchValueType;
|
||||||
import java.util.SortedSet;
|
|
||||||
|
|
||||||
import li.strolch.model.Tags;
|
|
||||||
import li.strolch.model.timevalue.ITimeValue;
|
|
||||||
import li.strolch.model.timevalue.impl.FloatValue;
|
import li.strolch.model.timevalue.impl.FloatValue;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
|
@ -35,8 +25,6 @@ public class FloatTimedState extends AbstractStrolchTimedState<FloatValue> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public static final String TYPE = "FloatState";
|
|
||||||
|
|
||||||
public FloatTimedState() {
|
public FloatTimedState() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
@ -45,45 +33,14 @@ public class FloatTimedState extends AbstractStrolchTimedState<FloatValue> {
|
||||||
super(id, name);
|
super(id, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FloatTimedState(Element element) {
|
|
||||||
super.fromDom(element);
|
|
||||||
|
|
||||||
this.state = new TimedState<>();
|
|
||||||
|
|
||||||
NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE);
|
|
||||||
for (int i = 0; i < timeValueElems.getLength(); i++) {
|
|
||||||
Element timeValueElem = (Element) timeValueElems.item(i);
|
|
||||||
String timeS = timeValueElem.getAttribute(Tags.TIME);
|
|
||||||
Date date = ISO8601FormatFactory.getInstance().parseDate(timeS);
|
|
||||||
long time = date.getTime();
|
|
||||||
|
|
||||||
Double value = Double.valueOf(timeValueElem.getAttribute(Tags.VALUE));
|
|
||||||
FloatValue floatValue = new FloatValue(value);
|
|
||||||
this.state.getTimeEvolution().setValueAt(time, floatValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Element toDom(Document doc) {
|
public void setStateFromStringAt(Long time, String value) {
|
||||||
|
getTimeEvolution().setValueAt(time, new FloatValue(value));
|
||||||
Element stateElement = doc.createElement(Tags.TIMED_STATE);
|
|
||||||
super.fillElement(stateElement);
|
|
||||||
SortedSet<ITimeValue<FloatValue>> values = this.state.getTimeEvolution().getValues();
|
|
||||||
for (ITimeValue<FloatValue> timeValue : values) {
|
|
||||||
Long time = timeValue.getTime();
|
|
||||||
FloatValue value = timeValue.getValue();
|
|
||||||
Element valueElem = doc.createElement(Tags.VALUE);
|
|
||||||
valueElem.setAttribute(Tags.TIME, ISO8601FormatFactory.getInstance().formatDate(time));
|
|
||||||
valueElem.setAttribute(Tags.VALUE, value.getValue().toString());
|
|
||||||
stateElement.appendChild(valueElem);
|
|
||||||
}
|
|
||||||
|
|
||||||
return stateElement;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return TYPE;
|
return StrolchValueType.FLOAT.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,19 +15,9 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model.timedstate;
|
package li.strolch.model.timedstate;
|
||||||
|
|
||||||
import java.util.Date;
|
import li.strolch.model.StrolchValueType;
|
||||||
import java.util.SortedSet;
|
|
||||||
|
|
||||||
import li.strolch.model.Tags;
|
|
||||||
import li.strolch.model.timevalue.ITimeValue;
|
|
||||||
import li.strolch.model.timevalue.impl.IntegerValue;
|
import li.strolch.model.timevalue.impl.IntegerValue;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
|
@ -35,8 +25,6 @@ public class IntegerTimedState extends AbstractStrolchTimedState<IntegerValue> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public static final String TYPE = "IntegerState";
|
|
||||||
|
|
||||||
public IntegerTimedState() {
|
public IntegerTimedState() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
@ -45,45 +33,14 @@ public class IntegerTimedState extends AbstractStrolchTimedState<IntegerValue> {
|
||||||
super(id, name);
|
super(id, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IntegerTimedState(Element element) {
|
|
||||||
super.fromDom(element);
|
|
||||||
|
|
||||||
this.state = new TimedState<>();
|
|
||||||
|
|
||||||
NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE);
|
|
||||||
for (int i = 0; i < timeValueElems.getLength(); i++) {
|
|
||||||
Element timeValueElem = (Element) timeValueElems.item(i);
|
|
||||||
String timeS = timeValueElem.getAttribute(Tags.TIME);
|
|
||||||
Date date = ISO8601FormatFactory.getInstance().parseDate(timeS);
|
|
||||||
long time = date.getTime();
|
|
||||||
|
|
||||||
Integer value = Integer.valueOf(timeValueElem.getAttribute(Tags.VALUE));
|
|
||||||
IntegerValue integerValue = new IntegerValue(value);
|
|
||||||
this.state.getTimeEvolution().setValueAt(time, integerValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Element toDom(Document doc) {
|
public void setStateFromStringAt(Long time, String value) {
|
||||||
|
getTimeEvolution().setValueAt(time, new IntegerValue(value));
|
||||||
Element stateElement = doc.createElement(Tags.TIMED_STATE);
|
|
||||||
super.fillElement(stateElement);
|
|
||||||
SortedSet<ITimeValue<IntegerValue>> values = this.state.getTimeEvolution().getValues();
|
|
||||||
for (ITimeValue<IntegerValue> timeValue : values) {
|
|
||||||
Long time = timeValue.getTime();
|
|
||||||
IntegerValue value = timeValue.getValue();
|
|
||||||
Element valueElem = doc.createElement(Tags.VALUE);
|
|
||||||
valueElem.setAttribute(Tags.TIME, ISO8601FormatFactory.getInstance().formatDate(time));
|
|
||||||
valueElem.setAttribute(Tags.VALUE, value.getValue().toString());
|
|
||||||
stateElement.appendChild(valueElem);
|
|
||||||
}
|
|
||||||
|
|
||||||
return stateElement;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return TYPE;
|
return StrolchValueType.INTEGER.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,23 +15,9 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model.timedstate;
|
package li.strolch.model.timedstate;
|
||||||
|
|
||||||
import java.util.Date;
|
import li.strolch.model.StrolchValueType;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.SortedSet;
|
|
||||||
|
|
||||||
import li.strolch.model.Tags;
|
|
||||||
import li.strolch.model.timevalue.ITimeValue;
|
|
||||||
import li.strolch.model.timevalue.impl.AString;
|
|
||||||
import li.strolch.model.timevalue.impl.StringSetValue;
|
import li.strolch.model.timevalue.impl.StringSetValue;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
|
@ -39,8 +25,6 @@ public class StringSetTimedState extends AbstractStrolchTimedState<StringSetValu
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public static final String TYPE = "StringSetState";
|
|
||||||
|
|
||||||
public StringSetTimedState() {
|
public StringSetTimedState() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
@ -49,63 +33,14 @@ public class StringSetTimedState extends AbstractStrolchTimedState<StringSetValu
|
||||||
super(id, name);
|
super(id, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringSetTimedState(Element element) {
|
|
||||||
super.fromDom(element);
|
|
||||||
|
|
||||||
this.state = new TimedState<>();
|
|
||||||
|
|
||||||
NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE);
|
|
||||||
for (int i = 0; i < timeValueElems.getLength(); i++) {
|
|
||||||
Element timeValueElem = (Element) timeValueElems.item(i);
|
|
||||||
String timeS = timeValueElem.getAttribute(Tags.TIME);
|
|
||||||
Date date = ISO8601FormatFactory.getInstance().parseDate(timeS);
|
|
||||||
long time = date.getTime();
|
|
||||||
|
|
||||||
String valueAsString = timeValueElem.getAttribute(Tags.VALUE);
|
|
||||||
Set<AString> value = new HashSet<>();
|
|
||||||
String[] values = valueAsString.split(",");
|
|
||||||
for (String s : values) {
|
|
||||||
value.add(new AString(s.trim()));
|
|
||||||
}
|
|
||||||
|
|
||||||
StringSetValue integerValue = new StringSetValue(value);
|
|
||||||
this.state.getTimeEvolution().setValueAt(time, integerValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Element toDom(Document doc) {
|
public void setStateFromStringAt(Long time, String value) {
|
||||||
|
getTimeEvolution().setValueAt(time, new StringSetValue(value));
|
||||||
Element stateElement = doc.createElement(Tags.TIMED_STATE);
|
|
||||||
super.fillElement(stateElement);
|
|
||||||
SortedSet<ITimeValue<StringSetValue>> values = this.state.getTimeEvolution().getValues();
|
|
||||||
for (ITimeValue<StringSetValue> timeValue : values) {
|
|
||||||
Long time = timeValue.getTime();
|
|
||||||
StringSetValue stringSetValue = timeValue.getValue();
|
|
||||||
|
|
||||||
Set<AString> value = stringSetValue.getValue();
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
Iterator<AString> iter = value.iterator();
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
sb.append(iter.next().getString());
|
|
||||||
if (iter.hasNext()) {
|
|
||||||
sb.append(", ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String valueAsString = sb.toString();
|
|
||||||
|
|
||||||
Element valueElem = doc.createElement(Tags.VALUE);
|
|
||||||
valueElem.setAttribute(Tags.TIME, ISO8601FormatFactory.getInstance().formatDate(time));
|
|
||||||
valueElem.setAttribute(Tags.VALUE, valueAsString);
|
|
||||||
stateElement.appendChild(valueElem);
|
|
||||||
}
|
|
||||||
|
|
||||||
return stateElement;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return TYPE;
|
return StrolchValueType.STRING_SET.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -108,6 +108,16 @@ public interface StrolchTimedState<T extends IValue> extends StrolchElement {
|
||||||
|
|
||||||
public ITimeValue<T> getStateAt(Long time);
|
public ITimeValue<T> getStateAt(Long time);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the value at a point in time to a given time value object from a string value
|
||||||
|
*
|
||||||
|
* @param time
|
||||||
|
* the time to set the {@link IValue}
|
||||||
|
* @param value
|
||||||
|
* the string to parse to an {@link IValue}
|
||||||
|
*/
|
||||||
|
void setStateFromStringAt(final Long time, final String value);
|
||||||
|
|
||||||
public ITimeVariable<T> getTimeEvolution();
|
public ITimeVariable<T> getTimeEvolution();
|
||||||
|
|
||||||
public void setParent(Resource aThis);
|
public void setParent(Resource aThis);
|
||||||
|
|
|
@ -26,6 +26,11 @@ package li.strolch.model.timevalue;
|
||||||
*/
|
*/
|
||||||
public interface IValue<T> {
|
public interface IValue<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the type of this {@link IValue}
|
||||||
|
*/
|
||||||
|
String getType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the backing value
|
* @return the backing value
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -18,12 +18,9 @@ package li.strolch.model.timevalue;
|
||||||
import li.strolch.model.timedstate.AbstractStrolchTimedState;
|
import li.strolch.model.timedstate.AbstractStrolchTimedState;
|
||||||
import li.strolch.model.timevalue.impl.TimeVariable;
|
import li.strolch.model.timevalue.impl.TimeVariable;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for operators to be used to change the values of {@link ITimeValue}
|
* Interface for operators to be used to change the values of {@link ITimeValue} in a {@link ITimeVariable} or
|
||||||
* in a {@link ITimeVariable} or {@link AbstractStrolchTimedState}.
|
* {@link AbstractStrolchTimedState}.
|
||||||
*
|
*
|
||||||
* @author Martin Smock <smock.martin@gmail.com>
|
* @author Martin Smock <smock.martin@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
@ -31,15 +28,13 @@ import org.w3c.dom.Element;
|
||||||
public interface IValueChange<T extends IValue> {
|
public interface IValueChange<T extends IValue> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the id of the {@link AbstractStrolchTimedState} the change
|
* @return the id of the {@link AbstractStrolchTimedState} the change applies to
|
||||||
* applies to
|
|
||||||
*/
|
*/
|
||||||
String getStateId();
|
String getStateId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param id
|
* @param id
|
||||||
* the id of the {@link AbstractStrolchTimedState} the change
|
* the id of the {@link AbstractStrolchTimedState} the change applies to
|
||||||
* applies to
|
|
||||||
*/
|
*/
|
||||||
void setStateId(String id);
|
void setStateId(String id);
|
||||||
|
|
||||||
|
@ -58,8 +53,7 @@ public interface IValueChange<T extends IValue> {
|
||||||
void setValue(T value);
|
void setValue(T value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the inverse neutralizing a change. Very useful to undo changes
|
* @return the inverse neutralizing a change. Very useful to undo changes made to a {@link TimeVariable}.
|
||||||
* made to a {@link TimeVariable}.
|
|
||||||
*/
|
*/
|
||||||
IValueChange<T> getInverse();
|
IValueChange<T> getInverse();
|
||||||
|
|
||||||
|
@ -67,11 +61,4 @@ public interface IValueChange<T extends IValue> {
|
||||||
* @return a copy of this
|
* @return a copy of this
|
||||||
*/
|
*/
|
||||||
IValueChange<T> getClone();
|
IValueChange<T> getClone();
|
||||||
|
|
||||||
/**
|
|
||||||
* @param doc
|
|
||||||
* @return a xml serialisation of this
|
|
||||||
*/
|
|
||||||
Element toDom(Document doc);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ package li.strolch.model.timevalue.impl;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import li.strolch.model.StrolchValueType;
|
||||||
import li.strolch.model.timevalue.ITimeValue;
|
import li.strolch.model.timevalue.ITimeValue;
|
||||||
import li.strolch.model.timevalue.IValue;
|
import li.strolch.model.timevalue.IValue;
|
||||||
|
|
||||||
|
@ -45,6 +46,11 @@ public class BooleanValue implements IValue<Boolean>, Serializable {
|
||||||
this.value = Boolean.parseBoolean(valueAsString);
|
this.value = Boolean.parseBoolean(valueAsString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return StrolchValueType.BOOLEAN.getType();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BooleanValue add(Boolean o) {
|
public BooleanValue add(Boolean o) {
|
||||||
this.value = o;
|
this.value = o;
|
||||||
|
|
|
@ -17,6 +17,7 @@ package li.strolch.model.timevalue.impl;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import li.strolch.model.StrolchValueType;
|
||||||
import li.strolch.model.timevalue.ITimeValue;
|
import li.strolch.model.timevalue.ITimeValue;
|
||||||
import li.strolch.model.timevalue.IValue;
|
import li.strolch.model.timevalue.IValue;
|
||||||
|
|
||||||
|
@ -53,6 +54,11 @@ public class FloatValue implements IValue<Double>, Serializable {
|
||||||
this.value = Double.parseDouble(valueAsString);
|
this.value = Double.parseDouble(valueAsString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return StrolchValueType.FLOAT.getType();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FloatValue add(Double o) {
|
public FloatValue add(Double o) {
|
||||||
this.value += o;
|
this.value += o;
|
||||||
|
|
|
@ -17,6 +17,7 @@ package li.strolch.model.timevalue.impl;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import li.strolch.model.StrolchValueType;
|
||||||
import li.strolch.model.timevalue.ITimeValue;
|
import li.strolch.model.timevalue.ITimeValue;
|
||||||
import li.strolch.model.timevalue.IValue;
|
import li.strolch.model.timevalue.IValue;
|
||||||
|
|
||||||
|
@ -45,6 +46,11 @@ public class IntegerValue implements IValue<Integer>, Serializable {
|
||||||
this.value = Integer.parseInt(valueAsString);
|
this.value = Integer.parseInt(valueAsString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return StrolchValueType.INTEGER.getType();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IntegerValue add(Integer o) {
|
public IntegerValue add(Integer o) {
|
||||||
this.value += o;
|
this.value += o;
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
|
import li.strolch.model.StrolchValueType;
|
||||||
import li.strolch.model.timevalue.ITimeValue;
|
import li.strolch.model.timevalue.ITimeValue;
|
||||||
import li.strolch.model.timevalue.IValue;
|
import li.strolch.model.timevalue.IValue;
|
||||||
import ch.eitchnet.utils.dbc.DBC;
|
import ch.eitchnet.utils.dbc.DBC;
|
||||||
|
@ -42,7 +43,7 @@ public class StringSetValue implements IValue<Set<AString>>, Serializable {
|
||||||
|
|
||||||
private Set<AString> aStrings = new HashSet<>();
|
private Set<AString> aStrings = new HashSet<>();
|
||||||
|
|
||||||
public StringSetValue() {
|
private StringSetValue() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringSetValue(final Set<AString> aStrings) {
|
public StringSetValue(final Set<AString> aStrings) {
|
||||||
|
@ -50,6 +51,20 @@ public class StringSetValue implements IValue<Set<AString>>, Serializable {
|
||||||
this.aStrings = aStrings;
|
this.aStrings = aStrings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StringSetValue(String valueAsString) {
|
||||||
|
Set<AString> value = new HashSet<>();
|
||||||
|
String[] values = valueAsString.split(",");
|
||||||
|
for (String s : values) {
|
||||||
|
value.add(new AString(s.trim()));
|
||||||
|
}
|
||||||
|
this.aStrings = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return StrolchValueType.STRING_SET.getType();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<AString> getValue() {
|
public Set<AString> getValue() {
|
||||||
return this.aStrings;
|
return this.aStrings;
|
||||||
|
|
|
@ -17,15 +17,9 @@ package li.strolch.model.timevalue.impl;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import li.strolch.model.Tags;
|
|
||||||
import li.strolch.model.timevalue.IValue;
|
import li.strolch.model.timevalue.IValue;
|
||||||
import li.strolch.model.timevalue.IValueChange;
|
import li.strolch.model.timevalue.IValueChange;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Martin Smock <smock.martin@gmail.com>
|
* @author Martin Smock <smock.martin@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
@ -68,6 +62,7 @@ public class ValueChange<T extends IValue> implements IValueChange<T>, Serializa
|
||||||
return this.time;
|
return this.time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setTime(Long time) {
|
public void setTime(Long time) {
|
||||||
this.time = time;
|
this.time = time;
|
||||||
}
|
}
|
||||||
|
@ -78,6 +73,7 @@ public class ValueChange<T extends IValue> implements IValueChange<T>, Serializa
|
||||||
return (T) this.value.getCopy();
|
return (T) this.value.getCopy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setValue(T value) {
|
public void setValue(T value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
@ -134,13 +130,15 @@ public class ValueChange<T extends IValue> implements IValueChange<T>, Serializa
|
||||||
sb.append(this.time);
|
sb.append(this.time);
|
||||||
sb.append(", value=");
|
sb.append(", value=");
|
||||||
sb.append(this.value);
|
sb.append(this.value);
|
||||||
|
sb.append(", stateId=");
|
||||||
|
sb.append(this.stateId);
|
||||||
sb.append("]");
|
sb.append("]");
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getStateId() {
|
public String getStateId() {
|
||||||
return stateId;
|
return this.stateId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -151,17 +149,6 @@ public class ValueChange<T extends IValue> implements IValueChange<T>, Serializa
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public IValueChange<T> getClone() {
|
public IValueChange<T> getClone() {
|
||||||
return new ValueChange(time, value);
|
return new ValueChange(this.time, this.value, this.stateId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Element toDom(Document doc) {
|
|
||||||
Element element = doc.createElement(Tags.VALUE_CHANGE);
|
|
||||||
element.setAttribute(Tags.STATE_ID, this.stateId);
|
|
||||||
element.setAttribute(Tags.TIME, ISO8601FormatFactory.getInstance().formatDate(time));
|
|
||||||
element.setAttribute(Tags.VALUE, this.value.getValueAsString());
|
|
||||||
element.setAttribute(Tags.VALUE_CLASS, this.value.getClass().getName());
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,9 @@ import static li.strolch.model.StrolchModelConstants.UOM_NONE;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
@ -36,12 +37,15 @@ import li.strolch.model.ParameterizedElement;
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
import li.strolch.model.StrolchElement;
|
import li.strolch.model.StrolchElement;
|
||||||
import li.strolch.model.Tags;
|
import li.strolch.model.Tags;
|
||||||
|
import li.strolch.model.activity.Action;
|
||||||
|
import li.strolch.model.activity.Activity;
|
||||||
|
import li.strolch.model.activity.IActivityElement;
|
||||||
import li.strolch.model.parameter.Parameter;
|
import li.strolch.model.parameter.Parameter;
|
||||||
import li.strolch.model.timedstate.StrolchTimedState;
|
import li.strolch.model.timedstate.StrolchTimedState;
|
||||||
import li.strolch.model.timevalue.ITimeValue;
|
import li.strolch.model.timevalue.ITimeValue;
|
||||||
import li.strolch.model.timevalue.ITimeVariable;
|
import li.strolch.model.timevalue.ITimeVariable;
|
||||||
import li.strolch.model.timevalue.IValue;
|
import li.strolch.model.timevalue.IValue;
|
||||||
import ch.eitchnet.utils.helper.StringHelper;
|
import li.strolch.model.timevalue.IValueChange;
|
||||||
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
|
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,16 +59,81 @@ public abstract class AbstractToSaxWriterVisitor {
|
||||||
this.writer = writer;
|
this.writer = writer;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void writeElement(String tag, Order order) throws XMLStreamException {
|
protected void writeElement(Order order) throws XMLStreamException {
|
||||||
boolean empty = !order.hasParameterBags();
|
boolean empty = !order.hasParameterBags();
|
||||||
writeElement(tag, empty, order);
|
|
||||||
|
writeStartStrolchElement(Tags.ORDER, empty, order);
|
||||||
|
this.writer.writeAttribute(Tags.DATE, ISO8601FormatFactory.getInstance().formatDate(order.getDate()));
|
||||||
|
this.writer.writeAttribute(Tags.STATE, order.getState().name());
|
||||||
|
|
||||||
|
if (order.hasParameterBags()) {
|
||||||
|
writeParameterBags(order);
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty)
|
if (!empty)
|
||||||
this.writer.writeEndElement();
|
this.writer.writeEndElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void writeElement(String tag, Resource resource) throws XMLStreamException {
|
protected void writeElement(Activity activity) throws XMLStreamException {
|
||||||
|
boolean empty = !activity.hasParameterBags() && !activity.hasElements();
|
||||||
|
|
||||||
|
writeStartStrolchElement(Tags.ACTIVITY, empty, activity);
|
||||||
|
|
||||||
|
if (activity.hasParameterBags()) {
|
||||||
|
writeParameterBags(activity);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activity.hasElements()) {
|
||||||
|
Iterator<Entry<String, IActivityElement>> iter = activity.elementIterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
IActivityElement element = iter.next().getValue();
|
||||||
|
if (element instanceof Activity)
|
||||||
|
writeElement((Activity) element);
|
||||||
|
else if (element instanceof Action)
|
||||||
|
writeElement((Action) element);
|
||||||
|
else
|
||||||
|
throw new IllegalArgumentException("Unhandled Element class " + element.getClass());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty)
|
||||||
|
this.writer.writeEndElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> void writeElement(Action action) throws XMLStreamException {
|
||||||
|
boolean empty = !action.hasParameterBags() && !action.hasChanges();
|
||||||
|
|
||||||
|
writeStartStrolchElement(Tags.ACTION, empty, action);
|
||||||
|
this.writer.writeAttribute(Tags.STATE, action.getState().name());
|
||||||
|
this.writer.writeAttribute(Tags.RESOURCE_ID, action.getResourceId());
|
||||||
|
this.writer.writeAttribute(Tags.RESOURCE_TYPE, action.getResourceType());
|
||||||
|
|
||||||
|
if (action.hasParameterBags()) {
|
||||||
|
writeParameterBags(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action.hasChanges()) {
|
||||||
|
for (IValueChange<? extends IValue<?>> change : action.getChanges()) {
|
||||||
|
this.writer.writeEmptyElement(Tags.VALUE_CHANGE);
|
||||||
|
this.writer.writeAttribute(Tags.STATE_ID, change.getStateId());
|
||||||
|
this.writer.writeAttribute(Tags.TIME, ISO8601FormatFactory.getInstance().formatDate(change.getTime()));
|
||||||
|
this.writer.writeAttribute(Tags.VALUE, change.getValue().getValueAsString());
|
||||||
|
this.writer.writeAttribute(Tags.TYPE, change.getValue().getClass().getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty)
|
||||||
|
this.writer.writeEndElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void writeElement(Resource resource) throws XMLStreamException {
|
||||||
boolean empty = !resource.hasParameterBags() && !resource.hasTimedStates();
|
boolean empty = !resource.hasParameterBags() && !resource.hasTimedStates();
|
||||||
writeElement(tag, empty, resource);
|
|
||||||
|
writeStartStrolchElement(Tags.RESOURCE, empty, resource);
|
||||||
|
|
||||||
|
if (resource.hasParameterBags()) {
|
||||||
|
writeParameterBags(resource);
|
||||||
|
}
|
||||||
|
|
||||||
if (resource.hasTimedStates())
|
if (resource.hasTimedStates())
|
||||||
writeTimedStates(resource);
|
writeTimedStates(resource);
|
||||||
|
@ -97,14 +166,6 @@ public abstract class AbstractToSaxWriterVisitor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void writeElement(String tag, boolean empty, GroupedParameterizedElement element)
|
|
||||||
throws XMLStreamException {
|
|
||||||
writeStartStrolchElement(tag, empty, element);
|
|
||||||
if (!empty) {
|
|
||||||
writeParameterBags(element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void writeStartStrolchElement(String tag, boolean empty, StrolchElement element)
|
protected void writeStartStrolchElement(String tag, boolean empty, StrolchElement element)
|
||||||
throws XMLStreamException {
|
throws XMLStreamException {
|
||||||
if (empty) {
|
if (empty) {
|
||||||
|
@ -114,9 +175,7 @@ public abstract class AbstractToSaxWriterVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.writer.writeAttribute(Tags.ID, element.getId());
|
this.writer.writeAttribute(Tags.ID, element.getId());
|
||||||
if (StringHelper.isNotEmpty(element.getName())) {
|
|
||||||
this.writer.writeAttribute(Tags.NAME, element.getName());
|
this.writer.writeAttribute(Tags.NAME, element.getName());
|
||||||
}
|
|
||||||
this.writer.writeAttribute(Tags.TYPE, element.getType());
|
this.writer.writeAttribute(Tags.TYPE, element.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,12 +195,7 @@ public abstract class AbstractToSaxWriterVisitor {
|
||||||
protected void writeParameters(ParameterizedElement element) throws XMLStreamException {
|
protected void writeParameters(ParameterizedElement element) throws XMLStreamException {
|
||||||
|
|
||||||
List<Parameter<?>> parameters = new ArrayList<>(element.getParameters());
|
List<Parameter<?>> parameters = new ArrayList<>(element.getParameters());
|
||||||
Collections.sort(parameters, new Comparator<Parameter<?>>() {
|
Collections.sort(parameters, (o1, o2) -> Integer.valueOf(o1.getIndex()).compareTo(o2.getIndex()));
|
||||||
@Override
|
|
||||||
public int compare(Parameter<?> o1, Parameter<?> o2) {
|
|
||||||
return Integer.valueOf(o1.getIndex()).compareTo(o2.getIndex());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
for (Parameter<?> parameter : parameters) {
|
for (Parameter<?> parameter : parameters) {
|
||||||
writeStartStrolchElement(Tags.PARAMETER, true, parameter);
|
writeStartStrolchElement(Tags.PARAMETER, true, parameter);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package li.strolch.model.xml;
|
||||||
|
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
|
||||||
|
import li.strolch.model.ActivityVisitor;
|
||||||
|
import li.strolch.model.activity.Action;
|
||||||
|
import li.strolch.model.activity.Activity;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
import ch.eitchnet.utils.helper.DomUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*/
|
||||||
|
public class ActivityToDomVisitor extends StrolchElementToDomVisitor implements ActivityVisitor<Document> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Document visit(Activity activity) {
|
||||||
|
DocumentBuilder documentBuilder = DomUtil.createDocumentBuilder();
|
||||||
|
this.document = documentBuilder.getDOMImplementation().createDocument(null, null, null);
|
||||||
|
|
||||||
|
Element asDom = toDom(activity);
|
||||||
|
document.appendChild(asDom);
|
||||||
|
return this.document;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Element toDom(Action action) {
|
||||||
|
return super.toDom(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Element toDom(Activity activity) {
|
||||||
|
return super.toDom(activity);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package li.strolch.model.xml;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
import javax.xml.stream.XMLStreamException;
|
||||||
|
import javax.xml.stream.XMLStreamWriter;
|
||||||
|
|
||||||
|
import li.strolch.exception.StrolchException;
|
||||||
|
import li.strolch.model.ActivityVisitor;
|
||||||
|
import li.strolch.model.activity.Activity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*/
|
||||||
|
public class ActivityToSaxWriterVisitor extends AbstractToSaxWriterVisitor implements ActivityVisitor<Void> {
|
||||||
|
|
||||||
|
public ActivityToSaxWriterVisitor(XMLStreamWriter writer) {
|
||||||
|
super(writer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void visit(Activity activity) {
|
||||||
|
try {
|
||||||
|
writeElement(activity);
|
||||||
|
this.writer.flush();
|
||||||
|
} catch (XMLStreamException e) {
|
||||||
|
String msg = "Failed to write Activity {0} due to {1}"; //$NON-NLS-1$
|
||||||
|
msg = MessageFormat.format(msg, activity.getLocator(), e.getMessage());
|
||||||
|
throw new StrolchException(msg, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package li.strolch.model.xml;
|
||||||
|
|
||||||
|
import li.strolch.model.Order;
|
||||||
|
import li.strolch.model.State;
|
||||||
|
import li.strolch.model.Tags;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
import ch.eitchnet.utils.helper.StringHelper;
|
||||||
|
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*/
|
||||||
|
public class OrderFromDomVisitor extends StrolchElementFromDomVisitor {
|
||||||
|
|
||||||
|
public Order visit(Document doc) {
|
||||||
|
return fromDom(doc.getDocumentElement());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Order fromDom(Element element) {
|
||||||
|
Order order = new Order();
|
||||||
|
fromDom(element, order);
|
||||||
|
|
||||||
|
String date = element.getAttribute(Tags.DATE);
|
||||||
|
String state = element.getAttribute(Tags.STATE);
|
||||||
|
|
||||||
|
if (StringHelper.isEmpty(date)) {
|
||||||
|
order.setDate(ISO8601FormatFactory.getInstance().getDateFormat().parse("-")); //$NON-NLS-1$
|
||||||
|
} else {
|
||||||
|
order.setDate(ISO8601FormatFactory.getInstance().getDateFormat().parse(date));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state == null || state.isEmpty()) {
|
||||||
|
order.setState(State.CREATED);
|
||||||
|
} else {
|
||||||
|
order.setState(State.valueOf(state));
|
||||||
|
}
|
||||||
|
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,25 +28,15 @@ import ch.eitchnet.utils.helper.DomUtil;
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
public class OrderToDomVisitor implements OrderVisitor<Document> {
|
public class OrderToDomVisitor extends StrolchElementToDomVisitor implements OrderVisitor<Document> {
|
||||||
|
|
||||||
private Document document;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the document
|
|
||||||
*/
|
|
||||||
public Document getDocument() {
|
|
||||||
return this.document;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Document visit(Order order) {
|
public Document visit(Order order) {
|
||||||
DocumentBuilder documentBuilder = DomUtil.createDocumentBuilder();
|
DocumentBuilder documentBuilder = DomUtil.createDocumentBuilder();
|
||||||
Document document = documentBuilder.getDOMImplementation().createDocument(null, null, null);
|
this.document = documentBuilder.getDOMImplementation().createDocument(null, null, null);
|
||||||
|
|
||||||
Element orderDom = order.toDom(document);
|
Element asDom = toDom(order);
|
||||||
document.appendChild(orderDom);
|
document.appendChild(asDom);
|
||||||
this.document = document;
|
|
||||||
return this.document;
|
return this.document;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ import javax.xml.stream.XMLStreamWriter;
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
import li.strolch.model.OrderVisitor;
|
import li.strolch.model.OrderVisitor;
|
||||||
import li.strolch.model.Tags;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
@ -37,7 +36,7 @@ public class OrderToSaxWriterVisitor extends AbstractToSaxWriterVisitor implemen
|
||||||
@Override
|
@Override
|
||||||
public Void visit(Order order) {
|
public Void visit(Order order) {
|
||||||
try {
|
try {
|
||||||
writeElement(Tags.ORDER, order);
|
writeElement(order);
|
||||||
this.writer.flush();
|
this.writer.flush();
|
||||||
} catch (XMLStreamException e) {
|
} catch (XMLStreamException e) {
|
||||||
String msg = "Failed to write Order {0} due to {1}"; //$NON-NLS-1$
|
String msg = "Failed to write Order {0} due to {1}"; //$NON-NLS-1$
|
||||||
|
|
|
@ -0,0 +1,105 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package li.strolch.model.xml;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import li.strolch.exception.StrolchException;
|
||||||
|
import li.strolch.model.AbstractStrolchElement;
|
||||||
|
import li.strolch.model.Resource;
|
||||||
|
import li.strolch.model.StrolchValueType;
|
||||||
|
import li.strolch.model.Tags;
|
||||||
|
import li.strolch.model.timedstate.StrolchTimedState;
|
||||||
|
import li.strolch.model.timevalue.IValue;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
|
import ch.eitchnet.utils.dbc.DBC;
|
||||||
|
import ch.eitchnet.utils.helper.StringHelper;
|
||||||
|
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*/
|
||||||
|
public class ResourceFromDomVisitor extends StrolchElementFromDomVisitor {
|
||||||
|
|
||||||
|
public Resource visit(Document doc) {
|
||||||
|
return fromDom(doc.getDocumentElement());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Resource fromDom(Element resourceElement) {
|
||||||
|
Resource resource = new Resource();
|
||||||
|
fromDom(resourceElement, resource);
|
||||||
|
|
||||||
|
NodeList timedStateElems = resourceElement.getElementsByTagName(Tags.TIMED_STATE);
|
||||||
|
for (int i = 0; i < timedStateElems.getLength(); i++) {
|
||||||
|
Element timedStateElem = (Element) timedStateElems.item(i);
|
||||||
|
String typeS = timedStateElem.getAttribute(Tags.TYPE);
|
||||||
|
|
||||||
|
DBC.PRE.assertNotEmpty("Type must be set on TimedState for resource with id " + resource.getId(), typeS);
|
||||||
|
StrolchValueType valueType = StrolchValueType.parse(typeS);
|
||||||
|
StrolchTimedState<? extends IValue<?>> timedState = valueType.timedStateInstance();
|
||||||
|
|
||||||
|
fromDom(timedStateElem, (AbstractStrolchElement) timedState);
|
||||||
|
|
||||||
|
String interpretation = timedStateElem.getAttribute(Tags.INTERPRETATION);
|
||||||
|
String hidden = timedStateElem.getAttribute(Tags.HIDDEN);
|
||||||
|
String uom = timedStateElem.getAttribute(Tags.UOM);
|
||||||
|
String index = timedStateElem.getAttribute(Tags.INDEX);
|
||||||
|
|
||||||
|
timedState.setInterpretation(interpretation);
|
||||||
|
timedState.setUom(uom);
|
||||||
|
|
||||||
|
if (StringHelper.isEmpty(index)) {
|
||||||
|
timedState.setIndex(0);
|
||||||
|
} else {
|
||||||
|
timedState.setIndex(Integer.valueOf(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringHelper.isEmpty(hidden)) {
|
||||||
|
timedState.setHidden(false);
|
||||||
|
} else {
|
||||||
|
if (hidden.equalsIgnoreCase(Boolean.TRUE.toString())) {
|
||||||
|
timedState.setHidden(true);
|
||||||
|
} else if (hidden.equalsIgnoreCase(Boolean.FALSE.toString())) {
|
||||||
|
timedState.setHidden(false);
|
||||||
|
} else {
|
||||||
|
String msg = "Boolean string must be either {0} or {1}"; //$NON-NLS-1$
|
||||||
|
msg = MessageFormat.format(msg, Boolean.TRUE.toString(), Boolean.FALSE.toString());
|
||||||
|
throw new StrolchException(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeList timeValueElems = timedStateElem.getElementsByTagName(Tags.VALUE);
|
||||||
|
for (int j = 0; j < timeValueElems.getLength(); j++) {
|
||||||
|
Element timeValueElem = (Element) timeValueElems.item(j);
|
||||||
|
String timeS = timeValueElem.getAttribute(Tags.TIME);
|
||||||
|
Date date = ISO8601FormatFactory.getInstance().parseDate(timeS);
|
||||||
|
long time = date.getTime();
|
||||||
|
|
||||||
|
String valueS = timeValueElem.getAttribute(Tags.VALUE);
|
||||||
|
timedState.setStateFromStringAt(time, valueS);
|
||||||
|
}
|
||||||
|
|
||||||
|
resource.addTimedState(timedState);
|
||||||
|
}
|
||||||
|
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,25 +28,15 @@ import ch.eitchnet.utils.helper.DomUtil;
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
public class ResourceToDomVisitor implements ResourceVisitor<Document> {
|
public class ResourceToDomVisitor extends StrolchElementToDomVisitor implements ResourceVisitor<Document> {
|
||||||
|
|
||||||
private Document document;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the document
|
|
||||||
*/
|
|
||||||
public Document getDocument() {
|
|
||||||
return this.document;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Document visit(Resource resource) {
|
public Document visit(Resource resource) {
|
||||||
DocumentBuilder documentBuilder = DomUtil.createDocumentBuilder();
|
DocumentBuilder documentBuilder = DomUtil.createDocumentBuilder();
|
||||||
Document document = documentBuilder.getDOMImplementation().createDocument(null, null, null);
|
this.document = documentBuilder.getDOMImplementation().createDocument(null, null, null);
|
||||||
|
|
||||||
Element resourceDom = resource.toDom(document);
|
Element asDom = toDom(resource);
|
||||||
document.appendChild(resourceDom);
|
document.appendChild(asDom);
|
||||||
this.document = document;
|
|
||||||
return this.document;
|
return this.document;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ import javax.xml.stream.XMLStreamWriter;
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
import li.strolch.model.ResourceVisitor;
|
import li.strolch.model.ResourceVisitor;
|
||||||
import li.strolch.model.Tags;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
@ -37,7 +36,7 @@ public class ResourceToSaxWriterVisitor extends AbstractToSaxWriterVisitor imple
|
||||||
@Override
|
@Override
|
||||||
public Void visit(Resource resource) {
|
public Void visit(Resource resource) {
|
||||||
try {
|
try {
|
||||||
writeElement(Tags.RESOURCE, resource);
|
writeElement(resource);
|
||||||
this.writer.flush();
|
this.writer.flush();
|
||||||
} catch (XMLStreamException e) {
|
} catch (XMLStreamException e) {
|
||||||
String msg = "Failed to write Resource {0} due to {1}"; //$NON-NLS-1$
|
String msg = "Failed to write Resource {0} due to {1}"; //$NON-NLS-1$
|
||||||
|
|
|
@ -0,0 +1,122 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package li.strolch.model.xml;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
import li.strolch.exception.StrolchException;
|
||||||
|
import li.strolch.model.AbstractStrolchElement;
|
||||||
|
import li.strolch.model.GroupedParameterizedElement;
|
||||||
|
import li.strolch.model.ParameterBag;
|
||||||
|
import li.strolch.model.ParameterizedElement;
|
||||||
|
import li.strolch.model.StrolchValueType;
|
||||||
|
import li.strolch.model.Tags;
|
||||||
|
import li.strolch.model.parameter.Parameter;
|
||||||
|
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
|
import ch.eitchnet.utils.helper.StringHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*/
|
||||||
|
public class StrolchElementFromDomVisitor {
|
||||||
|
|
||||||
|
protected void fromDom(Element element, AbstractStrolchElement strolchElement) {
|
||||||
|
String id = element.getAttribute(Tags.ID);
|
||||||
|
String name = element.getAttribute(Tags.NAME);
|
||||||
|
|
||||||
|
if (id != null && name != null) {
|
||||||
|
strolchElement.setId(id);
|
||||||
|
strolchElement.setName(name);
|
||||||
|
} else {
|
||||||
|
String msg = "Check the values of the element: {0} either id or name attribute is null!"; //$NON-NLS-1$
|
||||||
|
msg = MessageFormat.format(msg, element.getNodeName());
|
||||||
|
throw new StrolchException(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fromDom(Element element, GroupedParameterizedElement order) {
|
||||||
|
fromDom(element, (AbstractStrolchElement) order);
|
||||||
|
|
||||||
|
String type = element.getAttribute(Tags.TYPE);
|
||||||
|
order.setType(type);
|
||||||
|
|
||||||
|
NodeList bags = element.getElementsByTagName(Tags.PARAMETER_BAG);
|
||||||
|
for (int i = 0; i < bags.getLength(); i++) {
|
||||||
|
Element bagElement = (Element) bags.item(i);
|
||||||
|
ParameterBag bag = new ParameterBag();
|
||||||
|
fromDom(bagElement, bag);
|
||||||
|
order.addParameterBag(bag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fromDom(Element element, ParameterizedElement parameterizedElement) {
|
||||||
|
fromDom(element, (AbstractStrolchElement) parameterizedElement);
|
||||||
|
|
||||||
|
String type = element.getAttribute(Tags.TYPE);
|
||||||
|
parameterizedElement.setType(type);
|
||||||
|
|
||||||
|
// add all the parameters
|
||||||
|
NodeList parameterElements = element.getElementsByTagName(Tags.PARAMETER);
|
||||||
|
for (int i = 0; i < parameterElements.getLength(); i++) {
|
||||||
|
Element paramElement = (Element) parameterElements.item(i);
|
||||||
|
String paramtype = paramElement.getAttribute(Tags.TYPE);
|
||||||
|
|
||||||
|
StrolchValueType paramValueType = StrolchValueType.parse(paramtype);
|
||||||
|
Parameter<?> parameter = paramValueType.parameterInstance();
|
||||||
|
fromDom(paramElement, parameter);
|
||||||
|
parameterizedElement.addParameter(parameter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fromDom(Element element, Parameter<?> param) {
|
||||||
|
|
||||||
|
fromDom(element, (AbstractStrolchElement) param);
|
||||||
|
|
||||||
|
String value = element.getAttribute(Tags.VALUE);
|
||||||
|
param.setValueFromString(value);
|
||||||
|
|
||||||
|
String interpretation = element.getAttribute(Tags.INTERPRETATION);
|
||||||
|
String hidden = element.getAttribute(Tags.HIDDEN);
|
||||||
|
String uom = element.getAttribute(Tags.UOM);
|
||||||
|
String index = element.getAttribute(Tags.INDEX);
|
||||||
|
|
||||||
|
param.setInterpretation(interpretation);
|
||||||
|
param.setUom(uom);
|
||||||
|
|
||||||
|
if (StringHelper.isEmpty(index)) {
|
||||||
|
param.setIndex(0);
|
||||||
|
} else {
|
||||||
|
param.setIndex(Integer.valueOf(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringHelper.isEmpty(hidden)) {
|
||||||
|
param.setHidden(false);
|
||||||
|
} else {
|
||||||
|
if (hidden.equalsIgnoreCase(Boolean.TRUE.toString())) {
|
||||||
|
param.setHidden(true);
|
||||||
|
} else if (hidden.equalsIgnoreCase(Boolean.FALSE.toString())) {
|
||||||
|
param.setHidden(false);
|
||||||
|
} else {
|
||||||
|
String msg = "Boolean string must be either {0} or {1}"; //$NON-NLS-1$
|
||||||
|
msg = MessageFormat.format(msg, Boolean.TRUE.toString(), Boolean.FALSE.toString());
|
||||||
|
throw new StrolchException(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,222 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package li.strolch.model.xml;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
|
||||||
|
import li.strolch.model.AbstractStrolchElement;
|
||||||
|
import li.strolch.model.GroupedParameterizedElement;
|
||||||
|
import li.strolch.model.Order;
|
||||||
|
import li.strolch.model.ParameterBag;
|
||||||
|
import li.strolch.model.ParameterizedElement;
|
||||||
|
import li.strolch.model.Resource;
|
||||||
|
import li.strolch.model.StrolchModelConstants;
|
||||||
|
import li.strolch.model.Tags;
|
||||||
|
import li.strolch.model.activity.Action;
|
||||||
|
import li.strolch.model.activity.Activity;
|
||||||
|
import li.strolch.model.activity.IActivityElement;
|
||||||
|
import li.strolch.model.parameter.Parameter;
|
||||||
|
import li.strolch.model.timedstate.StrolchTimedState;
|
||||||
|
import li.strolch.model.timevalue.ITimeValue;
|
||||||
|
import li.strolch.model.timevalue.IValue;
|
||||||
|
import li.strolch.model.timevalue.IValueChange;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*/
|
||||||
|
public class StrolchElementToDomVisitor {
|
||||||
|
|
||||||
|
protected Document document;
|
||||||
|
|
||||||
|
public Document getDocument() {
|
||||||
|
return this.document;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Element toDom(Order order) {
|
||||||
|
|
||||||
|
Element asDom = document.createElement(Tags.ORDER);
|
||||||
|
fillElement(asDom, order);
|
||||||
|
|
||||||
|
asDom.setAttribute(Tags.DATE, ISO8601FormatFactory.getInstance().formatDate(order.getDate()));
|
||||||
|
asDom.setAttribute(Tags.STATE, order.getState().name());
|
||||||
|
|
||||||
|
return asDom;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Element toDom(Resource resource) {
|
||||||
|
|
||||||
|
Element asDom = document.createElement(Tags.RESOURCE);
|
||||||
|
fillElement(asDom, resource);
|
||||||
|
|
||||||
|
if (resource.hasTimedStates()) {
|
||||||
|
for (String stateKey : resource.getTimedStateKeySet()) {
|
||||||
|
StrolchTimedState<IValue<?>> timedState = resource.getTimedState(stateKey);
|
||||||
|
Element stateElement = toDom(timedState);
|
||||||
|
asDom.appendChild(stateElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return asDom;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Element toDom(Activity activity) {
|
||||||
|
Element element = document.createElement(Tags.ACTIVITY);
|
||||||
|
fillElement(element, activity);
|
||||||
|
|
||||||
|
if (activity.hasElements()) {
|
||||||
|
Iterator<Entry<String, IActivityElement>> iter = activity.elementIterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
IActivityElement activityElement = iter.next().getValue();
|
||||||
|
if (activityElement instanceof Activity) {
|
||||||
|
element.appendChild(toDom((Activity) activityElement));
|
||||||
|
} else if (activityElement instanceof Action) {
|
||||||
|
element.appendChild(toDom((Action) activityElement));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Element toDom(Action action) {
|
||||||
|
Element element = document.createElement(Tags.ACTION);
|
||||||
|
fillElement(element, action);
|
||||||
|
|
||||||
|
element.setAttribute(Tags.RESOURCE_ID, action.getResourceId());
|
||||||
|
element.setAttribute(Tags.RESOURCE_TYPE, action.getResourceType());
|
||||||
|
element.setAttribute(Tags.STATE, action.getState().name());
|
||||||
|
|
||||||
|
if (action.hasChanges()) {
|
||||||
|
Iterator<IValueChange<? extends IValue<?>>> iter = action.changesIterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
IValueChange<? extends IValue<?>> value = iter.next();
|
||||||
|
Element valueChangeElement = toDom(value);
|
||||||
|
element.appendChild(valueChangeElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Element toDom(IValueChange<? extends IValue<?>> value) {
|
||||||
|
Element element = document.createElement(Tags.VALUE_CHANGE);
|
||||||
|
element.setAttribute(Tags.STATE_ID, value.getStateId());
|
||||||
|
element.setAttribute(Tags.TIME, ISO8601FormatFactory.getInstance().formatDate(value.getTime()));
|
||||||
|
element.setAttribute(Tags.VALUE, value.getValue().getValueAsString());
|
||||||
|
element.setAttribute(Tags.TYPE, value.getValue().getType());
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Element toDom(StrolchTimedState<IValue<?>> timedState) {
|
||||||
|
|
||||||
|
Element element = document.createElement(Tags.TIMED_STATE);
|
||||||
|
fillElement(element, (AbstractStrolchElement) timedState);
|
||||||
|
|
||||||
|
if (!timedState.getInterpretation().equals(StrolchModelConstants.INTERPRETATION_NONE)) {
|
||||||
|
element.setAttribute(Tags.INTERPRETATION, timedState.getInterpretation());
|
||||||
|
}
|
||||||
|
if (!timedState.getUom().equals(StrolchModelConstants.UOM_NONE)) {
|
||||||
|
element.setAttribute(Tags.UOM, timedState.getUom());
|
||||||
|
}
|
||||||
|
if (timedState.isHidden()) {
|
||||||
|
element.setAttribute(Tags.HIDDEN, Boolean.toString(timedState.isHidden()));
|
||||||
|
}
|
||||||
|
if (timedState.getIndex() != 0) {
|
||||||
|
element.setAttribute(Tags.INDEX, Integer.toString(timedState.getIndex()));
|
||||||
|
}
|
||||||
|
|
||||||
|
SortedSet<ITimeValue<IValue<?>>> values = timedState.getTimeEvolution().getValues();
|
||||||
|
for (ITimeValue<IValue<?>> iTimeValue : values) {
|
||||||
|
|
||||||
|
Long time = iTimeValue.getTime();
|
||||||
|
String valueS = iTimeValue.getValue().getValueAsString();
|
||||||
|
|
||||||
|
Element valueElement = document.createElement(Tags.VALUE);
|
||||||
|
valueElement.setAttribute(Tags.TIME, ISO8601FormatFactory.getInstance().formatDate(time));
|
||||||
|
valueElement.setAttribute(Tags.VALUE, valueS);
|
||||||
|
|
||||||
|
element.appendChild(valueElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Element toDom(ParameterBag bag) {
|
||||||
|
Element bagElement = document.createElement(Tags.PARAMETER_BAG);
|
||||||
|
fillElement(bagElement, (ParameterizedElement) bag);
|
||||||
|
return bagElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Element toDom(Parameter<?> param) {
|
||||||
|
Element element = document.createElement(Tags.PARAMETER);
|
||||||
|
fillElement(element, (AbstractStrolchElement) param);
|
||||||
|
|
||||||
|
element.setAttribute(Tags.VALUE, param.getValueAsString());
|
||||||
|
|
||||||
|
if (!param.getInterpretation().equals(StrolchModelConstants.INTERPRETATION_NONE)) {
|
||||||
|
element.setAttribute(Tags.INTERPRETATION, param.getInterpretation());
|
||||||
|
}
|
||||||
|
if (!param.getUom().equals(StrolchModelConstants.UOM_NONE)) {
|
||||||
|
element.setAttribute(Tags.UOM, param.getUom());
|
||||||
|
}
|
||||||
|
if (param.isHidden()) {
|
||||||
|
element.setAttribute(Tags.HIDDEN, Boolean.toString(param.isHidden()));
|
||||||
|
}
|
||||||
|
if (param.getIndex() != 0) {
|
||||||
|
element.setAttribute(Tags.INDEX, Integer.toString(param.getIndex()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fillElement(Element element, AbstractStrolchElement strolchElement) {
|
||||||
|
element.setAttribute(Tags.ID, strolchElement.getId());
|
||||||
|
element.setAttribute(Tags.NAME, strolchElement.getName());
|
||||||
|
element.setAttribute(Tags.TYPE, strolchElement.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fillElement(Element element, GroupedParameterizedElement groupedParameterizedElement) {
|
||||||
|
fillElement(element, (AbstractStrolchElement) groupedParameterizedElement);
|
||||||
|
|
||||||
|
if (groupedParameterizedElement.hasParameterBags()) {
|
||||||
|
for (String bagKey : groupedParameterizedElement.getParameterBagKeySet()) {
|
||||||
|
ParameterBag bag = groupedParameterizedElement.getParameterBag(bagKey);
|
||||||
|
Element bagElement = toDom(bag);
|
||||||
|
element.appendChild(bagElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fillElement(Element element, ParameterizedElement parameterizedElement) {
|
||||||
|
fillElement(element, (AbstractStrolchElement) parameterizedElement);
|
||||||
|
|
||||||
|
if (parameterizedElement.hasParameters()) {
|
||||||
|
for (String paramKey : parameterizedElement.getParameterKeySet()) {
|
||||||
|
Parameter<?> parameter = parameterizedElement.getParameter(paramKey);
|
||||||
|
Element paramElement = toDom(parameter);
|
||||||
|
element.appendChild(paramElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -76,8 +76,7 @@ public class XmlModelSaxFileReader extends XmlModelSaxReader {
|
||||||
|
|
||||||
XmlModelSaxFileReader handler = new XmlModelSaxFileReader(this.listener, includeFile, this.allowInclude);
|
XmlModelSaxFileReader handler = new XmlModelSaxFileReader(this.listener, includeFile, this.allowInclude);
|
||||||
handler.parseFile();
|
handler.parseFile();
|
||||||
this.statistics.nrOfOrders += handler.statistics.nrOfOrders;
|
this.statistics.add(handler.statistics);
|
||||||
this.statistics.nrOfResources += handler.statistics.nrOfResources;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
package li.strolch.model.xml;
|
package li.strolch.model.xml;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
import java.util.ArrayDeque;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.Deque;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.GroupedParameterizedElement;
|
import li.strolch.model.GroupedParameterizedElement;
|
||||||
|
@ -27,30 +27,14 @@ import li.strolch.model.Order;
|
||||||
import li.strolch.model.ParameterBag;
|
import li.strolch.model.ParameterBag;
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
import li.strolch.model.State;
|
import li.strolch.model.State;
|
||||||
|
import li.strolch.model.StrolchValueType;
|
||||||
import li.strolch.model.Tags;
|
import li.strolch.model.Tags;
|
||||||
import li.strolch.model.parameter.BooleanParameter;
|
import li.strolch.model.activity.Action;
|
||||||
import li.strolch.model.parameter.DateParameter;
|
import li.strolch.model.activity.Activity;
|
||||||
import li.strolch.model.parameter.DurationParameter;
|
|
||||||
import li.strolch.model.parameter.FloatListParameter;
|
|
||||||
import li.strolch.model.parameter.FloatParameter;
|
|
||||||
import li.strolch.model.parameter.IntegerListParameter;
|
|
||||||
import li.strolch.model.parameter.IntegerParameter;
|
|
||||||
import li.strolch.model.parameter.LongListParameter;
|
|
||||||
import li.strolch.model.parameter.LongParameter;
|
|
||||||
import li.strolch.model.parameter.Parameter;
|
import li.strolch.model.parameter.Parameter;
|
||||||
import li.strolch.model.parameter.StringListParameter;
|
|
||||||
import li.strolch.model.parameter.StringParameter;
|
|
||||||
import li.strolch.model.timedstate.BooleanTimedState;
|
|
||||||
import li.strolch.model.timedstate.FloatTimedState;
|
|
||||||
import li.strolch.model.timedstate.IntegerTimedState;
|
|
||||||
import li.strolch.model.timedstate.StringSetTimedState;
|
|
||||||
import li.strolch.model.timedstate.StrolchTimedState;
|
import li.strolch.model.timedstate.StrolchTimedState;
|
||||||
import li.strolch.model.timevalue.IValue;
|
import li.strolch.model.timevalue.IValue;
|
||||||
import li.strolch.model.timevalue.impl.AString;
|
import li.strolch.model.timevalue.impl.ValueChange;
|
||||||
import li.strolch.model.timevalue.impl.BooleanValue;
|
|
||||||
import li.strolch.model.timevalue.impl.FloatValue;
|
|
||||||
import li.strolch.model.timevalue.impl.IntegerValue;
|
|
||||||
import li.strolch.model.timevalue.impl.StringSetValue;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -72,13 +56,15 @@ public class XmlModelSaxReader extends DefaultHandler {
|
||||||
protected ModelStatistics statistics;
|
protected ModelStatistics statistics;
|
||||||
|
|
||||||
private GroupedParameterizedElement parameterizedElement;
|
private GroupedParameterizedElement parameterizedElement;
|
||||||
|
private Deque<Activity> activityStack;
|
||||||
private ParameterBag pBag;
|
private ParameterBag pBag;
|
||||||
private StrolchTimedState<? extends IValue<?>> state;
|
private StrolchTimedState<? extends IValue<?>> state;
|
||||||
private String stateType;
|
private StrolchValueType stateType;
|
||||||
|
|
||||||
public XmlModelSaxReader(StrolchElementListener listener) {
|
public XmlModelSaxReader(StrolchElementListener listener) {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
this.statistics = new ModelStatistics();
|
this.statistics = new ModelStatistics();
|
||||||
|
this.activityStack = new ArrayDeque<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -104,6 +90,56 @@ public class XmlModelSaxReader extends DefaultHandler {
|
||||||
String resType = attributes.getValue(Tags.TYPE);
|
String resType = attributes.getValue(Tags.TYPE);
|
||||||
Resource resource = new Resource(resId, resName, resType);
|
Resource resource = new Resource(resId, resName, resType);
|
||||||
this.parameterizedElement = resource;
|
this.parameterizedElement = resource;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Tags.ACTIVITY:
|
||||||
|
|
||||||
|
String activityId = attributes.getValue(Tags.ID);
|
||||||
|
String activityName = attributes.getValue(Tags.NAME);
|
||||||
|
String activityType = attributes.getValue(Tags.TYPE);
|
||||||
|
Activity activity = new Activity(activityId, activityName, activityType);
|
||||||
|
this.parameterizedElement = activity;
|
||||||
|
this.activityStack.push(activity);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Tags.ACTION:
|
||||||
|
|
||||||
|
// Action Id="action_1" Name="Action 1" ResourceId="dummyId" ResourceType="dummyType" State="CREATED" Type="Use"
|
||||||
|
|
||||||
|
String actionId = attributes.getValue(Tags.ID);
|
||||||
|
String actionName = attributes.getValue(Tags.NAME);
|
||||||
|
String actionType = attributes.getValue(Tags.TYPE);
|
||||||
|
String actionResourceId = attributes.getValue(Tags.RESOURCE_ID);
|
||||||
|
String actionResourceType = attributes.getValue(Tags.RESOURCE_TYPE);
|
||||||
|
String actionState = attributes.getValue(Tags.STATE);
|
||||||
|
Action action = new Action(actionId, actionName, actionType);
|
||||||
|
action.setResourceId(actionResourceId);
|
||||||
|
action.setResourceType(actionResourceType);
|
||||||
|
action.setState(State.valueOf(actionState));
|
||||||
|
|
||||||
|
this.activityStack.peek().addElement(action);
|
||||||
|
this.parameterizedElement = action;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Tags.VALUE_CHANGE:
|
||||||
|
|
||||||
|
// ValueChange StateId="dummyId" Time="2012-11-30T18:12:05.628+01:00" Value="5" ValueClass="Integer"
|
||||||
|
|
||||||
|
String valueChangeStateId = attributes.getValue(Tags.STATE_ID);
|
||||||
|
String valueChangeTimeS = attributes.getValue(Tags.TIME);
|
||||||
|
String valueChangeValue = attributes.getValue(Tags.VALUE);
|
||||||
|
String valueChangeType = attributes.getValue(Tags.TYPE);
|
||||||
|
|
||||||
|
IValue<?> value = StrolchValueType.parse(valueChangeType).valueInstance(valueChangeValue);
|
||||||
|
long valueChangeTime = ISO8601FormatFactory.getInstance().getDateFormat().parse(valueChangeTimeS).getTime();
|
||||||
|
ValueChange<IValue<?>> valueChange = new ValueChange<IValue<?>>(valueChangeTime, value);
|
||||||
|
valueChange.setStateId(valueChangeStateId);
|
||||||
|
|
||||||
|
((Action) this.parameterizedElement).addChange(valueChange);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Tags.ORDER:
|
case Tags.ORDER:
|
||||||
|
@ -122,6 +158,7 @@ public class XmlModelSaxReader extends DefaultHandler {
|
||||||
order.setState(orderState);
|
order.setState(orderState);
|
||||||
}
|
}
|
||||||
this.parameterizedElement = order;
|
this.parameterizedElement = order;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Tags.PARAMETER_BAG:
|
case Tags.PARAMETER_BAG:
|
||||||
|
@ -131,12 +168,11 @@ public class XmlModelSaxReader extends DefaultHandler {
|
||||||
ParameterBag pBag = new ParameterBag(pBagId, pBagName, pBagType);
|
ParameterBag pBag = new ParameterBag(pBagId, pBagName, pBagType);
|
||||||
this.pBag = pBag;
|
this.pBag = pBag;
|
||||||
this.parameterizedElement.addParameterBag(pBag);
|
this.parameterizedElement.addParameterBag(pBag);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Tags.PARAMETER:
|
case Tags.PARAMETER:
|
||||||
|
|
||||||
// TODO refactor this code into using visitors
|
|
||||||
|
|
||||||
String paramId = attributes.getValue(Tags.ID);
|
String paramId = attributes.getValue(Tags.ID);
|
||||||
String paramName = attributes.getValue(Tags.NAME);
|
String paramName = attributes.getValue(Tags.NAME);
|
||||||
String paramType = attributes.getValue(Tags.TYPE);
|
String paramType = attributes.getValue(Tags.TYPE);
|
||||||
|
@ -149,110 +185,50 @@ public class XmlModelSaxReader extends DefaultHandler {
|
||||||
.parseBoolean(paramHiddenS);
|
.parseBoolean(paramHiddenS);
|
||||||
String paramUom = attributes.getValue(Tags.UOM);
|
String paramUom = attributes.getValue(Tags.UOM);
|
||||||
String paramInterpretation = attributes.getValue(Tags.INTERPRETATION);
|
String paramInterpretation = attributes.getValue(Tags.INTERPRETATION);
|
||||||
Parameter<?> param;
|
|
||||||
switch (paramType) {
|
StrolchValueType type = StrolchValueType.parse(paramType);
|
||||||
case StringParameter.TYPE:
|
|
||||||
param = new StringParameter(paramId, paramName, paramValue);
|
Parameter<?> param = type.parameterInstance();
|
||||||
break;
|
param.setId(paramId);
|
||||||
case IntegerParameter.TYPE:
|
param.setName(paramName);
|
||||||
param = new IntegerParameter(paramId, paramName, IntegerParameter.parseFromString(paramValue));
|
param.setValueFromString(paramValue);
|
||||||
break;
|
|
||||||
case BooleanParameter.TYPE:
|
|
||||||
param = new BooleanParameter(paramId, paramName, BooleanParameter.parseFromString(paramValue));
|
|
||||||
break;
|
|
||||||
case LongParameter.TYPE:
|
|
||||||
param = new LongParameter(paramId, paramName, LongParameter.parseFromString(paramValue));
|
|
||||||
break;
|
|
||||||
case DateParameter.TYPE:
|
|
||||||
param = new DateParameter(paramId, paramName, DateParameter.parseFromString(paramValue));
|
|
||||||
break;
|
|
||||||
case DurationParameter.TYPE:
|
|
||||||
param = new DurationParameter(paramId, paramName, DurationParameter.parseFromString(paramValue));
|
|
||||||
break;
|
|
||||||
case StringListParameter.TYPE:
|
|
||||||
param = new StringListParameter(paramId, paramName, StringListParameter.parseFromString(paramValue));
|
|
||||||
break;
|
|
||||||
case IntegerListParameter.TYPE:
|
|
||||||
param = new IntegerListParameter(paramId, paramName,
|
|
||||||
IntegerListParameter.parseFromString(paramValue));
|
|
||||||
break;
|
|
||||||
case FloatListParameter.TYPE:
|
|
||||||
param = new FloatListParameter(paramId, paramName, FloatListParameter.parseFromString(paramValue));
|
|
||||||
break;
|
|
||||||
case LongListParameter.TYPE:
|
|
||||||
param = new LongListParameter(paramId, paramName, LongListParameter.parseFromString(paramValue));
|
|
||||||
break;
|
|
||||||
case FloatParameter.TYPE:
|
|
||||||
param = new FloatParameter(paramId, paramName, FloatParameter.parseFromString(paramValue));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new UnsupportedOperationException(MessageFormat.format(
|
|
||||||
"Parameters of type {0} are not supported!", paramType)); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
param.setHidden(paramHidden);
|
param.setHidden(paramHidden);
|
||||||
param.setUom(paramUom);
|
param.setUom(paramUom);
|
||||||
param.setInterpretation(paramInterpretation);
|
param.setInterpretation(paramInterpretation);
|
||||||
param.setIndex(index);
|
param.setIndex(index);
|
||||||
|
|
||||||
this.pBag.addParameter(param);
|
this.pBag.addParameter(param);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new StrolchException("Failed to instantiate parameter " + paramId + " for bag "
|
throw new StrolchException("Failed to instantiate parameter " + paramId + " for bag "
|
||||||
+ this.pBag.getLocator() + " due to " + e.getMessage(), e);
|
+ this.pBag.getLocator() + " due to " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Tags.TIMED_STATE:
|
case Tags.TIMED_STATE:
|
||||||
|
|
||||||
String stateId = attributes.getValue(Tags.ID);
|
String stateId = attributes.getValue(Tags.ID);
|
||||||
String stateName = attributes.getValue(Tags.NAME);
|
String stateName = attributes.getValue(Tags.NAME);
|
||||||
this.stateType = attributes.getValue(Tags.TYPE);
|
String stateType = attributes.getValue(Tags.TYPE);
|
||||||
|
|
||||||
switch (this.stateType) {
|
this.stateType = StrolchValueType.parse(stateType);
|
||||||
case FloatTimedState.TYPE:
|
this.state = this.stateType.timedStateInstance();
|
||||||
this.state = new FloatTimedState(stateId, stateName);
|
this.state.setId(stateId);
|
||||||
break;
|
this.state.setName(stateName);
|
||||||
case IntegerTimedState.TYPE:
|
|
||||||
this.state = new IntegerTimedState(stateId, stateName);
|
|
||||||
break;
|
|
||||||
case BooleanTimedState.TYPE:
|
|
||||||
this.state = new BooleanTimedState(stateId, stateName);
|
|
||||||
break;
|
|
||||||
case StringSetTimedState.TYPE:
|
|
||||||
this.state = new StringSetTimedState(stateId, stateName);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Tags.VALUE:
|
case Tags.VALUE:
|
||||||
|
|
||||||
String valueTime = attributes.getValue(Tags.TIME);
|
String valueTime = attributes.getValue(Tags.TIME);
|
||||||
Date date = ISO8601FormatFactory.getInstance().parseDate(valueTime);
|
Date date = ISO8601FormatFactory.getInstance().parseDate(valueTime);
|
||||||
long time = date.getTime();
|
long time = date.getTime();
|
||||||
String valueValue = attributes.getValue(Tags.VALUE);
|
String valueValue = attributes.getValue(Tags.VALUE);
|
||||||
switch (this.stateType) {
|
|
||||||
case FloatTimedState.TYPE:
|
|
||||||
((FloatTimedState) this.state).getTimeEvolution().setValueAt(time, new FloatValue(valueValue));
|
|
||||||
break;
|
|
||||||
case IntegerTimedState.TYPE:
|
|
||||||
((IntegerTimedState) this.state).getTimeEvolution().setValueAt(time, new IntegerValue(valueValue));
|
|
||||||
break;
|
|
||||||
case BooleanTimedState.TYPE:
|
|
||||||
((BooleanTimedState) this.state).getTimeEvolution().setValueAt(time, new BooleanValue(valueValue));
|
|
||||||
break;
|
|
||||||
case StringSetTimedState.TYPE:
|
|
||||||
|
|
||||||
Set<AString> value = new HashSet<>();
|
this.state.setStateFromStringAt(time, valueValue);
|
||||||
String[] values = valueValue.split(",");
|
|
||||||
for (String s : values) {
|
|
||||||
value.add(new AString(s.trim()));
|
|
||||||
}
|
|
||||||
|
|
||||||
StringSetValue stringSetValue = new StringSetValue(value);
|
|
||||||
((StringSetTimedState) this.state).getTimeEvolution().setValueAt(time, stringSetValue);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -264,30 +240,58 @@ public class XmlModelSaxReader extends DefaultHandler {
|
||||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
|
||||||
switch (qName) {
|
switch (qName) {
|
||||||
case Tags.STROLCH_MODEL:
|
|
||||||
break;
|
|
||||||
case Tags.RESOURCE:
|
case Tags.RESOURCE:
|
||||||
this.listener.notifyResource((Resource) this.parameterizedElement);
|
this.listener.notifyResource((Resource) this.parameterizedElement);
|
||||||
this.statistics.nrOfResources++;
|
this.statistics.nrOfResources++;
|
||||||
this.parameterizedElement = null;
|
this.parameterizedElement = null;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Tags.ACTIVITY:
|
||||||
|
|
||||||
|
Activity activity = this.activityStack.pop();
|
||||||
|
if (this.activityStack.isEmpty()) {
|
||||||
|
this.listener.notifyActivity(activity);
|
||||||
|
this.statistics.nrOfActivities++;
|
||||||
|
}
|
||||||
|
this.parameterizedElement = null;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
case Tags.ORDER:
|
case Tags.ORDER:
|
||||||
|
|
||||||
this.listener.notifyOrder((Order) this.parameterizedElement);
|
this.listener.notifyOrder((Order) this.parameterizedElement);
|
||||||
this.statistics.nrOfOrders++;
|
this.statistics.nrOfOrders++;
|
||||||
this.parameterizedElement = null;
|
this.parameterizedElement = null;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Tags.ACTION:
|
||||||
|
|
||||||
|
this.parameterizedElement = null;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
case Tags.PARAMETER_BAG:
|
case Tags.PARAMETER_BAG:
|
||||||
|
|
||||||
this.pBag = null;
|
this.pBag = null;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case Tags.PARAMETER:
|
|
||||||
break;
|
|
||||||
case Tags.INCLUDE_FILE:
|
|
||||||
break;
|
|
||||||
case Tags.TIMED_STATE:
|
case Tags.TIMED_STATE:
|
||||||
|
|
||||||
((Resource) this.parameterizedElement).addTimedState(this.state);
|
((Resource) this.parameterizedElement).addTimedState(this.state);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Tags.PARAMETER:
|
||||||
|
case Tags.INCLUDE_FILE:
|
||||||
case Tags.VALUE:
|
case Tags.VALUE:
|
||||||
|
case Tags.VALUE_CHANGE:
|
||||||
|
case Tags.STROLCH_MODEL:
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$
|
throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,10 +86,14 @@ import li.strolch.model.visitor.OrderDeepEqualsVisitor;
|
||||||
import li.strolch.model.visitor.ResourceDeepEqualsVisitor;
|
import li.strolch.model.visitor.ResourceDeepEqualsVisitor;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@SuppressWarnings("nls")
|
@SuppressWarnings("nls")
|
||||||
public class ModelTest {
|
public class ModelTest {
|
||||||
|
|
||||||
|
protected static final Logger logger = LoggerFactory.getLogger(ModelTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateResource() {
|
public void shouldCreateResource() {
|
||||||
|
|
||||||
|
|
|
@ -18,12 +18,13 @@ package li.strolch.model;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import li.strolch.model.visitor.OrderDeepEqualsVisitor;
|
import li.strolch.model.visitor.OrderDeepEqualsVisitor;
|
||||||
import li.strolch.model.visitor.ResourceDeepEqualsVisitor;
|
import li.strolch.model.visitor.ResourceDeepEqualsVisitor;
|
||||||
|
import li.strolch.model.xml.OrderFromDomVisitor;
|
||||||
import li.strolch.model.xml.OrderToDomVisitor;
|
import li.strolch.model.xml.OrderToDomVisitor;
|
||||||
|
import li.strolch.model.xml.ResourceFromDomVisitor;
|
||||||
import li.strolch.model.xml.ResourceToDomVisitor;
|
import li.strolch.model.xml.ResourceToDomVisitor;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
@ -40,8 +41,7 @@ public class XmlToDomTest extends ModelTest {
|
||||||
domVisitor.visit(order);
|
domVisitor.visit(order);
|
||||||
Document document = domVisitor.getDocument();
|
Document document = domVisitor.getDocument();
|
||||||
|
|
||||||
Element rootElement = document.getDocumentElement();
|
Order parsedOrder = new OrderFromDomVisitor().visit(document);
|
||||||
Order parsedOrder = new Order(rootElement);
|
|
||||||
|
|
||||||
OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(order);
|
OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(order);
|
||||||
visitor.visit(parsedOrder);
|
visitor.visit(parsedOrder);
|
||||||
|
@ -57,8 +57,7 @@ public class XmlToDomTest extends ModelTest {
|
||||||
domVisitor.visit(resource);
|
domVisitor.visit(resource);
|
||||||
Document document = domVisitor.getDocument();
|
Document document = domVisitor.getDocument();
|
||||||
|
|
||||||
Element rootElement = document.getDocumentElement();
|
Resource parsedResource = new ResourceFromDomVisitor().visit(document);
|
||||||
Resource parsedResource = new Resource(rootElement);
|
|
||||||
|
|
||||||
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(resource);
|
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(resource);
|
||||||
visitor.visit(parsedResource);
|
visitor.visit(parsedResource);
|
||||||
|
|
|
@ -18,6 +18,7 @@ import javax.xml.transform.stream.StreamResult;
|
||||||
import li.strolch.model.timevalue.IValueChange;
|
import li.strolch.model.timevalue.IValueChange;
|
||||||
import li.strolch.model.timevalue.impl.IntegerValue;
|
import li.strolch.model.timevalue.impl.IntegerValue;
|
||||||
import li.strolch.model.timevalue.impl.ValueChange;
|
import li.strolch.model.timevalue.impl.ValueChange;
|
||||||
|
import li.strolch.model.xml.ActivityToDomVisitor;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -76,7 +77,7 @@ public class ActionTest {
|
||||||
|
|
||||||
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||||
Document document = db.newDocument();
|
Document document = db.newDocument();
|
||||||
Element dom = this.action.toDom(document);
|
Element dom = new ActivityToDomVisitor().toDom(this.action);
|
||||||
document.appendChild(dom);
|
document.appendChild(dom);
|
||||||
|
|
||||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||||
|
|
|
@ -13,6 +13,7 @@ import javax.xml.transform.stream.StreamResult;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.State;
|
import li.strolch.model.State;
|
||||||
|
import li.strolch.model.xml.ActivityToDomVisitor;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -128,7 +129,7 @@ public class ActivityTest {
|
||||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||||
Document document = db.newDocument();
|
Document document = db.newDocument();
|
||||||
Element dom = this.activity.toDom(document);
|
Element dom = new ActivityToDomVisitor().toDom(this.activity);
|
||||||
document.appendChild(dom);
|
document.appendChild(dom);
|
||||||
|
|
||||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||||
|
|
|
@ -1,12 +1,108 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<StrolchModel>
|
<StrolchModel>
|
||||||
|
|
||||||
<Activity Id="activity" Name="Activity" Type="parentType">
|
<Activity Id="activity_1" Name="Activity" Type="parentType">
|
||||||
<Action Id="action_1" Name="Action 1" ResourceId="dummyId" ResourceType="dummyType" State="CREATED" Type="Use" />
|
<Action Id="action_1" Name="Action 1" ResourceId="dummyId" ResourceType="dummyType" State="CREATED" Type="Use">
|
||||||
|
<ValueChange StateId="dummyId" Time="2012-11-30T18:12:05.628+01:00" Value="5" Type="Integer" />
|
||||||
|
</Action>
|
||||||
<Activity Id="child_activity" Name="Child Activity" Type="childType">
|
<Activity Id="child_activity" Name="Child Activity" Type="childType">
|
||||||
<Action Id="action_2" Name="Action 2" ResourceId="dummyId" ResourceType="dummyType" State="PLANNED" Type="Use" />
|
<Action Id="action_2" Name="Action 2" ResourceId="dummyId" ResourceType="dummyType" State="PLANNED" Type="Use" />
|
||||||
<Action Id="action_3" Name="Action 3" ResourceId="dummyId" ResourceType="dummyType" State="CREATED" Type="Use" />
|
<Action Id="action_3" Name="Action 3" ResourceId="dummyId" ResourceType="dummyType" State="CREATED" Type="Use" />
|
||||||
</Activity>
|
</Activity>
|
||||||
</Activity>
|
</Activity>
|
||||||
|
|
||||||
|
<Activity Id="activity_2" Name="Activity" Type="parentType">
|
||||||
|
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
||||||
|
<Parameter Id="@param8" Name="Duration Param" Type="Duration" Value="P1D" />
|
||||||
|
<Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" />
|
||||||
|
<Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" />
|
||||||
|
<Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" />
|
||||||
|
<Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" />
|
||||||
|
<Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" />
|
||||||
|
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
|
||||||
|
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
|
||||||
|
</ParameterBag>
|
||||||
|
<Action Id="action_1" Name="Action 1" ResourceId="dummyId" ResourceType="dummyType" State="CREATED" Type="Use">
|
||||||
|
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
||||||
|
<Parameter Id="@param8" Name="Duration Param" Type="Duration" Value="P1D" />
|
||||||
|
<Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" />
|
||||||
|
<Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" />
|
||||||
|
<Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" />
|
||||||
|
<Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" />
|
||||||
|
<Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" />
|
||||||
|
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
|
||||||
|
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
|
||||||
|
</ParameterBag>
|
||||||
|
</Action>
|
||||||
|
<Activity Id="child_activity" Name="Child Activity" Type="childType">
|
||||||
|
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
||||||
|
<Parameter Id="@param8" Name="Duration Param" Type="Duration" Value="P1D" />
|
||||||
|
<Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" />
|
||||||
|
<Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" />
|
||||||
|
<Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" />
|
||||||
|
<Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" />
|
||||||
|
<Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" />
|
||||||
|
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
|
||||||
|
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
|
||||||
|
</ParameterBag>
|
||||||
|
<Action Id="action_2" Name="Action 2" ResourceId="dummyId" ResourceType="dummyType" State="PLANNED" Type="Use">
|
||||||
|
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
||||||
|
<Parameter Id="@param8" Name="Duration Param" Type="Duration" Value="P1D" />
|
||||||
|
<Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" />
|
||||||
|
<Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" />
|
||||||
|
<Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" />
|
||||||
|
<Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" />
|
||||||
|
<Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" />
|
||||||
|
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
|
||||||
|
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
|
||||||
|
</ParameterBag>
|
||||||
|
</Action>
|
||||||
|
<Action Id="action_3" Name="Action 3" ResourceId="dummyId" ResourceType="dummyType" State="CREATED" Type="Use">
|
||||||
|
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
||||||
|
<Parameter Id="@param8" Name="Duration Param" Type="Duration" Value="P1D" />
|
||||||
|
<Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" />
|
||||||
|
<Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" />
|
||||||
|
<Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" />
|
||||||
|
<Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" />
|
||||||
|
<Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" />
|
||||||
|
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
|
||||||
|
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
|
||||||
|
</ParameterBag>
|
||||||
|
</Action>
|
||||||
|
</Activity>
|
||||||
|
</Activity>
|
||||||
|
|
||||||
|
<Activity Id="activity_3" Name="Activity" Type="parentType">
|
||||||
|
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
||||||
|
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
|
||||||
|
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
|
||||||
|
</ParameterBag>
|
||||||
|
<Action Id="action_1" Name="Action 1" ResourceId="dummyId" ResourceType="dummyType" State="CREATED" Type="Use">
|
||||||
|
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
||||||
|
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
|
||||||
|
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
|
||||||
|
</ParameterBag>
|
||||||
|
</Action>
|
||||||
|
<Activity Id="child_activity" Name="Child Activity" Type="childType">
|
||||||
|
<Action Id="action_2" Name="Action 2" ResourceId="dummyId" ResourceType="dummyType" State="PLANNED" Type="Use">
|
||||||
|
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
||||||
|
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
|
||||||
|
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
|
||||||
|
</ParameterBag>
|
||||||
|
</Action>
|
||||||
|
<Activity Id="child_child_activity" Name="Child Activity" Type="childType">
|
||||||
|
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
||||||
|
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
|
||||||
|
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
|
||||||
|
</ParameterBag>
|
||||||
|
<Action Id="action_3" Name="Action 3" ResourceId="dummyId" ResourceType="dummyType" State="CREATED" Type="Use">
|
||||||
|
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
||||||
|
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
|
||||||
|
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
|
||||||
|
</ParameterBag>
|
||||||
|
</Action>
|
||||||
|
</Activity>
|
||||||
|
</Activity>
|
||||||
|
</Activity>
|
||||||
|
|
||||||
</StrolchModel>
|
</StrolchModel>
|
|
@ -14,12 +14,12 @@
|
||||||
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
|
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
|
||||||
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
|
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
|
||||||
</ParameterBag>
|
</ParameterBag>
|
||||||
<TimedState Id="@booleanState" Name="Boolean State" Type="BooleanState">
|
<TimedState Id="@booleanState" Name="Boolean State" Type="Boolean">
|
||||||
<Value Time="1970-01-01T00:00:00.000+01:00" Value="false" />
|
<Value Time="1970-01-01T00:00:00.000+01:00" Value="false" />
|
||||||
<Value Time="1970-01-01T00:01:00.000+01:00" Value="true" />
|
<Value Time="1970-01-01T00:01:00.000+01:00" Value="true" />
|
||||||
<Value Time="1970-01-01T00:02:00.000+01:00" Value="false" />
|
<Value Time="1970-01-01T00:02:00.000+01:00" Value="false" />
|
||||||
</TimedState>
|
</TimedState>
|
||||||
<TimedState Id="@integerState" Name="Integer State" Type="IntegerState">
|
<TimedState Id="@integerState" Name="Integer State" Type="Integer">
|
||||||
<Value Time="1970-01-01T00:00:00.000+01:00" Value="1" />
|
<Value Time="1970-01-01T00:00:00.000+01:00" Value="1" />
|
||||||
<Value Time="1970-01-01T00:01:00.000+01:00" Value="2" />
|
<Value Time="1970-01-01T00:01:00.000+01:00" Value="2" />
|
||||||
<Value Time="1970-01-01T00:02:00.000+01:00" Value="3" />
|
<Value Time="1970-01-01T00:02:00.000+01:00" Value="3" />
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
<Value Time="1970-01-01T00:04:00.000+01:00" Value="1" />
|
<Value Time="1970-01-01T00:04:00.000+01:00" Value="1" />
|
||||||
<Value Time="1970-01-01T00:05:00.000+01:00" Value="0" />
|
<Value Time="1970-01-01T00:05:00.000+01:00" Value="0" />
|
||||||
</TimedState>
|
</TimedState>
|
||||||
<TimedState Id="@floatState" Name="Float State" Type="FloatState">
|
<TimedState Id="@floatState" Name="Float State" Type="Float">
|
||||||
<Value Time="1970-01-01T00:00:00.000+01:00" Value="1.1" />
|
<Value Time="1970-01-01T00:00:00.000+01:00" Value="1.1" />
|
||||||
<Value Time="1970-01-01T00:01:00.000+01:00" Value="2.2" />
|
<Value Time="1970-01-01T00:01:00.000+01:00" Value="2.2" />
|
||||||
<Value Time="1970-01-01T00:02:00.000+01:00" Value="3.3" />
|
<Value Time="1970-01-01T00:02:00.000+01:00" Value="3.3" />
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
<Value Time="1970-01-01T00:04:00.000+01:00" Value="1.1" />
|
<Value Time="1970-01-01T00:04:00.000+01:00" Value="1.1" />
|
||||||
<Value Time="1970-01-01T00:05:00.000+01:00" Value="0.0" />
|
<Value Time="1970-01-01T00:05:00.000+01:00" Value="0.0" />
|
||||||
</TimedState>
|
</TimedState>
|
||||||
<TimedState Id="@stringSetState" Name="StringSet State" Type="StringSetState">
|
<TimedState Id="@stringSetState" Name="StringSet State" Type="StringSet">
|
||||||
<Value Time="1970-01-01T00:00:00.000+01:00" Value="foo" />
|
<Value Time="1970-01-01T00:00:00.000+01:00" Value="foo" />
|
||||||
<Value Time="1970-01-01T00:01:00.000+01:00" Value="foo, bar" />
|
<Value Time="1970-01-01T00:01:00.000+01:00" Value="foo, bar" />
|
||||||
<Value Time="1970-01-01T00:02:00.000+01:00" Value="bar" />
|
<Value Time="1970-01-01T00:02:00.000+01:00" Value="bar" />
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.command;
|
package li.strolch.command;
|
||||||
|
|
||||||
|
import li.strolch.agent.api.ActivityMap;
|
||||||
import li.strolch.agent.api.ComponentContainer;
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.agent.api.OrderMap;
|
import li.strolch.agent.api.OrderMap;
|
||||||
import li.strolch.agent.api.ResourceMap;
|
import li.strolch.agent.api.ResourceMap;
|
||||||
|
@ -30,6 +31,7 @@ public class ClearModelCommand extends Command {
|
||||||
// input
|
// input
|
||||||
private boolean clearOrders;
|
private boolean clearOrders;
|
||||||
private boolean clearResources;
|
private boolean clearResources;
|
||||||
|
private boolean clearActivities;
|
||||||
|
|
||||||
// output
|
// output
|
||||||
private ModelStatistics statistics;
|
private ModelStatistics statistics;
|
||||||
|
@ -62,6 +64,11 @@ public class ClearModelCommand extends Command {
|
||||||
statistics.nrOfResources = resourceMap.removeAll(tx());
|
statistics.nrOfResources = resourceMap.removeAll(tx());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.clearActivities) {
|
||||||
|
ActivityMap activitiesMap = tx().getActivityMap();
|
||||||
|
statistics.nrOfActivities = activitiesMap.removeAll(tx());
|
||||||
|
}
|
||||||
|
|
||||||
this.statistics = statistics;
|
this.statistics = statistics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,6 +93,14 @@ public class ClearModelCommand extends Command {
|
||||||
this.clearResources = clearResources;
|
this.clearResources = clearResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param clearActivities
|
||||||
|
* the clearActivities to set
|
||||||
|
*/
|
||||||
|
public void setClearActivities(boolean clearActivities) {
|
||||||
|
this.clearActivities = clearActivities;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the statistics
|
* @return the statistics
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -34,16 +34,19 @@ import javax.xml.stream.XMLOutputFactory;
|
||||||
import javax.xml.stream.XMLStreamException;
|
import javax.xml.stream.XMLStreamException;
|
||||||
import javax.xml.stream.XMLStreamWriter;
|
import javax.xml.stream.XMLStreamWriter;
|
||||||
|
|
||||||
|
import li.strolch.agent.api.ActivityMap;
|
||||||
import li.strolch.agent.api.ComponentContainer;
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.agent.api.OrderMap;
|
import li.strolch.agent.api.OrderMap;
|
||||||
import li.strolch.agent.api.ResourceMap;
|
import li.strolch.agent.api.ResourceMap;
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
|
import li.strolch.model.ActivityVisitor;
|
||||||
import li.strolch.model.ModelStatistics;
|
import li.strolch.model.ModelStatistics;
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
import li.strolch.model.OrderVisitor;
|
import li.strolch.model.OrderVisitor;
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
import li.strolch.model.ResourceVisitor;
|
import li.strolch.model.ResourceVisitor;
|
||||||
import li.strolch.model.Tags;
|
import li.strolch.model.Tags;
|
||||||
|
import li.strolch.model.activity.Activity;
|
||||||
import li.strolch.model.xml.OrderToSaxWriterVisitor;
|
import li.strolch.model.xml.OrderToSaxWriterVisitor;
|
||||||
import li.strolch.model.xml.ResourceToSaxWriterVisitor;
|
import li.strolch.model.xml.ResourceToSaxWriterVisitor;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
|
@ -262,6 +265,17 @@ public class XmlExportModelCommand extends Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void writeActivitiesByType(XMLStreamWriter writer, ActivityMap activityMap, String type) {
|
||||||
|
ActivityVisitor<?> visitor = new ActivityToSaxWriterVisitor(writer);
|
||||||
|
Set<String> keysByType = new TreeSet<>(activityMap.getKeysBy(tx(), type));
|
||||||
|
for (String id : keysByType) {
|
||||||
|
Activity activity = activityMap.getBy(tx(), type, id);
|
||||||
|
visitor.visit(activity);
|
||||||
|
this.statistics.nrOfActivities++;
|
||||||
|
logElementsWritten();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private XMLStreamWriter openXmlStreamWriter(FileOutputStream out) throws FactoryConfigurationError,
|
private XMLStreamWriter openXmlStreamWriter(FileOutputStream out) throws FactoryConfigurationError,
|
||||||
XMLStreamException {
|
XMLStreamException {
|
||||||
XMLOutputFactory factory = XMLOutputFactory.newInstance();
|
XMLOutputFactory factory = XMLOutputFactory.newInstance();
|
||||||
|
|
Loading…
Reference in New Issue