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.
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
@@ -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<String, String> payloadExpressionMap;
|
||||
|
||||
@@ -39,55 +37,12 @@ public class MethodNameMappingExpressionSource implements ExpressionSource {
|
||||
|
||||
private volatile Map<String, String[]> 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<String, String> 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<String, String[]> 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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user