directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r889776 - in /directory/shared/branches/shared-schema: ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/ ldap-schema-loader/src/test/java/org/apache/directory/server/schema/ ldap/src/main/java/org/apache/directory/shared/...
Date Fri, 11 Dec 2009 19:16:08 GMT
Author: elecharny
Date: Fri Dec 11 19:16:07 2009
New Revision: 889776

URL: http://svn.apache.org/viewvc?rev=889776&view=rev
Log:
o Added a lookupObjectClassRegistry method
o Added tests for OC without a superior
o Fixed the toString() method for OC (if NAME was empty, the 'Name' was still printed)
o Removed duplicated AT in MAY and MUST
o addXXX() methods for OC now take a vararg
o 

Modified:
    directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
    directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerAddTest.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DescriptionUtils.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java?rev=889776&r1=889775&r2=889776&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
Fri Dec 11 19:16:07 2009
@@ -1362,6 +1362,15 @@
     /**
      * {@inheritDoc}
      */
+    public ObjectClass lookupObjectClassRegistry( String oid ) throws NamingException
+    {
+        return registries.getObjectClassRegistry().lookup( StringTools.toLowerCase( oid ).trim()
);
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
     public LdapSyntax lookupLdapSyntaxRegistry( String oid ) throws NamingException
     {
         return registries.getLdapSyntaxRegistry().lookup( StringTools.toLowerCase( oid ).trim()
);

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerAddTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerAddTest.java?rev=889776&r1=889775&r2=889776&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerAddTest.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerAddTest.java
Fri Dec 11 19:16:07 2009
@@ -28,7 +28,9 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import javax.naming.NamingException;
 import javax.naming.directory.NoSuchAttributeException;
@@ -41,6 +43,7 @@
 import org.apache.directory.shared.ldap.schema.LdapSyntax;
 import org.apache.directory.shared.ldap.schema.MatchingRule;
 import org.apache.directory.shared.ldap.schema.Normalizer;
+import org.apache.directory.shared.ldap.schema.ObjectClass;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
 import org.apache.directory.shared.ldap.schema.SyntaxChecker;
 import org.apache.directory.shared.ldap.schema.UsageEnum;
@@ -161,6 +164,28 @@
 
 
     /**
+     * Check if an OC is present in the OC registry
+     */
+    private boolean isOCPresent( SchemaManager schemaManager, String oid )
+    {
+        try
+        {
+            ObjectClass objectClass = schemaManager.lookupObjectClassRegistry( oid );
+
+            return objectClass != null;
+        }
+        catch ( NoSuchAttributeException nsae )
+        {
+            return false;
+        }
+        catch ( NamingException ne )
+        {
+            return false;
+        }
+    }
+
+
+    /**
      * Check if a S is present in the S registry
      */
     private boolean isSyntaxPresent( SchemaManager schemaManager, String oid )
@@ -1146,7 +1171,412 @@
     //=========================================================================
     // ObjectClass addition tests
     //-------------------------------------------------------------------------
-    // TODO
+    //-------------------------------------------------------------------------
+    // First, not defined superior
+    //-------------------------------------------------------------------------
+    /**
+     * Addition of a valid OC
+     */
+    @Test
+    public void testAddObjectClassNoSuperiorValid() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int ocrSize = schemaManager.getObjectClassRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+
+        ObjectClass objectClass = new ObjectClass( "1.1.1" );
+
+        assertTrue( schemaManager.add( objectClass ) );
+
+        assertEquals( 0, schemaManager.getErrors().size() );
+
+        ObjectClass added = schemaManager.lookupObjectClassRegistry( "1.1.1" );
+
+        assertNotNull( added );
+
+        assertEquals( ocrSize + 1, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( goidSize + 1, schemaManager.getOidRegistry().size() );
+    }
+
+
+    /**
+     * Addition of an OC with an existing OID
+     */
+    @Test
+    public void testAddObjectClassNoSuperiorWithExistingOid() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int ocrSize = schemaManager.getObjectClassRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+
+        ObjectClass objectClass = new ObjectClass( "2.5.17.0" );
+
+        assertFalse( schemaManager.add( objectClass ) );
+
+        assertEquals( 1, schemaManager.getErrors().size() );
+        Throwable error = schemaManager.getErrors().get( 0 );
+
+        assertTrue( error instanceof LdapSchemaViolationException );
+
+        ObjectClass added = schemaManager.lookupObjectClassRegistry( "2.5.17.0" );
+
+        assertNotNull( added );
+
+        assertEquals( ocrSize, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
+    }
+
+
+    /**
+     * Addition of an OC with an existing OC name
+     */
+    @Test
+    public void testAddObjectClassNoSuperiorWithExistingOCName() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int ocrSize = schemaManager.getObjectClassRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+
+        ObjectClass objectClass = new ObjectClass( "1.1.0" );
+        objectClass.setNames( "Test", "referral" );
+
+        assertFalse( schemaManager.add( objectClass ) );
+
+        assertEquals( 1, schemaManager.getErrors().size() );
+        Throwable error = schemaManager.getErrors().get( 0 );
+
+        assertTrue( error instanceof LdapSchemaViolationException );
+
+        assertFalse( isOCPresent( schemaManager, "1.1.0" ) );
+
+        assertEquals( ocrSize, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
+    }
+
+
+    /**
+     * Addition of an OC with an AT name
+     */
+    @Test
+    public void testAddObjectClassNoSuperiorWithATName() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int ocrSize = schemaManager.getObjectClassRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+
+        ObjectClass objectClass = new ObjectClass( "1.1.1" );
+        objectClass.setNames( "Test", "cn" );
+
+        assertTrue( schemaManager.add( objectClass ) );
+
+        assertEquals( 0, schemaManager.getErrors().size() );
+
+        ObjectClass added = schemaManager.lookupObjectClassRegistry( "1.1.1" );
+
+        assertNotNull( added );
+        assertTrue( added.getNames().contains( "Test" ) );
+        assertTrue( added.getNames().contains( "cn" ) );
+
+        assertEquals( ocrSize + 1, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( goidSize + 1, schemaManager.getOidRegistry().size() );
+    }
+
+
+    /**
+     * Addition of an OC with not existing AT in MAY
+     */
+    @Test
+    public void testAddObjectClassNoSuperiorNonExistingAtInMay() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int ocrSize = schemaManager.getObjectClassRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+
+        ObjectClass objectClass = new ObjectClass( "1.1.1" );
+        objectClass.addMayAttributeTypeOids( "cn", "none", "sn" );
+
+        assertFalse( schemaManager.add( objectClass ) );
+
+        assertEquals( 1, schemaManager.getErrors().size() );
+        Throwable error = schemaManager.getErrors().get( 0 );
+
+        assertTrue( error instanceof LdapSchemaViolationException );
+
+        assertFalse( isOCPresent( schemaManager, "1.1.1" ) );
+
+        assertEquals( ocrSize, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
+    }
+
+
+    /**
+     * Addition of an OC with not existing AT in MUST
+     */
+    @Test
+    public void testAddObjectClassNoSuperiorNonExistingAtInMust() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int ocrSize = schemaManager.getObjectClassRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+
+        ObjectClass objectClass = new ObjectClass( "1.1.1" );
+        objectClass.addMustAttributeTypeOids( "cn", "none", "sn" );
+
+        assertFalse( schemaManager.add( objectClass ) );
+
+        assertEquals( 1, schemaManager.getErrors().size() );
+        Throwable error = schemaManager.getErrors().get( 0 );
+
+        assertTrue( error instanceof LdapSchemaViolationException );
+
+        assertFalse( isOCPresent( schemaManager, "1.1.1" ) );
+
+        assertEquals( ocrSize, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
+    }
+
+
+    /**
+     * Addition of an OC with an AT present more than once in MAY
+     */
+    @Test
+    public void testAddObjectClassNoSuperiorATMoreThanOnceInMay() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int ocrSize = schemaManager.getObjectClassRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+
+        ObjectClass objectClass = new ObjectClass( "1.1.1" );
+        objectClass.addMayAttributeTypeOids( "cn", "ref", "commonName" );
+
+        assertTrue( schemaManager.add( objectClass ) );
+
+        assertEquals( 0, schemaManager.getErrors().size() );
+
+        assertTrue( isOCPresent( schemaManager, "1.1.1" ) );
+
+        ObjectClass added = schemaManager.lookupObjectClassRegistry( "1.1.1" );
+
+        assertNotNull( added );
+
+        assertNotNull( added.getMayAttributeTypes() );
+        assertEquals( 2, added.getMayAttributeTypes().size() );
+        Set<String> expectedAT = new HashSet<String>();
+
+        expectedAT.add( "cn" );
+        expectedAT.add( "ref" );
+
+        for ( AttributeType attributeType : added.getMayAttributeTypes() )
+        {
+            assertTrue( expectedAT.contains( attributeType.getName() ) );
+
+            expectedAT.remove( attributeType.getName() );
+        }
+
+        assertEquals( ocrSize + 1, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( goidSize + 1, schemaManager.getOidRegistry().size() );
+    }
+
+
+    /**
+     * Addition of an OC with an AT present more than once in MUST
+     */
+    @Test
+    public void testAddObjectClassNoSuperiorATMoreThanOnceInMust() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int ocrSize = schemaManager.getObjectClassRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+
+        ObjectClass objectClass = new ObjectClass( "1.1.1" );
+        objectClass.addMustAttributeTypeOids( "cn", "ref", "2.5.4.3" );
+
+        assertTrue( schemaManager.add( objectClass ) );
+
+        assertEquals( 0, schemaManager.getErrors().size() );
+
+        assertTrue( isOCPresent( schemaManager, "1.1.1" ) );
+
+        ObjectClass added = schemaManager.lookupObjectClassRegistry( "1.1.1" );
+
+        assertNotNull( added );
+
+        assertNotNull( added.getMustAttributeTypes() );
+        assertEquals( 2, added.getMustAttributeTypes().size() );
+        Set<String> expectedAT = new HashSet<String>();
+
+        expectedAT.add( "cn" );
+        expectedAT.add( "ref" );
+
+        for ( AttributeType attributeType : added.getMustAttributeTypes() )
+        {
+            assertTrue( expectedAT.contains( attributeType.getName() ) );
+
+            expectedAT.remove( attributeType.getName() );
+        }
+
+        assertEquals( ocrSize + 1, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( goidSize + 1, schemaManager.getOidRegistry().size() );
+    }
+
+
+    /**
+     * Addition of an OC with an AT present in MUST and MAY.
+     */
+    @Test
+    public void testAddObjectClassNoSuperiorATInMustAndMay() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int ocrSize = schemaManager.getObjectClassRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+
+        ObjectClass objectClass = new ObjectClass( "1.1.1" );
+        objectClass.addMustAttributeTypeOids( "cn", "ref" );
+        objectClass.addMayAttributeTypeOids( "2.5.4.3" );
+
+        assertTrue( schemaManager.add( objectClass ) );
+
+        assertEquals( 0, schemaManager.getErrors().size() );
+
+        assertTrue( isOCPresent( schemaManager, "1.1.1" ) );
+
+        ObjectClass added = schemaManager.lookupObjectClassRegistry( "1.1.1" );
+
+        assertNotNull( added );
+
+        assertNotNull( added.getMustAttributeTypes() );
+        assertEquals( 2, added.getMustAttributeTypes().size() );
+        Set<String> expectedAT = new HashSet<String>();
+
+        expectedAT.add( "cn" );
+        expectedAT.add( "ref" );
+
+        for ( AttributeType attributeType : added.getMustAttributeTypes() )
+        {
+            assertTrue( expectedAT.contains( attributeType.getName() ) );
+
+            expectedAT.remove( attributeType.getName() );
+        }
+
+        assertNotNull( added.getMayAttributeTypes() );
+        assertEquals( 1, added.getMayAttributeTypes().size() );
+        assertEquals( "2.5.4.3", added.getMayAttributeTypes().get( 0 ).getOid() );
+
+        assertEquals( ocrSize + 1, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( goidSize + 1, schemaManager.getOidRegistry().size() );
+    }
+
+
+    //-------------------------------------------------------------------------
+    // Then, with superiors
+    //-------------------------------------------------------------------------
+    /**
+     * Addition of a valid OC
+     */
+    @Test
+    public void testAddObjectClassSuperiorsValid() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int ocrSize = schemaManager.getObjectClassRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+    }
+
+
+    /**
+     * Addition of an OC with itself in the SUP list
+     */
+    @Test
+    public void testAddObjectClassSuperiorsWithCycle() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int ocrSize = schemaManager.getObjectClassRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+    }
+
+
+    /**
+     * Addition of an OC with the same OC more than once in SUP
+     */
+    @Test
+    public void testAddObjectClassSuperiorsOcMoreThanOnceInSup() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int ocrSize = schemaManager.getObjectClassRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+    }
+
+
+    /**
+     * Addition of an OC with a non existing OC in SUP
+     */
+    @Test
+    public void testAddObjectClassSuperiorsNonExistingOCInSup() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int ocrSize = schemaManager.getObjectClassRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+    }
+
+
+    /**
+     * Addition of an ABSTRACT OC with some AUXILIARY superior
+     */
+    @Test
+    public void testAddObjectClassSuperiorsAbstractWithAuxiliaryInSup() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int ocrSize = schemaManager.getObjectClassRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+    }
+
+
+    /**
+     * Addition of an ABSTRACT OC with some STRUCTURAL superior
+     */
+    @Test
+    public void testAddObjectClassSuperiorsAbstractWithStructuralInSup() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int ocrSize = schemaManager.getObjectClassRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+    }
+
+
+    /**
+     * Addition of an AUXILIARY OC with some STRUCTURAL superior
+     */
+    @Test
+    public void testAddObjectClassSuperiorsAuxiliaryWithStructuralInSup() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int ocrSize = schemaManager.getObjectClassRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+    }
+
+
+    /**
+     * Addition of an STRUCTURAL OC with some AUXILIARY superior
+     */
+    @Test
+    public void testAddObjectClassSuperiorsStructuralWithAuxiliaryInSup() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int ocrSize = schemaManager.getObjectClassRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+    }
+
+
+    /**
+     * Addition of an OC with a some AT present in one of its superiors' MAY or MUST 
+     */
+    @Test
+    public void testAddObjectClassSuperiorsATPresentInSuperiors() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int ocrSize = schemaManager.getObjectClassRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+    }
+
 
     //=========================================================================
     // Syntax addition tests

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DescriptionUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DescriptionUtils.java?rev=889776&r1=889775&r2=889776&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DescriptionUtils.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DescriptionUtils.java
Fri Dec 11 19:16:07 2009
@@ -132,14 +132,14 @@
         if ( attributeType.getSyntax() != null )
         {
             buf.append( " SYNTAX " );
-            
+
             buf.append( attributeType.getSyntaxName() );
 
             if ( attributeType.getSyntaxLength() > 0 )
             {
                 buf.append( '{' ).append( attributeType.getSyntaxLength() ).append( '}' );
             }
-            
+
             buf.append( '\n' );
         }
 
