⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commondatamodelproducer.java

📁 intra_mart是日本NDD公司开发的著名企业应用解决方案中间件。集成了J2ee服务器
💻 JAVA
字号:
/*
 * 嶌惉擔: 2003/12/25
 */
package jp.co.intra_mart.framework.base.data;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import javax.xml.parsers.ParserConfigurationException;

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;

/**
 * CommonDataModel傪惗惉偟傑偡丅
 * @author INTRAMART
 * @version 1.0
 */
class CommonDataModelProducer {

    /**
     * 僐僱僋僞乕儌僨儖傪嶌惉偟傑偡丅
     * @param fileName丂XML僼傽僀儖
     * @return Map 
     * @throws ParserConfigurationException
     * @throws SAXException
     * @throws IOException
     * @throws EventPropertyException
     * @throws IllegalArgumentException
     */
    Map createConnectorModels(String fileName)
        throws
            ParserConfigurationException,
            SAXException,
            IOException,
            DataPropertyException,
            IllegalArgumentException {

        Map models = null;
        XMLDocumentProducer producer = new XMLDocumentProducer();
        Document doc = null;
        doc = producer.getDocument(fileName);
        Node node = producer.getRoot(doc);
        XMLNode root = new XMLNode(node);
        //僲乕僪偐傜僐僱僋僞僲乕僪孮傪庢傝弌偡

        models = createModels(root);
        
        return models;
    }

    /**
     * 嫟捠儕僜乕僗忣曬傪帩偮儌僨儖孮傪嶌惉偟傑偡丅
     * @param root
     * @return
     * @throws DataPropertyException
     */
    private Map createModels(XMLNode root) throws DataPropertyException {
        HashMap models = new HashMap();
        XMLNode[] nodes = root.select(ConnectorModel.ID);
        for (int i = 0; i < nodes.length; i++) {
            ConnectorModel connector = getConnectorModel(nodes[i]);
            models.put(connector.getConnectorName(), connector);
        }
        return models;
    }

    /**
     * 僐僱僋僞乕儌僨儖傪庢摼偟傑偡丅
     * @param connectorNode 僲乕僪 
     * @return ConnectorModel 僐僱僋僞乕儌僨儖 
     * @throws DataPropertyException
     */
    private ConnectorModel getConnectorModel(XMLNode connectorNode)
        throws DataPropertyException {
        ConnectorModel model = new ConnectorModel();

        model.setConnectorName(getConnectorName(connectorNode));
        model.setConnectorClassName(getConnectorClassName(connectorNode));
        model.setConnectorResource(getConnectorResource(connectorNode));

        return model;
    }

    /**
     * 僐僱僋僞柤傪庢摼偟傑偡丅
     * @param connectorNode
     * @return String 僐僱僋僞柤 
     * @throws DataPropertyException
     */
    private String getConnectorName(XMLNode connectorNode)
        throws DataPropertyException {
        String connectorName =
            connectorNode.getString(ConnectorModel.P_ID_CONNECTOR_NAME);
        if (connectorName == null || connectorName.equals("")) {
            throw new DataPropertyException();
        }
        return connectorName;
    }

    /**
     * 僐僱僋僞僋儔僗柤傪庢摼偟傑偡丅
     * @param connectorNode
     * @return String 僐僱僋僞僋儔僗柤 
     * @throws DataPropertyException
     */
    private String getConnectorClassName(XMLNode connectorNode)
        throws DataPropertyException {
        String connectorClass =
            connectorNode.getString(ConnectorModel.P_ID_CONNECTOR_CLASS);
        if (connectorClass == null || connectorClass.equals("")) {
            String message = null;
            try {
                message =
                    ResourceBundle.getBundle(
                        "jp.co.intra_mart.framework.base.data.i18n").getString(
                        "ResourceBundleDataPropertyHandlerUtil.param.ConnectorClassNotDeclared");
            } catch (MissingResourceException e) {
            }
            throw new DataPropertyException(
                message
                    + " : Connector name = "
                    + connectorNode.getString(
                        ConnectorModel.P_ID_CONNECTOR_NAME));
        }
        return connectorClass;
    }

    /**
     * 僐僱僋僞僲乕僪偐傜儕僜乕僗柤傪庢摼偟傑偡丅
     * @param connectorNode
     * @return String 儕僜乕僗柤 
     * @throws DataPropertyException
     */
    private String getConnectorResource(XMLNode connectorNode)
        throws DataPropertyException {
        return connectorNode.getString(ConnectorModel.P_ID_RESOURCE_NAME);

    }

    /**
     * 儕僜乕僗儌僨儖傪嶌惉偟傑偡丅
     * 
     * @param fileName
     * @return Map 儕僜乕僗儌僨儖 
     * @throws ParserConfigurationException
     * @throws SAXException
     * @throws IOException
     * @throws DataPropertyException
     * @throws IllegalArgumentException
     */
    Map createResourceModels(String fileName)
        throws
            ParserConfigurationException,
            SAXException,
            IOException,
            DataPropertyException,
            IllegalArgumentException {
        Map models = null;
        XMLDocumentProducer producer = new XMLDocumentProducer();
        Document doc = producer.getDocument(fileName);
        Node node = producer.getRoot(doc);
        XMLNode root = new XMLNode(node);
        //僲乕僪偐傜儕僜乕僗僲乕僪孮傪庢傝弌偡

        models = createResourceModels(root);
        return models;
    }

