/** Returns an Evaluation that contains the node, source and whether it is a set operation. If there are no Evaluation objects in the pool one is created and returned. */ public synchronized Evaluation create(SimpleNode node, Object source, boolean setOperation) { Evaluation result; if (size > 0) { result = (Evaluation)evaluations.remove(size - 1); result.init(node, source, setOperation); size--; recovered++; } else { result = new Evaluation(node, source, setOperation); created++; } return result; }
/** Gets the first descendent. In any Evaluation tree this will the Evaluation that was first executed. */ public Evaluation getFirstDescendant() { if (firstChild != null) { return firstChild.getFirstDescendant(); } return this; }
/** Gets the last descendent. In any Evaluation tree this will the Evaluation that was most recently executing. */ public Evaluation getLastDescendant() { if (lastChild != null) { return lastChild.getLastDescendant(); } return this; }
private Type extractGenericType(OgnlContext ctx, Object target) { Type genericType; if (ctx.getRoot() != target) { Evaluation eval = ctx.getCurrentEvaluation(); Evaluation previous = eval.getPrevious(); String fieldName = previous.getNode().toString(); Object origin = previous.getSource(); Proxifier proxifier = (Proxifier) ctx.get("proxifier"); Method getter = new ReflectionBasedNullHandler(proxifier).findGetter(origin, StringUtils.capitalize(fieldName)); genericType = getter.getGenericReturnType(); } else { genericType = (Type) ctx.get("rootType"); } return genericType; }
Type getListType(Object target, Evaluation evaluation, OgnlContext ctx) { // creating instance Object listHolder = evaluation.getSource(); String listPropertyName = evaluation.getNode().toString(); Proxifier proxifier = (Proxifier) ctx.get("proxifier"); Method listSetter = new ReflectionBasedNullHandler(proxifier).findSetter(listHolder, StringUtils.capitalize(listPropertyName), target.getClass()); Type[] types = listSetter.getGenericParameterTypes(); Type type = types[0]; if (!(type instanceof ParameterizedType)) { throw new VRaptorException("Vraptor does not support non-generic collection at " + listSetter.getName()); } return type; }
Evaluation eval = context.popEvaluation(); eval.setResult(result); if (evalException != null) { eval.setException(evalException);
/** * Returns the Evaluation at the relative index given. This should be zero or a negative number * as a relative reference back up the evaluation stack. Therefore getEvaluation(0) returns the * current Evaluation. */ public Evaluation getEvaluation(int relativeIndex) { Evaluation result = null; if (relativeIndex <= 0) { result = _currentEvaluation; while((++relativeIndex < 0) && (result != null)) { result = result.getParent(); } } return result; }
int indexInParent = ctx.getCurrentEvaluation().getNode().getIndexInParent(); int maxIndex = ctx.getRootEvaluation().getNode().jjtGetNumChildren() - 1; return list.instantiate(target, property, list.getListType(target, ctx.getCurrentEvaluation().getPrevious(), ctx));
/** Resets this Evaluation to the initial state. */ public void reset() { init(null, null, false); }
/** Returns an Evaluation that contains the node, source and whether it is a set operation. */ public Evaluation create(SimpleNode node, Object source, boolean setOperation) { // synchronization is removed as we do not rely anymore on the in-house object pooling return new Evaluation(node, source, setOperation); }
/** * Pushes a new Evaluation onto the stack. This is done before a node evaluates. When evaluation * is complete it should be popped from the stack via <code>popEvaluation()</code>. */ public void pushEvaluation(Evaluation value) { if (_currentEvaluation != null) { _currentEvaluation.addChild(value); } else { setRootEvaluation(value); } setCurrentEvaluation(value); }
public final void setValue( OgnlContext context, Object target, Object value ) throws OgnlException { if (context.getTraceEvaluations()) { EvaluationPool pool = OgnlRuntime.getEvaluationPool(); Throwable evalException = null; Evaluation evaluation = pool.create(this, target, true); context.pushEvaluation(evaluation); try { evaluateSetValueBody(context, target, value); } catch (OgnlException ex) { evalException = ex; ex.setEvaluation(evaluation); throw ex; } catch (RuntimeException ex) { evalException = ex; throw ex; } finally { Evaluation eval = context.popEvaluation(); if (evalException != null) { eval.setException(evalException); } if ((evalException == null) && (context.getRootEvaluation() == null) && !context.getKeepLastEvaluation()) { pool.recycleAll(eval); } } } else { evaluateSetValueBody(context, target, value); } }
@Override public void setProperty(Map context, Object array, Object key, Object value) throws OgnlException { int index = (Integer) key; int length = Array.getLength(array); if (length <= index) { Object newArray = copyOf(array, index, length); OgnlContext ctx = (OgnlContext) context; if (array == ctx.getRoot()) { ctx.setRoot(newArray); } else { String fieldName = ctx.getCurrentEvaluation().getPrevious().getNode().toString(); Object origin = ctx.getCurrentEvaluation().getPrevious().getSource(); Proxifier proxifier = (Proxifier) context.get("proxifier"); Method setter = new ReflectionBasedNullHandler(proxifier).findMethod(origin.getClass(), "set" + StringUtils.capitalize(fieldName), origin.getClass(), null); EmptyElementsRemoval removal = (EmptyElementsRemoval) context.get("removal"); removal.add(newArray, setter, origin); new Mirror().on(origin).invoke().method(setter).withArgs(newArray); } array = newArray; } super.setProperty(context, array, key, value); }
@Test(expected = VRaptorException.class) public void shouldNotSupportNonGenericLists() throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { SimpleNode node = mock(SimpleNode.class); when(node.toString()).thenReturn("nonGeneric"); when(evaluation.getNode()).thenReturn(node); when(evaluation.getSource()).thenReturn(client); handler.instantiate(client.nonGeneric, "2", handler.getListType(client.nonGeneric, evaluation, context)); }
Evaluation eval = context.popEvaluation(); eval.setResult(result); if (evalException != null) { eval.setException(evalException);
/** Returns the Evaluation at the relative index given. This should be zero or a negative number as a relative reference back up the evaluation stack. Therefore getEvaluation(0) returns the current Evaluation. */ public Evaluation getEvaluation(int relativeIndex) { Evaluation result = null; if (relativeIndex <= 0) { result = currentEvaluation; while ((++relativeIndex < 0) && (result != null)) { result = result.getParent(); } } return result; }
/** Resets this Evaluation to the initial state. */ public void reset() { init(null, null, false); }
/** Returns an Evaluation that contains the node, source and whether it is a set operation. */ public Evaluation create(SimpleNode node, Object source, boolean setOperation) { // synchronization is removed as we do not rely anymore on the in-house object pooling return new Evaluation(node, source, setOperation); }
/** * Pushes a new Evaluation onto the stack. This is done before a node evaluates. When evaluation * is complete it should be popped from the stack via <code>popEvaluation()</code>. */ public void pushEvaluation(Evaluation value) { if (_currentEvaluation != null) { _currentEvaluation.addChild(value); } else { setRootEvaluation(value); } setCurrentEvaluation(value); }
eval.setException(evalException);