cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r410139 - in /cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet: AbstractParanoidListener.java ParanoidHttpSessionListener.java ParanoidServletContextListener.java ParanoidServletFilter.java
Date Mon, 29 May 2006 18:49:45 GMT
Author: cziegeler
Date: Mon May 29 11:49:44 2006
New Revision: 410139

URL: http://svn.apache.org/viewvc?rev=410139&view=rev
Log:
Add paranoid listeners for http sessions listeners and servlet context listeners

Added:
    cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/AbstractParanoidListener.java
  (with props)
    cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/ParanoidHttpSessionListener.java
  (with props)
    cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/ParanoidServletContextListener.java
  (with props)
Modified:
    cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/ParanoidServletFilter.java

Added: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/AbstractParanoidListener.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/AbstractParanoidListener.java?rev=410139&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/AbstractParanoidListener.java
(added)
+++ cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/AbstractParanoidListener.java
Mon May 29 11:49:44 2006
@@ -0,0 +1,90 @@
+/*
+ * Copyright 1999-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.bootstrap.servlet;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+/**
+ * This listener can be used as a wrapper around "real" listeners to
+ * support the paranoid class loader.
+ *
+ * @version $Id$
+ */
+public abstract class AbstractParanoidListener {
+
+    protected ClassLoader classloader;
+
+    protected List listeners = new ArrayList();
+
+    protected void init(ServletContext context, String key) {
+        // Get the classloader
+        try {
+            this.classloader = BootstrapClassLoaderManager.getClassLoader(context);
+        } catch (ServletException se) {
+            throw new RuntimeException("Unable to create bootstrap classloader.", se);
+        }
+
+        // Create the listeners
+        final ClassLoader old = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(this.classloader);
+            final String listenersConfig = context.getInitParameter(key);
+            if ( listenersConfig != null ) {
+                final StringTokenizer st = new StringTokenizer(listenersConfig, " \t\r\n\f;,",
false);
+                while ( st.hasMoreTokens() ) {
+                    final String className = st.nextToken();
+                    try {    
+                        Class listenerClass = this.classloader.loadClass(className);
+                        final Object listener = listenerClass.newInstance();
+                        this.listeners.add(listener);
+                    } catch (Exception e) {
+                        throw new RuntimeException("Cannot load listener " + className, e);
+                    }
+                }
+            }
+        } finally {
+            Thread.currentThread().setContextClassLoader(old);
+        }
+    }
+
+    protected void invoke(String identifier, Object event) {
+        if ( this.classloader != null ) {
+            final ClassLoader old = Thread.currentThread().getContextClassLoader();
+            try {
+                Thread.currentThread().setContextClassLoader(this.classloader);
+                final Iterator i = this.listeners.iterator();
+                while ( i.hasNext() ) {
+                    final Object listener = i.next();
+                    try {
+                    } catch (Exception e) {
+                        throw new RuntimeException("Cannot invoke listener " + listener,
e);
+                    }
+                }
+            } finally {
+                Thread.currentThread().setContextClassLoader(old);
+            }
+        }
+    }
+
+    protected abstract void invokeListener(String identifier, Object listener, Object event)
+    throws Exception;
+}
\ No newline at end of file

