Package org.springframework.context.event

# Class ApplicationListenerMethodAdapter

java.lang.Object
org.springframework.context.event.ApplicationListenerMethodAdapter

All Implemented Interfaces:
  `EventListener`, `ApplicationListener<ApplicationEvent>`, `GenericApplicationListener`, `SmartApplicationListener`, `org.springframework.core.Ordered`

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 subclasses a chance to deviate from the default. Unwraps the content of a `PayloadApplicationEvent` if necessary to allow a 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, Sebastien Deleuze, Yanming Zhou

## Field Summary

Fields
Modifier and Type
Field
Description
`protected final org.apache.commons.logging.Log`
`logger`

### Fields inherited from interface org.springframework.core.Ordered

`HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE`

## Constructor Summary

Constructors
Constructor
Description
`ApplicationListenerMethodAdapter(String beanName, Class<?> targetClass, Method method)`
Construct a new ApplicationListenerMethodAdapter.

## Method Summary

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`
`getDefaultListenerId()`
Determine the default id for the target listener, to be applied in case of no `annotation-specified id value`.
`protected String`
`getDetailedErrorMessage(Object bean, String message)`
Add additional details such as the bean type and method signature to the given error message.
`String`
`getListenerId()`
Return an optional identifier for the listener.
`int`
`getOrder()`
Determine this listener's order in a set of listeners for the same event.
`protected Object`
`getTargetBean()`
Return the target bean instance to use.
`protected Method`
`getTargetMethod()`
Return the target listener method.
`protected void`
`handleAsyncError(Throwable t)`
`protected void`
`handleResult(Object result)`
`protected boolean`
`isDefaultExecution()`
Return whether default execution is applicable for the target listener.
`void`
`onApplicationEvent(ApplicationEvent event)`
Handle an application event.
`void`
`processEvent(ApplicationEvent event)`
Process the specified `ApplicationEvent`, checking if the condition matches and handling a non-null result, if any.
`protected Object[]`
`resolveArguments(ApplicationEvent event)`
Resolve the method arguments to use for the specified `ApplicationEvent`.
`boolean`
`shouldHandle(ApplicationEvent event)`
Determine whether the listener method would actually handle the given event, checking if the condition matches.
`boolean`
`supportsEventType(org.springframework.core.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()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.springframework.context.ApplicationListener

`supportsAsyncExecution`

### Methods inherited from interface org.springframework.context.event.GenericApplicationListener

`supportsEventType`

## Field Details

### logger

protected final org.apache.commons.logging.Log logger

## Constructor Details

### ApplicationListenerMethodAdapter

public ApplicationListenerMethodAdapter(String beanName, Class<?> targetClass, Method method)
Construct a new ApplicationListenerMethodAdapter.

Parameters:
  `beanName` - the name of the bean to invoke the listener method on
  `targetClass` - the target class that the method is declared on
  `method` - the listener method to invoke

## Method Details

### onApplicationEvent

public void onApplicationEvent(ApplicationEvent event)
Description copied from interface: `ApplicationListener`
Handle an application event.

Specified by:
  `onApplicationEvent` in interface `ApplicationListener<ApplicationEvent>`
Parameters:
  `event` - the event to respond to

### supportsEventType

public boolean supportsEventType(org.springframework.core.ResolvableType eventType)
Description copied from interface: `GenericApplicationListener`
Determine whether this listener actually supports the given event type.

Specified by:
  `supportsEventType` in interface `GenericApplicationListener`
Parameters:
  `eventType` - the event type (never `null`)

### supportsSourceType

public boolean supportsSourceType(@Nullable Class<?> sourceType)
Description copied from interface: `SmartApplicationListener`
Determine whether this listener actually supports the given source type.

The default implementation always returns `true`.

Specified by:
  `supportsSourceType` in interface `SmartApplicationListener`
Parameters:
  `sourceType` - the source type, or `null` if no source

### getOrder

public int getOrder()
Description copied from interface: `SmartApplicationListener`
Determine this listener's order in a set of listeners for the same event.

The default implementation returns `Ordered.LOWEST_PRECEDENCE`.

Specified by:
  `getOrder` in interface `org.springframework.core.Ordered`
Specified by:
  `getOrder` in interface `SmartApplicationListener`

### getListenerId

public String getListenerId()
Description copied from interface: `SmartApplicationListener`
Return an optional identifier for the listener.

The default value is an empty String.

Specified by:
  `getListenerId` in interface `SmartApplicationListener`
See Also:
  - `EventListener.id()`
  - `ApplicationEventMulticaster.removeApplicationListeners(java.util.function.Predicate<org.springframework.context.ApplicationListener<?>>)`

### getDefaultListenerId

protected String getDefaultListenerId()
Determine the default id for the target listener, to be applied in case of no `annotation-specified id value`.

The default implementation builds a method name with parameter types.

Since:
  5.3.5
See Also:
  - `getListenerId()`

### isDefaultExecution

protected boolean isDefaultExecution()
Return whether default execution is applicable for the target listener.

Since:
  6.2
See Also:
  - `onApplicationEvent(org.springframework.context.ApplicationEvent)`
  - `EventListener.defaultExecution()`

### processEvent

public void processEvent(ApplicationEvent event)
Process the specified `ApplicationEvent`, checking if the condition matches and handling a non-null result, if any.

Parameters:
  `event` - the event to process through the listener method

### shouldHandle

public boolean shouldHandle(ApplicationEvent event)
Determine whether the listener method would actually handle the given event, checking if the condition matches.

Parameters:
  `event` - the event to process through the listener method
Since:
  6.1

### resolveArguments

@Nullable protected Object[] resolveArguments(ApplicationEvent event)
Resolve the method arguments to use for the specified `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.

### handleResult

protected void handleResult(Object result)

### handleAsyncError

protected void handleAsyncError(Throwable t)

### doInvoke

@Nullable protected Object doInvoke(@Nullable Object... args)
Invoke the event listener method with the given argument values.

### getTargetBean

protected Object getTargetBean()
Return the target bean instance to use.

### getTargetMethod

protected Method getTargetMethod()
Return the target listener method.

Since:
  5.3

### getCondition

@Nullable protected String getCondition()
Return the condition to use.

Matches the `condition` attribute of the `EventListener` annotation or any matching attribute on a composed annotation that is meta-annotated with `@EventListener`.

### getDetailedErrorMessage

protected String getDetailedErrorMessage(Object bean, @Nullable 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

### toString

public String toString()

Overrides:
  `toString` in class `Object`