directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r430093 - in /directory/branches/apacheds/1.0: core-plugin/src/main/antlr/ core-plugin/src/main/java/org/apache/directory/server/core/tools/schema/ core-plugin/src/test/java/org/apache/directory/server/core/tools/schema/ core/src/main/java/...
Date Wed, 09 Aug 2006 16:52:06 GMT
Author: akarasulu
Date: Wed Aug  9 09:52:02 2006
New Revision: 430093

URL: http://svn.apache.org/viewvc?rev=430093&view=rev
Log:
changes ...

 o Fixed bug in core-plugin where a map was being used and the order of object-
   Classes and attributeTypes were being mangled in the generated producers.  
   This was resulting in unpredictable order of registration.  This was bad for
   when there were dependencies between attribute types and objectClasses. 
 o Added code for rapidly deducing the descendants of an ancestor attributeType.
   This code will be used to expand filters when general attributeTypes are used
   as opposed to ones that are specific (specialized rather)

Modified:
    directory/branches/apacheds/1.0/core-plugin/src/main/antlr/openldap.g
    directory/branches/apacheds/1.0/core-plugin/src/main/java/org/apache/directory/server/core/tools/schema/DirectorySchemaToolMojo.java
    directory/branches/apacheds/1.0/core-plugin/src/main/java/org/apache/directory/server/core/tools/schema/OpenLdapSchemaParser.java
    directory/branches/apacheds/1.0/core-plugin/src/test/java/org/apache/directory/server/core/tools/schema/OpenLdapSchemaParserTest.java
    directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/AttributeTypeRegistry.java
    directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/GlobalAttributeTypeRegistry.java
    directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/bootstrap/BootstrapAttributeTypeRegistry.java
    directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/bootstrap/BootstrapSchemaLoader.java
    directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/authz/support/DummyAttributeTypeRegistry.java
    directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/schema/SchemaServiceTest.java

Modified: directory/branches/apacheds/1.0/core-plugin/src/main/antlr/openldap.g
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core-plugin/src/main/antlr/openldap.g?rev=430093&r1=430092&r2=430093&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/core-plugin/src/main/antlr/openldap.g (original)
+++ directory/branches/apacheds/1.0/core-plugin/src/main/antlr/openldap.g Wed Aug  9 09:52:02
2006
@@ -114,8 +114,8 @@
 {
     public static final String[] EMPTY = new String[0];
 
-    private Map attributeTypes = new HashMap();
-    private Map objectClasses = new HashMap();
+    private List attributeTypes = new ArrayList();
+    private List objectClasses = new ArrayList();
     private ParserMonitor monitor = null;
 
 
@@ -131,15 +131,15 @@
     }
 
 
-    public Map getAttributeTypes()
+    public List getAttributeTypes()
     {
-        return Collections.unmodifiableMap( attributeTypes );
+        return Collections.unmodifiableList( attributeTypes );
     }
 
 
-    public Map getObjectClasses()
+    public List getObjectClasses()
     {
-        return Collections.unmodifiableMap( objectClasses );
+        return Collections.unmodifiableList( objectClasses );
     }
 
 
@@ -206,7 +206,7 @@
     ( may[objectClass] )?
     CLOSE_PAREN
     {
-        objectClasses.put( objectClass.getOid(), objectClass );
+        objectClasses.add( objectClass );
     }
     ;
 
@@ -378,7 +378,7 @@
 
     CLOSE_PAREN
     {
-        attributeTypes.put( type.getOid(), type );
+        attributeTypes.add( type );
     }
     ;
 

