[New] added a ParameterVisitor interface with SetParameterValueVisitor
This commit is contained in:
parent
8b76bf3d4b
commit
14dd9ff73b
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model;
|
package li.strolch.model;
|
||||||
|
|
||||||
|
import li.strolch.model.visitor.StrolchElementVisitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model;
|
package li.strolch.model;
|
||||||
|
|
||||||
|
import li.strolch.model.visitor.StrolchElementVisitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -21,6 +21,7 @@ import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.AbstractStrolchElement;
|
import li.strolch.model.AbstractStrolchElement;
|
||||||
import li.strolch.model.Locator;
|
import li.strolch.model.Locator;
|
||||||
import li.strolch.model.Locator.LocatorBuilder;
|
import li.strolch.model.Locator.LocatorBuilder;
|
||||||
|
import li.strolch.model.visitor.ParameterVisitor;
|
||||||
import li.strolch.model.ParameterizedElement;
|
import li.strolch.model.ParameterizedElement;
|
||||||
import li.strolch.model.Tags;
|
import li.strolch.model.Tags;
|
||||||
|
|
||||||
|
@ -163,12 +164,12 @@ public abstract class AbstractParameter<T> extends AbstractStrolchElement implem
|
||||||
setInterpretation(interpretation);
|
setInterpretation(interpretation);
|
||||||
setUom(uom);
|
setUom(uom);
|
||||||
|
|
||||||
if(StringHelper.isEmpty(index)) {
|
if (StringHelper.isEmpty(index)) {
|
||||||
this.index = 0;
|
this.index = 0;
|
||||||
} else {
|
} else {
|
||||||
this.index = Integer.valueOf(index);
|
this.index = Integer.valueOf(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringHelper.isEmpty(hidden)) {
|
if (StringHelper.isEmpty(hidden)) {
|
||||||
setHidden(false);
|
setHidden(false);
|
||||||
} else {
|
} else {
|
||||||
|
@ -228,6 +229,11 @@ public abstract class AbstractParameter<T> extends AbstractStrolchElement implem
|
||||||
clone.setIndex(this.index);
|
clone.setIndex(this.index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <U> U accept(ParameterVisitor visitor) {
|
||||||
|
return visitor.visitParam(this);
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("nls")
|
@SuppressWarnings("nls")
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
|
@ -19,6 +19,7 @@ import java.text.MessageFormat;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Tags;
|
import li.strolch.model.Tags;
|
||||||
|
import li.strolch.model.visitor.ParameterVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
@ -102,6 +103,11 @@ public class BooleanParameter extends AbstractParameter<Boolean> {
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <U> U accept(ParameterVisitor visitor) {
|
||||||
|
return visitor.visitBooleanParam(this);
|
||||||
|
}
|
||||||
|
|
||||||
public static Boolean parseFromString(String valueS) {
|
public static Boolean parseFromString(String valueS) {
|
||||||
return Boolean.valueOf(valueS);
|
return Boolean.valueOf(valueS);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import java.util.Date;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Tags;
|
import li.strolch.model.Tags;
|
||||||
|
import li.strolch.model.visitor.ParameterVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
@ -104,6 +105,11 @@ public class DateParameter extends AbstractParameter<Date> {
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <U> U accept(ParameterVisitor visitor) {
|
||||||
|
return visitor.visitDateParam(this);
|
||||||
|
}
|
||||||
|
|
||||||
public static Date parseFromString(String valueS) {
|
public static Date parseFromString(String valueS) {
|
||||||
return ISO8601FormatFactory.getInstance().getDateFormat().parse(valueS);
|
return ISO8601FormatFactory.getInstance().getDateFormat().parse(valueS);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import java.text.MessageFormat;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Tags;
|
import li.strolch.model.Tags;
|
||||||
|
import li.strolch.model.visitor.ParameterVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
@ -103,7 +104,12 @@ public class FloatParameter extends AbstractParameter<Double> {
|
||||||
|
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <U> U accept(ParameterVisitor visitor) {
|
||||||
|
return visitor.visitFloatParam(this);
|
||||||
|
}
|
||||||
|
|
||||||
public static Double parseFromString(String valueS) {
|
public static Double parseFromString(String valueS) {
|
||||||
return Double.valueOf(valueS);
|
return Double.valueOf(valueS);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import java.text.MessageFormat;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Tags;
|
import li.strolch.model.Tags;
|
||||||
|
import li.strolch.model.visitor.ParameterVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
@ -103,6 +104,11 @@ public class IntegerParameter extends AbstractParameter<Integer> {
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <U> U accept(ParameterVisitor visitor) {
|
||||||
|
return visitor.visitIntegerParam(this);
|
||||||
|
}
|
||||||
|
|
||||||
public static Integer parseFromString(String valueS) {
|
public static Integer parseFromString(String valueS) {
|
||||||
return Integer.valueOf(valueS);
|
return Integer.valueOf(valueS);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import java.text.MessageFormat;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Tags;
|
import li.strolch.model.Tags;
|
||||||
|
import li.strolch.model.visitor.ParameterVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
@ -103,6 +104,11 @@ public class LongParameter extends AbstractParameter<Long> {
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <U> U accept(ParameterVisitor visitor) {
|
||||||
|
return visitor.visitLongParam(this);
|
||||||
|
}
|
||||||
|
|
||||||
public static Long parseFromString(String valueS) {
|
public static Long parseFromString(String valueS) {
|
||||||
return Long.valueOf(valueS);
|
return Long.valueOf(valueS);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import li.strolch.model.Order;
|
||||||
import li.strolch.model.ParameterizedElement;
|
import li.strolch.model.ParameterizedElement;
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
import li.strolch.model.StrolchElement;
|
import li.strolch.model.StrolchElement;
|
||||||
|
import li.strolch.model.visitor.ParameterVisitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
@ -158,4 +159,6 @@ public interface Parameter<T> extends StrolchElement {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Parameter<T> getClone();
|
public Parameter<T> getClone();
|
||||||
|
|
||||||
|
public <U> U accept(ParameterVisitor visitor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.List;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Tags;
|
import li.strolch.model.Tags;
|
||||||
|
import li.strolch.model.visitor.ParameterVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
@ -134,6 +135,11 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <U> U accept(ParameterVisitor visitor) {
|
||||||
|
return visitor.visitStringListParam(this);
|
||||||
|
}
|
||||||
|
|
||||||
public static List<String> parseFromString(String value) {
|
public static List<String> parseFromString(String value) {
|
||||||
if (value.isEmpty())
|
if (value.isEmpty())
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
|
|
|
@ -19,6 +19,7 @@ import java.text.MessageFormat;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Tags;
|
import li.strolch.model.Tags;
|
||||||
|
import li.strolch.model.visitor.ParameterVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
@ -104,4 +105,9 @@ public class StringParameter extends AbstractParameter<String> {
|
||||||
|
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <U> U accept(ParameterVisitor visitor) {
|
||||||
|
return visitor.visitStringParam(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* 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.visitor;
|
||||||
|
|
||||||
|
import li.strolch.model.parameter.BooleanParameter;
|
||||||
|
import li.strolch.model.parameter.DateParameter;
|
||||||
|
import li.strolch.model.parameter.FloatParameter;
|
||||||
|
import li.strolch.model.parameter.IntegerParameter;
|
||||||
|
import li.strolch.model.parameter.ListParameter;
|
||||||
|
import li.strolch.model.parameter.LongParameter;
|
||||||
|
import li.strolch.model.parameter.Parameter;
|
||||||
|
import li.strolch.model.parameter.StringListParameter;
|
||||||
|
import li.strolch.model.parameter.StringParameter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*/
|
||||||
|
public interface ParameterVisitor {
|
||||||
|
|
||||||
|
public <T> T visitParam(Parameter<?> param);
|
||||||
|
|
||||||
|
public <T> T visitBooleanParam(BooleanParameter param);
|
||||||
|
|
||||||
|
public <T> T visitDateParam(DateParameter param);
|
||||||
|
|
||||||
|
public <T> T visitFloatParam(FloatParameter param);
|
||||||
|
|
||||||
|
public <T> T visitIntegerParam(IntegerParameter param);
|
||||||
|
|
||||||
|
public <T> T visitLongParam(LongParameter param);
|
||||||
|
|
||||||
|
public <T> T visitStringParam(StringParameter param);
|
||||||
|
|
||||||
|
public <T> T visitListParam(ListParameter<?> param);
|
||||||
|
|
||||||
|
public <T> T visitStringListParam(StringListParameter param);
|
||||||
|
}
|
|
@ -0,0 +1,96 @@
|
||||||
|
/*
|
||||||
|
* 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.visitor;
|
||||||
|
|
||||||
|
import li.strolch.model.parameter.BooleanParameter;
|
||||||
|
import li.strolch.model.parameter.DateParameter;
|
||||||
|
import li.strolch.model.parameter.FloatParameter;
|
||||||
|
import li.strolch.model.parameter.IntegerParameter;
|
||||||
|
import li.strolch.model.parameter.ListParameter;
|
||||||
|
import li.strolch.model.parameter.LongParameter;
|
||||||
|
import li.strolch.model.parameter.Parameter;
|
||||||
|
import li.strolch.model.parameter.StringListParameter;
|
||||||
|
import li.strolch.model.parameter.StringParameter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*/
|
||||||
|
public class SetParameterValueVisitor implements ParameterVisitor {
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
public void setValue(Parameter<?> parameter, String value) {
|
||||||
|
this.value = value;
|
||||||
|
try {
|
||||||
|
parameter.accept(this);
|
||||||
|
} finally {
|
||||||
|
this.value = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T visitParam(Parameter<?> param) {
|
||||||
|
throw new UnsupportedOperationException("Not implemented on " + param.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T visitListParam(ListParameter<?> param) {
|
||||||
|
throw new UnsupportedOperationException("Not implemented on " + param.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T visitBooleanParam(BooleanParameter param) {
|
||||||
|
param.setValue(BooleanParameter.parseFromString(this.value));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T visitDateParam(DateParameter param) {
|
||||||
|
param.setValue(DateParameter.parseFromString(this.value));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T visitFloatParam(FloatParameter param) {
|
||||||
|
param.setValue(FloatParameter.parseFromString(this.value));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T visitIntegerParam(IntegerParameter param) {
|
||||||
|
param.setValue(IntegerParameter.parseFromString(this.value));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T visitLongParam(LongParameter param) {
|
||||||
|
param.setValue(LongParameter.parseFromString(this.value));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T visitStringParam(StringParameter param) {
|
||||||
|
param.setValue(this.value);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T visitStringListParam(StringListParameter param) {
|
||||||
|
param.setValue(StringListParameter.parseFromString(this.value));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -13,7 +13,9 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package li.strolch.model;
|
package li.strolch.model.visitor;
|
||||||
|
|
||||||
|
import li.strolch.model.StrolchElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
Loading…
Reference in New Issue