Propchange: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/AbstractParanoidListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/AbstractParanoidListener.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/ParanoidHttpSessionListener.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/ParanoidHttpSessionListener.java?rev=410139&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/ParanoidHttpSessionListener.java
(added)
+++ cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/ParanoidHttpSessionListener.java
Mon May 29 11:49:44 2006
@@ -0,0 +1,63 @@
+/*
+ * Copyright 1999-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.bootstrap.servlet;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+
+/**
+ * This listener can be used as a wrapper around "real" listeners to
+ * support the paranoid class loader.
+ *
+ * @version $Id$
+ */
+public class ParanoidHttpSessionListener
+    extends AbstractParanoidListener
+    implements HttpSessionListener {
+
+    protected static final String KEY = ParanoidHttpSessionListener.class.getName();
+
+    protected static final String DESTROYED_EVENT = "d";
+    protected static final String CREATED_EVENT = "c";
+
+    protected void invokeListener(String identifier, Object listener, Object event) throws
Exception {
+        final HttpSessionListener l = (HttpSessionListener)listener;
+        final HttpSessionEvent e = (HttpSessionEvent)event;
+        if ( identifier.equals(DESTROYED_EVENT) ) {
+            l.sessionDestroyed(e);
+        } else {
+            l.sessionCreated(e);
+        }
+    }
+
+    /**
+     * @see javax.servlet.http.HttpSessionListener#sessionCreated(javax.servlet.http.HttpSessionEvent)
+     */
+    public void sessionCreated(HttpSessionEvent event) {
+        final ServletContext context = event.getSession().getServletContext();
+        this.init(context, KEY);
+
+        this.invoke(CREATED_EVENT, event);
+    }
+
+    /**
+     * @see javax.servlet.http.HttpSessionListener#sessionDestroyed(javax.servlet.http.HttpSessionEvent)
+     */
+    public void sessionDestroyed(HttpSessionEvent event) {
+        this.invoke(DESTROYED_EVENT, event);
+    }
+}
\ No newline at end of file

Propchange: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/ParanoidHttpSessionListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/ParanoidHttpSessionListener.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/ParanoidServletContextListener.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/ParanoidServletContextListener.java?rev=410139&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/ParanoidServletContextListener.java
(added)
+++ cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/ParanoidServletContextListener.java
Mon May 29 11:49:44 2006
@@ -0,0 +1,66 @@
+/*
+ * Copyright 1999-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.bootstrap.servlet;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+/**
+ * This listener can be used as a wrapper around "real" listeners to
+ * support the paranoid class loader.
+ *
+ * @version $Id$
+ */
+public class ParanoidServletContextListener
+    extends AbstractParanoidListener
+    implements ServletContextListener {
+
+    protected static final String KEY = ParanoidServletContextListener.class.getName();
+
+    protected static final String DESTROYED_EVENT = "d";
+    protected static final String CREATED_EVENT = "c";
+    
+    /**
+     * @see org.apache.cocoon.bootstrap.servlet.AbstractParanoidListener#invokeListener(java.lang.String,
java.lang.Object, java.lang.Object)
+     */
+    protected void invokeListener(String identifier, Object listener, Object event) throws
Exception {
+        final ServletContextListener l = (ServletContextListener)listener;
+        final ServletContextEvent e = (ServletContextEvent)event;
+        if ( identifier.equals(DESTROYED_EVENT) ) {
+            l.contextDestroyed(e);
+        } else {
+            l.contextInitialized(e);
+        }
+    }
+
+    /**
+     * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
+     */
+    public void contextDestroyed(ServletContextEvent contextEvent) {
+        this.invoke(DESTROYED_EVENT, contextEvent);
+    }
+
+    /**
+     * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
+     */
+    public void contextInitialized(ServletContextEvent contextEvent) {
+        final ServletContext context = contextEvent.getServletContext();
+        this.init(context, KEY);
+
+        this.invoke(CREATED_EVENT, contextEvent);
+   }
+}
\ No newline at end of file

Propchange: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/ParanoidServletContextListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/ParanoidServletContextListener.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/ParanoidServletFilter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/ParanoidServletFilter.java?rev=410139&r1=410138&r2=410139&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/ParanoidServletFilter.java
(original)
+++ cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/bootstrap/servlet/ParanoidServletFilter.java
Mon May 29 11:49:44 2006
@@ -25,6 +25,9 @@
 import javax.servlet.ServletResponse;
 
 /**
+ * This filter can be used as a wrapper around a "real" filter to
+ * support the paranoid class loader.
+ *
  * @version $Id$
  */
 public class ParanoidServletFilter implements Filter {



Mime
View raw message