directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1071331 - in /directory: apacheds/branches/m1/core/src/main/java/org/apache/directory/server/core/authz/support/ apacheds/branches/m1/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ shared/branches/m1/integ/src/test/java/org...
Date Wed, 16 Feb 2011 17:59:14 GMT
Author: elecharny
Date: Wed Feb 16 17:59:14 2011
New Revision: 1071331

URL: http://svn.apache.org/viewvc?rev=1071331&view=rev
Log:
o Removed the Dn.getPrefix( pos ) method
o Added the Dn.getParent( Dn ) method
o Fixed the code accordingly

Modified:
    directory/apacheds/branches/m1/core/src/main/java/org/apache/directory/server/core/authz/support/MaxImmSubFilter.java
    directory/apacheds/branches/m1/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractStore.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/src/main/java/org/apache/directory/server/core/authz/support/MaxImmSubFilter.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/m1/core/src/main/java/org/apache/directory/server/core/authz/support/MaxImmSubFilter.java?rev=1071331&r1=1071330&r2=1071331&view=diff
==============================================================================
--- directory/apacheds/branches/m1/core/src/main/java/org/apache/directory/server/core/authz/support/MaxImmSubFilter.java
(original)
+++ directory/apacheds/branches/m1/core/src/main/java/org/apache/directory/server/core/authz/support/MaxImmSubFilter.java
Wed Feb 16 17:59:14 2011
@@ -165,8 +165,9 @@ public class MaxImmSubFilter implements 
 
         try
         {
+            Dn baseDn = new Dn( opContext.getSession().getDirectoryService().getSchemaManager(),
entryName.getRdn( 0 ) );
             SearchOperationContext searchContext = new SearchOperationContext( opContext.getSession(),
-                entryName.getPrefix( 1 ), childrenFilter, childrenSearchControls );
+                baseDn, childrenFilter, childrenSearchControls );
             searchContext.setByPassed( SEARCH_BYPASS );
             searchContext.setAliasDerefMode( AliasDerefMode.DEREF_ALWAYS );
 

