use of gate.util.NameBearer in project gate-core by GateNLP.
the class PersistenceManager method getPersistentRepresentation.
/**
* Recursively traverses the provided object and replaces it and all
* its contents with the appropriate persistent equivalent classes.
*
* @param target the object to be analysed and translated into a
* persistent equivalent.
* @return the persistent equivalent value for the provided target
*/
public static Serializable getPersistentRepresentation(Object target) throws PersistenceException {
if (target == null)
return null;
// first check we don't have it already
Persistence res = existingPersistentReplacements.get().getFirst().get(new ObjectHolder(target));
if (res != null)
return res;
Class<? extends Object> type = target.getClass();
Class<?> newType = getMostSpecificPersistentType(type);
if (newType == null) {
// no special handler
if (target instanceof Serializable)
return (Serializable) target;
else
throw new PersistenceException("Could not find a serialisable replacement for " + type);
}
// we have a new type; create the new object, populate and return it
try {
res = (Persistence) newType.newInstance();
} catch (Exception e) {
throw new PersistenceException(e);
}
if (target instanceof NameBearer) {
StatusListener sListener = (StatusListener) Gate.getListeners().get("gate.event.StatusListener");
if (sListener != null) {
sListener.statusChanged("Storing " + ((NameBearer) target).getName());
}
}
res.extractDataFromSource(target);
existingPersistentReplacements.get().getFirst().put(new ObjectHolder(target), res);
return res;
}
Aggregations