public Object convertValue(Map context, Object target, Member member, String propertyName, Object value, Class toType) throws ValueCoercionException { try { return conversionService.executeConversion(value, toType); } catch (ConversionException e) { throw new ValueCoercionException(context.getClass(), expressionString, value, toType, e); } } };
public void testSetBogusValueWithCoersion() { Expression e = parser.parseExpression("date", null); try { e.setValue(bean, "bogus"); fail("Should have failed tme"); } catch (ValueCoercionException ex) { assertTrue(ex.getCause() instanceof TypeMismatchException); } }
private Object convertValueIfNecessary(Object value, Class<?> expectedType, Object context) throws ValueCoercionException { if (expectedType == null) { return value; } else { try { return conversionService.executeConversion(value, expectedType); } catch (ConversionException e) { throw new ValueCoercionException(context.getClass(), getExpressionString(), value, expectedType, e); } } }
private Object convertValueIfNecessary(Object value, Class<?> expectedType, Object context) throws ValueCoercionException { if (expectedType == null) { return value; } else { try { return conversionService.executeConversion(value, expectedType); } catch (ConversionException e) { throw new ValueCoercionException(context.getClass(), getExpressionString(), value, expectedType, e); } } }
private Object convertValueIfNecessary(Object value, Class expectedType, Object context) throws ValueCoercionException { if (expectedType == null) { return value; } else { try { return conversionService.executeConversion(value, expectedType); } catch (ConversionException e) { throw new ValueCoercionException(context.getClass(), getExpressionString(), value, expectedType, e); } } }
public void setValue(Object context, Object value) { try { BeanWrapperImpl beanWrapper = new BeanWrapperImpl(context); Set converters = conversionService.getConversionExecutors(String.class); for (Iterator it = converters.iterator(); it.hasNext();) { ConversionExecutor converter = (ConversionExecutor) it.next(); beanWrapper.registerCustomEditor(converter.getTargetClass(), new PropertyEditorConverter(converter)); } beanWrapper.setPropertyValue(expression, value); } catch (NotWritablePropertyException e) { throw new PropertyNotFoundException(context.getClass(), expression, e); } catch (TypeMismatchException e) { throw new ValueCoercionException(context.getClass(), expression, value, e.getRequiredType(), e); } catch (BeansException e) { throw new EvaluationException(context.getClass(), getExpressionString(), "A BeansException occurred setting the value of expression '" + getExpressionString() + "' on context [" + context.getClass() + "] to [" + value + "]", e); } }
public void setValue(Object context, Object value) { try { BeanWrapperImpl beanWrapper = new BeanWrapperImpl(context); beanWrapper.setAutoGrowNestedPaths(autoGrowNestedPaths); beanWrapper.setAutoGrowCollectionLimit(autoGrowCollectionLimit); beanWrapper.setConversionService(conversionService.getDelegateConversionService()); beanWrapper.setPropertyValue(expression, value); } catch (NotWritablePropertyException e) { throw new PropertyNotFoundException(context.getClass(), expression, e); } catch (TypeMismatchException e) { throw new ValueCoercionException(context.getClass(), expression, value, e.getRequiredType(), e); } catch (BeansException e) { throw new EvaluationException(context.getClass(), getExpressionString(), "A BeansException occurred setting the value of expression '" + getExpressionString() + "' on context [" + context.getClass() + "] to [" + value + "]", e); } }
public void setValue(Object context, Object value) { try { BeanWrapperImpl beanWrapper = new BeanWrapperImpl(context); beanWrapper.setAutoGrowNestedPaths(autoGrowNestedPaths); beanWrapper.setAutoGrowCollectionLimit(autoGrowCollectionLimit); beanWrapper.setConversionService(conversionService.getDelegateConversionService()); beanWrapper.setPropertyValue(expression, value); } catch (NotWritablePropertyException e) { throw new PropertyNotFoundException(context.getClass(), expression, e); } catch (TypeMismatchException e) { throw new ValueCoercionException(context.getClass(), expression, value, e.getRequiredType(), e); } catch (BeansException e) { throw new EvaluationException(context.getClass(), getExpressionString(), "A BeansException occurred setting the value of expression '" + getExpressionString() + "' on context [" + context.getClass() + "] to [" + value + "]", e); } }
@SuppressWarnings("deprecation") public Object getValue(Object rootObject) throws EvaluationException { try { EvaluationContext context = contextFactory.createContext(rootObject); if (context instanceof StandardEvaluationContext) { extendEvaluationContext((StandardEvaluationContext) context); } return expression.getValue(context, expectedType); } catch (SpelEvaluationException e) { if (e.getMessageCode().equals(SpelMessage.PROPERTY_OR_FIELD_NOT_READABLE)) { throw new PropertyNotFoundException(rootObject.getClass(), getExpressionString(), e); } if (e.getMessageCode().equals(SpelMessage.TYPE_CONVERSION_ERROR)) { throw new ValueCoercionException(rootObject.getClass(), getExpressionString(), null, expectedType, e); } throw new EvaluationException(rootObject.getClass(), expression.getExpressionString(), "An ELException occurred getting the value for expression '" + getExpressionString() + "' on context [" + rootObject.getClass() + "]", e); } }
@SuppressWarnings("deprecation") public Object getValue(Object rootObject) throws EvaluationException { try { EvaluationContext context = contextFactory.createContext(rootObject); if (context instanceof StandardEvaluationContext) { extendEvaluationContext((StandardEvaluationContext) context); } return expression.getValue(context, expectedType); } catch (SpelEvaluationException e) { if (e.getMessageCode().equals(SpelMessage.PROPERTY_OR_FIELD_NOT_READABLE)) { throw new PropertyNotFoundException(rootObject.getClass(), getExpressionString(), e); } if (e.getMessageCode().equals(SpelMessage.TYPE_CONVERSION_ERROR)) { throw new ValueCoercionException(rootObject.getClass(), getExpressionString(), null, expectedType, e); } throw new EvaluationException(rootObject.getClass(), expression.getExpressionString(), "An ELException occurred getting the value for expression '" + getExpressionString() + "' on context [" + rootObject.getClass() + "]", e); } }
@SuppressWarnings("deprecation") public void setValue(Object rootObject, Object value) throws EvaluationException { try { EvaluationContext context = contextFactory.createContext(rootObject); if (context instanceof StandardEvaluationContext) { extendEvaluationContext((StandardEvaluationContext) context); } expression.setValue(context, value); } catch (SpelEvaluationException e) { if (e.getMessageCode().equals(SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE)) { throw new PropertyNotFoundException(rootObject.getClass(), getExpressionString(), e); } if (e.getMessageCode().equals(SpelMessage.EXCEPTION_DURING_PROPERTY_WRITE)) { throw new ValueCoercionException(rootObject.getClass(), getExpressionString(), value, expectedType, e); } throw new EvaluationException(rootObject.getClass(), getExpressionString(), "An ELException occurred setting the value of expression '" + getExpressionString() + "' on context [" + rootObject.getClass() + "] to [" + value + "]", e); } }
@SuppressWarnings("deprecation") public void setValue(Object rootObject, Object value) throws EvaluationException { try { EvaluationContext context = contextFactory.createContext(rootObject); if (context instanceof StandardEvaluationContext) { extendEvaluationContext((StandardEvaluationContext) context); } expression.setValue(context, value); } catch (SpelEvaluationException e) { if (e.getMessageCode().equals(SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE)) { throw new PropertyNotFoundException(rootObject.getClass(), getExpressionString(), e); } if (e.getMessageCode().equals(SpelMessage.EXCEPTION_DURING_PROPERTY_WRITE)) { throw new ValueCoercionException(rootObject.getClass(), getExpressionString(), value, expectedType, e); } throw new EvaluationException(rootObject.getClass(), getExpressionString(), "An ELException occurred setting the value of expression '" + getExpressionString() + "' on context [" + rootObject.getClass() + "] to [" + value + "]", e); } }