cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r482656 [2/2] - in /cocoon/trunk/tools/cocoon-rcl: ./ cocoon-rcl-plugin-demo/ cocoon-rcl-plugin-demo/src/ cocoon-rcl-plugin-demo/src/main/ cocoon-rcl-plugin-demo/src/main/java/ cocoon-rcl-plugin-demo/src/main/java/demo/ cocoon-rcl-plugin-de...
Date Tue, 05 Dec 2006 14:03:21 GMT
Added: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingClassloaderCreationException.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingClassloaderCreationException.java?view=auto&rev=482656
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingClassloaderCreationException.java
(added)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingClassloaderCreationException.java
Tue Dec  5 06:03:18 2006
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.servlet;
+
+public class ReloadingClassloaderCreationException extends RuntimeException {
+
+    public ReloadingClassloaderCreationException(String msg, Exception e) {
+        super(msg, e);
+    }
+    
+}

Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingClassloaderCreationException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingClassloaderCreationException.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingClassloaderCreationException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingClassloaderManager.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingClassloaderManager.java?view=auto&rev=482656
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingClassloaderManager.java
(added)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingClassloaderManager.java
Tue Dec  5 06:03:18 2006
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.servlet;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.servlet.ServletContext;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.jci.ReloadingClassLoader;
+import org.apache.commons.jci.monitor.FilesystemAlterationMonitor;
+
+public class ReloadingClassloaderManager {
+
+    private static final String WEB_INF_RCL_URLCL_CONF = "/WEB-INF/cocoon/rclwrapper.urlcl.conf";
+    
+    private static final String WEB_INF_RCLWRAPPER_RCL_CONF = "/WEB-INF/cocoon/rclwrapper.rcl.conf";
       
+    
+    private static ReloadingClassLoader reloadingClassloader = null;
+
+    private ReloadingClassloaderManager() {
+        // only allow static usage
+    }
+    
+    public static synchronized ClassLoader getClassLoader(ServletContext context) {
+        if ( ReloadingClassloaderManager.reloadingClassloader == null ) { 
+            final ClassLoader urlClassloader = createURLClassLoader(context);
+            final ReloadingClassLoader classloader = new ReloadingClassLoader(urlClassloader);
  
+            final FilesystemAlterationMonitor fam = new FilesystemAlterationMonitor();  
         
+            List reloadingListeners = createReloadingListeners(context);
+            for(Iterator rlIt = reloadingListeners.iterator(); rlIt.hasNext();) {
+                org.apache.commons.jci.listeners.ReloadingListener rl = 
+                        (org.apache.commons.jci.listeners.ReloadingListener) rlIt.next();
+                classloader.addListener(rl);
+                fam.addListener(rl);
+            }
+            fam.start();    
+            
+            
+            // (rpoetz) debugging stuff: get a list of all resources with the name 
+            // "META-INF/cocoon/spring/demo-application-context.xml"
+            ReloadingClassloaderManager.reloadingClassloader = classloader;            
+            Enumeration o = null;
+            try {
+                o = classloader.getResources("META-INF/cocoon/spring/demo-application-context.xml");
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+            if(o != null) while(o.hasMoreElements()) {
+                System.out.println("--> rcl: " + o.nextElement());
+            }
+            // (rpoetz) end debugging stuff
+        }   
+        return ReloadingClassloaderManager.reloadingClassloader;
+    }    
+    
+    protected static ClassLoader createURLClassLoader(ServletContext context) {
+        try {
+            List urlsList = new ArrayList();
+            List lines = IOUtils.readLines(context.getResourceAsStream(WEB_INF_RCL_URLCL_CONF));
+            for (Iterator linesIt = lines.iterator(); linesIt.hasNext();) {
+                String line = (String) linesIt.next();
+                urlsList.add(new URL(line));
+            }
+            URL[] urls = (URL[]) 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:/"
+                    + WEB_INF_RCL_URLCL_CONF, e);
+        }
+    }
+    
+    protected static List createReloadingListeners(ServletContext context) {
+        try {
+            List reloadingListeners = new ArrayList();
+            List lines = IOUtils.readLines(context.getResourceAsStream(WEB_INF_RCLWRAPPER_RCL_CONF));
+            for (Iterator linesIt = lines.iterator(); linesIt.hasNext();) {
+                String line = (String) linesIt.next();
+                org.apache.commons.jci.listeners.ReloadingListener rl = new CocoonReloadingListener(new
File(line));
+                reloadingListeners.add(rl);
+            }
+            return reloadingListeners;
+        } catch (Exception e) {
+            throw new ReloadingClassloaderCreationException("Error while creating the URLClassLoader
from context:/"
+                    + WEB_INF_RCLWRAPPER_RCL_CONF, e);
+        }
+    }    
+    
+}

Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingClassloaderManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingClassloaderManager.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingClassloaderManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingListener.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingListener.java?view=auto&rev=482656
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingListener.java
(added)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingListener.java
Tue Dec  5 06:03:18 2006
@@ -0,0 +1,286 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.servlet;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextAttributeEvent;
+import javax.servlet.ServletContextAttributeListener;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.servlet.http.HttpSessionActivationListener;
+import javax.servlet.http.HttpSessionAttributeListener;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionBindingListener;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+
+/**
+ * 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 {
+
+    private static final String SERVLET_CONTEXT_CREATED = "CLC";
+
+    private static final String SERVLET_CONTEXT_DESTROYED = "CLD";
+
+    private static final String SESSION_CREATED = "SEC";
+
+    private static final String SESSION_DESTROYED = "SED";
+
+    private static final String SESSION_ACTIVATED = "SEAC";
+
+    private static final String SESSION_PASSIVATE = "SEDE";
+
+    private static final String VALUE_BOUND = "VB";
+
+    private static final String VALUE_UNBOUND = "VUB";
+
+    private static final String ATTR_REPLACED = "ARE";
+
+    private static final String ATTR_REMOVED = "ADE";
+
+    private static final String ATTR_ADDED = "AAD";
+
+    private static final String CONTEXT_ATTR_REPLACED = "CARE";
+
+    private static final String CONTEXT_ATTR_REMOVED = "CADE";
+
+    private static final String CONTEXT_ATTR_ADDED = "CAAD";
+
+    protected List httpSessionListeners = new ArrayList();
+
+    protected List servletContextListeners = new ArrayList();
+
+    protected List httpSessionActivationListeners = new ArrayList();
+
+    protected List httpSessionBindingListeners = new ArrayList();
+
+    protected List servletContextAttributeListeners = new ArrayList();
+
+    protected List httpSessionAttributeListeners = new ArrayList();
+    
+    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();
+                        ClassLoader listenerClassloader = listener.getClass().getClassLoader();
+                        System.out.println("ReloadingListener: ReloadingClassloaderManager.getClassLoader().getClass()="
+ className + "; cl=" + ReloadingClassloaderManager.getClassLoader(this.context).getClass().getName());
+                        System.out.println("ReloadingListener: listener.getClass().getClassloader()="
+ listenerClassloader);
+                        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);
+                        }
+                    } catch (Exception e) {
+                        throw new RuntimeException("Cannot load listener " + className, e);
+                    }
+                }
+            }
+        } finally {
+            Thread.currentThread().setContextClassLoader(old);
+        }
+    }
+
+    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);
                           
+                        }
+                    } catch (Exception e) {
+                        throw new RuntimeException("Cannot invoke listener " + listener,
e);
+                    }
+                }
+            } finally {
+                Thread.currentThread().setContextClassLoader(old);
+            }
+        }
+    }
+
+    /**
+     * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
+     */
+    public void contextDestroyed(ServletContextEvent contextEvent) {
+        this.invoke(this.servletContextListeners, ReloadingListener.SERVLET_CONTEXT_DESTROYED,
contextEvent);
+    }
+
+    /**
+     * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
+     */
+    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.HttpSessionListener#sessionCreated(javax.servlet.http.HttpSessionEvent)
+     */
+    public void sessionCreated(HttpSessionEvent event) {
+        this.invoke(this.httpSessionListeners, ReloadingListener.SESSION_CREATED, event);
+    }
+
+    /**
+     * @see javax.servlet.http.HttpSessionListener#sessionDestroyed(javax.servlet.http.HttpSessionEvent)
+     */
+    public void sessionDestroyed(HttpSessionEvent event) {
+        this.invoke(this.httpSessionListeners, ReloadingListener.SESSION_DESTROYED, event);
+    }
+
+    /**
+     * @see javax.servlet.http.HttpSessionBindingListener#valueBound(javax.servlet.http.HttpSessionBindingEvent)
+     */
+    public void valueBound(HttpSessionBindingEvent event) {
+        this.invoke(this.httpSessionBindingListeners, ReloadingListener.VALUE_BOUND, event);
+    }
+
+    /**
+     * @see javax.servlet.http.HttpSessionBindingListener#valueUnbound(javax.servlet.http.HttpSessionBindingEvent)
+     */
+    public void valueUnbound(HttpSessionBindingEvent event) {
+        this.invoke(this.httpSessionBindingListeners, ReloadingListener.VALUE_UNBOUND, event);
+    }
+
+    /**
+     * @see javax.servlet.http.HttpSessionAttributeListener#attributeAdded(javax.servlet.http.HttpSessionBindingEvent)
+     */
+    public void attributeAdded(HttpSessionBindingEvent event) {
+        this.invoke(this.httpSessionAttributeListeners, ReloadingListener.ATTR_ADDED, event);
+    }
+
+    /**
+     * @see javax.servlet.http.HttpSessionAttributeListener#attributeRemoved(javax.servlet.http.HttpSessionBindingEvent)
+     */
+    public void attributeRemoved(HttpSessionBindingEvent event) {
+        this.invoke(this.httpSessionAttributeListeners, ReloadingListener.ATTR_REMOVED, event);
+    }
+
+    /**
+     * @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.HttpSessionActivationListener#sessionDidActivate(javax.servlet.http.HttpSessionEvent)
+     */
+    public void sessionDidActivate(HttpSessionEvent event) {
+        this.invoke(this.httpSessionActivationListeners, ReloadingListener.SESSION_ACTIVATED,
event);
+    }
+
+    /**
+     * @see javax.servlet.http.HttpSessionActivationListener#sessionWillPassivate(javax.servlet.http.HttpSessionEvent)
+     */
+    public void sessionWillPassivate(HttpSessionEvent event) {
+        this.invoke(this.httpSessionActivationListeners, ReloadingListener.SESSION_PASSIVATE,
event);
+    }
+
+    /**
+     * @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)
+     */
+    public void attributeRemoved(ServletContextAttributeEvent event) {
+        this.invoke(this.servletContextAttributeListeners, ReloadingListener.CONTEXT_ATTR_REMOVED,
event);
+    }
+
+    /**
+     * @see javax.servlet.ServletContextAttributeListener#attributeReplaced(javax.servlet.ServletContextAttributeEvent)
+     */
+    public void attributeReplaced(ServletContextAttributeEvent event) {
+        this.invoke(this.servletContextAttributeListeners, ReloadingListener.CONTEXT_ATTR_REPLACED,
event);
+    }
+}

Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingListener.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingNotificationSubscriber.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingNotificationSubscriber.java?view=auto&rev=482656
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingNotificationSubscriber.java
(added)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingNotificationSubscriber.java
Tue Dec  5 06:03:18 2006
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.servlet;
+
+public interface ReloadingNotificationSubscriber {
+
+    void handleNotification();
+    
+}

Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingNotificationSubscriber.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingNotificationSubscriber.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingNotificationSubscriber.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingServlet.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingServlet.java?view=auto&rev=482656
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingServlet.java
(added)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingServlet.java
Tue Dec  5 06:03:18 2006
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.servlet;
+
+import java.io.IOException;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+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
+ * 
+ * <p>
+ * 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 {
+
+    protected Servlet servlet;
+    protected ServletConfig config;
+
+    /**
+     * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig)
+     */
+    public void init(ServletConfig config) throws ServletException {
+        super.init(config);
+        this.config = config;
+        
+        String servletName = config.getInitParameter("servlet-class");
+        if (servletName == null) {
+            throw new ServletException("ReloadingServlet: Init-Parameter 'servlet-class'
is missing.");
+        }
+
+        // Create the servlet
+        try {
+            ClassLoader cl = ReloadingClassloaderManager.getClassLoader(config.getServletContext());
+//            System.out.println("ReloadingServlet: rcm.getClassloader=" + cl);
+            Class servletClass = cl.loadClass(servletName);
+//            System.out.println("ReloadingServlet: servletClass.getClassloader()=" + servletClass.getClassLoader());
+            this.servlet = (Servlet) servletClass.newInstance();
+//            System.out.println("ReloadingServlet compare=" + (cl == servletClass.getClassLoader()));
+
+        } catch (Exception e) {
+            throw new ServletException("Cannot load servlet " + servletName, e);
+        }
+
+        // Always set the context classloader. JAXP uses it to find a
+        // ParserFactory,
+        // and thus fails if it's not set to the webapp classloader.
+        final ClassLoader old = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(ReloadingClassloaderManager.getClassLoader(config.getServletContext()));
+
+            // Inlitialize the actual servlet
+            this.servlet.init(this.getServletConfig());
+        } finally {
+            Thread.currentThread().setContextClassLoader(old);
+        }
+
+    }
+
+    /**
+     * Service the request by delegating the call to the real servlet
+     */
+    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()));
+            this.servlet.service(request, response);
+        } catch(Throwable t) {
+            t.printStackTrace();
+        }
+        finally {
+            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();
+    }
+}

Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingServlet.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingServlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingServletFilter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingServletFilter.java?view=auto&rev=482656
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingServletFilter.java
(added)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingServletFilter.java
Tue Dec  5 06:03:18 2006
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.servlet;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+/**
+ * This filter can be used as a wrapper around a "real" filter to
+ * support the reloading class loader.
+ *
+ * @version $Id$
+ */
+public class ReloadingServletFilter implements Filter {
+
+    protected Filter filter;
+    protected ServletContext context;
+
+    /**
+     * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse,
javax.servlet.FilterChain)
+     */
+    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+    throws IOException, ServletException {
+        if ( this.filter != null ) {
+            final ClassLoader old = Thread.currentThread().getContextClassLoader();
+            try {
+                Thread.currentThread().setContextClassLoader(ReloadingClassloaderManager.getClassLoader(this.context));
+
+                this.filter.doFilter(request, response, chain);
+            } finally {
+                Thread.currentThread().setContextClassLoader(old);
+            }            
+        }
+    }
+
+    /**
+     * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
+     */
+    public void init(FilterConfig config) throws ServletException {
+        String filterName = config.getInitParameter("filter-class");
+        this.context = config.getServletContext();
+        if (filterName == null) {
+            throw new ServletException("ReloadingServletFilter: 'filter-class' parameter
is missing.");
+        }
+
+        // Create the filter
+        try {
+
+            Class filterClass = ReloadingClassloaderManager.getClassLoader(this.context).loadClass(filterName);
+            this.filter = (Filter) filterClass.newInstance();
+
+        } catch (Exception e) {
+            throw new ServletException("Cannot load filter " + filterName, e);
+        }
+
+        final ClassLoader old = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(ReloadingClassloaderManager.getClassLoader(this.context));
+
+            // Inlitialize the actual filter
+            this.filter.init(config);
+        } finally {
+            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);
+            }
+        }
+    }
+}

Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingServletFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingServletFilter.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingServletFilter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingSpringFilter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingSpringFilter.java?view=auto&rev=482656
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingSpringFilter.java
(added)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingSpringFilter.java
Tue Dec  5 06:03:18 2006
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.servlet;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.springframework.context.ApplicationContext;
+import org.springframework.web.context.ContextLoader;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+/*
+ * For now only some experimental stuff regarding the reload of the Spring application context.
+ * 
+ * @version $Id$
+ */
+public class ReloadingSpringFilter implements Filter {
+
+    private FilterConfig config;
+
+    public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain)
throws IOException,
+            ServletException {
+        
+        System.out.println("doFilter ReloadingSpringFilter!");
+        
+        if(CocoonReloadingListener.isReload()) {
+            synchronized (this) {
+                ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.config.getServletContext());
+                System.out.println("old appContext: " + appContext);
+                
+                ContextLoader springContextLoader = new ContextLoader();
+                springContextLoader.closeWebApplicationContext(this.config.getServletContext());
+                this.config.getServletContext().removeAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
+                springContextLoader.initWebApplicationContext(this.config.getServletContext());
+                
+                appContext = WebApplicationContextUtils.getWebApplicationContext(this.config.getServletContext());
+                System.out.println("new appContext: " + appContext);     
+            }
+        }
+        // continue processing the request
+        filterChain.doFilter(req, res);            
+    }
+
+    public void destroy() {
+    }
+
+    public void init(FilterConfig filterConfig) throws ServletException {
+        this.config = filterConfig;
+        
+    }
+ 
+}

Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingSpringFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingSpringFilter.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/servlet/ReloadingSpringFilter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/trunk/tools/cocoon-rcl/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/pom.xml?view=auto&rev=482656
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/pom.xml (added)
+++ cocoon/trunk/tools/cocoon-rcl/pom.xml Tue Dec  5 06:03:18 2006
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  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.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<!--+
+    | @version $Id$
+    +-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <groupId>org.apache.cocoon</groupId>
+    <artifactId>cocoon-tools-modules</artifactId>
+    <version>2-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>cocoon-rcl-modules</artifactId>
+  <version>1-SNAPSHOT</version>
+  <packaging>pom</packaging>
+  <name>Cocoon Reloading ClassLoader [modules]</name>
+  <modules>
+    <module>cocoon-rcl-webapp-wrapper</module>
+    <module>cocoon-rcl-plugin</module>
+  </modules>
+  <scm>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/cocoon/trunk/tools/cocoon-rcl</connection>
+  </scm>
+</project>

Propchange: cocoon/trunk/tools/cocoon-rcl/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/tools/cocoon-rcl/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/trunk/tools/cocoon-rcl/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message