*
* @param xdesc
* @param pCls
*/
private void addClassIndicator(XMLDescriptor xdesc, Class pCls, boolean isInheritanceRoot) {
XMLField field = (XMLField)getXmlDescriptor().buildField("@xsi:type");
xdesc.getInheritancePolicy().setClassIndicatorField(field);
String parentIndicator = getName();
String parentPrefix = xdesc.getNamespaceResolver().resolveNamespaceURI(getURI());
if (parentPrefix != null) {
parentIndicator = parentPrefix + SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT + parentIndicator;
}
xdesc.getInheritancePolicy().addClassIndicator(pCls, parentIndicator);
// In some cases such as defining types via DataObject API (not by schema) we need
// to add an inheritance node value to TreeObjectBuilder in order to have the class
// indicator (xsi:type) written out
if (isInheritanceRoot) {
InheritanceNodeValue inheritanceNodeValue = new InheritanceNodeValue();
inheritanceNodeValue.setInheritancePolicy(xdesc.getInheritancePolicy());
((TreeObjectBuilder)xmlDescriptor.getObjectBuilder()).addChild(field.getXPathFragment(), inheritanceNodeValue, xmlDescriptor.getNamespaceResolver());
}
// only add the @sdoRef attribute if necessary
if (xdesc.getMappingForAttributeName(SDO_REF_MAPPING_ATTRIBUTE_NAME) == null) {
String sdoPrefix = ((SDOTypeHelper)aHelperContext.getTypeHelper()).getPrefix(SDOConstants.SDO_URL);
XMLDirectMapping sdoRefMapping = new XMLDirectMapping();
sdoRefMapping.setAttributeName(SDO_REF_MAPPING_ATTRIBUTE_NAME);
XMLField xmlField = new XMLField("@" + sdoPrefix + SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT + SDOConstants.CHANGESUMMARY_REF);
xmlField.getXPathFragment().setNamespaceURI(SDOConstants.SDO_URL);
xmlField.getLastXPathFragment().setNamespaceURI(SDOConstants.SDO_URL);
sdoRefMapping.setField(xmlField);
xdesc.addMapping(sdoRefMapping);
}
}