1 16 17 18 package org.apache.commons.logging.impl; 19 20 import java.lang.reflect.InvocationTargetException ; 21 import java.lang.reflect.Method ; 22 23 import javax.servlet.ServletContextEvent ; 24 import javax.servlet.ServletContextListener ; 25 26 import org.apache.commons.logging.LogFactory; 27 28 29 50 51 public class ServletContextCleaner implements ServletContextListener { 52 53 private Class [] RELEASE_SIGNATURE = {ClassLoader .class}; 54 55 60 public void contextDestroyed(ServletContextEvent sce) { 61 ClassLoader tccl = Thread.currentThread().getContextClassLoader(); 62 63 Object [] params = new Object [1]; 64 params[0] = tccl; 65 66 ClassLoader loader = tccl; 97 while (loader != null) { 98 try { 102 Class logFactoryClass = loader.loadClass("org.apache.commons.logging.LogFactory"); 103 Method releaseMethod = logFactoryClass.getMethod("release", RELEASE_SIGNATURE); 104 releaseMethod.invoke(null, params); 105 loader = logFactoryClass.getClassLoader().getParent(); 106 } catch(ClassNotFoundException ex) { 107 loader = null; 110 } catch(NoSuchMethodException ex) { 111 System.err.println("LogFactory instance found which does not support release method!"); 113 loader = null; 114 } catch(IllegalAccessException ex) { 115 System.err.println("LogFactory instance found which is not accessable!"); 117 loader = null; 118 } catch(InvocationTargetException ex) { 119 System.err.println("LogFactory instance release method failed!"); 121 loader = null; 122 } 123 } 124 125 LogFactory.release(tccl); 129 } 130 131 134 public void contextInitialized(ServletContextEvent sce) { 135 } 137 } 138 | Popular Tags |