001: /*
002: * Copyright (c) 2002-2006 by OpenSymphony
003: * All rights reserved.
004: */
005:
006: package com.opensymphony.xwork.interceptor;
007:
008: import java.util.Collections;
009: import java.util.Set;
010:
011: import org.apache.commons.logging.Log;
012: import org.apache.commons.logging.LogFactory;
013:
014: import com.opensymphony.xwork.ActionInvocation;
015: import com.opensymphony.xwork.util.TextParseUtil;
016:
017: /**
018: * <!-- START SNIPPET: javadoc -->
019: *
020: * An abstract <code>Interceptor</code> that is applied to selectively according
021: * to specified included/excluded method lists.
022: *
023: * <p/>
024: *
025: * Setable parameters are as follows:
026: *
027: * <ul>
028: * <li>excludeMethods - methods name to be excluded</li>
029: * <li>includeMethods - methods name to be included</li>
030: * </ul>
031: *
032: * <p/>
033: *
034: * <b>NOTE:</b> If method name are available in both includeMethods and
035: * excludeMethods, it will still be considered as an included method. In short
036: * includeMethods takes precedence over excludeMethods.
037: *
038: * <p/>
039: *
040: * Interceptors that extends this capability would be :-
041: *
042: * <ul>
043: * <li>TokenInterceptor</li>
044: * <li>TokenSessionStoreInterceptor</li>
045: * <li>DefaultWorkflowInterceptor</li>
046: * <li>ValidationInterceptor</li>
047: * </ul>
048: *
049: * <!-- END SNIPPET: javadoc -->
050: *
051: * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
052: * @author Rainer Hermanns
053: *
054: * @see com.opensymphony.webwork.interceptor.TokenInterceptor
055: * @see com.opensymphony.webwork.interceptor.TokenSessionStoreInterceptor
056: * @see com.opensymphony.xwork.interceptor.DefaultWorkflowInterceptor
057: * @see com.opensymphony.xwork.validator.ValidationInterceptor
058: *
059: * @version $Date: 2006-05-15 09:42:45 +0200 (Mo, 15 Mai 2006) $ $Id: MethodFilterInterceptor.java 1017 2006-05-15 07:42:45Z tmjee $
060: */
061: public abstract class MethodFilterInterceptor implements Interceptor {
062: protected transient Log log = LogFactory.getLog(getClass());
063:
064: protected Set excludeMethods = Collections.EMPTY_SET;
065: protected Set includeMethods = Collections.EMPTY_SET;
066:
067: public void setExcludeMethods(String excludeMethods) {
068: this .excludeMethods = TextParseUtil
069: .commaDelimitedStringToSet(excludeMethods);
070: }
071:
072: public Set getExcludeMethodsSet() {
073: return excludeMethods;
074: }
075:
076: public void setIncludeMethods(String includeMethods) {
077: this .includeMethods = TextParseUtil
078: .commaDelimitedStringToSet(includeMethods);
079: }
080:
081: public Set getIncludeMethodsSet() {
082: return includeMethods;
083: }
084:
085: public String intercept(ActionInvocation invocation)
086: throws Exception {
087: if (applyInterceptor(invocation)) {
088: return doIntercept(invocation);
089: }
090: return invocation.invoke();
091: }
092:
093: protected boolean applyInterceptor(ActionInvocation invocation) {
094: String method = invocation.getProxy().getMethod();
095: // ValidationInterceptor
096: boolean applyMethod = MethodFilterInterceptorUtil.applyMethod(
097: excludeMethods, includeMethods, method);
098: if (log.isDebugEnabled()) {
099: if (!applyMethod) {
100: log.debug("Skipping Interceptor... Method [" + method
101: + "] found in exclude list.");
102: }
103: }
104: return applyMethod;
105: }
106:
107: /**
108: * Subclasses must override to implement the interceptor logic.
109: *
110: * @param invocation the action invocation
111: * @return the result of invocation
112: * @throws Exception
113: */
114: protected abstract String doIntercept(ActionInvocation invocation)
115: throws Exception;
116:
117: public void destroy() {
118: }
119:
120: public void init() {
121: }
122: }
|