Search in sources :

Example 51 with TMLExpressionException

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;
}
Also used : Message(com.dexels.navajo.document.Message) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Property(com.dexels.navajo.document.Property)

Example 52 with TMLExpressionException

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");
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) Selection(com.dexels.navajo.document.Selection) Navajo(com.dexels.navajo.document.Navajo) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 53 with TMLExpressionException

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()");
}
Also used : List(java.util.List) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 54 with TMLExpressionException

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;
}
Also used : TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 55 with TMLExpressionException

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.");
    }
}
Also used : TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Aggregations

TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)129 Message (com.dexels.navajo.document.Message)26 Navajo (com.dexels.navajo.document.Navajo)26 Binary (com.dexels.navajo.document.types.Binary)23 Property (com.dexels.navajo.document.Property)17 ArrayList (java.util.ArrayList)16 Operand (com.dexels.navajo.document.Operand)15 List (java.util.List)13 NavajoException (com.dexels.navajo.document.NavajoException)12 IOException (java.io.IOException)12 Selection (com.dexels.navajo.document.Selection)11 Access (com.dexels.navajo.script.api.Access)10 Calendar (java.util.Calendar)10 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)9 Test (org.junit.Test)9 Money (com.dexels.navajo.document.types.Money)8 SystemException (com.dexels.navajo.script.api.SystemException)8 StringTokenizer (java.util.StringTokenizer)8 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)7 ClockTime (com.dexels.navajo.document.types.ClockTime)7