cziegeler 2003/05/07 02:06:51
Modified: src/blocks/portal/java/org/apache/cocoon/portal/event/impl DefaultEventManager.java Log: Fixing issues with JDK 1.3 - strange! Revision Changes Path 1.2 +46 -54 cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/event/impl/DefaultEventManager.java Index: DefaultEventManager.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/event/impl/DefaultEventManager.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- DefaultEventManager.java 7 May 2003 06:22:23 -0000 1.1 +++ DefaultEventManager.java 7 May 2003 09:06:51 -0000 1.2 @@ -94,12 +94,11 @@ Initializable, ThreadSafe, Configurable, - Disposable { + Disposable, + Publisher, Register { private final String rootEventType = Event.class.getName(); private Class eventClass; - private Publisher publisher = new DefaultPublisher(); - private Register register = new DefaultRegister(); private List subscribers = new ArrayList(); private ComponentManager manager; private Configuration configuration; @@ -109,11 +108,11 @@ protected ComponentSelector aspectSelector; public Publisher getPublisher() { - return this.publisher; + return this; } public Register getRegister() { - return this.register; + return this; } /* (non-Javadoc) @@ -146,68 +145,61 @@ } // FIXME (CZ,HIGH) : Make this configurable - this.register.subscribe(new DefaultLayoutEventSubscriber(this.manager)); - this.register.subscribe(new SizingEventSubscriber(this.manager)); + this.subscribe(new DefaultLayoutEventSubscriber(this.manager)); + this.subscribe(new SizingEventSubscriber(this.manager)); } - class DefaultPublisher implements Publisher { + public void publish( final Event event ) { - public void publish( final Event event ) { - - if ( getLogger().isDebugEnabled() ) { - getLogger().debug("Publishing event " + event.getClass()); - } - for ( Iterator e = subscribers.iterator(); e.hasNext(); ){ - Subscriber subscriber = (Subscriber)e.next(); - if (subscriber.getEventType().isAssignableFrom(event.getClass()) - && (subscriber.getFilter() == null || subscriber.getFilter().filter(event))) { - if ( getLogger().isDebugEnabled() ) { - getLogger().info("Informing subscriber "+subscriber+" of event "+event.getClass()); - } - subscriber.inform(event); + if ( getLogger().isDebugEnabled() ) { + getLogger().debug("Publishing event " + event.getClass()); + } + for ( Iterator e = subscribers.iterator(); e.hasNext(); ){ + Subscriber subscriber = (Subscriber)e.next(); + if (subscriber.getEventType().isAssignableFrom(event.getClass()) + && (subscriber.getFilter() == null || subscriber.getFilter().filter(event))) { + if ( getLogger().isDebugEnabled() ) { + getLogger().info("Informing subscriber "+subscriber+" of event "+event.getClass()); } + subscriber.inform(event); } } - } + + public void subscribe( final Subscriber subscriber ) + throws InvalidEventTypeException { + if ( !eventClass.isAssignableFrom( subscriber.getEventType() ) ) { + throw new InvalidEventTypeException(); + } - class DefaultRegister implements Register { + if ( getLogger().isDebugEnabled() ) { + getLogger().debug( "Subscribing event " + subscriber.getEventType().getName() ); + } - public void subscribe( final Subscriber subscriber ) - throws InvalidEventTypeException { - if ( !eventClass.isAssignableFrom( subscriber.getEventType() ) ) { - throw new InvalidEventTypeException(); - } - + // Add to list but prevent duplicate subscriptions + if ( !subscribers.contains( subscriber ) ) { + subscribers.add( subscriber ); if ( getLogger().isDebugEnabled() ) { - getLogger().debug( "Subscribing event " + subscriber.getEventType().getName() ); - } - - // Add to list but prevent duplicate subscriptions - if ( !subscribers.contains( subscriber ) ) { - subscribers.add( subscriber ); - if ( getLogger().isDebugEnabled() ) { - getLogger().debug( "Subscribed Event " + subscriber.getEventType().getName() ); - getLogger().debug( "Subscribers now active: " + subscribers.size() ); - } + getLogger().debug( "Subscribed Event " + subscriber.getEventType().getName() ); + getLogger().debug( "Subscribers now active: " + subscribers.size() ); } } + } + + public void unsubscribe( Subscriber subscriber ) + throws InvalidEventTypeException { - public void unsubscribe( Subscriber subscriber ) - throws InvalidEventTypeException { - - if ( !eventClass.isAssignableFrom( subscriber.getEventType() ) ) { - throw new InvalidEventTypeException(); - } - if ( subscribers.contains( subscriber ) ) { - subscribers.remove( subscriber ); - if ( getLogger().isDebugEnabled() ) { - getLogger().debug( "Unsubscribed Event " + subscriber.getEventType().getName() ); - getLogger().debug( "Subscribers now active: " + subscribers.size() ); - } - } else { - getLogger().warn( "Subscriber " + subscriber + " not found" ); + if ( !eventClass.isAssignableFrom( subscriber.getEventType() ) ) { + throw new InvalidEventTypeException(); + } + if ( subscribers.contains( subscriber ) ) { + subscribers.remove( subscriber ); + if ( getLogger().isDebugEnabled() ) { + getLogger().debug( "Unsubscribed Event " + subscriber.getEventType().getName() ); + getLogger().debug( "Subscribers now active: " + subscribers.size() ); } + } else { + getLogger().warn( "Subscriber " + subscriber + " not found" ); } }