From 2de00f0964e4f7bd9f11ab7082e91fafc6890081 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Wed, 3 Mar 2010 21:31:52 +0000 Subject: [PATCH] INT-953 added a SimpleExpressionSource implementation for configuring single values for the channel, payload expression, and header expression array rather than using a per-method Map. --- .../aop/AbstractExpressionSource.java | 87 +++++++++++++++++++ .../MethodNameMappingExpressionSource.java | 51 +---------- .../aop/SimpleExpressionSource.java | 70 +++++++++++++++ 3 files changed, 160 insertions(+), 48 deletions(-) create mode 100644 org.springframework.integration/src/main/java/org/springframework/integration/aop/AbstractExpressionSource.java create mode 100644 org.springframework.integration/src/main/java/org/springframework/integration/aop/SimpleExpressionSource.java diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/aop/AbstractExpressionSource.java b/org.springframework.integration/src/main/java/org/springframework/integration/aop/AbstractExpressionSource.java new file mode 100644 index 0000000000..fbff7b0a6a --- /dev/null +++ b/org.springframework.integration/src/main/java/org/springframework/integration/aop/AbstractExpressionSource.java @@ -0,0 +1,87 @@ +/* + * Copyright 2002-2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.aop; + +import java.lang.reflect.Method; + +import org.springframework.core.LocalVariableTableParameterNameDiscoverer; +import org.springframework.core.ParameterNameDiscoverer; + +/** + * Base class for {@link ExpressionSource} implementations. + * + * @author Mark Fisher + * @since 2.0 + */ +public abstract class AbstractExpressionSource implements ExpressionSource { + + private volatile String methodNameVariableName = ExpressionSource.DEFAULT_METHOD_NAME_VARIABLE_NAME; + + private volatile String argumentMapVariableName = ExpressionSource.DEFAULT_ARGUMENT_MAP_VARIABLE_NAME; + + private volatile String returnValueVariableName = ExpressionSource.DEFAULT_RETURN_VALUE_VARIABLE_NAME; + + private volatile String exceptionVariableName = ExpressionSource.DEFAULT_EXCEPTION_VARIABLE_NAME; + + private final ParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer(); + + + public void setMethodNameVariableName(String methodNameVariableName) { + this.methodNameVariableName = methodNameVariableName; + } + + public String getMethodNameVariableName(Method method) { + return this.methodNameVariableName; + } + + public void setArgumentMapVariableName(String argumentMapVariableName) { + this.argumentMapVariableName = argumentMapVariableName; + } + + public String getArgumentMapVariableName(Method method) { + return this.argumentMapVariableName; + } + + public void setExceptionVariableName(String exceptionVariableName) { + this.exceptionVariableName = exceptionVariableName; + } + + public String getExceptionVariableName(Method method) { + return this.exceptionVariableName; + } + + public void setReturnValueVariableName(String returnValueVariableName) { + this.returnValueVariableName = returnValueVariableName; + } + + public String getReturnValueVariableName(Method method) { + return this.returnValueVariableName; + } + + protected String[] discoverMethodParameterNames(Method method) { + return this.parameterNameDiscoverer.getParameterNames(method); + } + + public abstract String getPayloadExpression(Method method); + + public abstract String[] getArgumentVariableNames(Method method); + + public abstract String[] getHeaderExpressions(Method method); + + public abstract String getChannelName(Method method); + +} diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/aop/MethodNameMappingExpressionSource.java b/org.springframework.integration/src/main/java/org/springframework/integration/aop/MethodNameMappingExpressionSource.java index 140c314968..3b3283d887 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/aop/MethodNameMappingExpressionSource.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/aop/MethodNameMappingExpressionSource.java @@ -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"); * you may not use this file except in compliance with the License. @@ -20,8 +20,6 @@ import java.lang.reflect.Method; import java.util.Collections; import java.util.Map; -import org.springframework.core.LocalVariableTableParameterNameDiscoverer; -import org.springframework.core.ParameterNameDiscoverer; import org.springframework.util.Assert; import org.springframework.util.PatternMatchUtils; @@ -29,7 +27,7 @@ import org.springframework.util.PatternMatchUtils; * @author Mark Fisher * @since 2.0 */ -public class MethodNameMappingExpressionSource implements ExpressionSource { +public class MethodNameMappingExpressionSource extends AbstractExpressionSource { private final Map payloadExpressionMap; @@ -39,55 +37,12 @@ public class MethodNameMappingExpressionSource implements ExpressionSource { private volatile Map argumentVariableNameMap; - private volatile String methodNameVariableName = ExpressionSource.DEFAULT_METHOD_NAME_VARIABLE_NAME; - - private volatile String argumentMapVariableName = ExpressionSource.DEFAULT_ARGUMENT_MAP_VARIABLE_NAME; - - private volatile String returnValueVariableName = ExpressionSource.DEFAULT_RETURN_VALUE_VARIABLE_NAME; - - private volatile String exceptionVariableName = ExpressionSource.DEFAULT_EXCEPTION_VARIABLE_NAME; - - private final ParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer(); - public MethodNameMappingExpressionSource(Map payloadExpressionMap) { Assert.notEmpty(payloadExpressionMap, "payloadExpressionMap must not be empty"); this.payloadExpressionMap = payloadExpressionMap; } - - public void setMethodNameVariableName(String methodNameVariableName) { - this.methodNameVariableName = methodNameVariableName; - } - - public String getMethodNameVariableName(Method method) { - return this.methodNameVariableName; - } - - public void setArgumentMapVariableName(String argumentMapVariableName) { - this.argumentMapVariableName = argumentMapVariableName; - } - - public String getArgumentMapVariableName(Method method) { - return this.argumentMapVariableName; - } - - public void setExceptionVariableName(String exceptionVariableName) { - this.exceptionVariableName = exceptionVariableName; - } - - public String getExceptionVariableName(Method method) { - return this.exceptionVariableName; - } - - public void setReturnValueVariableName(String returnValueVariableName) { - this.returnValueVariableName = returnValueVariableName; - } - - public String getReturnValueVariableName(Method method) { - return this.returnValueVariableName; - } - public void setArgumentVariableNameMap(Map argumentVariableNameMap) { this.argumentVariableNameMap = argumentVariableNameMap; } @@ -108,7 +63,7 @@ public class MethodNameMappingExpressionSource implements ExpressionSource { } } } - return this.parameterNameDiscoverer.getParameterNames(method); + return this.discoverMethodParameterNames(method); } public String getPayloadExpression(Method method) { diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/aop/SimpleExpressionSource.java b/org.springframework.integration/src/main/java/org/springframework/integration/aop/SimpleExpressionSource.java new file mode 100644 index 0000000000..c44c473633 --- /dev/null +++ b/org.springframework.integration/src/main/java/org/springframework/integration/aop/SimpleExpressionSource.java @@ -0,0 +1,70 @@ +/* + * Copyright 2002-2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.aop; + +import java.lang.reflect.Method; + +/** + * Simple implementation of {@link ExpressionSource} that allows for + * configuration of a single channel name, payload expression, and + * array of header key=value expressions. + * + * @author Mark Fisher + * @since 2.0 + */ +public class SimpleExpressionSource extends AbstractExpressionSource { + + private volatile String channelName; + + private volatile String payloadExpression; + + private volatile String[] headerExpressions; + + + public void setChannelName(String channelName) { + this.channelName = channelName; + } + + @Override + public String getChannelName(Method method) { + return this.channelName; + } + + public void setPayloadExpression(String payloadExpression) { + this.payloadExpression = payloadExpression; + } + + @Override + public String getPayloadExpression(Method method) { + return this.payloadExpression; + } + + public void setHeaderExpressions(String[] headerExpressions) { + this.headerExpressions = headerExpressions; + } + + @Override + public String[] getHeaderExpressions(Method method) { + return this.headerExpressions; + } + + @Override + public String[] getArgumentVariableNames(Method method) { + return this.discoverMethodParameterNames(method); + } + +}