@@ -161,7 +161,7 @@
         buf.append( " USAGE " );
         buf.append( UsageEnum.render( attributeType.getUsage() ) );
         buf.append( '\n' );
-        
+
         if ( attributeType.getExtensions() != null )
         {
             getExtensions( buf, attributeType.getExtensions() );
@@ -172,7 +172,7 @@
         return buf.toString();
     }
 
-    
+
     /**
      * Generates the ComparatorDescription for a LdapComparator. Only the right 
      * hand side of the description starting at the opening parenthesis is 
@@ -196,7 +196,7 @@
     {
         return getLoadableDescription( comparator );
     }
-    
+
 
     /**
      * Generates the DITContentRuleDescription for a DITContentRule as defined
@@ -249,7 +249,7 @@
 
         // print out all the auxiliary object class oids
         List<ObjectClass> aux = dITContentRule.getAuxObjectClasses();
-        
+
         if ( ( aux != null ) && ( aux.size() > 0 ) )
         {
             buf.append( " AUX " );
@@ -257,7 +257,7 @@
         }
 
         List<AttributeType> must = dITContentRule.getMustAttributeTypes();
-        
+
         if ( ( must != null ) && ( must.size() > 0 ) )
         {
             buf.append( " MUST " );
@@ -265,7 +265,7 @@
         }
 
         List<AttributeType> may = dITContentRule.getMayAttributeTypes();
-        
+
         if ( ( may != null ) && ( may.size() > 0 ) )
         {
             buf.append( " MAY " );
@@ -273,7 +273,7 @@
         }
 
         List<AttributeType> not = dITContentRule.getNotAttributeTypes();
-        
+
         if ( ( not != null ) && ( not.size() > 0 ) )
         {
             buf.append( " NOT " );
@@ -289,7 +289,7 @@
         return buf.toString();
     }
 
-    
+
     /**
      * Generates the DITStructureRuleDescription for a DITStructureRule as
      * defined by the syntax: 1.3.6.1.4.1.1466.115.121.1.17. Only the right hand
@@ -342,11 +342,11 @@
 
         // TODO : Shouldn't we get the ruleId OID ? 
         List<Integer> sups = dITStructureRule.getSuperRules();
-        
+
         if ( ( sups != null ) && ( sups.size() > 0 ) )
         {
             buf.append( " SUP\n" );
-            
+
             if ( sups.size() == 1 )
             {
                 buf.append( sups.get( 0 ) );
@@ -355,7 +355,7 @@
             {
                 boolean isFirst = true;
                 buf.append( "( " );
-                
+
                 for ( int sup : sups )
                 {
                     if ( isFirst )
@@ -366,10 +366,10 @@
                     {
                         buf.append( " " );
                     }
-                    
+
                     buf.append( sup );
                 }
-                
+
                 buf.append( " )" );
             }
 
@@ -428,8 +428,8 @@
 
         buf.append( " SYNTAX " );
         buf.append( matchingRule.getSyntaxOid() );
-        buf.append( '\n' ); 
-        
+        buf.append( '\n' );
+
         if ( matchingRule.getExtensions() != null )
         {
             getExtensions( buf, matchingRule.getExtensions() );
@@ -494,7 +494,7 @@
 
         buf.append( " APPLIES " );
         List<AttributeType> attributeTypes = matchingRuleUse.getApplicableAttributes();
-        
+
         if ( attributeTypes.size() == 1 )
         {
             buf.append( attributeTypes.get( 0 ).getOid() );
@@ -503,9 +503,9 @@
         // for list of oids we need a parenthesis
         {
             buf.append( "( " );
-            
+
             boolean isFirst = true;
-            
+
             for ( AttributeType attributeType : attributeTypes )
             {
                 if ( isFirst )
@@ -516,10 +516,10 @@
                 {
                     buf.append( " $ " );
                 }
-                
+
                 buf.append( attributeType );
             }
-            
+
             buf.append( " ) " );
         }
 
@@ -529,7 +529,7 @@
         }
 
         buf.append( " )\n" );
-        
+
         return buf.toString();
     }
 
@@ -606,7 +606,7 @@
         return buf.toString();
     }
 
-    
+
     /**
      * Generates the NormalizerDescription for a Normalizer. Only the right 
      * hand side of the description starting at the opening parenthesis is 
@@ -662,7 +662,7 @@
         buf.append( objectClass.getOid() );
         buf.append( '\n' );
 
-        if ( objectClass.getNames() != null )
+        if ( ( objectClass.getNames() != null ) && ( objectClass.getNames().size()
!= 0 ) )
         {
             buf.append( " NAME " );
             getQDescrs( buf, objectClass.getNames() );
@@ -696,7 +696,7 @@
         }
 
         List<AttributeType> must = objectClass.getMustAttributeTypes();
-        
+
         if ( ( must != null ) && ( must.size() > 0 ) )
         {
             buf.append( " MUST " );
@@ -704,7 +704,7 @@
         }
 
         List<AttributeType> may = objectClass.getMayAttributeTypes();
-        
+
         if ( ( may != null ) && ( may.size() > 0 ) )
         {
             buf.append( " MAY " );
@@ -757,12 +757,12 @@
         {
             getExtensions( buf, syntax.getExtensions() );
         }
-        
+
         buf.append( " )" );
         return buf.toString();
     }
 
-    
+
     /**
      * Generates the SyntaxCheckerDescription for a SyntaxChecker. Only the right 
      * hand side of the description starting at the opening parenthesis is 
@@ -790,13 +790,13 @@
 
     private static void getExtensions( StringBuilder sb, Map<String, List<String>>
extensions )
     {
-        for ( String key:extensions.keySet() )
+        for ( String key : extensions.keySet() )
         {
             sb.append( key ).append( " " );
-            
+
             List<String> values = extensions.get( key );
-            
-            if ( ( values != null ) && ( values.size() != 0 ) ) 
+
+            if ( ( values != null ) && ( values.size() != 0 ) )
             {
                 if ( values.size() == 1 )
                 {
@@ -806,7 +806,7 @@
                 {
                     boolean isFirst = true;
                     sb.append( "( " );
-                    
+
                     for ( String value : values )
                     {
                         if ( isFirst )
@@ -817,22 +817,22 @@
                         {
                             sb.append( " " );
                         }
-                        
+
                         sb.append( value );
                     }
-                    
+
                     sb.append( " )" );
                 }
             }
-            
+
             sb.append( '\n' );
         }
     }
 
-    
+
     private static void getQDStrings( StringBuilder sb, List<? extends SchemaObject>
schemaObjects )
     {
-        if ( ( schemaObjects != null ) && ( schemaObjects.size() != 0 ) ) 
+        if ( ( schemaObjects != null ) && ( schemaObjects.size() != 0 ) )
         {
             if ( schemaObjects.size() == 1 )
             {
@@ -842,7 +842,7 @@
             {
                 boolean isFirst = true;
                 sb.append( "( " );
-                
+
                 for ( SchemaObject schemaObject : schemaObjects )
                 {
                     if ( isFirst )
@@ -853,21 +853,21 @@
                     {
                         sb.append( " " );
                     }
-                    
+
                     sb.append( '\'' ).append( schemaObject.getName() ).append( '\'' );
                 }
-                
+
                 sb.append( " )" );
             }
         }
-        
+
         sb.append( '\n' );
     }
 
-    
+
     private static void getQDescrs( StringBuilder sb, List<String> names )
     {
-        if ( ( names != null ) && ( names.size() != 0 ) ) 
+        if ( ( names != null ) && ( names.size() != 0 ) )
         {
             if ( names.size() == 1 )
             {
@@ -877,7 +877,7 @@
             {
                 boolean isFirst = true;
                 sb.append( "( " );
-                
+
                 for ( String name : names )
                 {
                     if ( isFirst )
@@ -888,18 +888,18 @@
                     {
                         sb.append( " " );
                     }
-                    
+
                     sb.append( '\'' ).append( name ).append( '\'' );
                 }
-                
+
                 sb.append( " )" );
             }
         }
-        
+
         sb.append( '\n' );
     }
-    
-    
+
+
     /**
      * Generate the description for Comparators, Normalizers and SyntaxCheckers.
      */
