*
*/
@Override
public void inject2Instance(Object object, String key) {
DisconfCenterItem disconfCenterItem = DisconfCenterStore.getInstance()
.getConfItemMap().get(key);
// 校验是否存在
if (disconfCenterItem == null) {
LOGGER.error("canot find " + key + " in store....");
return;
}
//
// 非静态类
//
if (object != null) {
disconfCenterItem.setObject(object);
}
// 根据类型设置值
//
// 注入实体
//
try {
if (object != null) {
// 默认值
Object defaultValue = disconfCenterItem.getField().get(object);
LOGGER.debug(disconfCenterItem.getKey()
+ " is a non-static field. ");
if (disconfCenterItem.getValue() == null) {
// 如果仓库里的值为空,则实例直接使用默认值,
disconfCenterItem.getField().set(object, defaultValue);
// 仓库里也使用此值
disconfCenterItem.setValue(defaultValue);
} else {
// 如果仓库里的值为非空,则实例使用仓库里的值
disconfCenterItem.getField().set(object,
disconfCenterItem.getValue());
}
} else {
//
// 静态类
//
if (Modifier.isStatic(disconfCenterItem.getField()
.getModifiers())) {
LOGGER.debug(disconfCenterItem.getKey()
+ " is a static field. ");
disconfCenterItem.getField().set(null,
disconfCenterItem.getValue());
}
}
} catch (Exception e) {
LOGGER.error(e.toString(), e);