cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r1059998 - /cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/
Date Mon, 17 Jan 2011 17:13:44 GMT
Author: reinhard
Date: Mon Jan 17 17:13:44 2011
New Revision: 1059998

URL: http://svn.apache.org/viewvc?rev=1059998&view=rev
Log:
cleanups & formatting

Modified:
    cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/CocoonReloadingListener.java
    cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/Constants.java
    cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingClassloaderCreationException.java
    cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingClassloaderManager.java
    cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingListener.java
    cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingNotificationSubscriber.java
    cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingServlet.java
    cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingServletFilter.java
    cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingSpringFilter.java

Modified: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/CocoonReloadingListener.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/CocoonReloadingListener.java?rev=1059998&r1=1059997&r2=1059998&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/CocoonReloadingListener.java
(original)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/CocoonReloadingListener.java
Mon Jan 17 17:13:44 2011
@@ -34,21 +34,40 @@ public class CocoonReloadingListener ext
         super();
     }
 
+    public static void enableConsoleOutput() {
+        CocoonReloadingListener.consoleOutput = true;
+    }
+
+    public static synchronized boolean isReload() {
+        if (reload == true) {
+            reload = false;
+            return true;
+        }
+
+        return reload;
+    }
+
+    @Override
     public void onFileChange(File file) {
         super.onFileChange(file);
-        // after the first change/deletion of a file is detected, log to the console
-        changeDetected(file, "update");
-    }
 
-    public void onFileDelete(File file) {
-        super.onFileDelete(file);
         // after the first change/deletion of a file is detected, log to the console
-        changeDetected(file, "delete");
+        this.changeDetected(file, "update");
     }
 
+    @Override
     public void onFileCreate(File file) {
         super.onFileCreate(file);
-        changeDetected(file, "create");
+
+        this.changeDetected(file, "create");
+    }
+
+    @Override
+    public void onFileDelete(File file) {
+        super.onFileDelete(file);
+
+        // after the first change/deletion of a file is detected, log to the console
+        this.changeDetected(file, "delete");
     }
 
     protected void changeDetected(File changedFile, String operation) {
@@ -62,27 +81,16 @@ public class CocoonReloadingListener ext
                 changedFilePath.endsWith(".class") ||                               // Java
class file change
                 changedFilePath.endsWith(".jar") ||                                 // JAR
file change
                 changedFileParentPath.endsWith("config/spring")                     // local
Spring bean configurations
-           ) {
-            log.debug("Configuration or .class file change detected [" + operation + "]:
" + changedFile);
+        ) {
+            this.log.debug("Configuration or .class file change detected [" + operation +
"]: " + changedFile);
+
             if (CocoonReloadingListener.consoleOutput) {
                 System.out.println("RCL [" + operation + "]: " + changedFile);
             }
+
             reload = true;
         } else {
-            log.debug("Other file change detected, no reload [" + operation + "]: " + changedFile);
 // any other file change
+            this.log.debug("Other file change detected, no reload [" + operation + "]: "
+ changedFile);  // any other file change
         }
     }
-
-    public static void enableConsoleOutput() {
-        CocoonReloadingListener.consoleOutput = true;
-    }
-
-    public static synchronized boolean isReload() {
-        if (reload == true) {
-            reload = false;
-            return true;
-        }
-        return reload;
-    }
-
 }
\ No newline at end of file

Modified: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/Constants.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/Constants.java?rev=1059998&r1=1059997&r2=1059998&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/Constants.java
(original)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/Constants.java
Mon Jan 17 17:13:44 2011
@@ -27,5 +27,4 @@ public interface Constants {
     String RELOADING_SPRING_ENABLED = "reloading.spring.enabled";
 
     String RELOADING_CLASSLOADER_ENABLED = "reloading.classloader.enabled";
-
 }

Modified: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingClassloaderCreationException.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingClassloaderCreationException.java?rev=1059998&r1=1059997&r2=1059998&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingClassloaderCreationException.java
(original)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingClassloaderCreationException.java
Mon Jan 17 17:13:44 2011
@@ -17,7 +17,9 @@
 package org.apache.cocoon.tools.rcl.wrapper.servlet;
 
 public class ReloadingClassloaderCreationException extends RuntimeException {
-    
+
+    private static final long serialVersionUID = 1L;
+
     public ReloadingClassloaderCreationException(String msg) {
         super(msg);
     }
@@ -25,5 +27,4 @@ public class ReloadingClassloaderCreatio
     public ReloadingClassloaderCreationException(String msg, Exception e) {
         super(msg, e);
     }
-
 }

