Save This Page
Home » xwork-2.1.1-src » com.opensymphony.xwork2.interceptor » [javadoc | source]
    1   /*
    2    * Copyright (c) 2002-2006 by OpenSymphony
    3    * All rights reserved.
    4    */
    5   
    6   package com.opensymphony.xwork2.interceptor;
    7   
    8   import java.util.Collections;
    9   import java.util.Set;
   10   
   11   import com.opensymphony.xwork2.ActionInvocation;
   12   import com.opensymphony.xwork2.util.TextParseUtil;
   13   import com.opensymphony.xwork2.util.logging.Logger;
   14   import com.opensymphony.xwork2.util.logging.LoggerFactory;
   15   
   16   
   17   /**
   18    * <!-- START SNIPPET: javadoc -->
   19    * 
   20    * MethodFilterInterceptor is an abstract <code>Interceptor</code> used as
   21    * a base class for interceptors that will filter execution based on method 
   22    * names according to specified included/excluded method lists.
   23    * 
   24    * <p/>
   25    * 
   26    * Settable parameters are as follows:
   27    * 
   28    * <ul>
   29    * 		<li>excludeMethods - method names to be excluded from interceptor processing</li>
   30    * 		<li>includeMethods - method names to be included in interceptor processing</li>
   31    * </ul>
   32    * 
   33    * <p/>
   34    * 
   35    * <b>NOTE:</b> If method name are available in both includeMethods and 
   36    * excludeMethods, it will be considered as an included method: 
   37    * includeMethods takes precedence over excludeMethods.
   38    * 
   39    * <p/>
   40    * 
   41    * Interceptors that extends this capability include:
   42    * 
   43    * <ul>
   44    *    <li>TokenInterceptor</li>
   45    *    <li>TokenSessionStoreInterceptor</li>
   46    *    <li>DefaultWorkflowInterceptor</li>
   47    *    <li>ValidationInterceptor</li>
   48    * </ul>
   49    * 
   50    * <!-- END SNIPPET: javadoc -->
   51    * 
   52    * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
   53    * @author Rainer Hermanns
   54    * 
   55    * @see org.apache.struts2.interceptor.TokenInterceptor
   56    * @see org.apache.struts2.interceptor.TokenSessionStoreInterceptor
   57    * @see com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor
   58    * @see com.opensymphony.xwork2.validator.ValidationInterceptor
   59    * 
   60    * @version $Date: 2008-02-16 16:24:55 +0100 (Sat, 16 Feb 2008) $ $Id: MethodFilterInterceptor.java 1747 2008-02-16 15:24:55Z davenewton $
   61    */
   62   public abstract class MethodFilterInterceptor extends AbstractInterceptor {
   63       protected transient Logger log = LoggerFactory.getLogger(getClass());
   64       
   65       protected Set excludeMethods = Collections.EMPTY_SET;
   66       protected Set includeMethods = Collections.EMPTY_SET;
   67   
   68       public void setExcludeMethods(String excludeMethods) {
   69           this.excludeMethods = TextParseUtil.commaDelimitedStringToSet(excludeMethods);
   70       }
   71       
   72       public Set getExcludeMethodsSet() {
   73       	return excludeMethods;
   74       }
   75   
   76       public void setIncludeMethods(String includeMethods) {
   77           this.includeMethods = TextParseUtil.commaDelimitedStringToSet(includeMethods);
   78       }
   79       
   80       public Set getIncludeMethodsSet() {
   81       	return includeMethods;
   82       }
   83   
   84       public String intercept(ActionInvocation invocation) throws Exception {
   85           if (applyInterceptor(invocation)) {
   86               return doIntercept(invocation);
   87           } 
   88           return invocation.invoke();
   89       }
   90   
   91       protected boolean applyInterceptor(ActionInvocation invocation) {
   92           String method = invocation.getProxy().getMethod();
   93           // ValidationInterceptor
   94           boolean applyMethod = MethodFilterInterceptorUtil.applyMethod(excludeMethods, includeMethods, method);
   95           if (log.isDebugEnabled()) {
   96           	if (!applyMethod) {
   97           		log.debug("Skipping Interceptor... Method [" + method + "] found in exclude list.");
   98           	}
   99           }
  100           return applyMethod;
  101       }
  102       
  103       /**
  104        * Subclasses must override to implement the interceptor logic.
  105        * 
  106        * @param invocation the action invocation
  107        * @return the result of invocation
  108        * @throws Exception
  109        */
  110       protected abstract String doIntercept(ActionInvocation invocation) throws Exception;
  111       
  112   }

Save This Page
Home » xwork-2.1.1-src » com.opensymphony.xwork2.interceptor » [javadoc | source]