final Callable c;
try {
if (primaryKey.getPrimaryKey().length > 1) {
Map<String, Object> idWrapper = new HashMap<String, Object>();
for (int y = 0; y < primaryKey.getPrimaryKey().length; y++) {
XMLObjectReferenceMapping refMapping = (XMLObjectReferenceMapping) reference.getMapping();
String idName = (String) refMapping.getReferenceDescriptor().getPrimaryKeyFieldNames().get(y);
Object idValue = primaryKey.getPrimaryKey()[y];
idWrapper.put(idName, idValue);
}
c = userSpecifiedResolver.resolve(idWrapper, reference.getTargetClass());
} else {
c = userSpecifiedResolver.resolve(primaryKey.getPrimaryKey()[0], reference.getTargetClass());
}
if (c != null) {
value = c.call();
}
} catch (Exception e) {
throw XMLMarshalException.unmarshalException(e);
}
} else {
value = getValue(session, reference, primaryKey, handler);
}
if (value != null) {
cPolicy.addInto(value, container, session);
}
}
}
// for each reference, get the source object and add it to the container policy
// when finished, set the policy on the mapping
mapping.setAttributeValueInObject(referenceSourceObject, container);
XMLInverseReferenceMapping inverseReferenceMapping = mapping.getInverseReferenceMapping();
if(inverseReferenceMapping != null && value != null) {
AttributeAccessor backpointerAccessor = inverseReferenceMapping.getAttributeAccessor();
ContainerPolicy backpointerContainerPolicy = inverseReferenceMapping.getContainerPolicy();
if(backpointerContainerPolicy == null) {
backpointerAccessor.setAttributeValueInObject(value, referenceSourceObject);
} else {
Object backpointerContainer = backpointerAccessor.getAttributeValueFromObject(value);
if(backpointerContainer == null) {
backpointerContainer = backpointerContainerPolicy.containerInstance();
backpointerAccessor.setAttributeValueInObject(value, backpointerContainer);
}
backpointerContainerPolicy.addInto(referenceSourceObject, backpointerContainer, session);
}
}
} else if (reference.getMapping() instanceof XMLObjectReferenceMapping) {
CacheId primaryKey = (CacheId) reference.getPrimaryKey();
Object value = null;
if (userSpecifiedResolver != null) {
final Callable c;
try {
if (primaryKey.getPrimaryKey().length > 1) {
Map<String, Object> idWrapper = new HashMap<String, Object>();
for (int y = 0; y < primaryKey.getPrimaryKey().length; y++) {
XMLObjectReferenceMapping refMapping = (XMLObjectReferenceMapping) reference.getMapping();
String idName = (String) refMapping.getReferenceDescriptor().getPrimaryKeyFieldNames().get(y);
Object idValue = primaryKey.getPrimaryKey()[y];
idWrapper.put(idName, idValue);
}
c = userSpecifiedResolver.resolve(idWrapper, reference.getTargetClass());
} else {
c = userSpecifiedResolver.resolve(primaryKey.getPrimaryKey()[0], reference.getTargetClass());
}
if (c != null) {
value = c.call();
}
} catch (Exception e) {
throw XMLMarshalException.unmarshalException(e);
}
} else {
value = getValue(session, reference, primaryKey, handler);
}
XMLObjectReferenceMapping mapping = (XMLObjectReferenceMapping)reference.getMapping();
if (value != null) {
mapping.setAttributeValueInObject(reference.getSourceObject(), value);
}
if (null != reference.getSetting()) {
reference.getSetting().setValue(value);
}
XMLInverseReferenceMapping inverseReferenceMapping = mapping.getInverseReferenceMapping();
if(inverseReferenceMapping != null) {
AttributeAccessor backpointerAccessor = inverseReferenceMapping.getAttributeAccessor();
ContainerPolicy backpointerContainerPolicy = inverseReferenceMapping.getContainerPolicy();
if(backpointerContainerPolicy == null) {
backpointerAccessor.setAttributeValueInObject(value, referenceSourceObject);