throw new UnableToCreateObjectDueToBadKeyException(input, containedClass);
}
try {
entity = datastore.get(current);
} catch (EntityNotFoundException e) {
throw new UnableToCreateObjectException(e, containedClass);
}
}
// Load object from source entity
try {
if (logger.isLoggable(Level.FINER)) {
logger.finer("getting object associated to " + entity);
}
// Do some entity check to see if a migration is required
if(migrator!=null) {
String storedVersionField = entity.getProperty(migrator.getPersistedVersionFieldName()).toString();
Object storedVersion = entity.getProperty(storedVersionField);
Object liveVersion = migrator.getCurrentVersion();
if(!storedVersion.equals(liveVersion)) {
entity = migrator.migrate(this, entity, storedVersion, liveVersion);
}
}
DataType returned;
try {
String dynamicClass = (String) entity
.getProperty(CLASS_PROPERTY);
if (logger.isLoggable(Level.FINER)) {
logger.finer("object should be a " + dynamicClass);
}
Class<?> instanciated = Class.forName(dynamicClass);
returned = (DataType) instanciated.newInstance();
objectsBeingAccessed.put(entity.getKey(),
new WeakReference<DataType>(returned));
} catch (Exception e) {
throw new UnableToCreateObjectException(e, containedClass);
}
if (logger.isLoggable(Level.FINER)) {
logger.finer("mapping fields");
}
// Set all fields values