/** INTERNAL: Build and return a new element based on the change set. */
  public Object buildAddedElementFromChangeSet(Object changeSet, MergeManager mergeManager) {
    ObjectChangeSet objectChangeSet = (ObjectChangeSet) changeSet;

    if (this.shouldMergeCascadeParts(mergeManager)) {
      Object targetElement = null;
      if (mergeManager.shouldMergeChangesIntoDistributedCache()) {
        targetElement =
            objectChangeSet.getTargetVersionOfSourceObject(mergeManager.getSession(), true);
      } else {
        targetElement = objectChangeSet.getUnitOfWorkClone();
      }
      mergeManager.mergeChanges(targetElement, objectChangeSet);
    }

    return this.buildElementFromChangeSet(changeSet, mergeManager);
  }
  /** INTERNAL: Build and return a new element based on the specified element. */
  public Object buildElementFromElement(Object element, MergeManager mergeManager) {
    if (this.shouldMergeCascadeParts(mergeManager)) {
      ObjectChangeSet objectChangeSet = null;
      if (mergeManager.getSession().isUnitOfWork()) {
        UnitOfWorkChangeSet uowChangeSet =
            (UnitOfWorkChangeSet)
                ((UnitOfWorkImpl) mergeManager.getSession()).getUnitOfWorkChangeSet();
        if (uowChangeSet != null) {
          objectChangeSet = (ObjectChangeSet) uowChangeSet.getObjectChangeSetForClone(element);
        }
      }
      Object mergeElement = mergeManager.getObjectToMerge(element);
      mergeManager.mergeChanges(mergeElement, objectChangeSet);
    }

    return mergeManager.getTargetVersionOfSourceObject(element);
  }