Modified: directory/branches/apacheds/1.0/core-plugin/src/main/java/org/apache/directory/server/core/tools/schema/DirectorySchemaToolMojo.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core-plugin/src/main/java/org/apache/directory/server/core/tools/schema/DirectorySchemaToolMojo.java?rev=430093&r1=430092&r2=430093&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/core-plugin/src/main/java/org/apache/directory/server/core/tools/schema/DirectorySchemaToolMojo.java
(original)
+++ directory/branches/apacheds/1.0/core-plugin/src/main/java/org/apache/directory/server/core/tools/schema/DirectorySchemaToolMojo.java
Wed Aug  9 09:52:02 2006
@@ -221,7 +221,7 @@
 
         int size = parser.getAttributeTypes().size();
         AttributeTypeLiteral[] attributeTypes = new AttributeTypeLiteral[size];
-        attributeTypes = ( AttributeTypeLiteral[] ) parser.getAttributeTypes().values().toArray(
attributeTypes );
+        attributeTypes = ( AttributeTypeLiteral[] ) parser.getAttributeTypes().toArray( attributeTypes
);
 
         VelocityContext context = new VelocityContext();
         context.put( "package", schema.getPackageName() );
@@ -249,7 +249,7 @@
 
         int size = parser.getObjectClassTypes().size();
         ObjectClassLiteral[] objectClasses = new ObjectClassLiteral[size];
-        objectClasses = ( ObjectClassLiteral[] ) parser.getObjectClassTypes().values().toArray(
objectClasses );
+        objectClasses = ( ObjectClassLiteral[] ) parser.getObjectClassTypes().toArray( objectClasses
);
 
         VelocityContext context = new VelocityContext();
         context.put( "package", schema.getPackageName() );

Modified: directory/branches/apacheds/1.0/core-plugin/src/main/java/org/apache/directory/server/core/tools/schema/OpenLdapSchemaParser.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core-plugin/src/main/java/org/apache/directory/server/core/tools/schema/OpenLdapSchemaParser.java?rev=430093&r1=430092&r2=430093&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/core-plugin/src/main/java/org/apache/directory/server/core/tools/schema/OpenLdapSchemaParser.java
(original)
+++ directory/branches/apacheds/1.0/core-plugin/src/main/java/org/apache/directory/server/core/tools/schema/OpenLdapSchemaParser.java
Wed Aug  9 09:52:02 2006
@@ -21,7 +21,7 @@
 import org.apache.directory.server.core.tools.schema.antlrOpenLdapSchemaParser;
 import org.apache.directory.shared.ldap.util.ExceptionUtils;
 
-import java.util.Map;
+import java.util.List;
 import java.text.ParseException;
 import java.io.*;
 
@@ -77,13 +77,13 @@
     }
 
 
-    public Map getAttributeTypes()
+    public List getAttributeTypes()
     {
         return parser.getAttributeTypes();
     }
 
 
-    public Map getObjectClassTypes()
+    public List getObjectClassTypes()
     {
         return parser.getObjectClasses();
     }

Modified: directory/branches/apacheds/1.0/core-plugin/src/test/java/org/apache/directory/server/core/tools/schema/OpenLdapSchemaParserTest.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core-plugin/src/test/java/org/apache/directory/server/core/tools/schema/OpenLdapSchemaParserTest.java?rev=430093&r1=430092&r2=430093&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/core-plugin/src/test/java/org/apache/directory/server/core/tools/schema/OpenLdapSchemaParserTest.java
(original)
+++ directory/branches/apacheds/1.0/core-plugin/src/test/java/org/apache/directory/server/core/tools/schema/OpenLdapSchemaParserTest.java
Wed Aug  9 09:52:02 2006
@@ -17,6 +17,8 @@
 package org.apache.directory.server.core.tools.schema;
 
 
+import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import junit.framework.TestCase;
@@ -61,7 +63,8 @@
             + "        SYNTAX 1.3.6.1.4.1.1466.115.121.1.25 )";
 
         parser.parse( attributeTypeData );
-        Map attributeTypes = parser.getAttributeTypes();
+        List attributeTypeList = parser.getAttributeTypes();
+        Map attributeTypes = mapAttributeTypes( attributeTypeList );
         AttributeTypeLiteral type = ( AttributeTypeLiteral ) attributeTypes.get( "2.5.4.14"
);
 
         assertNotNull( type );
