directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1072019 - in /directory: apacheds/branches/m1/core-integ/src/test/java/org/apache/directory/server/core/trigger/ apacheds/branches/m1/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ shared/branches/m1/integ/src/test/...
Date Fri, 18 Feb 2011 15:17:04 GMT
Author: elecharny
Date: Fri Feb 18 15:16:49 2011
New Revision: 1072019

URL: http://svn.apache.org/viewvc?rev=1072019&view=rev
Log:
o Removed the Dn.get( int ) method
o Added the getDescendantOf( Dn/String ) methods
o Fixed the tests and the code accordingly

Modified:
    directory/apacheds/branches/m1/core-integ/src/test/java/org/apache/directory/server/core/trigger/BackupUtilitiesSP.java
    directory/apacheds/branches/m1/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java
    directory/shared/branches/m1/integ/src/test/java/org/apache/directory/shared/ldap/name/DnTest.java
    directory/shared/branches/m1/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java

Modified: directory/apacheds/branches/m1/core-integ/src/test/java/org/apache/directory/server/core/trigger/BackupUtilitiesSP.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/m1/core-integ/src/test/java/org/apache/directory/server/core/trigger/BackupUtilitiesSP.java?rev=1072019&r1=1072018&r2=1072019&view=diff
==============================================================================
--- directory/apacheds/branches/m1/core-integ/src/test/java/org/apache/directory/server/core/trigger/BackupUtilitiesSP.java
(original)
+++ directory/apacheds/branches/m1/core-integ/src/test/java/org/apache/directory/server/core/trigger/BackupUtilitiesSP.java
Fri Feb 18 15:16:49 2011
@@ -24,7 +24,6 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.entry.ClonedServerEntry;
 import org.apache.directory.shared.ldap.model.entry.Entry;
 import org.apache.directory.shared.ldap.model.name.Dn;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -51,7 +50,7 @@ public class BackupUtilitiesSP
     {
         LOG.info( "User \"" + session.getEffectivePrincipal() + "\" has deleted entry \""
+ deletedEntry + "\"" );
         Dn backupDn = new Dn( "ou=backupContext,ou=system" );
-        String deletedEntryRdn = deletedEntry.getDn().get( deletedEntry.getDn().size() -
1 );
+        String deletedEntryRdn = deletedEntry.getDn().getRdn().getName();
         Entry entry = ( Entry ) deletedEntry.getOriginalEntry().clone();
         backupDn = backupDn.add( deletedEntryRdn );
         entry.setDn( backupDn );

Modified: directory/apacheds/branches/m1/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/m1/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java?rev=1072019&r1=1072018&r2=1072019&view=diff
==============================================================================
--- directory/apacheds/branches/m1/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java
(original)
+++ directory/apacheds/branches/m1/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java
Fri Feb 18 15:16:49 2011
@@ -1403,19 +1403,10 @@ public class SearchHandler extends LdapR
              * Dn of the ref LDAP URL.  We must calculate the remaining (difference)
              * name past the farthest referral Dn which the target name extends.
              */
-            int diff = req.getBase().size() - referralAncestor.getDn().size();
-            Dn extra = new Dn();
-
-            // TODO - fix this by access unormalized Rdn values
-            // seems we have to do this because get returns normalized rdns
-            Dn reqUnnormalizedDn = new Dn( req.getBase().getName() );
-            for ( int jj = 0; jj < diff; jj++ )
-            {
-                extra = extra.add( reqUnnormalizedDn.get( referralAncestor.getDn().size()
+ jj ) );
-            }
-
-            urlDn = urlDn.addAll( extra );
-            ldapUrl.setDn( urlDn );
+            Dn suffix = req.getBase().getDescendantOf( referralAncestor.getDn() );
+            Dn refDn = urlDn.addAll( suffix );
+            
+            ldapUrl.setDn( refDn );
             ldapUrl.setForceScopeRendering( true );
             ldapUrl.setAttributes( req.getAttributes() );
             ldapUrl.setScope( req.getScope().getScope() );
@@ -1491,18 +1482,8 @@ public class SearchHandler extends LdapR
              * Dn of the ref LDAP URL.  We must calculate the remaining (difference)
              * name past the farthest referral Dn which the target name extends.
              */
-            int diff = reqTargetDn.size() - referralAncestor.getDn().size();
-            Dn extra = new Dn();
-
-            // TODO - fix this by access unormalized Rdn values
-            // seems we have to do this because get returns normalized rdns
-            Dn reqUnnormalizedDn = new Dn( reqTargetDn.getName() );
-            for ( int jj = 0; jj < diff; jj++ )
-            {
-                extra = extra.add( reqUnnormalizedDn.get( referralAncestor.getDn().size()
+ jj ) );
-            }
-
-            urlDn = urlDn.addAll( extra );
+            Dn suffix = req.getBase().getDescendantOf( referralAncestor.getDn() );
+            urlDn = urlDn.addAll( suffix );
 
             StringBuilder buf = new StringBuilder();
             buf.append( ldapUrl.getScheme() );

Modified: directory/shared/branches/m1/integ/src/test/java/org/apache/directory/shared/ldap/name/DnTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/m1/integ/src/test/java/org/apache/directory/shared/ldap/name/DnTest.java?rev=1072019&r1=1072018&r2=1072019&view=diff
==============================================================================
--- directory/shared/branches/m1/integ/src/test/java/org/apache/directory/shared/ldap/name/DnTest.java
(original)
+++ directory/shared/branches/m1/integ/src/test/java/org/apache/directory/shared/ldap/name/DnTest.java
Fri Feb 18 15:16:49 2011
@@ -1139,228 +1139,6 @@ public class DnTest
     }
 
 
