Fefactored xml parsing and writing to no longer depend on JDom. Now
only basic Java XML is used.
This commit is contained in:
parent
39e2eee613
commit
487ad3e826
7
pom.xml
7
pom.xml
|
@ -96,13 +96,6 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Reading XML -->
|
||||
<dependency>
|
||||
<groupId>dom4j</groupId>
|
||||
<artifactId>dom4j</artifactId>
|
||||
<version>1.6</version>
|
||||
</dependency>
|
||||
|
||||
<!-- testing -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
|
|
@ -24,7 +24,7 @@ package li.strolch.model;
|
|||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.Locator.LocatorBuilder;
|
||||
|
||||
import org.dom4j.Element;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
|
@ -113,9 +113,9 @@ public abstract class AbstractStrolchElement implements StrolchElement {
|
|||
}
|
||||
|
||||
protected void fillElement(Element element) {
|
||||
element.addAttribute("Id", getId());
|
||||
element.addAttribute("Name", getName());
|
||||
element.addAttribute("Type", getType());
|
||||
element.setAttribute("Id", getId());
|
||||
element.setAttribute("Name", getName());
|
||||
element.setAttribute("Type", getType());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -124,14 +124,14 @@ public abstract class AbstractStrolchElement implements StrolchElement {
|
|||
* @param element
|
||||
*/
|
||||
protected void fromDom(Element element) {
|
||||
String id = element.attributeValue("Id");
|
||||
String name = element.attributeValue("Name");
|
||||
String id = element.getAttribute("Id");
|
||||
String name = element.getAttribute("Name");
|
||||
|
||||
if (id != null && name != null) {
|
||||
setId(id);
|
||||
setName(name);
|
||||
} else {
|
||||
throw new StrolchException("Check the values of the element: " + element.getName()
|
||||
throw new StrolchException("Check the values of the element: " + element.getNodeName()
|
||||
+ " either id or name attribute is null!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,14 +24,14 @@ package li.strolch.model;
|
|||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
|
||||
import org.dom4j.Element;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import ch.eitchnet.utils.helper.StringHelper;
|
||||
|
||||
|
@ -222,16 +222,15 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void fromDom(Element element) {
|
||||
super.fromDom(element);
|
||||
|
||||
String type = element.attributeValue("Type");
|
||||
String type = element.getAttribute("Type");
|
||||
setType(type);
|
||||
|
||||
List<Element> bags = element.elements("ParameterBag");
|
||||
for (Element bagElement : bags) {
|
||||
|
||||
NodeList bags = element.getElementsByTagName("ParameterBag");
|
||||
for (int i = 0; i < bags.getLength(); i++) {
|
||||
Element bagElement = (Element) bags.item(i);
|
||||
ParameterBag bag = new ParameterBag(bagElement);
|
||||
addParameterBag(bag);
|
||||
}
|
||||
|
@ -243,7 +242,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
|
|||
|
||||
if (this.parameterBagMap != null) {
|
||||
for (ParameterBag bag : this.parameterBagMap.values()) {
|
||||
element.add(bag.toDom());
|
||||
element.appendChild(bag.toDom(element.getOwnerDocument()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
|
||||
import li.strolch.exception.StrolchException;
|
||||
|
||||
import ch.eitchnet.utils.helper.StringHelper;
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,10 +21,10 @@
|
|||
*/
|
||||
package li.strolch.model;
|
||||
|
||||
import li.strolch.model.Locator.LocatorBuilder;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.tree.DefaultElement;
|
||||
import li.strolch.model.Locator.LocatorBuilder;
|
||||
|
||||
/**
|
||||
* The Order is an object used in the EDF to transfer data from one range to another. Orders are not to be thought of as
|
||||
|
@ -91,8 +91,8 @@ public class Order extends GroupedParameterizedElement {
|
|||
public Order(Element element) {
|
||||
super.fromDom(element);
|
||||
|
||||
String date = element.attributeValue("Date");
|
||||
String state = element.attributeValue("State");
|
||||
String date = element.getAttribute("Date");
|
||||
String state = element.getAttribute("State");
|
||||
|
||||
// TODO the format should be globally configured
|
||||
if (date == null || date.isEmpty()) {
|
||||
|
@ -139,17 +139,17 @@ public class Order extends GroupedParameterizedElement {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see li.strolch.StrolchElement.datalandscape.element.IEdpElement#toDom()
|
||||
* @see li.strolch.StrolchElement.datalandscape.element.IEdpElement#toDom(Document)
|
||||
*/
|
||||
@Override
|
||||
public Element toDom() {
|
||||
public Element toDom(Document doc) {
|
||||
|
||||
Element orderElement = new DefaultElement("Order");
|
||||
Element orderElement = doc.createElement("Order");
|
||||
fillElement(orderElement);
|
||||
|
||||
// TODO the format should be globally configured
|
||||
orderElement.addAttribute("Date", Long.toString(this.date));
|
||||
orderElement.addAttribute("State", this.state.toString());
|
||||
orderElement.setAttribute("Date", Long.toString(this.date));
|
||||
orderElement.setAttribute("State", this.state.toString());
|
||||
|
||||
return orderElement;
|
||||
}
|
||||
|
|
|
@ -21,8 +21,9 @@
|
|||
*/
|
||||
package li.strolch.model;
|
||||
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.tree.DefaultElement;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
|
@ -65,9 +66,9 @@ public class ParameterBag extends ParameterizedElement {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Element toDom() {
|
||||
public Element toDom(Document doc) {
|
||||
|
||||
Element element = new DefaultElement("ParameterBag");
|
||||
Element element = doc.createElement("ParameterBag");
|
||||
|
||||
fillElement(element);
|
||||
|
||||
|
|
|
@ -39,7 +39,8 @@ import li.strolch.model.parameter.LongParameter;
|
|||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
|
||||
import org.dom4j.Element;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import ch.eitchnet.utils.helper.StringHelper;
|
||||
|
||||
|
@ -207,15 +208,14 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
|
|||
protected void fromDom(Element element) {
|
||||
super.fromDom(element);
|
||||
|
||||
String type = element.attributeValue("Type");
|
||||
String type = element.getAttribute("Type");
|
||||
setType(type);
|
||||
|
||||
// add all the parameters
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Element> parameterElements = element.elements("Parameter");
|
||||
for (Object object : parameterElements) {
|
||||
Element paramElement = (Element) object;
|
||||
String paramtype = paramElement.attributeValue("Type");
|
||||
NodeList parameterElements = element.getElementsByTagName("Parameter");
|
||||
for (int i = 0; i < parameterElements.getLength(); i++) {
|
||||
Element paramElement = (Element) parameterElements.item(i);
|
||||
String paramtype = paramElement.getAttribute("Type");
|
||||
|
||||
if (paramtype.equals(StringParameter.TYPE)) {
|
||||
StringParameter param = new StringParameter(paramElement);
|
||||
|
@ -247,7 +247,7 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
|
|||
|
||||
if (this.parameterMap != null) {
|
||||
for (Parameter<?> parameter : this.parameterMap.values()) {
|
||||
element.add(parameter.toDom());
|
||||
element.appendChild(parameter.toDom(element.getOwnerDocument()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,10 +21,10 @@
|
|||
*/
|
||||
package li.strolch.model;
|
||||
|
||||
import li.strolch.model.Locator.LocatorBuilder;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.tree.DefaultElement;
|
||||
import li.strolch.model.Locator.LocatorBuilder;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
|
@ -62,9 +62,9 @@ public class Resource extends GroupedParameterizedElement {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Element toDom() {
|
||||
public Element toDom(Document doc) {
|
||||
|
||||
Element element = new DefaultElement("Resource");
|
||||
Element element = doc.createElement("Resource");
|
||||
fillElement(element);
|
||||
|
||||
return element;
|
||||
|
|
|
@ -23,7 +23,8 @@ package li.strolch.model;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.dom4j.Element;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
|
@ -85,9 +86,13 @@ public interface StrolchElement extends Serializable, Comparable<StrolchElement>
|
|||
/**
|
||||
* Returns a dom4j {@link Element} object which is an XML representation of this object
|
||||
*
|
||||
* @param doc
|
||||
* the document to which this element is being written. The client should not append to the document, the
|
||||
* caller will perform this as needed
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Element toDom();
|
||||
public Element toDom(Document doc);
|
||||
|
||||
/**
|
||||
* Returns the type of this {@link StrolchElement}
|
||||
|
|
|
@ -21,15 +21,14 @@
|
|||
*/
|
||||
package li.strolch.model.parameter;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.AbstractStrolchElement;
|
||||
import li.strolch.model.Locator;
|
||||
import li.strolch.model.Locator.LocatorBuilder;
|
||||
import li.strolch.model.ParameterizedElement;
|
||||
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.tree.DefaultElement;
|
||||
|
||||
import ch.eitchnet.utils.helper.StringHelper;
|
||||
|
||||
/**
|
||||
|
@ -113,18 +112,18 @@ public abstract class AbstractParameter<T> extends AbstractStrolchElement implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public Element toDom() {
|
||||
Element element = new DefaultElement("Parameter");
|
||||
public Element toDom(Document doc) {
|
||||
Element element = doc.createElement("Parameter");
|
||||
fillElement(element);
|
||||
|
||||
element.addAttribute("Value", getValueAsString());
|
||||
element.setAttribute("Value", getValueAsString());
|
||||
|
||||
if (!this.interpretation.equals(Parameter.INTERPRETATION_NONE))
|
||||
element.addAttribute("Interpretation", this.interpretation);
|
||||
element.setAttribute("Interpretation", this.interpretation);
|
||||
if (!this.uom.equals(Parameter.UOM_NONE))
|
||||
element.addAttribute("Uom", this.uom);
|
||||
element.setAttribute("Uom", this.uom);
|
||||
if (this.hidden)
|
||||
element.addAttribute("Hidden", Boolean.toString(this.hidden));
|
||||
element.setAttribute("Hidden", Boolean.toString(this.hidden));
|
||||
|
||||
return element;
|
||||
}
|
||||
|
@ -134,16 +133,16 @@ public abstract class AbstractParameter<T> extends AbstractStrolchElement implem
|
|||
|
||||
super.fromDom(element);
|
||||
|
||||
String typeS = element.attributeValue("Type");
|
||||
String typeS = element.getAttribute("Type");
|
||||
if (StringHelper.isEmpty(typeS)) {
|
||||
throw new StrolchException("Type must be set on element with id " + this.id);
|
||||
} else if (!typeS.equals(getType())) {
|
||||
throw new StrolchException(getClass().getSimpleName() + " must have type " + getType() + ", not: " + typeS);
|
||||
}
|
||||
|
||||
String interpretation = element.attributeValue("Interpretation");
|
||||
String isHidden = element.attributeValue("Hidden");
|
||||
String uom = element.attributeValue("Uom");
|
||||
String interpretation = element.getAttribute("Interpretation");
|
||||
String isHidden = element.getAttribute("Hidden");
|
||||
String uom = element.getAttribute("Uom");
|
||||
|
||||
setInterpretation(interpretation);
|
||||
setUom(uom);
|
||||
|
|
|
@ -21,10 +21,9 @@
|
|||
*/
|
||||
package li.strolch.model.parameter;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import li.strolch.exception.StrolchException;
|
||||
|
||||
import org.dom4j.Element;
|
||||
|
||||
import ch.eitchnet.utils.helper.StringHelper;
|
||||
|
||||
/**
|
||||
|
@ -64,7 +63,7 @@ public class BooleanParameter extends AbstractParameter<Boolean> {
|
|||
public BooleanParameter(Element element) {
|
||||
super.fromDom(element);
|
||||
|
||||
String valueS = element.attributeValue("Value");
|
||||
String valueS = element.getAttribute("Value");
|
||||
if (StringHelper.isEmpty(valueS)) {
|
||||
throw new StrolchException("No value defined for " + this.id);
|
||||
}
|
||||
|
|
|
@ -23,10 +23,9 @@ package li.strolch.model.parameter;
|
|||
|
||||
import java.text.DateFormat;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import li.strolch.exception.StrolchException;
|
||||
|
||||
import org.dom4j.Element;
|
||||
|
||||
import ch.eitchnet.utils.helper.StringHelper;
|
||||
|
||||
/**
|
||||
|
@ -66,7 +65,7 @@ public class DateParameter extends AbstractParameter<Long> {
|
|||
public DateParameter(Element element) {
|
||||
super.fromDom(element);
|
||||
|
||||
String valueS = element.attributeValue("Value");
|
||||
String valueS = element.getAttribute("Value");
|
||||
if (StringHelper.isEmpty(valueS)) {
|
||||
throw new StrolchException("No value defined for " + this.id);
|
||||
}
|
||||
|
|
|
@ -21,10 +21,9 @@
|
|||
*/
|
||||
package li.strolch.model.parameter;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import li.strolch.exception.StrolchException;
|
||||
|
||||
import org.dom4j.Element;
|
||||
|
||||
import ch.eitchnet.utils.helper.StringHelper;
|
||||
|
||||
/**
|
||||
|
@ -66,7 +65,7 @@ public class FloatParameter extends AbstractParameter<Double> {
|
|||
public FloatParameter(Element element) {
|
||||
super.fromDom(element);
|
||||
|
||||
String valueS = element.attributeValue("Value");
|
||||
String valueS = element.getAttribute("Value");
|
||||
if (StringHelper.isEmpty(valueS)) {
|
||||
throw new StrolchException("No value defined for " + this.id);
|
||||
}
|
||||
|
|
|
@ -21,10 +21,9 @@
|
|||
*/
|
||||
package li.strolch.model.parameter;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import li.strolch.exception.StrolchException;
|
||||
|
||||
import org.dom4j.Element;
|
||||
|
||||
import ch.eitchnet.utils.helper.StringHelper;
|
||||
|
||||
/**
|
||||
|
@ -65,7 +64,7 @@ public class IntegerParameter extends AbstractParameter<Integer> {
|
|||
public IntegerParameter(Element element) {
|
||||
super.fromDom(element);
|
||||
|
||||
String valueS = element.attributeValue("Value");
|
||||
String valueS = element.getAttribute("Value");
|
||||
if (StringHelper.isEmpty(valueS)) {
|
||||
throw new StrolchException("No value defined for " + this.id);
|
||||
}
|
||||
|
|
|
@ -21,10 +21,9 @@
|
|||
*/
|
||||
package li.strolch.model.parameter;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import li.strolch.exception.StrolchException;
|
||||
|
||||
import org.dom4j.Element;
|
||||
|
||||
import ch.eitchnet.utils.helper.StringHelper;
|
||||
|
||||
/**
|
||||
|
@ -65,7 +64,7 @@ public class LongParameter extends AbstractParameter<Long> {
|
|||
public LongParameter(Element element) {
|
||||
super.fromDom(element);
|
||||
|
||||
String valueS = element.attributeValue("Value");
|
||||
String valueS = element.getAttribute("Value");
|
||||
if (StringHelper.isEmpty(valueS)) {
|
||||
throw new StrolchException("No value defined for " + this.id);
|
||||
}
|
||||
|
|
|
@ -27,11 +27,10 @@ import java.util.Collections;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.StrolchElement;
|
||||
|
||||
import org.dom4j.Element;
|
||||
|
||||
import ch.eitchnet.utils.helper.StringHelper;
|
||||
|
||||
/**
|
||||
|
@ -72,7 +71,7 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
|
|||
public StringListParameter(Element element) {
|
||||
super.fromDom(element);
|
||||
|
||||
String valueS = element.attributeValue("Value");
|
||||
String valueS = element.getAttribute("Value");
|
||||
if (StringHelper.isEmpty(valueS)) {
|
||||
throw new StrolchException("No value defined for " + this.id);
|
||||
}
|
||||
|
|
|
@ -21,10 +21,9 @@
|
|||
*/
|
||||
package li.strolch.model.parameter;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import li.strolch.exception.StrolchException;
|
||||
|
||||
import org.dom4j.Element;
|
||||
|
||||
import ch.eitchnet.utils.helper.StringHelper;
|
||||
|
||||
/**
|
||||
|
@ -66,7 +65,7 @@ public class StringParameter extends AbstractParameter<String> {
|
|||
public StringParameter(Element element) {
|
||||
super.fromDom(element);
|
||||
|
||||
String valueS = element.attributeValue("Value");
|
||||
String valueS = element.getAttribute("Value");
|
||||
if (StringHelper.isEmpty(valueS)) {
|
||||
throw new StrolchException("No value defined for " + this.id);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package li.strolch.model.timevalue.impl;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package li.strolch.model.timedstate;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import li.strolch.model.timedstate.ITimedState;
|
||||
import li.strolch.model.timedstate.TimedState;
|
||||
import li.strolch.model.timevalue.ITimeValue;
|
||||
import li.strolch.model.timevalue.IValueChange;
|
||||
import li.strolch.model.timevalue.impl.DoubleValue;
|
||||
|
|
|
@ -4,9 +4,6 @@ import java.util.Collection;
|
|||
import java.util.SortedSet;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import li.strolch.model.timevalue.ITimeValue;
|
||||
import li.strolch.model.timevalue.IValue;
|
||||
import li.strolch.model.timevalue.IValueChange;
|
||||
import li.strolch.model.timevalue.impl.DoubleValue;
|
||||
import li.strolch.model.timevalue.impl.TimeVariable;
|
||||
import li.strolch.model.timevalue.impl.ValueChange;
|
||||
|
|
|
@ -6,9 +6,6 @@ import java.util.Map;
|
|||
import java.util.SortedSet;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import li.strolch.model.timevalue.ITimeValue;
|
||||
import li.strolch.model.timevalue.IValue;
|
||||
import li.strolch.model.timevalue.IValueChange;
|
||||
import li.strolch.model.timevalue.impl.IntegerValue;
|
||||
import li.strolch.model.timevalue.impl.TimeVariable;
|
||||
import li.strolch.model.timevalue.impl.ValueChange;
|
||||
|
|
|
@ -8,9 +8,6 @@ import java.util.Set;
|
|||
import java.util.SortedSet;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import li.strolch.model.timevalue.ITimeValue;
|
||||
import li.strolch.model.timevalue.IValue;
|
||||
import li.strolch.model.timevalue.IValueChange;
|
||||
import li.strolch.model.timevalue.impl.AString;
|
||||
import li.strolch.model.timevalue.impl.StringSetValue;
|
||||
import li.strolch.model.timevalue.impl.TimeVariable;
|
||||
|
|
|
@ -5,7 +5,6 @@ import static org.junit.Assert.assertEquals;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import li.strolch.model.timevalue.IValue;
|
||||
import li.strolch.model.timevalue.impl.AString;
|
||||
import li.strolch.model.timevalue.impl.DoubleValue;
|
||||
import li.strolch.model.timevalue.impl.IntegerValue;
|
||||
|
|
Loading…
Reference in New Issue