}
DOMRecord record = (DOMRecord) row;
Object attributeValue = this.getAttributeValueFromObject(object);
Node root = record.getDOM();
org.w3c.dom.Document doc = record.getDocument();
XMLField xmlRootField = null;
if (attributeValue == null) {
return;
}
if (field != null) {
root = XPathEngine.getInstance().create((XMLField) getField(), record.getDOM(), session);
DOMRecord rootRecord = new DOMRecord(root);
rootRecord.setSession(session);
rootRecord.setDocPresPolicy(record.getDocPresPolicy());
rootRecord.setNamespaceResolver(record.getNamespaceResolver());
rootRecord.setMarshaller(record.getMarshaller());
record = rootRecord;
}
ContainerPolicy cp = this.getContainerPolicy();
ArrayList childNodes = getUnmappedChildNodes(record.getDOM().getChildNodes());
Object iter = cp.iteratorFor(attributeValue);
int childNodeCount = 0;
boolean wasXMLRoot = false;
while (cp.hasNext(iter) && (childNodeCount < childNodes.size())) {
Object element = cp.next(iter, session);
if(this.getConverter() != null) {
element = getConverter().convertObjectValueToDataValue(element, session, record.getMarshaller());
}
Object originalObject = element;
Node nextChild = null;
while (childNodeCount < childNodes.size()) {
Node nextPossible = (Node) childNodes.get(childNodeCount);
if ((nextPossible.getNodeType() == Node.ELEMENT_NODE) || (nextPossible.getNodeType() == Node.TEXT_NODE) || (nextPossible.getNodeType() == Node.CDATA_SECTION_NODE)) {
nextChild = nextPossible;
childNodeCount++;
break;
}
childNodeCount++;
}
if (nextChild == null) {
break;
}
if (usesXMLRoot() && (element instanceof XMLRoot)) {
xmlRootField = new XMLField();
wasXMLRoot = true;
XPathFragment frag = new XPathFragment();
if ((((XMLRoot) element)).getRootFragment().getNamespaceURI() != null) {
frag.setNamespaceURI(((XMLRoot) element).getNamespaceURI());
} else {
frag.setXPath(((XMLRoot) element).getLocalName());
}
xmlRootField.setXPathFragment(frag);
xmlRootField.setNamespaceResolver(record.getNamespaceResolver());
element = ((XMLRoot) element).getObject();
}
if (element instanceof String) {
if (wasXMLRoot) {
if (((XMLRoot) originalObject).getRootFragment().getNamespaceURI() != null) {
String prefix = record.getNamespaceResolver().resolveNamespaceURI(((XMLRoot) originalObject).getRootFragment().getNamespaceURI());
if ((prefix == null) || prefix.equals("")) {
xmlRootField.getXPathFragment().setGeneratedPrefix(true);
prefix = record.getNamespaceResolver().generatePrefix();
}
xmlRootField.getXPathFragment().setXPath(prefix + ":" + ((XMLRoot) originalObject).getLocalName());
}
}
if (xmlRootField != null) {
XPathEngine.getInstance().create(xmlRootField, root, element, session);
} else {
Text textNode = doc.createTextNode((String) element);
root.replaceChild(textNode, nextChild);
}
} else if (element instanceof org.w3c.dom.Node) {
Node importedCopy = doc.importNode((Node) element, true);
root.replaceChild(importedCopy, nextChild);
} else {
XMLDescriptor referenceDescriptor = (XMLDescriptor) session.getDescriptor(element.getClass());
if (wasXMLRoot) {
if (((XMLRoot) originalObject).getRootFragment().getNamespaceURI() != null) {
String prefix = referenceDescriptor.getNonNullNamespaceResolver().resolveNamespaceURI(((XMLRoot) originalObject).getNamespaceURI());
if ((prefix == null) || prefix.equals("")) {
prefix = record.getNamespaceResolver().resolveNamespaceURI(((XMLRoot) originalObject).getRootFragment().getNamespaceURI());
}
if ((prefix == null) || prefix.equals("")) {
xmlRootField.getXPathFragment().setGeneratedPrefix(true);
prefix = record.getNamespaceResolver().generatePrefix();
}
xmlRootField.getXPathFragment().setXPath(prefix + ":" + ((XMLRoot) originalObject).getLocalName());
}
}
DOMRecord nestedRecord = (DOMRecord) buildCompositeRow(element, session, referenceDescriptor, row, xmlRootField, element, wasXMLRoot);
if (nestedRecord != null) {