-    // GET ALL operations
-    /**
-     * test a getAll operation on a null Dn
-     *
-    @Test
-    public void testDnGetAllNull()
-    {
-        Dn dn = new Dn();
-        Enumeration<String> nc = dn.getAll();
-
-        assertEquals( false, nc.hasMoreElements() );
-    }
-
-
-    /**
-     * test a getAll operation on an empty Dn
-     *
-    @Test
-    public void testDnGetAllEmpty() throws LdapException
-    {
-        Dn dn = new Dn( "" );
-        Enumeration<String> nc = dn.getAll();
-
-        assertEquals( false, nc.hasMoreElements() );
-    }
-
-
-    /**
-     * test a getAll operation on a simple Dn
-     *
-    @Test
-    public void testDnGetAllSimple() throws LdapException
-    {
-        Dn dn = new Dn( "a=b" );
-        Enumeration<String> nc = dn.getAll();
-
-        assertEquals( true, nc.hasMoreElements() );
-        assertEquals( "a=b", nc.nextElement() );
-        assertEquals( false, nc.hasMoreElements() );
-    }
-
-
-    /**
-     * test a getAll operation on a complex Dn
-     *
-    @Test
-    public void testDnGetAllComplex() throws LdapException
-    {
-        Dn dn = new Dn( "e=f+g=h,a=b,c=d" );
-        Enumeration<String> nc = dn.getAll();
-
-        assertEquals( true, nc.hasMoreElements() );
-        assertEquals( "c=d", nc.nextElement() );
-        assertEquals( true, nc.hasMoreElements() );
-        assertEquals( "a=b", nc.nextElement() );
-        assertEquals( true, nc.hasMoreElements() );
-        assertEquals( "e=f+g=h", nc.nextElement() );
-        assertEquals( false, nc.hasMoreElements() );
-    }
-
-
-    /**
-     * test a getAll operation on a complex Dn
-     *
-    @Test
-    public void testDnGetAllComplexOrdered() throws LdapException
-    {
-        Dn dn = new Dn( "g=h+e=f,a=b,c=d" );
-        Enumeration<String> nc = dn.getAll();
-
-        assertEquals( true, nc.hasMoreElements() );
-        assertEquals( "c=d", nc.nextElement() );
-        assertEquals( true, nc.hasMoreElements() );
-        assertEquals( "a=b", nc.nextElement() );
-        assertEquals( true, nc.hasMoreElements() );
-
-        assertEquals( "e=f+g=h", nc.nextElement() );
-        assertEquals( false, nc.hasMoreElements() );
-    }
-
-
-    // CLONE Operation
-    /**
-     * test a clone operation on a empty Dn
-     *
-    @Test
-    public void testDnCloneEmpty()
-    {
-        Dn dn = new Dn();
-        Dn clone = (Dn) dn.clone();
-
-        assertEquals( "", clone.getName() );
-    }
-
-
-    /**
-     * test a clone operation on a simple Dn
-     *
-    @Test
-    public void testDnCloneSimple() throws LdapException
-    {
-        Dn dn = new Dn( "a=b" );
-        Dn clone = (Dn) dn.clone();
-
-        assertEquals( "a=b", clone.getName() );
-        dn.remove( 0 );
-        assertEquals( "a=b", clone.getName() );
-    }
-
-
-    /**
-     * test a clone operation on a complex Dn
-     *
-    @Test
-    public void testDnCloneComplex() throws LdapException
-    {
-        Dn dn = new Dn( "e=f+g=h,a=b,c=d" );
-        Dn clone = (Dn) dn.clone();
-
-        assertEquals( "e=f+g=h,a=b,c=d", clone.getName() );
-        dn.remove( 2 );
-        assertEquals( "e=f+g=h,a=b,c=d", clone.getName() );
-    }
-
-
-    // GET operations
-    /**
-     * test a get in a null Dn
-     */
-    @Test
-    public void testDnGetNull()
-    {
-        Dn dn = new Dn();
-        assertEquals( "", dn.get( 0 ) );
-    }
-
-
-    /**
-     * test a get in an empty Dn
-     */
-    @Test
-    public void testDnGetEmpty() throws LdapException
-    {
-        Dn dn = new Dn( "" );
-        assertEquals( "", dn.get( 0 ) );
-    }
-
-
-    /**
-     * test a get in a simple Dn
-     */
-    @Test
-    public void testDnGetSimple() throws LdapException
-    {
-        Dn dn = new Dn( "a = b" );
-        assertEquals( "a=b", dn.get( 0 ) );
-    }
-
-
-    /**
-     * test a get in a complex Dn
-     */
-    @Test
-    public void testDnGetComplex() throws LdapException
-    {
-        Dn dn = new Dn( "a = b + c= d, e= f; g =h" );
-        assertEquals( "g=h", dn.get( 0 ) );
-        assertEquals( "e=f", dn.get( 1 ) );
-        assertEquals( "a=b+c=d", dn.get( 2 ) );
-    }
-
-
-    /**
-     * test a get out of bound
-     */
-    @Test
-    public void testDnGetOutOfBound() throws LdapException
-    {
-        Dn dn = new Dn( "a = b + c= d, e= f; g =h" );
-
-        try
-        {
-            dn.get( 4 );
-            fail();
-        }
-        catch ( IndexOutOfBoundsException aioob )
-        {
-            assertTrue( true );
-        }
-    }
-
-
-    /**
-     * Tests the examples from the JNDI tutorials to make sure LdapName behaves
-     * appropriately. The example can be found online <a href="">here</a>.
-     *
-     * @throws Exception
-     *             if anything goes wrong
-     *
-    @Test
-    public void testJNDITutorialExample() throws Exception
-    {
-        // Parse the name
-        Dn name = new Dn( "cn=John,ou=People,ou=Marketing" );
-
-        // Remove the second component from the head: ou=People
-        name = name.remove( 1 );
-        String out = name.toString();
-
-        assertEquals( "cn=John,ou=Marketing", out );
-
-        // Add to the head (first): cn=John,ou=Marketing,ou=East
-        name = new Dn( out, "ou=East" );
-        out = name.toString();
-
-        assertEquals( "cn=John,ou=Marketing,ou=East", out );
-
-        // Add to the tail (last): cn=HomeDir,cn=John,ou=Marketing,ou=East
-        out = name.add( "cn=HomeDir" ).toString();
-
-        assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", out );
-    }
 
 
     @Test
@@ -1780,20 +1558,6 @@ public class DnTest
 
 
     /**
-     * Test the get( int ) method
-     */
-    @Test
-    public void testGet() throws Exception
-    {
-        Dn name = new Dn( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
-        assertEquals( "cn=HomeDir", name.get( 3 ) );
-        assertEquals( "cn=John", name.get( 2 ) );
-        assertEquals( "ou=Marketing", name.get( 1 ) );
-        assertEquals( "ou=East", name.get( 0 ) );
-    }
-
-
-    /**
      * Test the getRdn( int ) method
      */
     @Test

Modified: directory/shared/branches/m1/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/m1/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java?rev=1072019&r1=1072018&r2=1072019&view=diff
==============================================================================
--- directory/shared/branches/m1/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java
(original)
+++ directory/shared/branches/m1/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java
Fri Feb 18 15:16:49 2011
@@ -964,32 +964,6 @@ public final class Dn implements Iterabl
 
 
     /**
-     * Get the given Rdn as a String. The position is used in the
-     * reverse order. Assuming that we have a Dn like
-     * <pre>dc=example,dc=apache,dc=org</pre>
-     * then :
-     * <li><code>get(0)</code> will return dc=org</li>
-     * <li><code>get(1)</code> will return dc=apache</li>
-     * <li><code>get(2)</code> will return dc=example</li>
-     *
-     * @param posn The position of the wanted Rdn in the Dn.
-     */
-    public String get( int posn )
-    {
-        if ( rdns.size() == 0 )
-        {
-            return "";
-        }
-        else
-        {
-            Rdn rdn = rdns.get( rdns.size() - posn - 1 );
-
-            return rdn.getNormName();
-        }
-    }
-
-
-    /**
      * Retrieves a component of this name.
      *
      * @param posn
@@ -1045,6 +1019,89 @@ public final class Dn implements Iterabl
 
 
     /**
+     * Get the descendant of a given DN, using the ancestr DN. Assuming that
+     * a DN has two parts :<br/>
+     * DN = [descendant DN][ancestor DN]<br/>
+     * To get back the descendant from the full DN, you just pass the ancestor DN
+     * as a parameter. Here is a working example :
+     * <pre>
+     * Dn dn = new Dn( "cn=test, dc=server, dc=directory, dc=apache, dc=org" );
+     * 
+     * Dn descendant = dn.getDescendantOf( "dc=apache, dc=org" );
+     * 
+     * // At this point, the descendant contains cn=test, dc=server, dc=directory"
+     * </pre> 
+     */
+    public Dn getDescendantOf( String ancestor ) throws LdapInvalidDnException
+    {
+        return getDescendantOf( new Dn( schemaManager, ancestor ) );
+    }
+    
+
+    
+    /**
+     * Get the descendant of a given DN, using the ancestr DN. Assuming that
+     * a DN has two parts :<br/>
+     * DN = [descendant DN][ancestor DN]<br/>
+     * To get back the descendant from the full DN, you just pass the ancestor DN
+     * as a parameter. Here is a working example :
+     * <pre>
+     * Dn dn = new Dn( "cn=test, dc=server, dc=directory, dc=apache, dc=org" );
+     * 
+     * Dn descendant = dn.getDescendantOf( "dc=apache, dc=org" );
+     * 
+     * // At this point, the descendant contains cn=test, dc=server, dc=directory"
+     * </pre> 
+     */
+    public Dn getDescendantOf( Dn ancestor ) throws LdapInvalidDnException
+    {
+        if ( ( ancestor == null ) || ( ancestor.size() == 0 ) )
+        {
+            return this;
+        }
+        
+        if ( rdns.size() == 0 )
+        {
+            return EMPTY_DN;
+        }
+        
+        int length = ancestor.size();
+        
+        if ( length > rdns.size() )
+        {
+            String message = I18n.err( I18n.ERR_04206, length, rdns.size() );
+            LOG.error( message );
+            throw new ArrayIndexOutOfBoundsException( message );
+        }
+
+        Dn newDn = new Dn( schemaManager );
+        List<Rdn> rdnsAncestor = ancestor.getRdns();
+        
+        for ( int i = 0; i < ancestor.size(); i++ )
+        {
+            Rdn rdn = rdns.get( size() -1 - i );
+            Rdn rdnDescendant = rdnsAncestor.get( ancestor.size() - 1 - i );
+            
+            if ( !rdn.equals( rdnDescendant ) )
+            {
+                throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX );
+            }
+        }
+
+        for ( int i = 0; i < rdns.size() - length; i++ )
+        {
+            // Don't forget to clone the rdns !
+            newDn.rdns.add( rdns.get( i ).clone() );
+        }
+
+        newDn.toUpName();
+        newDn.toNormName();
+        newDn.normalized.set( normalized.get() );
+
+        return newDn;
+    }
+
+    /**
      * Get the ancestor of a given DN, using the descendant DN. Assuming that
      * a DN has two parts :<br/>
      * DN = [descendant DN][ancestor DN]<br/>



Mime
View raw message