private void removeExisted(NodeData sameUuidItem) throws RepositoryException, ConstraintViolationException,
      PathNotFoundException
   {

      if (!nodeTypeDataManager.isNodeType(Constants.MIX_REFERENCEABLE, sameUuidItem.getPrimaryTypeName(), sameUuidItem
         .getMixinTypeNames()))
      {
         throw new RepositoryException("An incoming referenceable node has the same "
            + " UUID as a identifier of non mix:referenceable" + " node already existing in the workspace!");
      }

      // If an incoming referenceable node has the same UUID as a node
      // already existing in the workspace then the already existing
      // node (and its subtree) is removed from wherever it may be in
      // the workspace before the incoming node is added. Note that this
      // can result in nodes disappearing from locations in the
      // workspace that are remote from the location to which the
      // incoming subtree is being written.
      // parentNodeData = (NodeData) sameUuidItem.getParent().getData();

      QPath sameUuidPath = sameUuidItem.getQPath();

      if (ancestorToSave.isDescendantOf(sameUuidPath) || ancestorToSave.equals(sameUuidPath))
      {
         throw new ConstraintViolationException("The imported document contains a element"
            + " with jcr:uuid attribute the same as the  parent of the import target.");
      }

      setAncestorToSave(QPath.getCommonAncestorPath(ancestorToSave, sameUuidPath));

      ItemDataRemoveVisitor visitor =
         new ItemDataRemoveVisitor(dataConsumer, getAncestorToSave(), nodeTypeDataManager, accessManager, userState);
      sameUuidItem.accept(visitor);

      changesLog.addAll(visitor.getRemovedStates());
      
      // Refresh the indexes if needed
      boolean reloadSNS =
         uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING
            || uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING;
      if (reloadSNS)
      {
         NodeData parentData = (NodeData)dataConsumer.getItemData(sameUuidItem.getParentIdentifier());
         ItemState lastState = getLastItemState(sameUuidItem.getParentIdentifier());

         if (sameUuidItem != null && (lastState == null || !lastState.isDeleted()))
         {
            InternalQName name =
               new InternalQName(sameUuidItem.getQPath().getName().getNamespace(), sameUuidItem.getQPath().getName()
                  .getName());
            List<ItemState> transientAddChilds = getItemStatesList(parentData, name, ItemState.ADDED, null);
            if (transientAddChilds.isEmpty())
               return;
            List<ItemState> statesToReLoad = new LinkedList<ItemState>();
            for (int i = 0, length = transientAddChilds.size(); i < length; i++)
            {
               ItemState state = transientAddChilds.get(i);
               if (sameUuidItem.getQPath().getIndex() < state.getData().getQPath().getIndex() && state.getData() instanceof ImportNodeData)
               {
                  statesToReLoad.add(state);
               }
            }
            if (statesToReLoad.isEmpty())
               return;
            for (ItemState state : statesToReLoad)
            {
               ImportNodeData node = (ImportNodeData)state.getData();
               reloadChangesInfoAfterUC(parentData, node, node.getIdentifier());
            }
         }
      }
   }
private void removeExisted ( NodeData sameUuidItem ) throws RepositoryException , ConstraintViolationException , PathNotFoundException { if ( ! nodeTypeDataManager . isNodeType ( Constants . MIX_REFERENCEABLE , sameUuidItem . getPrimaryTypeName ( ) , sameUuidItem . getMixinTypeNames ( ) ) ) { throw new RepositoryException ( "An incoming referenceable node has the same " + " UUID as a identifier of non mix:referenceable" + " node already existing in the workspace!" ) ; } QPath sameUuidPath = sameUuidItem . getQPath ( ) ; if ( ancestorToSave . isDescendantOf ( sameUuidPath ) || ancestorToSave . equals ( sameUuidPath ) ) { throw new ConstraintViolationException ( "The imported document contains a element" + " with jcr:uuid attribute the same as the  parent of the import target." ) ; } setAncestorToSave ( QPath . getCommonAncestorPath ( ancestorToSave , sameUuidPath ) ) ; ItemDataRemoveVisitor visitor = new ItemDataRemoveVisitor ( dataConsumer , getAncestorToSave ( ) , nodeTypeDataManager , accessManager , userState ) ; sameUuidItem . accept ( visitor ) ; changesLog . addAll ( visitor . getRemovedStates ( ) ) ; boolean reloadSNS = uuidBehavior == ImportUUIDBehavior . IMPORT_UUID_COLLISION_REMOVE_EXISTING || uuidBehavior == ImportUUIDBehavior . IMPORT_UUID_COLLISION_REPLACE_EXISTING ; if ( reloadSNS ) { NodeData parentData = ( NodeData ) dataConsumer . getItemData ( sameUuidItem . getParentIdentifier ( ) ) ; ItemState lastState = getLastItemState ( sameUuidItem . getParentIdentifier ( ) ) ; if ( sameUuidItem != null && ( lastState == null || ! lastState . isDeleted ( ) ) ) { InternalQName name = new InternalQName ( sameUuidItem . getQPath ( ) . getName ( ) . getNamespace ( ) , sameUuidItem . getQPath ( ) . getName ( ) . getName ( ) ) ; List < ItemState > transientAddChilds = getItemStatesList ( parentData , name , ItemState . ADDED , null ) ; if ( transientAddChilds . isEmpty ( ) ) return ; List < ItemState > statesToReLoad = new LinkedList < ItemState > ( ) ; for ( int i = 0 , length = transientAddChilds . size ( ) ; i < length ; i ++ ) { ItemState state = transientAddChilds . get ( i ) ; if ( sameUuidItem . getQPath ( ) . getIndex ( ) < state . getData ( ) . getQPath ( ) . getIndex ( ) && state . getData ( ) instanceof ImportNodeData ) { statesToReLoad . add ( state ) ; } } if ( statesToReLoad . isEmpty ( ) ) return ; for ( ItemState state : statesToReLoad ) { ImportNodeData node = ( ImportNodeData ) state . getData ( ) ; reloadChangesInfoAfterUC ( parentData , node , node . getIdentifier ( ) ) ; } } } }
Remove existed item.

@param sameUuidItem
@throws RepositoryException
@throws ConstraintViolationException
@throws PathNotFoundException