diff --git a/src/Spring/Spring.Messaging/Messaging/Listener/MessageListenerAdapter.cs b/src/Spring/Spring.Messaging/Messaging/Listener/MessageListenerAdapter.cs index 6c00916f..d1237537 100644 --- a/src/Spring/Spring.Messaging/Messaging/Listener/MessageListenerAdapter.cs +++ b/src/Spring/Spring.Messaging/Messaging/Listener/MessageListenerAdapter.cs @@ -118,6 +118,8 @@ namespace Spring.Messaging.Listener #endregion + #region Fields + private IApplicationContext applicationContext; private object handlerObject; @@ -134,19 +136,31 @@ namespace Spring.Messaging.Listener private IMessageQueueFactory messageQueueFactory; + #endregion + #region Constructors + + /// + /// Initializes a new instance of the class. + /// public MessageListenerAdapter() { + InitDefaultStrategies(); handlerObject = this; - processingExpression = Expression.Parse(defaultHandlerMethod + "(#convertedObject)"); - messageQueueTemplate = new MessageQueueTemplate(); } + /// + /// Initializes a new instance of the class. + /// + /// The handler object. public MessageListenerAdapter(object handlerObject) { + InitDefaultStrategies(); this.handlerObject = handlerObject; } + #endregion + public object HandlerObject { get { return handlerObject; } @@ -156,11 +170,40 @@ namespace Spring.Messaging.Listener public string DefaultHandlerMethod { get { return defaultHandlerMethod; } - set { defaultHandlerMethod = value; } + set { + defaultHandlerMethod = value; + processingExpression = Expression.Parse(defaultHandlerMethod + "(#convertedObject)"); + } } #region IInitializingObject Members + /// + /// Invoked by an + /// after it has injected all of an object's dependencies. + /// + /// + ///

+ /// This method allows the object instance to perform the kind of + /// initialization only possible when all of it's dependencies have + /// been injected (set), and to throw an appropriate exception in the + /// event of misconfiguration. + ///

+ ///

+ /// Please do consult the class level documentation for the + /// interface for a + /// description of exactly when this method is invoked. In + /// particular, it is worth noting that the + /// + /// and + /// callbacks will have been invoked prior to this method being + /// called. + ///

+ ///
+ /// + /// In the event of misconfiguration (such as the failure to set a + /// required property) or if initialization fails. + /// public void AfterPropertiesSet() { if (messageQueueFactory == null) @@ -276,14 +319,12 @@ namespace Spring.Messaging.Listener } } - - protected virtual string GetHandlerMethodName(Message originalMessage, object extractedMessage) - { - return DefaultHandlerMethod; - } - #region IMessageListener Members + /// + /// Called when message is received. + /// + /// The message. public virtual void OnMessage(Message message) { object convertedMessage = ExtractMessage(message); @@ -291,11 +332,6 @@ namespace Spring.Messaging.Listener IDictionary vars = new Hashtable(); vars["convertedObject"] = convertedMessage; - //Need to parse each time since have overloaded methods and - //expression processor caches target of first invocation. - //TODO - use regular reflection. - processingExpression = Expression.Parse(defaultHandlerMethod + "(#convertedObject)"); - //Invoke message handler method and get result. object result = processingExpression.GetValue(handlerObject, vars); if (result != null) @@ -310,6 +346,26 @@ namespace Spring.Messaging.Listener #endregion + /// + /// Gets the name of the handler method. + /// + /// The original message. + /// The extracted message. + /// The name of the handler method. + protected virtual string GetHandlerMethodName(Message originalMessage, object extractedMessage) + { + return DefaultHandlerMethod; + } + + /// + /// Initialize the default implementations for the adapter's strategies. + /// + protected virtual void InitDefaultStrategies() + { + processingExpression = Expression.Parse(defaultHandlerMethod + "(#convertedObject)"); + messageQueueTemplate = new MessageQueueTemplate(); + } + protected virtual object ExtractMessage(Message message) { IMessageConverter converter = MessageConverter;