Package org.dayatang.configuration

Examples of org.dayatang.configuration.ConfigurationException


  public Date getDate(String key, Date defaultValue) {
    String result = getString(key);
    try {
      return StringUtils.isBlank(result) ? defaultValue : new SimpleDateFormat(dateFormat).parse(result);
    } catch (ParseException e) {
      throw new ConfigurationException("日期解析错误!日期格式是:" + dateFormat + ", 日期:" + result, e);
    }
  }
View Full Code Here


    String ret = raw;
    try {
      byte[] bytes = raw.getBytes(ISO_8859_1);
      ret = new String(bytes, encoding);
    } catch (UnsupportedEncodingException e) {
      throw new ConfigurationException("Unsupport Encoding:" + encoding, e);
    }
    return ret;
  }
View Full Code Here

    String ret = validStr;
    try {
      byte[] bytes = validStr.getBytes(encoding);
      ret = new String(bytes, ISO_8859_1);
    } catch (UnsupportedEncodingException e) {
      throw new ConfigurationException("Unsupport Encoding:" + encoding, e);
    }
    return ret;
  }
View Full Code Here

      in = url.openStream();
      props.load(in);
      hTable = pfu.rectifyProperties(props);
      LOGGER.debug("Load configuration from {} at {}", url, new Date());
    } catch (IOException e) {
      throw new ConfigurationException("Cannot load config file: " + url, e);
    } finally {
      if (in != null) {
        try {
          in.close();
        } catch (IOException e) {
          throw new ConfigurationException("Cannot close input stream.", e);
        }
      }
    }
  }
View Full Code Here

          connection.rollback();
        }
      } catch (SQLException e1) {
        e1.printStackTrace();
      }
      throw new ConfigurationException(e);
    } finally {
      if (rs != null) {
        try {
          rs.close();
        } catch (SQLException e) {
          LOGGER.error("Could not close Resultset!");
          throw new ConfigurationException(e);
        }
      }
      if (queryStmt != null) {
        try {
          queryStmt.close();
        } catch (SQLException e) {
          LOGGER.error("Could not close query statement!");
          throw new ConfigurationException(e);
        }
      }
      if (updateStmt != null) {
        try {
          updateStmt.close();
        } catch (SQLException e) {
          LOGGER.error("Could not close update statement!");
          throw new ConfigurationException(e);
        }
      }
      if (insertStmt != null) {
        try {
          insertStmt.close();
        } catch (SQLException e) {
          LOGGER.error("Could not close insert statement!");
          throw new ConfigurationException(e);
        }
      }
      if (connection != null) {
        try {
          connection.close();
        } catch (SQLException e) {
          LOGGER.error("Could not close connection!");
          throw new ConfigurationException(e);
        }
      }
    }
  }
View Full Code Here

      while (rs.next()) {
        results.put(rs.getString(keyColumn), rs.getString(valueColumn));
      }
      return results;
    } catch (SQLException e) {
      throw new ConfigurationException(e);
    } finally {
      if (rs != null) {
        try {
          rs.close();
        } catch (SQLException e) {
          LOGGER.error("Could not close Resultset!");
          throw new ConfigurationException(e);
        }
      }
      if (stmt != null) {
        try {
          stmt.close();
        } catch (SQLException e) {
          LOGGER.error("Could not close query statement!");
          throw new ConfigurationException(e);
        }
      }
      if (connection != null) {
        try {
          connection.close();
        } catch (SQLException e) {
          LOGGER.error("Could not close connection!");
          throw new ConfigurationException(e);
        }
      }
    }
  }
View Full Code Here

    try {
      connection = dataSource.getConnection();
      stmt = connection.prepareStatement(sql);
      return stmt.executeUpdate();
    } catch (SQLException e) {
      throw new ConfigurationException(e);
    } finally {
      if (stmt != null) {
        try {
          stmt.close();
        } catch (SQLException e) {
          LOGGER.error("Could not close query statement!");
          throw new ConfigurationException(e);
        }
      }
      if (connection != null) {
        try {
          connection.close();
        } catch (SQLException e) {
          LOGGER.error("Could not close connection!");
          throw new ConfigurationException(e);
        }
      }
    }
  }
View Full Code Here

    return fromFileSystem(new File(dirPath, fileName));
  }
 
  public static ConfigurationFileImpl fromFileSystem(final File file) {
    if (!file.exists()) {
      throw new ConfigurationException("File " + file.getName() + " not found!");
    }
    if (!file.canRead()) {
      throw new ConfigurationException("File " + file.getName() + " is unreadable!");
    }
    return new ConfigurationFileImpl(file);
  }
View Full Code Here

      in = new FileInputStream(file);
      props.load(in);
      hTable = pfu.rectifyProperties(props);
      LOGGER.debug("Load configuration from {} at {}", file.getAbsolutePath(), new Date());
    } catch (IOException e) {
      throw new ConfigurationException("Cannot load config file: " + file, e);
    } finally {
      if (in != null) {
        try {
          in.close();
        } catch (IOException e) {
          throw new ConfigurationException("Cannot close input stream.", e);
        }
      }
    }
  }
View Full Code Here

    try {
      Properties props = pfu.unRectifyProperties(getHashtable());
      out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), PropertiesFileUtils.ISO_8859_1));
      store(props, out, "Config file for " + file);
    } catch (Exception e) {
      throw new ConfigurationException(e);
    } finally {
      if (out != null) {
        try {
          out.close();
        } catch (IOException e) {
          throw new ConfigurationException("Cannot close input stream.", e);
        }
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.dayatang.configuration.ConfigurationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.