/*
* Created on 2005/07/07.
* Copyright by 北京五岳.
* All right reserved.
*/
package admit.common;
import java.util.MissingResourceException;
import java.util.PropertyResourceBundle;
/**
* <p>Title: EnviromentLoader</p>
* <p>Description: 读取properties</p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company:wuyue</p>
*
* @author gongjian
* @version 1.0
*/
public class EnviromentLoader {
// 本类名称的字符串
private static final String THIS_CLASS = "EnviromentLoader";
// 错误代码的字符串
private static String strErrorCode = "";
// 错误信息的字符串
private static String strErrorMessage = "";
// 代表文件读取状态的字符串
private static String FILE_READING_STATUS;
// 要读取的.properties文件,本类中读取的是db.properties
private static String CONFIG_BUNDLE_NAME = "db";
/**
* DATABASE CONNECTION VARS (用于数据库连接的变量定义)
*/
// the DB Connection Driver String
// etc. oracle.jdbc.driver.OracleDriver
static String strDBConnectDriver = "";
// the DB Connection URL
// etc. jdbc:oracle:thin:@192.168.0.100:1521:admit
static String strDBConnectURL = "";
// the DB Connection Max Connnects
// etc. 50
static String strDBMaxConnects = "0";
// the DB Connection User
// etc. admit
static String strDBUser = "";
// the DB Connection Password
// etc. wuyue
static String strDBPassword = "";
/**
* @author gongjian
*
* 无参数的构造方法
*/
public EnviromentLoader() {
}
//定义静态块(初始化类的时候即会调用得到数据的方法getEnvironment)
static {
getEnvironment();
}
/**
* Static method. Get System Vars From Defination File
* 从定义好的property文件中读取数据
*/
private static void getEnvironment() {
PropertyResourceBundle configBundle = (PropertyResourceBundle) PropertyResourceBundle
.getBundle(CONFIG_BUNDLE_NAME);
if (configBundle == null) {
FILE_READING_STATUS = "FAILED";
retMessageFormat("1001", "getEnvironment() :system file open error");
return;
}
try {
strDBConnectDriver = configBundle.getString("DBConnectDriver");
strDBConnectURL = configBundle.getString("DBConnectURL");
strDBUser = configBundle.getString("DBUser");
strDBPassword = configBundle.getString("DBPassword");
strDBMaxConnects = configBundle.getString("DBMaxCount");
} catch (MissingResourceException e) {
FILE_READING_STATUS = "FAILED";
retMessageFormat("1002", "getEnvironment() :" + e.getMessage());
return;
}
FILE_READING_STATUS = "FINISHED";
}
/**
* 判断文件读取的状态
*
* @return true 读取成功
* false 读取失败
*/
public boolean isEnabled() {
if (FILE_READING_STATUS.compareTo("FINISHED") == 0) {
return true;
} else {
return false;
}
}
/**
* 得到错误的信息
*
* @return String 错误信息字符串
*/
public String getErrorMessage() {
return strErrorMessage;
}
/**
* 得到错误的代码
*
* @return String 错误信息代码字符串
*/
public String getErrorCode() {
return strErrorCode;
}
/**
* 得到读取的数据库连接驱动
*
* @return String 数据库连接驱动字符串
*/
public static String getDBConnectDriver() {
return strDBConnectDriver;
}
/**
* 得到读取的数据库连接内容
*
* @return String 数据库连接字符串
*/
public static String getConnectionString() {
return strDBConnectURL;
}
/**
* 得到读取的数据库连接用户
*
* @return String 数据库连接用户字符串
*/
public static String getDBUser() {
return strDBUser;
}
/**
* 得到读取的数据库连接密码
*
* @return String 数据库连接密码字符串
*/
public static String getDBPassword() {
return strDBPassword;
}
/**
* 得到读取的数据库最大连接数
*
* @return int 数据库最大连接数字符串 (-1代表着无限制)
*/
public int getDBMaxConnects() {
if (strDBMaxConnects != null && strDBMaxConnects.compareTo("") != 0) {
return Integer.parseInt(strDBMaxConnects);
} else {
return -1;
}
}
/**
* 用传入的字符串格式化错误代码和错误信息
*
* @param code 传入的错误代码
* @param msg 传入的错误信息
*/
private static void retMessageFormat(String code, String msg) {
strErrorCode = code;
strErrorMessage = THIS_CLASS + "-->" + msg;
}
}
**************************************************************************************************************
####################
#admit
#####################
DBConnectDriver = oracle.jdbc.driver.OracleDriver
DBConnectURL = jdbc:oracle:thin:@192.168.0.100:1521:adminSys
DBMaxCount = 50
DBUser = admit
DBPassword = wuyue