📄 commonservicemodelproducer.java
字号:
/*
* CommonServiceModelProducer.java
*
* Created on 2004/01/12, 17:48
*/
package jp.co.intra_mart.framework.base.service;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import jp.co.intra_mart.framework.system.property.PropertyParam;
import jp.co.intra_mart.framework.util.XMLDocumentProducer;
import jp.co.intra_mart.framework.util.XMLNode;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
/**
* 嫟捠儕僜乕僗儌僨儖傪嶌惉偡傞僋儔僗偱偡丅
*
* @author INTRAMART
* @since 5.0
*/
class CommonServiceModelProducer {
/**
* 嫟捠儕僜乕僗儌僨儖傪嶌惉偟傑偡丅
*
* @param fileName
* 僼傽僀儖柤
* @return
* @throws ParserConfigurationException
* @throws SAXException
* @throws IOException
*/
CommonServiceModel createCommonServiceModel(String fileName)
throws ParserConfigurationException, SAXException, IOException {
CommonServiceModel model = null;
XMLDocumentProducer producer = new XMLDocumentProducer();
Document doc = producer.getDocument(fileName);
Node node = producer.getRoot(doc);
XMLNode root = new XMLNode(node);
model = getCommonServiceModel(root);
return model;
}
/**
* 嫟捠儕僜乕僗儌僨儖傪庢摼偟傑偡丅
*
* @param root
* 儖乕僩僲乕僪
* @return CommonServiceModel
*/
private CommonServiceModel getCommonServiceModel(XMLNode root) {
CommonServiceModel model = new CommonServiceModel();
// 擖椡僄儔乕偺庢摼
XMLNode inputErrorPage = root.lookup(ErrorPageModel.P_ID_INPUT_ERROR);
model.setInputErrorPage(getInputErrorPage(inputErrorPage));
// 僒乕價僗僄儔乕偺庢摼
XMLNode serviceErrorPage = root
.lookup(ErrorPageModel.P_ID_SERVICE_ERROR);
model.setServiceErrorPage(getServiceErrorPage(serviceErrorPage));
// 僔僗僥儉僄儔乕偺庢摼
XMLNode systemErrorPage = root.lookup(ErrorPageModel.P_ID_SYSTEM_ERROR);
model.setSystemErrorPage(getSystemErrorPage(systemErrorPage));
// 儌僨儖偵抣傪愝掕
model.setClientEncoding(getClientEncoding(root));
model.setEncodingAttributeName(getEncodingAttributeName(root));
model.setClientLocale(getClientLocale(root));
model.setLocaleAttributeName(getLocaleAttributeName(root));
model.setContextPath(getContextPath(root));
model.setServiceServletPath(getServiceServlet(root));
model.setApplicationParamName(getApplicationParamName(root));
model.setServiceParamName(getServiceParamName(root));
model.setExceptionAttributeName(getExceptionAttributeName(root));
// model.setCacheRuleInfos(getCacheRuleInfos(root));
return model;
}
/**
* 椺奜懏惈柤傪庢摼偟傑偡丅
*
* @param root
* 儖乕僩僲乕僪
* @return String 椺奜懏惈柤
*/
private String getExceptionAttributeName(XMLNode root) {
return root.getString(CommonServiceModel.P_ID_EXCEPTION_ATTRIBUTE_NAME);
}
/**
* 僒乕價僗僷儔儊乕僞柤傪庢摼偟傑偡丅
*
* @param root
* 儖乕僩僲乕僪
* @return String 僒乕價僗僷儔儊乕僞柤
*/
private String getServiceParamName(XMLNode root) {
return root.getString(CommonServiceModel.P_ID_SERVICE_PARAM_NAME);
}
/**
* 傾僾儕働乕僔儑儞僷儔儊乕僞柤傪庢摼偟傑偡丅
*
* @param root
* 儖乕僩僲乕僪
* @return String 傾僾儕働乕僔儑儞僷儔儊乕僞柤
*/
private String getApplicationParamName(XMLNode root) {
return root.getString(CommonServiceModel.P_ID_APPLICATION_PARAM_NAME);
}
/**
* 僒乕價僗僒乕僽儗僢僩僷僗傪撉傒崬傒傑偡丅
*
* @param root
* 儖乕僩僲乕僪
* @return String 僒乕價僗僒乕僽儗僢僩僷僗
*/
private String getServiceServlet(XMLNode root) {
return root.getString(CommonServiceModel.P_ID_SERVICE_SERVLET);
}
/**
* 僐儞僥僉僗僩僷僗傪庢摼偟傑偡丅
*
* @param root
* 儖乕僩僲乕僪
* @return String 僐儞僥僉僗僩僷僗
*/
private String getContextPath(XMLNode root) {
return root.getString(CommonServiceModel.P_ID_CONTEXT_PATH);
}
/**
* 儘働乕儖懏惈柤傪庢摼偟傑偡丅
*
* @param root
* 儖乕僩僲乕僪
* @return String 儘働乕儖懏惈柤
*/
private String getLocaleAttributeName(XMLNode root) {
return root.getString(CommonServiceModel.P_ID_LOCALE_ATTRIBUTE);
}
/**
* 僋儔僀傾儞僩儘乕働儖傪庢摼偟傑偡丅
*
* @param root
* 儖乕僩僲乕僪
* @return String 僋儔僀傾儞僩儘乕働儖
*/
private String getClientLocale(XMLNode root) {
return root.getString(CommonServiceModel.P_ID_CLIENT_LOCALE);
}
/**
* 僄儞僐乕僨傿儞僌懏惈柤傪庢摼偟傑偡丅
*
* @param root
* 儖乕僩僲乕僪
* @return String 僄儞僐乕僨傿儞僌懏惈柤
*/
private String getEncodingAttributeName(XMLNode root) {
return root.getString(CommonServiceModel.P_ID_ENCODING_ATTRIBUTE_NAME);
}
/**
* 僋儔僀傾儞僩僄儞僐乕僨傿儞僌傪庢摼偟傑偡丅
*
* @param root
* 儖乕僩僲乕僪
* @return String 僋儔僀傾儞僩僄儞僐乕僨傿儞僌
*/
private String getClientEncoding(XMLNode root) {
return root.getString(CommonServiceModel.P_ID_CLIENT_ENCODING);
}
/**
* 僉儍僢僔儏儖乕儖忣曬僐儗僋僔儑儞傪庢摼偟傑偡丅 彂偐傟偰偄側偄偲偒偼嬻偺僐儗僋僔儑儞傪曉偟傑偡丅
*
* @param root
* 儖乕僩僲乕僪
* @return Collection 僉儍僢僔儏儖乕儖忣曬
*/
// private Collection getCacheRuleInfos(XMLNode root) {
// XMLNode[] cacheRuleNodes = root
// .select(CommonServiceModel.P_ID_CACHE_RULE);
// ArrayList list = new ArrayList();
// for (int i = 0; i < cacheRuleNodes.length; i++) {
// CacheRuleInfo info = getCacheRuleInfo(cacheRuleNodes[i]);
// list.add(info);
// }
//
// return list;
// }
/**
* 僉儍僢僔儏儖乕儖忣曬傪庢摼偟傑偡丅
*
* @param node
* 僉儍僢僔儏儖乕儖僲乕僪
* @return CacheRuleInfo 僉儍僢僔儏儖乕儖忣曬
*/
// private CacheRuleInfo getCacheRuleInfo(XMLNode cacheRuleNode) {
// CacheRuleInfo info = new CacheRuleInfo();
// String cacheConditionClass = getCacheConditionClass(cacheRuleNode);
// String cacheClass = getCacheClass(cacheRuleNode);
// PropertyParam[] conditionParams = getConditionParams(cacheRuleNode);
// PropertyParam[] cacheParams = getCacheParams(cacheRuleNode);
//
// info.setCondition(cacheConditionClass);
// info.setCache(cacheClass);
// info.setConditionParameters(conditionParams);
// info.setCacheParameters(cacheParams);
//
// return info;
// }
/**
* 僉儍僢僔儏忦審僋儔僗傪庢摼偟傑偡丅
*
* @param node
* 僉儍僢僔儏儖乕儖僲乕僪
* @return String 僉儍僢僔儏忦審僋儔僗
*/
private String getCacheConditionClass(XMLNode cacheRuleNode) {
StringBuffer path = new StringBuffer();
path.append(CommonServiceModel.P_ID_CACHE_CONDITION).append("/")
.append(CommonServiceModel.P_ID_CACHE_CONDITION_CLASS);
String cacheConditionClass = cacheRuleNode.getString(path.toString());
return cacheConditionClass;
}
/**
* 僉儍僢僔儏僋儔僗傪庢摼偟傑偡丅
*
* @param node
* 僉儍僢僔儏儖乕儖僲乕僪
* @return String 僉儍僢僔儏僋儔僗
*/
private String getCacheClass(XMLNode cahceRuleNode) {
StringBuffer path = new StringBuffer();
path.append(CommonServiceModel.P_ID_CACHE).append("/").append(
CommonServiceModel.P_ID_CACHE_CLASS);
String cacheClass = cahceRuleNode.getString(path.toString());
return cacheClass;
}
/**
* 僉儍僢僔儏忦審僋儔僗偺僷儔儊乕僞傪庢摼偟傑偡丅
*
* @param cacheRuleNode
* 僉儍僢僔儏儖乕儖僲乕僪
* @return PropertyParam[] 僉儍僢僔儏忦審僋儔僗偺僷儔儊乕僞
*/
private PropertyParam[] getConditionParams(XMLNode cacheRuleNode) {
StringBuffer initParamPath = new StringBuffer();
initParamPath.append(CommonServiceModel.P_ID_CACHE_CONDITION).append(
"/").append(CommonServiceModel.P_ID_INIT_PARAM);
XMLNode[] initParamNodes = cacheRuleNode.select(initParamPath
.toString());
PropertyParam[] params = new PropertyParam[initParamNodes.length];
for (int i = 0; i < initParamNodes.length; i++) {
params[i] = getInitParam(initParamNodes[i]);
}
return params;
}
/**
* 僉儍僢僔儏僋儔僗偺僷儔儊乕僞傪庢摼偟傑偡丅
*
* @param cacheRuleNode
* 僉儍僢僔儏儖乕儖僲乕僪
* @return PropertyParam[] 僉儍僢僔儏僋儔僗偺僷儔儊乕僞
*/
private PropertyParam[] getCacheParams(XMLNode cacheRuleNode) {
StringBuffer initParamPath = new StringBuffer();
initParamPath.append(CommonServiceModel.P_ID_CACHE).append("/").append(
CommonServiceModel.P_ID_INIT_PARAM);
XMLNode[] initParamNodes = cacheRuleNode.select(initParamPath
.toString());
PropertyParam[] params = new PropertyParam[initParamNodes.length];
for (int i = 0; i < initParamNodes.length; i++) {
params[i] = getInitParam(initParamNodes[i]);
}
return params;
}
/**
* 僷儔儊乕僞傪庢摼偟傑偡丅
*
* @param initNode
* @return PropertyParam 僷儔儊乕僞
*/
private PropertyParam getInitParam(XMLNode initNode) {
PropertyParam param = new PropertyParam();
param.setName(initNode.getString(CommonServiceModel.P_ID_PARAM_NAME));
param.setValue(initNode.getString(CommonServiceModel.P_ID_PARAM_VALUE));
return param;
}
/**
* 擖椡僄儔乕儁乕僕傪庢摼偟傑偡丅
*
* @param node
* @return ErrorPageModel 擖椡僄儔乕儁乕僕
*/
private ErrorPageModel getInputErrorPage(XMLNode node) {
return getErrorPage(node);
}
/**
* 僒乕價僗僄儔乕儁乕僕傪庢摼偟傑偡丅
*
* @param node
* @return ErrorPageModel 僒乕價僗僄儔乕儁乕僕
*/
private ErrorPageModel getServiceErrorPage(XMLNode node) {
return getErrorPage(node);
}
/**
* 僔僗僥儉僄儔乕儁乕僕傪庢摼
*
* @param node
* @return ErrorPageModel 僔僗僥儉僄儔乕儁乕僕
*/
private ErrorPageModel getSystemErrorPage(XMLNode node) {
return getErrorPage(node);
}
/**
* 僄儔乕儁乕僕偺儌僨儖傪庢摼
*
* @param node
* @return ErrorPageModel 僄儔乕儁乕僕
*/
private ErrorPageModel getErrorPage(XMLNode node) {
ErrorPageModel errorPage = new ErrorPageModel();
String page = null;
if (node != null) {
page = node.getString(ErrorPageModel.P_ID_ERROR_PAGE);
}
errorPage.setErrorPage(page);
return errorPage;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -