1.1.1 actioninvocation class
Actioninvocation is defined as an interface to show the execution status of an action. It has the interceptor and action instances. Execute the invoke method repeatedly. The request is first sent to the actionproxy and then to the Interceptor. After all the interceptors are executed, they are the action and result.
Figure 3.3.4 main methods of the actioninvocation class
1.1.2 defaactionactioninvocation class
The defaactionactioninvocation class is the implementation class of the actioninvocation interface. It is generally used to instantiate actioninvocation. The main method is as follows:
Figure 3.3.5 main method of the defaultactioninvocation class
Key Method: invoke () method
Executed = false; The default value is false, indicating that the action has not been executed. If executed, an execution exception is thrown.
Then, determine whether the interceptor has been configured. If the interceptor is configured, the interceptor configuration class interceptormapping will be obtained from the configuration information. This class only contains two attributes: Name and interceptor instance.
PublicString invoke ()ThrowsException { String profilekey = "INVOKE :"; Try{ Utiltimerstack.Push(Profilekey ); If(Executed ){ Throw newIllegalstateexception ("action has already executed "); } // Recursively execute interceptor If(Interceptors. hasnext ()) {// Interceptors are interceptormapping actually an interceptor chain like // filterchain // Call invocation. Invoke () to implement recursive callback Loop FinalInterceptormapping interceptor = interceptors. Next (); String interceptormsg = "Interceptor:" + Interceptor. getname (); Utiltimerstack.Push(Interceptormsg ); Try{ // Return invocation. Invoke () in each interceptor Method () Resultcode = Interceptor. getinterceptor (). Intercept (defaultactioninvocation.This); } Finally{ Utiltimerstack.Pop(Interceptormsg ); } }Else{ // When all interceptors are completed and finally the action is executed, invokeactiononly will call // invokeaction () method Resultcode = invokeactiononly (); } |
|
// This is needed because the result will be executed, then control will return to the interceptor, which will // Return abve and flow through again // Call preresultlisteners before the result is returned. // Execute only once through executed Control If(! Executed ){ If(Preresultlisteners! =Null){ For(Object preresultlistener: preresultlisteners ){ Preresultlistener listener = (preresultlistener) preresultlistener; String _ profilekey = "preresultlistener :"; Try{ Utiltimerstack.Push(_ Profilekey ); Listener. beforeresult (This, Resultcode ); } Finally{ Utiltimerstack.Pop(_ Profilekey ); } } } // Now execute the result, if we're re supposed // Execute result. If(Proxy. getexecuteresult ()){ Executeresult (); } Executed =True; } ReturnResultcode; } Finally{ Utiltimerstack.Pop(Profilekey ); } } |
|