[New][Major] Initial to JSON visitors for Resources and Orders

- added PolicyDefs to Actions
- also fixed a bug in StringSetValue().getValueAsString()
- further refactorings and clean-up
This commit is contained in:
Robert von Burg 2015-11-16 22:37:00 +01:00
parent 8e76e5658e
commit d06fe4fb04
32 changed files with 407 additions and 817 deletions

View File

@ -28,6 +28,12 @@
</scm>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>ch.eitchnet</groupId>
<artifactId>ch.eitchnet.utils</artifactId>

View File

@ -37,9 +37,9 @@ public class Order extends GroupedParameterizedElement implements StrolchRootEle
private static final long serialVersionUID = 0L;
private Date date;
private State state;
private PolicyDefs policyDefs;
protected Date date;
protected State state;
protected PolicyDefs policyDefs;
/**
* Empty constructor - for marshalling only!

View File

@ -37,8 +37,8 @@ public class Resource extends GroupedParameterizedElement implements StrolchRoot
private static final long serialVersionUID = 0L;
private Map<String, StrolchTimedState<IValue<?>>> timedStateMap;
private PolicyDefs policyDefs;
protected Map<String, StrolchTimedState<IValue<?>>> timedStateMap;
protected PolicyDefs policyDefs;
/**
* Empty constructor - for marshalling only!

View File

@ -19,22 +19,27 @@ package li.strolch.model;
public class Tags {
public static final String CDATA = "CDATA";
public static final String OBJECT_TYPE = "ObjectType";
public static final String ID = "Id";
public static final String NAME = "Name";
public static final String TYPE = "Type";
public static final String DATE = "Date";
public static final String STATE = "State";
public static final String VALUE = "Value";
public static final String VALUES = "Values";
public static final String TIME = "Time";
public static final String INTERPRETATION = "Interpretation";
public static final String UOM = "Uom";
public static final String HIDDEN = "Hidden";
public static final String INDEX = "Index";
public static final String PARAMETER = "Parameter";
public static final String PARAMETERS = "Parameters";
public static final String TIMED_STATE = "TimedState";
public static final String TIMED_STATES = "TimedStates";
public static final String PARAMETERIZED_ELEMENT = "ParameterizedElement";
public static final String RESOURCE = "Resource";
public static final String ORDER = "Order";
public static final String PARAMETER_BAGS = "ParameterBags";
public static final String PARAMETER_BAG = "ParameterBag";
public static final String STROLCH_MODEL = "StrolchModel";
public static final String INCLUDE_FILE = "IncludeFile";

View File

@ -22,12 +22,14 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import li.strolch.exception.StrolchPolicyException;
import li.strolch.model.GroupedParameterizedElement;
import li.strolch.model.Locator;
import li.strolch.model.Locator.LocatorBuilder;
import li.strolch.model.Resource;
import li.strolch.model.State;
import li.strolch.model.StrolchRootElement;
import li.strolch.model.policy.PolicyDefs;
import li.strolch.model.timevalue.IValue;
import li.strolch.model.timevalue.IValueChange;
@ -46,6 +48,7 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
protected String resourceId;
protected String resourceType;
protected State state;
protected PolicyDefs policyDefs;
protected List<IValueChange<? extends IValue<?>>> changes;
@ -186,6 +189,21 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
return clone;
}
public PolicyDefs getPolicyDefs() {
if (this.policyDefs == null)
throw new StrolchPolicyException(getLocator() + " has no Policies defined!");
return this.policyDefs;
}
public boolean hasPolicyDefs() {
return this.policyDefs != null;
}
public void setPolicyDefs(PolicyDefs policyDefs) {
this.policyDefs = policyDefs;
this.policyDefs.setParent(this);
}
@Override
public Locator getLocator() {
LocatorBuilder lb = new LocatorBuilder();

View File

@ -27,11 +27,11 @@ import li.strolch.exception.StrolchPolicyException;
import li.strolch.model.GroupedParameterizedElement;
import li.strolch.model.Locator;
import li.strolch.model.Locator.LocatorBuilder;
import li.strolch.model.policy.PolicyDefs;
import li.strolch.model.State;
import li.strolch.model.StrolchElement;
import li.strolch.model.StrolchRootElement;
import li.strolch.model.Tags;
import li.strolch.model.policy.PolicyDefs;
import li.strolch.model.visitor.StrolchRootElementVisitor;
/**
@ -47,7 +47,7 @@ public class Activity extends GroupedParameterizedElement
protected Activity parent;
protected Map<String, IActivityElement> elements;
private PolicyDefs policyDefs;
protected PolicyDefs policyDefs;
/**
* Empty constructor - for marshalling only!

View File

@ -0,0 +1,25 @@
package li.strolch.model.json;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import li.strolch.model.Order;
import li.strolch.model.OrderVisitor;
public class OrderToJsonVisitor extends StrolchElementToJsonVisitor implements OrderVisitor<JsonObject> {
@Override
public JsonObject visit(Order element) {
JsonObject rootJ = toJson(element);
return rootJ;
}
public static String toJsonString(Order element) {
OrderToJsonVisitor visitor = new OrderToJsonVisitor();
JsonObject jsonObject = visitor.visit(element);
String entity = new Gson().toJson(jsonObject);
return entity;
}
}

View File

@ -0,0 +1,25 @@
package li.strolch.model.json;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import li.strolch.model.Resource;
import li.strolch.model.ResourceVisitor;
public class ResourceToJsonVisitor extends StrolchElementToJsonVisitor implements ResourceVisitor<JsonObject> {
@Override
public JsonObject visit(Resource element) {
JsonObject rootJ = toJson(element);
return rootJ;
}
public static String toJsonString(Resource element) {
ResourceToJsonVisitor visitor = new ResourceToJsonVisitor();
JsonObject jsonObject = visitor.visit(element);
String entity = new Gson().toJson(jsonObject);
return entity;
}
}

View File

@ -0,0 +1,153 @@
package li.strolch.model.json;
import java.util.SortedSet;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
import li.strolch.model.AbstractStrolchElement;
import li.strolch.model.GroupedParameterizedElement;
import li.strolch.model.Order;
import li.strolch.model.ParameterBag;
import li.strolch.model.Resource;
import li.strolch.model.Tags;
import li.strolch.model.parameter.Parameter;
import li.strolch.model.policy.PolicyDef;
import li.strolch.model.policy.PolicyDefs;
import li.strolch.model.timedstate.StrolchTimedState;
import li.strolch.model.timevalue.ITimeValue;
import li.strolch.model.timevalue.IValue;
public class StrolchElementToJsonVisitor {
public JsonObject toJson(Resource element) {
JsonObject rootJ = new JsonObject();
rootJ.addProperty(Tags.OBJECT_TYPE, Tags.RESOURCE);
toJson(element, rootJ);
addParameterBags(element, rootJ);
addTimedStates(element, rootJ);
if (element.hasPolicyDefs())
addPolicies(element.getPolicyDefs(), rootJ);
return rootJ;
}
public JsonObject toJson(Order element) {
JsonObject rootJ = new JsonObject();
rootJ.addProperty(Tags.OBJECT_TYPE, Tags.ORDER);
toJson(element, rootJ);
rootJ.addProperty(Tags.DATE, ISO8601FormatFactory.getInstance().formatDate(element.getDate()));
rootJ.addProperty(Tags.STATE, element.getState().name());
addParameterBags(element, rootJ);
if (element.hasPolicyDefs())
addPolicies(element.getPolicyDefs(), rootJ);
return rootJ;
}
protected void addPolicies(PolicyDefs policyDefs, JsonObject rootJ) {
if (!policyDefs.hasPolicyDefs())
return;
JsonObject policyDefsJ = new JsonObject();
rootJ.add(Tags.POLICIES, policyDefsJ);
for (String type : policyDefs.getPolicyTypes()) {
PolicyDef policyDef = policyDefs.getPolicyDef(type);
policyDefsJ.addProperty(policyDef.getType(), policyDef.getValue());
}
}
public JsonObject toJson(AbstractStrolchElement element, JsonObject rootJ) {
rootJ.addProperty(Tags.ID, element.getId());
rootJ.addProperty(Tags.NAME, element.getName());
rootJ.addProperty(Tags.TYPE, element.getType());
return rootJ;
}
protected void addParameterBags(GroupedParameterizedElement element, JsonObject rootJ) {
if (!element.hasParameterBags())
return;
JsonObject parameterBagsJ = new JsonObject();
rootJ.add(Tags.PARAMETER_BAGS, parameterBagsJ);
for (String bagKey : element.getParameterBagKeySet()) {
ParameterBag bag = element.getParameterBag(bagKey);
JsonObject bagJ = new JsonObject();
parameterBagsJ.add(bagKey, bagJ);
toJson(bag, bagJ);
addParameters(bag, bagJ);
}
}
protected void addParameters(ParameterBag bag, JsonObject bagJ) {
if (!bag.hasParameters())
return;
JsonObject paramsJ = new JsonObject();
bagJ.add(Tags.PARAMETERS, paramsJ);
for (String paramKey : bag.getParameterKeySet()) {
Parameter<?> param = bag.getParameter(paramKey);
JsonObject paramJ = new JsonObject();
paramsJ.add(paramKey, paramJ);
toJson((AbstractStrolchElement) param, paramJ);
paramJ.addProperty(Tags.VALUE, param.getValueAsString());
}
}
protected void addTimedStates(Resource element, JsonObject rootJ) {
if (!element.hasTimedStates())
return;
JsonObject timedStatesJ = new JsonObject();
rootJ.add(Tags.TIMED_STATES, timedStatesJ);
for (String stateKey : element.getTimedStateKeySet()) {
StrolchTimedState<IValue<?>> state = element.getTimedState(stateKey);
JsonObject stateJ = new JsonObject();
timedStatesJ.add(stateKey, stateJ);
toJson((AbstractStrolchElement) state, stateJ);
JsonArray valuesJ = new JsonArray();
stateJ.add(Tags.VALUES, valuesJ);
SortedSet<ITimeValue<IValue<?>>> values = state.getTimeEvolution().getValues();
for (ITimeValue<IValue<?>> value : values) {
JsonObject valueJ = new JsonObject();
valuesJ.add(valueJ);
Long time = value.getTime();
String valueS = value.getValue().getValueAsString();
valueJ.addProperty(Tags.TIME, ISO8601FormatFactory.getInstance().formatDate(time));
valueJ.addProperty(Tags.VALUE, valueS);
}
}
}
}

View File

@ -21,6 +21,7 @@ import java.util.Set;
import ch.eitchnet.utils.dbc.DBC;
import li.strolch.exception.StrolchPolicyException;
import li.strolch.model.StrolchElement;
import li.strolch.model.StrolchRootElement;
/**
@ -30,7 +31,7 @@ import li.strolch.model.StrolchRootElement;
*/
public class PolicyDefs {
private StrolchRootElement parent;
private StrolchElement parent;
private Map<String, PolicyDef> policyDefMap;
@ -38,11 +39,11 @@ public class PolicyDefs {
this.policyDefMap = new HashMap<>(0);
}
public void setParent(StrolchRootElement parent) {
public void setParent(StrolchElement parent) {
this.parent = parent;
}
public StrolchRootElement getParent() {
public StrolchElement getParent() {
return this.parent;
}

View File

@ -102,5 +102,4 @@ public class AString implements Serializable {
sb.append("]");
return sb.toString();
}
}

View File

@ -21,12 +21,12 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import ch.eitchnet.utils.dbc.DBC;
import ch.eitchnet.utils.helper.StringHelper;
import li.strolch.exception.StrolchException;
import li.strolch.model.StrolchValueType;
import li.strolch.model.timevalue.ITimeValue;
import li.strolch.model.timevalue.IValue;
import ch.eitchnet.utils.dbc.DBC;
import ch.eitchnet.utils.helper.StringHelper;
/**
* {@link IValue} implementation to work with String valued {@link ITimeValue} objects. Since a java.util.String object
@ -127,7 +127,7 @@ public class StringSetValue implements IValue<Set<AString>>, Serializable {
StringBuilder sb = new StringBuilder();
Iterator<AString> iter = this.aStrings.iterator();
while (iter.hasNext()) {
sb.append(iter.next());
sb.append(iter.next().getString());
if (iter.hasNext())
sb.append(", ");
}

View File

@ -27,7 +27,7 @@ import li.strolch.model.activity.Activity;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ActivityToSaxWriterVisitor extends AbstractToSaxWriterVisitor implements ActivityVisitor<Void> {
public class ActivityToSaxWriterVisitor extends StrolchElementToSaxWriterVisitor implements ActivityVisitor<Void> {
public ActivityToSaxWriterVisitor(XMLStreamWriter writer) {
super(writer);

View File

@ -27,7 +27,7 @@ import li.strolch.model.OrderVisitor;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class OrderToSaxWriterVisitor extends AbstractToSaxWriterVisitor implements OrderVisitor<Void> {
public class OrderToSaxWriterVisitor extends StrolchElementToSaxWriterVisitor implements OrderVisitor<Void> {
public OrderToSaxWriterVisitor(XMLStreamWriter writer) {
super(writer);

View File

@ -27,7 +27,7 @@ import li.strolch.model.ResourceVisitor;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ResourceToSaxWriterVisitor extends AbstractToSaxWriterVisitor implements ResourceVisitor<Void> {
public class ResourceToSaxWriterVisitor extends StrolchElementToSaxWriterVisitor implements ResourceVisitor<Void> {
public ResourceToSaxWriterVisitor(XMLStreamWriter writer) {
super(writer);

View File

@ -17,15 +17,14 @@ package li.strolch.model.xml;
import java.io.StringWriter;
import javanet.staxutils.IndentingXMLStreamWriter;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;
import ch.eitchnet.utils.dbc.DBC;
import javanet.staxutils.IndentingXMLStreamWriter;
import li.strolch.model.Resource;
import li.strolch.model.ResourceVisitor;
import li.strolch.model.StrolchModelConstants;
import ch.eitchnet.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
@ -42,14 +41,15 @@ public class ResourceToXmlStringVisitor implements ResourceVisitor<String> {
writer = new IndentingXMLStreamWriter(writer);
// start document
writer.writeStartDocument(StrolchModelConstants.DEFAULT_ENCODING, StrolchModelConstants.DEFAULT_XML_VERSION);
writer.writeStartDocument(StrolchModelConstants.DEFAULT_ENCODING,
StrolchModelConstants.DEFAULT_XML_VERSION);
new ResourceToSaxWriterVisitor(writer).visit(element);
writer.writeEndDocument();
return stringWriter.toString();
} catch (Exception e) {
throw new RuntimeException("Failed to format Element " + element.getLocator() + " to xml string due to "
+ e.getMessage(), e);
throw new RuntimeException(
"Failed to format Element " + element.getLocator() + " to xml string due to " + e.getMessage(), e);
}
}
}

View File

@ -245,7 +245,7 @@ public class StrolchElementFromDomVisitor {
}
}
protected void fillElement(Element activityElement, Activity activity) {
public void fillElement(Element activityElement, Activity activity) {
fillElement(activityElement, (GroupedParameterizedElement) activity);
PolicyDefs defs = parsePolicies(activityElement);
@ -291,6 +291,10 @@ public class StrolchElementFromDomVisitor {
action.setResourceType(resourceType);
action.setState(State.valueOf(stateS));
PolicyDefs defs = parsePolicies(element);
if (defs.hasPolicyDefs())
action.setPolicyDefs(defs);
NodeList valueChangeNodes = element.getChildNodes();
for (int i = 0; i < valueChangeNodes.getLength(); i++) {
Node item = valueChangeNodes.item(i);
@ -316,7 +320,7 @@ public class StrolchElementFromDomVisitor {
}
}
private PolicyDefs parsePolicies(Element element) {
protected PolicyDefs parsePolicies(Element element) {
PolicyDefs policyDefs = new PolicyDefs();

View File

@ -86,25 +86,6 @@ public class StrolchElementToDomVisitor {
return asDom;
}
private void fillElement(Element asDom, PolicyDefs policyDefs) {
if (policyDefs == null || !policyDefs.hasPolicyDefs())
return;
Element policiesElem = this.document.createElement(Tags.POLICIES);
for (String type : policyDefs.getPolicyTypes()) {
PolicyDef policyDef = policyDefs.getPolicyDef(type);
Element policyElem = this.document.createElement(Tags.POLICY);
policyElem.setAttribute(Tags.TYPE, policyDef.getType());
policyElem.setAttribute(Tags.VALUE, policyDef.getValueForXml());
policiesElem.appendChild(policyElem);
}
asDom.appendChild(policiesElem);
}
protected Element toDom(Activity activity) {
Element element = document.createElement(Tags.ACTIVITY);
fillElement(element, activity);
@ -137,6 +118,9 @@ public class StrolchElementToDomVisitor {
element.setAttribute(Tags.RESOURCE_TYPE, action.getResourceType());
element.setAttribute(Tags.STATE, action.getState().name());
if (action.hasPolicyDefs())
fillElement(element, action.getPolicyDefs());
if (action.hasChanges()) {
Iterator<IValueChange<? extends IValue<?>>> iter = action.changesIterator();
while (iter.hasNext()) {
@ -250,4 +234,22 @@ public class StrolchElementToDomVisitor {
}
}
protected void fillElement(Element asDom, PolicyDefs policyDefs) {
if (policyDefs == null || !policyDefs.hasPolicyDefs())
return;
Element policiesElem = this.document.createElement(Tags.POLICIES);
for (String type : policyDefs.getPolicyTypes()) {
PolicyDef policyDef = policyDefs.getPolicyDef(type);
Element policyElem = this.document.createElement(Tags.POLICY);
policyElem.setAttribute(Tags.TYPE, policyDef.getType());
policyElem.setAttribute(Tags.VALUE, policyDef.getValueForXml());
policiesElem.appendChild(policyElem);
}
asDom.appendChild(policiesElem);
}
}

View File

@ -85,7 +85,7 @@ public abstract class StrolchElementToSaxVisitor {
return attributes;
}
private Attributes attributesFor(StrolchTimedState<IValue<?>> state) {
protected Attributes attributesFor(StrolchTimedState<IValue<?>> state) {
AttributesImpl attributes = attributesFor((StrolchElement) state);
if (!UOM_NONE.equals(state.getUom())) {
@ -104,7 +104,7 @@ public abstract class StrolchElementToSaxVisitor {
return attributes;
}
private Attributes attributesFor(ITimeValue<IValue<?>> value) {
protected Attributes attributesFor(ITimeValue<IValue<?>> value) {
AttributesImpl attributes = new AttributesImpl();
ISO8601FormatFactory df = ISO8601FormatFactory.getInstance();
attributes.addAttribute(null, null, Tags.TIME, Tags.CDATA, df.formatDate(value.getTime()));
@ -195,7 +195,24 @@ public abstract class StrolchElementToSaxVisitor {
this.contentHandler.endElement(null, null, Tags.ACTIVITY);
}
private void toSax(PolicyDefs policyDefs) throws SAXException {
protected void toSax(Action action) throws SAXException {
this.contentHandler.startElement(null, null, Tags.ACTION, attributesFor(action));
toSax((GroupedParameterizedElement) action);
if (action.hasPolicyDefs())
toSax(action.getPolicyDefs());
Iterator<IValueChange<? extends IValue<?>>> iter = action.changesIterator();
while (iter.hasNext()) {
IValueChange<? extends IValue<?>> valueChange = iter.next();
this.contentHandler.startElement(null, null, Tags.VALUE_CHANGE, attributesFor(valueChange));
this.contentHandler.endElement(null, null, Tags.VALUE_CHANGE);
}
this.contentHandler.endElement(null, null, Tags.ACTION);
}
protected void toSax(PolicyDefs policyDefs) throws SAXException {
if (!policyDefs.hasPolicyDefs())
return;
@ -232,18 +249,4 @@ public abstract class StrolchElementToSaxVisitor {
attributes.addAttribute(null, null, Tags.TYPE, Tags.CDATA, valueChange.getValue().getType());
return attributes;
}
protected void toSax(Action action) throws SAXException {
this.contentHandler.startElement(null, null, Tags.ACTION, attributesFor(action));
toSax((GroupedParameterizedElement) action);
Iterator<IValueChange<? extends IValue<?>>> iter = action.changesIterator();
while (iter.hasNext()) {
IValueChange<? extends IValue<?>> valueChange = iter.next();
this.contentHandler.startElement(null, null, Tags.VALUE_CHANGE, attributesFor(valueChange));
this.contentHandler.endElement(null, null, Tags.VALUE_CHANGE);
}
this.contentHandler.endElement(null, null, Tags.ACTION);
}
}

View File

@ -30,6 +30,7 @@ import java.util.TreeSet;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
import li.strolch.model.GroupedParameterizedElement;
import li.strolch.model.Order;
import li.strolch.model.ParameterBag;
@ -41,26 +42,46 @@ 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.policy.PolicyDef;
import li.strolch.model.policy.PolicyDefs;
import li.strolch.model.timedstate.StrolchTimedState;
import li.strolch.model.timevalue.ITimeValue;
import li.strolch.model.timevalue.ITimeVariable;
import li.strolch.model.timevalue.IValue;
import li.strolch.model.timevalue.IValueChange;
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class AbstractToSaxWriterVisitor {
public abstract class StrolchElementToSaxWriterVisitor {
protected XMLStreamWriter writer;
public AbstractToSaxWriterVisitor(XMLStreamWriter writer) {
public StrolchElementToSaxWriterVisitor(XMLStreamWriter writer) {
this.writer = writer;
}
protected void writeElement(Resource resource) throws XMLStreamException {
boolean empty = !resource.hasParameterBags() && !resource.hasTimedStates() && !resource.hasPolicyDefs();
writeStartStrolchElement(Tags.RESOURCE, empty, resource);
if (resource.hasParameterBags()) {
writeParameterBags(resource);
}
if (resource.hasTimedStates())
writeTimedStates(resource);
if (resource.hasPolicyDefs())
writePolicyDefs(resource.getPolicyDefs());
if (!empty)
this.writer.writeEndElement();
}
protected void writeElement(Order order) throws XMLStreamException {
boolean empty = !order.hasParameterBags();
boolean empty = !order.hasParameterBags() && !order.hasPolicyDefs();
writeStartStrolchElement(Tags.ORDER, empty, order);
this.writer.writeAttribute(Tags.DATE, ISO8601FormatFactory.getInstance().formatDate(order.getDate()));
@ -70,12 +91,15 @@ public abstract class AbstractToSaxWriterVisitor {
writeParameterBags(order);
}
if (order.hasPolicyDefs())
writePolicyDefs(order.getPolicyDefs());
if (!empty)
this.writer.writeEndElement();
}
protected void writeElement(Activity activity) throws XMLStreamException {
boolean empty = !activity.hasParameterBags() && !activity.hasElements();
boolean empty = !activity.hasParameterBags() && !activity.hasElements() && !activity.hasPolicyDefs();
writeStartStrolchElement(Tags.ACTIVITY, empty, activity);
@ -96,12 +120,15 @@ public abstract class AbstractToSaxWriterVisitor {
}
}
if (activity.hasPolicyDefs())
writePolicyDefs(activity.getPolicyDefs());
if (!empty)
this.writer.writeEndElement();
}
private <T> void writeElement(Action action) throws XMLStreamException {
boolean empty = !action.hasParameterBags() && !action.hasChanges();
protected <T> void writeElement(Action action) throws XMLStreamException {
boolean empty = !action.hasParameterBags() && !action.hasChanges() && !action.hasPolicyDefs();
writeStartStrolchElement(Tags.ACTION, empty, action);
this.writer.writeAttribute(Tags.STATE, action.getState().name());
@ -122,31 +149,31 @@ public abstract class AbstractToSaxWriterVisitor {
}
}
if (action.hasPolicyDefs())
writePolicyDefs(action.getPolicyDefs());
if (!empty)
this.writer.writeEndElement();
}
protected void writeElement(Resource resource) throws XMLStreamException {
boolean empty = !resource.hasParameterBags() && !resource.hasTimedStates();
protected void writePolicyDefs(PolicyDefs policyDefs) throws XMLStreamException {
writeStartStrolchElement(Tags.RESOURCE, empty, resource);
if (!policyDefs.hasPolicyDefs())
return;
if (resource.hasParameterBags()) {
writeParameterBags(resource);
this.writer.writeStartElement(Tags.POLICIES);
for (String type : policyDefs.getPolicyTypes()) {
PolicyDef policyDef = policyDefs.getPolicyDef(type);
this.writer.writeEmptyElement(Tags.POLICY);
this.writer.writeAttribute(Tags.TYPE, policyDef.getType());
this.writer.writeAttribute(Tags.VALUE, policyDef.getValueForXml());
this.writer.writeEndElement();
}
if (resource.hasTimedStates())
writeTimedStates(resource);
if (!empty)
this.writer.writeEndElement();
this.writer.writeEndElement();
}
/**
* @param resource
* @throws XMLStreamException
*/
private void writeTimedStates(Resource resource) throws XMLStreamException {
protected void writeTimedStates(Resource resource) throws XMLStreamException {
List<StrolchTimedState<IValue<?>>> timedStates = resource.getTimedStates();
for (StrolchTimedState<IValue<?>> timedState : timedStates) {
ITimeVariable<IValue<?>> timeEvolution = timedState.getTimeEvolution();
@ -156,8 +183,8 @@ public abstract class AbstractToSaxWriterVisitor {
for (ITimeValue<IValue<?>> timeValue : values) {
this.writer.writeEmptyElement(Tags.VALUE);
this.writer.writeAttribute(Tags.TIME, ISO8601FormatFactory.getInstance()
.formatDate(timeValue.getTime()));
this.writer.writeAttribute(Tags.TIME,
ISO8601FormatFactory.getInstance().formatDate(timeValue.getTime()));
this.writer.writeAttribute(Tags.VALUE, timeValue.getValue().getValueAsString());
}

View File

@ -307,6 +307,8 @@ public class XmlModelSaxReader extends DefaultHandler {
((Order) this.parameterizedElement).setPolicyDefs(this.policies);
} else if (this.parameterizedElement instanceof Activity) {
((Activity) this.parameterizedElement).setPolicyDefs(this.policies);
} else if (this.parameterizedElement instanceof Action) {
((Action) this.parameterizedElement).setPolicyDefs(this.policies);
} else {
throw new StrolchPolicyException(
"Policies are currently not allowed on " + this.parameterizedElement.getClass());

View File

@ -2,10 +2,22 @@
<StrolchModel>
<Activity Id="activity_1" Name="Activity" Type="parentType">
<Policies>
<Policy Type="PlanningPolicy" Value="key:SimplePlanning" />
<Policy Type="ConfirmationPolicy" Value="key:NoConfirmation" />
</Policies>
<Action Id="action_1" Name="Action 1" ResourceId="dummyId" ResourceType="dummyType" State="CREATED" Type="Use">
<Policies>
<Policy Type="PlanningPolicy" Value="key:SimplePlanning" />
<Policy Type="ConfirmationPolicy" Value="key:NoConfirmation" />
</Policies>
<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">
<Policies>
<Policy Type="PlanningPolicy" Value="key:SimplePlanning" />
<Policy Type="ConfirmationPolicy" Value="key:NoConfirmation" />
</Policies>
<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" />
</Activity>

View File

@ -14,5 +14,9 @@
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
</ParameterBag>
<Policies>
<Policy Type="PlanningPolicy" Value="key:SimplePlanning" />
<Policy Type="ConfirmationPolicy" Value="key:NoConfirmation" />
</Policies>
</Order>
</StrolchModel>

View File

@ -40,5 +40,9 @@
<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" />
</TimedState>
<Policies>
<Policy Type="PlanningPolicy" Value="key:SimplePlanning" />
<Policy Type="ConfirmationPolicy" Value="key:NoConfirmation" />
</Policies>
</Resource>
</StrolchModel>

View File

@ -36,12 +36,17 @@ import javax.ws.rs.core.Response;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import ch.eitchnet.privilege.model.Certificate;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.OrderMap;
import li.strolch.agent.api.ResourceMap;
import li.strolch.exception.StrolchException;
import li.strolch.model.Order;
import li.strolch.model.Resource;
import li.strolch.model.json.OrderToJsonVisitor;
import li.strolch.model.json.ResourceToJsonVisitor;
import li.strolch.model.xml.OrderToXmlStringVisitor;
import li.strolch.model.xml.ResourceToXmlStringVisitor;
import li.strolch.model.xml.SimpleStrolchElementListener;
@ -54,11 +59,9 @@ import li.strolch.rest.model.AgentOverview;
import li.strolch.rest.model.ElementMapOverview;
import li.strolch.rest.model.ElementMapType;
import li.strolch.rest.model.ElementMapsOverview;
import li.strolch.rest.model.OrderDetail;
import li.strolch.rest.model.OrderOverview;
import li.strolch.rest.model.RealmDetail;
import li.strolch.rest.model.RealmOverview;
import li.strolch.rest.model.ResourceDetail;
import li.strolch.rest.model.ResourceOverview;
import li.strolch.rest.model.Result;
import li.strolch.rest.model.StrolchElementOverview;
@ -70,10 +73,6 @@ import li.strolch.service.UpdateResourceService;
import li.strolch.service.UpdateResourceService.UpdateResourceArg;
import li.strolch.service.api.ServiceResult;
import org.xml.sax.InputSource;
import ch.eitchnet.privilege.model.Certificate;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@ -81,8 +80,8 @@ import ch.eitchnet.privilege.model.Certificate;
public class Inspector {
private StrolchTransaction openTx(Certificate certificate, String realm) {
return RestfulStrolchComponent.getInstance().getContainer().getRealm(realm)
.openTx(certificate, Inspector.class);
return RestfulStrolchComponent.getInstance().getContainer().getRealm(realm).openTx(certificate,
Inspector.class);
}
/**
@ -381,11 +380,7 @@ public class Inspector {
throw new StrolchException(MessageFormat.format("No Resource exists for {0}/{1}", type, id)); //$NON-NLS-1$
}
ResourceDetail resourceDetail = new ResourceDetail(resource);
GenericEntity<ResourceDetail> entity = new GenericEntity<ResourceDetail>(resourceDetail, ResourceDetail.class) {
//
};
return Response.ok().entity(entity).build();
return Response.ok().entity(ResourceToJsonVisitor.toJsonString(resource)).build();
}
@GET
@ -422,17 +417,17 @@ public class Inspector {
parser.parse(new InputSource(new StringReader(data)), new XmlModelSaxReader(listener));
if (listener.getResources().size() == 0)
throw new StrolchPersistenceException(MessageFormat.format(
"No Resources parsed from xml value for {0} / {1}", id, type));
throw new StrolchPersistenceException(
MessageFormat.format("No Resources parsed from xml value for {0} / {1}", id, type));
if (listener.getResources().size() > 1)
throw new StrolchPersistenceException(MessageFormat.format(
"Multiple Resources parsed from xml value for {0} / {1}", id, type));
throw new StrolchPersistenceException(
MessageFormat.format("Multiple Resources parsed from xml value for {0} / {1}", id, type));
resource = listener.getResources().get(0);
} catch (Exception e) {
throw new StrolchPersistenceException(MessageFormat.format(
"Failed to extract Resources from xml value for {0} / {1}", id, type), e);
throw new StrolchPersistenceException(
MessageFormat.format("Failed to extract Resources from xml value for {0} / {1}", id, type), e);
}
UpdateResourceService svc = new UpdateResourceService();
@ -464,11 +459,7 @@ public class Inspector {
throw new StrolchException(MessageFormat.format("No Order exists for {0}/{1}", type, id)); //$NON-NLS-1$
}
OrderDetail orderDetail = new OrderDetail(order);
GenericEntity<OrderDetail> entity = new GenericEntity<OrderDetail>(orderDetail, OrderDetail.class) {
//
};
return Response.ok().entity(entity).build();
return Response.ok().entity(OrderToJsonVisitor.toJsonString(order)).build();
}
@GET
@ -505,17 +496,17 @@ public class Inspector {
parser.parse(new InputSource(new StringReader(data)), new XmlModelSaxReader(listener));
if (listener.getOrders().size() == 0)
throw new StrolchPersistenceException(MessageFormat.format(
"No Orders parsed from xml value for {0} / {1}", id, type));
throw new StrolchPersistenceException(
MessageFormat.format("No Orders parsed from xml value for {0} / {1}", id, type));
if (listener.getOrders().size() > 1)
throw new StrolchPersistenceException(MessageFormat.format(
"Multiple Orders parsed from xml value for {0} / {1}", id, type));
throw new StrolchPersistenceException(
MessageFormat.format("Multiple Orders parsed from xml value for {0} / {1}", id, type));
order = listener.getOrders().get(0);
} catch (Exception e) {
throw new StrolchPersistenceException(MessageFormat.format(
"Failed to extract Order from xml value for {0} / {1}", id, type), e);
throw new StrolchPersistenceException(
MessageFormat.format("Failed to extract Order from xml value for {0} / {1}", id, type), e);
}
UpdateOrderService svc = new UpdateOrderService();

View File

@ -17,9 +17,13 @@ package li.strolch.rest.helper;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.HttpHeaders;
import ch.eitchnet.privilege.model.Certificate;
import ch.eitchnet.utils.dbc.DBC;
import ch.eitchnet.utils.helper.StringHelper;
import li.strolch.rest.StrolchRestfulConstants;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
@ -31,4 +35,10 @@ public class RestfulHelper {
return null;
return headers.getAcceptableLanguages().get(0);
}
public static Certificate getCert(HttpServletRequest request) {
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
DBC.PRE.assertNotNull("Certificate not found as request attribute!", cert);
return cert;
}
}

View File

@ -1,102 +0,0 @@
/*
* 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.rest.model;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
import li.strolch.model.GroupedParameterizedElement;
import li.strolch.model.ParameterBag;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "GroupedParameterizedElement")
@XmlSeeAlso({ ResourceDetail.class, OrderDetail.class })
public class GroupedParameterizedElementDetail extends StrolchElementDetail {
@XmlElement(name = "parameterBags", type = ParameterizedElementDetail.class)
private List<ParameterizedElementDetail> parameterizedElements;
public GroupedParameterizedElementDetail() {
// no-arg constructor for JAXB
}
public GroupedParameterizedElementDetail(String id, String name, String type,
List<ParameterizedElementDetail> parameterizedElements) {
super(id, name, type);
this.parameterizedElements = parameterizedElements;
}
public GroupedParameterizedElementDetail(GroupedParameterizedElement groupedParameterizedElement) {
super(groupedParameterizedElement);
Set<String> bagKeySet = groupedParameterizedElement.getParameterBagKeySet();
this.parameterizedElements = new ArrayList<>(bagKeySet.size());
for (String bagId : bagKeySet) {
ParameterBag parameterBag = groupedParameterizedElement.getParameterBag(bagId);
this.parameterizedElements.add(new ParameterizedElementDetail(parameterBag));
}
}
/**
* @return the parameterizedElements
*/
public List<ParameterizedElementDetail> getParameterizedElements() {
return this.parameterizedElements;
}
/**
* @param parameterizedElements
* the parameterizedElements to set
*/
public void setParameterizedElements(List<ParameterizedElementDetail> parameterizedElements) {
this.parameterizedElements = parameterizedElements;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((this.parameterizedElements == null) ? 0 : this.parameterizedElements.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
GroupedParameterizedElementDetail other = (GroupedParameterizedElementDetail) obj;
if (this.parameterizedElements == null) {
if (other.parameterizedElements != null)
return false;
} else if (!this.parameterizedElements.equals(other.parameterizedElements))
return false;
return true;
}
}

View File

@ -1,129 +0,0 @@
/*
* 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.rest.model;
import java.util.Date;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import li.strolch.model.Order;
import li.strolch.model.State;
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "Order")
@XmlType(name = "")
public class OrderDetail extends GroupedParameterizedElementDetail {
@XmlAttribute(name = "date")
private String date;
@XmlAttribute(name = "state")
private State state;
public OrderDetail() {
// no-arg constructor for JAXB
}
/**
* @param id
* @param name
* @param type
* @param date
* @param state
* @param parameterizedElementDetails
*/
public OrderDetail(String id, String name, String type, Date date, State state,
List<ParameterizedElementDetail> parameterizedElementDetails) {
super(id, name, type, parameterizedElementDetails);
this.state = state;
this.date = ISO8601FormatFactory.getInstance().formatDate(date);
}
/**
* @param order
*/
public OrderDetail(Order order) {
super(order);
this.state = order.getState();
this.date = ISO8601FormatFactory.getInstance().formatDate(order.getDate());
}
/**
* @return the date
*/
public String getDate() {
return this.date;
}
/**
* @param date
* the date to set
*/
public void setDate(String date) {
this.date = date;
}
/**
* @return the state
*/
public State getState() {
return this.state;
}
/**
* @param state
* the state to set
*/
public void setState(State state) {
this.state = state;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((this.date == null) ? 0 : this.date.hashCode());
result = prime * result + ((this.state == null) ? 0 : this.state.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
OrderDetail other = (OrderDetail) obj;
if (this.date == null) {
if (other.date != null)
return false;
} else if (!this.date.equals(other.date))
return false;
if (this.state != other.state)
return false;
return true;
}
}

View File

@ -1,174 +0,0 @@
/*
* 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.rest.model;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import li.strolch.model.parameter.Parameter;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "Parameter")
public class ParameterDetail extends StrolchElementDetail {
@XmlAttribute(name = "hidden")
private boolean hidden;
@XmlAttribute(name = "interpretation")
private String interpretation;
@XmlAttribute(name = "uom")
private String uom;
@XmlAttribute(name = "value")
private String value;
public ParameterDetail() {
// no-arg constructor for JAXB
}
/**
*
* @param id
* @param name
* @param type
* @param hidden
* @param interpretation
* @param uom
* @param value
*/
public ParameterDetail(String id, String name, String type, boolean hidden, String interpretation, String uom,
String value) {
super(id, name, type);
this.hidden = hidden;
this.interpretation = interpretation;
this.uom = uom;
this.value = value;
}
/**
* @param parameter
*/
public ParameterDetail(Parameter<?> parameter) {
super(parameter);
this.hidden = parameter.isHidden();
this.interpretation = parameter.getInterpretation();
this.uom = parameter.getUom();
this.value = parameter.getValueAsString();
}
/**
* @return the hidden
*/
public boolean isHidden() {
return this.hidden;
}
/**
* @param hidden
* the hidden to set
*/
public void setHidden(boolean hidden) {
this.hidden = hidden;
}
/**
* @return the interpretation
*/
public String getInterpretation() {
return this.interpretation;
}
/**
* @param interpretation
* the interpretation to set
*/
public void setInterpretation(String interpretation) {
this.interpretation = interpretation;
}
/**
* @return the uom
*/
public String getUom() {
return this.uom;
}
/**
* @param uom
* the uom to set
*/
public void setUom(String uom) {
this.uom = uom;
}
/**
* @return the value
*/
public String getValue() {
return this.value;
}
/**
* @param value
* the value to set
*/
public void setValue(String value) {
this.value = value;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + (this.hidden ? 1231 : 1237);
result = prime * result + ((this.interpretation == null) ? 0 : this.interpretation.hashCode());
result = prime * result + ((this.uom == null) ? 0 : this.uom.hashCode());
result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
ParameterDetail other = (ParameterDetail) obj;
if (this.hidden != other.hidden)
return false;
if (this.interpretation == null) {
if (other.interpretation != null)
return false;
} else if (!this.interpretation.equals(other.interpretation))
return false;
if (this.uom == null) {
if (other.uom != null)
return false;
} else if (!this.uom.equals(other.uom))
return false;
if (this.value == null) {
if (other.value != null)
return false;
} else if (!this.value.equals(other.value))
return false;
return true;
}
}

View File

@ -1,97 +0,0 @@
/*
* 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.rest.model;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import li.strolch.model.ParameterizedElement;
import li.strolch.model.parameter.Parameter;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "ParameterBag")
public class ParameterizedElementDetail extends StrolchElementDetail {
@XmlElement(name = "parameters", type = ParameterDetail.class)
private List<ParameterDetail> parameters;
public ParameterizedElementDetail() {
// no-arg constructor for JAXB
}
public ParameterizedElementDetail(String id, String name, String type, List<ParameterDetail> parameters) {
super(id, name, type);
this.parameters = parameters;
}
public ParameterizedElementDetail(ParameterizedElement parameterizedElement) {
super(parameterizedElement);
List<Parameter<?>> parameters = parameterizedElement.getParameters();
this.parameters = new ArrayList<>(parameters.size());
for (Parameter<?> parameter : parameters) {
this.parameters.add(new ParameterDetail(parameter));
}
}
/**
* @return the parameters
*/
public List<ParameterDetail> getParameters() {
return this.parameters;
}
/**
* @param parameters
* the parameters to set
*/
public void setParameters(List<ParameterDetail> parameters) {
this.parameters = parameters;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((this.parameters == null) ? 0 : this.parameters.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
ParameterizedElementDetail other = (ParameterizedElementDetail) obj;
if (this.parameters == null) {
if (other.parameters != null)
return false;
} else if (!this.parameters.equals(other.parameters))
return false;
return true;
}
}

View File

@ -1,55 +0,0 @@
/*
* 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.rest.model;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import li.strolch.model.Resource;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "Resource")
@XmlType(name = "")
public class ResourceDetail extends GroupedParameterizedElementDetail {
public ResourceDetail() {
// no-arg constructor for JAXB
}
/**
* @param id
* @param name
* @param type
* @param parameterizedElements
*/
public ResourceDetail(String id, String name, String type, List<ParameterizedElementDetail> parameterizedElements) {
super(id, name, type, parameterizedElements);
}
/**
* @param resource
*/
public ResourceDetail(Resource resource) {
super(resource);
}
}

View File

@ -1,144 +0,0 @@
/*
* 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.rest.model;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlSeeAlso;
import li.strolch.model.StrolchElement;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlSeeAlso({ GroupedParameterizedElementDetail.class, ParameterizedElementDetail.class, ParameterDetail.class })
public abstract class StrolchElementDetail {
@XmlAttribute(name = "id", required = true)
private String id;
@XmlAttribute(name = "name", required = true)
private String name;
@XmlAttribute(name = "type", required = true)
private String type;
public StrolchElementDetail() {
// no-arg constructor for JAXB
}
/**
* @param id
* @param name
* @param type
*/
public StrolchElementDetail(String id, String name, String type) {
this.id = id;
this.name = name;
this.type = type;
}
/**
* @param strolchElement
*/
public StrolchElementDetail(StrolchElement strolchElement) {
this.id = strolchElement.getId();
this.name = strolchElement.getName();
this.type = strolchElement.getType();
}
/**
* @return the id
*/
public String getId() {
return this.id;
}
/**
* @param id
* the id to set
*/
public void setId(String id) {
this.id = id;
}
/**
* @return the name
*/
public String getName() {
return this.name;
}
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the type
*/
public String getType() {
return this.type;
}
/**
* @param type
* the type to set
*/
public void setType(String type) {
this.type = type;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
result = prime * result + ((this.type == null) ? 0 : this.type.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
StrolchElementDetail other = (StrolchElementDetail) obj;
if (this.id == null) {
if (other.id != null)
return false;
} else if (!this.id.equals(other.id))
return false;
if (this.name == null) {
if (other.name != null)
return false;
} else if (!this.name.equals(other.name))
return false;
if (this.type == null) {
if (other.type != null)
return false;
} else if (!this.type.equals(other.type))
return false;
return true;
}
}