Commits

Anonymous committed 2824220

Removed the AroundInterceptor, and added a simple AbstractInterceptor to remove all
the empty init/destroy methods. I think a future feature improvement will be changing
them anyways.

Issue number: XW-393

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@1045e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits e60a7e2

Comments (0)

Files changed (20)

File src/java/com/opensymphony/xwork/interceptor/AbstractInterceptor.java

+/*
+ * Copyright (c) 2002-2006 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.interceptor;
+
+import com.opensymphony.xwork.ActionInvocation;
+
+/**
+ * Provides default implementations of optional lifecycle methods
+ */
+public abstract class AbstractInterceptor implements Interceptor {
+
+    /**
+     * Does nothing
+     */
+    public void init() {
+    }
+    
+    /**
+     * Does nothing
+     */
+    public void destroy() {
+    }
+
+
+    /**
+     * Override to handle interception
+     */
+    public abstract String intercept(ActionInvocation invocation) throws Exception;
+}

File src/java/com/opensymphony/xwork/interceptor/AliasInterceptor.java

  *
  * @author Matthew Payne
  */
-public class AliasInterceptor extends AroundInterceptor {
+public class AliasInterceptor extends AbstractInterceptor {
     private static final Log log = LogFactory.getLog(AliasInterceptor.class);
     private static final String DEFAULT_ALIAS_KEY = "aliases";
 
         this.aliasesKey = aliasesKey;
     }
 
-    public void destroy() {
-    }
-
-    public void init() {
-    }
+    public String intercept(ActionInvocation invocation) throws Exception {
 
-    protected void before(ActionInvocation invocation) throws Exception {
         ActionConfig config = invocation.getProxy().getConfig();
         ActionContext ac = invocation.getInvocationContext();
 
                 log.debug("invalid alias expression:" + aliasesKey);
             }
         }
-    }
-
-    protected void after(ActionInvocation invocation, String result) throws Exception {
+        
+        return invocation.invoke();
     }
 }

File src/java/com/opensymphony/xwork/interceptor/AroundInterceptor.java

-/*
- * Copyright (c) 2002-2006 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.xwork.interceptor;
-
-import com.opensymphony.xwork.ActionInvocation;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-
-/**
- * An abstract interceptor that provides simple access to before/after callouts.
- *
- * @author Jason Carreira
- */
-public abstract class AroundInterceptor implements Interceptor {
-
-    protected transient Log log = LogFactory.getLog(getClass());
-
-    public void destroy() {
-    }
-
-    public void init() {
-    }
-
-    public String intercept(ActionInvocation invocation) throws Exception {
-        String result = null;
-
-        before(invocation);
-        result = invocation.invoke();
-        after(invocation, result);
-
-        return result;
-    }
-
-    /**
-     * Called after the invocation has been executed.
-     *
-     * @param result the result value returned by the invocation
-     */
-    protected abstract void after(ActionInvocation dispatcher, String result) throws Exception;
-
-    /**
-     * Called before the invocation has been executed.
-     */
-    protected abstract void before(ActionInvocation invocation) throws Exception;
-}

File src/java/com/opensymphony/xwork/interceptor/ChainingInterceptor.java

  * @author tm_jee ( tm_jee(at)yahoo.co.uk )
  * @version $Revision$
  */
-public class ChainingInterceptor extends AroundInterceptor {
+public class ChainingInterceptor extends AbstractInterceptor {
 	
 	private static final Log _log = LogFactory.getLog(ChainingInterceptor.class);
 	
     Collection excludes;
     Collection includes;
 
-    protected void after(ActionInvocation invocation, String result) throws Exception {
-    }
-
-    protected void before(ActionInvocation invocation) throws Exception {
+    public String intercept(ActionInvocation invocation) throws Exception {
         OgnlValueStack stack = invocation.getStack();
         CompoundRoot root = stack.getRoot();
 
                 }
             }
         }
+        return invocation.invoke();
     }
-
+    
     public Collection getExcludes() {
         return excludes;
     }

File src/java/com/opensymphony/xwork/interceptor/ConversionErrorInterceptor.java

  *
  * @author Jason Carreira
  */
