📄 xmlmodelparser.java
字号:
/**
* Copyright 2003-2005 the original author or authors.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jdon.controller.config;
import java.util.Map;
import com.jdon.model.handler.HandlerMetaDef;
import com.jdon.model.mapping.ModelMapping;
import java.util.List;
import java.util.Iterator;
import com.jdon.util.Debug;
import org.jdom.Element;
public class XmlModelParser extends XmlParser{
private final static String module = XmlModelParser.class.getName();
public void parse(Element root, Map mps) throws Exception {
try {
List modelList = root.getChildren("models");
Iterator iter = modelList.iterator();
while (iter.hasNext()) {
Element models = (Element) iter.next();
Iterator i = models.getChildren("model").iterator();
while (i.hasNext()) {
Element model = (Element) i.next();
parseModelConfig(model, mps);
}
}
} catch (Exception e) {
Debug.logError("parse models error: " + e, module);
throw new Exception(e);
}
}
private void parseModelConfig(Element model, Map mps) throws Exception {
try {
ModelMapping mp = new ModelMapping();
mp.setKeyName(model.getAttributeValue("key"));
mp.setClassName(model.getAttributeValue("class"));
Debug.logVerbose(" read Config Model: " + mp.getClassName(), module);
Debug.logVerbose(" key: " + mp.getKeyName(), module);
Element actionFormE = model.getChild("actionForm");
mp.setFormName(actionFormE.getAttributeValue("name"));
Debug.logVerbose(" actionForm name: " + mp.getFormName(), module);
Element handlerE = model.getChild("handler");
if (handlerE != null) {
String classAttr = handlerE.getAttributeValue("class");
if (classAttr != null) {
mp.setHandler(classAttr);
Debug.logVerbose(" handler class: " + mp.getHandler(), module);
}
Debug.logVerbose(" look up service in handler: ", module);
HandlerMetaDef sm = new HandlerMetaDef();
Element serviceE = handlerE.getChild("service");
if (serviceE != null) {
parseHandlerConfig(serviceE, sm);
mp.setHandlerMetaDef(sm);
}
}
mps.put(mp.getFormName(), mp);
} catch (Exception e) {
Debug.logError("parse Model class:"+ model.getAttributeValue("class")+" error: " + e, module);
throw new Exception(e);
}
}
private void parseHandlerConfig(Element serviceE, HandlerMetaDef sm) throws
Exception {
Debug.logVerbose(" find a ejbService in handler: ", module);
try {
sm.setServiceRef(serviceE.getAttributeValue("ref"));
Debug.logVerbose(" service ref: " + sm.getServiceRef(), module);
Element initMethod = serviceE.getChild("initMethod");
if (initMethod != null){
sm.setInitMethod(initMethod.getAttributeValue("name"));
Debug.logVerbose(" initMethod name: " + sm.getInitMethod(), module);
}
Element getMethod = serviceE.getChild("getMethod");
if (getMethod != null){
sm.setFindtMethod(getMethod.getAttributeValue("name"));
Debug.logVerbose(" getMethod name: " + sm.getFindMethod(), module);
}
Element createMethod = serviceE.getChild("createMethod");
if (createMethod != null){
sm.setCreateMethod(createMethod.getAttributeValue("name"));
Debug.logVerbose(" createMethod name: " + sm.getCreateMethod(), module);
}
Element updateMethod = serviceE.getChild("updateMethod");
if (updateMethod != null){
sm.setUpdateMethod(updateMethod.getAttributeValue("name"));
Debug.logVerbose(" updateMethod name: " + sm.getUpdateMethod(), module);
}
Element deleteMethod = serviceE.getChild("deleteMethod");
if (deleteMethod != null){
sm.setDeleteMethod(deleteMethod.getAttributeValue("name"));
Debug.logVerbose(" deleteMethod name: " + sm.getDeleteMethod(), module);
}
} catch (Exception e) {
Debug.logError("parseHandlerConfig error: " + e, module);
throw new Exception(e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -