01: package org.jasig.portal.events.handlers;
02:
03: import org.apache.commons.logging.Log;
04: import org.apache.commons.logging.LogFactory;
05: import org.jasig.portal.events.EventHandler;
06: import org.jasig.portal.events.PortalEvent;
07: import org.springframework.beans.factory.InitializingBean;
08:
09: /**
10: * Abstract implemenation that allows for one EventHandler to handle many events
11: * configurably without being defined multiple times.
12: * <p>
13: * Takes an array of Class objects and compares them to the current event by
14: * doing an isAssignableFrom check (rather than a strict equals comparison).
15: *
16: * @author Scott Battaglia
17: * @version $Revision: 42356 $ $Date: 2007-08-18 10:46:00 -0700 (Sat, 18 Aug 2007) $
18: * @since 2.6
19: *
20: */
21: public abstract class AbstractLimitedSupportEventHandler implements
22: EventHandler, InitializingBean {
23:
24: /** Protected logging instance. */
25: protected Log log = LogFactory.getLog(this .getClass());
26:
27: /** The default supported class of PortalEvent. */
28: private final Class[] DEFAULT_SUPPORTED_EVENTS = new Class[] { PortalEvent.class };
29:
30: /** The list of supported classes. */
31: private Class[] supportedEvents;
32:
33: public final boolean supports(final PortalEvent event) {
34: for (int i = 0; i < supportedEvents.length; i++) {
35: final Class supportedEvent = supportedEvents[i];
36: if (supportedEvent.isAssignableFrom(event.getClass())) {
37: return true;
38: }
39: }
40: return false;
41: }
42:
43: public final void afterPropertiesSet() throws Exception {
44: if (supportedEvents == null) {
45: log
46: .info("No supported events set. Using default of all PortalEvents.");
47: this .supportedEvents = DEFAULT_SUPPORTED_EVENTS;
48: }
49:
50: afterPropertiesSetInternal();
51: }
52:
53: protected void afterPropertiesSetInternal() throws Exception {
54: }
55:
56: public void setSupportedEvents(final Class[] supportedEvents) {
57: this.supportedEvents = supportedEvents;
58: }
59:
60: }
|