@Override public Object get(String express) throws ExpressException { try { context.setMemberAccess(new DefaultMemberAccess(true)); return Ognl.getValue(express, context, bindObject); } catch (Exception e) { throw new ExpressException(express, e); } }
@Override public Object get(String express) throws ExpressException { try { context.setMemberAccess(new DefaultMemberAccess(true)); return Ognl.getValue(express, context, bindObject); } catch (Exception e) { throw new ExpressException(express, e); } }
if (key.equals(OgnlContext.MEMBER_ACCESS_CONTEXT_KEY)) { result = getMemberAccess(); setMemberAccess(null); } else { throw new IllegalArgumentException("unknown reserved key '" + key + "'");
if (key.equals(OgnlContext.MEMBER_ACCESS_CONTEXT_KEY)) { result = getMemberAccess(); setMemberAccess((MemberAccess)value); } else { throw new IllegalArgumentException("unknown reserved key '" + key + "'");
public void clear() { values.clear(); setRoot(null); setCurrentObject(null); setRootEvaluation(null); setCurrentEvaluation(null); setLastEvaluation(null); setCurrentNode(null); setClassResolver(DEFAULT_CLASS_RESOLVER); setTypeConverter(DEFAULT_TYPE_CONVERTER); setMemberAccess(DEFAULT_MEMBER_ACCESS); }
/** * Explicit injection of the objectToInject into the specified property of the target. The property should be a * correct OGNL expression. * * @param objectToInject The object that is injected * @param target The target object * @param property The OGNL expression that defines where the object will be injected, not null * @return The object that was replaced by the injection */ public static Object injectInto(Object objectToInject, Object target, String property) { if (target == null) { throw new UnitilsException("Target for injection should not be null"); } try { OgnlContext ognlContext = new OgnlContext(); ognlContext.setMemberAccess(new DefaultMemberAccess(true)); Object ognlExpression = Ognl.parseExpression(property); Object oldValue = null; try { Ognl.getValue(ognlExpression, ognlContext, target); } catch (Exception e) { logger.warn("Unable to retrieve current value of field to inject into. Will not be able to restore value after injection.", e); } Ognl.setValue(ognlExpression, ognlContext, target, objectToInject); return oldValue; } catch (OgnlException e) { throw new UnitilsException("Failed to set value using OGNL expression " + property, e); } }
/** * Appends the standard naming context for evaluating an OGNL expression * into the context given so that cached maps can be used as a context. * * @param root the root of the object graph * @param context the context to which OGNL context will be added. * @return Context Map with the keys <CODE>root</CODE> and <CODE>context</CODE> * set appropriately */ public static Map addDefaultContext( Object root, ClassResolver classResolver, TypeConverter converter, MemberAccess memberAccess, Map context ) { OgnlContext result; if (!(context instanceof OgnlContext)) { result = new OgnlContext(); result.setValues(context); } else { result = (OgnlContext)context; } if (classResolver != null) { result.setClassResolver(classResolver); } if (converter != null) { result.setTypeConverter(converter); } if (memberAccess != null) { result.setMemberAccess(memberAccess); } result.setRoot(root); return result; }