Browse Source

Declare default methods for supportsSourceType and getOrder

Issue: SPR-17163
pull/1925/head
Juergen Hoeller 6 years ago
parent
commit
c437a0d1c3
  1. 26
      spring-context/src/main/java/org/springframework/context/event/GenericApplicationListener.java
  2. 24
      spring-context/src/main/java/org/springframework/context/event/SmartApplicationListener.java

26
spring-context/src/main/java/org/springframework/context/event/GenericApplicationListener.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,24 +24,40 @@ import org.springframework.lang.Nullable;
/** /**
* Extended variant of the standard {@link ApplicationListener} interface, * Extended variant of the standard {@link ApplicationListener} interface,
* exposing further metadata such as the supported event type. * exposing further metadata such as the supported event and source type.
* *
* <p>As of Spring Framework 4.2, supersedes {@link SmartApplicationListener} with * <p>As of Spring Framework 4.2, this interface supersedes the Class-based
* proper handling of generics-based event. * {@link SmartApplicationListener} with full handling of generic event types.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @since 4.2 * @since 4.2
* @see SmartApplicationListener
* @see GenericApplicationListenerAdapter
*/ */
public interface GenericApplicationListener extends ApplicationListener<ApplicationEvent>, Ordered { public interface GenericApplicationListener extends ApplicationListener<ApplicationEvent>, Ordered {
/** /**
* Determine whether this listener actually supports the given event type. * Determine whether this listener actually supports the given event type.
* @param eventType the event type (never {@code null})
*/ */
boolean supportsEventType(ResolvableType eventType); boolean supportsEventType(ResolvableType eventType);
/** /**
* Determine whether this listener actually supports the given source type. * Determine whether this listener actually supports the given source type.
* <p>The default implementation always returns {@code true}.
* @param sourceType the source type, or {@code null} if no source
*/ */
boolean supportsSourceType(@Nullable Class<?> sourceType); default boolean supportsSourceType(@Nullable Class<?> sourceType) {
return true;
}
/**
* Determine this listener's order in a set of listeners for the same event.
* <p>The default implementation returns {@link #LOWEST_PRECEDENCE}.
*/
@Override
default int getOrder() {
return LOWEST_PRECEDENCE;
}
} }

24
spring-context/src/main/java/org/springframework/context/event/SmartApplicationListener.java

@ -23,26 +23,40 @@ import org.springframework.lang.Nullable;
/** /**
* Extended variant of the standard {@link ApplicationListener} interface, * Extended variant of the standard {@link ApplicationListener} interface,
* exposing further metadata such as the supported event type. * exposing further metadata such as the supported event and source type.
* *
* <p>Users are <b>strongly advised</b> to use the {@link GenericApplicationListener} * <p>For full introspection of generic event types, consider implementing
* interface instead as it provides an improved detection of generics-based * the {@link GenericApplicationListener} interface instead.
* event types.
* *
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 3.0 * @since 3.0
* @see GenericApplicationListener * @see GenericApplicationListener
* @see GenericApplicationListenerAdapter
*/ */
public interface SmartApplicationListener extends ApplicationListener<ApplicationEvent>, Ordered { public interface SmartApplicationListener extends ApplicationListener<ApplicationEvent>, Ordered {
/** /**
* Determine whether this listener actually supports the given event type. * Determine whether this listener actually supports the given event type.
* @param eventType the event type (never {@code null})
*/ */
boolean supportsEventType(Class<? extends ApplicationEvent> eventType); boolean supportsEventType(Class<? extends ApplicationEvent> eventType);
/** /**
* Determine whether this listener actually supports the given source type. * Determine whether this listener actually supports the given source type.
* <p>The default implementation always returns {@code true}.
* @param sourceType the source type, or {@code null} if no source
*/ */
boolean supportsSourceType(@Nullable Class<?> sourceType); default boolean supportsSourceType(@Nullable Class<?> sourceType) {
return true;
}
/**
* Determine this listener's order in a set of listeners for the same event.
* <p>The default implementation returns {@link #LOWEST_PRECEDENCE}.
*/
@Override
default int getOrder() {
return LOWEST_PRECEDENCE;
}
} }

Loading…
Cancel
Save