changed 'method' property to 'methodName'

This commit is contained in:
Mark Fisher
2007-12-16 18:27:02 +00:00
parent 1b4e3ce666
commit 4442098a76
6 changed files with 43 additions and 20 deletions

View File

@@ -49,7 +49,7 @@ public class ComponentConfigurer {
RootBeanDefinition endpointDef = new RootBeanDefinition(GenericMessageEndpoint.class);
RootBeanDefinition adapterDef = new RootBeanDefinition(DefaultMessageHandlerAdapter.class);
adapterDef.getPropertyValues().addPropertyValue("object", new RuntimeBeanReference(objectRef));
adapterDef.getPropertyValues().addPropertyValue("method", method);
adapterDef.getPropertyValues().addPropertyValue("methodName", method);
String adapterName = beanNameGenerator.generateBeanName(adapterDef, this.registry);
this.registry.registerBeanDefinition(adapterName, adapterDef);
endpointDef.getPropertyValues().addPropertyValue("handler", new RuntimeBeanReference(adapterName));

View File

@@ -56,7 +56,7 @@ public class EndpointParser implements BeanDefinitionParser {
private static final String OBJECT_PROPERTY = "object";
private static final String METHOD_PROPERTY = "method";
private static final String METHOD_NAME_PROPERTY = "methodName";
private static final String PERIOD_ATTRIBUTE = "period";
@@ -84,7 +84,7 @@ public class EndpointParser implements BeanDefinitionParser {
if (StringUtils.hasText(handlerMethod)) {
BeanDefinition handlerAdapterDef = new RootBeanDefinition(DefaultMessageHandlerAdapter.class);
handlerAdapterDef.getPropertyValues().addPropertyValue(OBJECT_PROPERTY, new RuntimeBeanReference(handlerRef));
handlerAdapterDef.getPropertyValues().addPropertyValue(METHOD_PROPERTY, handlerMethod);
handlerAdapterDef.getPropertyValues().addPropertyValue(METHOD_NAME_PROPERTY, handlerMethod);
String adapterBeanName = parserContext.getReaderContext().generateBeanName(handlerAdapterDef);
parserContext.registerBeanComponent(new BeanComponentDefinition(handlerAdapterDef, adapterBeanName));
endpointDef.getPropertyValues().addPropertyValue(HANDLER_PROPERTY, new RuntimeBeanReference(adapterBeanName));

View File

@@ -20,7 +20,7 @@ import org.w3c.dom.Element;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.bus.MessageBus;
@@ -29,9 +29,9 @@ import org.springframework.integration.bus.MessageBus;
*
* @author Mark Fisher
*/
public class MessageBusParser extends AbstractSingleBeanDefinitionParser {
public class MessageBusParser extends AbstractSimpleBeanDefinitionParser {
public static final String MESSAGE_BUS_BEAN_NAME = "internal.messageBus";
public static final String MESSAGE_BUS_BEAN_NAME = "org.springframework.integration.bus.internalMessageBus";
@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)

View File

@@ -29,8 +29,10 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.OrderComparator;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.integration.MessagingConfigurationException;
import org.springframework.integration.bus.ConsumerPolicy;
import org.springframework.integration.bus.MessageBus;
import org.springframework.integration.channel.ChannelMappingAware;
import org.springframework.integration.endpoint.GenericMessageEndpoint;
import org.springframework.integration.endpoint.InboundMethodInvokingChannelAdapter;
import org.springframework.integration.endpoint.OutboundMethodInvokingChannelAdapter;
@@ -42,6 +44,8 @@ import org.springframework.integration.handler.MessageHandlerChain;
import org.springframework.integration.handler.annotation.AnnotationHandlerCreator;
import org.springframework.integration.handler.annotation.DefaultAnnotationHandlerCreator;
import org.springframework.integration.handler.annotation.Handler;
import org.springframework.integration.handler.annotation.Router;
import org.springframework.integration.router.RouterAnnotationHandlerCreator;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
@@ -75,6 +79,7 @@ public class MessageEndpointAnnotationPostProcessor implements BeanPostProcessor
public void afterPropertiesSet() {
Assert.notNull(this.messageBus, "messageBus is required");
this.handlerCreators.put(Handler.class, new DefaultAnnotationHandlerCreator());
this.handlerCreators.put(Router.class, new RouterAnnotationHandlerCreator());
}
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
@@ -139,9 +144,13 @@ public class MessageEndpointAnnotationPostProcessor implements BeanPostProcessor
return;
}
ReflectionUtils.doWithMethods(bean.getClass(), new ReflectionUtils.MethodCallback() {
boolean foundDefaultOutput = false;
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
Annotation annotation = AnnotationUtils.getAnnotation(method, DefaultOutput.class);
if (annotation != null) {
if (foundDefaultOutput) {
throw new MessagingConfigurationException("only one @DefaultOutput allowed per endpoint");
}
OutboundMethodInvokingChannelAdapter<Object> adapter = new OutboundMethodInvokingChannelAdapter<Object>();
adapter.setObject(bean);
adapter.setMethod(method.getName());
@@ -149,6 +158,7 @@ public class MessageEndpointAnnotationPostProcessor implements BeanPostProcessor
String channelName = beanName + "-defaultOutputChannel";
messageBus.registerChannel(channelName, adapter);
endpoint.setDefaultOutputChannelName(channelName);
foundDefaultOutput = true;
return;
}
}
@@ -164,6 +174,17 @@ public class MessageEndpointAnnotationPostProcessor implements BeanPostProcessor
Annotation annotation = AnnotationUtils.getAnnotation(method, annotationType);
if (annotation != null) {
MessageHandler handler = handlerCreators.get(annotationType).createHandler(bean, method, annotation);
if (handler instanceof ChannelMappingAware) {
((ChannelMappingAware) handler).setChannelMapping(messageBus);
}
if (handler instanceof InitializingBean) {
try {
((InitializingBean) handler).afterPropertiesSet();
}
catch (Exception e) {
throw new MessagingConfigurationException("failed to create handler", e);
}
}
if (handler != null) {
handlers.add(handler);
}

View File

@@ -82,7 +82,7 @@ public class SubscriberAnnotationPostProcessor implements BeanPostProcessor {
if (annotation != null) {
String channelName = (String) AnnotationUtils.getValue(annotation, channelNameAttribute);
DefaultMessageHandlerAdapter adapter = new DefaultMessageHandlerAdapter();
adapter.setMethod(method.getName());
adapter.setMethodName(method.getName());
adapter.setObject(bean);
adapter.afterPropertiesSet();
GenericMessageEndpoint endpoint = new GenericMessageEndpoint();
@@ -92,9 +92,6 @@ public class SubscriberAnnotationPostProcessor implements BeanPostProcessor {
String endpointName = ClassUtils.getShortNameAsProperty(targetClass) +
"-" + method.getName() + "-endpoint";
messageBus.registerEndpoint(endpointName, endpoint);
if (logger.isInfoEnabled()) {
logger.info("registered endpoint: " + endpointName);
}
}
}
});

View File

@@ -16,6 +16,9 @@
package org.springframework.integration.handler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.Ordered;
import org.springframework.integration.endpoint.SimpleMethodInvoker;
@@ -36,9 +39,11 @@ import org.springframework.util.Assert;
*/
public abstract class AbstractMessageHandlerAdapter<T> implements MessageHandler, Ordered, InitializingBean {
protected Log logger = LogFactory.getLog(this.getClass());
private T object;
private String method;
private String methodName;
private MessageMapper mapper = new SimplePayloadMessageMapper();
@@ -56,13 +61,13 @@ public abstract class AbstractMessageHandlerAdapter<T> implements MessageHandler
return this.object;
}
public void setMethod(String method) {
Assert.notNull(method, "'method' must not be null");
this.method = method;
public void setMethodName(String methodName) {
Assert.notNull(methodName, "'methodName' must not be null");
this.methodName = methodName;
}
public String getMethod() {
return this.method;
public String getMethodName() {
return this.methodName;
}
public void setMapper(MessageMapper mapper) {
@@ -82,15 +87,15 @@ public abstract class AbstractMessageHandlerAdapter<T> implements MessageHandler
return this.order;
}
public void afterPropertiesSet() {
this.invoker = new SimpleMethodInvoker<T>(this.object, this.method);
public final void afterPropertiesSet() {
this.invoker = new SimpleMethodInvoker<T>(this.object, this.methodName);
}
public Message handle(Message message) {
public final Message<?> handle(Message<?> message) {
Object result = this.doHandle(message, invoker);
if (result != null) {
if (result instanceof Message) {
return (Message) result;
return (Message<?>) result;
}
return this.mapper.toMessage(result);
}