| « | Mar.2026 | » | | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | | | | | |
| 公告 |
| 不得窥道门,不得悟佛门,不得入窄门,实乃破门。 |
| Blog信息 |
|
blog名称:破门点滴 日志总数:161 评论数量:404 留言数量:-2 访问次数:1448648 建立时间:2004年11月13日 |

| |
| [开发笔记]在Triones中引入xWork+Webwork对Action的支持 心得体会, 软件技术 破门 发表于 2005/1/14 13:34:17 | |
在Triones中引入xWork+Webwork对Action的支持:
主要思路:
通过Eclipse的扩展点配置替换xwork.xml,实现action由插件中加载。
具体实现:
第一步:通过扩展 Webwork 的ServletDispatcher 同时实现 ITrionesController接口,将Triones框架的Servlet请求传递到Webwork框架中。
在ITrionesController的dispach() 方法中调用 Webwork中 ServletDispathcer 的service() 方法。
运行时发现 ServletDispather 未能初始化servlet 环境,因此在ItrionerController接口中增加 init() 方法解决servlet环境初始化的问题。
此外,因为不能正确获得Servlet环境导致 getApplicationMap() 方法错误,所以在TrionesWebworkServletController中覆盖ServletDispather的getApplicationMap() 方法。
第二步:,通过Eclipse扩展点实现 xWork 的Action配置:
1、考虑了一下xWork架构,有三种途径可以实现对Action配置的修改:
//* 方法一: 覆盖ActionProxyFactory来创建xwork action, 对interceptor的支持将不完整。
// ActionProxyFactory.setFactory(new TrionesActionProxyFactory(true, false));
// * 方法二: 覆盖ConfigurationProvider来获取配置(难度较大)
// ConfigurationManager.addConfigurationProvider(new TrionesConfigurationProvider());
// * 方法三: 覆盖AcionProxy重载ActionConfig的生成
ActionProxyFactory.setFactory(new TrionesActionProxyFactory(true, true));
经过测试后的综合考虑,决定采用第三种方案实现,就是覆盖xWork 的DefaultActionProxy。
public ActionProxy createActionProxy(String namespace, String actionName,
Map extraContext, boolean executeResult) throws Exception {
return new TrionesActionProxy(namespace, actionName, extraContext,
executeResult);
}
但是实际运行时发现 xwork 的DefaultActionProxy 未定义默认的建构函数,因此在继承时必须显式的调用其定义的建构函数
// TODO 无法拦截xwork的配置异常,必须有默认的配置文件。
// xwork 仍会尝试加载xwork.xml配置
// super(namespace, actionName, extraContext, executeResult);
此配置文件因为在Eclipse插件环境中不能正确定位,因此建构函数的异常不能拦截,只能直接去实现ActionProxy接口。
2、截取ActionConfig
在TrioneActionProxy 对象中通过Eclipse扩展点配置重新组装xwork的 ActionConfig:
config = TrionesActionConfiguration.getTrionesActionConfig(namespace,
actionName);
3、TrionesActionConfiguration的实现
public static ActionConfig getTrionesActionConfig(String namespace, String actionName) {
loadActions(); //读取TrionesAction配置
TrionesActionInfo actionInfo
= (TrionesActionInfo) actions.get(actionName);
…
ActionConfig actionConfig = new ActionConfig();//创建xwork配置
// 这里是由TrionesActionInvocation根据actionName寻找,
// 因此不是action 的实际ClassName
actionConfig.setClassName(actionName);
// TODO actionInfo 支持 MethodName 定义
actionConfig.setMethodName(null);
// TODO actionInfo 支持 Package 定义
actionConfig.setPackageName("default");
// TODO actionInfo 支持 Parameters 定义
actionConfig.setParams(null);
// 设置results
HashMap results = new HashMap();
Iterator it = actionInfo.getResults();
while(it.hasNext()) {
TrionesResultInfo resultInfo = (TrionesResultInfo) it.next();
// 设置 ResultConfig
ResultConfig resultConfig = new ResultConfig();
// (TrionesResultInfo) resultTypes.get(resultName);
resultConfig.setClassName(resultInfo.getClass().getName());
resultConfig.setName(resultInfo.getName());
// TODO 对Result的 Parameters 支持
resultConfig.setParams(null);
// resultConfig.
results.put(resultInfo.getName(), resultConfig);
}
actionConfig.setResults(results);
// TODO 设置interceptors, 直接put object list
Vector its = new Vector();
it = actionInfo.getInteceptors();
while(it.hasNext()) {
String itName = (String) it.next();
// 设置 Interceptors
Object itInfo = interceptors.get(itName);
its.add(itInfo);
}
// List itl = ;
// itl.addAll()
// actionConfig.addInterceptors(new Vector(itcs.values()));
actionConfig.addInterceptors(its);
return actionConfig;
} | |
|