You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2013/01/05 00:13:01 UTC

svn commit: r1429167 - /tomcat/trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java

Author: kkolinko
Date: Fri Jan  4 23:13:00 2013
New Revision: 1429167

URL: http://svn.apache.org/viewvc?rev=1429167&view=rev
Log:
Further review of ApplicationFilterConfig.
Inline the setFilterDef() method.
In the constructor the filterDef is never null and there is no need to care about destroying a filter. Thus the code is simplier.
The method was package-visible, thus there should not be any 3rd party callers.

Modified:
    tomcat/trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java

Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java?rev=1429167&r1=1429166&r2=1429167&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java Fri Jan  4 23:13:00 2013
@@ -101,8 +101,11 @@ public final class ApplicationFilterConf
         super();
 
         this.context = context;
-        setFilterDef(filterDef);
-        if (filterDef.getFilter() != null) {
+        this.filterDef = filterDef;
+        // Allocate a new filter instance if necessary
+        if (filterDef.getFilter() == null) {
+            getFilter();
+        } else {
             this.filter = filterDef.getFilter();
             getInstanceManager().newInstance(filter);
             initFilter();
@@ -128,7 +131,7 @@ public final class ApplicationFilterConf
     /**
      * The <code>FilterDef</code> that defines our associated Filter.
      */
-    private FilterDef filterDef = null;
+    private final FilterDef filterDef;
 
     /**
      * the InstanceManager used to create and destroy filter instances.
@@ -334,74 +337,6 @@ public final class ApplicationFilterConf
      }
 
 
-    /**
-     * Set the filter definition we are configured for.  This has the side
-     * effect of instantiating an instance of the corresponding filter class.
-     *
-     * @param filterDef The new filter definition
-     *
-     * @exception ClassCastException if the specified class does not implement
-     *  the <code>javax.servlet.Filter</code> interface
-     * @exception ClassNotFoundException if the filter class cannot be found
-     * @exception IllegalAccessException if the filter class cannot be
-     *  publicly instantiated
-     * @exception InstantiationException if an exception occurs while
-     *  instantiating the filter object
-     * @exception ServletException if thrown by the filter's init() method
-     * @throws NamingException
-     * @throws InvocationTargetException
-     */
-    void setFilterDef(FilterDef filterDef)
-        throws ClassCastException, ClassNotFoundException,
-               IllegalAccessException, InstantiationException,
-               ServletException, InvocationTargetException, NamingException {
-
-        FilterDef oldFilterDef = this.filterDef;
-        this.filterDef = filterDef;
-        if (filterDef == null) {
-
-            // Release any previously allocated filter instance
-            if (this.filter != null){
-                try {
-                    if (Globals.IS_SECURITY_ENABLED) {
-                        try{
-                            SecurityUtil.doAsPrivilege("destroy", filter);
-                        } finally {
-                            SecurityUtil.remove(filter);
-                        }
-                    } else {
-                        filter.destroy();
-                    }
-                } catch (Throwable t) {
-                    ExceptionUtils.handleThrowable(t);
-                    context.getLogger().error(sm.getString(
-                            "applicationFilterConfig.release",
-                            oldFilterDef.getFilterName(),
-                            oldFilterDef.getFilterClass()), t);
-                }
-                if (!context.getIgnoreAnnotations()) {
-                    try {
-                        ((StandardContext) context).getInstanceManager().destroyInstance(this.filter);
-                    } catch (Exception e) {
-                        Throwable t = ExceptionUtils
-                                .unwrapInvocationTargetException(e);
-                        ExceptionUtils.handleThrowable(t);
-                        context.getLogger().error("ApplicationFilterConfig.preDestroy", t);
-                    }
-                }
-            }
-            this.filter = null;
-
-        } else {
-            // Allocate a new filter instance if necessary
-            if (filterDef.getFilter() == null) {
-                getFilter();
-            }
-        }
-
-    }
-
-
     // -------------------------------------------------------- Private Methods
 
     private InstanceManager getInstanceManager() {



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org