@@ -72,13 +75,28 @@
     }
 
 
+    private Map mapAttributeTypes( List attributeTypeList )
+    {
+        Map m = new HashMap();
+        
+        for ( int ii = 0 ; ii < attributeTypeList.size(); ii++ )
+        {
+            AttributeTypeLiteral type = ( AttributeTypeLiteral ) attributeTypeList.get( ii
);
+            m.put( type.getOid(), type );
+        }
+        
+        return m;
+    }
+
+
     public void testSimpleAttributeTypeParse() throws Exception
     {
         String attributeTypeData = "# adding a comment  \n" + "attributetype ( 2.5.4.2 NAME
'knowledgeInformation'\n"
             + "        DESC 'RFC2256: knowledge information'\n" + "        EQUALITY caseIgnoreMatch\n"
             + "        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )";
         parser.parse( attributeTypeData );
-        Map attributeTypes = parser.getAttributeTypes();
+        List attributeTypeList = parser.getAttributeTypes();
+        Map attributeTypes = mapAttributeTypes( attributeTypeList );
         AttributeTypeLiteral type = ( AttributeTypeLiteral ) attributeTypes.get( "2.5.4.2"
);
 
         assertNotNull( type );
@@ -96,7 +114,8 @@
             + "        DESC 'RFC2256: \"knowledge\" information'\n" + "        EQUALITY caseIgnoreMatch\n"
             + "        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )";
         parser.parse( attributeTypeData );
-        Map attributeTypes = parser.getAttributeTypes();
+        List attributeTypeList = parser.getAttributeTypes();
+        Map attributeTypes = mapAttributeTypes( attributeTypeList );
         AttributeTypeLiteral type = ( AttributeTypeLiteral ) attributeTypes.get( "2.5.4.2"
);
 
         assertNotNull( type );
@@ -115,7 +134,8 @@
             + "        DESC 'RFC2256: knowledge information'\n" + "        EQUALITY caseIgnoreMatch\n"
             + "        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )";
         parser.parse( attributeTypeData );
-        Map attributeTypes = parser.getAttributeTypes();
+        List attributeTypeList = parser.getAttributeTypes();
+        Map attributeTypes = mapAttributeTypes( attributeTypeList );
         AttributeTypeLiteral type = ( AttributeTypeLiteral ) attributeTypes.get( "2.5.4.2"
);
 
         assertNotNull( type );
@@ -127,13 +147,28 @@
     }
 
 
