Search in sources :

Example 1 with ELException

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

the class JuelScriptEngine method importFunctions.

public static void importFunctions(ScriptContext ctx, String namespace, Object obj) {
    Class<?> clazz = null;
    if (obj instanceof Class) {
        clazz = (Class<?>) obj;
    } else if (obj instanceof String) {
        try {
            clazz = ReflectUtil.loadClass((String) obj);
        } catch (ProcessEngineException ae) {
            throw new ELException(ae);
        }
    } else {
        throw new ELException("Class or class name is missing");
    }
    Method[] methods = clazz.getMethods();
    for (Method m : methods) {
        int mod = m.getModifiers();
        if (Modifier.isStatic(mod) && Modifier.isPublic(mod)) {
            String name = namespace + ":" + m.getName();
            ctx.setAttribute(name, m, ScriptContext.ENGINE_SCOPE);
        }
    }
}
Also used : ELException(org.camunda.bpm.engine.impl.javax.el.ELException) Method(java.lang.reflect.Method) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 2 with ELException

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

the class ExpressionFactoryImpl method loadProperties.

private Properties loadProperties(String path) {
    Properties properties = new Properties(loadDefaultProperties());
    // try to find and load properties
    InputStream input = null;
    try {
        input = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
    } catch (SecurityException e) {
        input = ClassLoader.getSystemResourceAsStream(path);
    }
    if (input != null) {
        try {
            properties.load(input);
        } catch (IOException e) {
            throw new ELException("Cannot read EL properties", e);
        } finally {
            try {
                input.close();
            } catch (IOException e) {
            // ignore...
            }
        }
    }
    return properties;
}
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)

Example 3 with ELException

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

the class ExpressionFactoryImpl method createTreeStore.

/**
 * Create the factory's tree store. This implementation creates a new tree store using the
 * default builder and cache implementations. The builder and cache are configured using the
 * specified properties. The maximum cache size will be as specified unless overridden by
 * property <code>javax.el.cacheSize</code>.
 */
protected TreeStore createTreeStore(int defaultCacheSize, Profile profile, Properties properties) {
    // create builder
    TreeBuilder builder = null;
    if (properties == null) {
        builder = createTreeBuilder(null, profile.features());
    } else {
        EnumSet<Builder.Feature> features = EnumSet.noneOf(Builder.Feature.class);
        if (getFeatureProperty(profile, properties, Feature.METHOD_INVOCATIONS, PROP_METHOD_INVOCATIONS)) {
            features.add(Builder.Feature.METHOD_INVOCATIONS);
        }
        if (getFeatureProperty(profile, properties, Feature.VARARGS, PROP_VAR_ARGS)) {
            features.add(Builder.Feature.VARARGS);
        }
        if (getFeatureProperty(profile, properties, Feature.NULL_PROPERTIES, PROP_NULL_PROPERTIES)) {
            features.add(Builder.Feature.NULL_PROPERTIES);
        }
        builder = createTreeBuilder(properties, features.toArray(new Builder.Feature[0]));
    }
    // create cache
    int cacheSize = defaultCacheSize;
    if (properties != null && properties.containsKey(PROP_CACHE_SIZE)) {
        try {
            cacheSize = Integer.parseInt(properties.getProperty(PROP_CACHE_SIZE));
        } catch (NumberFormatException e) {
            throw new ELException("Cannot parse EL property " + PROP_CACHE_SIZE, e);
        }
    }
    Cache cache = cacheSize > 0 ? new Cache(cacheSize) : null;
    return new TreeStore(builder, cache);
}
Also used : ELException(org.camunda.bpm.engine.impl.javax.el.ELException) Feature(org.camunda.bpm.engine.impl.juel.Builder.Feature)

Example 4 with ELException

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

the class JuelExpression method getValue.

public Object getValue(VariableScope variableScope, BaseDelegateExecution contextExecution) {
    ELContext elContext = expressionManager.getElContext(variableScope);
    try {
        ExpressionGetInvocation invocation = new ExpressionGetInvocation(valueExpression, elContext, contextExecution);
        Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(invocation);
        return invocation.getInvocationResult();
    } catch (PropertyNotFoundException pnfe) {
        throw new ProcessEngineException("Unknown property used in expression: " + expressionText + ". Cause: " + pnfe.getMessage(), pnfe);
    } catch (MethodNotFoundException mnfe) {
        throw new ProcessEngineException("Unknown method used in expression: " + expressionText + ". Cause: " + mnfe.getMessage(), mnfe);
    } catch (ELException ele) {
        throw new ProcessEngineException("Error while evaluating expression: " + expressionText + ". Cause: " + ele.getMessage(), ele);
    } catch (Exception e) {
        throw new ProcessEngineException("Error while evaluating expression: " + expressionText + ". Cause: " + e.getMessage(), e);
    }
}
Also used : ELContext(org.camunda.bpm.engine.impl.javax.el.ELContext) PropertyNotFoundException(org.camunda.bpm.engine.impl.javax.el.PropertyNotFoundException) ELException(org.camunda.bpm.engine.impl.javax.el.ELException) MethodNotFoundException(org.camunda.bpm.engine.impl.javax.el.MethodNotFoundException) ExpressionGetInvocation(org.camunda.bpm.engine.impl.delegate.ExpressionGetInvocation) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) MethodNotFoundException(org.camunda.bpm.engine.impl.javax.el.MethodNotFoundException) PropertyNotFoundException(org.camunda.bpm.engine.impl.javax.el.PropertyNotFoundException) ELException(org.camunda.bpm.engine.impl.javax.el.ELException)

Example 5 with ELException

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

the class AstProperty method invoke.

public Object invoke(Bindings bindings, ELContext context, Class<?> returnType, Class<?>[] paramTypes, Object[] paramValues) {
    Object base = prefix.eval(bindings, context);
    if (base == null) {
        throw new PropertyNotFoundException(LocalMessages.get("error.property.base.null", prefix));
    }
    Object property = getProperty(bindings, context);
    if (property == null && strict) {
        throw new PropertyNotFoundException(LocalMessages.get("error.property.method.notfound", "null", base));
    }
    String name = bindings.convert(property, String.class);
    Method method = findMethod(name, base.getClass(), returnType, paramTypes);
    try {
        return method.invoke(base, paramValues);
    } catch (IllegalAccessException e) {
        throw new ELException(LocalMessages.get("error.property.method.access", name, base.getClass()));
    } catch (IllegalArgumentException e) {
        throw new ELException(LocalMessages.get("error.property.method.invocation", name, base.getClass()), e);
    } catch (InvocationTargetException e) {
        throw new ELException(LocalMessages.get("error.property.method.invocation", name, base.getClass()), e.getCause());
    }
}
Also used : PropertyNotFoundException(org.camunda.bpm.engine.impl.javax.el.PropertyNotFoundException) Method(java.lang.reflect.Method) ELException(org.camunda.bpm.engine.impl.javax.el.ELException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

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