📄 defaultpropertymanager.java
字号:
/*
* DefaultPropertyManager.java
*
* Created on 2001/11/08, 11:17
*/
package jp.co.intra_mart.framework.system.property;
import java.util.Enumeration;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
import java.util.Vector;
import java.util.MissingResourceException;
import jp.co.intra_mart.framework.system.property.PropertyHandlerException;
/**
* 僨僼僅儖僩偺僾儘僷僥傿儅僱乕僕儍偱偡丅
* 儕僜乕僗僶儞僪儖偱愝掕偝傟偨僾儘僷僥傿忣曬傪娗棟偟傑偡丅
* 僾儘僷僥傿忣曬偺儕僜乕僗僶儞僪儖偼埲壓偺弴斣偱寛掕偝傟傑偡丅
* <PRE>
* 1.僔僗僥儉僾儘僷僥傿{@link #KEY}偱愝掕偝傟偰偄傞儕僜乕僗僶儞僪儖
* 2.僨僼僅儖僩偺僾儘僷僥傿儅僱乕僕儍{@link #DEFAULT_BUNDLE_NAME}偱愝掕偝傟偰偄傞儕僜乕僗僶儞僪儖
* </PRE>
*
* @author INTRAMART
* @version 1.0
*/
public class DefaultPropertyManager extends PropertyManager {
/**
* 僾儘僷僥傿儅僱乕僕儍傪巜掕偡傞僉乕
*/
public static final String KEY = "jp.co.intra_mart.framework.system.property.DefaultPropertyManager";
/**
* 僨僼僅儖僩偺儕僜乕僗僶儞僪儖柤
*/
public static final String DEFAULT_BUNDLE_NAME = "/PropertyConfig.properties";
/**
* 僔僗僥儉忣曬偑愝掕偝傟偰偄傞儕僜乕僗僶儞僪儖
*/
private ResourceBundle bundle;
/**
* 僐儞僗僩儔僋僞偱偡丅
*
* @throws PropertyManagerException 僾儘僷僥傿儅僱乕僕儍偺愝掕偵幐攕
*/
public DefaultPropertyManager() throws PropertyManagerException {
super();
String bundleName = System.getProperty(KEY, DEFAULT_BUNDLE_NAME);
try {
this.bundle = new PropertyResourceBundle(this.getClass().getResourceAsStream(bundleName));
} catch (Exception e) {
String message = null;
try {
message = java.util.ResourceBundle.getBundle("jp.co.intra_mart.framework.system.property.i18n").getString("DefaultPropertyManager.FailedToCreateManager");
} catch (MissingResourceException ex) {
}
throw new PropertyManagerException(message + " : resource bundle = " + bundleName, e);
}
}
/**
* 僉乕偱巜掕偝傟偨僾儘僷僥傿僴儞僪儔偺僋儔僗柤傪庢摼偟傑偡丅
*
* @return 僾儘僷僥傿僴儞僪儔偺僋儔僗柤
* @param key 僾儘僷僥傿僴儞僪儔偺僉乕
* @throws PropertyHandlerException 僋儔僗柤偺庢摼偵幐攕
*/
protected String getPropertyHandlerName(String key) throws PropertyHandlerException {
String keyName = key + ".class";
String result;
try {
result = this.bundle.getString(keyName);
} catch (MissingResourceException e) {
String message = null;
try {
message = java.util.ResourceBundle.getBundle("jp.co.intra_mart.framework.system.property.i18n").getString("DefaultPropertyManager.NoSuchKey");
} catch (MissingResourceException ex) {
}
throw new PropertyHandlerException(message + " : key = " + keyName, e);
}
return result;
}
/**
* 僉乕偱巜掕偝傟偨僾儘僷僥傿僴儞僪儔偺弶婜壔僨乕僞傪庢摼偟傑偡丅
* 弶婜壔僨乕僞偑懚嵼偟側偄応崌丄null偑曉傝傑偡丅
*
* @param key 僾儘僷僥傿僴儞僪儔偺僉乕
* @return 僾儘僷僥傿僴儞僪儔偺弶婜壔僨乕僞
*/
protected PropertyHandlerParam[] getPropertyHandlerParams(String key) {
Enumeration keys = this.bundle.getKeys();
String prefix = key + ".param.";
String currentKey;
String name;
String value;
PropertyHandlerParam param;
Vector params = new Vector();
PropertyHandlerParam[] result;
if (keys != null) {
while (keys.hasMoreElements()) {
currentKey = (String)keys.nextElement();
if (currentKey.startsWith(prefix)) {
param = new PropertyHandlerParam();
param.setName(currentKey.substring(prefix.length()));
try {
param.setValue((String)this.bundle.getString(currentKey));
} catch (MissingResourceException e) {
param.setValue("");
}
params.add(param);
}
}
}
result = new PropertyHandlerParam[params.size()];
for (int i = 0; i < params.size(); i++) {
result[i] = (PropertyHandlerParam)params.elementAt(i);
}
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -