* @param marshalRecord the marshalRecord to marshal the object to
* @param descriptor the XMLDescriptor for the object being marshalled
*/
private void marshal(Object object, MarshalRecord marshalRecord, XMLDescriptor descriptor, boolean isXMLRoot) {
addDescriptorNamespacesToXMLRecord(descriptor, marshalRecord);
NamespaceResolver nr = marshalRecord.getNamespaceResolver();
XMLRoot root = null;
if(isXMLRoot) {
root = (XMLRoot)object;
}
if (getMarshalListener() != null) {
getMarshalListener().beforeMarshal(object);
}
if (!isFragment()) {
String encoding = getEncoding();
String version = DEFAULT_XML_VERSION;
if (!isXMLRoot) {
marshalRecord.setLeafElementType(descriptor.getDefaultRootElementType());
} else {
if (root.getEncoding() != null) {
encoding = root.getEncoding();
}
if (root.getXMLVersion() != null) {
version = root.getXMLVersion();
}
}
marshalRecord.startDocument(encoding, version);
}
XPathFragment rootFragment = buildRootFragment(object, descriptor, isXMLRoot, marshalRecord);
boolean shouldWriteTypeAttribute = shouldWriteTypeAttribute(object, descriptor, isXMLRoot);
String schemaLocation = getSchemaLocation();
String noNsSchemaLocation = getNoNamespaceSchemaLocation();
if (isXMLRoot) {
object = root.getObject();
if (root.getSchemaLocation() != null) {
schemaLocation = root.getSchemaLocation();
}
if (root.getNoNamespaceSchemaLocation() != null) {
noNsSchemaLocation = root.getNoNamespaceSchemaLocation();
}
marshalRecord.setLeafElementType(root.getSchemaType());
}
String xsiPrefix = null;
if ((null != getSchemaLocation()) || (null != getNoNamespaceSchemaLocation()) || shouldWriteTypeAttribute) {
xsiPrefix = nr.resolveNamespaceURI(XMLConstants.SCHEMA_INSTANCE_URL);
if (null == xsiPrefix) {
xsiPrefix = XMLConstants.SCHEMA_INSTANCE_PREFIX;
nr.put(XMLConstants.SCHEMA_INSTANCE_PREFIX, XMLConstants.SCHEMA_INSTANCE_URL);
}
}
TreeObjectBuilder treeObjectBuilder = null;
AbstractSession session = null;