public void initializeDescriptor(XMLDescriptor descriptor) {
   AbstractSession theSession = (AbstractSession) getXmlContext().getSession(0);
   // do initialization for new descriptor;
   descriptor.preInitialize(theSession);
   descriptor.initialize(theSession);
   descriptor.postInitialize(theSession);
   descriptor.getObjectBuilder().initializePrimaryKey(theSession);
   getXmlContext().storeXMLDescriptorByQName(descriptor);
 }
  /** Set the value on the underlying POJO, unwrapping values as necessary. */
  public void setDeclaredProperty(int propertyIndex, Object value) {
    SDOProperty declaredProperty =
        (SDOProperty) dataObject.getType().getDeclaredProperties().get(propertyIndex);
    if (declaredProperty.getType().isChangeSummaryType()) {
      return;
    }

    Mapping mapping = this.getJAXBMappingForProperty(declaredProperty);

    Object newValue = value;
    Object oldValue = mapping.getAttributeAccessor().getAttributeValueFromObject(entity);

    if (declaredProperty.getType().isDataType()) {
      if (!declaredProperty.isMany()) {
        AbstractSession session =
            ((JAXBContext) jaxbHelperContext.getJAXBContext()).getXMLContext().getSession(entity);
        XMLDirectMapping directMapping = (XMLDirectMapping) mapping;
        if (directMapping.hasConverter()) {
          newValue = directMapping.getConverter().convertDataValueToObjectValue(newValue, session);
        } else {
          CoreField field = mapping.getField();
          newValue =
              session
                  .getDatasourcePlatform()
                  .getConversionManager()
                  .convertObject(
                      newValue,
                      descriptor.getObjectBuilder().getFieldClassification((XMLField) field));
        }
      }
      mapping.setAttributeValueInObject(entity, newValue);
    } else if (declaredProperty.isMany()) {
      // Get a ListWrapper and set it's current elements
      ListWrapper listWrapper = (ListWrapper) getDeclaredProperty(propertyIndex);
      listWrapper.addAll((List) newValue);
    } else {
      // OLD VALUE
      if (mapping.isAbstractCompositeObjectMapping()) {
        XMLCompositeObjectMapping compositeMapping = (XMLCompositeObjectMapping) mapping;
        if (oldValue != null && compositeMapping.getContainerAccessor() != null) {
          compositeMapping.getContainerAccessor().setAttributeValueInObject(oldValue, null);
        }
      }

      // NEW VALUE
      newValue = jaxbHelperContext.unwrap((DataObject) value);
      mapping.getAttributeAccessor().setAttributeValueInObject(entity, newValue);
      if (mapping.isAbstractCompositeObjectMapping()) {
        XMLCompositeObjectMapping compositeMapping = (XMLCompositeObjectMapping) mapping;
        if (value != null && compositeMapping.getContainerAccessor() != null) {
          compositeMapping.getContainerAccessor().setAttributeValueInObject(newValue, entity);
        }
      }
    }
  }
 /**
  * Return the JAXB mapping for the SDO property. They are matched on their XML schema
  * representation.
  */
 Mapping getJAXBMappingForProperty(SDOProperty sdoProperty) {
   DatabaseMapping sdoMapping = sdoProperty.getXmlMapping();
   XMLField field;
   if (sdoMapping instanceof XMLObjectReferenceMapping) {
     XMLObjectReferenceMapping referenceMapping = (XMLObjectReferenceMapping) sdoMapping;
     field = (XMLField) referenceMapping.getFields().get(0);
   } else {
     field = (XMLField) sdoMapping.getField();
   }
   TreeObjectBuilder treeObjectBuilder = (TreeObjectBuilder) descriptor.getObjectBuilder();
   XPathNode xPathNode = treeObjectBuilder.getRootXPathNode();
   XPathFragment xPathFragment = field.getXPathFragment();
   while (xPathNode != null && xPathFragment != null) {
     if (xPathFragment.isAttribute()) {
       if (sdoProperty.isMany()
           && !sdoProperty.isContainment()
           && !sdoProperty.getType().isDataType()) {
         xPathFragment = null;
         break;
       }
       Map attributeChildrenMap = xPathNode.getAttributeChildrenMap();
       if (null == attributeChildrenMap) {
         xPathNode = null;
       } else {
         xPathNode = (XPathNode) attributeChildrenMap.get(xPathFragment);
       }
     } else if (xPathFragment.nameIsText()) {
       xPathNode = xPathNode.getTextNode();
     } else {
       Map nonAttributeChildrenMap = xPathNode.getNonAttributeChildrenMap();
       if (null == nonAttributeChildrenMap) {
         xPathNode = null;
       } else {
         xPathNode = (XPathNode) nonAttributeChildrenMap.get(xPathFragment);
       }
     }
     xPathFragment = xPathFragment.getNextFragment();
     if (xPathFragment != null && xPathFragment.nameIsText()) {
       if (sdoProperty.isMany() && !sdoProperty.isContainment()) {
         xPathFragment = null;
         break;
       }
     }
   }
   if (null == xPathFragment && xPathNode != null) {
     if (xPathNode.getNodeValue().isMappingNodeValue()) {
       MappingNodeValue mappingNodeValue = (MappingNodeValue) xPathNode.getNodeValue();
       return mappingNodeValue.getMapping();
     }
   }
   throw SDOException.sdoJaxbNoMappingForProperty(sdoProperty.getName(), field.getXPath());
 }