diff --git a/org.springframework.context/src/main/java/org/springframework/context/expression/StandardBeanExpressionResolver.java b/org.springframework.context/src/main/java/org/springframework/context/expression/StandardBeanExpressionResolver.java index 2bfe4b7e47e..80a981850a2 100644 --- a/org.springframework.context/src/main/java/org/springframework/context/expression/StandardBeanExpressionResolver.java +++ b/org.springframework.context/src/main/java/org/springframework/context/expression/StandardBeanExpressionResolver.java @@ -23,11 +23,14 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanExpressionException; import org.springframework.beans.factory.config.BeanExpressionContext; import org.springframework.beans.factory.config.BeanExpressionResolver; +import org.springframework.core.convert.ConversionService; import org.springframework.expression.Expression; import org.springframework.expression.ExpressionParser; import org.springframework.expression.ParserContext; import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.support.StandardEvaluationContext; +import org.springframework.expression.spel.support.StandardTypeConverter; +import org.springframework.expression.spel.support.StandardTypeLocator; import org.springframework.util.Assert; /** @@ -96,7 +99,7 @@ public class StandardBeanExpressionResolver implements BeanExpressionResolver { /** * Specify the EL parser to use for expression parsing. - *
Default is a {@link org.springframework.expression.spel.SpelExpressionParser}, + *
Default is a {@link org.springframework.expression.spel.standard.SpelExpressionParser}, * compatible with standard Unified EL style expression syntax. */ public void setExpressionParser(ExpressionParser expressionParser) { @@ -119,6 +122,11 @@ public class StandardBeanExpressionResolver implements BeanExpressionResolver { sec.addPropertyAccessor(new BeanExpressionContextAccessor()); sec.addPropertyAccessor(new BeanFactoryAccessor()); sec.addPropertyAccessor(new MapAccessor()); + sec.setTypeLocator(new StandardTypeLocator(evalContext.getBeanFactory().getBeanClassLoader())); + ConversionService conversionService = evalContext.getBeanFactory().getConversionService(); + if (conversionService != null) { + sec.setTypeConverter(new StandardTypeConverter(conversionService)); + } customizeEvaluationContext(sec); this.evaluationCache.put(evalContext, sec); } diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/EvaluationContext.java b/org.springframework.expression/src/main/java/org/springframework/expression/EvaluationContext.java index 105a630b3ae..9930e2131f6 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/EvaluationContext.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/EvaluationContext.java @@ -21,11 +21,11 @@ import java.util.List; /** * Expressions are executed in an evaluation context. It is in this context that references * are resolved when encountered during expression evaluation. - * - * There is a default implementation of the EvaluationContext, + * + *
There is a default implementation of the EvaluationContext, * {@link org.springframework.expression.spel.support.StandardEvaluationContext} * that can be extended, rather than having to implement everything. - * + * * @author Andy Clement * @author Juergen Hoeller * @since 3.0 @@ -36,27 +36,6 @@ public interface EvaluationContext { * @return the root context object against which unqualified properties/methods/etc should be resolved */ TypedValue getRootObject(); - - - /** - * @param rootObject the root object against which unqualified properties/methods/etc should be resolved - */ - void setRootObject(Object object); - - - /** - * Set a named variable within this execution context to a specified value. - * @param name variable to set - * @param value value to be placed in the variable - */ - void setVariable(String name, Object value); - - /** - * Look up a named variable within this execution context. - * @param name variable to lookup - * @return the value of the variable - */ - Object lookupVariable(String name); /** * @return a list of resolvers that will be asked in turn to locate a constructor @@ -78,20 +57,34 @@ public interface EvaluationContext { */ TypeLocator getTypeLocator(); - /** - * @return a type comparator for comparing pairs of objects for equality. - */ - TypeComparator getTypeComparator(); - /** * @return a type converter that can convert (or coerce) a value from one type to another. */ TypeConverter getTypeConverter(); + /** + * @return a type comparator for comparing pairs of objects for equality. + */ + TypeComparator getTypeComparator(); + /** * @return an operator overloader that may support mathematical operations between more than the standard set of * types */ OperatorOverloader getOperatorOverloader(); + /** + * Set a named variable within this evaluation context to a specified value. + * @param name variable to set + * @param value value to be placed in the variable + */ + void setVariable(String name, Object value); + + /** + * Look up a named variable within this evaluation context. + * @param name variable to lookup + * @return the value of the variable + */ + Object lookupVariable(String name); + } diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ExpressionState.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ExpressionState.java index fa8b932d86e..62f365c3575 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ExpressionState.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ExpressionState.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.expression.spel; import java.util.HashMap; @@ -36,7 +37,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParserConfigur * communicate state. This is in contrast to the EvaluationContext, which is shared amongst expression evaluations, and * any changes to it will be seen by other expressions or any code that chooses to ask questions of the context. * - * It also acts as a place for to define common utility routines that the various Ast nodes might need. + *
It also acts as a place for to define common utility routines that the various Ast nodes might need.
*
* @author Andy Clement
* @since 3.0
@@ -75,7 +76,8 @@ public class ExpressionState {
TypedValue rootObject = this.relatedContext.getRootObject();
if (rootObject == null) {
return TypedValue.NULL_TYPED_VALUE;
- } else {
+ }
+ else {
return rootObject;
}
}
@@ -94,7 +96,8 @@ public class ExpressionState {
TypedValue root = this.relatedContext.getRootObject();
if (root == null) {
return TypedValue.NULL_TYPED_VALUE;
- } else {
+ }
+ else {
return root;
}
}
@@ -105,10 +108,11 @@ public class ExpressionState {
public TypedValue lookupVariable(String name) {
Object value = this.relatedContext.lookupVariable(name);
- if (value==null) {
+ if (value == null) {
return TypedValue.NULL_TYPED_VALUE;
- } else {
- return new TypedValue(value,TypeDescriptor.forObject(value));
+ }
+ else {
+ return new TypedValue(value, TypeDescriptor.forObject(value));
}
}
diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java
index b02029cbf04..3a55f3fee49 100644
--- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java
+++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java
@@ -47,8 +47,6 @@ public class StandardEvaluationContext implements EvaluationContext {
private TypedValue rootObject;
- private final Map