Author: markt Date: Sun Mar 21 22:18:03 2010 New Revision: 925921 URL: http://svn.apache.org/viewvc?rev=925921&view=rev Log: Always use the InstanceManager to create listeners, filters & servlets
Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java?rev=925921&r1=925920&r2=925921&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java (original) +++ tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java Sun Mar 21 22:18:03 2010 @@ -1207,27 +1207,36 @@ public class ApplicationContext @Override public void addListener(String className) { - Class<?> clazz; - try { - clazz = Class.forName(className); - } catch (ClassNotFoundException e) { - throw new IllegalArgumentException(sm.getString( - "applicationContext.addListener.iae.cnfe", className), e); - } - - if (!EventListener.class.isAssignableFrom(clazz)) { - throw new IllegalArgumentException(sm.getString( - "applicationContext.addListener.iae.wrongType", className)); - } + Object obj = context.getInstanceManager().newInstance(className); - try { - @SuppressWarnings("unchecked") // tested above - EventListener listener = createListener((Class<EventListener>)clazz); + if (!(obj instanceof EventListener)) { + throw new IllegalArgumentException(sm.getString( + "applicationContext.addListener.iae.wrongType", + className)); + } + + EventListener listener = (EventListener) obj; addListener(listener); - } catch (ServletException e) { + } catch (IllegalAccessException e) { + throw new IllegalArgumentException(sm.getString( + "applicationContext.addListener.iae.cnfe", className), + e); + } catch (InvocationTargetException e) { + throw new IllegalArgumentException(sm.getString( + "applicationContext.addListener.iae.cnfe", className), + e); + } catch (NamingException e) { + throw new IllegalArgumentException(sm.getString( + "applicationContext.addListener.iae.cnfe", className), + e); + } catch (InstantiationException e) { + throw new IllegalArgumentException(sm.getString( + "applicationContext.addListener.iae.cnfe", className), + e); + } catch (ClassNotFoundException e) { throw new IllegalArgumentException(sm.getString( - "applicationContext.addListener.iae.wrongType", className), + "applicationContext.addListener.iae.cnfe", className), e); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org