directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1054545 - in /directory/shared/branches/shared-AP/ldap/src: main/java/org/apache/directory/shared/ldap/util/tree/DnNode.java test/java/org/apache/directory/shared/ldap/util/tree/DnNodeTest.java
Date Mon, 03 Jan 2011 07:57:13 GMT
Author: kayyagari
Date: Mon Jan  3 07:57:13 2011
New Revision: 1054545

URL: http://svn.apache.org/viewvc?rev=1054545&view=rev
Log:
o added rename operation and a test

Modified:
    directory/shared/branches/shared-AP/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnNode.java
    directory/shared/branches/shared-AP/ldap/src/test/java/org/apache/directory/shared/ldap/util/tree/DnNodeTest.java

Modified: directory/shared/branches/shared-AP/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnNode.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-AP/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnNode.java?rev=1054545&r1=1054544&r2=1054545&view=diff
==============================================================================
--- directory/shared/branches/shared-AP/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnNode.java
(original)
+++ directory/shared/branches/shared-AP/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnNode.java
Mon Jan  3 07:57:13 2011
@@ -34,13 +34,13 @@ import org.slf4j.LoggerFactory;
 
 
 /**
- * An class storing nodes in a tree designed to map DNs.<br/>
+ * A class storing nodes in a tree designed to map DNs.<br/>
  * Branch nodes in this tree refers to child nodes. Leaf nodes in the tree
  * don't have any children. <br/>
  * A node may contain a reference to an object whose suffix is the path through the
  * nodes of the tree from the root. <br/>
  * A node may also have no attached element.<br/>
- * Each node is referenced by a RDN, and holds the full DN corresponding to its position<br/>
+ * Each child node is referenced by a RDN, and holds the full DN corresponding to its position<br/>
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @param <N> The type of node we store
@@ -830,6 +830,51 @@ public class DnNode<N> implements Clonea
 
     
     /**
+     * rename the DnNode's DN
+     * 
+     * @param newRdn the new RDN of this node
+     * @throws LdapException
+     */
+    public void rename( RDN newRdn ) throws LdapException
+    {
+        DN temp = nodeDn.remove( nodeDn.size() - 1 );
+        temp = temp.add( newRdn );
+
+        RDN oldRdn = nodeRdn;
+        
+        nodeRdn = temp.getRdn();
+        nodeDn = temp;
+        
+        if ( parent != null )
+        {
+            parent.children.remove( oldRdn );
+            parent.children.put( nodeRdn, this );
+        }
+        
+        updateAfterModDn( nodeDn );
+    }
+    
+    
+    /**
+     * update the children's DN based on the new parent DN created
+     * after a rename or move operation
+     * 
+     * @param newParentDn
+     */
+    private void updateAfterModDn( DN newParentDn )
+    {
+        if ( children != null )
+        {
+            for( DnNode<N> child : children.values() )
+            {
+                child.nodeDn = newParentDn.add( child.nodeRdn );
+                child.updateAfterModDn( child.nodeDn );
+            }
+        }
+    }
+    
+    
+    /**
      * {@inheritDoc}
      */
     public DnNode<N> clone()

Modified: directory/shared/branches/shared-AP/ldap/src/test/java/org/apache/directory/shared/ldap/util/tree/DnNodeTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-AP/ldap/src/test/java/org/apache/directory/shared/ldap/util/tree/DnNodeTest.java?rev=1054545&r1=1054544&r2=1054545&view=diff
==============================================================================
--- directory/shared/branches/shared-AP/ldap/src/test/java/org/apache/directory/shared/ldap/util/tree/DnNodeTest.java
(original)
+++ directory/shared/branches/shared-AP/ldap/src/test/java/org/apache/directory/shared/ldap/util/tree/DnNodeTest.java
Mon Jan  3 07:57:13 2011
@@ -838,4 +838,31 @@ public class DnNodeTest
         assertEquals( dn1, dnLookupTree.getParentWithElement( test ).getElement() );
         assertNull( dnLookupTree.getParentWithElement( org ) );
     }
+    
+    
+    @Test
+    public void testRename() throws Exception
+    {
+        DnNode<DN> rootNode = new DnNode<DN>();
+        DN dn = new DN( "dc=directory,dc=apache,dc=org" );
+        rootNode.add( dn );
+        
+        RDN childRdn = new RDN( "dc=org" );
+
+        DnNode<DN> child = rootNode.getChild( childRdn );
+        assertNotNull( child );
+
+        RDN newChildRdn = new RDN( "dc=neworg" );
+
+        child.rename( newChildRdn );
+        assertNull( rootNode.getChild( childRdn ) );
+        assertEquals( new DN( "dc=neworg" ), child.getDn() );
+        
+        DnNode<DN> child2 = child.getChild( new RDN( "dc=apache" ) );
+        assertEquals( new DN( "dc=apache,dc=neworg" ), child2.getDn() );
+        
+        assertEquals( new DN( "dc=directory,dc=apache,dc=neworg" ), child2.getChild( new
RDN( "dc=directory" ) ).getDn() );
+        
+        assertNotNull( rootNode.getChild( newChildRdn ) );
+    }
 }



Mime
View raw message