use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class AppendArray method evaluate.
@Override
public Object evaluate() throws TMLExpressionException {
// input (ArrayList, Object).
if (this.getOperands().size() != 2)
throw new TMLExpressionException("AppendArray(ArrayMessage, ArrayMessage) expected");
Object a = this.getOperands().get(0);
if (!(a instanceof Message)) {
throw new TMLExpressionException("AppendArray(ArrayMessage, ArrayMessage) expected");
}
Object b = this.getOperands().get(1);
if (!(a instanceof Message)) {
throw new TMLExpressionException("AppendArray(ArrayMessage, ArrayMessage) expected");
}
Message source2 = (Message) a;
Message source = (Message) b;
List<Message> mmm = source2.getAllMessages();
for (Message message : mmm) {
source.addMessage(message);
}
return source;
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class DateAppendClockTime method evaluate.
@Override
public final Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
// Arguments number check
if (this.getOperands().size() != 2) {
throw new TMLExpressionException(this, "error: arguements missing. Please provide a valid Date and a valid ClockTime object.");
}
Object arg0 = this.getOperand(0);
Object arg1 = this.getOperand(1);
// Arguments type checks
if (!(arg0 instanceof Date)) {
throw new TMLExpressionException(this, "error: arguement 0 must be a Date object. The argument you supplied is : " + this.getOperand(0).getClass());
}
if (!(arg1 instanceof ClockTime)) {
throw new TMLExpressionException(this, "error: argument 1 must be a ClockTime. The argument you supplied is : " + this.getOperand(1).getClass());
}
Date date = (Date) arg0;
ClockTime cTime = (ClockTime) arg1;
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.SECOND, cTime.getSeconds());
calendar.set(Calendar.MINUTE, cTime.getMinutes());
calendar.set(Calendar.HOUR, cTime.getHours());
return calendar.getTime();
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class DecimalChar method evaluate.
@Override
public final Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
Object a = this.getOperands().get(0);
String result = "";
try {
int cr = Integer.parseInt(a + "");
result = Character.toString((char) cr);
} catch (Exception e) {
throw new TMLExpressionException("Invalid operand specified: " + a.toString());
}
return result;
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class FunctionFactoryFactory method getInstance.
@SuppressWarnings("unchecked")
public static FunctionFactoryInterface getInstance() {
if (instance != null) {
return instance;
}
synchronized (semaphore) {
if (instance != null) {
return instance;
}
String func = null;
try {
func = System.getProperty("NavajoFunctionFactory");
} catch (AccessControlException e1) {
// can't read property. Whatever, func remains null.
}
try {
if (Version.osgiActive()) {
logger.debug("OSGi environment detected!");
func = "com.dexels.navajo.functions.util.OsgiFunctionFactory";
} else {
logger.debug("no OSGi environment detected!");
}
} catch (Throwable t) {
logger.debug("NO OSGi environment detection failed!");
}
if (func != null) {
try {
Class<? extends FunctionFactoryInterface> c = (Class<? extends FunctionFactoryInterface>) Class.forName(func);
instance = c.getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new TMLExpressionException("Error resolving function", e);
}
} else {
instance = new JarFunctionFactory();
}
instance.init();
}
return instance;
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class ASTMappableNode method interpretToLambda.
@Override
public ContextExpression interpretToLambda(List<String> problems, String expression, Function<String, FunctionClassification> functionClassifier, Function<String, Optional<Node>> mapResolver) {
Optional<Node> resolved = mapResolver.apply(val);
if (resolved.isPresent()) {
return resolved.get().interpretToLambda(problems, expression, functionClassifier, mapResolver);
}
return new ContextExpression() {
@Override
public boolean isLiteral() {
return false;
}
@Override
public Operand apply(Navajo doc, Message parentMsg, Message parentParamMsg, Selection parentSel, MappableTreeNode mapNode, TipiLink tipiLink, Access access, Optional<ImmutableMessage> immutableMessage, Optional<ImmutableMessage> paramMessage) {
if (mapNode == null) {
throw new TMLExpressionException("No known mapobject resolver");
}
// MappableTreeNode mapNode = mapNodeResolver.apply(val);
// if(mapNode==null) {
// throw new TMLExpressionException("No known mapobject");
//
// }
// if(mapNode==null) {
// Node resolvedItem = mapResolver.get().apply(val);
// System.err.println(">> "+resolvedItem.getClass());
// resolvedItem.interpretToLambda(problems, expression, functionClassifier, mapResolver);
//
// }
List objects = null;
// Parameter array may contain parameters that are used when calling the get method.
Object[] parameterArray = null;
if (args > 0) {
objects = new ArrayList();
}
for (int i = 0; i < args; i++) {
List<String> problems = new ArrayList<>();
Operand a = jjtGetChild(i).interpretToLambda(problems, expression, functionClassifier, mapResolver).apply(doc, parentMsg, parentParamMsg, parentSel, mapNode, tipiLink, access, immutableMessage, paramMessage);
if (!problems.isEmpty()) {
throw new TMLExpressionException(problems, expression);
}
if (objects != null) {
objects.add(a.value);
}
}
// List<String> problems
if (objects != null) {
parameterArray = new Object[objects.size()];
parameterArray = objects.toArray(parameterArray);
}
try {
Object oValue = maybeGetMapAttribute(val, mapNode, parameterArray);
if (oValue == null)
return Operand.NULL;
else if (oValue instanceof Float) {
return Operand.ofFloat(((Float) oValue).doubleValue());
} else if (oValue instanceof Long) {
return Operand.ofLong(((Long) oValue).longValue());
} else {
return Operand.ofDynamic(oValue);
}
} catch (Exception me) {
throw new TMLExpressionException(me.getMessage(), me);
}
}
@Override
public Optional<String> returnType() {
return Optional.empty();
}
@Override
public String expression() {
return expression;
}
};
}
Aggregations