Search in sources :

Example 61 with TMLExpressionException

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

Example 62 with TMLExpressionException

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();
}
Also used : Calendar(java.util.Calendar) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) ClockTime(com.dexels.navajo.document.types.ClockTime) Date(java.util.Date)

Example 63 with TMLExpressionException

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

Example 64 with TMLExpressionException

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

Example 65 with TMLExpressionException

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;
        }
    };
}
Also used : MappableTreeNode(com.dexels.navajo.script.api.MappableTreeNode) Message(com.dexels.navajo.document.Message) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Optional(java.util.Optional) Selection(com.dexels.navajo.document.Selection) Operand(com.dexels.navajo.document.Operand) MappableTreeNode(com.dexels.navajo.script.api.MappableTreeNode) ContextExpression(com.dexels.navajo.expression.api.ContextExpression) Access(com.dexels.navajo.script.api.Access) ArrayList(java.util.ArrayList) Navajo(com.dexels.navajo.document.Navajo) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) TipiLink(com.dexels.navajo.expression.api.TipiLink) ArrayList(java.util.ArrayList) List(java.util.List)

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