01: package org.jasig.portal.events;
02:
03: import org.springframework.beans.factory.InitializingBean;
04: import org.springframework.context.ApplicationEvent;
05: import org.springframework.context.ApplicationListener;
06: import org.springframework.util.Assert;
07:
08: public abstract class AbstractEventListener implements
09: ApplicationListener, InitializingBean {
10:
11: private EventHandler[] handlers;
12:
13: public final void onApplicationEvent(ApplicationEvent event) {
14: if (!PortalEvent.class.isAssignableFrom(event.getClass())) {
15: return;
16: }
17:
18: final PortalEvent portalEvent = (PortalEvent) event;
19:
20: for (int i = 0; i < handlers.length; i++) {
21: final EventHandler current = handlers[i];
22:
23: if (current.supports(portalEvent)) {
24: onApplicationEventInternal(portalEvent, current);
25: }
26: }
27: }
28:
29: protected abstract void onApplicationEventInternal(
30: PortalEvent event, EventHandler handler);
31:
32: protected void afterPropertiesSetInternal() throws Exception {
33: };
34:
35: public final void setEventHandlers(final EventHandler[] handlers) {
36: this .handlers = handlers;
37: }
38:
39: public final void afterPropertiesSet() throws Exception {
40: Assert
41: .notEmpty(this .handlers,
42: "handlers array cannot be empty");
43: afterPropertiesSetInternal();
44: }
45: }
|