+    private Map mapObjectClasses( List attributeTypeList )
+    {
+        Map m = new HashMap();
+        
+        for ( int ii = 0 ; ii < attributeTypeList.size(); ii++ )
+        {
+            ObjectClassLiteral type = ( ObjectClassLiteral ) attributeTypeList.get( ii );
+            m.put( type.getOid(), type );
+        }
+        
+        return m;
+    }
+
+
     public void testObjectClassParse() throws Exception
     {
         String objectClassData = "objectclass ( 2.5.6.6 NAME 'person'\n" + "        DESC
'RFC2256: a person'\n"
             + "        SUP top STRUCTURAL\n" + "        MUST ( sn $ cn )\n"
             + "        MAY ( userPassword $ telephoneNumber $ seeAlso $ description ) )";
         parser.parse( objectClassData );
-        Map objectClasses = parser.getObjectClassTypes();
+        List objectClassesList = parser.getObjectClassTypes();
+        Map objectClasses = mapObjectClasses( objectClassesList );
         ObjectClassLiteral objectClass = ( ObjectClassLiteral ) objectClasses.get( "2.5.6.6"
);
 
         assertNotNull( objectClass );
@@ -162,7 +197,8 @@
             + "\t\tpagerTelephoneNumber $ organizationalStatus $\n"
             + "\t\tmailPreferenceOption $ personalSignature )\n" + "\t)";
         parser.parse( objectClassData );
-        Map objectClasses = parser.getObjectClassTypes();
+        List objectClassesList = parser.getObjectClassTypes();
+        Map objectClasses = mapObjectClasses( objectClassesList );
         ObjectClassLiteral objectClass = ( ObjectClassLiteral ) objectClasses.get( "0.9.2342.19200300.100.4.4"
);
 
         assertNotNull( objectClass );

Modified: directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/AttributeTypeRegistry.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/AttributeTypeRegistry.java?rev=430093&r1=430092&r2=430093&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/AttributeTypeRegistry.java
(original)
+++ directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/AttributeTypeRegistry.java
Wed Aug  9 09:52:02 2006
@@ -88,4 +88,17 @@
      * names.
      */
     Map getNormalizerMapping() throws NamingException; 
+    
+    
+    /**
+     * Get's an iterator over the set of descendant attributeTypes for
+     * some ancestor's name alias or their OID.
+     * 
+     * @param ancestorId the name alias or OID for an attributeType
+     * @return an Iterator over the AttributeTypes which have the ancestor
+     * within their superior chain to the top
+     * @throws NamingException if the ancestor attributeType cannot be 
+     * discerned from the ancestorId supplied
+     */
+    Iterator descendants( String ancestorId ) throws NamingException;
 }

Modified: directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/GlobalAttributeTypeRegistry.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/GlobalAttributeTypeRegistry.java?rev=430093&r1=430092&r2=430093&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/GlobalAttributeTypeRegistry.java
(original)
+++ directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/GlobalAttributeTypeRegistry.java
Wed Aug  9 09:52:02 2006
@@ -64,7 +64,7 @@
      *
      * @param bootstrap the bootstrapping registry to delegate to
      */
-    public GlobalAttributeTypeRegistry(BootstrapAttributeTypeRegistry bootstrap, OidRegistry
oidRegistry)
+    public GlobalAttributeTypeRegistry( BootstrapAttributeTypeRegistry bootstrap, OidRegistry
oidRegistry )
     {
         this.byOid = new HashMap();
         this.oidToSchema = new HashMap();
@@ -136,6 +136,8 @@
             mapping.put( aliases[jj], oidNormalizer );
             mapping.put( aliases[jj].toLowerCase(), oidNormalizer );
         }
+        
+        bootstrap.registerDescendants( attributeType );
     }
 
 
@@ -226,5 +228,11 @@
             }
         }
         return Collections.unmodifiableMap( mapping );
+    }
+
+
+    public Iterator descendants( String ancestorId ) throws NamingException
+    {
+        return bootstrap.descendants( ancestorId );
     }
 }

Modified: directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/bootstrap/BootstrapAttributeTypeRegistry.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/bootstrap/BootstrapAttributeTypeRegistry.java?rev=430093&r1=430092&r2=430093&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/bootstrap/BootstrapAttributeTypeRegistry.java
(original)
+++ directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/bootstrap/BootstrapAttributeTypeRegistry.java
Wed Aug  9 09:52:02 2006
@@ -19,8 +19,10 @@
 
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Set;
 
 import javax.naming.NamingException;
 
@@ -32,6 +34,7 @@
 import org.apache.directory.shared.ldap.schema.MatchingRule;
 import org.apache.directory.shared.ldap.schema.NoOpNormalizer;
 import org.apache.directory.shared.ldap.schema.OidNormalizer;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -50,6 +53,8 @@
     private final Map byOid;
     /** maps an OID to a schema name*/
     private final Map oidToSchema;
+    /** maps OIDs to a Set of descendants for that OID */
+    private final Map oidToDescendantSet;
     /** the registry used to resolve names to OIDs */
     private final OidRegistry oidRegistry;
     /** monitor notified via callback events */
