@Override
public TypeData getTypeDataFromObject(Object objectSaved)
{
Class<?> c = objectSaved.getClass();
TypeData data = DataStorageManager.getDataForType(new ClassContainer(type));
Field f = null;
Object obj;
// do Unique key stuff
try
{
if (isUniqueKeyField)
{
Class<?> tempClass = c;
while (f == null) {
try
{
f = tempClass.getDeclaredField(uniqueKey);
}
catch (NoSuchFieldException e)
{
tempClass = tempClass.getSuperclass();
if (tempClass == null)
throw e;
}
}
f.setAccessible(true);
data.setUniqueKey(f.get(objectSaved).toString());
}
else
{
Method m;
String methodName = uniqueKey.replace("()", "");
m = c.getDeclaredMethod(methodName, new Class[] {});
m.setAccessible(true);
Object val = m.invoke(objectSaved, new Object[] {});
data.setUniqueKey(val.toString());
}
}
catch (Exception e)
{
OutputHandler.exception(Level.SEVERE, "Reflection error trying to get UniqueLoadingKey from " + objectSaved.getClass()
+ ". FE will continue without saving this.", e);
}
String[] keys = fields.keySet().toArray(new String[fields.size()]);
Class<?> currentClass = c;
// Iterate over the object grabbing the fields we want to examine.
for (int i = 0; i < keys.length; ++i)
{
try
{
f = currentClass.getDeclaredField(keys[i]);
f.setAccessible(true);
obj = f.get(objectSaved);
if (obj != null)
{
if (StorageManager.isTypeComplex(obj.getClass()))
{
// This object is not a primitive. Call this function on the appropriate TypeTagger.
obj = DataStorageManager.getDataForObject(fields.get(keys[i]), obj);
}
data.putField(keys[i], obj);
}
// Ensure we reset the currentClass after trying this. It may have been altered by a previous attempt.
currentClass = c;
}
catch (NoSuchFieldException e)