Polish Javadoc & TODOs in ApplicationListenerMethodAdapter
Issue: SPR-12738
This commit is contained in:
parent
8ece1b145c
commit
e0d2dbd21d
|
|
@ -45,13 +45,14 @@ import org.springframework.util.StringUtils;
|
||||||
* {@link GenericApplicationListener} adapter that delegates the processing of
|
* {@link GenericApplicationListener} adapter that delegates the processing of
|
||||||
* an event to an {@link EventListener} annotated method.
|
* an event to an {@link EventListener} annotated method.
|
||||||
*
|
*
|
||||||
* <p>Delegates to {@link #processEvent(ApplicationEvent)} to give a chance to
|
* <p>Delegates to {@link #processEvent(ApplicationEvent)} to give sub-classes
|
||||||
* sub-classes to deviate from the default. Unwraps the content of a
|
* a chance to deviate from the default. Unwraps the content of a
|
||||||
* {@link PayloadApplicationEvent} if necessary to allow method declaration
|
* {@link PayloadApplicationEvent} if necessary to allow method declaration
|
||||||
* to define any arbitrary event type. If a condition is defined, it is
|
* to define any arbitrary event type. If a condition is defined, it is
|
||||||
* evaluated prior to invoking the underlying method.
|
* evaluated prior to invoking the underlying method.
|
||||||
*
|
*
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
|
* @author Sam Brannen
|
||||||
* @since 4.2
|
* @since 4.2
|
||||||
*/
|
*/
|
||||||
public class ApplicationListenerMethodAdapter implements GenericApplicationListener {
|
public class ApplicationListenerMethodAdapter implements GenericApplicationListener {
|
||||||
|
|
@ -124,6 +125,7 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe
|
||||||
protected Object[] resolveArguments(ApplicationEvent event) {
|
protected Object[] resolveArguments(ApplicationEvent event) {
|
||||||
if (!ApplicationEvent.class.isAssignableFrom(this.declaredEventType.getRawClass())
|
if (!ApplicationEvent.class.isAssignableFrom(this.declaredEventType.getRawClass())
|
||||||
&& event instanceof PayloadApplicationEvent) {
|
&& event instanceof PayloadApplicationEvent) {
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
Object payload = ((PayloadApplicationEvent) event).getPayload();
|
Object payload = ((PayloadApplicationEvent) event).getPayload();
|
||||||
if (this.declaredEventType.isAssignableFrom(ResolvableType.forClass(payload.getClass()))) {
|
if (this.declaredEventType.isAssignableFrom(ResolvableType.forClass(payload.getClass()))) {
|
||||||
return new Object[] {payload};
|
return new Object[] {payload};
|
||||||
|
|
@ -240,20 +242,20 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the condition to use. Matches the {@code condition} attribute of the
|
* Return the condition to use.
|
||||||
* {@link EventListener} annotation or any matching attribute on a composed
|
* <p>Matches the {@code condition} attribute of the {@link EventListener}
|
||||||
* annotation.
|
* annotation or any matching attribute on a composed annotation that
|
||||||
|
* is meta-annotated with {@code @EventListener}.
|
||||||
*/
|
*/
|
||||||
protected String getCondition() {
|
protected String getCondition() {
|
||||||
if (this.condition == null) {
|
if (this.condition == null) {
|
||||||
// TODO annotationAttributes are null with proxy
|
|
||||||
AnnotationAttributes annotationAttributes = AnnotatedElementUtils
|
AnnotationAttributes annotationAttributes = AnnotatedElementUtils
|
||||||
.getAnnotationAttributes(this.method, EventListener.class.getName());
|
.getAnnotationAttributes(this.method, EventListener.class.getName());
|
||||||
if (annotationAttributes != null) {
|
if (annotationAttributes != null) {
|
||||||
String value = annotationAttributes.getString("condition");
|
String value = annotationAttributes.getString("condition");
|
||||||
this.condition = (value != null ? value : "");
|
this.condition = (value != null ? value : "");
|
||||||
}
|
}
|
||||||
// TODO Remove once AnnotatedElementUtils supports annotations on proxies
|
// TODO [SPR-12738] Remove once AnnotatedElementUtils finds annotated methods on interfaces (e.g., in dynamic proxies)
|
||||||
else {
|
else {
|
||||||
EventListener eventListener = getMethodAnnotation(EventListener.class);
|
EventListener eventListener = getMethodAnnotation(EventListener.class);
|
||||||
this.condition = (eventListener != null ? eventListener.condition() : "");
|
this.condition = (eventListener != null ? eventListener.condition() : "");
|
||||||
|
|
|
||||||
|
|
@ -335,7 +335,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"unused", "serial"})
|
@SuppressWarnings({ "serial" })
|
||||||
static class PayloadStringTestEvent extends PayloadTestEvent<Long, String> {
|
static class PayloadStringTestEvent extends PayloadTestEvent<Long, String> {
|
||||||
public PayloadStringTestEvent(Object source, String payload, Long something) {
|
public PayloadStringTestEvent(Object source, String payload, Long something) {
|
||||||
super(source, payload, something);
|
super(source, payload, something);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue