DATACMNS-661 - Polishing.

Removed the ability to configure a custom SpElExpressionParser for now as it's not really part of the performance optimization. Polished assertions in SpelEvaluatingMethodInterceptor.

Original pull request: #118.
This commit is contained in:
Oliver Gierke
2015-03-19 18:52:37 +01:00
parent 0cf395c1b1
commit 5487395397
3 changed files with 12 additions and 42 deletions

View File

@@ -28,7 +28,6 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.data.util.AnnotationDetectionMethodCallback;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
/**
@@ -42,9 +41,9 @@ import org.springframework.util.ReflectionUtils;
public class SpelAwareProxyProjectionFactory extends ProxyProjectionFactory implements BeanFactoryAware {
private final Map<Class<?>, Boolean> typeCache = new HashMap<Class<?>, Boolean>();
private final SpelExpressionParser parser = new SpelExpressionParser();
private BeanFactory beanFactory;
private SpelExpressionParser parser = new SpelExpressionParser();
/*
* (non-Javadoc)
@@ -55,18 +54,6 @@ public class SpelAwareProxyProjectionFactory extends ProxyProjectionFactory impl
this.beanFactory = beanFactory;
}
/**
* Set the {@link SpelExpressionParser} to use.
*
* @param parser must not be {@literal null}
*/
public void setParser(SpelExpressionParser parser) {
Assert.notNull(parser, "Parser must not be null!");
this.parser = parser;
}
/**
* Inspects the given target type for methods with {@link Value} annotations and caches the result. Will create a
* {@link SpelEvaluatingMethodInterceptor} if an annotation was found or return the delegate as is if not.

View File

@@ -46,6 +46,7 @@ import org.springframework.util.StringUtils;
class SpelEvaluatingMethodInterceptor implements MethodInterceptor {
private static final ParserContext PARSER_CONTEXT = new TemplateParserContext();
private final EvaluationContext evaluationContext;
private final MethodInterceptor delegate;
private final Map<Integer, Expression> expressions;
@@ -65,9 +66,9 @@ class SpelEvaluatingMethodInterceptor implements MethodInterceptor {
SpelExpressionParser parser, Class<?> targetInterface) {
Assert.notNull(delegate, "Delegate MethodInterceptor must not be null!");
Assert.notNull(target, "TargetObject must not be null!");
Assert.notNull(parser, "TargetObject must not be null!");
Assert.notNull(targetInterface, "TargetInterface must not be null!");
Assert.notNull(target, "Target object must not be null!");
Assert.notNull(parser, "SpelExpressionParser must not be null!");
Assert.notNull(targetInterface, "Target interface must not be null!");
StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new TargetWrapper(target));
@@ -90,12 +91,12 @@ class SpelEvaluatingMethodInterceptor implements MethodInterceptor {
* {@code method.hashCode()} as key and the parsed {@link Expression} or an {@link Collections#emptyMap()} if no
* {@code Expressions} were found.
*
* @param parser
* @param targetInterface
* @param parser must not be {@literal null}.
* @param targetInterface must not be {@literal null}.
* @return
*/
private Map<Integer, Expression> potentiallyCreateExpressionsForMethodsOnTargetInterface(SpelExpressionParser parser,
Class<?> targetInterface) {
private static Map<Integer, Expression> potentiallyCreateExpressionsForMethodsOnTargetInterface(
SpelExpressionParser parser, Class<?> targetInterface) {
Map<Integer, Expression> expressions = new HashMap<Integer, Expression>();
@@ -106,16 +107,15 @@ class SpelEvaluatingMethodInterceptor implements MethodInterceptor {
}
Value value = method.getAnnotation(Value.class);
if (!StringUtils.hasText(value.value())) {
throw new IllegalStateException(String.format("@Value annotation on %s contains empty expression!", method));
}
Expression expression = parser.parseExpression(value.value(), PARSER_CONTEXT);
expressions.put(method.hashCode(), expression);
expressions.put(method.hashCode(), parser.parseExpression(value.value(), PARSER_CONTEXT));
}
return expressions.isEmpty() ? Collections.<Integer, Expression> emptyMap() : expressions;
return Collections.unmodifiableMap(expressions);
}
/*