@@ -65,10 +70,11 @@
     /**
      * Creates an empty BootstrapAttributeTypeRegistry.
      */
-    public BootstrapAttributeTypeRegistry(OidRegistry oidRegistry)
+    public BootstrapAttributeTypeRegistry( OidRegistry oidRegistry )
     {
         this.byOid = new HashMap();
         this.oidToSchema = new HashMap();
+        this.oidToDescendantSet= new HashMap();
         this.oidRegistry = oidRegistry;
         this.monitor = new AttributeTypeRegistryMonitorAdapter();
     }
@@ -105,11 +111,49 @@
             oidRegistry.register( names[ii], attributeType.getOid() );
         }
 
+        registerDescendants( attributeType );
         oidToSchema.put( attributeType.getOid(), schema );
         byOid.put( attributeType.getOid(), attributeType );
         monitor.registered( attributeType );
     }
 
+    
+    public void registerDescendants( AttributeType attributeType ) throws NamingException
+    {
+        // add/create the descendent set for this attribute
+        oidToDescendantSet.put( attributeType.getOid(), new HashSet( 5 ) );
+        
+        // add this attribute to descendant list of other attributes in superior chain
+        onRegisterAddToAncestorDescendants( attributeType, attributeType.getSuperior() );
+    }
+    
+    
+    /**
+     * Recursively adds a new attributeType to the descendant's list of all ancestors
+     * until top is reached.  Top will not have the new type added.
+     * 
+     * @param newType the new attributeType being added
+     * @param ancestor some anscestor from superior up to and including top
+     * @throws NamingException
+     */
+    protected void onRegisterAddToAncestorDescendants( AttributeType newType, AttributeType
ancestor ) 
+        throws NamingException
+    {
+        if ( ancestor == null || ancestor.getName().equals( "top" ) )
+        {
+            return;
+        }
+        
+        Set descendants = ( Set ) oidToDescendantSet.get( ancestor.getOid() );
+        if ( descendants == null )
+        {
+            descendants = new HashSet( 5 );
+            oidToDescendantSet.put( ancestor.getOid(), descendants );
+        }
+        descendants.add( newType );
+        onRegisterAddToAncestorDescendants( newType, ancestor.getSuperior() );
+    }
+    
 
     public AttributeType lookup( String id ) throws NamingException
     {
@@ -196,5 +240,17 @@
         }
         
         return Collections.unmodifiableMap( mapping );
+    }
+
+
+    public Iterator descendants( String ancestorId ) throws NamingException
+    {
+        String oid = oidRegistry.getOid( ancestorId );
+        Set descendants = ( Set ) oidToDescendantSet.get( oid );
+        if ( descendants == null )
+        {
+            return Collections.EMPTY_SET.iterator();
+        }
+        return descendants.iterator();
     }
 }

Modified: directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/bootstrap/BootstrapSchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/bootstrap/BootstrapSchemaLoader.java?rev=430093&r1=430092&r2=430093&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/bootstrap/BootstrapSchemaLoader.java
(original)
+++ directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/bootstrap/BootstrapSchemaLoader.java
Wed Aug  9 09:52:02 2006
@@ -38,6 +38,7 @@
 import org.apache.directory.server.core.schema.NormalizerRegistry;
 import org.apache.directory.server.core.schema.ObjectClassRegistry;
 import org.apache.directory.server.core.schema.ObjectFactoryRegistry;
+import org.apache.directory.server.core.schema.OidRegistry;
 import org.apache.directory.server.core.schema.StateFactoryRegistry;
 import org.apache.directory.server.core.schema.SyntaxCheckerRegistry;
 import org.apache.directory.server.core.schema.SyntaxRegistry;
@@ -52,6 +53,7 @@
 import org.apache.directory.shared.ldap.schema.NameForm;
 import org.apache.directory.shared.ldap.schema.Normalizer;
 import org.apache.directory.shared.ldap.schema.ObjectClass;
