use of com.dexels.navajo.document.Navajo in project navajo by Dexels.
the class MergeNavajo method evaluate.
@Override
public final Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
Object a = this.getOperands().get(0);
Object b = this.getOperands().get(1);
try {
Navajo slave = (Navajo) a;
Navajo result = slave.copy();
Navajo master = (Navajo) b;
return result.merge(master);
} catch (Exception e) {
throw new TMLExpressionException(this, "Illegal type specified in MergeNavajo() function: " + e.getMessage(), e);
}
}
use of com.dexels.navajo.document.Navajo in project navajo by Dexels.
the class EvaluateParameters method main.
public static void main(String[] args) throws Exception {
// Navajo n = NavajoFactory.getInstance().createNavajo();
// Message noot = NavajoFactory.getInstance().createMessage(n, "Noot");
//
// n.addMessage(noot);
// noot.addProperty(ai);
String expression = "test [/mies/ActivityId]";
Navajo m = NavajoFactory.getInstance().createNavajo();
Message mies = NavajoFactory.getInstance().createMessage(m, "mies");
Property ai = NavajoFactory.getInstance().createProperty(m, "ActivityId", "string", "4792834", 10, "Ac", "in");
mies.addProperty(ai);
Property p = NavajoFactory.getInstance().createProperty(m, "exp", "string", expression, 10, "Ac", "in");
m.addMessage(mies);
mies.addProperty(p);
System.err.println(Expression.evaluate("EvaluateParameters([/mies/exp])", m).value);
/*
EvaluateParameters ce = new EvaluateParameters();
ce.reset();
ce.currentMessage = noot;
ce.insertOperand(Expression.evaluate("[/mies/exp]", m).value);
String result = (String) ce.evaluate();
System.err.println("result:");
System.err.println(result);*/
}
use of com.dexels.navajo.document.Navajo in project navajo by Dexels.
the class ExistsProperty method evaluate.
@Override
public Object evaluate() throws TMLExpressionException {
if (getOperands().size() != 1) {
throw new TMLExpressionException(this, "Invalid function call");
}
Object o = getOperand(0);
if (!(o instanceof String)) {
throw new TMLExpressionException(this, "Invalid function call");
}
Navajo in = getNavajo();
return (in.getProperty((String) o) != null);
}
use of com.dexels.navajo.document.Navajo in project navajo by Dexels.
the class ForAll method evaluate.
@Override
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
/**
*@todo Implement this com.dexels.navajo.parser.FunctionInterface abstract method
*/
Message arrayMessage = null;
String messagePath = null;
if (getOperand(0) instanceof Message) {
arrayMessage = (Message) getOperand(0);
} else {
messagePath = (String) getOperand(0);
}
String expression = (String) getOperand(1);
String filter = null;
if (getOperands().size() > 2) {
filter = (String) getOperand(2);
}
Message parent = getCurrentMessage();
Navajo doc = getNavajo();
// try {
try {
List<Message> arrayMsg = null;
if (arrayMessage != null) {
arrayMsg = arrayMessage.getAllMessages();
} else {
arrayMsg = (parent != null ? parent.getMessages(messagePath) : doc.getMessages(messagePath));
}
if (arrayMsg == null) {
throw new TMLExpressionException(this, "Empty or non existing array message: " + messagePath);
}
for (int i = 0; i < arrayMsg.size(); i++) {
Message current = arrayMsg.get(i);
try {
boolean evaluate = (filter != null ? Condition.evaluate(filter, doc, null, current, getAccess()) : true);
if (evaluate) {
Operand result = Expression.evaluate(expression, doc, null, current);
if (result == null) {
throw new TMLExpressionException(this, "Error evaluating expression: " + expression + " in message: " + current.getFullMessageName());
}
if (result.value == null) {
throw new TMLExpressionException(this, "Error evaluating expression: " + expression + " in message: " + current.getFullMessageName());
}
String res2 = "" + result.value;
Operand result2 = Expression.evaluate(res2, doc, null, current);
if (result2 == null) {
throw new TMLExpressionException(this, "Error evaluating expression: " + res2 + " in message: " + current.getFullMessageName());
}
if (result2.value == null) {
throw new TMLExpressionException(this, "Error evaluating expression: " + res2 + " in message: " + current.getFullMessageName());
}
boolean res = ((Boolean) result2.value).booleanValue();
if (!res) {
return Boolean.FALSE;
}
}
} catch (SystemException ex) {
logger.error("Error: ", ex);
}
}
} catch (NavajoException ex) {
throw new TMLExpressionException(this, "Error evaluating message path");
}
return Boolean.TRUE;
}
use of com.dexels.navajo.document.Navajo in project navajo by Dexels.
the class GetPropertyValue method evaluate.
@Override
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
if (getOperands().size() != 2) {
throw new TMLExpressionException(this, "Invalid function call");
}
Object m = operand(0).value;
;
if (m == null) {
throw new TMLExpressionException(this, "Message or navajo argument expected. This one is null");
}
// Object o = getOperand(1);
// if (!(o instanceof String)) {
// throw new TMLExpressionException(this, "String argument expected");
// }
String propertyName = getStringOperand(1);
if (!(m instanceof Message) && !(m instanceof Navajo)) {
throw new TMLExpressionException(this, "Message or navajo argument expected");
}
if (m instanceof Navajo) {
Navajo n = (Navajo) m;
return n.getProperty(propertyName).getTypedValue();
}
if (m instanceof Message) {
Message message = (Message) m;
return message.getProperty(propertyName).getTypedValue();
}
return null;
}
Aggregations