Webwarp Util Event


The package provides a simple implementation for the GoF Observer Pattern. Note that Spring itself provides a solution with  Spring Managed Beans; see http://static.springframework.org/spring/docs/2.0.x/reference/beans.html#context-functionality-events.

Class Overview

Example Usage

Implementing a provider

Any arbitrary class can implement a event provider, e.g. by instantiating a ProviderListenerSupporterImpl instance variable. Then the implementation of the ProviderListenerSupporter interface is simple: public class MyEventSource extends SomeArbitraryBaseClassOrObject implements ProviderListenerSupporter{ private ProviderListenerSupporter pls = new ProviderListenerSupporterImpl(); [...] public void insertItem(Object item){ pls.notifyPreAction(new ProviderEvent(null, null, ProviderEvent.INSERT_EVENT)); [...] // do insert pls.notifyPostAction(new ProviderEvent(null, null, ProviderEvent.INSERT_EVENT)); } }

Implementing and registering a listener

MyEventSource supporterImpl = new MyEventSource(); ProviderListener l = new ProviderListener(){ public void postAction(ProviderEvent event) { // do somehting useful } public void preAction(ProviderEvent event) { // do somehting useful } } supporterImpl.addProviderListener(l);

Webwarp Util