ReferenceResolver resolver = ReferenceResolver.getInstance(session);
if (resolver == null) {
return;
}
Reference reference = resolver.getReference(this, srcObject, xmlField);
if (reference == null) {
// if reference is null, create a new instance and set it on the resolver
reference = new Reference(this, srcObject, referenceClass, new HashMap());
resolver.addReference(reference);
}
CacheId primaryKeys;
if(null == referenceClass || ClassConstants.OBJECT == referenceClass) {
HashMap primaryKeyMap = reference.getPrimaryKeyMap();
CacheId pks = (CacheId) primaryKeyMap.get(null);
if (pks == null){
Object[] pkValues = new Object[1];
pks = new CacheId(pkValues);
primaryKeyMap.put(null, pks);
}
if(usesSingleNode) {
for (StringTokenizer stok = new StringTokenizer((String) object); stok.hasMoreTokens();) {
pks.add(stok.nextToken());
reference = resolver.getReference(this, srcObject, xmlField);
if (reference == null) {
// if reference is null, create a new instance and set it on the resolver
reference = new Reference(this, srcObject, referenceClass, new HashMap());
resolver.addReference(reference);
}
primaryKeyMap = reference.getPrimaryKeyMap();
pks = (CacheId) primaryKeyMap.get(null);
if (pks == null){
Object[] pkValues = new Object[1];
pks = new CacheId(pkValues);
primaryKeyMap.put(null, pks);
}
}
} else {
pks.add(object);
}
} else {
XMLField tgtFld = (XMLField) getSourceToTargetKeyFieldAssociations().get(xmlField);
String tgtXPath = tgtFld.getXPath();
HashMap primaryKeyMap = reference.getPrimaryKeyMap();
CacheId pks = (CacheId) primaryKeyMap.get(tgtXPath);
ClassDescriptor descriptor = session.getClassDescriptor(referenceClass);
if (pks == null){
pks = new CacheId(new Object[0]);
primaryKeyMap.put(tgtXPath, pks);
}
Class type = descriptor.getTypedField(tgtFld).getType();
XMLConversionManager xmlConversionManager = (XMLConversionManager) session.getDatasourcePlatform().getConversionManager();
if(usesSingleNode) {
for (StringTokenizer stok = new StringTokenizer((String) object); stok.hasMoreTokens();) {
Object value = xmlConversionManager.convertObject(stok.nextToken(), type);
if (value != null) {
pks.add(value);
}
reference = resolver.getReference(this, srcObject, xmlField);
if (reference == null) {
// if reference is null, create a new instance and set it on the resolver
reference = new Reference(this, srcObject, referenceClass, new HashMap());
resolver.addReference(reference);
}
primaryKeyMap = reference.getPrimaryKeyMap();
pks = (CacheId) primaryKeyMap.get(null);
if (pks == null){
pks = new CacheId(new Object[0]);
primaryKeyMap.put(tgtXPath, pks);
}