Modified: directory/apacheds/branches/m1/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/m1/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java?rev=1071331&r1=1071330&r2=1071331&view=diff
==============================================================================
--- directory/apacheds/branches/m1/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java
(original)
+++ directory/apacheds/branches/m1/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java
Wed Feb 16 17:59:14 2011
@@ -1953,7 +1953,7 @@ public abstract class AbstractStore<E, I
 
         while ( !ancestorDn.equals( suffixDn ) && ancestorDn.size() > suffixDn.size()
)
         {
-            ancestorDn = ancestorDn.getPrefix( ancestorDn.size() - 1 );
+            ancestorDn = ancestorDn.getParent();
             ancestorId = getEntryId( ancestorDn );
 
             subAliasIdx.drop( ancestorId, targetId );
@@ -2001,7 +2001,7 @@ public abstract class AbstractStore<E, I
          * Start droping index tuples with the first ancestor right above the
          * moved base.  This is the first ancestor effected by the move.
          */
-        Dn ancestorDn = movedBase.getPrefix( 1 );
+        Dn ancestorDn = new Dn( schemaManager, movedBase.getRdn( 0 ) );
         ID ancestorId = getEntryId( ancestorDn );
 
         /*
@@ -2025,7 +2025,7 @@ public abstract class AbstractStore<E, I
 
         while ( !ancestorDn.equals( suffixDn ) )
         {
-            ancestorDn = ancestorDn.getPrefix( 1 );
+            ancestorDn = new Dn( schemaManager, ancestorDn.getRdn( 0 ) );
             ancestorId = getEntryId( ancestorDn );
 
             subAliasIdx.drop( ancestorId, targetId );

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=1071331&r1=1071330&r2=1071331&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
Wed Feb 16 17:59:14 2011
@@ -40,6 +40,7 @@ import javax.naming.InvalidNameException
 import javax.naming.ldap.LdapName;
 
 import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
 import org.apache.directory.shared.ldap.model.name.Ava;
 import org.apache.directory.shared.ldap.model.name.Dn;
 import org.apache.directory.shared.ldap.model.name.DnParser;
@@ -889,8 +890,8 @@ public class DnTest
     public void testDnGetPrefixPos0() throws LdapException
     {
         Dn dn = new Dn( "a=b, c=d,e = f" );
-        Dn newDn = ( dn.getPrefix( 0 ) );
-        assertEquals( "", newDn.getName() );
+        Dn newDn = ( dn.getParent( "" ) );
+        assertEquals( "a=b, c=d,e = f", newDn.getName() );
     }
 
 
@@ -901,8 +902,8 @@ public class DnTest
     public void testDnGetPrefixPos1() throws LdapException
     {
         Dn dn = new Dn( "a=b, c=d,e = f" );
-        Dn newDn = ( dn.getPrefix( 1 ) );
-        assertEquals( "e = f", newDn.getName() );
+        Dn newDn = ( dn.getParent( "a=b" ) );
+        assertEquals( " c=d,e = f", newDn.getName() );
     }
 
 
@@ -913,8 +914,8 @@ public class DnTest
     public void testDnGetPrefixPos2() throws LdapException
     {
         Dn dn = new Dn( "a=b, c=d,e = f" );
-        Dn newDn = ( dn.getPrefix( 2 ) );
-        assertEquals( " c=d,e = f", newDn.getName() );
+        Dn newDn = ( dn.getParent( "a=b, c=d" ) );
+        assertEquals( "e = f", newDn.getName() );
     }
 
 
@@ -925,29 +926,20 @@ public class DnTest
     public void testDnGetPrefixPos3() throws LdapException
     {
         Dn dn = new Dn( "a=b, c=d,e = f" );
-        Dn newDn = ( dn.getPrefix( 3 ) );
-        assertEquals( "a=b, c=d,e = f", newDn.getName() );
+        Dn newDn = ( dn.getParent( "a=b, c=d,e = f" ) );
+        assertEquals( "", newDn.getName() );
     }
 
 
     /**
      * Get the prefix out of bound
      */
-    @Test
+    @Test( expected=LdapInvalidDnException.class)
     public void testDnGetPrefixPos4() throws LdapException
     {
         Dn dn = new Dn( "a=b, c=d,e = f" );
 
-        try
-        {
-            dn.getPrefix( 4 );
-            // We should not reach this point.
-            fail();
-        }
-        catch ( ArrayIndexOutOfBoundsException aoobe )
-        {
-            assertTrue( true );
-        }
+        Dn res = dn.getParent( "a=z" );
     }
 
 
@@ -955,10 +947,10 @@ public class DnTest
      * Get the prefix of an empty LdapName
      */
     @Test
-    public void testDnGetPrefixEmptyDN()
+    public void testDnGetPrefixEmptyDN() throws LdapInvalidDnException
     {
         Dn dn = new Dn();
-        Dn newDn = ( dn.getPrefix( 0 ) );
+        Dn newDn = ( dn.getParent( "" ) );
         assertEquals( "", newDn.getName() );
     }
 
@@ -1959,11 +1951,11 @@ public class DnTest
     {
         Dn name = new Dn( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
 
-        assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getPrefix( 4 ).toString()
);
-        assertEquals( "cn=John,ou=Marketing,ou=East", name.getPrefix( 3 ).toString() );
-        assertEquals( "ou=Marketing,ou=East", name.getPrefix( 2 ).toString() );
-        assertEquals( "ou=East", name.getPrefix( 1 ).toString() );
-        assertEquals( "", name.getPrefix( 0 ).toString() );
+        assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getParent( "" ).toString()
);
+        assertEquals( "cn=John,ou=Marketing,ou=East", name.getParent( "cn=HomeDir" ).toString()
);
+        assertEquals( "ou=Marketing,ou=East", name.getParent( "cn=HomeDir,cn=John" ).toString()
);
+        assertEquals( "ou=East", name.getParent( "cn=HomeDir,cn=John,ou=Marketing" ).toString()
);
+        assertEquals( "", name.getParent( "cn=HomeDir,cn=John,ou=Marketing,ou=East" ).toString()
);
     }
 
 
@@ -2542,11 +2534,11 @@ public class DnTest
         LdapName jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
         Dn aName = new Dn( "cn=four,cn=three,cn=two,cn=one" );
 
