/**
   * INTERNAL: Make a copy of all settings on the original sequence onto the copy sequence while
   * using a cross-reference doMap that relates the original DataObject key to the copy DataObject
   * key. This function is used during deep copy and changeSummary copy.
   *
   * @param origSequence
   * @param copySequence
   * @param doMap
   */
  private void replicateAndRereferenceSequenceCopyPrivate(
      SDOSequence origSequence,
      SDOSequence copySequence,
      DataObject dataObject,
      DataObject copy,
      Map doMap,
      SDOChangeSummary cs) {
    if (cs != null && cs.isDeleted(dataObject)) {
      origSequence = cs.getOldSequence(dataObject);
    }

    SDOProperty seqProperty = null;
    try {
      List settings = origSequence.getSettings();
      for (int index = 0, size = origSequence.size(); index < size; index++) {
        Setting nextSetting = (Setting) settings.get(index);
        seqProperty = origSequence.getProperty(nextSetting);

        if ((null == seqProperty) || seqProperty.getType().isDataType()) {
          Setting copySetting = nextSetting.copy(copy);
          copySequence.getSettings().add(copySetting);
          copySequence.addValueToSettings(copySetting);
        } else {
          Object copySeqValue = null;
          Object origSeqValue = origSequence.getValue(index);

          if (cs != null) {
            Object orig = cs.getReverseDeletedMap().get(origSeqValue);
            if (orig != null) {
              origSeqValue = orig;
            }
          }

          if (origSeqValue instanceof XMLRoot) {
            origSeqValue = ((XMLRoot) origSeqValue).getObject();
          }

          // lookup copy if not null, if null then the copySeqValue will be null in the reduced
          // scope assignment above
          if (null != origSeqValue) {
            copySeqValue = doMap.get(origSeqValue);
          } else {
            // as a secondary verification to the assignment above - make sure the copy is null as
            // well
            copySeqValue =
                null; // this assignment is however redundant in our reduced scope assignment above
          }

          // now we have the new value
          Setting copySetting = nextSetting.copy(copy, copySeqValue);
          copySequence.getSettings().add(copySetting);
          copySequence.addValueToSettings(copySetting);
        }

        /**
         * Move assignment inside the loop to minimize scope and to initialize the variable to null
         * to handle the case where the original is null and no lookup is performed. Do not move the
         * scope of this variable outside the for loop or we will end up with the previous
         * iterations' value set for a complex object that is unset(null). see #6026714
         */
      }
    } catch (ClassCastException cce) { // catch any failure of a DataObject cast above
      throw SDOException.foundSimpleValueForNonDataTypeProperty(seqProperty.getName());
    }
  }