cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r158492 - in cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor: ConcreteTreeProcessor.java sitemap/SitemapLanguage.java
Date Mon, 21 Mar 2005 18:01:52 GMT
Author: cziegeler
Date: Mon Mar 21 10:01:50 2005
New Revision: 158492

URL: http://svn.apache.org/viewcvs?view=rev&rev=158492
Log:
Invoke listeners

Modified:
    cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
    cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java?view=diff&r1=158491&r2=158492
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
Mon Mar 21 10:01:50 2005
@@ -36,7 +36,12 @@
 import org.apache.cocoon.environment.internal.ForwardEnvironmentWrapper;
 import org.apache.cocoon.environment.wrapper.MutableEnvironmentFacade;
 import org.apache.cocoon.sitemap.ComponentLocator;
+import org.apache.cocoon.sitemap.EnterSitemapEvent;
+import org.apache.cocoon.sitemap.EnterSitemapEventListener;
+import org.apache.cocoon.sitemap.LeaveSitemapEvent;
+import org.apache.cocoon.sitemap.LeaveSitemapEventListener;
 import org.apache.cocoon.sitemap.SitemapExecutor;
+import org.apache.cocoon.sitemap.SitemapListener;
 
 /**
  * The concrete implementation of {@link Processor}, containing the evaluation tree and associated
@@ -226,6 +231,16 @@
         currentThread.setContextClassLoader(this.classloader);
 
         try {
+            // invoke listeners
+            if ( this.enterSitemapEventListeners.size() > 0 ) {
+                final EnterSitemapEvent enterEvent = new EnterSitemapEvent(this, environment);
+                final Iterator enterSEI = this.enterSitemapEventListeners.iterator();
+                while ( enterSEI.hasNext() ) {
+                    final TreeBuilder.EventComponent current = (TreeBuilder.EventComponent)enterSEI.next();
+                    ((EnterSitemapEventListener)current.component).enteredSitemap(enterEvent);
+                }
+            }
+
             // and now process
             EnvironmentHelper.enterProcessor(this, this.manager, environment);
             final Redirector oldRedirector = context.getRedirector();
@@ -247,6 +262,16 @@
             }
 
         } finally {
+            // invoke listeners
+            if ( this.leaveSitemapEventListeners.size() > 0 ) {
+                final LeaveSitemapEvent leaveEvent = new LeaveSitemapEvent(this, environment);
+                final Iterator leaveSEI = this.leaveSitemapEventListeners.iterator();
+                while ( leaveSEI.hasNext() ) {
+                    final TreeBuilder.EventComponent current = (TreeBuilder.EventComponent)leaveSEI.next();
+                    ((LeaveSitemapEventListener)current.component).leftSitemap(leaveEvent);
+                }
+            }
+
             // Restore classloader
             currentThread.setContextClassLoader(oldClassLoader);
 
@@ -330,8 +355,10 @@
         this.disposeListeners(this.enterSitemapEventListeners);
         this.disposeListeners(this.leaveSitemapEventListeners);
 
-        // dispose component locator
-        ContainerUtil.dispose(this.applicationContainer);
+        // dispose component locator - if it is a SitemapListener it is already disposed!
+        if ( !(this.applicationContainer instanceof SitemapListener) ) {
+            ContainerUtil.dispose(this.applicationContainer);
+        }
         this.applicationContainer = null;
     }
 

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java?view=diff&r1=158491&r2=158492
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
Mon Mar 21 10:01:50 2005
@@ -44,7 +44,10 @@
 import org.apache.cocoon.generation.Generator;
 import org.apache.cocoon.serialization.Serializer;
 import org.apache.cocoon.sitemap.ComponentLocator;
+import org.apache.cocoon.sitemap.EnterSitemapEventListener;
+import org.apache.cocoon.sitemap.LeaveSitemapEventListener;
 import org.apache.cocoon.sitemap.PatternException;
+import org.apache.cocoon.sitemap.SitemapListener;
 import org.apache.cocoon.sitemap.impl.ComponentManager;
 import org.apache.cocoon.util.ClassUtils;
 import org.apache.cocoon.util.StringUtils;
@@ -138,20 +141,20 @@
             }
 
             // and finally the listeners
+            if ( this.applicationContainer instanceof SitemapListener ) {
+                this.addListener(new TreeBuilder.EventComponent(this.applicationContainer,
false));
+            }
+
             final Configuration listenersWrapper = config.getChild("listeners", false);
             if ( listenersWrapper != null ) {
-                final Configuration[] listeners = listenersWrapper.getChildren("listener");
+                final Configuration[] listeners = listenersWrapper.getChildren("listener");
               
                 for(int i = 0; i < listeners.length; i++) {
                     final Configuration current = listeners[i];
-                    // TODO - we could use a string tokenizer and allow several invoke keys
-                    final String invoke = current.getAttribute("invoke");
-                    if ( "on-enter".equals(invoke) ) {
-                        this.enterSitemapEventListeners.add(this.createListener(newManager,
context, current));
-                    } else if ( "on-leave".equals(invoke) ) {
-                        this.leaveSitemapEventListeners.add(this.createListener(newManager,
context, current));                        
-                    } else {
-                        throw new ConfigurationException("Unknown invokation key '" + invoke
+ "' for sitemap listener.");
+                    final TreeBuilder.EventComponent listener = this.createListener(newManager,
context, current);
+                    if ( !(listener.component instanceof SitemapListener) ) {
+                        throw new ConfigurationException("Listener must implement the SitemapListener
interface.");
                     }
+                    this.addListener(listener);
                 }
             }
         } finally {
@@ -164,7 +167,7 @@
     /**
      * Create a listener
      */
-    protected Object createListener(ServiceManager manager, Context context, Configuration
config) 
+    protected TreeBuilder.EventComponent createListener(ServiceManager manager, Context context,
Configuration config) 
     throws Exception {
         // role or class?
         final String role = config.getAttribute("role", null);
@@ -177,6 +180,17 @@
             LifecycleHelper.setupComponent(component, this.getLogger(), context, manager,
config);
 
             return new TreeBuilder.EventComponent(component, false);
+        }
+    }
+
+    /**
+     * Add a listener
+     */
+    protected void addListener(TreeBuilder.EventComponent listener) {
+        if ( listener.component instanceof EnterSitemapEventListener ) {
+            this.enterSitemapEventListeners.add(listener);
+        } else if ( listener.component instanceof LeaveSitemapEventListener ) {
+            this.leaveSitemapEventListeners.add(listener);
         }
     }
 



Mime
View raw message