{
throw new NucleusUserException(LOCALISER.msg("010006"));
}
else if (id instanceof DatastoreUniqueOID)
{
throw new NucleusObjectNotFoundException(LOCALISER.msg("010026"), id);
}
else if (api.isDatastoreIdentity(id) || api.isSingleFieldIdentity(id))
{
// DatastoreIdentity or SingleFieldIdentity, so check that the implied class is managed
originalClassName = getStoreManager().manageClassForIdentity(id, clr);
}
else if (objectClassName != null)
{
// Object class name specified so use that directly
originalClassName = objectClassName;
}
else
{
// We dont know the object class so try to deduce it from what is known by the StoreManager
originalClassName = getStoreManager().getClassNameForObjectID(id, clr, this);
checkedClassName = true;
}
if (checkInheritance)
{
// Verify if correct class inheritance level is set
if (!checkedClassName)
{
className = getStoreManager().getClassNameForObjectID(id, clr, this);
}
else
{
// We just checked the name of the class in the section above so just use that
className = originalClassName;
}
if (className == null)
{
throw new NucleusObjectNotFoundException(LOCALISER.msg("010026"), id);
}
if (originalClassName != null && !originalClassName.equals(className))
{
// Inheritance checking has found a different inherited
// object with this identity so create new id
if (api.isDatastoreIdentity(id))
{
// Create new OID using correct target class and recheck the cache
id = OIDFactory.getInstance(getNucleusContext(), className, ((OID)id).getKeyValue());
pc = getObjectFromCache(id);
}
else if (api.isSingleFieldIdentity(id))
{
// Create new SingleFieldIdentity using correct targetClass and recheck the cache
id = api.getNewSingleFieldIdentity(id.getClass(), clr.classForName(className),
api.getTargetKeyForSingleFieldIdentity(id));
pc = getObjectFromCache(id);
}
}
}
else
{
className = originalClassName;
}
if (pc == null)
{
// Still not found, so create a Hollow instance with supplied PK values if possible
try
{
Class pcClass = clr.classForName(className, (id instanceof OID) ? null : id.getClass().getClassLoader());
if (Modifier.isAbstract(pcClass.getModifiers()))
{
// This class is abstract so impossible to have an instance of this type
throw new NucleusObjectNotFoundException(LOCALISER.msg("010027",
getIdentityAsString(id), className));
}
sm = (StateManager) ObjectProviderFactory.newForHollow(this, pcClass, id);
pc = sm.getObject();