directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r433132 - in /directory/branches/apacheds/1.0: core-unit/src/test/java/org/apache/directory/server/core/subtree/ core/src/main/java/org/apache/directory/server/core/subtree/
Date Mon, 21 Aug 2006 03:17:14 GMT
Author: akarasulu
Date: Sun Aug 20 20:17:12 2006
New Revision: 433132

URL: http://svn.apache.org/viewvc?rev=433132&view=rev
Log:
encapsulating access to subtree specification map

Added:
    directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/subtree/SubtreeCache.java
Modified:
    directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/subtree/BadSubentryServiceITest.java
    directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java

Modified: directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/subtree/BadSubentryServiceITest.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/subtree/BadSubentryServiceITest.java?rev=433132&r1=433131&r2=433132&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/subtree/BadSubentryServiceITest.java
(original)
+++ directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/subtree/BadSubentryServiceITest.java
Sun Aug 20 20:17:12 2006
@@ -183,5 +183,4 @@
         assertEquals( 1, accessControlSubentries.size() );
         */
     }
-    
 }

Modified: directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java?rev=433132&r1=433131&r2=433132&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java
(original)
+++ directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java
Sun Aug 20 20:17:12 2006
@@ -1,5 +1,5 @@
 /*
- *   Copyright 2004 The Apache Software Foundation
+ *   Copyright 2006 The Apache Software Foundation
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
  *   you may not use this file except in compliance with the License.
@@ -96,7 +96,8 @@
     private static final Logger log = LoggerFactory.getLogger( SubentryService.class );
 
     /** the hash mapping the DN of a subentry to its SubtreeSpecification */
-    private final Map subtrees = new HashMap();
+    private final SubtreeCache subtreeCache = new SubtreeCache();
+    
     private DirectoryServiceConfiguration factoryCfg;
     private SubtreeSpecificationParser ssParser;
     private SubtreeEvaluator evaluator;
@@ -104,7 +105,6 @@
     private AttributeTypeRegistry attrRegistry;
     private OidRegistry oidRegistry;
     
-    
     private AttributeType objectClassType;
     private AttributeType administrativeRoleType;
 
@@ -166,7 +166,7 @@
                 LdapDN dnName = new LdapDN( dn );
                 //dnName = LdapDN.normalize( dnName, registry.getNormalizerMapping() );
                 dnName.normalize( attrRegistry.getNormalizerMapping() );
-                subtrees.put( dnName.toString(), ss );
+                subtreeCache.setSubtreeSpecification( dnName.toString(), ss );
             }
         }
     }
