com.opensymphony.xwork.interceptor.annotations
Class AnnotationWorkflowInterceptor

java.lang.Object
  extended by com.opensymphony.xwork.interceptor.annotations.AnnotationWorkflowInterceptor
All Implemented Interfaces:
com.opensymphony.xwork.interceptor.Interceptor, com.opensymphony.xwork.interceptor.PreResultListener, Serializable

public class AnnotationWorkflowInterceptor
extends Object
implements com.opensymphony.xwork.interceptor.Interceptor, com.opensymphony.xwork.interceptor.PreResultListener

Invokes any annotated methods on the action. Specifically, it supports the following annotations:

There can be multiple methods marked with the same annotations, but the order of their execution is not guaranteed. However, the annotated methods on the superclass chain are guaranteed to be invoked before the annotated method in the current class in the case of a Before annotations and after, if the annotations is After.

 
  public class BaseAnnotatedAction {
        protected String log = "";

        @Before
        public String baseBefore() {
                log = log + "baseBefore-";
                return null;
        }
  }

  public class AnnotatedAction extends BaseAnnotatedAction {
        @Before
        public String before() {
                log = log + "before";
                return null;
        }

        public String execute() {
                log = log + "-execute";
                return Action.SUCCESS;
        }

        @BeforeResult
        public void beforeResult() throws Exception {
                log = log +"-beforeResult";
        }

        @After
        public void after() {
                log = log + "-after";
        }
  }
 
  

With the interceptor applied and the action executed on AnnotatedAction the log instance variable will contain baseBefore-before-execute-beforeResult-after.

Configure a stack in xwork.xml that replaces the PrepareInterceptor with the AnnotationWorkflowInterceptor:

 
 
        
        
        
        
 
  
 

Author:
Zsolt Szasz, zsolt at lorecraft dot com, Rainer Hermanns
See Also:
Serialized Form

Constructor Summary
AnnotationWorkflowInterceptor()
           
 
Method Summary
 void beforeResult(com.opensymphony.xwork.ActionInvocation invocation, String resultCode)
          Invokes any @BeforeResult annotated methods
 void destroy()
           
 void init()
           
 String intercept(com.opensymphony.xwork.ActionInvocation invocation)
          Discovers annotated methods on the action and calls them according to the workflow
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnnotationWorkflowInterceptor

public AnnotationWorkflowInterceptor()
Method Detail

intercept

public String intercept(com.opensymphony.xwork.ActionInvocation invocation)
                 throws Exception
Discovers annotated methods on the action and calls them according to the workflow

Specified by:
intercept in interface com.opensymphony.xwork.interceptor.Interceptor
Throws:
Exception
See Also:
Interceptor.intercept(com.opensymphony.xwork.ActionInvocation)

destroy

public void destroy()
Specified by:
destroy in interface com.opensymphony.xwork.interceptor.Interceptor

init

public void init()
Specified by:
init in interface com.opensymphony.xwork.interceptor.Interceptor

beforeResult

public void beforeResult(com.opensymphony.xwork.ActionInvocation invocation,
                         String resultCode)
Invokes any @BeforeResult annotated methods

Specified by:
beforeResult in interface com.opensymphony.xwork.interceptor.PreResultListener
See Also:
PreResultListener.beforeResult(com.opensymphony.xwork.ActionInvocation, String)

XWork Project Page