org.springframework.binding.expression.beanwrapper
Class BeanWrapperExpression

java.lang.Object
  extended by org.springframework.binding.expression.beanwrapper.BeanWrapperExpression
All Implemented Interfaces:
Expression

public class BeanWrapperExpression
extends java.lang.Object
implements Expression

An expression that delegates to a bean wrapper to evaluate or set a property of a context. Also supports the configuration of a ConversionService to allow StringToObject type conversion to occur as part of setting a property. The StringToObject ConversionExecutors are automatically adapted and registered as PropertyEditors. Mainly exists to take advantage of BeanWrapper's unique property access features as an Expression implementation, notably the ability to infer types of generic collections and maps and perform type coersion on collection elements when setting values. Note that Spring's BeanWrapper is not a full-blown EL implementation: it only supports property access, and does not support method invocation, arithmetic operations, or logic operations.

Author:
Keith Donald, Scott Andrews

Constructor Summary
BeanWrapperExpression(java.lang.String expression, ConversionService conversionService)
          Creates a new bean wrapper expression.
 
Method Summary
 boolean equals(java.lang.Object o)
           
 java.lang.String getExpressionString()
          Returns the original string used to create this expression, unmodified.
 java.lang.Object getValue(java.lang.Object context)
          Evaluate this expression in the provided context and return the result of evaluation.
 java.lang.Class getValueType(java.lang.Object context)
          Returns the most general type that can be passed to the Expression.setValue(Object, Object) method for the given context.
 int hashCode()
           
protected  void registerConvertersAsPropertyEditors(org.springframework.beans.PropertyEditorRegistry registry)
          Adapts the String->Object converters to PropertyEditors for use during a setValue attempt.
 void setValue(java.lang.Object context, java.lang.Object value)
          Set this expression in the provided context to the value provided.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BeanWrapperExpression

public BeanWrapperExpression(java.lang.String expression,
                             ConversionService conversionService)
Creates a new bean wrapper expression.

Parameters:
expression - the property expression string
conversionService - the conversion service containing converters to use as PropertyEditors for type conversion
Method Detail

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

getValue

public java.lang.Object getValue(java.lang.Object context)
                          throws EvaluationException
Description copied from interface: Expression
Evaluate this expression in the provided context and return the result of evaluation.

Specified by:
getValue in interface Expression
Parameters:
context - the context to evaluate this expression in
Returns:
the evaluation result
Throws:
EvaluationException - an exception occurred during expression evaluation

setValue

public void setValue(java.lang.Object context,
                     java.lang.Object value)
Description copied from interface: Expression
Set this expression in the provided context to the value provided.

Specified by:
setValue in interface Expression
Parameters:
context - the context on which the new value should be set
value - the new value to set

getValueType

public java.lang.Class getValueType(java.lang.Object context)
Description copied from interface: Expression
Returns the most general type that can be passed to the Expression.setValue(Object, Object) method for the given context.

Specified by:
getValueType in interface Expression
Parameters:
context - the context to evaluate
Returns:
the most general type of value that can be set on this context, or null if the type information cannot be determined

getExpressionString

public java.lang.String getExpressionString()
Description copied from interface: Expression
Returns the original string used to create this expression, unmodified.

Specified by:
getExpressionString in interface Expression
Returns:
the original expression string

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

registerConvertersAsPropertyEditors

protected void registerConvertersAsPropertyEditors(org.springframework.beans.PropertyEditorRegistry registry)
Adapts the String->Object converters to PropertyEditors for use during a setValue attempt. Excludes any String->Enum converter, since BeanWrapper has built in support for Enum conversion.

Parameters:
registry - the registry to register converter-to-editor adapters with