use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class SetAllProperties method evaluate.
@Override
public Object evaluate() throws TMLExpressionException {
// input (ArrayList, Object).
if (this.getOperands().size() != 3)
throw new TMLExpressionException("SetAllProperties(Message, String, Object) expected");
Object a = this.getOperands().get(0);
if (!(a instanceof Message))
throw new TMLExpressionException("SetAllProperties(Message, String, Object) expected");
Object b = this.getOperands().get(1);
if (!(b instanceof String))
throw new TMLExpressionException("SetAllProperties(Message, String, Object) expected");
Object c = this.getOperands().get(2);
Message source = (Message) a;
String propertyName = (String) b;
for (Iterator<Message> iter = source.getAllMessages().iterator(); iter.hasNext(); ) {
Message element = iter.next();
Property p = element.getProperty(propertyName);
if (p != null) {
p.setAnyValue(c);
}
}
return null;
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class ParseSelection method evaluate.
@Override
public Object evaluate() throws TMLExpressionException {
if (getOperands().size() == 0) {
throw new TMLExpressionException(this, "Operand expected");
}
Object o = getOperand(0);
if (o instanceof String) {
StringTokenizer st = new StringTokenizer((String) o, ";");
Navajo dummy = NavajoFactory.getInstance().createNavajo();
Selection[] allSelections = new Selection[st.countTokens()];
int index = 0;
while (st.hasMoreTokens()) {
String value = st.nextToken();
allSelections[index++] = NavajoFactory.getInstance().createSelection(dummy, value, value, true);
}
return allSelections;
} else {
throw new TMLExpressionException(this, "String expected");
}
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class Max method evaluate.
@Override
public final Object evaluate() throws TMLExpressionException {
List<?> operands = this.getOperands();
if (operands.size() == 2) {
Object a = operands.get(0);
Object b = operands.get(1);
return max(a, b);
} else if (operands.size() == 1) {
// List as argument.
Object a = operands.get(0);
if (!(a instanceof List)) {
throw new TMLExpressionException("Invalid number of arguments for Max()");
}
List<?> list = (List<?>) a;
Object currentMax = list.isEmpty() ? null : list.get(0);
for (int i = 1; i < list.size(); i++) {
Object b = list.get(i);
currentMax = max(currentMax, b);
}
return currentMax;
}
throw new TMLExpressionException("Invalid number of arguments for Max()");
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class StringField 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);
Object c = this.getOperands().get(2);
if (!(a instanceof String) || !(b instanceof String) || !(c instanceof Integer))
throw new TMLExpressionException("StringField(): invalid operand. Usage: " + usage());
String text = (String) a;
String seperator = (String) b;
int field = ((Integer) c).intValue();
String[] tokens = text.split(seperator, -1);
if (field <= tokens.length) {
return (tokens[field - 1] != null) ? tokens[field - 1].trim() : null;
}
return null;
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class Switch method evaluate.
@Override
public Object evaluate() throws TMLExpressionException {
if (getOperands().size() == 0) {
throw new TMLExpressionException(this, "Not enough parameters for decode.");
}
Object oValue = getOperand(0);
int i = 1;
try {
for (i = 1; i < getOperands().size() - 1; i += 2) {
Object matchValue = getOperand(i);
Object newValue = getOperand(i + 1);
if (oValue.equals(matchValue)) {
return newValue;
}
}
} catch (Throwable t) {
throw new TMLExpressionException(this, "Not enough parameters for decode.");
}
if (getOperands().size() - 1 == i) {
return getOperands().get(i);
} else {
throw new TMLExpressionException(this, "Not enough parameters for decode.");
}
}
Aggregations