use of com.dexels.navajo.document.Operand in project navajo by Dexels.
the class CallService method evaluate.
@Override
public Object evaluate() throws TMLExpressionException {
Operand result = null;
String serviceName = getStringOperand(0);
String expression = getOperands().size() == 1 ? null : getStringOperand(1);
if (getNavajo() == null) {
throw new TMLExpressionException("No Navajo Request object available.");
}
if (getOperands().size() > 2) {
throw new TMLExpressionException("Invalid number of parameters.");
}
try {
Navajo response = getNavajo().getNavajo(serviceName);
if (response == null) {
DispatcherInterface dispatcher = DispatcherFactory.getInstance();
Navajo input = getNavajo().copy();
input.getHeader().setRPCName(serviceName);
response = dispatcher.handle(input, this.getAccess().getTenant(), true);
getNavajo().addNavajo(serviceName, response);
}
if (expression == null) {
Binary bbb = new Binary();
OutputStream os = bbb.getOutputStream();
response.write(os);
os.flush();
os.close();
return bbb;
} else {
result = Expression.evaluate(expression, response);
}
} catch (Exception ex) {
logger.error("Error: ", ex);
}
if (result != null) {
return result.value;
} else {
return null;
}
}
use of com.dexels.navajo.document.Operand in project navajo by Dexels.
the class EvaluateExpression method evaluate.
@Override
public final Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
if (getOperands().size() != 1 && getOperands().size() != 3) {
throw new TMLExpressionException("Wrong number of arguments");
}
Navajo currentNavajo = this.getNavajo();
Message currentMessage = this.getCurrentMessage();
Operand result = null;
boolean conditional = (this.getOperands().size() == 3);
if (!conditional) {
String expression = (String) getOperand(0);
try {
result = Expression.evaluate(expression, currentNavajo, null, currentMessage, null, null, null, null);
} catch (TMLExpressionException ex) {
logger.error("Error: ", ex);
}
} else {
String condition = (String) getOperand(0);
String exp1 = (String) getOperand(1);
String exp2 = (String) getOperand(2);
try {
if (Condition.evaluate(condition, currentNavajo, null, currentMessage, getAccess())) {
result = Expression.evaluate(exp1, currentNavajo, null, currentMessage, null, null, null, null);
} else {
result = Expression.evaluate(exp2, currentNavajo, null, currentMessage, null, null, null, null);
}
} catch (SystemException ex1) {
logger.error("Error: ", ex1);
throw new TMLExpressionException(this, ex1.getMessage());
} catch (TMLExpressionException ex1) {
logger.error("Error: ", ex1);
throw new TMLExpressionException(this, ex1.getMessage());
}
}
if (result != null) {
return result.value;
} else {
return null;
}
}
use of com.dexels.navajo.document.Operand in project navajo by Dexels.
the class ParseStringList method main.
public static void main(String[] args) throws Exception {
String expression = "Contains(ParseStringList('CLUBFUNCTION,UNIONFUNCTION,2',','), 'FUNCTION'))";
Operand o = Expression.evaluate(expression, null);
System.err.println("o = " + o.value);
}
use of com.dexels.navajo.document.Operand in project navajo by Dexels.
the class Size method main.
public static void main(String[] args) throws Exception {
Navajo n = NavajoFactory.getInstance().createNavajo();
Message m = NavajoFactory.getInstance().createMessage(n, "Aap");
n.addMessage(m);
Property p = NavajoFactory.getInstance().createProperty(n, "Selection", "+", "", "out");
m.addProperty(p);
Selection s = NavajoFactory.getInstance().createSelection(n, "Aap", "0", false);
p.addSelection(s);
n.write(System.err);
Operand o = Expression.evaluate("GetPropertyType('/Aap/Selection') == 'selection' AND Size([Aap/Selection]) == 0", n);
System.err.println("o " + o.value + ", type: " + o.type);
}
use of com.dexels.navajo.document.Operand in project navajo by Dexels.
the class ToClockTime method main.
public static void main(String[] args) throws Exception {
// Tests.
ToClockTime cct = new ToClockTime();
cct.reset();
cct.insertStringOperand("12");
System.out.println("cct = " + cct.evaluate());
String expr = "ToClockTime('09:00') + ToClockTime('10')";
Operand o = Expression.evaluate(expr, null);
System.out.println("9:00 > 10:00 ? " + o.value + ", ToClockTime('25:88') = " + new ClockTime("25:88").toString());
expr = "ToClockTime('9') >= ToClockTime('9')";
Operand o2 = Expression.evaluate(expr, null);
System.out.println("9:00 >= 9:00 ? " + o2.value);
expr = "ToClockTime('9') < ToClockTime('12')";
Operand o3 = Expression.evaluate(expr, null);
System.out.println("9:00 < 12:00 ? " + o3.value);
}
Aggregations