if (xmlAnyObjectMapping.isReadOnly()) {
return false;
}
XMLMarshaller marshaller = marshalRecord.getMarshaller();
Object objectValue = marshalContext.getAttributeValue(object, xmlAnyObjectMapping);
if(xmlAnyObjectMapping.getConverter() != null) {
objectValue = xmlAnyObjectMapping.getConverter().convertObjectValueToDataValue(objectValue, session, marshalRecord.getMarshaller());
}
if (null == objectValue) {
return false;
}
XPathFragment groupingFragment = marshalRecord.openStartGroupingElements(namespaceResolver);
marshalRecord.closeStartGroupingElements(groupingFragment);
boolean wasXMLRoot = false;
XPathFragment xmlRootFragment = null;
Object originalValue = objectValue;
if (xmlAnyObjectMapping.usesXMLRoot() && (objectValue instanceof XMLRoot)) {
xmlRootFragment = new XPathFragment();
wasXMLRoot = true;
objectValue = ((XMLRoot) objectValue).getObject();
}
if (objectValue instanceof String) {
marshalSimpleValue(xmlRootFragment, marshalRecord, originalValue, object, objectValue, session, namespaceResolver);
} else {
Session childSession = null;
try {
childSession = marshaller.getXMLContext().getSession(objectValue);
} catch (XMLMarshalException e) {
marshalSimpleValue(xmlRootFragment, marshalRecord, originalValue, object, objectValue, session, namespaceResolver);
return true;
}
XMLDescriptor descriptor = (XMLDescriptor) childSession.getDescriptor(objectValue);
TreeObjectBuilder objectBuilder = (TreeObjectBuilder) descriptor.getObjectBuilder();
List extraNamespaces = objectBuilder.addExtraNamespacesToNamespaceResolver(descriptor, marshalRecord, session);
if (wasXMLRoot) {
Namespace generatedNamespace = setupFragment(((XMLRoot) originalValue), xmlRootFragment, marshalRecord);
if (generatedNamespace != null) {
extraNamespaces.add(generatedNamespace);
}
}
/*
* B5112171: 25 Apr 2006
* During marshalling - XML AnyObject and AnyCollection
* mappings throw a NullPointerException when the
* "document root element" on child object descriptors are not
* all defined. These nodes will be ignored with a warning.
*/
String defaultRootElementString = descriptor.getDefaultRootElement();
if (!wasXMLRoot && (defaultRootElementString == null)) {
AbstractSessionLog.getLog().log(SessionLog.WARNING, "marshal_warning_null_document_root_element", new Object[] { Helper.getShortClassName(this.getClass()), descriptor });
} else {
if ((marshaller != null) && (marshaller.getMarshalListener() != null)) {
marshaller.getMarshalListener().beforeMarshal(objectValue);
}
if (xmlRootFragment != null) {
rootFragment = xmlRootFragment;
} else {
rootFragment = new XPathFragment(defaultRootElementString);
//resolve URI
if ((rootFragment.getNamespaceURI() == null) && (rootFragment.getPrefix() != null)) {
String uri = descriptor.getNonNullNamespaceResolver().resolveNamespacePrefix(rootFragment.getPrefix());
rootFragment.setNamespaceURI(uri);
}
}
if (!wasXMLRoot) {
marshalRecord.setLeafElementType(descriptor.getDefaultRootElementType());
}
getXPathNode().startElement(marshalRecord, rootFragment, object, session, descriptor.getNonNullNamespaceResolver(), objectBuilder, objectValue);
if (xmlAnyObjectMapping.shouldAddXsiType(marshaller, descriptor, originalValue, wasXMLRoot)) {
String typeValue = descriptor.getSchemaReference().getSchemaContext();
addTypeAttribute(descriptor, marshalRecord, typeValue);
}
writeExtraNamespaces(extraNamespaces, marshalRecord, session);
objectBuilder.buildRow(marshalRecord, objectValue, (org.eclipse.persistence.internal.sessions.AbstractSession) childSession, marshaller);
marshalRecord.endElement(rootFragment, namespaceResolver);
objectBuilder.removeExtraNamespacesFromNamespaceResolver(marshalRecord, extraNamespaces, session);
if ((marshaller != null) && (marshaller.getMarshalListener() != null)) {
marshaller.getMarshalListener().afterMarshal(objectValue);
}
}
}
return true;