* @return
*/
private static DisconfCenterFile transformScanFile(
Class<?> disconfFileClass, Set<Method> methods) {
DisconfCenterFile disconfCenterFile = new DisconfCenterFile();
//
// class
disconfCenterFile.setCls(disconfFileClass);
DisconfFile disconfFileAnnotation = disconfFileClass
.getAnnotation(DisconfFile.class);
//
// file name
disconfCenterFile.setFileName(disconfFileAnnotation.filename());
//
// disConfCommonModel
DisConfCommonModel disConfCommonModel = makeDisConfCommonModel(
disconfFileAnnotation.env(), disconfFileAnnotation.version());
disconfCenterFile.setDisConfCommonModel(disConfCommonModel);
// Remote URL
String url = DisconfWebPathMgr.getRemoteUrlParameter(
DisClientSysConfig.getInstance().CONF_SERVER_STORE_ACTION,
disConfCommonModel.getApp(), disConfCommonModel.getVersion(),
disConfCommonModel.getEnv(), disconfCenterFile.getFileName(),
DisConfigTypeEnum.FILE);
disconfCenterFile.setRemoteServerUrl(url);
// fields
Field[] expectedFields = disconfFileClass.getDeclaredFields();
//
// KEY & VALUE
//
Map<String, FileItemValue> keyMaps = new HashMap<String, FileItemValue>();
for (Method method : methods) {
// 获取指定的域
Field field = MethodUtils.getFieldFromMethod(method,
expectedFields, DisConfigTypeEnum.FILE);
if (field == null) {
continue;
}
//
DisconfFileItem disconfFileItem = method
.getAnnotation(DisconfFileItem.class);
String keyName = disconfFileItem.name();
// access
field.setAccessible(true);
// static 则直接获取其值
if (Modifier.isStatic(field.getModifiers())) {
try {
FileItemValue fileItemValue = new FileItemValue(
field.get(null), field);
keyMaps.put(keyName, fileItemValue);
} catch (Exception e) {
LOGGER.error(e.toString());
}
} else {
// 非static则为Null, 这里我们没有必要获取其Bean的值
FileItemValue fileItemValue = new FileItemValue(null, field);
keyMaps.put(keyName, fileItemValue);
}
}
// 设置
disconfCenterFile.setKeyMaps(keyMaps);
return disconfCenterFile;
}