org.axonframework.common.annotation
Class AbstractMessageHandler

java.lang.Object
  extended by org.axonframework.common.annotation.AbstractMessageHandler
All Implemented Interfaces:
Comparable<AbstractMessageHandler>
Direct Known Subclasses:
ConstructorCommandMessageHandler, MethodMessageHandler

public abstract class AbstractMessageHandler
extends Object
implements Comparable<AbstractMessageHandler>

Abstract superclass for annotation based Message handlers. Handlers can be compared with on another to decide upon their priority. Handlers that deal with unrelated payloads (i.e. have no parent-child relationship) are ordered based on their payload type's class name.

Handler invokers should always evaluate the first (smallest) suitable handler before evaluating the next.

Since:
2.0
Author:
Allard Buijze

Constructor Summary
protected AbstractMessageHandler(AbstractMessageHandler delegate)
          Constructor used for implementations that delegate activity to another handler.
protected AbstractMessageHandler(Class<?> payloadType, Class<?> declaringClass, ParameterResolver... parameterValueResolvers)
          Initializes the MessageHandler to handle messages with the given payloadType, declared in the given declaringClass and using the given parameterValueResolvers.
 
Method Summary
 int compareTo(AbstractMessageHandler o)
           
 boolean equals(Object obj)
           
protected static ParameterResolver[] findResolvers(ParameterResolverFactory parameterResolverFactory, Annotation[] memberAnnotations, Class<?>[] parameterTypes, Annotation[][] parameterAnnotations, boolean resolvePayload)
          Finds ParameterResolvers for the given Member details.
abstract
<T extends Annotation>
T
getAnnotation(Class<T> annotationType)
          Returns the member-level annotation of given annotationType, or null if no such annotation is present.
protected  ParameterResolver[] getParameterValueResolvers()
          Returns the parameter resolvers provided at construction time.
 Class getPayloadType()
          Returns the type of payload this handler expects.
 int hashCode()
           
abstract  Object invoke(Object target, Message message)
          Invokes this handler for the given target instance, using the given message as source object to provide parameter values.
 boolean matches(Message message)
          Indicates whether this Handler is suitable for the given message.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractMessageHandler

protected AbstractMessageHandler(Class<?> payloadType,
                                 Class<?> declaringClass,
                                 ParameterResolver... parameterValueResolvers)
Initializes the MessageHandler to handle messages with the given payloadType, declared in the given declaringClass and using the given parameterValueResolvers.

Parameters:
payloadType - The type of payload this handlers deals with
declaringClass - The class on which the handler is declared
parameterValueResolvers - The resolvers for each of the handlers' parameters

AbstractMessageHandler

protected AbstractMessageHandler(AbstractMessageHandler delegate)
Constructor used for implementations that delegate activity to another handler. Required information is gathered from the target handler.

Parameters:
delegate - The handler to which actual invocations are being forwarded
Method Detail

matches

public boolean matches(Message message)
Indicates whether this Handler is suitable for the given message.

Parameters:
message - The message to inspect
Returns:
true if this handler can handle the message, otherwise false.

invoke

public abstract Object invoke(Object target,
                              Message message)
                       throws InvocationTargetException,
                              IllegalAccessException
Invokes this handler for the given target instance, using the given message as source object to provide parameter values.

Parameters:
target - The target instance to invoke the Handler on.
message - The message providing parameter values
Returns:
The result of the handler invocation
Throws:
InvocationTargetException - when the handler throws a checked exception
IllegalAccessException - if the SecurityManager refuses the handler invocation

getPayloadType

public Class getPayloadType()
Returns the type of payload this handler expects.

Returns:
the type of payload this handler expects

compareTo

public int compareTo(AbstractMessageHandler o)
Specified by:
compareTo in interface Comparable<AbstractMessageHandler>

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

findResolvers

protected static ParameterResolver[] findResolvers(ParameterResolverFactory parameterResolverFactory,
                                                   Annotation[] memberAnnotations,
                                                   Class<?>[] parameterTypes,
                                                   Annotation[][] parameterAnnotations,
                                                   boolean resolvePayload)
Finds ParameterResolvers for the given Member details. The returning array contains as many elements as the given parameterTypes, where each ParameterResolver corresponds with the parameter type at the same location.

Parameters:
parameterResolverFactory - The factory to create the ParameterResolvers with
memberAnnotations - The annotations on the member (e.g. method)
parameterTypes - The parameter type of the member
parameterAnnotations - The annotations on each of the parameters
resolvePayload - Indicates whether the payload of the message should be resolved from the parameters
Returns:
the parameter resolvers for the given Member details
See Also:
Method, Constructor

getParameterValueResolvers

protected ParameterResolver[] getParameterValueResolvers()
Returns the parameter resolvers provided at construction time.

Returns:
the parameter resolvers provided at construction time

getAnnotation

public abstract <T extends Annotation> T getAnnotation(Class<T> annotationType)
Returns the member-level annotation of given annotationType, or null if no such annotation is present.

Type Parameters:
T - The type of annotation to retrieve
Parameters:
annotationType - The type of annotation to retrieve
Returns:
the annotation instance, or null if no such annotation is present.


Copyright © 2010-2016. All Rights Reserved.