[Major] Added new TextParameter type. Used for multiline strings
This commit is contained in:
parent
ca3f16b0db
commit
93ba7efe7c
|
@ -73,6 +73,9 @@ public class ModelGenerator {
|
|||
public static final String PARAM_LIST_LONG_ID = "@param11";
|
||||
public static final String PARAM_LIST_LONG_NAME = "LongList Param";
|
||||
|
||||
public static final String PARAM_TEXT_ID = "@param12";
|
||||
public static final String PARAM_TEXT_NAME = "String Param";
|
||||
|
||||
public static final String STATE_FLOAT_ID = "@state1";
|
||||
public static final String STATE_FLOAT_NAME = "Float State";
|
||||
|
||||
|
@ -466,6 +469,10 @@ public class ModelGenerator {
|
|||
stringParam.setIndex(5);
|
||||
bag.addParameter(stringParam);
|
||||
|
||||
TextParameter textParam = new TextParameter(PARAM_TEXT_ID, PARAM_TEXT_NAME, "Strolch\n\nmulti\n\n\nline");
|
||||
textParam.setIndex(12);
|
||||
bag.addParameter(textParam);
|
||||
|
||||
DateParameter dateParam = new DateParameter(PARAM_DATE_ID, PARAM_DATE_NAME, new Date(1354295525628L));
|
||||
dateParam.setIndex(6);
|
||||
bag.addParameter(dateParam);
|
||||
|
|
|
@ -201,6 +201,41 @@ public enum StrolchValueType {
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Can be used for:
|
||||
* <ul>
|
||||
* <li>{@link Parameter}</li>
|
||||
* </ul>
|
||||
*/
|
||||
TEXT("Text") {
|
||||
@Override
|
||||
public Object parseValue(String value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parameter<?> parameterInstance() {
|
||||
return new TextParameter();
|
||||
}
|
||||
|
||||
@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$
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isString() {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Can be used for:
|
||||
* <ul>
|
||||
|
|
|
@ -268,6 +268,13 @@ public class StrolchElementToJsonVisitor implements StrolchElementVisitor<JsonEl
|
|||
return paramToJsonFull(param);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement visitTextParam(TextParameter param) {
|
||||
if (isFlat())
|
||||
return new JsonPrimitive(param.getValueAsString());
|
||||
return paramToJsonFull(param);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement visitStringListParam(StringListParameter param) {
|
||||
if (isFlat())
|
||||
|
|
|
@ -27,7 +27,7 @@ import li.strolch.utils.dbc.DBC;
|
|||
*/
|
||||
public class StringParameter extends AbstractParameter<String> {
|
||||
|
||||
private String value = "";
|
||||
protected String value = "";
|
||||
|
||||
/**
|
||||
* Empty constructor
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* 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.parameter;
|
||||
|
||||
import li.strolch.model.StrolchValueType;
|
||||
import li.strolch.model.visitor.StrolchElementVisitor;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class TextParameter extends StringParameter {
|
||||
|
||||
/**
|
||||
* Empty constructor
|
||||
*/
|
||||
public TextParameter() {
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
* @param id
|
||||
* the id
|
||||
* @param name
|
||||
* the name
|
||||
* @param value
|
||||
* the value
|
||||
*/
|
||||
public TextParameter(String id, String name, String value) {
|
||||
super(id, name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return StrolchValueType.TEXT.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StrolchValueType getValueType() {
|
||||
return StrolchValueType.TEXT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextParameter getClone() {
|
||||
TextParameter clone = new TextParameter();
|
||||
|
||||
super.fillClone(clone);
|
||||
|
||||
clone.setValue(this.value);
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> U accept(StrolchElementVisitor<U> visitor) {
|
||||
return visitor.visitTextParam(this);
|
||||
}
|
||||
}
|
|
@ -53,6 +53,11 @@ public interface IActivityElementVisitor<U> extends StrolchElementVisitor<U> {
|
|||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + param.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
default U visitTextParam(TextParameter param) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + param.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
default U visitStringListParam(StringListParameter param) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + param.getClass());
|
||||
|
|
|
@ -70,6 +70,12 @@ public class SetParameterValueFromStringVisitor implements ParameterVisitor<Void
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitTextParam(TextParameter param) {
|
||||
param.setValue(this.value);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitStringListParam(StringListParameter param) {
|
||||
param.setValueFromString(this.value);
|
||||
|
|
|
@ -74,6 +74,12 @@ public class SetParameterValueVisitor implements ParameterVisitor<Void> {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitTextParam(TextParameter param) {
|
||||
param.setValue((String) this.value);
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Void visitStringListParam(StringListParameter param) {
|
||||
|
|
|
@ -419,6 +419,13 @@ public class StrolchElementDeepEqualsVisitor implements StrolchElementVisitor<Li
|
|||
return getMismatchedLocators();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Locator> visitTextParam(TextParameter param) {
|
||||
DBC.PRE.assertEquals("Can't compare apples with pairs =)", this.srcElement.getClass(), param.getClass());
|
||||
deepEquals((Parameter<?>) this.srcElement, param);
|
||||
return getMismatchedLocators();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Locator> visitStringListParam(StringListParameter param) {
|
||||
DBC.PRE.assertEquals("Can't compare apples with pairs =)", this.srcElement.getClass(), param.getClass());
|
||||
|
|
|
@ -50,6 +50,8 @@ public interface StrolchElementVisitor<U> extends StrolchVisitor {
|
|||
|
||||
U visitStringParam(StringParameter param);
|
||||
|
||||
U visitTextParam(TextParameter param);
|
||||
|
||||
U visitStringListParam(StringListParameter param);
|
||||
|
||||
U visitIntegerListParam(IntegerListParameter param);
|
||||
|
|
|
@ -65,6 +65,11 @@ public interface StrolchRootElementVisitor<U> extends StrolchElementVisitor<U> {
|
|||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + param.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
default U visitTextParam(TextParameter param) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + param.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
default U visitStringListParam(StringListParameter param) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + param.getClass());
|
||||
|
|
|
@ -28,82 +28,87 @@ import li.strolch.model.parameter.*;
|
|||
public interface TimedStateVisitor<U> extends StrolchElementVisitor<U> {
|
||||
|
||||
@Override
|
||||
public default U visitActivity(Activity activity) {
|
||||
default U visitActivity(Activity activity) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + activity.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public default U visitOrder(Order order) {
|
||||
default U visitOrder(Order order) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + order.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public default U visitResource(Resource resource) {
|
||||
default U visitResource(Resource resource) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + resource.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public default U visitAction(Action action) {
|
||||
default U visitAction(Action action) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + action.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public default U visitBooleanParam(BooleanParameter param) {
|
||||
default U visitBooleanParam(BooleanParameter param) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + param.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public default U visitDateParam(DateParameter param) {
|
||||
default U visitDateParam(DateParameter param) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + param.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public default U visitDurationParam(DurationParameter param) {
|
||||
default U visitDurationParam(DurationParameter param) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + param.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public default U visitFloatParam(FloatParameter param) {
|
||||
default U visitFloatParam(FloatParameter param) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + param.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public default U visitIntegerParam(IntegerParameter param) {
|
||||
default U visitIntegerParam(IntegerParameter param) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + param.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public default U visitLongParam(LongParameter param) {
|
||||
default U visitLongParam(LongParameter param) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + param.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public default U visitStringParam(StringParameter param) {
|
||||
default U visitStringParam(StringParameter param) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + param.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public default U visitStringListParam(StringListParameter param) {
|
||||
default U visitTextParam(TextParameter param) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + param.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public default U visitIntegerListParam(IntegerListParameter param) {
|
||||
default U visitStringListParam(StringListParameter param) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + param.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public default U visitFloatListParam(FloatListParameter param) {
|
||||
default U visitIntegerListParam(IntegerListParameter param) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + param.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public default U visitLongListParam(LongListParameter param) {
|
||||
default U visitFloatListParam(FloatListParameter param) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + param.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public default U visitParameterBag(ParameterBag bag) {
|
||||
default U visitLongListParam(LongListParameter param) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + param.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
default U visitParameterBag(ParameterBag bag) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + bag.getClass());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ public class StrolchElementFromDomVisitor {
|
|||
if (StringHelper.isEmpty(index)) {
|
||||
timedState.setIndex(0);
|
||||
} else {
|
||||
timedState.setIndex(Integer.valueOf(index));
|
||||
timedState.setIndex(Integer.parseInt(index));
|
||||
}
|
||||
|
||||
if (StringHelper.isEmpty(hidden)) {
|
||||
|
@ -245,7 +245,11 @@ public class StrolchElementFromDomVisitor {
|
|||
|
||||
fillElement(element, (AbstractStrolchElement) param);
|
||||
|
||||
String value = element.getAttribute(Tags.VALUE);
|
||||
String value;
|
||||
if (param.getValueType() == StrolchValueType.TEXT)
|
||||
value = element.getTextContent();
|
||||
else
|
||||
value = element.getAttribute(Tags.VALUE);
|
||||
param.setValueFromString(value);
|
||||
|
||||
String interpretation = element.getAttribute(Tags.INTERPRETATION);
|
||||
|
@ -259,7 +263,7 @@ public class StrolchElementFromDomVisitor {
|
|||
if (StringHelper.isEmpty(index)) {
|
||||
param.setIndex(0);
|
||||
} else {
|
||||
param.setIndex(Integer.valueOf(index));
|
||||
param.setIndex(Integer.parseInt(index));
|
||||
}
|
||||
|
||||
if (StringHelper.isEmpty(hidden)) {
|
||||
|
|
|
@ -117,15 +117,14 @@ public class StrolchElementToDomVisitor implements StrolchRootElementVisitor<Doc
|
|||
Iterator<Entry<String, IActivityElement>> iter = activity.elementIterator();
|
||||
while (iter.hasNext()) {
|
||||
IActivityElement activityElement = iter.next().getValue();
|
||||
if (activityElement instanceof Activity) {
|
||||
if (activityElement instanceof Activity)
|
||||
element.appendChild(toDom((Activity) activityElement));
|
||||
} else if (activityElement instanceof Action) {
|
||||
else if (activityElement instanceof Action)
|
||||
element.appendChild(toDom((Action) activityElement));
|
||||
} else {
|
||||
else
|
||||
throw new IllegalArgumentException("Unhandled element " + activityElement.getClass());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
@ -171,12 +170,10 @@ public class StrolchElementToDomVisitor implements StrolchRootElementVisitor<Doc
|
|||
Element element = document.createElement(Tags.TIMED_STATE);
|
||||
fillElement(element, (AbstractStrolchElement) timedState);
|
||||
|
||||
if (!timedState.getInterpretation().equals(StrolchModelConstants.INTERPRETATION_NONE)) {
|
||||
if (!timedState.getInterpretation().equals(StrolchModelConstants.INTERPRETATION_NONE))
|
||||
element.setAttribute(Tags.INTERPRETATION, timedState.getInterpretation());
|
||||
}
|
||||
if (!timedState.getUom().equals(StrolchModelConstants.UOM_NONE)) {
|
||||
if (!timedState.getUom().equals(StrolchModelConstants.UOM_NONE))
|
||||
element.setAttribute(Tags.UOM, timedState.getUom());
|
||||
}
|
||||
if (timedState.isHidden()) {
|
||||
element.setAttribute(Tags.HIDDEN, Boolean.toString(timedState.isHidden()));
|
||||
}
|
||||
|
@ -210,20 +207,19 @@ public class StrolchElementToDomVisitor implements StrolchRootElementVisitor<Doc
|
|||
Element element = document.createElement(Tags.PARAMETER);
|
||||
fillElement(element, (AbstractStrolchElement) param);
|
||||
|
||||
element.setAttribute(Tags.VALUE, param.getValueAsString());
|
||||
|
||||
if (!param.getInterpretation().equals(StrolchModelConstants.INTERPRETATION_NONE)) {
|
||||
if (!param.getInterpretation().equals(StrolchModelConstants.INTERPRETATION_NONE))
|
||||
element.setAttribute(Tags.INTERPRETATION, param.getInterpretation());
|
||||
}
|
||||
if (!param.getUom().equals(StrolchModelConstants.UOM_NONE)) {
|
||||
if (!param.getUom().equals(StrolchModelConstants.UOM_NONE))
|
||||
element.setAttribute(Tags.UOM, param.getUom());
|
||||
}
|
||||
if (param.isHidden()) {
|
||||
if (param.isHidden())
|
||||
element.setAttribute(Tags.HIDDEN, Boolean.toString(param.isHidden()));
|
||||
}
|
||||
if (param.getIndex() != 0) {
|
||||
if (param.getIndex() != 0)
|
||||
element.setAttribute(Tags.INDEX, Integer.toString(param.getIndex()));
|
||||
}
|
||||
|
||||
if (param.getValueType() == StrolchValueType.TEXT)
|
||||
element.setTextContent(param.getValueAsString());
|
||||
else
|
||||
element.setAttribute(Tags.VALUE, param.getValueAsString());
|
||||
|
||||
return element;
|
||||
}
|
||||
|
|
|
@ -207,6 +207,10 @@ public class StrolchElementToSaxVisitor implements StrolchRootElementVisitor<Voi
|
|||
for (String paramKey : parameterKeySet) {
|
||||
Parameter<?> parameter = parameterBag.getParameter(paramKey);
|
||||
this.contentHandler.startElement(null, null, Tags.PARAMETER, attributesFor(parameter));
|
||||
if (parameter.getValueType() == StrolchValueType.TEXT) {
|
||||
String valueAsString = parameter.getValueAsString();
|
||||
this.contentHandler.characters(valueAsString.toCharArray(), 0, valueAsString.length());
|
||||
}
|
||||
this.contentHandler.endElement(null, null, Tags.PARAMETER);
|
||||
}
|
||||
|
||||
|
@ -283,6 +287,7 @@ public class StrolchElementToSaxVisitor implements StrolchRootElementVisitor<Voi
|
|||
protected AttributesImpl attributesFor(Parameter<?> parameter) {
|
||||
AttributesImpl attributes = attributesFor((StrolchElement) parameter);
|
||||
|
||||
if (parameter.getValueType() != StrolchValueType.TEXT)
|
||||
attributes.addAttribute(null, null, Tags.VALUE, Tags.CDATA, parameter.getValueAsString());
|
||||
|
||||
if (!UOM_NONE.equals(parameter.getUom()))
|
||||
|
|
|
@ -288,7 +288,8 @@ public class StrolchElementToSaxWriterVisitor implements StrolchRootElementVisit
|
|||
List<Parameter<?>> parameters = new ArrayList<>(element.getParameters());
|
||||
parameters.sort(Comparator.comparingInt(Parameter::getIndex));
|
||||
for (Parameter<?> parameter : parameters) {
|
||||
writeStartStrolchElement(Tags.PARAMETER, true, parameter);
|
||||
boolean isTextParam = parameter.getValueType() == StrolchValueType.TEXT;
|
||||
writeStartStrolchElement(Tags.PARAMETER, !isTextParam, parameter);
|
||||
|
||||
if (!INTERPRETATION_NONE.equals(parameter.getInterpretation()))
|
||||
this.writer.writeAttribute(Tags.INTERPRETATION, parameter.getInterpretation());
|
||||
|
@ -299,7 +300,12 @@ public class StrolchElementToSaxWriterVisitor implements StrolchRootElementVisit
|
|||
if (parameter.getIndex() != 0)
|
||||
this.writer.writeAttribute(Tags.INDEX, Integer.toString(parameter.getIndex()));
|
||||
|
||||
if (isTextParam) {
|
||||
this.writer.writeCData(parameter.getValueAsString());
|
||||
this.writer.writeEndElement();
|
||||
} else {
|
||||
this.writer.writeAttribute(Tags.VALUE, parameter.getValueAsString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import li.strolch.model.activity.Action;
|
|||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.activity.TimeOrdering;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.parameter.TextParameter;
|
||||
import li.strolch.model.policy.PolicyDef;
|
||||
import li.strolch.model.policy.PolicyDefs;
|
||||
import li.strolch.model.timedstate.StrolchTimedState;
|
||||
|
@ -51,11 +52,14 @@ public class XmlModelSaxReader extends DefaultHandler {
|
|||
protected ModelStatistics statistics;
|
||||
|
||||
private GroupedParameterizedElement parameterizedElement;
|
||||
private TextParameter textParam;
|
||||
private Deque<Activity> activityStack;
|
||||
private ParameterBag pBag;
|
||||
private StrolchTimedState<? extends IValue<?>> state;
|
||||
private PolicyDefs policies;
|
||||
|
||||
private StringBuilder textBuffer;
|
||||
|
||||
public XmlModelSaxReader(StrolchElementListener listener) {
|
||||
this.listener = listener;
|
||||
this.statistics = new ModelStatistics();
|
||||
|
@ -72,7 +76,6 @@ public class XmlModelSaxReader extends DefaultHandler {
|
|||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||
|
||||
// TODO split each root object into its own file
|
||||
switch (qName) {
|
||||
|
||||
case Tags.STROLCH_MODEL:
|
||||
|
@ -171,11 +174,10 @@ public class XmlModelSaxReader extends DefaultHandler {
|
|||
|
||||
String paramName = attributes.getValue(Tags.NAME);
|
||||
String paramType = attributes.getValue(Tags.TYPE);
|
||||
String paramValue = attributes.getValue(Tags.VALUE);
|
||||
String paramHiddenS = attributes.getValue(Tags.HIDDEN);
|
||||
String paramIndexS = attributes.getValue(Tags.INDEX);
|
||||
|
||||
int index = StringHelper.isEmpty(paramIndexS) ? 0 : Integer.valueOf(paramIndexS);
|
||||
int index = StringHelper.isEmpty(paramIndexS) ? 0 : Integer.parseInt(paramIndexS);
|
||||
boolean paramHidden = !StringHelper.isEmpty(paramHiddenS) && StringHelper.parseBoolean(paramHiddenS);
|
||||
String paramUom = attributes.getValue(Tags.UOM);
|
||||
String paramInterpretation = attributes.getValue(Tags.INTERPRETATION);
|
||||
|
@ -185,13 +187,20 @@ public class XmlModelSaxReader extends DefaultHandler {
|
|||
Parameter<?> param = type.parameterInstance();
|
||||
param.setId(paramId);
|
||||
param.setName(paramName);
|
||||
param.setValueFromString(paramValue);
|
||||
|
||||
param.setHidden(paramHidden);
|
||||
param.setUom(paramUom);
|
||||
param.setInterpretation(paramInterpretation);
|
||||
param.setIndex(index);
|
||||
|
||||
if (type != StrolchValueType.TEXT) {
|
||||
String paramValue = attributes.getValue(Tags.VALUE);
|
||||
param.setValueFromString(paramValue);
|
||||
} else {
|
||||
this.textBuffer = new StringBuilder();
|
||||
this.textParam = (TextParameter) param;
|
||||
}
|
||||
|
||||
this.pBag.addParameter(param);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
@ -212,7 +221,7 @@ public class XmlModelSaxReader extends DefaultHandler {
|
|||
String stateIndexS = attributes.getValue(Tags.INDEX);
|
||||
String stateUom = attributes.getValue(Tags.UOM);
|
||||
String stateInterpretation = attributes.getValue(Tags.INTERPRETATION);
|
||||
int stateIndex = StringHelper.isEmpty(stateIndexS) ? 0 : Integer.valueOf(stateIndexS);
|
||||
int stateIndex = StringHelper.isEmpty(stateIndexS) ? 0 : Integer.parseInt(stateIndexS);
|
||||
boolean stateHidden = !StringHelper.isEmpty(stateHiddenS) && StringHelper.parseBoolean(stateHiddenS);
|
||||
|
||||
StrolchValueType stateType = StrolchValueType.parse(stateTypeS);
|
||||
|
@ -303,6 +312,13 @@ public class XmlModelSaxReader extends DefaultHandler {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||
if (this.textBuffer != null) {
|
||||
this.textBuffer.append(ch, start, length);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
|
||||
|
@ -374,9 +390,18 @@ public class XmlModelSaxReader extends DefaultHandler {
|
|||
|
||||
break;
|
||||
|
||||
case Tags.PARAMETER:
|
||||
|
||||
if (this.textParam != null) {
|
||||
this.textParam.setValue(this.textBuffer.toString());
|
||||
this.textBuffer = null;
|
||||
this.textParam = null;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case Tags.POLICY:
|
||||
case Tags.VERSION:
|
||||
case Tags.PARAMETER:
|
||||
case Tags.INCLUDE_FILE:
|
||||
case Tags.VALUE:
|
||||
case Tags.VALUE_CHANGE:
|
||||
|
|
|
@ -100,14 +100,18 @@
|
|||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="ParameterType">
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="xs:string">
|
||||
<xs:attribute type="xs:string" name="Id" use="required"/>
|
||||
<xs:attribute type="xs:string" name="Name" use="required"/>
|
||||
<xs:attribute type="ParameterValueType" name="Type" use="required"/>
|
||||
<xs:attribute type="xs:string" name="Value" use="required"/>
|
||||
<xs:attribute type="xs:string" name="Value" use="optional"/>
|
||||
<xs:attribute type="xs:string" name="Interpretation" use="optional"/>
|
||||
<xs:attribute type="xs:string" name="Uom" use="optional"/>
|
||||
<xs:attribute type="xs:boolean" name="Hidden" use="optional"/>
|
||||
<xs:attribute type="xs:int" name="Index" use="optional"/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="PoliciesType">
|
||||
|
@ -171,6 +175,7 @@
|
|||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="Boolean"/>
|
||||
<xs:enumeration value="String"/>
|
||||
<xs:enumeration value="Text"/>
|
||||
<xs:enumeration value="Integer"/>
|
||||
<xs:enumeration value="Long"/>
|
||||
<xs:enumeration value="Float"/>
|
||||
|
|
|
@ -57,7 +57,7 @@ public class ModelToSaxWriterTest extends ModelMarshallingTest {
|
|||
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(order);
|
||||
List<Locator> mismatches = parsedOrder.accept(visitor);
|
||||
assertTrue("To DOM and back should equal same Order:\n" + mismatches, mismatches.isEmpty());
|
||||
assertTrue("To SAX and back should equal same Order:\n" + mismatches, mismatches.isEmpty());
|
||||
|
||||
return parsedOrder;
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ public class ModelToSaxWriterTest extends ModelMarshallingTest {
|
|||
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(resource);
|
||||
List<Locator> mismatches = parsedResource.accept(visitor);
|
||||
assertTrue("To DOM and back should equal same Resource:\n" + mismatches, mismatches.isEmpty());
|
||||
assertTrue("To SAX and back should equal same Resource:\n" + mismatches, mismatches.isEmpty());
|
||||
|
||||
return parsedResource;
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ public class ModelToSaxWriterTest extends ModelMarshallingTest {
|
|||
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(activity);
|
||||
List<Locator> mismatches = parsedActivity.accept(visitor);
|
||||
assertTrue("To DOM and back should equal same Activity:\n" + mismatches, mismatches.isEmpty());
|
||||
assertTrue("To SAX and back should equal same Activity:\n" + mismatches, mismatches.isEmpty());
|
||||
|
||||
return parsedActivity;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public class StrolchXmlHelperTest {
|
|||
@Test
|
||||
public void shouldWriteAndReadXml() {
|
||||
|
||||
File outFile = new File("target/" + getClass().getSimpleName());
|
||||
File outFile = new File("target/" + getClass().getSimpleName() + ".xml");
|
||||
|
||||
Activity activity = ModelGenerator.createActivity("activity", "Activity", "Activity", TimeOrdering.SERIES);
|
||||
Resource resource = ModelGenerator.createResource("res", "Res", "Res");
|
||||
|
|
|
@ -41,6 +41,24 @@ public class ParameterTest {
|
|||
assertTrue(p.isEqualTo(other));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextParam() {
|
||||
|
||||
TextParameter other = new TextParameter("other", "other",
|
||||
"here we have the content\n\nand some more\n\n\ncontent over multiple lines");
|
||||
TextParameter p = resource.getParameter(BAG_ID, PARAM_TEXT_ID, true);
|
||||
|
||||
assertEquals("Strolch\n\nmulti\n\n\nline", p.getValue());
|
||||
|
||||
p.clear();
|
||||
assertTrue(p.isEmpty());
|
||||
assertEquals("", p.getValue());
|
||||
|
||||
p.setValueFrom(other);
|
||||
assertTrue(p.isEqualTo(other.getValue()));
|
||||
assertTrue(p.isEqualTo(other));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntegerParam() {
|
||||
|
||||
|
|
|
@ -6,6 +6,12 @@
|
|||
|
||||
<Resource Id="MyTestResource" Name="Test Name" Type="TestType">
|
||||
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
||||
<Parameter Id="@param9" Name="Text Param" Type="Text"><![CDATA[here we have the content
|
||||
|
||||
and some more
|
||||
|
||||
|
||||
content over multiple lines]]></Parameter>
|
||||
<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"/>
|
||||
|
|
|
@ -100,14 +100,18 @@
|
|||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="ParameterType">
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="xs:string">
|
||||
<xs:attribute type="xs:string" name="Id" use="required"/>
|
||||
<xs:attribute type="xs:string" name="Name" use="required"/>
|
||||
<xs:attribute type="ParameterValueType" name="Type" use="required"/>
|
||||
<xs:attribute type="xs:string" name="Value" use="required"/>
|
||||
<xs:attribute type="xs:string" name="Value" use="optional"/>
|
||||
<xs:attribute type="xs:string" name="Interpretation" use="optional"/>
|
||||
<xs:attribute type="xs:string" name="Uom" use="optional"/>
|
||||
<xs:attribute type="xs:boolean" name="Hidden" use="optional"/>
|
||||
<xs:attribute type="xs:int" name="Index" use="optional"/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="PoliciesType">
|
||||
|
@ -171,6 +175,7 @@
|
|||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="Boolean"/>
|
||||
<xs:enumeration value="String"/>
|
||||
<xs:enumeration value="Text"/>
|
||||
<xs:enumeration value="Integer"/>
|
||||
<xs:enumeration value="Long"/>
|
||||
<xs:enumeration value="Float"/>
|
||||
|
|
|
@ -100,14 +100,18 @@
|
|||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="ParameterType">
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="xs:string">
|
||||
<xs:attribute type="xs:string" name="Id" use="required"/>
|
||||
<xs:attribute type="xs:string" name="Name" use="required"/>
|
||||
<xs:attribute type="ParameterValueType" name="Type" use="required"/>
|
||||
<xs:attribute type="xs:string" name="Value" use="required"/>
|
||||
<xs:attribute type="xs:string" name="Value" use="optional"/>
|
||||
<xs:attribute type="xs:string" name="Interpretation" use="optional"/>
|
||||
<xs:attribute type="xs:string" name="Uom" use="optional"/>
|
||||
<xs:attribute type="xs:boolean" name="Hidden" use="optional"/>
|
||||
<xs:attribute type="xs:int" name="Index" use="optional"/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="PoliciesType">
|
||||
|
@ -171,6 +175,7 @@
|
|||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="Boolean"/>
|
||||
<xs:enumeration value="String"/>
|
||||
<xs:enumeration value="Text"/>
|
||||
<xs:enumeration value="Integer"/>
|
||||
<xs:enumeration value="Long"/>
|
||||
<xs:enumeration value="Float"/>
|
||||
|
|
|
@ -100,14 +100,18 @@
|
|||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="ParameterType">
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="xs:string">
|
||||
<xs:attribute type="xs:string" name="Id" use="required"/>
|
||||
<xs:attribute type="xs:string" name="Name" use="required"/>
|
||||
<xs:attribute type="ParameterValueType" name="Type" use="required"/>
|
||||
<xs:attribute type="xs:string" name="Value" use="required"/>
|
||||
<xs:attribute type="xs:string" name="Value" use="optional"/>
|
||||
<xs:attribute type="xs:string" name="Interpretation" use="optional"/>
|
||||
<xs:attribute type="xs:string" name="Uom" use="optional"/>
|
||||
<xs:attribute type="xs:boolean" name="Hidden" use="optional"/>
|
||||
<xs:attribute type="xs:int" name="Index" use="optional"/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="PoliciesType">
|
||||
|
@ -171,6 +175,7 @@
|
|||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="Boolean"/>
|
||||
<xs:enumeration value="String"/>
|
||||
<xs:enumeration value="Text"/>
|
||||
<xs:enumeration value="Integer"/>
|
||||
<xs:enumeration value="Long"/>
|
||||
<xs:enumeration value="Float"/>
|
||||
|
|
Loading…
Reference in New Issue