Go deep into struts2.0 (7) -- actioninvocation interface and 3defaactionactioninvocation class

Source: Internet
Author: User
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 );

}

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 

 

 

 

 

 

 

 

 

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.