Modified: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingClassloaderManager.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingClassloaderManager.java?rev=1059998&r1=1059997&r2=1059998&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingClassloaderManager.java
(original)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingClassloaderManager.java
Mon Jan 17 17:13:44 2011
@@ -47,20 +47,56 @@ public abstract class ReloadingClassload
             if (isReloadingClassloaderEnabled(context)) {
                 final ReloadingClassLoader classloader = new ReloadingClassLoader(urlClassloader);
                 final FilesystemAlterationMonitor fam = new FilesystemAlterationMonitor();
+
                 org.apache.commons.jci.listeners.ReloadingListener rl = new CocoonReloadingListener();
                 rl.addReloadNotificationListener(classloader);
+
                 addResourcesToFam(fam, rl, getRclConfResourceUrls(context));
                 fam.start();
+
                 ReloadingClassloaderManager.reloadingClassloader = classloader;
             } else {
                 // otherwise use the URL classloader only
                 ReloadingClassloaderManager.reloadingClassloader = urlClassloader;
             }
         }
-        
+
         return ReloadingClassloaderManager.reloadingClassloader;
     }
 
+    protected static ClassLoader createURLClassLoader(ServletContext context) {
+        try {
+            List<URL> urlsList = new ArrayList<URL>();
+            List<?> lines = IOUtils.readLines(context.getResourceAsStream(Constants.WEB_INF_RCL_URLCL_CONF));
+
+            for (Iterator<?> linesIt = lines.iterator(); linesIt.hasNext();) {
+                String line = (String) linesIt.next();
+                urlsList.add(new URL(line));
+            }
+
+            URL[] urls = urlsList.toArray(new URL[urlsList.size()]);
+
+            return new URLClassLoader(urls, ReloadingClassloaderManager.class.getClassLoader());
+        } catch (Exception e) {
+            throw new ReloadingClassloaderCreationException("Error while creating the URLClassLoader
from context:/"
+                    + Constants.WEB_INF_RCL_URLCL_CONF, e);
+        }
+    }
+
+    protected static boolean isReloadingClassloaderEnabled(ServletContext servletContext)
{
+        Properties rclProps = new Properties();
+
+        try {
+            rclProps.load(servletContext.getResourceAsStream(Constants.WEB_INF_RCLWRAPPER_PROPERTIES));
+        } catch (IOException e) {
+            throw new ReloadingClassloaderCreationException("Error while reading "
+                    + Constants.WEB_INF_RCLWRAPPER_PROPERTIES + " from servlet context.",
e);
+        }
+
+        String reloadingEnabled = rclProps.getProperty(Constants.RELOADING_CLASSLOADER_ENABLED,
"true");
+        return reloadingEnabled.trim().toLowerCase().equals("true");
+    }
+
     private static void addResourcesToFam(final FilesystemAlterationMonitor fam,
             org.apache.commons.jci.listeners.ReloadingListener rl, List<?> resourceUrl)
{
         for (Iterator<?> linesIt = resourceUrl.iterator(); linesIt.hasNext();) {
@@ -76,7 +112,8 @@ public abstract class ReloadingClassload
 
             // add libraries to the RCL
             if(url.endsWith(".jar")) {
-                // deactivate reloading of JARs 
+                // deactivate reloading of JARs since it isn't supported the JCI:
+                // see https://issues.apache.org/jira/browse/JCI-60
                 continue;
             }
             fam.addListener(new File(url), rl);
@@ -85,42 +122,14 @@ public abstract class ReloadingClassload
 
     private static List<?> getRclConfResourceUrls(ServletContext context) {
         List<?> lines = null;
+
         try {
             lines = IOUtils.readLines(context.getResourceAsStream(Constants.WEB_INF_RCLWRAPPER_RCL_CONF));
         } catch (IOException ioe) {
             throw new ReloadingClassloaderCreationException("Error while creating the URLClassLoader
from context:/"
                     + Constants.WEB_INF_RCLWRAPPER_RCL_CONF, ioe);
         }
-        return lines;
-    }
-
-    protected static ClassLoader createURLClassLoader(ServletContext context) {
-        try {
-            List<URL> urlsList = new ArrayList<URL>();
-            List<?> lines = IOUtils.readLines(context.getResourceAsStream(Constants.WEB_INF_RCL_URLCL_CONF));
-            for (Iterator<?> linesIt = lines.iterator(); linesIt.hasNext();) {
-                String line = (String) linesIt.next();
-                urlsList.add(new URL(line));
-            }
-
-            URL[] urls = urlsList.toArray(new URL[urlsList.size()]);
-            return new URLClassLoader(urls, ReloadingClassloaderManager.class.getClassLoader());
-        } catch (Exception e) {
-            throw new ReloadingClassloaderCreationException("Error while creating the URLClassLoader
from context:/"
-                    + Constants.WEB_INF_RCL_URLCL_CONF, e);
-        }
-    }
 
-    protected static boolean isReloadingClassloaderEnabled(ServletContext servletContext)
{
-        Properties rclProps = new Properties();
-        try {
-            rclProps.load(servletContext.getResourceAsStream(Constants.WEB_INF_RCLWRAPPER_PROPERTIES));
-        } catch (IOException e) {
-            throw new ReloadingClassloaderCreationException("Error while reading "
-                    + Constants.WEB_INF_RCLWRAPPER_PROPERTIES + " from servlet context.",
e);
-        }
-
-        String reloadingEnabled = rclProps.getProperty(Constants.RELOADING_CLASSLOADER_ENABLED,
"true");
-        return reloadingEnabled.trim().toLowerCase().equals("true");
+        return lines;
     }
 }

Modified: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingListener.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingListener.java?rev=1059998&r1=1059997&r2=1059998&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingListener.java
(original)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingListener.java
Mon Jan 17 17:13:44 2011
@@ -36,19 +36,12 @@ import javax.servlet.http.HttpSessionEve
 import javax.servlet.http.HttpSessionListener;
 
 /**
- * This listener can be used as a wrapper around "real" listeners to
- * support the reloading class loader.
- *
+ * This listener can be used as a wrapper around "real" listeners to support the reloading
class loader.
+ * 
  * @version $Id$
  */
-public class ReloadingListener
-    implements HttpSessionListener,
-               ServletContextListener,
-               HttpSessionActivationListener,
-               HttpSessionAttributeListener,
-               HttpSessionBindingListener,
-               ServletContextAttributeListener,
-               ServletRequestListener {
+public class ReloadingListener implements HttpSessionListener, ServletContextListener, HttpSessionActivationListener,
+HttpSessionAttributeListener, HttpSessionBindingListener, ServletContextAttributeListener,
ServletRequestListener {
 
     private static final String SERVLET_CONTEXT_CREATED = "CLC";
 
@@ -98,168 +91,91 @@ public class ReloadingListener
 
     protected ServletContext context;
 
-    protected void init(ServletContext context) {
-        this.context = context;
-        // Create the listeners
-        final ClassLoader old = Thread.currentThread().getContextClassLoader();
-        try {
-            Thread.currentThread().setContextClassLoader(ReloadingClassloaderManager.getClassLoader(this.context));
-            final String listenersConfig = context.getInitParameter(ReloadingListener.class.getName());
-            if ( listenersConfig != null ) {
-                final StringTokenizer st = new StringTokenizer(listenersConfig, " \t\r\n\f;,",
false);
-                while ( st.hasMoreTokens() ) {
-                    final String className = st.nextToken();
-                    try {
-                        ClassLoader cl = ReloadingClassloaderManager.getClassLoader(this.context);
-                        Class listenerClass = cl.loadClass(className);
-                        final Object listener = listenerClass.newInstance();
-                        if ( listener instanceof HttpSessionListener ) {
-                            this.httpSessionListeners.add(listener);
-                        }
-                        if ( listener instanceof ServletContextListener ) {
-                            this.servletContextListeners.add(listener);
-                        }
-                        if ( listener instanceof HttpSessionActivationListener ) {
-                            this.httpSessionActivationListeners.add(listener);
-                        }
-                        if ( listener instanceof HttpSessionAttributeListener ) {
-                            this.httpSessionAttributeListeners.add(listener);
-                        }
-                        if ( listener instanceof HttpSessionBindingListener ) {
-                            this.httpSessionBindingListeners.add(listener);
-                        }
-                        if ( listener instanceof ServletContextAttributeListener ) {
-                            this.servletContextAttributeListeners.add(listener);
-                        }
-                        if ( listener instanceof ServletRequestListener ) {
-                            this.servletRequestListeners.add(listener);
-                        }
-                    } catch (Exception e) {
-                        throw new RuntimeException("Cannot load listener " + className, e);
-                    }
-                }
-            }
-        } finally {
-            Thread.currentThread().setContextClassLoader(old);
-        }
+    /**
+     * @see javax.servlet.http.HttpSessionAttributeListener#attributeAdded(javax.servlet.http.HttpSessionBindingEvent)
+     */
+    public void attributeAdded(HttpSessionBindingEvent event) {
+        this.invoke(this.httpSessionAttributeListeners, ReloadingListener.ATTR_ADDED, event);
     }
 
-    protected void invoke(List listeners, String identifier, Object event) {
-        if ( ReloadingClassloaderManager.getClassLoader(this.context) != null ) {
-            final ClassLoader old = Thread.currentThread().getContextClassLoader();
-            try {
-                Thread.currentThread().setContextClassLoader(ReloadingClassloaderManager.getClassLoader(this.context));
-                final Iterator i = listeners.iterator();
-                while ( i.hasNext() ) {
-                    final Object listener = i.next();
-                    try {
-                        if ( ReloadingListener.SERVLET_CONTEXT_CREATED.equals(identifier)
) {
-                            ((ServletContextListener)listener).contextInitialized((ServletContextEvent)event);
-                        } else if ( ReloadingListener.SERVLET_CONTEXT_DESTROYED.equals(identifier)
) {
-                            ((ServletContextListener)listener).contextDestroyed((ServletContextEvent)event);
-                        } else if ( ReloadingListener.SESSION_CREATED.equals(identifier)
) {
-                            ((HttpSessionListener)listener).sessionCreated((HttpSessionEvent)event);
-                        } else if ( ReloadingListener.SESSION_DESTROYED.equals(identifier)
) {
-                            ((HttpSessionListener)listener).sessionDestroyed((HttpSessionEvent)event);
-                        } else if ( ReloadingListener.VALUE_BOUND.equals(identifier) ) {
-                            ((HttpSessionBindingListener)listener).valueBound((HttpSessionBindingEvent)event);
-                        } else if ( ReloadingListener.VALUE_UNBOUND.equals(identifier) )
{
-                            ((HttpSessionBindingListener)listener).valueUnbound((HttpSessionBindingEvent)event);
-                        } else if ( ReloadingListener.ATTR_ADDED.equals(identifier) ) {
-                            ((HttpSessionAttributeListener)listener).attributeAdded((HttpSessionBindingEvent)event);
-                        } else if ( ReloadingListener.ATTR_REMOVED.equals(identifier) ) {
-                            ((HttpSessionAttributeListener)listener).attributeRemoved((HttpSessionBindingEvent)event);
-                        } else if ( ReloadingListener.ATTR_REPLACED.equals(identifier) )
{
-                            ((HttpSessionAttributeListener)listener).attributeReplaced((HttpSessionBindingEvent)event);
-                        } else if ( ReloadingListener.CONTEXT_ATTR_ADDED.equals(identifier)
) {
-                            ((ServletContextAttributeListener)listener).attributeAdded((ServletContextAttributeEvent)event);
-                        } else if ( ReloadingListener.CONTEXT_ATTR_REMOVED.equals(identifier)
) {
-                            ((ServletContextAttributeListener)listener).attributeRemoved((ServletContextAttributeEvent)event);
-                        } else if ( ReloadingListener.CONTEXT_ATTR_REPLACED.equals(identifier)
) {
-                            ((ServletContextAttributeListener)listener).attributeReplaced((ServletContextAttributeEvent)event);
-                        } else if ( ReloadingListener.SESSION_ACTIVATED.equals(identifier)
) {
-                            ((HttpSessionActivationListener)listener).sessionDidActivate((HttpSessionEvent)event);
-                        } else if ( ReloadingListener.SESSION_PASSIVATE.equals(identifier)
) {
-                            ((HttpSessionActivationListener)listener).sessionWillPassivate((HttpSessionEvent)event);
-                        } else if ( ReloadingListener.REQUEST_DESTROYED.equals(identifier)
) {
-                            ((ServletRequestListener)listener).requestDestroyed((ServletRequestEvent)event);
-                        } else if ( ReloadingListener.REQUEST_INITIALIZED.equals(identifier)
) {
-                            ((ServletRequestListener)listener).requestInitialized((ServletRequestEvent)event);
-                        }
-                    } catch (Exception e) {
-                        throw new RuntimeException("Cannot invoke listener " + listener,
e);
-                    }
-                }
-            } finally {
-                Thread.currentThread().setContextClassLoader(old);
-            }
-        }
+    /**
+     * @see javax.servlet.ServletContextAttributeListener#attributeAdded(javax.servlet.ServletContextAttributeEvent)
+     */
+    public void attributeAdded(ServletContextAttributeEvent event) {
+        this.invoke(this.servletContextAttributeListeners, ReloadingListener.CONTEXT_ATTR_ADDED,
event);
     }
 
     /**
-     * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
+     * @see javax.servlet.http.HttpSessionAttributeListener#attributeRemoved(javax.servlet.http.HttpSessionBindingEvent)
      */
-    public void contextDestroyed(ServletContextEvent contextEvent) {
-        this.invoke(this.servletContextListeners, ReloadingListener.SERVLET_CONTEXT_DESTROYED,
contextEvent);
+    public void attributeRemoved(HttpSessionBindingEvent event) {
+        this.invoke(this.httpSessionAttributeListeners, ReloadingListener.ATTR_REMOVED, event);
     }
 
     /**
-     * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
+     * @see javax.servlet.ServletContextAttributeListener#attributeRemoved(javax.servlet.ServletContextAttributeEvent)
      */
-    public void contextInitialized(ServletContextEvent contextEvent) {
-        final ServletContext context = contextEvent.getServletContext();
-        this.init(context);
+    public void attributeRemoved(ServletContextAttributeEvent event) {
+        this.invoke(this.servletContextAttributeListeners, ReloadingListener.CONTEXT_ATTR_REMOVED,
event);
+    }
 
-        this.invoke(this.servletContextListeners, ReloadingListener.SERVLET_CONTEXT_CREATED,
contextEvent);
+    /**
+     * @see javax.servlet.http.HttpSessionAttributeListener#attributeReplaced(javax.servlet.http.HttpSessionBindingEvent)
+     */
+    public void attributeReplaced(HttpSessionBindingEvent event) {
+        this.invoke(this.httpSessionAttributeListeners, ReloadingListener.ATTR_REPLACED,
event);
     }
 
     /**
-     * @see javax.servlet.http.HttpSessionListener#sessionCreated(javax.servlet.http.HttpSessionEvent)
+     * @see javax.servlet.ServletContextAttributeListener#attributeReplaced(javax.servlet.ServletContextAttributeEvent)
      */
-    public void sessionCreated(HttpSessionEvent event) {
-        this.invoke(this.httpSessionListeners, ReloadingListener.SESSION_CREATED, event);
+    public void attributeReplaced(ServletContextAttributeEvent event) {
+        this.invoke(this.servletContextAttributeListeners, ReloadingListener.CONTEXT_ATTR_REPLACED,
event);
     }
 
     /**
-     * @see javax.servlet.http.HttpSessionListener#sessionDestroyed(javax.servlet.http.HttpSessionEvent)
+     * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
      */
-    public void sessionDestroyed(HttpSessionEvent event) {
-        this.invoke(this.httpSessionListeners, ReloadingListener.SESSION_DESTROYED, event);
+    public void contextDestroyed(ServletContextEvent contextEvent) {
+        this.invoke(this.servletContextListeners, ReloadingListener.SERVLET_CONTEXT_DESTROYED,
contextEvent);
     }
 
     /**
-     * @see javax.servlet.http.HttpSessionBindingListener#valueBound(javax.servlet.http.HttpSessionBindingEvent)
+     * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
      */
-    public void valueBound(HttpSessionBindingEvent event) {
-        this.invoke(this.httpSessionBindingListeners, ReloadingListener.VALUE_BOUND, event);
+    public void contextInitialized(ServletContextEvent contextEvent) {
+        final ServletContext context = contextEvent.getServletContext();
+        this.init(context);
+
+        this.invoke(this.servletContextListeners, ReloadingListener.SERVLET_CONTEXT_CREATED,
contextEvent);
     }
 
     /**
-     * @see javax.servlet.http.HttpSessionBindingListener#valueUnbound(javax.servlet.http.HttpSessionBindingEvent)
+     * @see javax.servlet.ServletRequestListener#requestDestroyed(javax.servlet.ServletRequestEvent)
      */
-    public void valueUnbound(HttpSessionBindingEvent event) {
-        this.invoke(this.httpSessionBindingListeners, ReloadingListener.VALUE_UNBOUND, event);
+    public void requestDestroyed(ServletRequestEvent event) {
+        this.invoke(this.servletRequestListeners, ReloadingListener.REQUEST_DESTROYED, event);
     }
 
     /**
-     * @see javax.servlet.http.HttpSessionAttributeListener#attributeAdded(javax.servlet.http.HttpSessionBindingEvent)
+     * @see javax.servlet.ServletRequestListener#requestInitialized(javax.servlet.ServletRequestEvent)
      */
-    public void attributeAdded(HttpSessionBindingEvent event) {
-        this.invoke(this.httpSessionAttributeListeners, ReloadingListener.ATTR_ADDED, event);
+    public void requestInitialized(ServletRequestEvent event) {
+        this.invoke(this.servletRequestListeners, ReloadingListener.REQUEST_INITIALIZED,
event);
     }
 
     /**
-     * @see javax.servlet.http.HttpSessionAttributeListener#attributeRemoved(javax.servlet.http.HttpSessionBindingEvent)
+     * @see javax.servlet.http.HttpSessionListener#sessionCreated(javax.servlet.http.HttpSessionEvent)
      */
-    public void attributeRemoved(HttpSessionBindingEvent event) {
-        this.invoke(this.httpSessionAttributeListeners, ReloadingListener.ATTR_REMOVED, event);
+    public void sessionCreated(HttpSessionEvent event) {
+        this.invoke(this.httpSessionListeners, ReloadingListener.SESSION_CREATED, event);
     }
 
     /**
-     * @see javax.servlet.http.HttpSessionAttributeListener#attributeReplaced(javax.servlet.http.HttpSessionBindingEvent)
+     * @see javax.servlet.http.HttpSessionListener#sessionDestroyed(javax.servlet.http.HttpSessionEvent)
      */
-    public void attributeReplaced(HttpSessionBindingEvent event) {
-        this.invoke(this.httpSessionAttributeListeners, ReloadingListener.ATTR_REPLACED,
event);
+    public void sessionDestroyed(HttpSessionEvent event) {
+        this.invoke(this.httpSessionListeners, ReloadingListener.SESSION_DESTROYED, event);
     }
 
     /**
@@ -277,37 +193,114 @@ public class ReloadingListener
     }
 
     /**
-     * @see javax.servlet.ServletContextAttributeListener#attributeAdded(javax.servlet.ServletContextAttributeEvent)
-     */
-    public void attributeAdded(ServletContextAttributeEvent event) {
-        this.invoke(this.servletContextAttributeListeners, ReloadingListener.CONTEXT_ATTR_ADDED,
event);
-    }
-
-    /**
-     * @see javax.servlet.ServletContextAttributeListener#attributeRemoved(javax.servlet.ServletContextAttributeEvent)
+     * @see javax.servlet.http.HttpSessionBindingListener#valueBound(javax.servlet.http.HttpSessionBindingEvent)
      */
-    public void attributeRemoved(ServletContextAttributeEvent event) {
-        this.invoke(this.servletContextAttributeListeners, ReloadingListener.CONTEXT_ATTR_REMOVED,
event);
+    public void valueBound(HttpSessionBindingEvent event) {
+        this.invoke(this.httpSessionBindingListeners, ReloadingListener.VALUE_BOUND, event);
     }
 
     /**
-     * @see javax.servlet.ServletContextAttributeListener#attributeReplaced(javax.servlet.ServletContextAttributeEvent)
+     * @see javax.servlet.http.HttpSessionBindingListener#valueUnbound(javax.servlet.http.HttpSessionBindingEvent)
      */
-    public void attributeReplaced(ServletContextAttributeEvent event) {
-        this.invoke(this.servletContextAttributeListeners, ReloadingListener.CONTEXT_ATTR_REPLACED,
event);
+    public void valueUnbound(HttpSessionBindingEvent event) {
+        this.invoke(this.httpSessionBindingListeners, ReloadingListener.VALUE_UNBOUND, event);
     }
 
-    /**
-     * @see javax.servlet.ServletRequestListener#requestDestroyed(javax.servlet.ServletRequestEvent)
-     */
-    public void requestDestroyed(ServletRequestEvent event) {
-        this.invoke(this.servletRequestListeners, ReloadingListener.REQUEST_DESTROYED, event);
+    protected void init(ServletContext context) {
+        this.context = context;
+        // Create the listeners
+        final ClassLoader old = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(ReloadingClassloaderManager.getClassLoader(this.context));
+            final String listenersConfig = context.getInitParameter(ReloadingListener.class.getName());
+            if (listenersConfig != null) {
+                final StringTokenizer st = new StringTokenizer(listenersConfig, " \t\r\n\f;,",
false);
+                while (st.hasMoreTokens()) {
+                    final String className = st.nextToken();
+                    try {
+                        ClassLoader cl = ReloadingClassloaderManager.getClassLoader(this.context);
+                        Class listenerClass = cl.loadClass(className);
+                        final Object listener = listenerClass.newInstance();
+                        if (listener instanceof HttpSessionListener) {
+                            this.httpSessionListeners.add(listener);
+                        }
+                        if (listener instanceof ServletContextListener) {
+                            this.servletContextListeners.add(listener);
+                        }
+                        if (listener instanceof HttpSessionActivationListener) {
+                            this.httpSessionActivationListeners.add(listener);
+                        }
+                        if (listener instanceof HttpSessionAttributeListener) {
+                            this.httpSessionAttributeListeners.add(listener);
+                        }
+                        if (listener instanceof HttpSessionBindingListener) {
+                            this.httpSessionBindingListeners.add(listener);
+                        }
+                        if (listener instanceof ServletContextAttributeListener) {
+                            this.servletContextAttributeListeners.add(listener);
+                        }
+                        if (listener instanceof ServletRequestListener) {
+                            this.servletRequestListeners.add(listener);
+                        }
+                    } catch (Exception e) {
+                        throw new RuntimeException("Cannot load listener " + className, e);
+                    }
+                }
+            }
+        } finally {
+            Thread.currentThread().setContextClassLoader(old);
+        }
     }
 
-    /**
-     * @see javax.servlet.ServletRequestListener#requestInitialized(javax.servlet.ServletRequestEvent)
-     */
-    public void requestInitialized(ServletRequestEvent event) {
-        this.invoke(this.servletRequestListeners, ReloadingListener.REQUEST_INITIALIZED,
event);
+    protected void invoke(List listeners, String identifier, Object event) {
+        if (ReloadingClassloaderManager.getClassLoader(this.context) != null) {
+            final ClassLoader old = Thread.currentThread().getContextClassLoader();
+            try {
+                Thread.currentThread().setContextClassLoader(ReloadingClassloaderManager.getClassLoader(this.context));
+                final Iterator i = listeners.iterator();
+                while (i.hasNext()) {
+                    final Object listener = i.next();
+                    try {
+                        if (ReloadingListener.SERVLET_CONTEXT_CREATED.equals(identifier))
{
+                            ((ServletContextListener) listener).contextInitialized((ServletContextEvent)
event);
+                        } else if (ReloadingListener.SERVLET_CONTEXT_DESTROYED.equals(identifier))
{
+                            ((ServletContextListener) listener).contextDestroyed((ServletContextEvent)
event);
+                        } else if (ReloadingListener.SESSION_CREATED.equals(identifier))
{
+                            ((HttpSessionListener) listener).sessionCreated((HttpSessionEvent)
event);
+                        } else if (ReloadingListener.SESSION_DESTROYED.equals(identifier))
{
+                            ((HttpSessionListener) listener).sessionDestroyed((HttpSessionEvent)
event);
+                        } else if (ReloadingListener.VALUE_BOUND.equals(identifier)) {
+                            ((HttpSessionBindingListener) listener).valueBound((HttpSessionBindingEvent)
event);
+                        } else if (ReloadingListener.VALUE_UNBOUND.equals(identifier)) {
+                            ((HttpSessionBindingListener) listener).valueUnbound((HttpSessionBindingEvent)
event);
+                        } else if (ReloadingListener.ATTR_ADDED.equals(identifier)) {
+                            ((HttpSessionAttributeListener) listener).attributeAdded((HttpSessionBindingEvent)
event);
+                        } else if (ReloadingListener.ATTR_REMOVED.equals(identifier)) {
+                            ((HttpSessionAttributeListener) listener).attributeRemoved((HttpSessionBindingEvent)
event);
+                        } else if (ReloadingListener.ATTR_REPLACED.equals(identifier)) {
+                            ((HttpSessionAttributeListener) listener).attributeReplaced((HttpSessionBindingEvent)
event);
+                        } else if (ReloadingListener.CONTEXT_ATTR_ADDED.equals(identifier))
{
+                            ((ServletContextAttributeListener) listener).attributeAdded((ServletContextAttributeEvent)
event);
+                        } else if (ReloadingListener.CONTEXT_ATTR_REMOVED.equals(identifier))
{
+                            ((ServletContextAttributeListener) listener).attributeRemoved((ServletContextAttributeEvent)
event);
+                        } else if (ReloadingListener.CONTEXT_ATTR_REPLACED.equals(identifier))
{
+                            ((ServletContextAttributeListener) listener).attributeReplaced((ServletContextAttributeEvent)
event);
+                        } else if (ReloadingListener.SESSION_ACTIVATED.equals(identifier))
{
+                            ((HttpSessionActivationListener) listener).sessionDidActivate((HttpSessionEvent)
event);
+                        } else if (ReloadingListener.SESSION_PASSIVATE.equals(identifier))
{
+                            ((HttpSessionActivationListener) listener).sessionWillPassivate((HttpSessionEvent)
event);
+                        } else if (ReloadingListener.REQUEST_DESTROYED.equals(identifier))
{
+                            ((ServletRequestListener) listener).requestDestroyed((ServletRequestEvent)
event);
+                        } else if (ReloadingListener.REQUEST_INITIALIZED.equals(identifier))
{
+                            ((ServletRequestListener) listener).requestInitialized((ServletRequestEvent)
event);
+                        }
+                    } catch (Exception e) {
+                        throw new RuntimeException("Cannot invoke listener " + listener,
e);
+                    }
+                }
+            } finally {
+                Thread.currentThread().setContextClassLoader(old);
+            }
+        }
     }
 }

Modified: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingNotificationSubscriber.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingNotificationSubscriber.java?rev=1059998&r1=1059997&r2=1059998&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingNotificationSubscriber.java
(original)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingNotificationSubscriber.java
Mon Jan 17 17:13:44 2011
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,5 +19,4 @@ package org.apache.cocoon.tools.rcl.wrap
 public interface ReloadingNotificationSubscriber {
 
     void handleNotification();
-    
 }

Modified: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingServlet.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingServlet.java?rev=1059998&r1=1059997&r2=1059998&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingServlet.java
(original)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingServlet.java
Mon Jan 17 17:13:44 2011
@@ -26,26 +26,48 @@ import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServlet;
 
 /**
- * This servlet builds a classloading sandbox and runs another servlet inside
- * that sandbox. The purpose is to use the reloading classloader to load the
- *
+ * This servlet builds a classloading sandbox and runs another servlet inside that sandbox.
The purpose is to use the
+ * reloading classloader.
+ * 
  * <p>
- * This servlet propagates all initialisation parameters to the sandboxed
- * servlet, and requires the parameter <code>servlet-class</code>.
+ * This servlet propagates all initialisation parameters to the sandboxed servlet, and requires
the parameter
+ * <code>servlet-class</code>.
  * <ul>
  * <li><code>servlet-class</code> defines the sandboxed servlet class.</li>
  * </ul>
- *
+ * 
  * @version $Id$
  */
 public class ReloadingServlet extends HttpServlet {
 
+    private static final long serialVersionUID = 1L;
+
     protected Servlet servlet;
     protected ServletConfig config;
 
     /**
+     * Destroy the actual servlet
+     */
+    @Override
+    public void destroy() {
+        if (this.servlet != null) {
+            final ClassLoader old = Thread.currentThread().getContextClassLoader();
+
+            try {
+                Thread.currentThread().setContextClassLoader(ReloadingClassloaderManager.getClassLoader(this.config.getServletContext()));
+                this.servlet.destroy();
+            } finally {
+                Thread.currentThread().setContextClassLoader(old);
+            }
+        }
+
+        super.destroy();
+    }
+
+    /**
      * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig)
      */
+    @Override
     public void init(ServletConfig config) throws ServletException {
         super.init(config);
         this.config = config;
@@ -82,12 +104,14 @@ public class ReloadingServlet extends Ht
     /**
      * Service the request by delegating the call to the real servlet
      */
+    @Override
     public void service(ServletRequest request, ServletResponse response) throws ServletException,
IOException {
         final ClassLoader old = Thread.currentThread().getContextClassLoader();
         try {
             Thread.currentThread().setContextClassLoader(ReloadingClassloaderManager.getClassLoader(this.config.getServletContext()));
 
             CocoonReloadingListener.enableConsoleOutput();
+
             this.servlet.service(request, response);
         } catch(Throwable t) {
             t.printStackTrace();
@@ -96,20 +120,4 @@ public class ReloadingServlet extends Ht
             Thread.currentThread().setContextClassLoader(old);
         }
     }
-
-    /**
-     * Destroy the actual servlet
-     */
-    public void destroy() {
-        if (this.servlet != null) {
-            final ClassLoader old = Thread.currentThread().getContextClassLoader();
-            try {
-                Thread.currentThread().setContextClassLoader(ReloadingClassloaderManager.getClassLoader(this.config.getServletContext()));
-                this.servlet.destroy();
-            } finally {
-                Thread.currentThread().setContextClassLoader(old);
-            }
-        }
-        super.destroy();
-    }
 }

Modified: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingServletFilter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingServletFilter.java?rev=1059998&r1=1059997&r2=1059998&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingServletFilter.java
(original)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingServletFilter.java
Mon Jan 17 17:13:44 2011
@@ -38,6 +38,21 @@ public class ReloadingServletFilter impl
     protected ServletContext context;
 
     /**
+     * @see javax.servlet.Filter#destroy()
+     */
+    public void destroy() {
+        if (this.filter != null) {
+            final ClassLoader old = Thread.currentThread().getContextClassLoader();
+            try {
+                Thread.currentThread().setContextClassLoader(ReloadingClassloaderManager.getClassLoader(this.context));
+                this.filter.destroy();
+            } finally {
+                Thread.currentThread().setContextClassLoader(old);
+            }
+        }
+    }
+
+    /**
      * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse,
javax.servlet.FilterChain)
      */
     public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
@@ -67,7 +82,6 @@ public class ReloadingServletFilter impl
 
         // Create the filter
         try {
-
             Class filterClass = ReloadingClassloaderManager.getClassLoader(this.context).loadClass(filterName);
             this.filter = (Filter) filterClass.newInstance();
 
@@ -85,19 +99,4 @@ public class ReloadingServletFilter impl
             Thread.currentThread().setContextClassLoader(old);
         }
     }
-
-    /**
-     * @see javax.servlet.Filter#destroy()
-     */
-    public void destroy() {
-        if (this.filter != null) {
-            final ClassLoader old = Thread.currentThread().getContextClassLoader();
-            try {
-                Thread.currentThread().setContextClassLoader(ReloadingClassloaderManager.getClassLoader(this.context));
-                this.filter.destroy();
-            } finally {
-                Thread.currentThread().setContextClassLoader(old);
-            }
-        }
-    }
 }

Modified: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingSpringFilter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingSpringFilter.java?rev=1059998&r1=1059997&r2=1059998&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingSpringFilter.java
(original)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingSpringFilter.java
Mon Jan 17 17:13:44 2011
@@ -45,19 +45,23 @@ public class ReloadingSpringFilter imple
 
     private FilterConfig config;
 
+    public void destroy() {
+        // do nothing
+    }
+
     public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain)
throws IOException,
-            ServletException {
+    ServletException {
 
-        if(isReloadingEnabled() && CocoonReloadingListener.isReload()) {
+        if(this.isReloadingEnabled() && CocoonReloadingListener.isReload()) {
             synchronized (this) {
-                log.info("Performing a reload of the Spring application context.");
+                this.log.info("Performing a reload of the Spring application context.");
                 // load the spring context loader from the reloading classloader
-                ClassLoader cl = ReloadingClassloaderManager.getClassLoader(config.getServletContext());
+                ClassLoader cl = ReloadingClassloaderManager.getClassLoader(this.config.getServletContext());
                 Object reloader = null;
                 try {
                     reloader = cl.loadClass("org.apache.cocoon.tools.rcl.springreloader.SpringReloader").newInstance();
                     Method reloadMethod = reloader.getClass().getMethod("reload", new Class[]{ServletContext.class}
);
-                    reloadMethod.invoke(reloader, new Object[]{config.getServletContext()});
+                    reloadMethod.invoke(reloader, new Object[]{this.config.getServletContext()});
                 } catch (Exception e) {
                     throw new ServletException("Can't use SpringReloader.", e);
                 }
@@ -67,9 +71,6 @@ public class ReloadingSpringFilter imple
         filterChain.doFilter(req, res);
     }
 
-    public void destroy() {
-    }
-
     public void init(FilterConfig filterConfig) throws ServletException {
         this.config = filterConfig;
     }
@@ -80,5 +81,4 @@ public class ReloadingSpringFilter imple
         String reloadingEnabled = rclProps.getProperty(Constants.RELOADING_SPRING_ENABLED,
"true");
         return reloadingEnabled.trim().toLowerCase().equals("true");
     }
-
 }
\ No newline at end of file



Mime
View raw message