看了看Dom4j,真不错,一个字:“好用!”
把小框架的配置放在了一个xml中:EasyAction.xml,写的还算顺利,一会就土路完了~废话少说,上Source:
/**
* 取得所有Action的配置信息
* */
private void readActionCfg(Element actionConfigElement){
// 遍历actionConfigElement下的所有叫“action”的元素
for ( Iterator actionConfigElementIterator = actionConfigElement.elementIterator("action"); actionConfigElementIterator.hasNext();) {
Element actionElement = (Element) actionConfigElementIterator.next();
// 取得Action名
String actionName = actionElement.attributeValue("name");
// 取得该Action对应的ActionClass名
String actionClassName = actionElement.attributeValue("ActionClass");
// 取得该Action对应的FormClass名
String formClassName = actionElement.attributeValue("FormClass");
// 以(action名,[actionClass名,formClass名])的形式保存数据
classNameMap.put(actionName, new String[]{actionClassName,formClassName});
// 读取该Action的Forward配置
this.readForwardCfg(actionElement);
}
}
/**
* 取得某个Action下的Forward配置信息
* */
private void readForwardCfg(Element actionElement){
// 遍历actionElement下的所有叫“forward”的元素
for ( Iterator actionElementIterator = actionElement.elementIterator("forward"); actionElementIterator.hasNext();) {
Element forwardElement = (Element) actionElementIterator.next();
// 取得Action名
String actionName = actionElement.attributeValue("name");
// 取得ReturnValue
String returnValue = forwardElement.attributeValue("value");
// 取得跳转的目标URL
String forwardURL = forwardElement.attributeValue("url");
// 以(Action名.ReturnValue, URL)的形式保存
forwardPathMap.put(actionName+"."+returnValue, forwardURL);
}
}
这样取得配置信息还真简单,吼吼~ 看来下一步的任务就是处理异常了.
不过貌似下周开始工作就要忙了,恐怕时间有限。