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);
}
}
}
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;
}
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);
}
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);
}
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());
}
}
Aggregations