[color=green]ActionProxyFactory: [/color]
create ActionProxy factory,create ActionInvocation,create ActionProxy
[color=green]ActionProxy: [/color]
serves as client code's handle to execute an action,it holds an ActionInvocation which reprents the current satate of the execution of the action.ActionProxy is created by a ActionProxyFactory in a dispatcher.ActionProxy sets up the execute context for the ActionInvocation and then calls invoke() on the ActionInvocation.
[color=green]ActionInvocation: [/color]reprents the current state of the execution of the action,it holds the action instance ,the interceptors to be applied,the map of results,and an ActionContext.
[color=green]ActionContext:[/color] which includes the request parameters,the application map ,the session map,the Local, and the ServletRequest and ServletResponse.
执行过程如下:
(1)在web.xml中指定的ServletDispacter或者FilterDispatcher,负责调用ActionProxyFactory完成ActionProxy的创建,
ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy(namespace, actionName, context);
(2)ActionProxy 为ActionInvocation设定执行环境上下文,并调用ActionInvocation的invoke()方法
(3)关键在于ActionInvocation的invoke()方法,
create ActionProxy factory,create ActionInvocation,create ActionProxy
[color=green]ActionProxy: [/color]
serves as client code's handle to execute an action,it holds an ActionInvocation which reprents the current satate of the execution of the action.ActionProxy is created by a ActionProxyFactory in a dispatcher.ActionProxy sets up the execute context for the ActionInvocation and then calls invoke() on the ActionInvocation.
[color=green]ActionInvocation: [/color]reprents the current state of the execution of the action,it holds the action instance ,the interceptors to be applied,the map of results,and an ActionContext.
[color=green]ActionContext:[/color] which includes the request parameters,the application map ,the session map,the Local, and the ServletRequest and ServletResponse.
执行过程如下:
(1)在web.xml中指定的ServletDispacter或者FilterDispatcher,负责调用ActionProxyFactory完成ActionProxy的创建,
ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy(namespace, actionName, context);
(2)ActionProxy 为ActionInvocation设定执行环境上下文,并调用ActionInvocation的invoke()方法
(3)关键在于ActionInvocation的invoke()方法,
public String invoke() throws Exception {
if (executed) {
throw new IllegalStateException("Action has already executed");
}
if (interceptors.hasNext()) { // notice here is if ,not while
InterceptorMapping interceptor = (InterceptorMapping) interceptors.next();
/** 调用拦截器的方法,将ActionInvocation作为参数
* 在intercept(this);中回调invoke() 方法,是一种递归的方式
*/
resultCode = interceptor.getInterceptor().intercept(this);
} else {
resultCode = invokeActionOnly();//当没有了拦截器没有调用时就invokeAction!然后返回!因为是递归调用的!然后按反顺序返回进行剩下的没完成部分...
}
// 做结果返回前的处理
// this is needed because the result will be executed, then control will return to the Interceptor, which will
// return above and flow through again
if (!executed) {
if (preResultListeners != null) {
for (Iterator iterator = preResultListeners.iterator();
iterator.hasNext();) {
PreResultListener listener = (PreResultListener) iterator.next();
listener.beforeResult(this, resultCode);
}
}
// now execute the result, if we're supposed to
if (proxy.getExecuteResult()) {
//执行结果的返回
executeResult();
}
executed = true;
}
return resultCode;
}