-        assertEquals( jName.getPrefix( 0 ).toString(), aName.getPrefix( 0 ).toString() );
-        assertEquals( jName.getPrefix( 1 ).toString(), aName.getPrefix( 1 ).toString() );
-        assertEquals( jName.getPrefix( 2 ).toString(), aName.getPrefix( 2 ).toString() );
-        assertEquals( jName.getPrefix( 3 ).toString(), aName.getPrefix( 3 ).toString() );
-        assertEquals( jName.getPrefix( 4 ).toString(), aName.getPrefix( 4 ).toString() );
+        assertEquals( jName.getPrefix( 0 ).toString(), aName.getParent( "cn=four,cn=three,cn=two,cn=one"
).toString() );
+        assertEquals( jName.getPrefix( 1 ).toString(), aName.getParent( "cn=four,cn=three,cn=two"
).toString() );
+        assertEquals( jName.getPrefix( 2 ).toString(), aName.getParent( "cn=four,cn=three"
).toString() );
+        assertEquals( jName.getPrefix( 3 ).toString(), aName.getParent( "cn=four" ).toString()
);
+        assertEquals( jName.getPrefix( 4 ).toString(), aName.getParent( "" ).toString() );
     }
 
 

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=1071331&r1=1071330&r2=1071331&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
Wed Feb 16 17:59:14 2011
@@ -365,6 +365,7 @@ public final class Dn implements Iterabl
         for ( Rdn rdn : rdns)
         {
             this.rdns.add( rdn.clone() );
+            
         }
 
         normalizeInternal();
@@ -393,9 +394,9 @@ public final class Dn implements Iterabl
 
         try
         {
+            normalized = new AtomicBoolean( false );
             normalize( schemaManager );
             toUpName();
-            normalized = new AtomicBoolean( false );
         }
         catch( LdapInvalidDnException lide )
         {
@@ -997,30 +998,58 @@ public final class Dn implements Iterabl
     /**
      * {@inheritDoc}
      */
-    public Dn getPrefix( int posn )
+    public Dn getParent( String descendant ) throws LdapInvalidDnException
     {
+        return getParent( new Dn( schemaManager, descendant ) );
+    }
+    
+
+    /**
+     * {@inheritDoc}
+     */
+    public Dn getParent( Dn descendant ) throws LdapInvalidDnException
+    {
+        if ( ( descendant == null ) || ( descendant.size() == 0 ) )
+        {
+            return this;
+        }
+        
         if ( rdns.size() == 0 )
         {
             return EMPTY_DN;
         }
-
-        if ( ( posn < 0 ) || ( posn > rdns.size() ) )
+        
+        int length = descendant.size();
+        
+        if ( length > rdns.size() )
         {
-            String message = I18n.err( I18n.ERR_04206, posn, rdns.size() );
+            String message = I18n.err( I18n.ERR_04206, length, rdns.size() );
             LOG.error( message );
             throw new ArrayIndexOutOfBoundsException( message );
         }
 
-        Dn newDn = new Dn();
+        Dn newDn = new Dn( schemaManager );
+        List<Rdn> rdnsDescendant = descendant.getRdns();
+        
+        for ( int i = 0; i < descendant.size(); i++ )
+        {
+            Rdn rdn = rdns.get( i );
+            Rdn rdnDescendant = rdnsDescendant.get( i );
+            
+            if ( !rdn.equals( rdnDescendant ) )
+            {
+                throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX );
+            }
+        }
 
-        for ( int i = rdns.size() - posn; i < rdns.size(); i++ )
+        for ( int i = length; i < rdns.size(); i++ )
         {
             // Don't forget to clone the rdns !
             newDn.rdns.add( rdns.get( i ).clone() );
         }
 
-        newDn.normName = newDn.toNormName();
-        newDn.upName = getUpNamePrefix( posn );
+        newDn.toUpName();
+        newDn.toNormName();
         newDn.normalized.set( normalized.get() );
 
         return newDn;
@@ -1374,7 +1403,26 @@ public final class Dn implements Iterabl
             return null;
         }
 
-        return getPrefix( size() - 1 );
+        if ( rdns.size() == 0 )
+        {
+            return EMPTY_DN;
+        }
+        
+        int posn = rdns.size() - 1;
+
+        Dn newDn = new Dn( schemaManager );
+
+        for ( int i = rdns.size() - posn; i < rdns.size(); i++ )
+        {
+            // Don't forget to clone the rdns !
+            newDn.rdns.add( rdns.get( i ).clone() );
+        }
+
+        newDn.normName = newDn.toNormName();
+        newDn.upName = getUpNamePrefix( posn );
+        newDn.normalized.set( normalized.get() );
+
+        return newDn;
     }
 
 



Mime
View raw message