/** Release the Filter instance associated with this FilterConfig, if there is one. */
  void release() {

    unregisterJMX();

    if (this.filter != null) {
      if (Globals.IS_SECURITY_ENABLED) {
        try {
          SecurityUtil.doAsPrivilege("destroy", filter);
        } catch (java.lang.Exception ex) {
          context.getLogger().error("ApplicationFilterConfig.doAsPrivilege", ex);
        }
        SecurityUtil.remove(filter);
      } else {
        filter.destroy();
      }
      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;
  }
  /**
   * Perform work as a particular <code>Subject</code>. Here the work will be granted to a <code>
   * null</code> subject.
   *
   * @param methodName the method to apply the security restriction
   * @param targetObject the <code>Filter</code> on which the method will be called.
   * @param targetType <code>Class</code> array used to instantiate a <code>Method</code> object.
   * @param targetArguments <code>Object</code> array contains the runtime parameters instance.
   */
  public static void doAsPrivilege(
      final String methodName,
      final Filter targetObject,
      final Class<?>[] targetType,
      final Object[] targetArguments)
      throws java.lang.Exception {

    doAsPrivilege(methodName, targetObject, targetType, targetArguments, null);
  }
  /**
   * 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 {

    this.filterDef = filterDef;
    if (filterDef == null) {

      // Release any previously allocated filter instance
      if (this.filter != null) {
        if (Globals.IS_SECURITY_ENABLED) {
          try {
            SecurityUtil.doAsPrivilege("destroy", filter);
          } catch (java.lang.Exception ex) {
            context.getLogger().error("ApplicationFilterConfig.doAsPrivilege", ex);
          }
          SecurityUtil.remove(filter);
        } else {
          filter.destroy();
        }
        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();
      }
    }
  }
 /**
  * Perform work as a particular </code>Subject</code>. Here the work will be granted to a <code>
  * null</code> subject.
  *
  * @param methodName the method to apply the security restriction
  * @param targetObject the <code>Servlet</code> on which the method will be called.
  */
 public static void doAsPrivilege(final String methodName, final Servlet targetObject)
     throws java.lang.Exception {
   doAsPrivilege(methodName, targetObject, null, null, null);
 }