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

📄 readconfig.java

📁 东软短信网关接入程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.zznode.dp.ismg.data;

import java.util.*;
import org.w3c.dom.*;

import com.zznode.dp.ismg.util.XmlHandler;
import com.zznode.dp.ismg.util.Log;
import com.zznode.dp.ismg.util.StringHandler;
import com.zznode.dp.ismg.data.ConnectionModel;
import com.zznode.dp.ismg.data.SubmitMessageModel;

public class ReadConfig {
  /**实例化日志操作对象*/
  private static Log log = null;
  private static ReadConfig _instance = null;
  private static StringHandler stringHandler = null;
  String filePath; //配置文件所在路径

  /**
   * 本类的实例对象
   * @return Log
   */
  public ReadConfig getReadConfig() {
    if (_instance == null) {
      _instance = new ReadConfig(filePath);
    }
    return _instance;
  }

  public ReadConfig(String filePath) {
    this.filePath = filePath;
    log = new Log().getLog();
    stringHandler = new StringHandler().getStringHandler();
  }

  public ConnectionModel getConnectionModel() {
    ConnectionModel connectionModel = new ConnectionModel();
    try {
      XmlHandler xh = new XmlHandler(filePath); //xml文件名(1为只读模式,2为读写模式)
      Node RootNode = xh.getRootNode(); //获得根节点下的manufacturer节点
      Node[] manufacturer = xh.findNodes(RootNode, "manufacturer");

      if (manufacturer != null) {
        for (int i = 0; i < manufacturer.length; i++) {
          /**ISMG厂商名称,是否使用该厂商的ISMG-*/
          String name=xh.getElementAttr(manufacturer[i], "name");
          String using_status=xh.getElementAttr(
              manufacturer[i], "using-status");
             if (using_status!= null && using_status.equalsIgnoreCase("true")) {
           log.writeLog("---------------开始读取" + name + "的配置信息----------");
            connectionModel.setName(name);
            connectionModel.setUsing_status(using_status);
            /**得到CMPPConnect*/
            Node CMPPConnectNode = xh.findNode(manufacturer[i], "CMPPConnect");

            /**主机名称*/
            Node hostNode = xh.findNode(CMPPConnectNode, "host");
            if (hostNode != null) {
              connectionModel.setHost(hostNode.getFirstChild().getNodeValue());
              log.writeLog("host=" + connectionModel.getHost());
            }

            /**InfoX主机端口号*/
            Node portNode = xh.findNode(CMPPConnectNode, "port");
            if (portNode != null) {
              connectionModel.setPort(portNode.getFirstChild().getNodeValue());
              log.writeLog("port=" + connectionModel.getPort());
            }

            /**登录帐号SP…ID*/
            Node source_addrNode = xh.findNode(CMPPConnectNode, "source-addr");
            if (source_addrNode != null) {
              connectionModel.setSource_addr(source_addrNode.getFirstChild().
                                             getNodeValue());
              log.writeLog("source-addr=" + connectionModel.getSource_addr());
            }

            /**登录密码*/
            Node shared_secretNode = xh.findNode(CMPPConnectNode,
                                                 "shared-secret");
            if (shared_secretNode != null) {
              connectionModel.setShared_secret(shared_secretNode.getFirstChild().
                                               getNodeValue());
              log.writeLog("shared-secret=" + connectionModel.getShared_secret());
            }

            /**心跳信息发送间隔时间(单位:秒)*/
            Node heartbeat_intervalNode = xh.findNode(CMPPConnectNode,
                "heartbeat-interval");
            if (heartbeat_intervalNode != null) {
              connectionModel.setHeartbeat_interval(heartbeat_intervalNode.
                  getFirstChild().getNodeValue());
              log.writeLog("heartbeat-interval=" +
                           connectionModel.getHeartbeat_interval());
            }

            /**连接中断时重连间隔时间(单位:秒)*/
            Node reconnect_intervalNode = xh.findNode(CMPPConnectNode,
                "reconnect-interval");
            if (reconnect_intervalNode != null) {
              connectionModel.setReconnect_interval(reconnect_intervalNode.
                  getFirstChild().getNodeValue());
              log.writeLog("reconnect-interval=" +
                           connectionModel.getReconnect_interval());
            }

            /**需要重连时,连续发出心跳而没有接收到响应的个数(单位:个)*/
            Node heartbeat_noresponseoutNode = xh.findNode(CMPPConnectNode,
                "heartbeat-noresponseout");
            if (heartbeat_noresponseoutNode != null) {
              connectionModel.setHeartbeat_noresponseout(
                  heartbeat_noresponseoutNode.getFirstChild().getNodeValue());
              log.writeLog("heartbeat-noresponseout=" +
                           connectionModel.getHeartbeat_noresponseout());
            }

            /**操作超时时间(单位:秒)*/
            Node transaction_timeoutNode = xh.findNode(CMPPConnectNode,
                "transaction-timeout");
            if (transaction_timeoutNode != null) {
              connectionModel.setTransaction_timeout(transaction_timeoutNode.
                  getFirstChild().getNodeValue());
              log.writeLog("transaction-timeout=" +
                           connectionModel.getTransaction_timeout());
            }

            /**双方协商的版本号(大于0,小于256)*/
            Node versionNode = xh.findNode(CMPPConnectNode, "version");
            if (versionNode != null) {
              connectionModel.setVersion(versionNode.getFirstChild().
                                         getNodeValue());
              log.writeLog("version=" + connectionModel.getVersion());
            }

            Node debugNode = xh.findNode(CMPPConnectNode, "debug");
            if (debugNode != null) {
              connectionModel.setDebug(debugNode.getFirstChild().getNodeValue());
              log.writeLog("debug=" + connectionModel.getDebug());
            }
          }
        }
      }
    }
    catch (Exception ex) {
      ex.printStackTrace();
      log.writeLog(ex.toString());
    }
    return connectionModel;
  }

  public SubmitMessageModel getSubmitMessageModel() {
    SubmitMessageModel submitMessageModel = new SubmitMessageModel();
    try {
      XmlHandler xh = new XmlHandler(filePath); //xml文件名(1为只读模式,2为读写模式)
      log.writeLog("\nfilePath=" + filePath);
      Node RootNode = xh.getRootNode(); //获得根节点下的manufacturer节点
      Node[] manufacturer = xh.findNodes(RootNode, "manufacturer");
      if (manufacturer != null) {
        for (int i = 0; i < manufacturer.length; i++) {
          /**ISMG厂商名称,是否使用该厂商的ISMG-*/
          String name = xh.getElementAttr(manufacturer[i], "name");
          String using_status = xh.getElementAttr(
              manufacturer[i], "using-status");
             if (using_status != null && using_status.equalsIgnoreCase("true")) {
            /**得到CMPPConnect*/
            Node CMPPSubmitMessageNode = xh.findNode(manufacturer[i],
                "CMPPSubmitMessage");

⌨️ 快捷键说明

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