// reference to entity
Oid oid = data.getOid();
Assert.assertTrue("can only create a reference to an entity", oid instanceof TypedOid);
final TypedOid typedOid = (TypedOid) oid;
if (typedOid == null) {
return null;
}
final ObjectAdapter referencedAdapter = getAdapterManager().adapterFor(typedOid);
if (data instanceof ObjectData) {
// no longer needed
//final ObjectSpecification spec = getSpecificationLoader().loadSpecification(data.getClassName());
if(typedOid instanceof ParentedOid) { // equiv to spec.isParented()), I think
// rather than the following, is it equivalent to pass in RESOLVING? (like everywhere else)
// final ResolveState targetState = ResolveState.GHOST;
// if (referencedAdapter.getResolveState().isValidToChangeTo(targetState)) {
// referencedAdapter.changeState(targetState);
// }
updateObject(referencedAdapter, data);
} else if (typedOid.isTransient()) {
updateObject(referencedAdapter, data);
}
}
return referencedAdapter;
}