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 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();
|
Object tarobj = tarclz.getConstructors()[0].newInstance();
|
||||||
for (Field tarfield : targetfields) {
|
for (Field tarfield : targetfields) {
|
||||||
String tarFieldName = tarfield.getName();
|
String tarFieldName = tarfield.getName();
|
||||||
String srcval = (String) srcclz.getMethod("get".concat(capitalize(tarFieldName))).invoke(srcobj);
|
String srcval = null;
|
||||||
Object tarval;
|
try {
|
||||||
if (tarfield.getType().getSimpleName().equals("Integer")) {
|
srcval = (String) srcclz.getMethod("get".concat(capitalize(tarFieldName))).invoke(srcobj);
|
||||||
if (srcval.length() == 2) {
|
Object tarval;
|
||||||
tarval = Integer.parseInt(srcval, 16);
|
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 {
|
} else {
|
||||||
tarval = HexUtils.reverseHexInt(srcval);
|
tarval = srcval;
|
||||||
}
|
}
|
||||||
} else if (tarFieldName.contains("ime")) {
|
tarclz.getMethod("set".concat(capitalize(tarFieldName)), tarfield.getType()).invoke(tarobj, tarval);
|
||||||
tarval = DateUtil.format(cp56toDate(srcval), NORM_DATETIME_FORMAT);
|
} catch (NoSuchMethodException ignored) {
|
||||||
} else {
|
|
||||||
tarval = srcval;
|
|
||||||
}
|
}
|
||||||
tarclz.getMethod("set".concat(capitalize(tarFieldName)), tarfield.getType()).invoke(tarobj, tarval);
|
|
||||||
}
|
}
|
||||||
return tarobj;
|
return tarobj;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user