public class ApplicationListenerMethodAdapter extends 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(String beanName,
Class<?> targetClass,
Method method) |
Modifier and Type | Method and 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.
|
protected EventListener |
getEventListener() |
protected <A extends Annotation> |
getMethodAnnotation(Class<A> annotationType) |
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 specified
ApplicationEvent , 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 specified
ApplicationEvent . |
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() |
protected final Log logger
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
public boolean supportsSourceType(Class<?> sourceType)
GenericApplicationListener
supportsSourceType
in interface GenericApplicationListener
public int getOrder()
Ordered
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.
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.protected 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(Object result)
protected Object doInvoke(Object... args)
protected Object getTargetBean()
protected <A extends Annotation> A getMethodAnnotation(Class<A> annotationType)
protected EventListener getEventListener()
protected 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 String getDetailedErrorMessage(Object bean, String message)
message
- error message to append the HandlerMethod details to