private Class<?> load(Class<?> clazz, Properties properties) { if (properties != null) { String className = properties.getProperty(clazz.getName()); if (className != null) { ClassLoader loader; try { loader = Thread.currentThread().getContextClassLoader(); } catch (Exception e) { throw new ELException("Could not get context class loader", e); } try { return loader == null ? Class.forName(className) : loader.loadClass(className); } catch (ClassNotFoundException e) { throw new ELException("Class " + className + " not found", e); } catch (Exception e) { throw new ELException("Class " + className + " could not be instantiated", e); } } } return null; }
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); try { node = builder.build(expr).getRoot(); } catch (ELException e) { throw new IOException(e.getMessage()); } } }
protected Boolean coerceToBoolean(Object value) { if (value == null || "".equals(value)) { return Boolean.FALSE; } if (value instanceof Boolean) { return (Boolean)value; } if (value instanceof String) { return Boolean.valueOf((String)value); } throw new ELException(LocalMessages.get("error.coerce.type", value, value.getClass(), Boolean.class)); }
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); try { node = builder.build(expr).getRoot(); } catch (ELException e) { throw new IOException(e.getMessage()); } } }
/** * Throw an exception. */ @Override public void setValue(ELContext context, Object value) { throw new ELException(LocalMessages.get("error.value.set.rvalue", "<object value expression>")); }
out.println(tree.getRoot().getValue(new Bindings(null, null), context, null)); } catch (ELException e) { out.println(e.getMessage());
public BeanProperties(Class<?> baseClass) { PropertyDescriptor[] descriptors; try { descriptors = Introspector.getBeanInfo(baseClass).getPropertyDescriptors(); } catch (IntrospectionException e) { throw new ELException(e); } for (PropertyDescriptor descriptor : descriptors) { map.put(descriptor.getName(), new BeanProperty(descriptor)); } }
@Override public Object invoke(ELContext context, Object[] params) { try { return method.invoke(null, params); } catch (IllegalAccessException e) { throw new ELException(LocalMessages.get("error.identifier.method.access", name), e); } catch (IllegalArgumentException e) { throw new ELException(LocalMessages.get("error.identifier.method.invocation", name, e)); } catch (InvocationTargetException e) { throw new ELException(LocalMessages.get("error.identifier.method.invocation", name, e.getCause())); } } @Override
protected Character coerceToCharacter(Object value) { if (value == null || "".equals(value)) { return Character.valueOf((char)0); } if (value instanceof Character) { return (Character)value; } if (value instanceof Number) { return Character.valueOf((char)((Number)value).shortValue()); } if (value instanceof String) { return Character.valueOf(((String)value).charAt(0)); } throw new ELException(LocalMessages.get("error.coerce.type", value, value.getClass(), Character.class)); }
/** * Create the factory's type converter. This implementation takes the * <code>de.odysseus.el.misc.TypeConverter</code> property as the name of a class implementing * the <code>de.odysseus.el.misc.TypeConverter</code> interface. If the property is not set, the * default converter (<code>TypeConverter.DEFAULT</code>) is used. */ protected TypeConverter createTypeConverter(Properties properties) { Class<?> clazz = load(TypeConverter.class, properties); if (clazz == null) { return TypeConverter.DEFAULT; } try { return TypeConverter.class.cast(clazz.newInstance()); } catch (Exception e) { throw new ELException("TypeConverter " + clazz + " could not be instantiated", e); } }
@SuppressWarnings("unchecked") protected <T extends Enum<T>> T coerceToEnum(Object value, Class<T> type) { if (value == null || "".equals(value)) { return null; } if (type.isInstance(value)) { return (T)value; } if (value instanceof String) { try { return Enum.valueOf(type, (String)value); } catch (IllegalArgumentException e) { throw new ELException(LocalMessages.get("error.coerce.value", value, value.getClass(), type), e); } } throw new ELException(LocalMessages.get("error.coerce.type", value, value.getClass(), type)); }
clazz = classLoader.loadClass(className.trim()); if (!ExpressionFactory.class.isAssignableFrom(clazz)) { throw new ELException("Invalid expression factory class: " + clazz.getName()); throw new ELException("Could not find expression factory class", e); throw new ELException("Could not create expression factory instance", e);
protected Double coerceToDouble(Object value) { if (value == null || "".equals(value)) { return Double.valueOf(0); } if (value instanceof Double) { return (Double)value; } if (value instanceof Number) { return Double.valueOf(((Number)value).doubleValue()); } if (value instanceof String) { try { return Double.valueOf((String)value); } catch (NumberFormatException e) { throw new ELException(LocalMessages.get("error.coerce.value", value, value.getClass(), Double.class), e); } } if (value instanceof Character) { return Double.valueOf((short)((Character)value).charValue()); } throw new ELException(LocalMessages.get("error.coerce.type", value, value.getClass(), Double.class)); }
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); } } }
protected Long coerceToLong(Object value) { if (value == null || "".equals(value)) { return Long.valueOf(0l); } if (value instanceof Long) { return (Long)value; } if (value instanceof Number) { return Long.valueOf(((Number)value).longValue()); } if (value instanceof String) { try { return Long.valueOf((String)value); } catch (NumberFormatException e) { throw new ELException(LocalMessages.get("error.coerce.value", value, value.getClass(), Long.class), e); } } if (value instanceof Character) { return Long.valueOf((short)((Character)value).charValue()); } throw new ELException(LocalMessages.get("error.coerce.type", value, value.getClass(), Long.class)); }
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 (FlowableException 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); } } }
protected Float coerceToFloat(Object value) { if (value == null || "".equals(value)) { return Float.valueOf(0); } if (value instanceof Float) { return (Float)value; } if (value instanceof Number) { return Float.valueOf(((Number)value).floatValue()); } if (value instanceof String) { try { return Float.valueOf((String)value); } catch (NumberFormatException e) { throw new ELException(LocalMessages.get("error.coerce.value", value, value.getClass(), Float.class), e); } } if (value instanceof Character) { return Float.valueOf((short)((Character)value).charValue()); } throw new ELException(LocalMessages.get("error.coerce.type", value, value.getClass(), Float.class)); }
protected Short coerceToShort(Object value) { if (value == null || "".equals(value)) { return Short.valueOf((short)0); } if (value instanceof Short) { return (Short)value; } if (value instanceof Number) { return Short.valueOf(((Number)value).shortValue()); } if (value instanceof String) { try { return Short.valueOf((String)value); } catch (NumberFormatException e) { throw new ELException(LocalMessages.get("error.coerce.value", value, value.getClass(), Short.class), e); } } if (value instanceof Character) { return Short.valueOf((short)((Character)value).charValue()); } throw new ELException(LocalMessages.get("error.coerce.type", value, value.getClass(), Short.class)); }
protected Integer coerceToInteger(Object value) { if (value == null || "".equals(value)) { return Integer.valueOf(0); } if (value instanceof Integer) { return (Integer)value; } if (value instanceof Number) { return Integer.valueOf(((Number)value).intValue()); } if (value instanceof String) { try { return Integer.valueOf((String)value); } catch (NumberFormatException e) { throw new ELException(LocalMessages.get("error.coerce.value", value, value.getClass(), Integer.class), e); } } if (value instanceof Character) { return Integer.valueOf((short)((Character)value).charValue()); } throw new ELException(LocalMessages.get("error.coerce.type", value, value.getClass(), Integer.class)); }
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; }