public void setValue( OgnlContext context, Object rootObject, Object value ) throws OgnlException { Ognl.setValue( expression, context, rootObject, value ); } }
public boolean setProperty(Object object, String property, Object value) { if ((object == null) || (property == null)) { return false; } try { Ognl.setValue(property, object, value); return true; } catch (OgnlException e) { return false; } }
public void setValue(String expression, Object obj, Object value) { try { Ognl.setValue(expression, newDefaultContext(), obj, value); } catch (OgnlException ex) { throw new RuntimeException("Failed to set value '" + expression + "' on " + obj, ex); } }
public void setValue(String expression, Map<String, Object> context, Object root, Object value) throws ReflectionException { try { Ognl.setValue(expression, context, root, value); } catch (OgnlException e) { throw new ReflectionException(e); } }
public Void execute(Object expr) throws OgnlException { Object value = Ognl.getValue(expr, contextFrom, from); Ognl.setValue(expr, contextTo, to, value); return null; } });
@Override public void set(Object obj, Object value) { try { Object convertedValue = OgnlUtils.convertValue(value, type); Ognl.setValue(parsedExpression, getActualOgnlContext(), obj, convertedValue); } catch (OgnlException e) { throw new RuntimeException(e); } }
public Void execute(Object tree) throws OgnlException { if (isEvalExpression(tree, context)) { throw new OgnlException("Eval expression/chained expressions cannot be used as parameter name"); } if (isArithmeticExpression(tree, context)) { throw new OgnlException("Arithmetic expressions cannot be used as parameter name"); } Ognl.setValue(tree, context, root, value); return null; } });
@Test public void canInstantiatingStringsInAListSettingItsInternalValueWithoutInvokingConverters() throws OgnlException { Ognl.setValue("legLength[0]", context, myCat, "small"); List<String> legs = myCat.legLength; assertThat(legs.get(0), is(equalTo("small"))); Ognl.setValue("legLength[1]", context, myCat, "big"); assertThat(legs.get(1), is(equalTo("big"))); }
@Test public void canInstantiateAndPopulateAListOfWrappers() throws OgnlException { Ognl.setValue("eyeColorCode[0]", context, myCat, "3"); assertThat(myCat.eyeColorCode.get(0), is(equalTo(3L))); Ognl.setValue("eyeColorCode[1]", context, myCat, "5"); assertThat(myCat.eyeColorCode.get(1), is(equalTo(5L))); } }
public void evaluateToSet(Object target, Object value, EvaluationContext context) { Assert.notNull(target, "The target object to evaluate is required"); Map contextAttributes = (context != null ? context.getAttributes() : Collections.EMPTY_MAP); try { Ognl.setValue(expression, contextAttributes, target, value); } catch (OgnlException e) { throw new EvaluationException(new SetValueAttempt(this, target, value, context), e); } }
@Test public void isCapableOfDealingWithEmptyParameterForInternalWrapperValue() throws OgnlException { when(converters.to(Integer.class)).thenReturn(new IntegerConverter()); Ognl.setValue("cat.firstLeg.id", context, house, ""); assertThat(house.cat.firstLeg.id, is(equalTo(null))); }
private static void resolve(final String expression, final ITestContextExpression contextExpression, final Map<String,Object> variables, final Locale locale) { try { final Object result = contextExpression.evaluate(variables, locale); final Object parsedExpression = Ognl.parseExpression(expression); Ognl.setValue(parsedExpression, variables, result); } catch (final Throwable t) { throw new TestEngineExecutionException( "Exception while trying to evaluate expression \"" + expression + "\" on context for test \"" + TestExecutor.getThreadTestName() + "\"", t); } }
@Test @SuppressWarnings("unchecked") public void shouldInvokePrimitiveConverter() throws OgnlException { when(converters.to(int.class)).thenReturn(converter); when(converter.convert("2", int.class, bundle)).thenReturn(2); Map<?,?> context = Ognl.createDefaultContext(myCat); Ognl.setTypeConverter(context, adapter); Ognl.setValue("length", context, myCat, "2"); assertThat(myCat.length, is(equalTo(2))); }
@Test public void isCapableOfDealingWithEmptyParameterForInternalValueWhichNeedsAConverter() throws OgnlException { final MutableRequest request = mock(MutableRequest.class); final RequestInfo webRequest = new RequestInfo(null, null, request, null); final JstlLocalization jstlLocalization = new JstlLocalization(webRequest); when(request.getAttribute("javax.servlet.jsp.jstl.fmt.locale.request")).thenReturn("pt_br"); when(converters.to(Calendar.class)).thenReturn(new LocaleBasedCalendarConverter(jstlLocalization)); Ognl.setValue("cat.firstLeg.birthDay", context, house, "10/5/2010"); assertThat(house.cat.firstLeg.birthDay, is(equalTo((Calendar) new GregorianCalendar(2010, 4, 10)))); }
@SuppressWarnings("unchecked") @Test public void shouldInvokeCustomTypeConverter() throws OgnlException { when(converters.to(Tail.class)).thenReturn(converter); when(converter.convert("15", Tail.class, bundle)).thenReturn(new Tail(15)); Map<?,?> context = Ognl.createDefaultContext(myCat); Ognl.setTypeConverter(context, adapter); Ognl.setValue("tail", context, myCat, "15"); assertThat(myCat.tail.length, is(equalTo(15))); }
@Test public void shouldInstantiateAListOfStrings() throws OgnlException { House house = new House(); Ognl.setValue("mouse.eyeColors[0]", context, house, "Blue"); Ognl.setValue("mouse.eyeColors[1]", context, house, "Green"); verify(removal).add(anyCollection()); assertThat(house.getMouse().getEyeColors().get(0), is(equalTo("Blue"))); assertThat(house.getMouse().getEyeColors().get(1), is(equalTo("Green"))); }
@Test public void shouldNotInstantiateIfLastTerm() throws OgnlException, NoSuchMethodException { final TypeConverter typeConverter = mock(TypeConverter.class); final House house = new House(); final Mouse tom = new Mouse(); Method method = House.class.getDeclaredMethod("setMouse", Mouse.class); when(typeConverter.convertValue(context, house, method, "mouse", "22", Mouse.class)).thenReturn(tom); Ognl.setTypeConverter(context, typeConverter); Ognl.setValue("mouse", context, house, "22"); assertThat(house.getMouse(), is(equalTo(tom))); }
@Test(expected=IllegalArgumentException.class) public void shouldThrowExceptionIfNoConverterIsFound() throws Throwable { when(converters.to(Tail.class)).thenReturn(null); Map<?,?> context = Ognl.createDefaultContext(myCat); Ognl.setTypeConverter(context, adapter); try { Ognl.setValue("tail", context, myCat, "15"); } catch (OgnlException e) { throw e.getCause(); } } }
@Test public void shouldInstantiateAnObjectIfRequiredToSetAProperty() throws OgnlException { House house = new House(); Ognl.setValue("mouse.name", context, house, "James"); assertThat(house.getMouse().getName(), is(equalTo("James"))); }