-public class ConversionErrorInterceptor extends AroundInterceptor {
+public class ConversionErrorInterceptor extends AbstractInterceptor {
     public static final String ORIGINAL_PROPERTY_OVERRIDE = "original.property.override";
 
     protected Object getOverrideExpr(ActionInvocation invocation, Object value) {
         return "'" + value + "'";
     }
 
-    protected void after(ActionInvocation dispatcher, String result) throws Exception {
-    }
+    public String intercept(ActionInvocation invocation) throws Exception {
 
-    protected void before(ActionInvocation invocation) throws Exception {
         ActionContext invocationContext = invocation.getInvocationContext();
         Map conversionErrors = invocationContext.getConversionErrors();
         OgnlValueStack stack = invocationContext.getValueStack();
                 }
             });
         }
+        return invocation.invoke();
     }
 
     protected boolean shouldAddError(String propertyName, Object value) {

File src/java/com/opensymphony/xwork/interceptor/ExceptionMappingInterceptor.java

  * @author Matthew E. Porter (matthew dot porter at metissian dot com) 
  * @author Claus Ibsen
  */
-public class ExceptionMappingInterceptor implements Interceptor {
+public class ExceptionMappingInterceptor extends AbstractInterceptor {
     
     protected static final Log log = LogFactory.getLog(ExceptionMappingInterceptor.class);
 
 		this.logLevel = logLevel;
 	}
 
-	public void destroy() {
-    }
-
-    public void init() {
-    }
-
     public String intercept(ActionInvocation invocation) throws Exception {
         String result;
 

File src/java/com/opensymphony/xwork/interceptor/ExternalReferencesInterceptor.java

  *         Reference Resolution is encapsulated in an interceptor so that the user can configure when references should
  *         be resloved
  */
-public class ExternalReferencesInterceptor extends AroundInterceptor {
+public class ExternalReferencesInterceptor extends AbstractInterceptor {
 
-    protected void after(ActionInvocation dispatcher, String result) throws Exception {
-    }
+    public String intercept(ActionInvocation invocation) throws Exception {
 
-    protected void before(ActionInvocation invocation) throws Exception {
         String packageName = invocation.getProxy().getConfig().getPackageName();
         PackageConfig packageConfig = XWorkStatic.getConfigurationManager().getConfiguration().getPackageConfig(packageName);
 
                 erResolver.resolveReferences(invocation);
             }
         }
+        return invocation.invoke();
     }
 }

File src/java/com/opensymphony/xwork/interceptor/I18nInterceptor.java

  *
  * @author Aleksei Gopachenko
  */
-public class I18nInterceptor implements Interceptor {
+public class I18nInterceptor extends AbstractInterceptor {
     protected static final Log log = LogFactory.getLog(I18nInterceptor.class);
 
     public static final String DEFAULT_SESSION_ATTRIBUTE = "WW_TRANS_I18N_LOCALE";
         this.attributeName = attributeName;
     }
 
-    public void init() {
-        if (log.isDebugEnabled()) log.debug("init()");
-    }
-
-    public void destroy() {
-        if (log.isDebugEnabled()) log.debug("destroy()");
-    }
-
     public String intercept(ActionInvocation invocation) throws Exception {
         if (log.isDebugEnabled()) {
             log.debug("intercept '"

File src/java/com/opensymphony/xwork/interceptor/LoggingInterceptor.java

  *
  * @author Jason Carreira
  */
-public class LoggingInterceptor extends AroundInterceptor {
+public class LoggingInterceptor extends AbstractInterceptor {
     private static final Log log = LogFactory.getLog(LoggingInterceptor.class);
     private static final String FINISH_MESSAGE = "Finishing execution stack for action ";
     private static final String START_MESSAGE = "Starting execution stack for action ";
 
-    protected void after(ActionInvocation invocation, String result) throws Exception {
+    public String intercept(ActionInvocation invocation) throws Exception {
         logMessage(invocation, FINISH_MESSAGE);
-    }
-
-    protected void before(ActionInvocation invocation) throws Exception {
+        String result = invocation.invoke();
         logMessage(invocation, START_MESSAGE);
+        return result;
     }
 
     private void logMessage(ActionInvocation invocation, String baseMessage) {

File src/java/com/opensymphony/xwork/interceptor/MethodFilterInterceptor.java

  * 
  * @version $Date$ $Id$
  */
-public abstract class MethodFilterInterceptor implements Interceptor {
+public abstract class MethodFilterInterceptor extends AbstractInterceptor {
     protected transient Log log = LogFactory.getLog(getClass());
     
     protected Set excludeMethods = Collections.EMPTY_SET;
      */
     protected abstract String doIntercept(ActionInvocation invocation) throws Exception;
     
-    public void destroy() {
-    }
-
-    public void init() {
-    }
 }

File src/java/com/opensymphony/xwork/interceptor/ModelDrivenInterceptor.java

  * @author tm_jee
  * @version $Date$ $Id$
  */
-public class ModelDrivenInterceptor extends AroundInterceptor {
+public class ModelDrivenInterceptor extends AbstractInterceptor {
 
-    protected void after(ActionInvocation dispatcher, String result) throws Exception {
-    }
-
-    protected void before(ActionInvocation invocation) throws Exception {
+    public String intercept(ActionInvocation invocation) throws Exception {
         Object action = invocation.getAction();
 
         if (action instanceof ModelDriven) {
             	stack.push(modelDriven.getModel());
             }
         }
+        return invocation.invoke();
     }
 }

File src/java/com/opensymphony/xwork/interceptor/ParameterFilterInterceptor.java

  *
  * @author Gabe
  */
-public class ParameterFilterInterceptor implements Interceptor {
+public class ParameterFilterInterceptor extends AbstractInterceptor {
 
     private static final Log LOG = LogFactory.getLog(ParameterFilterInterceptor.class);
 
 
     private boolean defaultBlock = false;
 
-    public void destroy() {
-    }
-
-    public void init() {
-    }
-
     public String intercept(ActionInvocation invocation) throws Exception {
 
         Map parameters = invocation.getInvocationContext().getParameters();

File src/java/com/opensymphony/xwork/interceptor/ParametersInterceptor.java

  *
  * @author Patrick Lightbody
  */
-public class ParametersInterceptor extends AroundInterceptor {
+public class ParametersInterceptor extends AbstractInterceptor {
 
     private static final Log LOG = LogFactory.getLog(ParametersInterceptor.class);
 
-    protected void after(ActionInvocation dispatcher, String result) throws Exception {
-    }
-
-    protected void before(ActionInvocation invocation) throws Exception {
+    public String intercept(ActionInvocation invocation) throws Exception {
         if (!(invocation.getAction() instanceof NoParameters)) {
             ActionContext ac = invocation.getInvocationContext();
             final Map parameters = ac.getParameters();
 
-            if (log.isDebugEnabled()) {
-                log.debug("Setting params " + getParameterLogMap(parameters));
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Setting params " + getParameterLogMap(parameters));
             }
 
             if (parameters != null) {
                 }
             }
         }
+        return invocation.invoke();
     }
 
     protected void setParameters(Object action, OgnlValueStack stack, final Map parameters) {

File src/java/com/opensymphony/xwork/interceptor/PrepareInterceptor.java

  * @author tm_jee
  * @see com.opensymphony.xwork.Preparable
  */
-public class PrepareInterceptor extends AroundInterceptor {
+public class PrepareInterceptor extends AbstractInterceptor {
 	
 	private static final long serialVersionUID = -5216969014510719786L;
 
 		this.alwaysInvokePrepare = Boolean.parseBoolean(alwaysInvokePrepare);
 	}
 	
-    protected void after(ActionInvocation dispatcher, String result) throws Exception {
-    }
-
-    protected void before(ActionInvocation invocation) throws Exception {
+    public String intercept(ActionInvocation invocation) throws Exception {
         Object action = invocation.getAction();
 
         if (action instanceof Preparable) {
-        	try {
-        		PrefixMethodInvocationUtil.invokePrefixMethod(invocation, 
-        			new String[] { PREPARE_PREFIX, ALT_PREPARE_PREFIX });
-        	}
-        	catch(Exception e) {
-        		// just in case there's an exception while doing reflection, 
-        		// we still want prepare() to be able to get called.
-        		_log.warn("an exception occured while trying to execute prefixed method", e);
-        	}
-        	if (alwaysInvokePrepare) {
-        		((Preparable) action).prepare();
-        	}
+            	try {
+            		PrefixMethodInvocationUtil.invokePrefixMethod(invocation, 
+            			new String[] { PREPARE_PREFIX, ALT_PREPARE_PREFIX });
+            	}
+            	catch(Exception e) {
+            		// just in case there's an exception while doing reflection, 
+            		// we still want prepare() to be able to get called.
+            		_log.warn("an exception occured while trying to execute prefixed method", e);
+            	}
+            	if (alwaysInvokePrepare) {
+            		((Preparable) action).prepare();
+            	}
         }
+        return invocation.invoke();
     }
 }

File src/java/com/opensymphony/xwork/interceptor/StaticParametersInterceptor.java

 import java.util.Iterator;
 import java.util.Map;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 
 /**
  * <!-- START SNIPPET: description -->
  *
  * @author Patrick Lightbody
  */
-public class StaticParametersInterceptor extends AroundInterceptor {
+public class StaticParametersInterceptor extends AbstractInterceptor {
 
     private boolean parse;
+    
+    private static final Log LOG = LogFactory.getLog(StaticParametersInterceptor.class);
 
     public void setParse(String value) {
         this.parse = Boolean.valueOf(value).booleanValue();
     }
 
-    protected void after(ActionInvocation invocation, String result) throws Exception {
-    }
-
-    protected void before(ActionInvocation invocation) throws Exception {
+    public String intercept(ActionInvocation invocation) throws Exception {
         ActionConfig config = invocation.getProxy().getConfig();
         Object action = invocation.getAction();
 
         final Map parameters = config.getParams();
 
-        if (log.isDebugEnabled()) {
-            log.debug("Setting static parameters " + parameters);
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Setting static parameters " + parameters);
         }
 
         // for actions marked as Parameterizable, pass the static parameters directly
                 stack.setValue(entry.getKey().toString(), val);
             }
         }
+        return invocation.invoke();
     }
 }

File src/java/com/opensymphony/xwork/interceptor/TimerInterceptor.java

  * @author Jason Carreira
  * @author Claus Ibsen
  */
-public class TimerInterceptor implements Interceptor {
+public class TimerInterceptor extends AbstractInterceptor {
     protected static final Log log = LogFactory.getLog(TimerInterceptor.class);
 
     protected Log categoryLogger;
         this.logLevel = logLevel;
     }
 
-    public void destroy() {
-    }
-
-    public void init() {
-    }
-
     public String intercept(ActionInvocation invocation) throws Exception {
         if (! shouldLog()) {
             return invocation.invoke();

File src/java/com/opensymphony/xwork/spring/interceptor/ActionAutowiringInterceptor.java

 
 import com.opensymphony.xwork.ActionContext;
 import com.opensymphony.xwork.ActionInvocation;
-import com.opensymphony.xwork.interceptor.AroundInterceptor;
+import com.opensymphony.xwork.interceptor.Interceptor;
 import com.opensymphony.xwork.spring.SpringObjectFactory;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
  * @author Simon Stewart
  * @author Eric Hauser
  */
-public class ActionAutowiringInterceptor extends AroundInterceptor implements ApplicationContextAware {
+public class ActionAutowiringInterceptor implements Interceptor, ApplicationContextAware {
     private static final Log log = LogFactory.getLog(ActionAutowiringInterceptor.class);
 
     public static final String APPLICATION_CONTEXT = "com.opensymphony.xwork.spring.interceptor.ActionAutowiringInterceptor.applicationContext";
         this.autowireStrategy = autowireStrategy;
     }
 
-    /**
-     * @param dispatcher
-     * @param result
-     * @throws Exception
-     */
-    protected void after(ActionInvocation dispatcher, String result) throws Exception {
-        // Empty
+    public void init() {
+    }
+    
+    public void destroy() {
     }
 
+    
     /**
      * Looks for the <code>ApplicationContext</code> under the attribute that the Spring listener sets in
      * the servlet context.  The configuration is done the first time here instead of in init() since the
      * @param invocation
      * @throws Exception
      */
-    protected void before(ActionInvocation invocation) throws Exception {
+    public String intercept(ActionInvocation invocation) throws Exception {
         if (!initialized) {
             ApplicationContext applicationContext = (ApplicationContext) ActionContext.getContext().getApplication().get(
                     WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
             initialized = true;
         }
 
-        if (factory == null)
-            return;
-
-        Object bean = invocation.getAction();
-        factory.autoWireBean(bean);
-
-        ActionContext.getContext().put(APPLICATION_CONTEXT, context);
+        if (factory != null) {
+            Object bean = invocation.getAction();
+            factory.autoWireBean(bean);
+    
+            ActionContext.getContext().put(APPLICATION_CONTEXT, context);
+        }
+        return invocation.invoke();
     }
 
     /**

File src/test/com/opensymphony/xwork/interceptor/ModelDrivenInterceptorTest.java

         action = new ModelDrivenAction();
         mockActionInvocation.expectAndReturn("getAction", action);
         mockActionInvocation.expectAndReturn("getStack", stack);
+        mockActionInvocation.expectAndReturn("invoke", "foo");
 
-        modelDrivenInterceptor.before((ActionInvocation) mockActionInvocation.proxy());
+        modelDrivenInterceptor.intercept((ActionInvocation) mockActionInvocation.proxy());
 
         Object topOfStack = stack.pop();
         assertEquals("our model should be on the top of the stack", model, topOfStack);
     public void testStackNotModifedForNormalAction() throws Exception {
         action = new ActionSupport();
         mockActionInvocation.expectAndReturn("getAction", action);
+        mockActionInvocation.expectAndReturn("invoke", "foo");
 
         // nothing should happen
-        modelDrivenInterceptor.before((ActionInvocation) mockActionInvocation.proxy());
+        modelDrivenInterceptor.intercept((ActionInvocation) mockActionInvocation.proxy());
     }
 
     protected void setUp() throws Exception {

File src/test/com/opensymphony/xwork/interceptor/PrepareInterceptorTest.java

         mai.setAction(mock.proxy());
         mock.expect("prepare");
 
-        interceptor.before(mai);
-        interceptor.after(mai, Action.SUCCESS); // to have higher code coverage
+        interceptor.intercept(mai);
     }
 
     public void testNoPrepareCalled() throws Exception {
         MockActionInvocation mai = new MockActionInvocation();
         mai.setAction(new SimpleFooAction());
 
-        interceptor.before(mai);
-        interceptor.after(mai, Action.SUCCESS); // to have higher code coverage
+        interceptor.intercept(mai);
     }
     
     public void testPrefixInvocation1() throws Exception {

File src/test/com/opensymphony/xwork/spring/interceptor/ActionAutowiringInterceptorTest.java

         interceptor.setApplicationContext(context);
         interceptor.init();
 
-        interceptor.before(invocation);
+        interceptor.intercept(invocation);
 
         assertEquals(bean, action.getBean());
     }
         SimpleAction action = new SimpleAction();
         ActionInvocation invocation = new TestActionInvocation(action);
 
-        interceptor.before(invocation);
+        interceptor.intercept(invocation);
 
         ApplicationContext loadedContext = interceptor.getApplicationContext();
 
         SimpleAction action = new SimpleAction();
         ActionInvocation invocation = new TestActionInvocation(action);
 
-        interceptor.before(invocation);
+        interceptor.intercept(invocation);
 
         ApplicationContext loadedContext = interceptor.getApplicationContext();
 
 
         // If an exception is thrown here, things are going to go wrong in
         // production
-        interceptor.before(invocation);
+        interceptor.intercept(invocation);
 
         assertEquals(bean, action.getBean());
     }