* @param oid is the identifier of the futur object
* @return a memory instance
*/
public Object newInstance(Object oid, ConnectionHolder context) throws PersistenceException {
if (!(oid instanceof PName))
throw new PersistenceException("Unmanaged object identifier: " + oid);
PName pn = (PName) oid;
String className = null;
try {
pn = pn.resolve(context);
if (logger.isLoggable(BasicLevel.DEBUG)) {
logger.log(BasicLevel.DEBUG, "newInstance(" + oid + "): pn.resolve=" + pn);
logger.log(BasicLevel.DEBUG, "newInstance(" + oid + "): pn.type=" + pn.getPType());
}
PType type = pn.getPType();
if (type == null) {
//Error detected by Roland Hedayat
throw new PersistenceException("newInstance() "
+ "\n\toid=" + oid
+ "\n\tpn=" + pn
+ "\n\tpn.pnc=" + (pn.getPNameManager() != null ? pn.getPNameManager() : null));
}
className = type.getJormName();
int idx = className.indexOf(JormPathHelper.SEP);
PClassMapping pcm = ((PBinder) pn.getPNameManager())
.getBinderClassMapping();
PersistentObjectItf sp = null;
if ((pcm instanceof AbstractGenClassHome) && idx != -1) {
// This is a Generic class
className = getGCClassName(className.substring(0, idx));
sp = (PersistentObjectItf) Class.forName(className).newInstance();
} else {
if (pcm != null) {
className = pcm.getClassName();
}
ClassLoader cl = jf.getClassLoader(className);
if (cl == null) {
cl = oid.getClass().getClassLoader();
if (cl == null) {
cl = ClassLoader.getSystemClassLoader();
}
}
sp = (PersistentObjectItf)
cl.loadClass(className).newInstance();
}
sp.speedoSetReferenceState(null);
return sp;
} catch (PException e) {
throw new PersistenceException(
"Impossible to analyze the object identifier" + oid, e);
} catch (Exception e) {
throw new PersistenceException(
"Impossible to instanciate the class " + className
+ "Be careful to the generic class (Collection, ...), oid class:"
+ oid.getClass(), e);
}
}