Exemplo n.º 1
0
  public DBInfoBean DBConfigLoader(String filename) {
    String path = null;
    XMLInputFactory inputFactory = null;
    InputStream in = null;
    XMLEventReader eventReader = null;
    XMLEvent event = null;
    StartElement startElement = null;
    DBInfoBean config = null;

    try {
      path = getConfigXMLPath(filename);
      if (path == null || path.length() == 0) {
        throw new Exception("Error Get SYS DataBase Config Path Fail;");
      } else {
        File f = new File(path);
        if (!f.exists()) {
          throw new Exception("Error SYS DataBase Config Not Found;");
        }
      }
      inputFactory = XMLInputFactory.newInstance();
      in = new FileInputStream(path);
      eventReader = inputFactory.createXMLEventReader(in);

      while (eventReader.hasNext()) {
        event = eventReader.nextEvent();

        if (event.isStartElement()) {
          startElement = event.asStartElement();
          // System.out.println(startElement.getName().getLocalPart());
          if (startElement.getName().getLocalPart().equals("DCISYS")) {
            config = new DBInfoBean();
            config.setConnID("SYSDB");
            continue;
          }

          if (event.asStartElement().getName().getLocalPart().equals("DBAddr")) {
            event = eventReader.nextEvent();
            config.setDBAddr(event.asCharacters().getData());
            continue;
          }

          if (event.asStartElement().getName().getLocalPart().equals("DBPort")) {
            event = eventReader.nextEvent();
            config.setDBPort(event.asCharacters().getData());
            continue;
          }

          if (event.asStartElement().getName().getLocalPart().equals("DBName")) {
            event = eventReader.nextEvent();
            config.setDBName(event.asCharacters().getData());
            continue;
          }

          if (event.asStartElement().getName().getLocalPart().equals("UserName")) {
            event = eventReader.nextEvent();
            config.setUserName(event.asCharacters().getData());
            continue;
          }

          if (event.asStartElement().getName().getLocalPart().equals("Password")) {
            event = eventReader.nextEvent();
            config.setPassword(DCIString.Base64Decode(event.asCharacters().getData()));
            // System.out.println(event.asCharacters().getData());
            continue;
          }

          if (event.asStartElement().getName().getLocalPart().equals("DBType")) {
            event = eventReader.nextEvent();
            config.setDBType(DBType.valueOf(event.asCharacters().getData()));
            continue;
          }

          if (event.asStartElement().getName().getLocalPart().equals("LangType")) {
            event = eventReader.nextEvent();
            config.setLangType(LangType.valueOf(event.asCharacters().getData()));
            continue;
          }

          if (event.asStartElement().getName().getLocalPart().equals("GuardIP")) {
            event = eventReader.nextEvent();
            if (event.isEndElement()) {
              config.setGuardIP("");
            } else {
              config.setGuardIP(event.asCharacters().getData());
            }
            continue;
          }

          if (event.asStartElement().getName().getLocalPart().equals("GuardPort")) {
            event = eventReader.nextEvent();
            int port = 6666;
            if (!DCIString.isNullOrEmpty(event.asCharacters().getData())) {
              if (DCIString.isInteger(event.asCharacters().getData())) {
                port = Integer.parseInt(event.asCharacters().getData());
              }
            }
            config.setGuardPort(port);
            continue;
          }

          if (event.asStartElement().getName().getLocalPart().equals("maxActive")) {
            event = eventReader.nextEvent();
            config.setMaxActive(Integer.parseInt(event.asCharacters().getData()));
            continue;
          }

          if (event.asStartElement().getName().getLocalPart().equals("maxWait")) {
            event = eventReader.nextEvent();
            config.setMaxWait(Long.parseLong(event.asCharacters().getData()));
            continue;
          }

          if (event.asStartElement().getName().getLocalPart().equals("maxIdle")) {
            event = eventReader.nextEvent();
            config.setMaxIdle(Integer.parseInt(event.asCharacters().getData()));
            continue;
          }

          if (event.asStartElement().getName().getLocalPart().equals("minIdle")) {
            event = eventReader.nextEvent();
            config.setMinIdle(Integer.parseInt(event.asCharacters().getData()));
            continue;
          }

          if (event.asStartElement().getName().getLocalPart().equals("RemoveAbandoned")) {
            event = eventReader.nextEvent();
            config.setRemoveAbandoned(Boolean.valueOf(event.asCharacters().getData()));
            continue;
          }

          if (event.asStartElement().getName().getLocalPart().equals("RemoveAbandonedTimeout")) {
            event = eventReader.nextEvent();
            config.setRemoveAbandonedTimeout(Integer.parseInt(event.asCharacters().getData()));
            continue;
          }

          if (event.asStartElement().getName().getLocalPart().equals("OfficialUrl")) {
            event = eventReader.nextEvent();
            if (event.isEndElement()) {
              config.setOfficialUrl("");
            } else {
              config.setOfficialUrl(event.asCharacters().getData());
            }
            continue;
          }
        }

        // if (event.isEndElement()) {
        // EndElement endElement = event.asEndElement();
        // if (endElement.getName().getLocalPart().equals("SFTSYS")) {
        // configs = new Object[2];
        // configs[0] = config;
        // configs[1] = pool;
        // }
        // }

      }

    } catch (Exception ex) {
      ex.printStackTrace();
    }

    return config;
  }