org.dellroad.stuff.vaadin
Class VaadinApplicationListener<E extends ApplicationEvent>

java.lang.Object
  extended by org.dellroad.stuff.vaadin.VaadinApplicationListener<E>
All Implemented Interfaces:
EventListener, ApplicationListener<ApplicationEvent>, SmartApplicationListener, Ordered

public abstract class VaadinApplicationListener<E extends ApplicationEvent>
extends Object
implements SmartApplicationListener

A Spring ApplicationListener support superclass customized for use by listeners that are part of a Vaadin application when listening to non-Vaadin application event sources.

Listeners that are part of a Vaadin application should use this superclass if they are going to be registered with non-Vaadin event sources. This will ensure that events are delivered in the proper Vaadin application context.

Note: to avoid memory leaks, listeners must be explicitly unregistered when the associated Vaadin application closes. This can be done by explicitly registering for an application close notification in which the listener is unregistered, or by unregistering the listener in the Spring destroy-method associated with a bean that has scope="vaadinApplication" or lives in a SpringContextApplication application context (so that the bean's destroy method will be invoked when the Vaadin application closes).

Note: when listening to event sources that are scoped to specific Vaadin application instances and originate events within the proper Vaadin application context, then the use of this listener superclass is not necessary.

See Also:
ContextApplication.invoke(java.lang.Runnable), VaadinApplicationScope, SpringContextApplication

Field Summary
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
VaadinApplicationListener(Class<E> eventType)
          Convenience constructor.
VaadinApplicationListener(Class<E> eventType, ContextApplication application)
          Primary constructor.
 
Method Summary
 ContextApplication getApplication()
           
 Class<E> getEventType()
           
 int getOrder()
          Get ordering value.
 void onApplicationEvent(ApplicationEvent event)
           
protected abstract  void onApplicationEventInternal(E event)
          Handle a listener event within the context of the ContextApplication with which this listener is associated.
 boolean supportsEventType(Class<? extends ApplicationEvent> 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VaadinApplicationListener

public VaadinApplicationListener(Class<E> eventType)
Convenience constructor. Equivalent to:
VaadinApplicationListener(eventType, ContextApplication.get())

Throws:
IllegalArgumentException - if eventType is null
IllegalStateException - if there is no ContextApplication associated with the current thread

VaadinApplicationListener

public VaadinApplicationListener(Class<E> eventType,
                                 ContextApplication application)
Primary constructor.

Parameters:
eventType - type of events this instance should receive (others will be ignored)
application - the associated Vaadin application
Throws:
IllegalArgumentException - if either parameter is null
Method Detail

getEventType

public final Class<E> getEventType()

getApplication

public final ContextApplication getApplication()

onApplicationEvent

public final void onApplicationEvent(ApplicationEvent event)
Specified by:
onApplicationEvent in interface ApplicationListener<ApplicationEvent>

onApplicationEventInternal

protected abstract void onApplicationEventInternal(E event)
Handle a listener event within the context of the ContextApplication with which this listener is associated. The current ContextApplication is also available via ContextApplication.get().

See Also:
ContextApplication.get()

supportsEventType

public boolean supportsEventType(Class<? extends ApplicationEvent> eventType)
Determine whether this listener actually supports the given event type.

The implementation in VaadinApplicationListener tests whether eventType is assignable to the type given in the constructor. Subclasses may override as desired.

Specified by:
supportsEventType in interface SmartApplicationListener

supportsSourceType

public boolean supportsSourceType(Class<?> sourceType)
Determine whether this listener actually supports the given source type.

The implementation in VaadinApplicationListener always returns true. Subclasses may override as desired.

Specified by:
supportsSourceType in interface SmartApplicationListener

getOrder

public int getOrder()
Get ordering value.

The implementation in VaadinApplicationListener always returns zero. Subclasses may override as desired.

Specified by:
getOrder in interface Ordered