polishing

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3569 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Juergen Hoeller 2010-08-12 18:42:13 +00:00
parent 39787d0745
commit 892d44f8c0
2 changed files with 10 additions and 20 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2009 the original author or authors. * Copyright 2002-2010 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,10 +19,11 @@ package org.springframework.expression;
import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.TypeDescriptor;
/** /**
* An expression capable of evaluating itself against context objects. Encapsulates the details of a previously parsed * An expression capable of evaluating itself against context objects.
* expression string. Provides a common abstraction for expression evaluation independent of any language like OGNL or * Encapsulates the details of a previously parsed expression string.
* the Unified EL. * Provides a common abstraction for expression evaluation independent
* * of any language like OGNL or the Unified EL.
*
* @author Keith Donald * @author Keith Donald
* @author Andy Clement * @author Andy Clement
* @since 3.0 * @since 3.0
@ -31,7 +32,6 @@ public interface Expression {
/** /**
* Evaluate this expression in the default standard context. * Evaluate this expression in the default standard context.
*
* @return the evaluation result * @return the evaluation result
* @throws EvaluationException if there is a problem during evaluation * @throws EvaluationException if there is a problem during evaluation
*/ */
@ -39,7 +39,6 @@ public interface Expression {
/** /**
* Evaluate this expression against the specified root object * Evaluate this expression against the specified root object
*
* @param rootObject the root object against which properties/etc will be resolved * @param rootObject the root object against which properties/etc will be resolved
* @return the evaluation result * @return the evaluation result
* @throws EvaluationException if there is a problem during evaluation * @throws EvaluationException if there is a problem during evaluation
@ -49,7 +48,6 @@ public interface Expression {
/** /**
* Evaluate the expression in the default context. If the result of the evaluation does not match (and * Evaluate the expression in the default context. If the result of the evaluation does not match (and
* cannot be converted to) the expected result type then an exception will be returned. * cannot be converted to) the expected result type then an exception will be returned.
*
* @param desiredResultType the class the caller would like the result to be * @param desiredResultType the class the caller would like the result to be
* @return the evaluation result * @return the evaluation result
* @throws EvaluationException if there is a problem during evaluation * @throws EvaluationException if there is a problem during evaluation
@ -60,7 +58,6 @@ public interface Expression {
* Evaluate the expression in the default context against the specified root object. If the * Evaluate the expression in the default context against the specified root object. If the
* result of the evaluation does not match (and cannot be converted to) the expected result type * result of the evaluation does not match (and cannot be converted to) the expected result type
* then an exception will be returned. * then an exception will be returned.
*
* @param rootObject the root object against which properties/etc will be resolved * @param rootObject the root object against which properties/etc will be resolved
* @param desiredResultType the class the caller would like the result to be * @param desiredResultType the class the caller would like the result to be
* @return the evaluation result * @return the evaluation result
@ -70,7 +67,6 @@ public interface Expression {
/** /**
* Evaluate this expression in the provided context and return the result of evaluation. * Evaluate this expression in the provided context and return the result of evaluation.
*
* @param context the context in which to evaluate the expression * @param context the context in which to evaluate the expression
* @return the evaluation result * @return the evaluation result
* @throws EvaluationException if there is a problem during evaluation * @throws EvaluationException if there is a problem during evaluation
@ -80,7 +76,6 @@ public interface Expression {
/** /**
* Evaluate this expression in the provided context and return the result of evaluation, but use * Evaluate this expression in the provided context and return the result of evaluation, but use
* the supplied root context as an override for any default root object specified in the context. * the supplied root context as an override for any default root object specified in the context.
*
* @param context the context in which to evaluate the expression * @param context the context in which to evaluate the expression
* @param rootObject the root object against which properties/etc will be resolved * @param rootObject the root object against which properties/etc will be resolved
* @return the evaluation result * @return the evaluation result
@ -92,7 +87,6 @@ public interface Expression {
* Evaluate the expression in a specified context which can resolve references to properties, methods, types, etc - * Evaluate the expression in a specified context which can resolve references to properties, methods, types, etc -
* the type of the evaluation result is expected to be of a particular class and an exception will be thrown if it * the type of the evaluation result is expected to be of a particular class and an exception will be thrown if it
* is not and cannot be converted to that type. * is not and cannot be converted to that type.
*
* @param context the context in which to evaluate the expression * @param context the context in which to evaluate the expression
* @param desiredResultType the class the caller would like the result to be * @param desiredResultType the class the caller would like the result to be
* @return the evaluation result * @return the evaluation result
@ -105,7 +99,6 @@ public interface Expression {
* the type of the evaluation result is expected to be of a particular class and an exception will be thrown if it * the type of the evaluation result is expected to be of a particular class and an exception will be thrown if it
* is not and cannot be converted to that type. The supplied root object overrides any default specified on the * is not and cannot be converted to that type. The supplied root object overrides any default specified on the
* supplied context. * supplied context.
*
* @param context the context in which to evaluate the expression * @param context the context in which to evaluate the expression
* @param rootObject the root object against which properties/etc will be resolved * @param rootObject the root object against which properties/etc will be resolved
* @param desiredResultType the class the caller would like the result to be * @param desiredResultType the class the caller would like the result to be
@ -115,9 +108,8 @@ public interface Expression {
<T> T getValue(EvaluationContext context, Object rootObject, Class<T> desiredResultType) throws EvaluationException; <T> T getValue(EvaluationContext context, Object rootObject, Class<T> desiredResultType) throws EvaluationException;
/** /**
* Returns the most general type that can be passed to the {@link #setValue(EvaluationContext, Object)} method using * Returns the most general type that can be passed to the {@link #setValue(EvaluationContext, Object)}
* the default context. * method using the default context.
*
* @return the most general type of value that can be set on this context * @return the most general type of value that can be set on this context
* @throws EvaluationException if there is a problem determining the type * @throws EvaluationException if there is a problem determining the type
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2009 the original author or authors. * Copyright 2002-2010 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -42,8 +42,7 @@ public abstract class ExpressionUtils {
* @throws EvaluationException if there is a problem during conversion or conversion of the value to the specified * @throws EvaluationException if there is a problem during conversion or conversion of the value to the specified
* type is not supported * type is not supported
*/ */
public static <T> T convert(EvaluationContext context, Object value, Class<T> targetType) public static <T> T convert(EvaluationContext context, Object value, Class<T> targetType) throws EvaluationException {
throws EvaluationException {
// TODO remove this function over time and use the one it delegates to // TODO remove this function over time and use the one it delegates to
return convertTypedValue(context,new TypedValue(value,TypeDescriptor.forObject(value)),targetType); return convertTypedValue(context,new TypedValue(value,TypeDescriptor.forObject(value)),targetType);
} }
@ -61,7 +60,6 @@ public abstract class ExpressionUtils {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> T convertTypedValue(EvaluationContext context, TypedValue typedValue, Class<T> targetType) { public static <T> T convertTypedValue(EvaluationContext context, TypedValue typedValue, Class<T> targetType) {
Object value = typedValue.getValue(); Object value = typedValue.getValue();
if (targetType == null || ClassUtils.isAssignableValue(targetType, value)) { if (targetType == null || ClassUtils.isAssignableValue(targetType, value)) {
return (T) value; return (T) value;
} }