    /**
     * 嫟捠儕僜乕僗忣曬傪帩偮儌僨儖孮傪嶌惉偟傑偡丅
     * 
     * @param root
     * @return Map 嫟捠儕僜乕僗忣曬傪帩偮儌僨儖孮
     * @throws DataPropertyException
     */
    private Map createResourceModels(XMLNode root)
        throws DataPropertyException {
        HashMap models = new HashMap();
        XMLNode[] nodes = root.select(ResourceModel.ID);

        for (int i = 0; i < nodes.length; i++) {
            ResourceModel resource = getResourceModel(nodes[i]);
            models.put(resource.getConnectorResource(), resource);
        }
        return models;
    }

    /**
     * 嫟捠儕僜乕僗忣曬傪帩偮儌僨儖孮傪庢摼偟傑偡丅
     * 
     * @param resourceNode
     * @return ResourceModel 
     * @throws DataPropertyException
     */
    private ResourceModel getResourceModel(XMLNode resourceNode) throws DataPropertyException {
        ResourceModel resourceModel = new ResourceModel();
        String resourceName =
            resourceNode.getString(ResourceModel.P_ID_RESOURCE_NAME);
        resourceModel.setConnectorResource(resourceName);

        if (resourceName == null || resourceName.equals("")) {
            throw new DataPropertyException();
        }

        ResourceParam[] initParams = getResourceParams(resourceNode);
        if (initParams == null || initParams.length == 0) {
            resourceModel.setParams(new ResourceParam[0]);
        } else {
            resourceModel.setParams(initParams);
        }
        return resourceModel;
    }

    /**
     * 儕僜乕僗僷儔儊乕僞傪嶌惉偟傑偡丅
     * 
     * @param resourceNode
     * @return ResourceParam[] 
     * @throws DataPropertyException
     */
    private ResourceParam[] getResourceParams(XMLNode resourceNode)
        throws DataPropertyException {
        XMLNode[] initParamNodes =
            resourceNode.select(ResourceModel.P_ID_RESOURCE_PARAM);
        ResourceParam[] params = new ResourceParam[initParamNodes.length];
        for (int i = 0; i < params.length; i++) {
            params[i] = getResourceParam(initParamNodes[i]);

        }
        return params;
    }

    /**
     * 儕僜乕僗僷儔儊乕僞僆僽僕僃僋僩偵僷儔儊乕僞僲乕僪偺抣傪奿擺偟傑偡丅
     * 
     * @param initParam
     * @return ResourceParam 
     * @throws DataPropertyException
     */
    private ResourceParam getResourceParam(XMLNode initParam)
        throws DataPropertyException {
        ResourceParam param = new ResourceParam();
        param.setName(getResourceParamName(initParam));
        param.setValue(getResourceParamValue(initParam));
        return param;
    }

    /**
     * 僷儔儊乕僞僲乕僪偐傜儕僜乕僗柤傪庢摼偟傑偡丅
     * 
     * @param initParam
     * @return String 儕僜乕僗柤 
     * @throws DataPropertyException
     */
    private String getResourceParamName(XMLNode initParam)
        throws DataPropertyException {
        String paramName = initParam.getString(ResourceModel.P_ID_PARAM_NAME);
        if (paramName == null || paramName.equals("")) {
            String message = null;
            try {
                message =
                    ResourceBundle.getBundle(
                        "jp.co.intra_mart.framework.base.data.i18n").getString(
                        "ResourceBundleDataPropertyHandlerUtil.param.ResourceDetailNotDeclared");
            } catch (MissingResourceException ex) {
            }
            throw new DataPropertyException(message);
        }
        return paramName;
    }

    /**
     * 僷儔儊乕僞僲乕僪偐傜僷儔儊乕僞抣傪庢摼偟傑偡丅
     * 
     * @param initParam
     * @return String 
     * @throws DataPropertyException
     */
    private String getResourceParamValue(XMLNode initParam)
        throws DataPropertyException {
        String paramValue = initParam.getString(ResourceModel.P_ID_PARAM_VALUE);
        if (paramValue == null || paramValue.equals("")) {
            String message = null;
            try {
                message =
                    ResourceBundle.getBundle(
                        "jp.co.intra_mart.framework.base.data.i18n").getString(
                        "ResourceBundleDataPropertyHandlerUtil.param.ResourceDetailNotDeclared");
            } catch (MissingResourceException ex) {
            }
            throw new DataPropertyException(
                message
                    + " : resource name = "
                    + initParam.getString(ResourceModel.P_ID_PARAM_NAME));
        }
        return paramValue;

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -