📄 distributesdatapropertyhandler.java
字号:
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 DefaultDataPropertyHandler ) {
DefaultDataPropertyHandler handler = (DefaultDataPropertyHandler) obj;
handler.init( params );
// Map偵曐帩偟傑偡丅
this.bundles.put(id, handler);
} else if ( obj instanceof TextFileDataPropertyHandler ) {
TextFileDataPropertyHandler handler = (TextFileDataPropertyHandler) obj;
handler.init( params );
// Map偵曐帩偟傑偡丅
this.bundles.put(id, handler);
} else if ( obj instanceof XmlDataPropertyHandler ) {
XmlDataPropertyHandler handler = (XmlDataPropertyHandler) 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 DataPropertyException 僠僃僢僋帪偵椺奜偑敪惗
* @since 3.2
*/
public boolean isDynamic() throws DataPropertyException {
return false;
}
/**
* DAO偺僋儔僗柤傪庢摼偟傑偡丅
* <CODE>application</CODE>丄<CODE>key</CODE>偲<CODE>connect</CODE>偱巜掕偝傟偨DAO偺僋儔僗柤傪庢摼偟傑偡丅
*
* @param application 傾僾儕働乕僔儑儞ID
* @param key DAO偺僉乕
* @param connect 愙懕忣曬
* @return DAO偺僋儔僗柤
* @throws DataPropertyException DAO偺僋儔僗柤偺庢摼偵幐攕
*/
public String getDAOName(String application, String key, String connect)
throws DataPropertyException {
String ret = new String();
Object obj = getApplicationBundle( application );
if ( obj instanceof DefaultDataPropertyHandler ) {
DefaultDataPropertyHandler handler = (DefaultDataPropertyHandler) obj;
ret = handler.getDAOName( application, key, connect );
} else if ( obj instanceof TextFileDataPropertyHandler ) {
TextFileDataPropertyHandler handler = (TextFileDataPropertyHandler) obj;
ret = handler.getDAOName( application, key, connect );
} else if ( obj instanceof XmlDataPropertyHandler ) {
XmlDataPropertyHandler handler = (XmlDataPropertyHandler) obj;
ret = handler.getDAOName( application, key, connect );
}
return ret;
}
/**
* DAO偵懳偡傞僨乕僞僐僱僋僞柤傪庢摼偟傑偡丅
* <CODE>application</CODE>丄<CODE>key</CODE>偲<CODE>connect</CODE>偱巜掕偝傟偨DAO偺僨乕僞僐僱僋僞柤傪庢摼偟傑偡丅
* 懳墳偡傞僨乕僞僐僱僋僞柤偑巜掕偝傟偰偄側偄応崌丄null偑曉傝傑偡丅
*
* @param application 傾僾儕働乕僔儑儞ID
* @param key DAO偺僉乕
* @param connect 愙懕忣曬
* @return 僨乕僞僐僱僋僞偺柤慜
* @throws DataPropertyException 僨乕僞僐僱僋僞柤偺庢摼帪偵椺奜偑敪惗
*/
public String getConnectorName(
String application,
String key,
String connect)
throws DataPropertyException {
String ret = new String();
Object obj = getApplicationBundle( application );
if ( obj instanceof DefaultDataPropertyHandler ) {
DefaultDataPropertyHandler handler = (DefaultDataPropertyHandler) obj;
ret = handler.getConnectorName( application, key, connect );
} else if ( obj instanceof TextFileDataPropertyHandler ) {
TextFileDataPropertyHandler handler = (TextFileDataPropertyHandler) obj;
ret = handler.getConnectorName( application, key, connect );
} else if ( obj instanceof XmlDataPropertyHandler ) {
XmlDataPropertyHandler handler = (XmlDataPropertyHandler) obj;
ret = handler.getConnectorName( application, key, connect );
}
return ret;
}
/**
* 僨乕僞僐僱僋僞偺僋儔僗柤傪庢摼偟傑偡丅
* <CODE>application</CODE>丄<CODE>key</CODE>偲<CODE>connect</CODE>偱巜掕偝傟偨僨乕僞僐僱僋僞偺僋儔僗柤傪庢摼偟傑偡丅
*
* @param connectorName 僨乕僞僐僱僋僞柤
* @return 僨乕僞僐僱僋僞偺僋儔僗柤
* @throws DataPropertyException 僨乕僞僐僱僋僞偺僋儔僗柤偺庢摼偵幐攕
*/
public String getConnectorClassName(String connectorName)
throws DataPropertyException {
return ResourceBundleDataPropertyHandlerUtil.getConnectorClassName(
getCommonBundle(),
connectorName);
}
/**
* 僨乕僞僐僱僋僞偺儕僜乕僗柤傪庢摼偟傑偡丅
* <CODE>application</CODE>丄<CODE>key</CODE>偲<CODE>connect</CODE>偱巜掕偝傟偨僨乕僞僐僱僋僞偺儕僜乕僗柤傪庢摼偟傑偡丅
* 懳墳偡傞儕僜乕僗柤偑側偄応崌丄null傪曉偟傑偡丅
*
* @param connectorName 僨乕僞僐僱僋僞柤
* @return 僨乕僞僐僱僋僞偺儕僜乕僗柤
* @throws DataPropertyException 僨乕僞僐僱僋僞偺儕僜乕僗柤偺庢摼帪偵椺奜偑敪惗
*/
public String getConnectorResource(String connectorName)
throws DataPropertyException {
return ResourceBundleDataPropertyHandlerUtil.getConnectorResource(
getCommonBundle(),
connectorName);
}
/**
* 儕僜乕僗偺僷儔儊乕僞傪庢摼偟傑偡丅
* name偱巜掕偝傟偨儕僜乕僗偺僷儔儊乕僞傪庢摼偟傑偡丅
*
* @param name 儕僜乕僗柤
* @return 儕僜乕僗偺僷儔儊乕僞
* @throws DataPropertyException 儕僜乕僗偺僷儔儊乕僞偺庢摼帪偵椺奜偑敪惗
*/
public ResourceParam[] getResourceParams(String name)
throws DataPropertyException {
return ResourceBundleDataPropertyHandlerUtil.getResourceParams(
getCommonBundle(),
name);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -