Skip to content

Commit c437a0d

Browse files
committed
Declare default methods for supportsSourceType and getOrder
Issue: SPR-17163
1 parent 309ffc6 commit c437a0d

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,24 +24,40 @@
2424

2525
/**
2626
* Extended variant of the standard {@link ApplicationListener} interface,
27-
* exposing further metadata such as the supported event type.
27+
* exposing further metadata such as the supported event and source type.
2828
*
29-
* <p>As of Spring Framework 4.2, supersedes {@link SmartApplicationListener} with
30-
* proper handling of generics-based event.
29+
* <p>As of Spring Framework 4.2, this interface supersedes the Class-based
30+
* {@link SmartApplicationListener} with full handling of generic event types.
3131
*
3232
* @author Stephane Nicoll
3333
* @since 4.2
34+
* @see SmartApplicationListener
35+
* @see GenericApplicationListenerAdapter
3436
*/
3537
public interface GenericApplicationListener extends ApplicationListener<ApplicationEvent>, Ordered {
3638

3739
/**
3840
* Determine whether this listener actually supports the given event type.
41+
* @param eventType the event type (never {@code null})
3942
*/
4043
boolean supportsEventType(ResolvableType eventType);
4144

4245
/**
4346
* Determine whether this listener actually supports the given source type.
47+
* <p>The default implementation always returns {@code true}.
48+
* @param sourceType the source type, or {@code null} if no source
4449
*/
45-
boolean supportsSourceType(@Nullable Class<?> sourceType);
50+
default boolean supportsSourceType(@Nullable Class<?> sourceType) {
51+
return true;
52+
}
53+
54+
/**
55+
* Determine this listener's order in a set of listeners for the same event.
56+
* <p>The default implementation returns {@link #LOWEST_PRECEDENCE}.
57+
*/
58+
@Override
59+
default int getOrder() {
60+
return LOWEST_PRECEDENCE;
61+
}
4662

4763
}

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,40 @@
2323

2424
/**
2525
* Extended variant of the standard {@link ApplicationListener} interface,
26-
* exposing further metadata such as the supported event type.
26+
* exposing further metadata such as the supported event and source type.
2727
*
28-
* <p>Users are <b>strongly advised</b> to use the {@link GenericApplicationListener}
29-
* interface instead as it provides an improved detection of generics-based
30-
* event types.
28+
* <p>For full introspection of generic event types, consider implementing
29+
* the {@link GenericApplicationListener} interface instead.
3130
*
3231
* @author Juergen Hoeller
3332
* @since 3.0
3433
* @see GenericApplicationListener
34+
* @see GenericApplicationListenerAdapter
3535
*/
3636
public interface SmartApplicationListener extends ApplicationListener<ApplicationEvent>, Ordered {
3737

3838
/**
3939
* Determine whether this listener actually supports the given event type.
40+
* @param eventType the event type (never {@code null})
4041
*/
4142
boolean supportsEventType(Class<? extends ApplicationEvent> eventType);
4243

4344
/**
4445
* Determine whether this listener actually supports the given source type.
46+
* <p>The default implementation always returns {@code true}.
47+
* @param sourceType the source type, or {@code null} if no source
4548
*/
46-
boolean supportsSourceType(@Nullable Class<?> sourceType);
49+
default boolean supportsSourceType(@Nullable Class<?> sourceType) {
50+
return true;
51+
}
52+
53+
/**
54+
* Determine this listener's order in a set of listeners for the same event.
55+
* <p>The default implementation returns {@link #LOWEST_PRECEDENCE}.
56+
*/
57+
@Override
58+
default int getOrder() {
59+
return LOWEST_PRECEDENCE;
60+
}
4761

4862
}

0 commit comments

Comments
 (0)