Search in sources :

Example 1 with ELException

use of org.activiti.engine.impl.javax.el.ELException in project Activiti by Activiti.

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 (ActivitiException 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 : ActivitiException(org.activiti.engine.ActivitiException) ELException(org.activiti.engine.impl.javax.el.ELException) Method(java.lang.reflect.Method)

Example 2 with ELException

use of org.activiti.engine.impl.javax.el.ELException in project Activiti by Activiti.

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.activiti.engine.impl.javax.el.ELException) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 3 with ELException

use of org.activiti.engine.impl.javax.el.ELException in project Activiti by Activiti.

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.activiti.engine.impl.javax.el.ELException) Feature(org.activiti.engine.impl.juel.Builder.Feature)

Example 4 with ELException

use of org.activiti.engine.impl.javax.el.ELException in project Activiti by Activiti.

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.isEmpty()) {
        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.activiti.engine.impl.javax.el.ValueExpression) Method(java.lang.reflect.Method) ELException(org.activiti.engine.impl.javax.el.ELException)

Example 5 with ELException

use of org.activiti.engine.impl.javax.el.ELException in project Activiti by Activiti.

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.activiti.engine.impl.javax.el.PropertyNotFoundException) Method(java.lang.reflect.Method) ELException(org.activiti.engine.impl.javax.el.ELException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ELException (org.activiti.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 ActivitiException (org.activiti.engine.ActivitiException)2 ELContext (org.activiti.engine.impl.javax.el.ELContext)2 PropertyNotFoundException (org.activiti.engine.impl.javax.el.PropertyNotFoundException)2 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ExpressionGetInvocation (org.activiti.engine.impl.delegate.ExpressionGetInvocation)1 MethodNotFoundException (org.activiti.engine.impl.javax.el.MethodNotFoundException)1 ValueExpression (org.activiti.engine.impl.javax.el.ValueExpression)1 Feature (org.activiti.engine.impl.juel.Builder.Feature)1