Exemplo n.º 1
0
  public ValueStore copy() {
    AbstractSession session =
        ((JAXBContext) jaxbHelperContext.getJAXBContext()).getXMLContext().getSession(entity);
    Object originalEntity = entity;
    entity = descriptor.getInstantiationPolicy().buildNewInstance();

    for (SDOProperty sdoProperty : (List<SDOProperty>) dataObject.getType().getProperties()) {
      if (!sdoProperty.getType().isChangeSummaryType()) {
        Mapping mapping = getJAXBMappingForProperty(sdoProperty);
        CoreAttributeAccessor attributeAccessor = mapping.getAttributeAccessor();
        Object attributeValue = attributeAccessor.getAttributeValueFromObject(originalEntity);
        if (mapping.isCollectionMapping()) {
          Object containerCopy = null;
          SDOChangeSummary sdoChangeSummary = dataObject.getChangeSummary();
          if (null != sdoChangeSummary) {
            List list = listWrappers.get(sdoProperty);
            containerCopy = sdoChangeSummary.getOriginalElements().get(list);
          }
          if (null == containerCopy) {
            CoreContainerPolicy containerPolicy = mapping.getContainerPolicy();
            containerCopy = containerPolicy.containerInstance();
            if (null != attributeValue) {
              Object attributeValueIterator = containerPolicy.iteratorFor(attributeValue);
              while (containerPolicy.hasNext(attributeValueIterator)) {
                containerPolicy.addInto(
                    containerPolicy.nextEntry(attributeValueIterator), containerCopy, session);
              }
            }
          }
          attributeAccessor.setAttributeValueInObject(entity, containerCopy);
        } else {
          attributeAccessor.setAttributeValueInObject(entity, attributeValue);
        }
      }
    }
    return new JAXBValueStore(
        jaxbHelperContext, originalEntity, descriptor, dataObject, listWrappers);
  }