Class ApplicationListenerMethodAdapter
- java.lang.Object
- org.springframework.context.event.ApplicationListenerMethodAdapter
- All Implemented Interfaces:
EventListener
,ApplicationListener<ApplicationEvent>
,GenericApplicationListener
,Ordered
public class ApplicationListenerMethodAdapter extends Object implements GenericApplicationListener
GenericApplicationListener
adapter that delegates the processing of an event to anEventListener
annotated method.Delegates to
processEvent(ApplicationEvent)
to give sub-classes a chance to deviate from the default. Unwraps the content of aPayloadApplicationEvent
if necessary to allow method declaration to define any arbitrary event type. If a condition is defined, it is evaluated prior to invoking the underlying method.- Since:
- 4.2
- Author:
- Stephane Nicoll, Juergen Hoeller, Sam Brannen
Field Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor Summary
Constructors Constructor Description ApplicationListenerMethodAdapter(String beanName, Class<?> targetClass, Method method)
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Object
doInvoke(Object... args)
Invoke the event listener method with the given argument values.protected String
getCondition()
Return the condition to use.protected String
getDetailedErrorMessage(Object bean, String message)
Add additional details such as the bean type and method signature to the given error message.int
getOrder()
Get the order value of this object.protected Object
getTargetBean()
Return the target bean instance to use.protected void
handleResult(Object result)
void
onApplicationEvent(ApplicationEvent event)
Handle an application event.void
processEvent(ApplicationEvent event)
Process the specifiedApplicationEvent
, checking if the condition match and handling non-null result, if any.protected Object[]
resolveArguments(ApplicationEvent event)
Resolve the method arguments to use for the specifiedApplicationEvent
.boolean
supportsEventType(ResolvableType eventType)
Determine whether this listener actually supports the given event type.boolean
supportsSourceType(Class<?> sourceType)
Determine whether this listener actually supports the given source type.String
toString()
Constructor Detail
ApplicationListenerMethodAdapter
public ApplicationListenerMethodAdapter(String beanName, Class<?> targetClass, Method method)
Method Detail
onApplicationEvent
public void onApplicationEvent(ApplicationEvent event)
Description copied from interface:ApplicationListener
Handle an application event.- Specified by:
onApplicationEvent
in interfaceApplicationListener<ApplicationEvent>
- Parameters:
event
- the event to respond to
supportsEventType
public boolean supportsEventType(ResolvableType eventType)
Description copied from interface:GenericApplicationListener
Determine whether this listener actually supports the given event type.- Specified by:
supportsEventType
in interfaceGenericApplicationListener
- Parameters:
eventType
- the event type (nevernull
)
supportsSourceType
public boolean supportsSourceType(Class<?> sourceType)
Description copied from interface:GenericApplicationListener
Determine whether this listener actually supports the given source type.- Specified by:
supportsSourceType
in interfaceGenericApplicationListener
- Parameters:
sourceType
- the source type, ornull
if no source
getOrder
public int getOrder()
Description copied from interface:Ordered
Get the order value of this object.Higher values are interpreted as lower priority. As a consequence, the object with the lowest value has the highest priority (somewhat analogous to Servlet
load-on-startup
values).Same order values will result in arbitrary sort positions for the affected objects.
- Specified by:
getOrder
in interfaceOrdered
- Returns:
- the order value
- See Also:
Ordered.HIGHEST_PRECEDENCE
,Ordered.LOWEST_PRECEDENCE
processEvent
public void processEvent(ApplicationEvent event)
Process the specifiedApplicationEvent
, checking if the condition match and handling non-null result, if any.
resolveArguments
protected Object[] resolveArguments(ApplicationEvent event)
Resolve the method arguments to use for the specifiedApplicationEvent
.These arguments will be used to invoke the method handled by this instance. Can return
null
to indicate that no suitable arguments could be resolved and therefore the method should not be invoked at all for the specified event.
handleResult
protected void handleResult(Object result)
doInvoke
protected Object doInvoke(Object... args)
Invoke the event listener method with the given argument values.
getTargetBean
protected Object getTargetBean()
Return the target bean instance to use.
getCondition
protected String getCondition()
Return the condition to use.Matches the
condition
attribute of theEventListener
annotation or any matching attribute on a composed annotation that is meta-annotated with@EventListener
.
getDetailedErrorMessage
protected String getDetailedErrorMessage(Object bean, String message)
Add additional details such as the bean type and method signature to the given error message.- Parameters:
message
- error message to append the HandlerMethod details to