@@ -926,7 +926,7 @@
         if ( schemaObject.getBytecode() != null )
         {
             buf.append( " BYTECODE " );
-            
+
             // We will dump only the 16 first bytes
             if ( schemaObject.getBytecode().length() > 16 )
             {
@@ -936,7 +936,7 @@
             {
                 buf.append( schemaObject.getBytecode() );
             }
-            
+
             buf.append( '\n' );
         }
 

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java?rev=889776&r1=889775&r2=889776&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java
Fri Dec 11 19:16:07 2009
@@ -149,9 +149,25 @@
             {
                 mayAttributeTypes = new ArrayList<AttributeType>( mayAttributeTypeOids.size()
);
 
+                List<String> toRemove = new ArrayList<String>();
+
                 for ( String mayAttributeTypeName : mayAttributeTypeOids )
                 {
-                    mayAttributeTypes.add( atRegistry.lookup( atRegistry.getOidByName( mayAttributeTypeName
) ) );
+                    AttributeType attributeType = atRegistry.lookup( mayAttributeTypeName
);
+
+                    if ( mayAttributeTypes.contains( attributeType ) )
+                    {
+                        // Already registrred : skip it and remove it from the OIDs list
+                        toRemove.add( mayAttributeTypeName );
+                        continue;
+                    }
+
+                    mayAttributeTypes.add( attributeType );
+                }
+
+                for ( String oid : toRemove )
+                {
+                    mayAttributeTypeOids.remove( oid );
                 }
             }
 
@@ -159,9 +175,25 @@
             {
                 mustAttributeTypes = new ArrayList<AttributeType>( mustAttributeTypeOids.size()
);
 
+                List<String> toRemove = new ArrayList<String>();
+
                 for ( String mustAttributeTypeName : mustAttributeTypeOids )
                 {
-                    mustAttributeTypes.add( atRegistry.lookup( atRegistry.getOidByName( mustAttributeTypeName
) ) );
+                    AttributeType attributeType = atRegistry.lookup( mustAttributeTypeName
);
+
+                    if ( mustAttributeTypes.contains( attributeType ) )
+                    {
+                        // Already registrred : skip it and remove it from the OIDs list
+                        toRemove.add( mustAttributeTypeName );
+                        continue;
+                    }
+
+                    mustAttributeTypes.add( attributeType );
+                }
+
+                for ( String oid : toRemove )
+                {
+                    mustAttributeTypeOids.remove( oid );
                 }
             }
 
@@ -207,32 +239,38 @@
 
 
     /**
-     * Add an allowed AttributeType
+     * Add some allowed AttributeType
      *
-     * @param oid The attributeType oid
+     * @param oids The attributeType oids
      */
-    public void addMayAttributeTypeOids( String oid )
+    public void addMayAttributeTypeOids( String... oids )
     {
         if ( !isReadOnly )
         {
-            mayAttributeTypeOids.add( oid );
+            for ( String oid : oids )
+            {
+                mayAttributeTypeOids.add( oid );
+            }
         }
     }
 
 
     /**
-     * Add an allowed AttributeType
+     * Add some allowed AttributeTypes
      *
-     * @param attributeType The attributeType
+     * @param attributeTypes The attributeTypes
      */
-    public void addMayAttributeTypes( AttributeType attributeType )
+    public void addMayAttributeTypes( AttributeType... attributeTypes )
     {
         if ( !isReadOnly )
         {
-            if ( !mayAttributeTypeOids.contains( attributeType.getOid() ) )
+            for ( AttributeType attributeType : attributeTypes )
             {
-                mayAttributeTypes.add( attributeType );
-                mayAttributeTypeOids.add( attributeType.getOid() );
+                if ( !mayAttributeTypeOids.contains( attributeType.getOid() ) )
+                {
+                    mayAttributeTypes.add( attributeType );
+                    mayAttributeTypeOids.add( attributeType.getOid() );
+                }
             }
         }
     }
@@ -311,32 +349,38 @@
 
 
     /**
-     * Add a required AttributeType OID
+     * Add some required AttributeType OIDs
      *
-     * @param oid The attributeType OID
+     * @param oid The attributeType OIDs
      */
-    public void addMustAttributeTypeOids( String oid )
+    public void addMustAttributeTypeOids( String... oids )
     {
         if ( !isReadOnly )
         {
-            mustAttributeTypeOids.add( oid );
+            for ( String oid : oids )
+            {
+                mustAttributeTypeOids.add( oid );
+            }
         }
     }
 
 
     /**
-     * Add a required AttributeType
+     * Add some required AttributeTypes
      *
-     * @param attributeType The attributeType
+     * @param attributeTypes The attributeTypse
      */
-    public void addMustAttributeTypes( AttributeType attributeType )
+    public void addMustAttributeTypes( AttributeType... attributeTypes )
     {
         if ( !isReadOnly )
         {
-            if ( !mustAttributeTypeOids.contains( attributeType.getOid() ) )
+            for ( AttributeType attributeType : attributeTypes )
             {
-                mustAttributeTypes.add( attributeType );
-                mustAttributeTypeOids.add( attributeType.getOid() );
+                if ( !mustAttributeTypeOids.contains( attributeType.getOid() ) )
+                {
+                    mustAttributeTypes.add( attributeType );
+                    mustAttributeTypeOids.add( attributeType.getOid() );
+                }
             }
         }
     }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java?rev=889776&r1=889775&r2=889776&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java
Fri Dec 11 19:16:07 2009
@@ -474,6 +474,16 @@
 
 
     /**
+     * Lookup for a ObjectClass in the ObjectClass registry
+     * 
+     * @param String oid the OID we are looking for
+     * @return The found ObjectClass 
+     * @throws NamingException if the OID is not found in the ObjectClass registry
+     */
+    ObjectClass lookupObjectClassRegistry( String oid ) throws NamingException;
+
+
+    /**
      * Lookup for an LdapSyntax in the LdapSyntax registry
      * 
      * @param String oid the OID we are looking for



Mime
View raw message