Search in sources :

Example 6 with ELException

use of org.camunda.bpm.engine.impl.javax.el.ELException in project camunda-bpm-platform by camunda.

the class Builder method main.

/**
 * Dump out abstract syntax tree for a given expression
 *
 * @param args array with one element, containing the expression string
 */
public static void main(String[] args) {
    if (args.length != 1) {
        System.err.println("usage: java " + Builder.class.getName() + " <expression string>");
        System.exit(1);
    }
    PrintWriter out = new PrintWriter(System.out);
    Tree tree = null;
    try {
        tree = new Builder(Feature.METHOD_INVOCATIONS).build(args[0]);
    } catch (TreeBuilderException e) {
        System.out.println(e.getMessage());
        System.exit(0);
    }
    NodePrinter.dump(out, tree.getRoot());
    if (!tree.getFunctionNodes().iterator().hasNext() && !tree.getIdentifierNodes().iterator().hasNext()) {
        ELContext context = new ELContext() {

            @Override
            public VariableMapper getVariableMapper() {
                return null;
            }

            @Override
            public FunctionMapper getFunctionMapper() {
                return null;
            }

            @Override
            public ELResolver getELResolver() {
                return null;
            }
        };
        out.print(">> ");
        try {
            out.println(tree.getRoot().getValue(new Bindings(null, null), context, null));
        } catch (ELException e) {
            out.println(e.getMessage());
        }
    }
    out.flush();
}
Also used : ELContext(org.camunda.bpm.engine.impl.javax.el.ELContext) ELException(org.camunda.bpm.engine.impl.javax.el.ELException) PrintWriter(java.io.PrintWriter)

Example 7 with ELException

use of org.camunda.bpm.engine.impl.javax.el.ELException in project camunda-bpm-platform by camunda.

the class ExpressionFactoryImpl method loadDefaultProperties.

private Properties loadDefaultProperties() {
    String home = System.getProperty("java.home");
    String path = home + File.separator + "lib" + File.separator + "el.properties";
    File file = new File(path);
    if (file.exists()) {
        Properties properties = new Properties();
        InputStream input = null;
        try {
            properties.load(input = new FileInputStream(file));
        } catch (IOException e) {
            throw new ELException("Cannot read default EL properties", e);
        } finally {
            try {
                input.close();
            } catch (IOException e) {
            // ignore...
            }
        }
        if (getClass().getName().equals(properties.getProperty("javax.el.ExpressionFactory"))) {
            return properties;
        }
    }
    if (getClass().getName().equals(System.getProperty("javax.el.ExpressionFactory"))) {
        return System.getProperties();
    }
    return null;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) ELException(org.camunda.bpm.engine.impl.javax.el.ELException) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 8 with ELException

use of org.camunda.bpm.engine.impl.javax.el.ELException in project camunda-bpm-platform by camunda.

the class Tree method bind.

/**
 * Create a bindings.
 * @param fnMapper the function mapper to use
 * @param varMapper the variable mapper to use
 * @param converter custom type converter
 * @return tree bindings
 */
public Bindings bind(FunctionMapper fnMapper, VariableMapper varMapper, TypeConverter converter) {
    Method[] methods = null;
    if (!functions.isEmpty()) {
        if (fnMapper == null) {
            throw new ELException(LocalMessages.get("error.function.nomapper"));
        }
        methods = new Method[functions.size()];
        for (FunctionNode node : functions) {
            String image = node.getName();
            Method method = null;
            int colon = image.indexOf(':');
            if (colon < 0) {
                method = fnMapper.resolveFunction("", image);
            } else {
                method = fnMapper.resolveFunction(image.substring(0, colon), image.substring(colon + 1));
            }
            if (method == null) {
                throw new ELException(LocalMessages.get("error.function.notfound", image));
            }
            if (node.isVarArgs() && method.isVarArgs()) {
                if (method.getParameterTypes().length > node.getParamCount() + 1) {
                    throw new ELException(LocalMessages.get("error.function.params", image));
                }
            } else {
                if (method.getParameterTypes().length != node.getParamCount()) {
                    throw new ELException(LocalMessages.get("error.function.params", image));
                }
            }
            methods[node.getIndex()] = method;
        }
    }
    ValueExpression[] expressions = null;
    if (identifiers.size() > 0) {
        expressions = new ValueExpression[identifiers.size()];
        for (IdentifierNode node : identifiers) {
            ValueExpression expression = null;
            if (varMapper != null) {
                expression = varMapper.resolveVariable(node.getName());
            }
            expressions[node.getIndex()] = expression;
        }
    }
    return new Bindings(methods, expressions, converter);
}
Also used : ValueExpression(org.camunda.bpm.engine.impl.javax.el.ValueExpression) Method(java.lang.reflect.Method) ELException(org.camunda.bpm.engine.impl.javax.el.ELException)

Aggregations

ELException (org.camunda.bpm.engine.impl.javax.el.ELException)8 Method (java.lang.reflect.Method)3 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Properties (java.util.Properties)2 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)2 ELContext (org.camunda.bpm.engine.impl.javax.el.ELContext)2 PropertyNotFoundException (org.camunda.bpm.engine.impl.javax.el.PropertyNotFoundException)2 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ExpressionGetInvocation (org.camunda.bpm.engine.impl.delegate.ExpressionGetInvocation)1 MethodNotFoundException (org.camunda.bpm.engine.impl.javax.el.MethodNotFoundException)1 ValueExpression (org.camunda.bpm.engine.impl.javax.el.ValueExpression)1 Feature (org.camunda.bpm.engine.impl.juel.Builder.Feature)1