Commits (2)
......@@ -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>
......
......@@ -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;
......
......@@ -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;
}
......
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;
}
}
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();
}
}
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;
}
}
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;
}
}
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;
}
}
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
......@@ -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;
}
......
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;
}
}
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;
}
}
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);
......
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);
......
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.");
}
}
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;
}
}
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;
}
}
......@@ -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));
......
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;
......
......@@ -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;
}
......