/**
   * For isMany=false properties set the value to null. For isMany=true set the value to an empty
   * container of the appropriate type.
   */
  public void unsetDeclaredProperty(int propertyIndex) {
    SDOProperty declaredProperty =
        (SDOProperty) dataObject.getType().getDeclaredProperties().get(propertyIndex);
    Mapping mapping = this.getJAXBMappingForProperty(declaredProperty);
    if (declaredProperty.isMany()) {
      ContainerMapping containerMapping = (ContainerMapping) mapping;
      ContainerPolicy containerPolicy = containerMapping.getContainerPolicy();

      // OLD VALUE
      if (mapping.isAbstractCompositeCollectionMapping()) {
        XMLCompositeCollectionMapping compositeMapping = (XMLCompositeCollectionMapping) mapping;
        if (compositeMapping.getContainerAccessor() != null) {

          Object oldContainer = mapping.getAttributeValueFromObject(entity);
          if (oldContainer != null) {
            AbstractSession session =
                ((JAXBContext) jaxbHelperContext.getJAXBContext())
                    .getXMLContext()
                    .getSession(entity);
            Object iterator = containerPolicy.iteratorFor(oldContainer);
            while (containerPolicy.hasNext(iterator)) {
              Object oldValue = containerPolicy.next(iterator, session);
              compositeMapping.getContainerAccessor().setAttributeValueInObject(oldValue, null);
            }
          }
        }
      }

      // NEW VALUE
      Object container = containerPolicy.containerInstance();
      mapping.getAttributeAccessor().setAttributeValueInObject(entity, container);
    } else {
      // OLD VALUE
      Object oldValue = mapping.getAttributeAccessor().getAttributeValueFromObject(entity);
      if (mapping.isAbstractCompositeObjectMapping()) {
        XMLCompositeObjectMapping compositeMapping = (XMLCompositeObjectMapping) mapping;
        if (compositeMapping.getContainerAccessor() != null) {
          if (oldValue != null) {
            compositeMapping.getContainerAccessor().setAttributeValueInObject(oldValue, null);
          }
        }
      }

      // NEW VALUE
      mapping.getAttributeAccessor().setAttributeValueInObject(entity, null);
    }
  }
  @Override
  public boolean marshalAttributes(
      MarshalRecord marshalRecord, Object object, CoreAbstractSession session) {
    lazyInitialize();
    boolean hasValue = false;
    NamespaceResolver namespaceResolver = ((Descriptor) descriptor).getNamespaceResolver();

    List<XPathNode> attributeChildren = rootXPathNode.getAttributeChildren();
    if (null != attributeChildren) {
      ObjectMarshalContext objectMarshalContext = ObjectMarshalContext.getInstance();
      for (XPathNode anAttributeChildren : attributeChildren) {
        hasValue =
            anAttributeChildren.marshal(
                    marshalRecord,
                    object,
                    session,
                    namespaceResolver,
                    null,
                    objectMarshalContext,
                    null)
                || hasValue;
      }
    }

    if (rootXPathNode.getAnyAttributeNode() != null) {
      hasValue =
          rootXPathNode
                  .getAnyAttributeNode()
                  .marshal(
                      marshalRecord,
                      object,
                      session,
                      namespaceResolver,
                      null,
                      ObjectMarshalContext.getInstance(),
                      null)
              || hasValue;
    }

    List<XPathNode> selfChildren = rootXPathNode.getSelfChildren();
    if (null != selfChildren) {
      for (XPathNode selfXPathNode : selfChildren) {
        NodeValue marshalNodeValue = selfXPathNode.getMarshalNodeValue();
        if (marshalNodeValue instanceof MappingNodeValue) {
          Mapping selfMapping = ((MappingNodeValue) marshalNodeValue).getMapping();
          Object value = selfMapping.getAttributeValueFromObject(object);
          Descriptor referenceDescriptor = (Descriptor) selfMapping.getReferenceDescriptor();
          Descriptor valueDescriptor;
          if (value != null
              && (referenceDescriptor == null || referenceDescriptor.hasInheritance())) {
            valueDescriptor = (Descriptor) session.getDescriptor(value.getClass());
          } else {
            valueDescriptor = referenceDescriptor;
          }
          if (null != valueDescriptor) {
            marshalRecord.addXsiTypeAndClassIndicatorIfRequired(
                valueDescriptor, referenceDescriptor, (Field) selfMapping.getField(), false);
          }
        }
        selfXPathNode.marshalSelfAttributes(
            marshalRecord, object, session, namespaceResolver, marshalRecord.getMarshaller());
      }
    }

    return hasValue;
  }