reflection NSME
This commit is contained in:
parent
335971ce51
commit
329740cc28
@ -11,25 +11,29 @@ import static com.xhpc.pp.utils.security.CP56Time2a.cp56toDate;
|
||||
|
||||
public class CacheDataUtils {
|
||||
|
||||
public static Object reflectTranslate(Object srcobj, Class tarclz, Class srcclz, Field[] targetfields) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException {
|
||||
public static Object reflectTranslate(Object srcobj, Class tarclz, Class srcclz, Field[] targetfields) throws IllegalAccessException, InvocationTargetException, InstantiationException {
|
||||
|
||||
Object tarobj = tarclz.getConstructors()[0].newInstance();
|
||||
for (Field tarfield : targetfields) {
|
||||
String tarFieldName = tarfield.getName();
|
||||
String srcval = (String) srcclz.getMethod("get".concat(capitalize(tarFieldName))).invoke(srcobj);
|
||||
Object tarval;
|
||||
if (tarfield.getType().getSimpleName().equals("Integer")) {
|
||||
if (srcval.length() == 2) {
|
||||
tarval = Integer.parseInt(srcval, 16);
|
||||
String srcval = null;
|
||||
try {
|
||||
srcval = (String) srcclz.getMethod("get".concat(capitalize(tarFieldName))).invoke(srcobj);
|
||||
Object tarval;
|
||||
if (tarfield.getType().getSimpleName().equals("Integer")) {
|
||||
if (srcval.length() == 2) {
|
||||
tarval = Integer.parseInt(srcval, 16);
|
||||
} else {
|
||||
tarval = HexUtils.reverseHexInt(srcval);
|
||||
}
|
||||
} else if (tarFieldName.contains("ime")) {
|
||||
tarval = DateUtil.format(cp56toDate(srcval), NORM_DATETIME_FORMAT);
|
||||
} else {
|
||||
tarval = HexUtils.reverseHexInt(srcval);
|
||||
tarval = srcval;
|
||||
}
|
||||
} else if (tarFieldName.contains("ime")) {
|
||||
tarval = DateUtil.format(cp56toDate(srcval), NORM_DATETIME_FORMAT);
|
||||
} else {
|
||||
tarval = srcval;
|
||||
tarclz.getMethod("set".concat(capitalize(tarFieldName)), tarfield.getType()).invoke(tarobj, tarval);
|
||||
} catch (NoSuchMethodException ignored) {
|
||||
}
|
||||
tarclz.getMethod("set".concat(capitalize(tarFieldName)), tarfield.getType()).invoke(tarobj, tarval);
|
||||
}
|
||||
return tarobj;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user