Xwork 通过Interceptor 实现了这一步骤,从而我们可以根据需要,灵活的配置所需的
Interceptor。从而为Action提供可扩展的预处理、后处理过程。
度,也正是由ActionInvocation负责。
ActionInvocation 是一个接口, 而DefaultActionInvocation 则是Webwork 对
ActionInvocation的默认实现。
1.ActionInvocation初始化时,根据配置,加载Action相关的所有Interceptor
private void init() throws Exception {
……
List interceptorList = new
ArrayList(proxy.getConfig().getInterceptors());
interceptors = interceptorList.iterator();
}
2.通过ActionInvocation.invoke方法调用Action实现时,执行Interceptor:
public String invoke() throws Exception {
//调用intercaptors
if (interceptors.hasNext()) {
Interceptor interceptor =(Interceptor) interceptors.next();
resultCode = interceptor.intercept(this);
} else {
if (proxy.getConfig().getMethodName() == null) {
resultCode = getAction().execute();
} else {
resultCode = invokeAction(
getAction(),
proxy.getConfig()
);
}
}
……
}
将Webwork传入的Map类型数据结构,转换为Action所需的Java 模型对象。
数据转换的过程并不复杂:
⑴ 首先由ActionContext获得Map型的参数集parameters。
⑵ 由ActionContext获得值栈(OgnlValueStack)。
⑶ 遍历parameters中的各项数据。
⑷ 通过OgnlValueStack,根据数据的键值,为Model 对象填充属性数据。
OgnlValueStack 是 http://www.ognl.org/ 提供的一套可读写对象属性的类库(功能上有点类似
Jakarta Commons BeanUtils,以及Spring BeanWrapper)
OgnlValueStack stack = new OgnlValueStack();
stack.push(new User());//首先将欲赋值对象压入栈中
stack.setValue("name","erica");//为栈顶对象的指定属性名赋值
381



被折叠的 条评论
为什么被折叠?



