public Object read(String property, Object contextObject) { return MVEL.getProperty(property, contextObject); } };
/** * getProperty * * @param bean a {@link java.lang.Object} object. * @param nm a {@link java.lang.String} object. * @return a {@link java.lang.Object} object. * @throws java.lang.Exception if any. */ public static Object getProperty(Object bean, String nm) throws Exception { Object val = null; val = MVEL.getProperty(nm, bean); return val; }
public Object read(String property, Object contextObject) { return MVEL.getProperty(property, contextObject); }
public Object read(String property, Object contextObject) { return MVEL.getProperty(property, contextObject); }
public Object read(String property, Object contextObject) { return MVEL.getProperty(property, contextObject); } };
public Object read(String property, Object contextObject) { return MVEL.getProperty(property, contextObject); } };
public Object read(String property, Object contextObject) { return MVEL.getProperty(property, contextObject); }
public Object read(String property, Object contextObject) { return MVEL.getProperty(property, contextObject); } };
public Object setValue(Object ctx, Object elCtx, VariableResolverFactory vars, Object value) { try { Object v = method.invoke(ctx, EMPTY); if (v == null) v = nullHandler.getProperty(method.getName(), ctx, vars); return nextNode.setValue(v, elCtx, vars, value); } catch (IllegalArgumentException e) { /** * HACK: Try to access this another way. */ Object v = getProperty(method.getName() + "()", ctx); if (v == null) v = nullHandler.getProperty(method.getName(), ctx, vars); return nextNode.setValue(v, elCtx, vars, value); } catch (CompileException e) { throw e; } catch (Exception e) { throw new RuntimeException("error " + method.getName() + ": " + e.getClass().getName() + ":" + e.getMessage(), e); } }
public Object getValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory) { if (!conversionType.isAssignableFrom(ctx.getClass())) { if (nextNode != null) { return nextNode.getValue(MVEL.getProperty(propertyName, ctx), elCtx, variableFactory); } else { return MVEL.getProperty(propertyName, ctx); } } try { if (nextNode != null) { return nextNode.getValue(propertyHandler.getProperty(propertyName, ctx, variableFactory), elCtx, variableFactory); } else { return propertyHandler.getProperty(propertyName, ctx, variableFactory); } } catch (Exception e) { throw new RuntimeException("unable to access field", e); } }
public Object getValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory) { if (!conversionType.isAssignableFrom(ctx.getClass())) { if (nextNode != null) { return nextNode.getValue(MVEL.getProperty(propertyName, ctx), elCtx, variableFactory); } else { return MVEL.getProperty(propertyName, ctx); } } try { if (nextNode != null) { return nextNode.getValue(propertyHandler.getProperty(propertyName, ctx, variableFactory), elCtx, variableFactory); } else { return propertyHandler.getProperty(propertyName, ctx, variableFactory); } } catch (Exception e) { throw new RuntimeException("unable to access field", e); } }
public Object setValue(Object ctx, Object elCtx, VariableResolverFactory vars, Object value) { try { Object v = method.invoke(ctx, EMPTY); if (v == null) v = nullHandler.getProperty(method.getName(), ctx, vars); return nextNode.setValue(v, elCtx, vars, value); } catch (IllegalArgumentException e) { /** * HACK: Try to access this another way. */ Object v = getProperty(method.getName() + "()", ctx); if (v == null) v = nullHandler.getProperty(method.getName(), ctx, vars); return nextNode.setValue(v, elCtx, vars, value); } catch (CompileException e) { throw e; } catch (Exception e) { throw new RuntimeException("error " + method.getName() + ": " + e.getClass().getName() + ":" + e.getMessage(), e); } }
public Object getValue(Object ctx, Object elCtx, VariableResolverFactory vars) { try { return nullHandle(method.getName(), method.invoke(ctx, EMPTY), ctx, elCtx, vars); } catch (IllegalArgumentException e) { if (ctx != null && method.getDeclaringClass() != ctx.getClass()) { Method o = getBestCandidate(EMPTY, method.getName(), ctx.getClass(), ctx.getClass().getMethods(), true); if (o != null) { return executeOverrideTarget(o, ctx, elCtx, vars); } } /** * HACK: Try to access this another way. */ return nullHandle(method.getName(), getProperty(method.getName() + "()", ctx), ctx, elCtx, vars); } catch (Exception e) { throw new CompileException("cannot invoke getter: " + method.getName() + " [declr.class: " + method.getDeclaringClass().getName() + "; act.class: " + (ctx != null ? ctx.getClass().getName() : "null") + "]", e); } }
public void testNullSafe() { Map<String, Map<String, Float>> ctx = new HashMap<String, Map<String, Float>>(); Map<String, Float> tmp = new HashMap<String, Float>(); // tmp.put("latitude", 0.5f); ctx.put("SessionSetupRequest", tmp); System.out.println("Result = " + MVEL.getProperty("SessionSetupRequest.?latitude", ctx)); }
public Object setValue(Object ctx, Object elCtx, VariableResolverFactory vars, Object value) { try { Object v = method.invoke(ctx, EMPTY); if (v == null) v = nullHandler.getProperty(method.getName(), ctx, vars); return nextNode.setValue(v, elCtx, vars, value); } catch (IllegalArgumentException e) { /** * HACK: Try to access this another way. */ Object v = getProperty(method.getName() + "()", ctx); if (v == null) v = nullHandler.getProperty(method.getName(), ctx, vars); return nextNode.setValue(v, elCtx, vars, value); } catch (CompileException e) { throw e; } catch (Exception e) { throw new CompileException("error " + method.getName() + ": " + e.getClass().getName() + ":" + e.getMessage(), e); } }
/** * Submitted by: cleverpig */ public void testBug4() { ClassA A = new ClassA(); ClassB B = new ClassB(); System.out.println(MVEL.getProperty("date", A)); System.out.println(MVEL.getProperty("date", B)); }
public void testInfiniteLoop() { A226 a = new A226(); Map m = Collections.singletonMap("a", a); String ex = "a.map['foo']"; try { MVEL.getProperty(ex, m); fail("access to a null field must fail"); } catch (Exception e) { // ignore } }
public void testSetListListener() { MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true; class MyListener implements Listener { public int counter; public void onEvent(Object context, String contextName, VariableResolverFactory variableFactory, Object value) { counter++; } } class MyBean { private List someList; public List getSomeList() { return someList; } } MyListener listener = new MyListener(); GlobalListenerFactory.registerGetListener(listener); MVEL.getProperty("someList", new MyBean()); MVEL.getProperty("someList", new MyBean()); assertEquals(2, listener.counter); }
public void testSetSemantics() { Bar bar = new Bar(); Foo foo = new Foo(); assertEquals("dog", MVEL.getProperty("name", bar)); assertEquals("dog", MVEL.getProperty("name", foo)); }
public void testMVEL226() { MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true; A226 a = new A226(); Map m = Collections.singletonMap("a", a); Map<String, Object> nestMap = Collections.<String, Object>singletonMap("foo", "bar"); String ex = "a.?map['foo']"; Serializable s; assertNull(MVEL.getProperty(ex, m)); OptimizerFactory.setDefaultOptimizer("ASM"); s = MVEL.compileExpression(ex); assertNull(MVEL.executeExpression(s, m)); a.map = nestMap; assertEquals("bar", MVEL.executeExpression(s, m)); a.map = null; OptimizerFactory.setDefaultOptimizer(OptimizerFactory.DYNAMIC); s = MVEL.compileExpression(ex); assertNull(MVEL.executeExpression(s, m)); a.map = nestMap; assertEquals("bar", MVEL.executeExpression(s, m)); }