if ((marshaller != null) && (marshaller.getMarshalListener() != null)) {
marshaller.getMarshalListener().beforeMarshal(object);
}
List extraNamespaces = null;
if (isXmlDescriptor()) {
XMLDescriptor xmlDescriptor = (XMLDescriptor)getDescriptor();
extraNamespaces = addExtraNamespacesToNamespaceResolver(xmlDescriptor, record, session);
writeExtraNamespaces(extraNamespaces, record);
}
writeOutMappings(record, object, session);
// If this descriptor is involved in inheritance add the class type.
if (isXmlDescriptor()) {
XMLDescriptor xmlDescriptor = (XMLDescriptor)getDescriptor();
XMLSchemaReference xmlRef = xmlDescriptor.getSchemaReference();
if (shouldWriteXsiType) {
writeXsiTypeAttribute(xmlDescriptor, (DOMRecord)record, xmlRef.getSchemaContext().substring(1));
}
if (getDescriptor().hasInheritance()) {
if ((record.getLeafElementType() != null) && ((xmlRef.getType() == 1) && xmlRef.isGlobalDefinition())) {
// only interested in global COMPLEX_TYPE
QName ctxQName = xmlRef.getSchemaContextAsQName(xmlDescriptor.getNamespaceResolver());
if (ctxQName.equals(record.getLeafElementType())) {
// don't write out xsi:type attribute
} else {
// write out the target descriptor's schema context as xsi:type
XMLField xmlField = (XMLField)xmlDescriptor.getInheritancePolicy().getClassIndicatorField();
if (xmlField.getLastXPathFragment().isAttribute()) {
writeXsiTypeAttribute(xmlDescriptor, (DOMRecord)record, xmlRef.getSchemaContext().substring(1));
} else {
writeXsiTypeAttribute(xmlDescriptor, (DOMRecord)record, xmlRef.getSchemaContext().substring(1));
}
}
// if the user has set the element type, but the target descriptor's
// schema context in not a global complex type or is null, delegate
// the work to the inheritance policy
} else {
// no user-set element type, so proceed via inheritance policy
if (!xmlDescriptor.getInheritancePolicy().hasClassExtractor()) {
XMLField xmlField = (XMLField)xmlDescriptor.getInheritancePolicy().getClassIndicatorField();
if (xmlField.getLastXPathFragment().isAttribute()) {
getDescriptor().getInheritancePolicy().addClassIndicatorFieldToRow(row);
} else {
getDescriptor().getInheritancePolicy().addClassIndicatorFieldToRow(row);
}