📄 distributesservicepropertyhandler.java
字号:
public void init(PropertyParam[] params) throws PropertyHandlerException {
String bundleName = null;
if (params != null) {
for (int i = 0; i < params.length; i++) {
if (params[i].getName().equals(DEFAULT_BUNDLE_NAME_PARAM)) {
bundleName = params[i].getValue();
}
}
// 僨僼僅儖僩偺Handler僋儔僗傪庢摼偟傑偡丅
getDefaultHandler(params);
// 傾僾儕働乕僔儑儞枅偺Handler僋儔僗傪庢摼偟傑偡丅
getApplicationHandler(params);
}
if (bundleName == null) {
bundleName = DEFAULT_BUNDLE_NAME;
}
setBundlePrefix(bundleName);
}
/**
* Default偺Handler忣曬傪庢摼偟傑偡丅
*
* @param params 弶婜僷儔儊乕僞
*/
private void getDefaultHandler(PropertyParam[] params)
throws PropertyHandlerException {
List keys = new ArrayList();
HashMap values = new HashMap();
try {
// "default"偱峣傝崬傒傑偡丅
for (int i = 0; i < params.length; i++) {
if (params[i].getName().indexOf(PARAM_DEFAULT) != -1) {
keys.add(params[i].getName());
values.put(params[i].getName(), params[i].getValue());
}
}
setApplicationBundles(PARAM_DEFAULT, keys, values);
} catch (Exception e) {
throw new PropertyHandlerException();
}
}
/**
* Application枅偺Handler忣曬傪庢摼偟傑偡丅
*
* @param params 弶婜僷儔儊乕僞
*/
private void getApplicationHandler(PropertyParam[] params)
throws PropertyHandlerException {
List keys = new ArrayList();
Map values = new HashMap();
// "application"偱峣傝崬傒傑偡丅
for (int i = 0; i < params.length; i++) {
if (params[i].getName().indexOf(PARAM_APPLICATION) != -1) {
keys.add(params[i].getName());
values.put(params[i].getName(), params[i].getValue());
}
}
// applicationID偺儕僗僩傪庢摼偟傑偡
String[] appIds = getApplicationIdList(keys);
// applicationID傪傕偲偵丄class丄property傪庢摼偟傑偡
for (int i = 0; i < appIds.length; i++) {
setApplicationBundles(appIds[i], keys, values);
}
}
/**
* Handler僋儔僗傪惗惉偟丄Map偵曐帩偟傑偡丅
*
* @param id
* @param list
* @param map
*/
private void setApplicationBundles(String id, List keys, Map values)
throws PropertyHandlerException {
// 僴儞僪儔僋儔僗柤傪庢摼偟傑偡丅
String className = getApplicationHandlerClass(id, keys, values);
Object obj = null;
try {
// 僋儔僗傪惗惉偟傑偡丅
obj = Class.forName(className).newInstance();
} catch (Exception ex) {
throw new PropertyHandlerException();
}
// 僷儔儊乕僞傪庢摼偟傑偡丅
PropertyParam[] params = getApplicationHandlerProperty(id, keys, values);
// Handler僋儔僗傪惗惉偟Map偵曐帩偟傑偡丅
Map returnMap = new HashMap();
if (obj instanceof DefaultServicePropertyHandler) {
DefaultServicePropertyHandler handler = (DefaultServicePropertyHandler) obj;
handler.init(params);
// Map偵曐帩偟傑偡丅
this.bundles.put(id, handler);
} else if (obj instanceof TextFileServicePropertyHandler) {
TextFileServicePropertyHandler handler = (TextFileServicePropertyHandler) obj;
handler.init(params);
// Map偵曐帩偟傑偡丅
this.bundles.put(id, handler);
} else if (obj instanceof XmlServicePropertyHandler) {
XmlServicePropertyHandler handler = (XmlServicePropertyHandler) obj;
handler.init(params);
// Map偵曐帩偟傑偡丅
this.bundles.put(id, handler);
}
}
/**
* ApplicationID偺儕僗僩傪庢摼偟傑偡
*
* @param params 弶婜僷儔儊乕僞
*/
private String[] getApplicationIdList(List keys) {
// applicationID偺儕僗僩傪庢摼偟傑偡
HashSet set = new HashSet();
for (int i = 0; i < keys.size(); i++) {
String str = (String) keys.get(i);
String[] paramArray = str.split("[.]");
set.add(getApplications(paramArray));
}
return (String[]) set.toArray(new String[0]);
}
/**
* ApplicationID偺儕僗僩傪庢摼偟傑偡
*
* @param params 弶婜僷儔儊乕僞
*/
private String getApplications(String[] paramArray) {
String aplid = new String();
int lastpos = 0;
int firstpos = 0;
if (paramArray[0].equals(PARAM_APPLICATION)) {
firstpos = 1;
}
if (paramArray[paramArray.length - 1].equals(PARAM_APPLICATION_CLASS)) {
lastpos = 1;
} else if (paramArray[paramArray.length - 2]
.equals(PARAM_APPLICATION_PARAM)
&& (paramArray[paramArray.length - 1].equals(PARAM_DYNAMIC)
|| paramArray[paramArray.length - 1]
.equals(PARAM_FILE_DIR) || paramArray[paramArray.length - 1]
.equals(PARAM_BUNDLE))) {
lastpos = 2;
}
for (int i = firstpos; i < paramArray.length - lastpos; i++) {
if (i == firstpos) {
aplid += paramArray[i];
} else {
aplid += "." + paramArray[i];
}
}
return aplid;
}
/**
* Handler僋儔僗柤傪庢摼偟傑偡丅
*
* @param applicationId
* @param list
* @param map
* @return
*/
private String getApplicationHandlerClass(String id, List list, Map map) {
Iterator listite = list.iterator();
String name = new String();
// applicationId偑堦抳偡傞傕偺偩偗庢傝弌偟傑偡
while (listite.hasNext()) {
String key = (String) listite.next();
// "<applicationID>.class"偺抣傪庢摼偟傑偡丅
if (key.indexOf(id + "." + PARAM_APPLICATION_CLASS) != -1) {
name = (String) map.get(key);
}
}
return name;
}
/**
* Handler偵堷偒搉偡僷儔儊乕僞傪庢摼偟傑偡丅
*
* @param applicationId
* @param list
* @param map
* @return
*/
private PropertyParam[] getApplicationHandlerProperty(String applicationId,
List list, Map map) {
Iterator iterator = list.iterator();
List keys = new ArrayList();
Map properties = new HashMap();
while (iterator.hasNext()) {
String key = (String) iterator.next();
// "<applicationID>.param.dynamic"偺抣傪庢摼偟傑偡丅
if (key.indexOf(applicationId + "." + PARAM_APPLICATION_PARAM + "."
+ PARAM_DYNAMIC) != -1) {
keys.add(PARAM_DYNAMIC);
properties.put(PARAM_DYNAMIC, (String) map.get(key));
// "<applicationID>.param.file_dir"偺抣傪庢摼偟傑偡丅
} else if (key.indexOf(applicationId + "."
+ PARAM_APPLICATION_PARAM + "." + PARAM_FILE_DIR) != -1) {
keys.add(PARAM_FILE_DIR);
properties.put(PARAM_FILE_DIR, (String) map.get(key));
// "<applicationID>.param.bundle"偺抣傪庢摼偟傑偡丅
} else if (key.indexOf(applicationId + "."
+ PARAM_APPLICATION_PARAM + "." + PARAM_BUNDLE) != -1) {
keys.add(PARAM_BUNDLE);
properties.put(PARAM_BUNDLE, (String) map.get(key));
}
}
// PropertyParam傪惗惉偟傑偡丅
PropertyParam[] param = new PropertyParam[keys.size()];
for (int i = 0; i < keys.size(); i++) {
param[i] = new PropertyParam();
param[i].setName((String) keys.get(i));
param[i].setValue((String) properties.get(keys.get(i)));
}
return param;
}
/**
* 僾儘僷僥傿偺摦揑撉傒崬傒偑壜擻偐偳偆偐挷傋傑偡丅 偙偺僋儔僗偱偼偙偺儊僜僢僪偼忢偵false傪曉偟傑偡丅
*
* @return 忢偵false
* @throws ServicePropertyException 僠僃僢僋帪偵椺奜偑敪惗
*/
public boolean isDynamic() throws ServicePropertyException {
return false;
}
/**
* 僋儔僀傾儞僩偺僄儞僐乕僪傪庢摼偟傑偡丅
*
* @return 僋儔僀傾儞僩偺僄儞僐乕僨傿儞僌
* @throws ServicePropertyException 僋儔僀傾儞僩偺僄儞僐乕僪偺庢摼帪偵椺奜偑敪惗
*/
public String getClientEncoding() throws ServicePropertyException {
return ResourceBundleServicePropertyHandlerUtil
.getClientEncoding(getCommonBundle(new Locale("", "")));
}
/**
* 僋儔僀傾儞僩偺僄儞僐乕僪傪庢摼偟傑偡丅
*
* @return 僋儔僀傾儞僩偺僄儞僐乕僨傿儞僌
* @throws ServicePropertyException 僋儔僀傾儞僩偺僄儞僐乕僪偺庢摼帪偵椺奜偑敪惗
*/
public Locale getClientLocale() throws ServicePropertyException {
return ResourceBundleServicePropertyHandlerUtil
.getClientLocale(getCommonBundle(new Locale("", "")));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -