Refine search
@Override public Express bind(String name, Object value) { context.put(name, value); return this; }
exp2 = exp2.replaceAll("@@" + entry.getKey() + "\\(", "@" + className + "@" + entry.getKey() + "("); object = Ognl.parseExpression(exp2); EXPRESSION_CACHE.put(exp, object); values.put(RET_VAL, retVal); OgnlContext context = new OgnlContext(values); context.setRoot(arguments); Object res = Ognl.getValue(object, context, context.getRoot(), valueType); return (T) res;
protected void setValueBody(OgnlContext context, Object target, Object value) throws OgnlException { Object expr = _children[0].getValue(context, target), previousRoot = context.getRoot(); Node node; target = _children[1].getValue(context, target); node = (expr instanceof Node) ? (Node) expr : (Node) Ognl.parseExpression(expr.toString()); try { context.setRoot(target); node.setValue(context, target, value); } finally { context.setRoot(previousRoot); } }
private static Object executeExpression( final IEngineConfiguration configuration, final Object parsedExpression, final Map<String,Object> context, final Object root) throws Exception { if (parsedExpression instanceof OGNLShortcutExpression) { return ((OGNLShortcutExpression) parsedExpression).evaluate(configuration, context, root); } // We create the OgnlContext here instead of just sending the Map as context because that prevents OGNL from // creating the OgnlContext empty and then setting the context Map variables one by one final OgnlContext ognlContext = new OgnlContext(context); return ognl.Ognl.getValue(parsedExpression, ognlContext, root); }
protected Object evaluate(Object o, ResourcePropertyMapping resourcePropertyMapping) throws ConversionException { OgnlContext ctx = new OgnlContext(); ctx.put(DATA_CONTEXT_KEY, o); try { return Ognl.getValue(expression, ctx, o); } catch (Exception e) { throw new ConversionException("Failed to evaluate [" + o + "] with expression [" + expression + "]", e); } } }
public Object readCompiled(Object target, Object expression) { OgnlContext context = null; try { context = (OgnlContext)_contextPool.borrowObject(); context.setRoot(target); return Ognl.getValue(expression, context, target); } catch (Exception ex) { throw new ApplicationRuntimeException(ImplMessages.unableToReadExpression(ImplMessages .parsedExpression(), target, ex), target, null, ex); } finally { try { if (context != null) _contextPool.returnObject(context); } catch (Exception e) {} } }
public <T> T evaluate(Exchange exchange, Class<T> tClass) { OgnlContext oglContext = new OgnlContext(); // setup the class resolver from camel oglContext.setClassResolver(new CamelClassResolver(exchange.getContext().getClassResolver())); try { Object value = Ognl.getValue(expression, oglContext, new RootObject(exchange)); return exchange.getContext().getTypeConverter().convertTo(tClass, value); } catch (OgnlException e) { throw new ExpressionEvaluationException(this, exchange, e); } }
Class currType = context.getCurrentType(); Class currAccessor = context.getCurrentAccessor(); Object cast = context.get(ExpressionCompiler.PRE_CAST); context.setCurrentObject(context.getRoot()); context.setCurrentType(context.getRoot() != null ? context.getRoot().getClass() : null); context.setCurrentAccessor(null); context.setPreviousType(null); children[i].toGetSourceString(context, context.getRoot()); parms[i] = context.getCurrentType(); context.put(ExpressionCompiler.PRE_CAST, cast); context.setCurrentType(currType); context.setCurrentAccessor(currAccessor); context.setCurrentObject(target); } else List methods = OgnlRuntime.getMethods(target, name, includeStatic); if (methods == null) return null; boolean varArgs = isJdk15() && m.isVarArgs(); && Character.TYPE != mparms[p] && Byte.TYPE != mparms[p] && Number.class.isAssignableFrom(parms[p]) && OgnlRuntime.getPrimitiveWrapperClass(parms[p]) == mparms[p])
@Before public void setup() throws Exception { MockitoAnnotations.initMocks(this); AbstractOgnlTestSupport.configOgnl(converters); removal = new EmptyElementsRemoval(); bundle = ResourceBundle.getBundle("messages"); when(container.instanceFor(Converters.class)).thenReturn(converters); when(converters.to(Long.class)).thenReturn(new LongConverter()); when(converters.to(String.class)).thenReturn(new StringConverter()); when(container.instanceFor(EmptyElementsRemoval.class)).thenReturn(removal); this.myCat = new Cat(); this.context = (OgnlContext) Ognl.createDefaultContext(myCat); context.setTraceEvaluations(true); context.put(Container.class, container); context.put("removal", removal); context.put("nullHandler", new GenericNullHandler(removal)); // OgnlRuntime.setPropertyAccessor(Set.class, new SetAccessor()); // OgnlRuntime.setPropertyAccessor(Map.class, new MapAccessor()); Ognl.setTypeConverter(context, new VRaptorConvertersAdapter(converters, bundle)); context.put("proxifier", new JavassistProxifier(new ReflectionInstanceCreator())); }
/** * Creates and returns a new standard naming context for evaluating an OGNL * expression. * * @param root the root of the object graph * @return a new Map with the keys <CODE>root</CODE> and <CODE>context</CODE> * set appropriately */ public static Map createDefaultContext( Object root, ClassResolver classResolver, TypeConverter converter, MemberAccess memberAccess ) { return addDefaultContext( root, classResolver, converter, memberAccess, new OgnlContext() ); }
result = getCurrentObject(); setCurrentObject(value); } else { if (key.equals(OgnlContext.ROOT_CONTEXT_KEY)) { result = getRoot(); setRoot(value); } else { if (key.equals(OgnlContext.CONTEXT_CONTEXT_KEY)) { } else { if (key.equals(OgnlContext.TRACE_EVALUATIONS_CONTEXT_KEY)) { result = getTraceEvaluations() ? Boolean.TRUE : Boolean.FALSE; setTraceEvaluations(OgnlOps.booleanValue(value)); } else { if (key.equals(OgnlContext.LAST_EVALUATION_CONTEXT_KEY)) { result = getLastEvaluation(); lastEvaluation = (Evaluation)value; } else { if (key.equals(OgnlContext.KEEP_LAST_EVALUATION_CONTEXT_KEY)) { result = getKeepLastEvaluation() ? Boolean.TRUE : Boolean.FALSE; setKeepLastEvaluation(OgnlOps.booleanValue(value)); } else { if (key.equals(OgnlContext.CLASS_RESOLVER_CONTEXT_KEY)) { result = getClassResolver(); setClassResolver((ClassResolver)value); } else { if (key.equals(OgnlContext.TYPE_CONVERTER_CONTEXT_KEY)) { result = getTypeConverter(); setTypeConverter((TypeConverter)value);
result = getCurrentObject(); setCurrentObject(value); } else { if (key.equals(OgnlContext.ROOT_CONTEXT_KEY)) { result = getRoot(); setRoot(value); } else { if (key.equals(OgnlContext.TRACE_EVALUATIONS_CONTEXT_KEY)) { result = getTraceEvaluations() ? Boolean.TRUE : Boolean.FALSE; setTraceEvaluations(OgnlOps.booleanValue(value)); } else { if (key.equals(OgnlContext.LAST_EVALUATION_CONTEXT_KEY)) { result = getLastEvaluation(); _lastEvaluation = (Evaluation) value; } else { if (key.equals(OgnlContext.KEEP_LAST_EVALUATION_CONTEXT_KEY)) { result = getKeepLastEvaluation() ? Boolean.TRUE : Boolean.FALSE; setKeepLastEvaluation(OgnlOps.booleanValue(value)); } else { throw new IllegalArgumentException("unknown reserved key '" + key + "'");
@Before public void setup() throws Exception { MockitoAnnotations.initMocks(this); AbstractOgnlTestSupport.configOgnl(converters); this.proxifier = new JavassistProxifier(new ReflectionInstanceCreator()); this.context = (OgnlContext) Ognl.createDefaultContext(null); context.setTraceEvaluations(true); context.put("removal", removal); context.put("nullHandler", new GenericNullHandler(removal)); context.put("proxifier", proxifier); when(container.instanceFor(Converters.class)).thenReturn(converters); when(converters.to(String.class)).thenReturn(new StringConverter()); when(converters.to(Long.class)).thenReturn(new LongConverter()); }
public String toSetSourceString(OgnlContext context, Object target) String prevChain = (String)context.get("_currentChain"); String prevChild = (String)context.get("_lastChild"); context.setCurrentObject(target); context.setCurrentType(target.getClass()); context.put("_lastChild", "true"); String value = _children[i].toSetSourceString(context, context.getCurrentObject()); && (_parent == null || !ASTSequence.class.isInstance(_parent))) value = OgnlRuntime.getCompiler().castExpression(context, _children[i], value); || ASTCtor.class.isInstance(_children[i]) || ASTStaticField.class.isInstance(_children[i])) { context.put("_noRoot", "true"); result = value; } else result += value; context.put("_currentChain", result); context.put("_lastChild", prevChild); context.put("_currentChain", prevChain);
/** * Used by {@link #castExpression(ognl.OgnlContext, ognl.Node, String)} to store the cast java * source string in to the current {@link OgnlContext}. This will either add to the existing * string present if it already exists or create a new instance and store it using the static key * of {@link #PRE_CAST}. * * @param context * The current execution context. * @param cast * The java source string to store in to the context. */ public static void addCastString(OgnlContext context, String cast) { String value = (String) context.get(PRE_CAST); if (value != null) value = cast + value; else value = cast; context.put(PRE_CAST, value); }
throw new UnsupportedCompilationException("Can only compile boolean expressions with two children."); String pre = (String) context.get("_currentChain"); if (pre == null) pre = ""; String first = ExpressionCompiler.getRootExpression(_children[0], context.getRoot(), context) + pre + _children[0].toGetSourceString(context, target); if (!OgnlRuntime.isBoolean(first)) first = OgnlRuntime.getCompiler().createLocalReference(context, first, Object.class); String second = ExpressionCompiler.getRootExpression(_children[1], context.getRoot(), context) + pre + _children[1].toSetSourceString(context, target); if (!OgnlRuntime.isBoolean(second)) second = OgnlRuntime.getCompiler().createLocalReference(context, second, context.getCurrentType()); context.setCurrentObject(target); context.setCurrentType(Boolean.TYPE);
public String toGetSourceString(OgnlContext context, Object target) Object value = context.get(_name); context.setCurrentType(_getterClass); context.setCurrentAccessor(context.getClass()); context.setCurrentObject(value); if (context.getCurrentObject() == null) throw new UnsupportedCompilationException("Current context object is null, can't compile var reference."); if (context.getCurrentType() != null) { pre = "((" + OgnlRuntime.getCompiler().getInterfaceClass(context.getCurrentType()).getName() + ")"; post = ")";
OgnlContext createContext(final Map<String, Object> vars) { OgnlContext ognlContext = new OgnlContext(); ognlContext.putAll(vars); ognlContext.put("logger", log); return ognlContext; }
@Before public void setup() { MockitoAnnotations.initMocks(this); client = new Client(); handler = new ListNullHandler(removal); context = (OgnlContext) Ognl.createDefaultContext(null); context.put("proxifier", new JavassistProxifier(new ReflectionInstanceCreator())); }
MultiKeyMap keyMap = new MultiKeyMap();//MultiKeyMap Creation keyMap.put("1","2","OneTwo");//storing value OgnlContext context = new OgnlContext();// Ognl Context context.put("vap", keyMap); Object expression = Ognl.parseExpression("vap.get(\"1\",\"2\")");// Ognl expression //to retrive value from multikeyMap System.out.println(Ognl.getValue(expression, context));//Printing value.