public class ApplicationListenerMethodAdapter extends java.lang.Object implements GenericApplicationListener
GenericApplicationListener
adapter that delegates the processing of
an event to an EventListener
annotated method.
Delegates to processEvent(ApplicationEvent)
to give sub-classes
a chance to deviate from the default. Unwraps the content of a
PayloadApplicationEvent
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.
Modifier and Type | Field and Description |
---|---|
protected Log |
logger |
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
ApplicationListenerMethodAdapter(java.lang.String beanName,
java.lang.Class<?> targetClass,
java.lang.reflect.Method method) |
Modifier and Type | Method and Description |
---|---|
protected java.lang.Object |
doInvoke(java.lang.Object... args)
Invoke the event listener method with the given argument values.
|
protected java.lang.String |
getCondition()
Return the condition to use.
|
protected java.lang.String |
getDetailedErrorMessage(java.lang.Object bean,
java.lang.String message)
Add additional details such as the bean type and method signature to
the given error message.
|
int |
getOrder()
Determine this listener's order in a set of listeners for the same event.
|
protected java.lang.Object |
getTargetBean()
Return the target bean instance to use.
|
protected void |
handleResult(java.lang.Object result) |
void |
onApplicationEvent(ApplicationEvent event)
Handle an application event.
|
void |
processEvent(ApplicationEvent event)
Process the specified
ApplicationEvent , checking if the condition
match and handling non-null result, if any. |
protected java.lang.Object[] |
resolveArguments(ApplicationEvent event)
Resolve the method arguments to use for the specified
ApplicationEvent . |
boolean |
supportsEventType(ResolvableType eventType)
Determine whether this listener actually supports the given event type.
|
boolean |
supportsSourceType(java.lang.Class<?> sourceType)
Determine whether this listener actually supports the given source type.
|
java.lang.String |
toString() |
protected final Log logger
public ApplicationListenerMethodAdapter(java.lang.String beanName, java.lang.Class<?> targetClass, java.lang.reflect.Method method)
public void onApplicationEvent(ApplicationEvent event)
ApplicationListener
onApplicationEvent
in interface ApplicationListener<ApplicationEvent>
event
- the event to respond topublic boolean supportsEventType(ResolvableType eventType)
GenericApplicationListener
supportsEventType
in interface GenericApplicationListener
eventType
- the event type (never null
)public boolean supportsSourceType(@Nullable java.lang.Class<?> sourceType)
GenericApplicationListener
The default implementation always returns true
.
supportsSourceType
in interface GenericApplicationListener
sourceType
- the source type, or null
if no sourcepublic int getOrder()
GenericApplicationListener
The default implementation returns Ordered.LOWEST_PRECEDENCE
.
getOrder
in interface GenericApplicationListener
getOrder
in interface Ordered
Ordered.HIGHEST_PRECEDENCE
,
Ordered.LOWEST_PRECEDENCE
public void processEvent(ApplicationEvent event)
ApplicationEvent
, checking if the condition
match and handling non-null result, if any.@Nullable protected java.lang.Object[] resolveArguments(ApplicationEvent event)
ApplicationEvent
.
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.
protected void handleResult(java.lang.Object result)
@Nullable protected java.lang.Object doInvoke(java.lang.Object... args)
protected java.lang.Object getTargetBean()
@Nullable protected java.lang.String getCondition()
Matches the condition
attribute of the EventListener
annotation or any matching attribute on a composed annotation that
is meta-annotated with @EventListener
.
protected java.lang.String getDetailedErrorMessage(java.lang.Object bean, java.lang.String message)
message
- error message to append the HandlerMethod details topublic java.lang.String toString()
toString
in class java.lang.Object