+import org.apache.directory.shared.ldap.schema.SchemaObject;
 import org.apache.directory.shared.ldap.schema.Syntax;
 import org.apache.directory.shared.ldap.schema.SyntaxChecker;
 import org.slf4j.Logger;
@@ -230,6 +232,18 @@
         BootstrapSchema schema = ( BootstrapSchema ) this.schemas.get();
         BootstrapRegistries registries = ( BootstrapRegistries ) this.registries.get();
 
+//        if ( schemaObject instanceof SchemaObject )
+//        {
+//            SchemaObject obj = ( SchemaObject ) schemaObject;
+//            OidRegistry oidRegistry = registries.getOidRegistry();
+//            String[] names = obj.getNames();
+//            for ( int ii = 0; ii < names.length; ii++ )
+//            {
+//                oidRegistry.register( names[ii], obj.getOid() );
+//            }
+//            oidRegistry.register( obj.getOid(), obj.getOid() );
+//        }
+        
         switch ( type.getValue() )
         {
             case ( ProducerTypeEnum.NORMALIZER_PRODUCER_VAL  ):

Modified: directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/authz/support/DummyAttributeTypeRegistry.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/authz/support/DummyAttributeTypeRegistry.java?rev=430093&r1=430092&r2=430093&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/authz/support/DummyAttributeTypeRegistry.java
(original)
+++ directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/authz/support/DummyAttributeTypeRegistry.java
Wed Aug  9 09:52:02 2006
@@ -451,4 +451,10 @@
     {
         return null;
     }
+
+
+    public Iterator descendants( String ancestorId ) throws NamingException
+    {
+        return null;
+    }
 }

Modified: directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/schema/SchemaServiceTest.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/schema/SchemaServiceTest.java?rev=430093&r1=430092&r2=430093&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/schema/SchemaServiceTest.java
(original)
+++ directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/schema/SchemaServiceTest.java
Wed Aug  9 09:52:02 2006
@@ -17,11 +17,14 @@
 package org.apache.directory.server.core.schema;
 
 
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.BasicAttribute;
 
-import org.apache.directory.server.core.schema.ObjectClassRegistry;
 import org.apache.directory.server.core.schema.SchemaService;
 import org.apache.directory.server.core.schema.bootstrap.ApacheSchema;
 import org.apache.directory.server.core.schema.bootstrap.BootstrapRegistries;
@@ -32,6 +35,7 @@
 import org.apache.directory.server.core.schema.bootstrap.SystemSchema;
 import org.apache.directory.shared.ldap.exception.LdapNamingException;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.schema.AttributeType;
 
 import junit.framework.TestCase;
 
