directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r433153 - in /directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/subtree: Subentry.java SubentryCache.java SubentryService.java SubtreeCache.java
Date Mon, 21 Aug 2006 05:15:41 GMT
Author: akarasulu
Date: Sun Aug 20 22:15:40 2006
New Revision: 433153

URL: http://svn.apache.org/viewvc?rev=433153&view=rev
Log:
refactored subtree specification cache into the subentry cache

Added:
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/subtree/Subentry.java
      - copied unchanged from r433152, directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/subtree/Subentry.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/subtree/SubentryCache.java
      - copied unchanged from r433152, directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/subtree/SubentryCache.java
Removed:
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/subtree/SubtreeCache.java
Modified:
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java?rev=433153&r1=433152&r2=433153&view=diff
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java
(original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java
Sun Aug 20 22:15:40 2006
@@ -98,8 +98,8 @@
 
     private static final Logger log = LoggerFactory.getLogger( SubentryService.class );
 
-    /** the hash mapping the DN of a subentry to its SubtreeSpecification */
-    private final SubtreeCache subtreeCache = new SubtreeCache();
+    /** the hash mapping the DN of a subentry to its SubtreeSpecification/types */
+    private final SubentryCache subentryCache = new SubentryCache();
     
     private DirectoryServiceConfiguration factoryCfg;
     private SubtreeSpecificationParser ssParser;
@@ -169,10 +169,45 @@
                 LdapDN dnName = new LdapDN( dn );
                 //dnName = LdapDN.normalize( dnName, registry.getNormalizerMapping() );
                 dnName.normalize( attrRegistry.getNormalizerMapping() );
-                subtreeCache.setSubtreeSpecification( dnName.toString(), ss );
+                subentryCache.setSubentry( dnName.toString(), ss, getSubentryTypes( subentry
) );
             }
         }
     }
+    
+    
+    private int getSubentryTypes( Attributes subentry ) throws NamingException
+    {
+        int types = 0;
+        
+        Attribute oc = subentry.get( "objectClass" );
+        if ( oc == null )
+        {
+            throw new LdapSchemaViolationException( "A subentry must have an objectClass
attribute", 
+                ResultCodeEnum.OBJECTCLASSVIOLATION );
+        }
+        
+        if ( oc.contains( AUTONOUMOUS_AREA ) )
+        {
+            types &= Subentry.AUTONOMOUS_AREA_SUBENTRY;
+        }
+        
+        if ( oc.contains( AC_AREA ) || oc.contains( AC_INNERAREA ) )
+        {
+            types &= Subentry.ACCESS_CONTROL_SUBENTRY;
+        }
+        
+        if ( oc.contains( SCHEMA_AREA ) )
+        {
+            types &= Subentry.SCHEMA_SUBENTRY;
+        }
+        
+        if ( oc.contains( COLLECTIVE_AREA ) )
+        {
+            types &= Subentry.COLLECTIVE_SUBENTRY;
+        }
+        
+        return types;
+    }
 
 
     // -----------------------------------------------------------------------
