Let's analyze the realization of another interceptor ModelDriven Interceptor, first talk about his design purposes, we know that there is usually an actionformbean in Struts, which is used to encapsulate request data, and this feature in WebWork2.x has been further Play, he can implement two Action drive patterns, they are all information carriers.
Property-Driven
Model-Driven
The most popular explanation is that Property-Driven runs through the entire MVC through the attribute, and Model-Driven is through the Model object throughout the MVC.
Their existence: Model-Drive is a separate class, and Property-Driven must be attached to your custom Action class.
If we use Model-Drive mode, you must add a ModelDriven Interceptor interceptor in the configuration file, transfer the value to our Model Bean, and you must implement the ModelDriven interface in your action to get the model bean. Let's take a look at the specific implementation of this interceptor, to do further analysis, the code is as follows:
Public Class ModelDrivenInterceptor Extends AroundInterceptor {
// ~ Methods
Protected void after (ActionInvocation Dispatcher, String Result) throws Exception {}
Protected void before (actioninvocation invocation) throws exception {
Action action = invocation.getAction ();
an Action InstanceOf Modeldriven {
// Determine whether the action implements the ModelDriven interface, if this modeldriven interface is implemented, he will transfer information to the model corresponding to this Action.
ModelDriven modelDriven = (modelDriven) action;
Ognwaestack stack = invocation.getStack ();
// Used to get model bean in action, and press OgnwaStack
Stack.push (ModelDriven.getModel ());
}
}
}
For specific information about OGNLVALUESTACK, please refer to http://www.ognl.org
From the above Public String Intercept (ActionInvocation Invocation) method we can see that all interceptors are executed through actionInvocation, we can call DefaultActionInvocation for the Xwork1.x scheduler, saying here I want everyone to WebWork2 The .x interceptor also has a probably a probably.
Since DefaultActionInvocation is a scheduler of xwork1.x, it does not analyze him saying that it can't be said. Next, we analyze the source code of the ActionInvocation's implementation of the DEFAULTACTIONINVOCATION, so that
Since some code of DefaultActionInvocation is also analyzed before, the following is not analyzed by the code to complete a brief analysis.
Public class defaultActioninvocation imports actionInvocation {
// The result is an interface here, and ActionchainResult is a implementation of his purpose is to process Action Chain, here's the following instructions for Action Chain:
Usually an action is executed, or returns a form, either return another action, continue to execute, if returned Action, the action chain action chain is formed, then continue this new action until a non-chain result is returned
Public Result getResult () throws exception {result returnResult = result;
// if we've chained to other actions, we need to find the last result
While (ReturnResult InstanceOf ActionchainResult) {
ActionProxy Aproxy = (ActionchainResult) ReturnResult) .GetProxy ();
IF (APROXY! = null) {
Result proxyResult = APROXY.GETINVOCATION (). GetResult ();
IF ((proxyResult! = null) && (APROXY.GETEXECUTERESULT ())) {
ReturnResult = proxyResult;
Else {Break;
Else {Break;
}
Return ReturnResult;
}
/ / Return Stack
Public OgnvaluestAck getStack () {
Return stack;
}
...
// The following method I will not go to it, I think everyone is to see the name should also understand it. If you have any questions, please refer to the previous analysis.
protected void createction () {
// load action
Try {
Action = ObjectFactory.getObjectFactory (). BuildAction (Proxy.getConfig ());
...
}
Protected String InvokeAction (Action Action, ActionConfig ActionConfig) Throws Exception {
IF (Proxy.getConfig (). getMethodName () == null) {
Return getAction (). EXECUTE ();
...
}
}