@@ -42,26 +46,46 @@
  */
 public class SchemaServiceTest extends TestCase
 {
-    ObjectClassRegistry registry = null;
+    BootstrapRegistries registries = new BootstrapRegistries();
 
 
     public void setUp() throws Exception
     {
-        if ( registry != null )
-        {
-            return;
-        }
-
-        BootstrapRegistries registries = new BootstrapRegistries();
+        registries = new BootstrapRegistries();
         BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
+        loader.load( new SystemSchema(), registries );
         loader.load( new ApacheSchema(), registries );
         loader.load( new CoreSchema(), registries );
         loader.load( new CosineSchema(), registries );
         loader.load( new InetorgpersonSchema(), registries );
-        loader.load( new SystemSchema(), registries );
-        registry = registries.getObjectClassRegistry();
     }
 
+    
+    public void testDescendants() throws Exception
+    {
+        AttributeTypeRegistry attrRegistry = registries.getAttributeTypeRegistry();
+        Iterator list = attrRegistry.descendants( "name" );
+        Set nameAttrs = new HashSet();
+        while ( list.hasNext() )
+        {
+            AttributeType type = ( AttributeType ) list.next();
+            nameAttrs.add( type.getName() );
+        }
+        assertEquals( "size of attributes extending name", 13, nameAttrs.size() );
+        assertTrue( nameAttrs.contains( "dmdName" ) );
+        assertTrue( nameAttrs.contains( "o" ) );
+        assertTrue( nameAttrs.contains( "c" ) );
+        assertTrue( nameAttrs.contains( "initials" ) );
+        assertTrue( nameAttrs.contains( "ou" ) );
+        assertTrue( nameAttrs.contains( "sn" ) );
+        assertTrue( nameAttrs.contains( "title" ) );
+        assertTrue( nameAttrs.contains( "l" ) );
+        assertTrue( nameAttrs.contains( "apacheExistance" ) );
+        assertTrue( nameAttrs.contains( "cn" ) );
+        assertTrue( nameAttrs.contains( "st" ) );
+        assertTrue( nameAttrs.contains( "givenName" ) );
+    }
+    
 
     public void testAlterObjectClassesBogusAttr() throws NamingException
     {
@@ -69,7 +93,7 @@
 
         try
         {
-            SchemaService.alterObjectClasses( attr, registry );
+            SchemaService.alterObjectClasses( attr, registries.getObjectClassRegistry() );
             fail( "should not get here" );
         }
         catch ( LdapNamingException e )
@@ -78,7 +102,7 @@
         }
 
         attr = new BasicAttribute( "objectClass" );
-        SchemaService.alterObjectClasses( attr, registry );
+        SchemaService.alterObjectClasses( attr, registries.getObjectClassRegistry() );
         assertEquals( 0, attr.size() );
     }
 
@@ -86,7 +110,7 @@
     public void testAlterObjectClassesNoAttrValue() throws NamingException
     {
         Attribute attr = new BasicAttribute( "objectClass" );
-        SchemaService.alterObjectClasses( attr, registry );
+        SchemaService.alterObjectClasses( attr, registries.getObjectClassRegistry() );
         assertEquals( 0, attr.size() );
     }
 
@@ -94,7 +118,7 @@
     public void testAlterObjectClassesTopAttrValue() throws NamingException
     {
         Attribute attr = new BasicAttribute( "objectClass", "top" );
-        SchemaService.alterObjectClasses( attr, registry );
+        SchemaService.alterObjectClasses( attr, registries.getObjectClassRegistry() );
         assertEquals( 0, attr.size() );
     }
 
@@ -102,7 +126,7 @@
     public void testAlterObjectClassesInetOrgPersonAttrValue() throws NamingException
     {
         Attribute attr = new BasicAttribute( "objectClass", "inetOrgPerson" );
-        SchemaService.alterObjectClasses( attr, registry );
+        SchemaService.alterObjectClasses( attr, registries.getObjectClassRegistry() );
         assertEquals( 3, attr.size() );
         assertTrue( attr.contains( "person" ) );
         assertTrue( attr.contains( "organizationalPerson" ) );
@@ -114,7 +138,7 @@
     {
         Attribute attr = new BasicAttribute( "objectClass", "inetOrgPerson" );
         attr.add( "residentialPerson" );
-        SchemaService.alterObjectClasses( attr, registry );
+        SchemaService.alterObjectClasses( attr, registries.getObjectClassRegistry() );
         assertEquals( 4, attr.size() );
         assertTrue( attr.contains( "person" ) );
         assertTrue( attr.contains( "organizationalPerson" ) );
@@ -128,7 +152,7 @@
         Attribute attr = new BasicAttribute( "objectClass", "inetOrgPerson" );
         attr.add( "residentialPerson" );
         attr.add( "dSA" );
-        SchemaService.alterObjectClasses( attr, registry );
+        SchemaService.alterObjectClasses( attr, registries.getObjectClassRegistry() );
         assertEquals( 6, attr.size() );
         assertTrue( attr.contains( "person" ) );
         assertTrue( attr.contains( "organizationalPerson" ) );



Mime
View raw message