Object id = ec.getApiAdapter().getNewApplicationIdentityObjectId(clr.classForName(cmd.getFullClassName()), nList.item(0).getFirstChild().getNodeValue());
Object related = ec.findObject(id, true, true, null);
if (relationType == Relation.ONE_TO_ONE_BI)
{
// Set other side of relation to avoid reloading
ObjectProvider relatedSM = ec.findObjectProvider(related);
AbstractMemberMetaData relatedMmd = mmd.getRelatedMemberMetaDataForObject(clr, sm.getObject(), related);
relatedSM.replaceField(relatedMmd.getAbsoluteFieldNumber(), sm.getObject());
}
return related;
}
return null;
case Relation.ONE_TO_MANY_UNI :
case Relation.ONE_TO_MANY_BI :
// TODO Cater for Map/array
if (mmd.hasCollection())
{
AbstractClassMetaData cmd2 = sm.getExecutionContext().getMetaDataManager().getMetaDataForClass(mmd.getCollection().getElementType(), clr);
// Get value being unmarshalled
sm.copyFieldsFromObject(value, new int[]{fieldNumber});
Collection collection = (Collection) sm.provideField(fieldNumber);
// Make sure we get the right type of element (allow for inheritance)
NodeList nLists = ((Element) node).getElementsByTagName(
XMLUtils.getElementNameForMember(mmd, FieldRole.ROLE_COLLECTION_ELEMENT));
for (int i = 0; i < nLists.getLength(); i++)
{
final String nodeValue = nLists.item(i).getFirstChild().getNodeValue();
if (nodeValue != null && nodeValue.trim().length() > 0)
{
final AbstractClassMetaData elementCmd = XMLUtils.findMetaDataForNode(doc, cmd2,
ec.getMetaDataManager(), nodeValue, clr);
if (elementCmd == null && cmd2 != null)
{
throw new NucleusException("Unable to find object of type " + cmd2.getFullClassName() + " with id=" + nodeValue);
}
Object id = ec.getApiAdapter().getNewApplicationIdentityObjectId(
clr.classForName(elementCmd.getFullClassName()), nodeValue);
Object related = ec.findObject(id, true, true, null);
if (relationType == Relation.ONE_TO_MANY_BI)
{
// Set other side of relation to avoid reloading
ObjectProvider relatedSM = ec.findObjectProvider(related);
AbstractMemberMetaData relatedMmd = relatedSM.getClassMetaData().getMetaDataForMember(mmd.getMappedBy());
relatedSM.replaceField(relatedMmd.getAbsoluteFieldNumber(), sm.getObject());
}
collection.add(related);
}
}