org.springframework.integration.handler
Class AbstractMessageHandlerAdapter

java.lang.Object
  extended by org.springframework.integration.handler.AbstractMessageHandlerAdapter
All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean, MessageHandler
Direct Known Subclasses:
DefaultMessageHandlerAdapter, MethodInvokingTarget, RouterMessageHandlerAdapter, SplitterMessageHandlerAdapter

public abstract class AbstractMessageHandlerAdapter
extends java.lang.Object
implements MessageHandler, org.springframework.beans.factory.InitializingBean

An implementation of the MessageHandler interface that invokes the specified method and target object. Either a Method reference or a 'methodName' may be provided, but both are not necessary. In fact, while preference is given to a Method reference if available, an Exception will be thrown if a non-matching 'methodName' has also been provided. Therefore, to avoid such ambiguity, it is recommended to provide just one or the other.

This handler also accepts an implementation of the MessageMapper strategy interface which it uses for converting from the Message being handled to an Object prior to invoking the method. Likewise, if the method has a non-null return value, a reply message will be generated by the configured implementation of the MessageCreator strategy interface. In both cases, the default implementations will simply consider the message's payload.

Author:
Mark Fisher

Field Summary
private  java.lang.Object initializationMonitor
           
private  boolean initialized
           
protected  MethodInvoker invoker
           
protected  org.apache.commons.logging.Log logger
           
private  MessageCreator messageCreator
           
private  MessageMapper messageMapper
           
private  java.lang.reflect.Method method
           
private  boolean methodExpectsMessage
           
private  java.lang.String methodName
           
private  java.lang.Object object
           
static java.lang.String OUTPUT_CHANNEL_NAME_KEY
           
 
Constructor Summary
AbstractMessageHandlerAdapter()
           
 
Method Summary
 void afterPropertiesSet()
           
protected  Message<?> createReplyMessage(java.lang.Object returnValue, Message<?> originalMessage)
           
protected  java.lang.reflect.Method getMethod()
           
protected  java.lang.Object getObject()
           
 Message<?> handle(Message<?> message)
           
protected abstract  Message<?> handleReturnValue(java.lang.Object returnValue, Message<?> originalMessage)
          Subclasses must implement this method to handle the return value.
protected  void initialize()
          Subclasses may override this method for custom initialization requirements.
 void setMessageCreator(MessageCreator messageCreator)
           
 void setMessageMapper(MessageMapper messageMapper)
           
 void setMethod(java.lang.reflect.Method method)
           
 void setMethodExpectsMessage(boolean methodExpectsMessage)
           
 void setMethodName(java.lang.String methodName)
           
 void setObject(java.lang.Object object)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OUTPUT_CHANNEL_NAME_KEY

public static final java.lang.String OUTPUT_CHANNEL_NAME_KEY
See Also:
Constant Field Values

logger

protected final org.apache.commons.logging.Log logger

object

private volatile java.lang.Object object

method

private volatile java.lang.reflect.Method method

methodName

private volatile java.lang.String methodName

methodExpectsMessage

private volatile boolean methodExpectsMessage

messageMapper

private volatile MessageMapper messageMapper

messageCreator

private volatile MessageCreator messageCreator

invoker

protected volatile MethodInvoker invoker

initialized

private volatile boolean initialized

initializationMonitor

private final java.lang.Object initializationMonitor
Constructor Detail

AbstractMessageHandlerAdapter

public AbstractMessageHandlerAdapter()
Method Detail

setObject

public void setObject(java.lang.Object object)

getObject

protected java.lang.Object getObject()

setMethod

public void setMethod(java.lang.reflect.Method method)

getMethod

protected java.lang.reflect.Method getMethod()

setMethodName

public void setMethodName(java.lang.String methodName)

setMethodExpectsMessage

public void setMethodExpectsMessage(boolean methodExpectsMessage)

setMessageMapper

public void setMessageMapper(MessageMapper messageMapper)

setMessageCreator

public void setMessageCreator(MessageCreator messageCreator)

afterPropertiesSet

public void afterPropertiesSet()
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean

initialize

protected void initialize()
Subclasses may override this method for custom initialization requirements.


handle

public Message<?> handle(Message<?> message)
Specified by:
handle in interface MessageHandler

createReplyMessage

protected Message<?> createReplyMessage(java.lang.Object returnValue,
                                        Message<?> originalMessage)

handleReturnValue

protected abstract Message<?> handleReturnValue(java.lang.Object returnValue,
                                                Message<?> originalMessage)
Subclasses must implement this method to handle the return value.