public int getNodeIndex ( NodeData parentData , InternalQName name , String skipIdentifier ) throws PathNotFoundException , IllegalPathException , RepositoryException { if ( name instanceof QPathEntry ) { name = new InternalQName ( name . getNamespace ( ) , name . getName ( ) ) ; } int newIndex = 1 ; NodeDefinitionData nodedef = nodeTypeDataManager . getChildNodeDefinition ( name , parentData . getPrimaryTypeName ( ) , parentData . getMixinTypeNames ( ) ) ; List < ItemState > transientAddChilds = getItemStatesList ( parentData , name , ItemState . ADDED , skipIdentifier ) ; List < ItemState > transientDeletedChilds ; if ( nodedef . isAllowsSameNameSiblings ( ) ) { transientDeletedChilds = getItemStatesList ( parentData , name , ItemState . DELETED , null ) ; } else { transientDeletedChilds = getItemStatesList ( parentData , new QPathEntry ( name , 0 ) , ItemState . DELETED , null ) ; ItemData sameNameNode = null ; try { sameNameNode = dataConsumer . getItemData ( parentData , new QPathEntry ( name , 0 ) , ItemType . NODE , false ) ; } catch ( PathNotFoundException e ) { // Ok no same name node; return newIndex ; } if ( ( ( sameNameNode != null ) || ( transientAddChilds . size ( ) > 0 ) ) ) { if ( ( sameNameNode != null ) && ( transientDeletedChilds . size ( ) < 1 ) ) { throw new ItemExistsException ( "The node already exists in " + sameNameNode . getQPath ( ) . getAsString ( ) + " and same name sibling is not allowed " ) ; } else if ( transientAddChilds . size ( ) > 0 ) { throw new ItemExistsException ( "The node already exists in add state " + " and same name sibling is not allowed " ) ; } } } newIndex += transientAddChilds . size ( ) ; List < NodeData > existedChilds = dataConsumer . getChildNodesData ( parentData ) ; // Calculate SNS index for dest root main : for ( int n = 0 , l = existedChilds . size ( ) ; n < l ; n ++ ) { NodeData child = existedChilds . get ( n ) ; if ( child . getQPath ( ) . getName ( ) . equals ( name ) ) { // skip deleted items if ( ! transientDeletedChilds . isEmpty ( ) ) { for ( int i = 0 , length = transientDeletedChilds . size ( ) ; i < length ; i ++ ) { ItemState state = transientDeletedChilds . get ( i ) ; if ( state . getData ( ) . equals ( child ) ) { transientDeletedChilds . remove ( i ) ; continue main ; } } } newIndex ++ ; // next sibling index } } // searching return newIndex ; }
Return new node index .