diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/pom.xml b/plugins/org.etsi.mts.tdl.execution.java.runtime/pom.xml index 7468d4ff2b090fa71dce604f977ee72c9f014fb3..7f00ced748aa8a578730c568e76111293ca31e34 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/pom.xml +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/pom.xml @@ -4,7 +4,7 @@ <modelVersion>4.0.0</modelVersion> <groupId>org.etsi.mts.tdl</groupId> <artifactId>org.etsi.mts.tdl.execution.java</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>1.0.0</version> <build> <sourceDirectory>src</sourceDirectory> <plugins> diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/adapters/DefaultAdapter.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/adapters/DefaultAdapter.java index 0ce391528855570e87ce1d5357d7700f6f4a1c07..35883391f5aba1444f21a2ef95afc97abfab13cd 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/adapters/DefaultAdapter.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/adapters/DefaultAdapter.java @@ -2,20 +2,16 @@ package org.etsi.mts.tdl.execution.java.adapters; import org.etsi.mts.tdl.execution.java.tri.Data; import org.etsi.mts.tdl.execution.java.tri.Reporter; -import org.etsi.mts.tdl.execution.java.tri.RuntimeHelper; -import org.etsi.mts.tdl.execution.java.tri.StopException; import org.etsi.mts.tdl.execution.java.tri.Validator; import org.etsi.mts.tdl.execution.java.tri.Verdict; -public class DefaultAdapter implements Validator, Reporter, RuntimeHelper { +public class DefaultAdapter implements Validator, Reporter { - @Override public boolean equals(Object o0, Object o1) { // TODO Auto-generated method stub return false; } - @Override public <T> T clone(T object) { // TODO Auto-generated method stub return object; diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/adapters/http/HttpSystemAdapter.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/adapters/http/HttpSystemAdapter.java index 6f0178e3cf2c3c63c7dde3608eda1efd5412b26a..5968066c955260544a7d3142d14d9c9b9d503153 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/adapters/http/HttpSystemAdapter.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/adapters/http/HttpSystemAdapter.java @@ -25,6 +25,7 @@ import org.etsi.mts.tdl.execution.java.tri.Connection; import org.etsi.mts.tdl.execution.java.tri.Data; import org.etsi.mts.tdl.execution.java.tri.ElementAnnotation; import org.etsi.mts.tdl.execution.java.tri.Mapping; +import org.etsi.mts.tdl.execution.java.tri.NamedElement; import org.etsi.mts.tdl.execution.java.tri.Procedure; import org.etsi.mts.tdl.execution.java.tri.Reporter; import org.etsi.mts.tdl.execution.java.tri.SystemAdapter; @@ -267,6 +268,11 @@ public class HttpSystemAdapter implements SystemAdapter { throw new UnsupportedOperationException("Procedure-based communication is not supported by this adapter."); } + @Override + public Data callFunction(NamedElement function, Argument[] arguments) { + throw new UnsupportedOperationException("Custom function implementations should be provided by extensions."); + } + protected HttpRequestData getRequestData(Data message) { if (message.getValue() instanceof HttpRequestData) return (HttpRequestData) message.getValue(); @@ -290,8 +296,8 @@ public class HttpSystemAdapter implements SystemAdapter { Mapping rs = m.getResource(); boolean isMapped = false; - for (ElementAnnotation a : rs.annotations) { - if (a.key.equals("Tdl::MappingName") && a.value.equals("Java")) { + for (ElementAnnotation a : rs.getAnnotations()) { + if (a.getKey().equals("Tdl::MappingName") && a.getValue().equals("Java")) { isMapped = true; break; } diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/ArgumentImpl.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/ArgumentImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..06d59fe401cd56ff4dc9edcab209976574a14a2f --- /dev/null +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/ArgumentImpl.java @@ -0,0 +1,21 @@ +package org.etsi.mts.tdl.execution.java.rt.core; + +import org.etsi.mts.tdl.execution.java.tri.Data; + +public class ArgumentImpl<T, V> extends DataImpl<T, V> { + private String parameterName; + + public ArgumentImpl(T type, V value, String parameterName) { + super(type, value); + this.parameterName = parameterName; + } + + public ArgumentImpl(Data<T, V> data, String parameterName) { + super(data.getType(), data.getValue()); + this.parameterName = parameterName; + } + + public String getParameterName() { + return parameterName; + } +} diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/ConnectionImpl.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/ConnectionImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..2920c661b5cfe38039ffd43a93c19c88bf84fb5f --- /dev/null +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/ConnectionImpl.java @@ -0,0 +1,27 @@ +package org.etsi.mts.tdl.execution.java.rt.core; + +import org.etsi.mts.tdl.execution.java.tri.Connection; +import org.etsi.mts.tdl.execution.java.tri.GateReference; + +public class ConnectionImpl extends ElementImpl implements Connection { + + + private final GateReference[] endPoints = new GateReference[2]; + + public ConnectionImpl(String name, GateReference sourceGate, GateReference targetGate) { + super(name); + getEndPoints()[0] = sourceGate; + getEndPoints()[1] = targetGate; + } + + public GateReference[] getEndPoints() { + return endPoints; + } + + @Override + public String toString() { + if (name != null) + return name; + return getEndPoints()[0].toString() + " :: " + getEndPoints()[1].toString(); + } +} diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/DataImpl.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/DataImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..2a82986da1a0e8c1f305784dbb5ebf1683909f9c --- /dev/null +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/DataImpl.java @@ -0,0 +1,29 @@ +package org.etsi.mts.tdl.execution.java.rt.core; + +import org.etsi.mts.tdl.execution.java.tri.Data; + +/** + * In Java environment the <code>type</code> is a Java class and + * <code>value</code> is an object of that class or a lambda expression that + * returns such object. + */ +public class DataImpl<T, V> implements Data<T, V> { + + private T type; + + private V value; + + public DataImpl(T type, V value) { + this.type = type; + this.value = value; + } + + public V getValue() { + return value; + } + + public T getType() { + return type; + } + +} diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/ElementAnnotationImpl.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/ElementAnnotationImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..096e6ff503de2dd7e7bc6e7a73de5bed72e4514a --- /dev/null +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/ElementAnnotationImpl.java @@ -0,0 +1,22 @@ +package org.etsi.mts.tdl.execution.java.rt.core; + +import org.etsi.mts.tdl.execution.java.tri.ElementAnnotation; + +public class ElementAnnotationImpl implements ElementAnnotation { + + public String key, value; + + public ElementAnnotationImpl(String key, String value) { + this.key = key; + this.value = value; + } + + public String getKey() { + return key; + } + + public String getValue() { + return value; + } + +} diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/ElementImpl.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/ElementImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..b1f54b2b378bf3d9eab215bc079a41f8eef94b57 --- /dev/null +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/ElementImpl.java @@ -0,0 +1,42 @@ +package org.etsi.mts.tdl.execution.java.rt.core; + +import java.util.ArrayList; +import java.util.List; + +import org.etsi.mts.tdl.execution.java.tri.Element; +import org.etsi.mts.tdl.execution.java.tri.ElementAnnotation; + +public class ElementImpl implements Element { + + protected String name; + + + private List<ElementAnnotation> annotations = new ArrayList<ElementAnnotation>(); + + public ElementImpl() { + } + + public ElementImpl(String name) { + this.name = name; + } + + @Override + public String getName() { + return name; + } + + @Override + public List<ElementAnnotation> getAnnotations() { + return annotations; + } + + + public void setAnnotations(List<ElementAnnotation> annotations) { + this.annotations = annotations; + } + + public ElementImpl addAnnotation(String key, String value) { + this.getAnnotations().add(new ElementAnnotationImpl(key, value)); + return this; + } +} diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/GateReferenceImpl.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/GateReferenceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..db1dbcce418d692acaa69ded20f0d19454fd0e17 --- /dev/null +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/GateReferenceImpl.java @@ -0,0 +1,85 @@ +package org.etsi.mts.tdl.execution.java.rt.core; + +import org.etsi.mts.tdl.execution.java.tri.ComponentInstanceRole; +import org.etsi.mts.tdl.execution.java.tri.Element; +import org.etsi.mts.tdl.execution.java.tri.GateReference; +import org.etsi.mts.tdl.execution.java.tri.GateTypeKind; +import org.etsi.mts.tdl.execution.java.tri.NamedElement; + +/** + * Encapsulation of a connection end-point specification. It's an aggregation of + * following TDL model elements: + * <ul> + * <li>GateInstance</li> + * <li>GateType</li> + * <li>ComponentInstance</li> + * <li>ComponentType</li> + * <li>ComponentInstanceRole</li> + * </ul> + * + */ +public class GateReferenceImpl implements GateReference { + private Element gate; + private NamedElement gateType; + private GateTypeKind gateTypeKind; + private Element component; + private NamedElement componentType; + private ComponentInstanceRole role; + + public GateReferenceImpl(Element gate, NamedElement gateType, GateTypeKind gateTypeKind, Element component, NamedElement componentType, + ComponentInstanceRole role) { + this.gate = gate; + this.gateType = gateType; + this.gateTypeKind = gateTypeKind; + this.component = component; + this.componentType = componentType; + this.role = role; + } + + @Override + public Element getGate() { + return gate; + } + + @Override + public NamedElement getGateType() { + return gateType; + } + + @Override + public GateTypeKind getGateTypeKind() { + return gateTypeKind; + } + + @Override + public Element getComponent() { + return component; + } + + @Override + public NamedElement getComponentType() { + return componentType; + } + + @Override + public ComponentInstanceRole getComponentRole() { + return role; + } + + @Override + public int hashCode() { + return gate.hashCode() << 8 + gateType.hashCode() << 6 + component.hashCode() << 4 + + componentType.hashCode() << 2 + role.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof GateReferenceImpl) { + GateReferenceImpl gr = (GateReferenceImpl) obj; + return gate.equals(gr.gate) && gateType.equals(gr.gateType) && component.equals(gr.component) + && componentType.equals(gr.componentType) && role.equals(gr.role); + } + return super.equals(obj); + } + +} \ No newline at end of file diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/MappingImpl.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/MappingImpl.java index 176a091ed10005b48252abf752902bb7708e17d7..f675b39494c2dfdc590086dc3b579851e2f9ba81 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/MappingImpl.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/MappingImpl.java @@ -3,10 +3,9 @@ package org.etsi.mts.tdl.execution.java.rt.core; import java.util.Hashtable; import java.util.Map; -import org.etsi.mts.tdl.execution.java.tri.ElementAnnotation; import org.etsi.mts.tdl.execution.java.tri.Mapping; -public class MappingImpl extends Mapping implements TriImpl<MappingImpl, MappingImpl> { +public class MappingImpl extends ElementImpl implements Mapping, TriImpl<MappingImpl, MappingImpl> { private String mappingName; private boolean resource; @@ -83,7 +82,7 @@ public class MappingImpl extends Mapping implements TriImpl<MappingImpl, Mapping @Override public MappingImpl addAnnotation(String key, String value) { - this.annotations.add(new ElementAnnotation(key, value)); + super.addAnnotation(key, value); return this; } diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/NamedElementImpl.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/NamedElementImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..7b0fdaf07a2a795529422595a9b6f838ab8b2215 --- /dev/null +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/NamedElementImpl.java @@ -0,0 +1,25 @@ +package org.etsi.mts.tdl.execution.java.rt.core; + +import org.etsi.mts.tdl.execution.java.tri.NamedElement; + +public class NamedElementImpl extends ElementImpl implements NamedElement { + + protected String qualifiedName; + + public NamedElementImpl() { + } + + public NamedElementImpl(String name, String qualifiedName) { + super(name); + this.setQualifiedName(qualifiedName); + } + + @Override + public String getQualifiedName() { + return qualifiedName; + } + + protected void setQualifiedName(String qualifiedName) { + this.qualifiedName = qualifiedName; + } +} diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/ParameterImpl.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/ParameterImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..47eba181da5c9ef9d6d00fb4b6d694d60a38ca91 --- /dev/null +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/ParameterImpl.java @@ -0,0 +1,29 @@ +package org.etsi.mts.tdl.execution.java.rt.core; + +import org.etsi.mts.tdl.execution.java.tri.Parameter; + +public class ParameterImpl extends ElementImpl implements Parameter<TypeImpl> { + + private TypeImpl type; + + public ParameterImpl(String parameterName) { + super(parameterName); + } + + @Override + public ParameterImpl addAnnotation(String key, String value) { + super.addAnnotation(key, value); + return this; + } + + public ParameterImpl setType(TypeImpl type) { + this.type = type; + return this; + } + + @Override + public TypeImpl getType() { + return type; + } + +} diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/PojoArgument.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/PojoArgument.java index 2a46bab2ea8583c6a77eb87c137fee9cf2d71454..c3c8ecc34416abe757d07dd15b242035824de74c 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/PojoArgument.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/PojoArgument.java @@ -1,8 +1,6 @@ package org.etsi.mts.tdl.execution.java.rt.core; -import org.etsi.mts.tdl.execution.java.tri.Argument; - -public class PojoArgument<V> extends Argument<Class<V>, V> { +public class PojoArgument<V> extends ArgumentImpl<Class<V>, V> { public PojoArgument(V value, String parameterName) { super((Class<V>) value.getClass(), value, parameterName); diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/PojoData.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/PojoData.java index 9c7b111681c0ab07bb1217e7f8d672773c35f39e..460be0db696e86cfb18136c7309d02e1ad721fcc 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/PojoData.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/PojoData.java @@ -1,8 +1,6 @@ package org.etsi.mts.tdl.execution.java.rt.core; -import org.etsi.mts.tdl.execution.java.tri.Data; - -public class PojoData<V> extends Data<Class<V>, V> { +public class PojoData<V> extends DataImpl<Class<V>, V> { public PojoData(V value) { super((Class<V>) value.getClass(), value); diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/PredefinedFunctionsImpl.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/PredefinedFunctionsImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..74797f303e75c00688be98904408bc5d7896ae13 --- /dev/null +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/PredefinedFunctionsImpl.java @@ -0,0 +1,151 @@ +package org.etsi.mts.tdl.execution.java.rt.core; + +import java.util.Collection; + +import org.etsi.mts.tdl.execution.java.tri.Data; +import org.etsi.mts.tdl.execution.java.tri.PredefinedFunctions; +import org.etsi.mts.tdl.execution.java.tri.Value; + +import com.google.inject.Inject; + +/** + * Default implementation of predefined functions specified in TDL. + */ +public class PredefinedFunctionsImpl implements PredefinedFunctions { + + @Inject + public PredefinedFunctionsImpl() { + } + + @Override + public boolean equals(Data<?, ?> d0, Data<?, ?> d1) { + return d0.equals(d1); + } + + @Override + public boolean notEquals(Data<?, ?> d0, Data<?, ?> d1) { + return !equals(d0, d1); + } + + @Override + public boolean and(boolean b0, boolean b1) { + return b0 && b1; + } + + @Override + public boolean or(boolean b0, boolean b1) { + return b0 || b1; + } + + @Override + public boolean xor(boolean b0, boolean b1) { + return b0 ^ b1; + } + + @Override + public boolean not(boolean b) { + return !b; + } + + @Override + public boolean lt(int i0, int i1) { + return i0 < i1; + } + + @Override + public boolean gt(int i0, int i1) { + return i0 > i1; + } + + @Override + public boolean lteq(int i0, int i1) { + return i0 <= i1; + } + + @Override + public boolean gteq(int i0, int i1) { + return i0 >= i1; + } + + @Override + public boolean lt(long i0, long i1) { + return i0 < i1; + } + + @Override + public boolean gt(long i0, long i1) { + return i0 > i1; + } + + @Override + public boolean lteq(long i0, long i1) { + return i0 <= i1; + } + + @Override + public boolean gteq(long i0, long i1) { + return i0 >= i1; + } + + @Override + public int plus(int i0, int i1) { + return i0 + i1; + } + + @Override + public int minus(int i0, int i1) { + return i0 - i1; + } + + @Override + public int multiply(int i0, int i1) { + return i0 * i1; + } + + @Override + public int divide(int i0, int i1) { + return i0 / i1; + } + + @Override + public int mod(int i0, int i1) { + return i0 % i1; + } + + @Override + public long plus(long i0, long i1) { + return i0 + i1; + } + + @Override + public long minus(long i0, long i1) { + return i0 - i1; + } + + @Override + public long multiply(long i0, long i1) { + return i0 * i1; + } + + @Override + public long divide(long i0, long i1) { + return i0 / i1; + } + + @Override + public long mod(long i0, long i1) { + return i0 % i1; + } + + @Override + public int size(Data<?, ?> collection) { + Object v = collection.getValue(); + if (v instanceof Collection<?>) + return ((Collection<?>) v).size(); + if (v instanceof Value) + if (((Value) v).isCollection()) + return ((Value) v).getItems().size(); + throw new IllegalArgumentException("Argument is not a collection."); + } + +} diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/ProcedureImpl.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/ProcedureImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..54ccd30694f9f680a1ad76950934943bd7eff9b9 --- /dev/null +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/ProcedureImpl.java @@ -0,0 +1,66 @@ +package org.etsi.mts.tdl.execution.java.rt.core; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; + +import org.etsi.mts.tdl.execution.java.tri.Parameter; +import org.etsi.mts.tdl.execution.java.tri.Procedure; + +/** + * May optionally be mapped to a method that implements the calling of the + * procedure + */ +public class ProcedureImpl extends NamedElementImpl implements Procedure { + + private List<ParameterImpl> in = new ArrayList<ParameterImpl>(); + private List<ParameterImpl> out = new ArrayList<ParameterImpl>(); + private List<ParameterImpl> exception = new ArrayList<ParameterImpl>(); + + private Consumer<Object[]> function; + + public ProcedureImpl addIn(ParameterImpl p) { + this.in.add(p); + return this; + } + + public ProcedureImpl addOut(ParameterImpl p) { + this.out.add(p); + return this; + } + + public ProcedureImpl addException(ParameterImpl p) { + this.exception.add(p); + return this; + } + + @Override + public List<Parameter> getIn() { + return (List)in; + } + + @Override + public List<Parameter> getOut() { + return (List)out; + } + + @Override + public List<Parameter> getException() { + return (List)exception; + } + + /** + * Optional function that implements this procedure call. + * <p> + * The function parameters must match the order and types of parameters of the + * procedure call. That is, for each parameter of a procedure call, a method + * parameter must exist such that the procedure call parameter type is mapped to + * the method parameter type (or class). + */ + public void setFunction(Consumer<Object[]> function) { + this.function = function; + } + public Consumer<Object[]> getFunction() { + return function; + } +} diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/StopExceptionImpl.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/StopExceptionImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..e1eca3654e05c67686d9463b21fedbb24a3db5cb --- /dev/null +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/StopExceptionImpl.java @@ -0,0 +1,23 @@ +package org.etsi.mts.tdl.execution.java.rt.core; + +import org.etsi.mts.tdl.execution.java.tri.StopException; +import org.etsi.mts.tdl.execution.java.tri.Verdict; + +@SuppressWarnings("serial") +public class StopExceptionImpl extends StopException { + + private Verdict verdict; + + public StopExceptionImpl(String message) { + super(message); + } + + public StopExceptionImpl(String message, Verdict verdict) { + super(message); + this.verdict = verdict; + } + + public Verdict getVerdict() { + return verdict; + } +} diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/TestControl.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/TestControl.java index 34f2bae43910df4f5444412f88a3a6e05461abeb..cc13d75c7636297f638a4ecf7d275625280c9ec8 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/TestControl.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/TestControl.java @@ -19,8 +19,6 @@ import org.etsi.mts.tdl.execution.java.tri.Data; import org.etsi.mts.tdl.execution.java.tri.GateReference; import org.etsi.mts.tdl.execution.java.tri.PredefinedFunctions; import org.etsi.mts.tdl.execution.java.tri.Reporter; -import org.etsi.mts.tdl.execution.java.tri.RuntimeHelper; -import org.etsi.mts.tdl.execution.java.tri.StopException; import org.etsi.mts.tdl.execution.java.tri.SystemAdapter; import org.etsi.mts.tdl.execution.java.tri.Validator; @@ -34,7 +32,6 @@ public class TestControl { public Validator validator; public Reporter reporter; public PredefinedFunctions functions; - public RuntimeHelper runtimeHelper; private Connection[] connections; private Map<Connection, ReceiverHub> receiverHubs = Collections @@ -59,7 +56,6 @@ public class TestControl { this.validator = injector.getInstance(Validator.class); this.reporter = injector.getInstance(Reporter.class); this.functions = injector.getInstance(PredefinedFunctions.class); - this.runtimeHelper = injector.getInstance(RuntimeHelper.class); this.executor = Executors.newCachedThreadPool(); this.completionService = new ExecutorCompletionService<ExecutionResult>(executor); @@ -88,7 +84,7 @@ public class TestControl { ExceptionalBehaviour anyReceiver = new ExceptionalBehaviour(false); anyReceiver.behaviour = () -> { - throw new StopException("Unexpected message received"); + throw new StopExceptionImpl("Unexpected message received"); }; anyReceiver.callable = new ExecutionCallable() { @Override @@ -109,16 +105,16 @@ public class TestControl { for (Connection c : connections) { int testerEP = -1; for (int i = 0; i <= 1; i++) - if (c.endPoints[i].component.getName().equals(testerComponentName) - && c.endPoints[i].gate.getName().equals(testerGateName)) { + if (c.getEndPoints()[i].getComponent().getName().equals(testerComponentName) + && c.getEndPoints()[i].getGate().getName().equals(testerGateName)) { testerEP = i; break; } if (testerEP == -1) continue; int targetEP = testerEP == 0 ? 1 : 0; - if (c.endPoints[targetEP].component.getName().equals(remoteComponentName) - && c.endPoints[targetEP].gate.getName().equals(remoteGateName)) + if (c.getEndPoints()[targetEP].getComponent().getName().equals(remoteComponentName) + && c.getEndPoints()[targetEP].getGate().getName().equals(remoteGateName)) return c; } throw new RuntimeException(String.format("Unknown connection: from %s.%s to %s.%s", testerComponentName, @@ -128,9 +124,9 @@ public class TestControl { public GateReference getGateReference(String testerComponentName, String testerGateName) { for (Connection c : connections) { for (int i = 0; i <= 1; i++) - if (c.endPoints[i].component.getName().equals(testerComponentName) - && c.endPoints[i].gate.getName().equals(testerGateName)) { - return c.endPoints[i]; + if (c.getEndPoints()[i].getComponent().getName().equals(testerComponentName) + && c.getEndPoints()[i].getGate().getName().equals(testerGateName)) { + return c.getEndPoints()[i]; } } throw new RuntimeException(String.format("Unknown gate: %s.%s", testerComponentName, testerGateName)); diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/Timer.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/Timer.java index 097881ecb47c178f4cd359a1ecfa541892f5b0bc..ece89a6efeb9469b452ab4eccf6dafe004d525fc 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/Timer.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/Timer.java @@ -1,8 +1,6 @@ package org.etsi.mts.tdl.execution.java.rt.core; -import org.etsi.mts.tdl.execution.java.tri.NamedElement; - -public class Timer extends NamedElement { +public class Timer extends NamedElementImpl { private TimeUnit unit; diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/TypeImpl.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/TypeImpl.java index a1aadfd8bc8832f3267cce7dec0a89729ddcf0b8..9628d5676783e3795852acc83b85830d65232dbc 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/TypeImpl.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/TypeImpl.java @@ -7,12 +7,11 @@ import java.util.List; import java.util.Map; import org.etsi.mts.tdl.execution.java.tri.Data; -import org.etsi.mts.tdl.execution.java.tri.ElementAnnotation; import org.etsi.mts.tdl.execution.java.tri.Mapping; import org.etsi.mts.tdl.execution.java.tri.Type; import org.etsi.mts.tdl.execution.java.tri.Value; -public class TypeImpl extends Type implements TriImpl<TypeImpl, TypeImpl> { +public class TypeImpl extends NamedElementImpl implements Type, TriImpl<TypeImpl, TypeImpl> { private boolean structure = false; private boolean collection = false; private boolean enumerated = false; @@ -95,20 +94,20 @@ public class TypeImpl extends Type implements TriImpl<TypeImpl, TypeImpl> { } public TypeImpl addEnumLiteral(ValueImpl literal) { - this.enumLiterals.add(new Data<Type, Value>(this, literal)); + this.enumLiterals.add(new DataImpl<Type, Value>(this, literal)); return this; } @Override public TypeImpl setName(String name, String qualifiedName) { this.name = name; - this.qualifiedName = qualifiedName; + this.setQualifiedName(qualifiedName); return this; } @Override public TypeImpl addAnnotation(String key, String value) { - this.annotations.add(new ElementAnnotation(key, value)); + super.addAnnotation(key, value); return this; } diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/ValueImpl.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/ValueImpl.java index 9230ae42339bce04df73c03ae659f5395a61adbe..efbd59cc7dd2859451124443b2397163b6481d76 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/ValueImpl.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/ValueImpl.java @@ -7,12 +7,11 @@ import java.util.List; import java.util.Map; import org.etsi.mts.tdl.execution.java.tri.Data; -import org.etsi.mts.tdl.execution.java.tri.ElementAnnotation; import org.etsi.mts.tdl.execution.java.tri.Mapping; import org.etsi.mts.tdl.execution.java.tri.Type; import org.etsi.mts.tdl.execution.java.tri.Value; -public class ValueImpl extends Value implements TriImpl<ValueImpl, Data<Type, Value>> { +public class ValueImpl extends NamedElementImpl implements Value, TriImpl<ValueImpl, Data<Type, Value>> { private TypeImpl type; private boolean collection = false; @@ -23,14 +22,14 @@ public class ValueImpl extends Value implements TriImpl<ValueImpl, Data<Type, Va private List<Data<Type, Value>> items = new ArrayList<Data<Type, Value>>(); private MappingImpl mapping; - + public ValueImpl() { } public ValueImpl(TypeImpl type) { this.type = type; } - + public ValueImpl setType(TypeImpl type) { this.type = type; return this; @@ -75,7 +74,7 @@ public class ValueImpl extends Value implements TriImpl<ValueImpl, Data<Type, Va this.value = value; return this; } - + @Override public Collection<String> getParameters() { return this.parameters.keySet(); @@ -110,18 +109,18 @@ public class ValueImpl extends Value implements TriImpl<ValueImpl, Data<Type, Va @Override public ValueImpl setName(String name, String qualifiedName) { this.name = name; - this.qualifiedName = qualifiedName; + this.setQualifiedName(qualifiedName); return this; } @Override public ValueImpl addAnnotation(String key, String value) { - this.annotations.add(new ElementAnnotation(key, value)); + super.addAnnotation(key, value); return this; } public Data<Type, Value> asData() { - return new Data<Type, Value>(type, this); + return new DataImpl<Type, Value>(type, this); } } diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/VerdictImpl.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/VerdictImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..82495e9c4847b1c8313140e26ee7aa98e4228bd4 --- /dev/null +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/core/VerdictImpl.java @@ -0,0 +1,15 @@ +package org.etsi.mts.tdl.execution.java.rt.core; + +import org.etsi.mts.tdl.execution.java.tri.Verdict; + +public class VerdictImpl extends NamedElementImpl implements Verdict { + /** + * Verdict instance predefined in TDL. + */ + public static VerdictImpl pass = new VerdictImpl("pass"), fail = new VerdictImpl("fail"), + inconclusive = new VerdictImpl("inconclusive"); + + public VerdictImpl(String name) { + super(name, null); + } +} diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/data/AcceptedType.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/data/AcceptedType.java deleted file mode 100644 index c1295269ed5e609f0f16fde7cc32e3999e5d6483..0000000000000000000000000000000000000000 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/rt/data/AcceptedType.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.etsi.mts.tdl.execution.java.rt.data; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * HTTP Accept header value usable on String fields. - * XXX who dis? - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface AcceptedType { -} diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Argument.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Argument.java index 11391cc063849d2c29192ce35f20f8dd05e03461..ae35783d3fa5a6a6f58fd27061530f955657428f 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Argument.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Argument.java @@ -4,23 +4,10 @@ package org.etsi.mts.tdl.execution.java.tri; * Extends {@link Data Data} to provide name of a parameter. The argument is * specified using <code>type</code> and <code>value</code>. */ -public class Argument<T, V> extends Data<T, V> { +public interface Argument<T, V> extends Data<T, V> { + /** * Name of the parameter as specified in TDL model. */ - private String parameterName; - - public Argument(T type, V value, String parameterName) { - super(type, value); - this.parameterName = parameterName; - } - - public Argument(Data<T, V> data, String parameterName) { - super(data.getType(), data.getValue()); - this.parameterName = parameterName; - } - - public String getParameterName() { - return parameterName; - } + String getParameterName(); } diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Connection.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Connection.java index 3b0303f1a260f75908e1f26c81b336f7a86fe14b..415dff5a22dc5a52fb4a56a2062258a38f5e09bb 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Connection.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Connection.java @@ -4,23 +4,10 @@ package org.etsi.mts.tdl.execution.java.tri; * Encapsulation of connected <code>GateReference</code>s. * */ -public class Connection extends Element { +public interface Connection extends Element { /** * The end-points of this connection as specified in TDL model. */ - public final GateReference[] endPoints = new GateReference[2]; - - public Connection(String name, GateReference sourceGate, GateReference targetGate) { - super(name); - endPoints[0] = sourceGate; - endPoints[1] = targetGate; - } - - @Override - public String toString() { - if (name != null) - return name; - return endPoints[0].toString() + " :: " + endPoints[1].toString(); - } + GateReference[] getEndPoints(); } diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Data.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Data.java index 6f45ace0a54113a316a0566e2558e2a7c0b658d0..2343744e99ea1f42eb9e51cf7159136e5e04120f 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Data.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Data.java @@ -3,41 +3,17 @@ package org.etsi.mts.tdl.execution.java.tri; /** * Encapsulation of type and value. The objects are resolved using TDL data * mappings. - * <p> - * In Java environment the <code>type</code> is a Java class and - * <code>value</code> is an object of that class or a lambda expression that - * returns such object. */ -public class Data<T, V> { - - /** - * The type information in environment specific form that can be used to decode - * incoming data. For example, an annotated class. - */ - private T type; - +public interface Data<T, V> { /** * The decoded value of the data that matches the type. */ - private V value; - - public Data(T type, V value) { - this.type = type; - this.value = value; - } - - /** - * @see #value - */ - public V getValue() { - return value; - } + V getValue(); /** - * @see #type + * The type information in environment specific form that can be used to decode + * incoming data. For example, an annotated class. */ - public T getType() { - return type; - } + T getType(); } diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Element.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Element.java index 305dd732ca685284f2d87115d0258e662040bdbf..6ee44bae4f8188ce49e707d05235bcef9e8194b4 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Element.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Element.java @@ -1,6 +1,5 @@ package org.etsi.mts.tdl.execution.java.tri; -import java.util.ArrayList; import java.util.List; /** @@ -10,25 +9,16 @@ import java.util.List; * meta-class. * */ -public class Element { +public interface Element { + /** * The name of the element as specified in TDL model. */ - protected String name; + String getName(); /** * The annotations assigned to the element as specified in TDL model. */ - public List<ElementAnnotation> annotations = new ArrayList<ElementAnnotation>(); - - public Element() { - } + List<ElementAnnotation> getAnnotations(); - public Element(String name) { - this.name = name; - } - - public String getName() { - return name; - } } diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/ElementAnnotation.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/ElementAnnotation.java index 62a1d4f957168270f2a96f9d22ca194e66d9be6d..d7062d83c2098d45be7095af8d0bf6b0fc41273b 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/ElementAnnotation.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/ElementAnnotation.java @@ -3,15 +3,16 @@ package org.etsi.mts.tdl.execution.java.tri; /** * Annotation as specified in TDL model. */ -public class ElementAnnotation { +public interface ElementAnnotation { + + /** + * Key of the annotation. + */ + String getKey(); + /** - * Key and value of the annotation. + * Value of the annotation. */ - public String key, value; + String getValue(); - public ElementAnnotation(String key, String value) { - this.key = key; - this.value = value; - } - } diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/GateReference.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/GateReference.java index f00f9e1d66df60ebfe37fd1dc4f563db1f8c82a0..382a7ef2b33bb24cd59f401daa41a2c4f03b2a01 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/GateReference.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/GateReference.java @@ -12,36 +12,18 @@ package org.etsi.mts.tdl.execution.java.tri; * </ul> * */ -public class GateReference { - public Element gate; - public Element gateType; - public Element component; - public Element componentType; - public ComponentInstanceRole role; +public interface GateReference { - public GateReference(Element gate, Element gateType, Element component, Element componentType, - ComponentInstanceRole role) { - this.gate = gate; - this.gateType = gateType; - this.component = component; - this.componentType = componentType; - this.role = role; - } + Element getGate(); - @Override - public int hashCode() { - return gate.hashCode() << 8 + gateType.hashCode() << 6 + component.hashCode() << 4 - + componentType.hashCode() << 2 + role.hashCode(); - } + NamedElement getGateType(); + + GateTypeKind getGateTypeKind(); - @Override - public boolean equals(Object obj) { - if (obj instanceof GateReference) { - GateReference gr = (GateReference) obj; - return gate.equals(gr.gate) && gateType.equals(gr.gateType) && component.equals(gr.component) - && componentType.equals(gr.componentType) && role.equals(gr.role); - } - return super.equals(obj); - } + Element getComponent(); + + NamedElement getComponentType(); + + ComponentInstanceRole getComponentRole(); } \ No newline at end of file diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Mapping.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Mapping.java index 38e3fb40f7e0ccdc542e5ff4e9fb7c7d62f64afe..9ae6c7266e088d74e147c03b7d9cd917f64a8422 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Mapping.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Mapping.java @@ -4,14 +4,14 @@ package org.etsi.mts.tdl.execution.java.tri; * Representation of a TDL model element of class <i>DataResourceMapping</i>, * <i>DataElementMapping</i> or <i>ParameterMapping</i>. */ -public abstract class Mapping extends Element { +public interface Mapping extends Element { /** * Get the name applied to the associated <i>DataResourceMapping</i> element * using the predefined <i>MappingName</i> annotation. * * @return A distinctive name for this mapping. */ - public abstract String getMappingName(); + String getMappingName(); /** * If this is a resource mapping. @@ -19,7 +19,7 @@ public abstract class Mapping extends Element { * @return <b>true</b> if this type represents a <i>DataResourceMapping</i> * element. */ - public abstract boolean isResource(); + boolean isResource(); /** * If this is a parameter mapping. @@ -27,14 +27,14 @@ public abstract class Mapping extends Element { * @return <b>true</b> if this type represents a <i>ParameterMapping</i> * element. */ - public abstract boolean isParameter(); + boolean isParameter(); /** * Get the type-sepcific URI for this mapping. * * @return The URI of this mapping as specified in corresponding model element. */ - public abstract String getUri(); + String getUri(); /** * Get the resource mapping for this data mapping. @@ -43,7 +43,7 @@ public abstract class Mapping extends Element { * element referenced by the associated <i>DataElementMapping</i> * element. */ - public abstract Mapping getResource(); + Mapping getResource(); /** * Get the parameter mappings of this data mapping. @@ -54,6 +54,6 @@ public abstract class Mapping extends Element { * @return A <code>Mapping</code> representing a <i>ParameterMapping</i> * element. */ - public abstract Mapping getParameter(String parameterName); + Mapping getParameter(String parameterName); } diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/NamedElement.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/NamedElement.java index 53e0df1125f2755c405ca92f58ac449fadd5885a..71e395ca77887557c5d0e915963c67cc8a3b69e9 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/NamedElement.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/NamedElement.java @@ -5,21 +5,10 @@ package org.etsi.mts.tdl.execution.java.tri; * in TDL. * */ -public class NamedElement extends Element { +public interface NamedElement extends Element { + /** * The qualified name of the element as specified in TDL model. */ - protected String qualifiedName; - - public NamedElement() { - } - - public NamedElement(String name, String qualifiedName) { - super(name); - this.qualifiedName = qualifiedName; - } - - public String getQualifiedName() { - return qualifiedName; - } + String getQualifiedName(); } diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Parameter.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Parameter.java new file mode 100644 index 0000000000000000000000000000000000000000..98c4b47389753d45c66041b165894dc22eee8e74 --- /dev/null +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Parameter.java @@ -0,0 +1,10 @@ +package org.etsi.mts.tdl.execution.java.tri; + +/** + * Representation of a TDL model element of class <i>Parameter</i> and its + * sub-classes. + */ +public interface Parameter<T> extends Element { + + T getType(); +} diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/PredefinedFunctions.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/PredefinedFunctions.java index 16bea9c893cf71bfefedaaff7e1bf79aa6e08b53..b9870fd834d63bafafe5e349820a37fa1eae335d 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/PredefinedFunctions.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/PredefinedFunctions.java @@ -1,122 +1,58 @@ package org.etsi.mts.tdl.execution.java.tri; -import java.util.Collection; +public interface PredefinedFunctions { -import com.google.inject.Inject; + boolean equals(Data<?, ?> d0, Data<?, ?> d1); -/** - * Default implementation of predefined functions specified in TDL. - */ -public class PredefinedFunctions { + boolean notEquals(Data<?, ?> d0, Data<?, ?> d1); - public RuntimeHelper helper; + boolean and(boolean b0, boolean b1); - @Inject - public PredefinedFunctions(RuntimeHelper helper) { - this.helper = helper; - } + boolean or(boolean b0, boolean b1); - public boolean equals(Data<?, ?> d0, Data<?, ?> d1) { - return helper.equals(d0.getValue(), d1.getValue()); - } + boolean xor(boolean b0, boolean b1); - public boolean notEquals(Data<?, ?> d0, Data<?, ?> d1) { - return !equals(d0, d1); - } + boolean not(boolean b); - public boolean and(boolean b0, boolean b1) { - return b0 && b1; - } + boolean lt(int i0, int i1); - public boolean or(boolean b0, boolean b1) { - return b0 || b1; - } + boolean gt(int i0, int i1); - public boolean xor(boolean b0, boolean b1) { - return b0 ^ b1; - } + boolean lteq(int i0, int i1); - public boolean not(boolean b) { - return !b; - } + boolean gteq(int i0, int i1); - public boolean lt(int i0, int i1) { - return i0 < i1; - } + boolean lt(long i0, long i1); - public boolean gt(int i0, int i1) { - return i0 > i1; - } + boolean gt(long i0, long i1); - public boolean lteq(int i0, int i1) { - return i0 <= i1; - } + boolean lteq(long i0, long i1); - public boolean gteq(int i0, int i1) { - return i0 >= i1; - } + boolean gteq(long i0, long i1); - public boolean lt(long i0, long i1) { - return i0 < i1; - } + int plus(int i0, int i1); - public boolean gt(long i0, long i1) { - return i0 > i1; - } + int minus(int i0, int i1); - public boolean lteq(long i0, long i1) { - return i0 <= i1; - } + int multiply(int i0, int i1); - public boolean gteq(long i0, long i1) { - return i0 >= i1; - } + int divide(int i0, int i1); - public int plus(int i0, int i1) { - return i0 + i1; - } + int mod(int i0, int i1); - public int minus(int i0, int i1) { - return i0 - i1; - } + long plus(long i0, long i1); - public int multiply(int i0, int i1) { - return i0 * i1; - } + long minus(long i0, long i1); - public int divide(int i0, int i1) { - return i0 / i1; - } + long multiply(long i0, long i1); - public int mod(int i0, int i1) { - return i0 % i1; - } + long divide(long i0, long i1); - public long plus(long i0, long i1) { - return i0 + i1; - } - - public long minus(long i0, long i1) { - return i0 - i1; - } - - public long multiply(long i0, long i1) { - return i0 * i1; - } - - public long divide(long i0, long i1) { - return i0 / i1; - } - - public long mod(long i0, long i1) { - return i0 % i1; - } + long mod(long i0, long i1); /** * @param collection An object that a CollectionDataInstance is mapped to. */ - public int size(Data<?, Collection<?>> collection) { - return collection.getValue().size(); - } + int size(Data<?, ?> collection); -} +} \ No newline at end of file diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Procedure.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Procedure.java index 22c086b50f501f7f3e2a1091541d6c5d790bbebd..46a8bf6e6b0083e22afc7f26491e89b6e11bd1d1 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Procedure.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Procedure.java @@ -1,20 +1,25 @@ package org.etsi.mts.tdl.execution.java.tri; -import java.util.function.Consumer; +import java.util.List; /** - * Encapsulation of procedure signature as specified in TDL model that may - * optionally be mapped to a method that implements the calling of the - * procedure. + * Encapsulation of procedure signature as specified in TDL model . */ -public class Procedure extends NamedElement { +public interface Procedure extends NamedElement { + + /** + * Get the parameters with <i>ParameterKind::In</i>. + */ + List<Parameter> getIn(); + + /** + * Get the parameters with <i>ParameterKind::Out</i>. + */ + List<Parameter> getOut(); + /** - * Optional function that implements this procedure call. - * <p> - * The function parameters must match the order and types of parameters of the - * procedure call. That is, for each parameter of a procedure call, a method - * parameter must exist such that the procedure call parameter type is mapped to - * the method parameter type (or class). + * Get the parameters with <i>ParameterKind::Exception</i>. */ - public Consumer<Object[]> function; + List<Parameter> getException(); } + \ No newline at end of file diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/ProviderModule.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/ProviderModule.java index 66d7590387df0aef41853898ec3083d60a1b5613..12f9894d2541b926ae2d0eeb4f30f757290c2dd2 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/ProviderModule.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/ProviderModule.java @@ -26,11 +26,5 @@ public interface ProviderModule extends com.google.inject.Module { @Provides @Singleton - default PredefinedFunctions providePredefinedFunctions(RuntimeHelper helper) { - return new PredefinedFunctions(helper); - } - - @Provides - @Singleton - RuntimeHelper provideRuntimeHelper(); + PredefinedFunctions providePredefinedFunctions(); } diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/RuntimeHelper.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/RuntimeHelper.java deleted file mode 100644 index 99a5ef3008c0344e670b0de0d548e618b0d2c7f9..0000000000000000000000000000000000000000 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/RuntimeHelper.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.etsi.mts.tdl.execution.java.tri; - -/** - * Helper functions to provide environment specific implementation for various - * operations. - */ -public interface RuntimeHelper { - /** - * Compare two objects. Can be used to implement deep equals operation for - * {@link Data Data} objects. - * - * @return <code>True</code> if objects are equal. - */ - boolean equals(Object o0, Object o1); - - /** - * Create a copy of an object. Can be used to implement deep clone of - * {@link Data Data} objects. - */ - <T> T clone(T object); -} diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/StopException.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/StopException.java index e0dfff77058e5f934a2423b4618f343f98402ed7..c7597d4627ecb71ae8c7bf2ea0a5b5df9f649532 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/StopException.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/StopException.java @@ -13,22 +13,19 @@ package org.etsi.mts.tdl.execution.java.tri; * */ @SuppressWarnings("serial") -public class StopException extends Exception { - /** - * Optional final verdict. - */ - private Verdict verdict; +public abstract class StopException extends Exception { public StopException(String message) { super(message); } - - public StopException(String message, Verdict verdict) { - super(message); - this.verdict = verdict; + + @Override + public String getMessage() { + return super.getMessage(); } - public Verdict getVerdict() { - return verdict; - } + /** + * Optional final verdict. + */ + public abstract Verdict getVerdict(); } diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/SystemAdapter.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/SystemAdapter.java index f68a0340bc612bc226ae7e062f5a84f53f88aef1..4f6f09d0a78b95cb27ffb434d7fbeefbc038a580 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/SystemAdapter.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/SystemAdapter.java @@ -101,4 +101,8 @@ public interface SystemAdapter { */ void replyCall(Procedure operation, Data reply, Data exception, Connection connection); + /** + * XXX do we need this? + */ + Data callFunction(NamedElement function, Argument[] arguments); } diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Type.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Type.java index 9b3791f6b4c85cb3058c7ff8d63741bfc14dff73..46206ccd9f0cda8c90a10768413529f35b8d138b 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Type.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Type.java @@ -7,7 +7,7 @@ import java.util.List; * Representation of a TDL model element of class <i>DataType</i> and its * sub-classes. */ -public abstract class Type extends NamedElement { +public interface Type extends NamedElement { /** * If this type is a structure. @@ -15,7 +15,7 @@ public abstract class Type extends NamedElement { * @return <b>true</b> if this type represents a <i>StructureDataType</i> * element. */ - public abstract boolean isStructure(); + boolean isStructure(); /** * If this type is a collection. @@ -23,14 +23,14 @@ public abstract class Type extends NamedElement { * @return <b>true</b> if this type represents a <i>CollectionDataType</i> * element. */ - public abstract boolean isCollection(); + boolean isCollection(); /** * If this type is an enum. * * @return <b>true</b> if this type represents a <i>EnumDataType</i> element. */ - public abstract boolean isEnum(); + boolean isEnum(); /** * Get the data mapping chosen for the runtime. The mapping that is chosen is @@ -39,7 +39,7 @@ public abstract class Type extends NamedElement { * @return A <code>Mapping</code> representing a <i>DataElementMapping</i> * element. */ - public abstract Mapping getMapping(); + Mapping getMapping(); /** * Get the names of members of this structured type. Includes all inherited @@ -48,7 +48,7 @@ public abstract class Type extends NamedElement { * @return Collection of names from the <i>Member</i> elements contained or * inherited in the corresponding <i>StructuredDataType</i> element. */ - public abstract Collection<String> getParameters(); + Collection<String> getParameters(); /** * Get the type of a parameter. @@ -59,7 +59,7 @@ public abstract class Type extends NamedElement { * <i>DataType</i> of the <i>Member</i> element corresponding to the * parameter. */ - public abstract Type getParameter(String parameterName); + Type getParameter(String parameterName); /** * Get the type of items of this collection type. @@ -67,7 +67,7 @@ public abstract class Type extends NamedElement { * @return The <code>Type</code> of the items contained in a collection of this * <code>Type</code>. */ - public abstract Type getItemType(); + Type getItemType(); /** * Get the literal values of this enumerated type. @@ -76,5 +76,5 @@ public abstract class Type extends NamedElement { * <i>SimpleDataInstance</i> elements contained in the corresponding * <i>EnumDataType</i> element. */ - public abstract List<Data<Type, Value>> getEnumLiterals(); + List<Data<Type, Value>> getEnumLiterals(); } diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Value.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Value.java index d95db038db586286850b7408c22fd642c4357c1d..6529e73afe64321e46ec9c59dc7bae2f532cf376 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Value.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Value.java @@ -7,14 +7,14 @@ import java.util.List; * Representation of a TDL model element of class <i>DataInstance</i> or * <i>DataUse</i> and their sub-classes. */ -public abstract class Value extends NamedElement { +public interface Value extends NamedElement { /** * If this value is a structure. * * @return <b>true</b> if the type of this value represents a * <i>StructureDataType</i> element. */ - public abstract boolean isStructure(); + boolean isStructure(); /** * If this value is a collection. @@ -22,7 +22,7 @@ public abstract class Value extends NamedElement { * @return <b>true</b> if the type of this value represents a * <i>CollectionDataType</i> element. */ - public abstract boolean isCollection(); + boolean isCollection(); /** * Get the data mapping chosen for the runtime. The mapping that is chosen is @@ -31,7 +31,7 @@ public abstract class Value extends NamedElement { * @return A <code>Mapping</code> representing a <i>DataElementMapping</i> * element. */ - public abstract Mapping getMapping(); + Mapping getMapping(); /** * Get the primitive or special value of this value object. @@ -39,7 +39,7 @@ public abstract class Value extends NamedElement { * @return A <code>String</code>, a <code>Boolean</code> or any other boxed * primitive value or an instance of {@link SpecialValue SpecialValue}. */ - public abstract Object getValue(); + Object getValue(); /** * Get the names of members of the structured type of this value. Only returns @@ -49,7 +49,7 @@ public abstract class Value extends NamedElement { * <i>ParameterBinding</i> elements contained in the corresponding * <i>DataInstance</i> or <i>DataUse</i> element. */ - public abstract Collection<String> getParameters(); + Collection<String> getParameters(); /** * Get the value data of a parameter. @@ -59,7 +59,7 @@ public abstract class Value extends NamedElement { * @return The <code>Value</code> of the parameter wrapped in <code>Data</code> * object. */ - public abstract Data<Type, Value> getParameter(String parameterName); + Data<Type, Value> getParameter(String parameterName); /** * Get the values contained in this collection value. @@ -67,5 +67,5 @@ public abstract class Value extends NamedElement { * @return The <code>Value</code>s of the items wrapped in <code>Data</code> * objects. */ - public abstract List<Data<Type, Value>> getItems(); + List<Data<Type, Value>> getItems(); } diff --git a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Verdict.java b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Verdict.java index 570cabcc137c36aa51667f38ab57c85ba101b740..8950cebd548a05a926decdb95b9255c891d051e0 100644 --- a/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Verdict.java +++ b/plugins/org.etsi.mts.tdl.execution.java.runtime/src/org/etsi/mts/tdl/execution/java/tri/Verdict.java @@ -3,14 +3,5 @@ package org.etsi.mts.tdl.execution.java.tri; /** * Either predefined or custom verdict. */ -public class Verdict extends NamedElement { - /** - * Verdict instance predefined in TDL. - */ - public static Verdict pass = new Verdict("pass"), fail = new Verdict("fail"), - inconclusive = new Verdict("inconclusive"); - - public Verdict(String name) { - super(name, null); - } +public interface Verdict extends NamedElement { } diff --git a/plugins/org.etsi.mts.tdl.execution.java/src/org/etsi/mts/tdl/execution/java/codegen/JUnitTestGenerator.java b/plugins/org.etsi.mts.tdl.execution.java/src/org/etsi/mts/tdl/execution/java/codegen/JUnitTestGenerator.java index 6aa8ef503986d217799091725d18600d10715517..64c4a78d4e2f44e01022141b9686b0c0f09af789 100644 --- a/plugins/org.etsi.mts.tdl.execution.java/src/org/etsi/mts/tdl/execution/java/codegen/JUnitTestGenerator.java +++ b/plugins/org.etsi.mts.tdl.execution.java/src/org/etsi/mts/tdl/execution/java/codegen/JUnitTestGenerator.java @@ -248,7 +248,8 @@ public class JUnitTestGenerator extends Renderer { } private Annotation getAnnotation(Element e, String keyName) { - Optional<Annotation> op = e.getAnnotation().stream().filter(a -> a.getKey().getName().equals(keyName)).findAny(); + Optional<Annotation> op = e.getAnnotation().stream().filter(a -> a.getKey().getName().equals(keyName)) + .findAny(); if (op.isPresent()) return op.get(); return null; @@ -499,7 +500,7 @@ public class JUnitTestGenerator extends Renderer { connectionNames.add(connectionName); List<GateReference> endpoints = conn.getEndPoint(); - append("Connection " + connectionName + " = new Connection"); + append("Connection " + connectionName + " = new ConnectionImpl"); callOpen(); line("\"" + conn.getName() + "\", "); writeGateReference(endpoints.get(0)); @@ -523,11 +524,13 @@ public class JUnitTestGenerator extends Renderer { } private void writeGateReference(GateReference e) { - append("new GateReference("); + append("new GateReferenceImpl("); writeElement(e.getGate()); append(", "); writeElement(e.getGate().getType()); append(", "); + append("GateTypeKind." + e.getGate().getType().getKind()); + append(", "); writeElement(e.getComponent()); append(", "); writeElement(e.getComponent().getType()); @@ -611,7 +614,7 @@ public class JUnitTestGenerator extends Renderer { declareType(iType, declaredTypes); } - //TODO add mapping name to mapping + // TODO add mapping name to mapping DataElementMapping mapping = getMapping(t); if (mapping == null) mapping = getMapping(t, settings.useMapping); @@ -645,11 +648,11 @@ public class JUnitTestGenerator extends Renderer { private void writeMapping(DataElementMapping mapping, String mappingVarName, boolean inline) { Annotation nameAnnotation = getAnnotation(mapping.getDataResourceMapping(), MAPPING_KEY); - String name = nameAnnotation != null ? nameAnnotation.getValue() : null; - + String name = nameAnnotation != null ? nameAnnotation.getValue() : null; + if (!inline) append(CORE_PACKAGE + ".MappingImpl " + mappingVarName + " = "); - + append("new " + CORE_PACKAGE + ".MappingImpl("); append("\"" + name + "\", "); // XXX @@ -693,7 +696,10 @@ public class JUnitTestGenerator extends Renderer { } private void writeElement(Element e) { - append("new Element(\"" + e.getName() + "\")"); + if (e instanceof NamedElement) + append("new NamedElementImpl(\"" + e.getName() + "\", \"" + ((NamedElement) e).getQualifiedName() + "\")"); + else + append("new ElementImpl(\"" + e.getName() + "\")"); } private void writeTestDescription(TestDescription tc) {