@@ -265,14 +265,14 @@
     {
         Attributes subentryAttrs = new LockableAttributesImpl();
         Attribute objectClasses = entryAttrs.get( "objectClass" );
-        Iterator list = subtrees.keySet().iterator();
+        Iterator list = subtreeCache.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 = ( SubtreeSpecification ) subtrees.get( subentryDnStr
);
+            SubtreeSpecification ss = subtreeCache.getSubtreeSpecification( subentryDnStr
);
 
             if ( evaluator.evaluate( ss, apDn, dn, objectClasses ) )
             {
@@ -388,7 +388,7 @@
                 log.warn( msg );
                 throw new LdapInvalidAttributeValueException( msg, ResultCodeEnum.INVALIDATTRIBUTESYNTAX
);
             }
-            subtrees.put( normName.toString(), ss );
+            subtreeCache.setSubtreeSpecification( normName.toString(), ss );
             next.add(normName, entry );
 
             /* ----------------------------------------------------------------
@@ -424,14 +424,14 @@
         }
         else
         {
-            Iterator list = subtrees.keySet().iterator();
+            Iterator list = subtreeCache.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 = ( SubtreeSpecification ) subtrees.get( subentryDn.toNormName()
);
+                SubtreeSpecification ss = subtreeCache.getSubtreeSpecification( subentryDn.toNormName()
);
 
                 if ( evaluator.evaluate( ss, apDn, normName, objectClasses ) )
                 {
@@ -513,7 +513,7 @@
 
         if ( objectClasses.contains( "subentry" ) )
         {
-            SubtreeSpecification ss = ( SubtreeSpecification ) subtrees.remove( name.toNormName()
);
+            SubtreeSpecification ss = subtreeCache.removeSubtreeSpecification( name.toNormName()
);
             next.delete( name );
 
             /* ----------------------------------------------------------------
@@ -604,13 +604,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 = subtrees.keySet().iterator();
+        Iterator subentries = subtreeCache.nameIterator();
         while ( subentries.hasNext() )
         {
             String subentryDn = ( String ) subentries.next();
             Name apDn = new LdapDN( subentryDn );
             apDn.remove( apDn.size() - 1 );
-            SubtreeSpecification ss = ( SubtreeSpecification ) subtrees.get( subentryDn );
+            SubtreeSpecification ss = subtreeCache.getSubtreeSpecification( subentryDn );
             boolean isOldNameSelected = evaluator.evaluate( ss, apDn, oldName, objectClasses
);
             boolean isNewNameSelected = evaluator.evaluate( ss, apDn, newName, objectClasses
);
 
@@ -666,7 +666,7 @@
 
         if ( objectClasses.contains( "subentry" ) )
         {
-            SubtreeSpecification ss = ( SubtreeSpecification ) subtrees.get( name.toNormName()
);
+            SubtreeSpecification ss = subtreeCache.getSubtreeSpecification( name.toNormName()
);
             LdapDN apName = ( LdapDN ) name.clone();
             apName.remove( apName.size() - 1 );
             LdapDN baseDn = ( LdapDN ) apName.clone();
@@ -679,7 +679,7 @@
             rdn.normalize( attrRegistry.getNormalizerMapping() );
             newName.normalize( attrRegistry.getNormalizerMapping() );
 
-            subtrees.put( newName.toNormName(), ss );
+            subtreeCache.setSubtreeSpecification( newName.toNormName(), ss );
             next.modifyRn( name, newRn, deleteOldRn );
 
             Attributes apAttrs = nexus.lookup( apName );
@@ -736,7 +736,7 @@
 
         if ( objectClasses.contains( "subentry" ) )
         {
-            SubtreeSpecification ss = ( SubtreeSpecification ) subtrees.get( oriChildName.toNormName()
);
+            SubtreeSpecification ss = subtreeCache.getSubtreeSpecification( oriChildName.toNormName()
);
             LdapDN apName = ( LdapDN ) oriChildName.clone();
             apName.remove( apName.size() - 1 );
             LdapDN baseDn = ( LdapDN ) apName.clone();
@@ -749,7 +749,7 @@
             rdn.normalize( attrRegistry.getNormalizerMapping() );
             newName.normalize( attrRegistry.getNormalizerMapping() );
             
-            subtrees.put( newName.toNormName(), ss );
+            subtreeCache.setSubtreeSpecification( newName.toNormName(), ss );
             next.move( oriChildName, newParentName, newRn, deleteOldRn );
 
             Attributes apAttrs = nexus.lookup( apName );
@@ -806,7 +806,7 @@
 
         if ( objectClasses.contains( "subentry" ) )
         {
-            SubtreeSpecification ss = ( SubtreeSpecification ) subtrees.get( oriChildName.toString()
);
+            SubtreeSpecification ss = subtreeCache.getSubtreeSpecification( oriChildName.toString()
);
             LdapDN apName = ( LdapDN ) oriChildName.clone();
             apName.remove( apName.size() - 1 );
             LdapDN baseDn = ( LdapDN ) apName.clone();
@@ -815,7 +815,7 @@
             newName.remove( newName.size() - 1 );
             newName.add( newParentName.get( newParentName.size() - 1 ) );
 
-            subtrees.put( newName.toString(), ss );
+            subtreeCache.setSubtreeSpecification( newName.toString(), ss );
             next.move( oriChildName, newParentName );
 
             Attributes apAttrs = nexus.lookup( apName );
@@ -876,7 +876,7 @@
 
         if ( objectClasses.contains( "subentry" ) && mods.get( "subtreeSpecification"
) != null )
         {
-            SubtreeSpecification ssOld = ( SubtreeSpecification ) subtrees.remove( name.toNormName()
);
+            SubtreeSpecification ssOld = subtreeCache.removeSubtreeSpecification( name.toNormName()
);
             SubtreeSpecification ssNew;
 
             try
@@ -890,7 +890,7 @@
                 throw new LdapInvalidAttributeValueException( msg, ResultCodeEnum.INVALIDATTRIBUTESYNTAX
);
             }
 
-            subtrees.put( name.toNormName(), ssNew );
+            subtreeCache.setSubtreeSpecification( name.toNormName(), ssNew );
             next.modify( name, modOp, mods );
 
             // search for all entries selected by the old SS and remove references to subentry
@@ -962,7 +962,7 @@
 
         if ( objectClasses.contains( "subentry" ) && isSubtreeSpecificationModification
)
         {
-            SubtreeSpecification ssOld = ( SubtreeSpecification ) subtrees.remove( name.toString()
);
+            SubtreeSpecification ssOld = subtreeCache.removeSubtreeSpecification( name.toString()
);
             SubtreeSpecification ssNew;
 
             try
@@ -976,7 +976,7 @@
                 throw new LdapInvalidAttributeValueException( msg, ResultCodeEnum.INVALIDATTRIBUTESYNTAX
);
             }
 
-            subtrees.put( name.toNormName(), ssNew );
+            subtreeCache.setSubtreeSpecification( name.toNormName(), ssNew );
             next.modify( name, mods );
 
             // search for all entries selected by the old SS and remove references to subentry
@@ -1293,7 +1293,7 @@
             String dn = result.getName();
 
             // see if we can get a match without normalization
-            if ( subtrees.containsKey( dn ) )
+            if ( subtreeCache.hasSubtreeSpecification( dn ) )
             {
                 return false;
             }
@@ -1329,7 +1329,7 @@
                 LdapDN ndn = new LdapDN( dn );
                 ndn.normalize( attrRegistry.getNormalizerMapping() );
                 String normalizedDn = ndn.toString();
-                return !subtrees.containsKey( normalizedDn );
+                return !subtreeCache.hasSubtreeSpecification( normalizedDn );
             }
 
             LdapDN name = new LdapDN( invocation.getCaller().getNameInNamespace() );
@@ -1338,7 +1338,7 @@
             LdapDN rest = new LdapDN( result.getName() );
             rest.normalize( attrRegistry.getNormalizerMapping() );
             name.addAll( rest );
-            return !subtrees.containsKey( name.toString() );
+            return !subtreeCache.hasSubtreeSpecification( name.toString() );
         }
     }
 
@@ -1354,7 +1354,7 @@
             String dn = result.getName();
 
             // see if we can get a match without normalization
-            if ( subtrees.containsKey( dn ) )
+            if ( subtreeCache.hasSubtreeSpecification( dn ) )
             {
                 return true;
             }
@@ -1389,7 +1389,7 @@
             {
                 LdapDN ndn = new LdapDN( dn );
                 ndn.normalize( attrRegistry.getNormalizerMapping() );
-                return subtrees.containsKey( ndn.toNormName() );
+                return subtreeCache.hasSubtreeSpecification( ndn.toNormName() );
             }
 
             LdapDN name = new LdapDN( invocation.getCaller().getNameInNamespace() );
@@ -1398,7 +1398,7 @@
             LdapDN rest = new LdapDN( result.getName() );
             rest.normalize( attrRegistry.getNormalizerMapping() );
             name.addAll( rest );
-            return subtrees.containsKey( name.toNormName() );
+            return subtreeCache.hasSubtreeSpecification( name.toNormName() );
         }
     }
 }

Added: directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/subtree/SubtreeCache.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/subtree/SubtreeCache.java?rev=433132&view=auto
==============================================================================
--- directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/subtree/SubtreeCache.java
(added)
+++ directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/subtree/SubtreeCache.java
Sun Aug 20 20:17:12 2006
@@ -0,0 +1,66 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.directory.server.core.subtree;
+
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.directory.shared.ldap.subtree.SubtreeSpecification;
+
+
+/**
+ * A cache for subtree specifications.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SubtreeCache
+{
+    private final Map subtrees = new HashMap();
+    
+    
+    final SubtreeSpecification getSubtreeSpecification( String normalizedName )
+    {
+        return ( SubtreeSpecification ) subtrees.get( normalizedName );
+    }
+    
+    
+    final SubtreeSpecification removeSubtreeSpecification( String normalizedName )
+    {
+        return ( SubtreeSpecification ) subtrees.remove( normalizedName );
+    }
+    
+    
+    final SubtreeSpecification setSubtreeSpecification( String normalizedName, SubtreeSpecification
ss )
+    {
+        return ( SubtreeSpecification ) subtrees.put( normalizedName, ss );
+    }
+    
+    
+    final boolean hasSubtreeSpecification( String normalizedName )
+    {
+        return subtrees.containsKey( normalizedName );
+    }
+    
+    
+    final Iterator nameIterator()
+    {
+        return subtrees.keySet().iterator();
+    }
+}



Mime
View raw message