@@ -268,14 +303,14 @@
     {
         Attributes subentryAttrs = new LockableAttributesImpl();
         Attribute objectClasses = entryAttrs.get( "objectClass" );
-        Iterator list = subtreeCache.nameIterator();
+        Iterator list = subentryCache.nameIterator();
         while ( list.hasNext() )
         {
             String subentryDnStr = ( String ) list.next();
             LdapDN subentryDn = new LdapDN( subentryDnStr );
             LdapDN apDn = ( LdapDN ) subentryDn.clone();
             apDn.remove( apDn.size() - 1 );
-            SubtreeSpecification ss = subtreeCache.getSubtreeSpecification( subentryDnStr
);
+            SubtreeSpecification ss = subentryCache.getSubentry( subentryDnStr ).getSubtreeSpecification();
 
             if ( evaluator.evaluate( ss, apDn, dn, objectClasses ) )
             {
@@ -400,7 +435,7 @@
                 log.warn( msg );
                 throw new LdapInvalidAttributeValueException( msg, ResultCodeEnum.INVALIDATTRIBUTESYNTAX
);
             }
-            subtreeCache.setSubtreeSpecification( normName.toString(), ss );
+            subentryCache.setSubentry( normName.toString(), ss, getSubentryTypes( entry )
);
             next.add(normName, entry );
 
             /* ----------------------------------------------------------------
@@ -436,14 +471,14 @@
         }
         else
         {
-            Iterator list = subtreeCache.nameIterator();
+            Iterator list = subentryCache.nameIterator();
             while ( list.hasNext() )
             {
                 String subentryDnStr = ( String ) list.next();
                 LdapDN subentryDn = new LdapDN( subentryDnStr );
                 LdapDN apDn = ( LdapDN ) subentryDn.clone();
                 apDn.remove( apDn.size() - 1 );
-                SubtreeSpecification ss = subtreeCache.getSubtreeSpecification( subentryDn.toNormName()
);
+                SubtreeSpecification ss = subentryCache.getSubentry( subentryDn.toNormName()
).getSubtreeSpecification();
 
                 if ( evaluator.evaluate( ss, apDn, normName, objectClasses ) )
                 {
@@ -534,7 +569,7 @@
 
         if ( objectClasses.contains( "subentry" ) )
         {
-            SubtreeSpecification ss = subtreeCache.removeSubtreeSpecification( name.toNormName()
);
+            SubtreeSpecification ss = subentryCache.removeSubentry( name.toNormName() ).getSubtreeSpecification();
             next.delete( name );
 
             /* ----------------------------------------------------------------
@@ -625,13 +660,13 @@
          * would be caused by chop exclusions. In this case we must add subentry
          * operational attribute values with the dn of this subentry.
          */
-        Iterator subentries = subtreeCache.nameIterator();
+        Iterator subentries = subentryCache.nameIterator();
         while ( subentries.hasNext() )
         {
             String subentryDn = ( String ) subentries.next();
             Name apDn = new LdapDN( subentryDn );
             apDn.remove( apDn.size() - 1 );
-            SubtreeSpecification ss = subtreeCache.getSubtreeSpecification( subentryDn );
+            SubtreeSpecification ss = subentryCache.getSubentry( subentryDn ).getSubtreeSpecification();
             boolean isOldNameSelected = evaluator.evaluate( ss, apDn, oldName, objectClasses
);
             boolean isNewNameSelected = evaluator.evaluate( ss, apDn, newName, objectClasses
);
 
@@ -687,7 +722,8 @@
 
         if ( objectClasses.contains( "subentry" ) )
         {
-            SubtreeSpecification ss = subtreeCache.getSubtreeSpecification( name.toNormName()
);
+            Subentry subentry = subentryCache.getSubentry( name.toNormName() );
+            SubtreeSpecification ss = subentry.getSubtreeSpecification();
             LdapDN apName = ( LdapDN ) name.clone();
             apName.remove( apName.size() - 1 );
             LdapDN baseDn = ( LdapDN ) apName.clone();
@@ -700,7 +736,7 @@
             rdn.normalize( attrRegistry.getNormalizerMapping() );
             newName.normalize( attrRegistry.getNormalizerMapping() );
 
-            subtreeCache.setSubtreeSpecification( newName.toNormName(), ss );
+            subentryCache.setSubentry( newName.toNormName(), ss, subentry.getTypes() );
             next.modifyRn( name, newRn, deleteOldRn );
 
             Attributes apAttrs = nexus.lookup( apName );
@@ -757,7 +793,8 @@
 
         if ( objectClasses.contains( "subentry" ) )
         {
-            SubtreeSpecification ss = subtreeCache.getSubtreeSpecification( oriChildName.toNormName()
);
+            Subentry subentry = subentryCache.getSubentry( oriChildName.toNormName() );
+            SubtreeSpecification ss = subentry.getSubtreeSpecification();
             LdapDN apName = ( LdapDN ) oriChildName.clone();
             apName.remove( apName.size() - 1 );
             LdapDN baseDn = ( LdapDN ) apName.clone();
@@ -770,7 +807,7 @@
             rdn.normalize( attrRegistry.getNormalizerMapping() );
             newName.normalize( attrRegistry.getNormalizerMapping() );
             
-            subtreeCache.setSubtreeSpecification( newName.toNormName(), ss );
+            subentryCache.setSubentry( newName.toNormName(), ss, subentry.getTypes() );
             next.move( oriChildName, newParentName, newRn, deleteOldRn );
 
             Attributes apAttrs = nexus.lookup( apName );
@@ -827,7 +864,8 @@
 
         if ( objectClasses.contains( "subentry" ) )
         {
-            SubtreeSpecification ss = subtreeCache.getSubtreeSpecification( oriChildName.toString()
);
+            Subentry subentry = subentryCache.getSubentry( oriChildName.toString() );
+            SubtreeSpecification ss = subentry.getSubtreeSpecification();
             LdapDN apName = ( LdapDN ) oriChildName.clone();
             apName.remove( apName.size() - 1 );
             LdapDN baseDn = ( LdapDN ) apName.clone();
@@ -836,7 +874,7 @@
             newName.remove( newName.size() - 1 );
             newName.add( newParentName.get( newParentName.size() - 1 ) );
 
-            subtreeCache.setSubtreeSpecification( newName.toString(), ss );
+            subentryCache.setSubentry( newName.toString(), ss, subentry.getTypes() );
             next.move( oriChildName, newParentName );
 
             Attributes apAttrs = nexus.lookup( apName );
@@ -890,6 +928,78 @@
     // Methods dealing subentry modification
     // -----------------------------------------------------------------------
 
+    
+    private int getSubentryTypes( Attributes subentry, int modOp, Attributes mods ) throws
NamingException
+    {
+        if ( mods.get( "objectClass" ) == null )
+        {
+            return getSubentryTypes( subentry );
+        }
+        
+        // ok user is modifying (replacing) the objectClasses of a subentry so
+        // endstate of objectClasses is contained in the mods attibutes
+        if ( modOp == DirContext.REPLACE_ATTRIBUTE )
+        {
+            return getSubentryTypes( mods );
+        }
+        
+        Attribute ocChanges = mods.get( "objectClass" );
+        Attribute ocFinalState = ( Attribute ) subentry.get( "objectClass" ).clone();
+        if ( modOp == DirContext.ADD_ATTRIBUTE )
+        {
+            for ( int ii = 0; ii < ocChanges.size(); ii++ )
+            {
+                ocFinalState.add( ocChanges.get( ii ) );
+            }
+        }
+        else // remove operation
+        {
+            for ( int ii = 0; ii < ocChanges.size(); ii++ )
+            {
+                ocFinalState.remove( ocChanges.get( ii ) );
+            }
+        }
+        
+        Attributes attrs = new LockableAttributesImpl();
+        attrs.put( ocFinalState );
+        return getSubentryTypes( attrs );
+    }
+    
+
+    private int getSubentryTypes( Attributes entry, ModificationItem[] mods ) throws NamingException
+    {
+        Attribute ocFinalState = ( Attribute ) entry.get( "objectClass" ).clone();
+        for ( int ii = 0; ii < mods.length; ii++ )
+        {
+            if ( mods[ii].getAttribute().getID().equalsIgnoreCase( "objectClass" ) )
+            {
+                switch ( mods[ii].getModificationOp() )
+                {
+                    case( DirContext.ADD_ATTRIBUTE ):
+                        for ( int jj = 0; jj < mods[ii].getAttribute().size(); jj++ )
+                        {
+                            ocFinalState.add( mods[ii].getAttribute().get( jj ) );
+                        }
+                        break;
+                    case( DirContext.REMOVE_ATTRIBUTE ):
+                        for ( int jj = 0; jj < mods[ii].getAttribute().size(); jj++ )
+                        {
+                            ocFinalState.remove( mods[ii].getAttribute().get( jj ) );
+                        }
+                        break;
+                    case( DirContext.REPLACE_ATTRIBUTE ):
+                        ocFinalState = mods[ii].getAttribute();
+                        break;
+                }
+            }
+        }
+        
+        Attributes attrs = new LockableAttributesImpl();
+        attrs.put( ocFinalState );
+        return getSubentryTypes( attrs );
+    }
+
+
     public void modify( NextInterceptor next, LdapDN name, int modOp, Attributes mods ) throws
NamingException
     {
         Attributes entry = nexus.lookup( name );
@@ -897,7 +1007,7 @@
 
         if ( objectClasses.contains( "subentry" ) && mods.get( "subtreeSpecification"
) != null )
         {
-            SubtreeSpecification ssOld = subtreeCache.removeSubtreeSpecification( name.toNormName()
);
+            SubtreeSpecification ssOld = subentryCache.removeSubentry( name.toNormName()
).getSubtreeSpecification();
             SubtreeSpecification ssNew;
 
             try
@@ -911,7 +1021,7 @@
                 throw new LdapInvalidAttributeValueException( msg, ResultCodeEnum.INVALIDATTRIBUTESYNTAX
);
             }
 
-            subtreeCache.setSubtreeSpecification( name.toNormName(), ssNew );
+            subentryCache.setSubentry( name.toNormName(), ssNew, getSubentryTypes( entry,
modOp, mods ) );
             next.modify( name, modOp, mods );
 
             // search for all entries selected by the old SS and remove references to subentry
@@ -983,7 +1093,7 @@
 
         if ( objectClasses.contains( "subentry" ) && isSubtreeSpecificationModification
)
         {
-            SubtreeSpecification ssOld = subtreeCache.removeSubtreeSpecification( name.toString()
);
+            SubtreeSpecification ssOld = subentryCache.removeSubentry( name.toString() ).getSubtreeSpecification();
             SubtreeSpecification ssNew;
 
             try
@@ -997,7 +1107,7 @@
                 throw new LdapInvalidAttributeValueException( msg, ResultCodeEnum.INVALIDATTRIBUTESYNTAX
);
             }
 
-            subtreeCache.setSubtreeSpecification( name.toNormName(), ssNew );
+            subentryCache.setSubentry( name.toNormName(), ssNew, getSubentryTypes( entry,
mods ) );
             next.modify( name, mods );
 
             // search for all entries selected by the old SS and remove references to subentry
@@ -1339,7 +1449,7 @@
             String dn = result.getName();
 
             // see if we can get a match without normalization
-            if ( subtreeCache.hasSubtreeSpecification( dn ) )
+            if ( subentryCache.hasSubentry( dn ) )
             {
                 return false;
             }
@@ -1375,7 +1485,7 @@
                 LdapDN ndn = new LdapDN( dn );
                 ndn.normalize( attrRegistry.getNormalizerMapping() );
                 String normalizedDn = ndn.toString();
-                return !subtreeCache.hasSubtreeSpecification( normalizedDn );
+                return !subentryCache.hasSubentry( normalizedDn );
             }
 
             LdapDN name = new LdapDN( invocation.getCaller().getNameInNamespace() );
@@ -1384,7 +1494,7 @@
             LdapDN rest = new LdapDN( result.getName() );
             rest.normalize( attrRegistry.getNormalizerMapping() );
             name.addAll( rest );
-            return !subtreeCache.hasSubtreeSpecification( name.toString() );
+            return !subentryCache.hasSubentry( name.toString() );
         }
     }
 
@@ -1400,7 +1510,7 @@
             String dn = result.getName();
 
             // see if we can get a match without normalization
-            if ( subtreeCache.hasSubtreeSpecification( dn ) )
+            if ( subentryCache.hasSubentry( dn ) )
             {
                 return true;
             }
@@ -1435,7 +1545,7 @@
             {
                 LdapDN ndn = new LdapDN( dn );
                 ndn.normalize( attrRegistry.getNormalizerMapping() );
-                return subtreeCache.hasSubtreeSpecification( ndn.toNormName() );
+                return subentryCache.hasSubentry( ndn.toNormName() );
             }
 
             LdapDN name = new LdapDN( invocation.getCaller().getNameInNamespace() );
@@ -1444,7 +1554,7 @@
             LdapDN rest = new LdapDN( result.getName() );
             rest.normalize( attrRegistry.getNormalizerMapping() );
             name.addAll( rest );
-            return subtreeCache.hasSubtreeSpecification( name.toNormName() );
+            return subentryCache.hasSubentry( name.toNormName() );
         }
     }
 }



Mime
View raw message