public String toSetSourceString(OgnlContext context, Object target) { return toString(); }
public String toString(String prefix) { return prefix + OgnlParserTreeConstants.jjtNodeName[_id] + " " + toString(); }
public String toGetSourceString(OgnlContext context, Object target) { return toString(); }
public String toSetSourceString(OgnlContext context, Object target) { return toString(); }
public String toString(String prefix) { return prefix + OgnlParserTreeConstants.jjtNodeName[_id] + " " + toString(); }
public String toGetSourceString(OgnlContext context, Object target) { return toString(); }
public String toString(String prefix) { return prefix + OgnlParserTreeConstants.jjtNodeName[id] + " " + toString(); }
public void dump(PrintWriter writer, String prefix) { writer.println(toString(prefix)); if (children != null) { for (int i = 0; i < children.length; ++i) { SimpleNode n = (SimpleNode)children[i]; if (n != null) { n.dump(writer, prefix + " "); } } } }
public void dump(PrintWriter writer, String prefix) { writer.println(toString(prefix)); if (_children != null) { for (int i = 0; i < _children.length; ++i) { SimpleNode n = (SimpleNode) _children[i]; if (n != null) { n.dump(writer, prefix + " "); } } } }
public void dump(PrintWriter writer, String prefix) { writer.println(toString(prefix)); if (_children != null) { for (int i = 0; i < _children.length; ++i) { SimpleNode n = (SimpleNode) _children[i]; if (n != null) { n.dump(writer, prefix + " "); } } } }
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; }
@Test public void shouldInsertItemsUntilTheRequiredPosition() throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { SimpleNode node = mock(SimpleNode.class); when(node.toString()).thenReturn("names"); when(evaluation.getNode()).thenReturn(node); when(evaluation.getSource()).thenReturn(client); handler.instantiate(client.names, 2, handler.getListType(client.names, evaluation, context)); assertThat(client.names.size(), is(equalTo(3))); assertThat(client.names.get(2), is(notNullValue())); verify(removal).add(client.names); } }
@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)); }
@Before public void setup() { this.context = mock(OgnlContext.class); this.evaluation = mock(Evaluation.class); this.node = mock(SimpleNode.class); this.instance = new Data(); this.typeConverter = mock(TypeConverter.class); final EmptyElementsRemoval removal = new EmptyElementsRemoval() { @Override public void removeExtraElements() { // does nothing } }; final Proxifier proxifier = new JavassistProxifier(new ReflectionInstanceCreator()); accessor = new ArrayAccessor(); when(context.get("removal")).thenReturn(removal); when(context.get("proxifier")).thenReturn(proxifier); when(context.getCurrentEvaluation()).thenReturn(evaluation); when(evaluation.getPrevious()).thenReturn(evaluation); when(evaluation.getNode()).thenReturn(node); when(node.toString()).thenReturn("values"); when(evaluation.getSource()).thenReturn(instance); when(context.getTypeConverter()).thenReturn(typeConverter); }
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; }
@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); }