use of com.yahoo.elide.core.type.Method in project elide by yahoo.
the class MultiplexWriteTransaction method cloneObject.
/**
* Clone contents of object for possible reverse transaction.
*/
private Object cloneObject(Object object) {
if (object == null) {
return null;
}
Type<?> cls = multiplexManager.getDictionary().lookupBoundClass(EntityDictionary.getType(object));
try {
Object clone = cls.newInstance();
for (Field field : cls.getFields()) {
field.set(clone, field.get(object));
}
for (Method method : cls.getMethods()) {
if (method.getName().startsWith("set")) {
try {
Method getMethod = cls.getMethod("get" + method.getName().substring(3));
method.invoke(clone, getMethod.invoke(object));
} catch (IllegalStateException | IllegalArgumentException | ReflectiveOperationException | SecurityException e) {
return null;
}
}
}
return clone;
} catch (InstantiationException | IllegalAccessException e) {
// ignore
}
return null;
}
Aggregations