directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r886866 - in /directory/shared/branches/shared-schema: ldap-schema-loader/src/test/java/org/apache/directory/server/schema/ ldap/src/main/java/org/apache/directory/shared/ldap/schema/ ldap/src/main/java/org/apache/directory/shared/ldap/sche...
Date Thu, 03 Dec 2009 18:01:35 GMT
Author: elecharny
Date: Thu Dec  3 18:01:34 2009
New Revision: 886866

URL: http://svn.apache.org/viewvc?rev=886866&view=rev
Log:
o Implemented all the tests for a AT addition into the schemaMnager
o Fixed some bad handling of the cycle detection
o Fixed some other issues

Modified:
    directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerTest.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AttributeType.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultAttributeTypeRegistry.java

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerTest.java?rev=886866&r1=886865&r2=886866&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerTest.java (original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerTest.java Thu Dec  3 18:01:34 2009
@@ -22,6 +22,7 @@
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import java.io.File;
@@ -106,14 +107,16 @@
     }
 
 
-    //-------------------------------------------------------------------------
+    //=========================================================================
     // AttributeType addition tests
     //-------------------------------------------------------------------------
+    // First, not defined superior
+    //-------------------------------------------------------------------------
     /**
      * Try to inject an AttributeType without any superior nor Syntax : it's invalid
      */
     @Test
-    public void testAddAttributeTypeNoSyntaxNoSuperior() throws Exception
+    public void testAddAttributeTypeNoSupNoSyntaxNoSuperior() throws Exception
     {
         SchemaManager schemaManager = loadSystem();
 
@@ -121,7 +124,6 @@
         attributeType.setEqualityOid( "2.5.13.1" );
         attributeType.setOrderingOid( null );
         attributeType.setSubstringOid( null );
-        attributeType.setSuperior( ( String ) null );
 
         // It should fail
         assertFalse( schemaManager.add( attributeType ) );
@@ -138,7 +140,7 @@
      * Try to inject an AttributeType which is Collective, and userApplication AT
      */
     @Test
-    public void testAddAttributeTypeCollectiveUser() throws Exception
+    public void testAddAttributeTypeNoSupCollectiveUser() throws Exception
     {
         SchemaManager schemaManager = loadSystem();
 
@@ -151,7 +153,9 @@
         attributeType.setCollective( true );
 
         // It should not fail
-        schemaManager.add( attributeType );
+        assertTrue( schemaManager.add( attributeType ) );
+
+        assertNotNull( schemaManager.lookupAttributeTypeRegistry( "1.1.0" ) );
     }
 
 
@@ -159,7 +163,7 @@
      * Try to inject an AttributeType which is Collective, but an operational AT
      */
     @Test
-    public void testAddAttributeTypeCollectiveOperational() throws Exception
+    public void testAddAttributeTypeNoSupCollectiveOperational() throws Exception
     {
         SchemaManager schemaManager = loadSystem();
 
@@ -172,6 +176,210 @@
         attributeType.setCollective( true );
 
         // It should fail
+        assertFalse( schemaManager.add( attributeType ) );
+
+        List<Throwable> errors = schemaManager.getErrors();
+        assertEquals( 1, errors.size() );
+        Throwable error = errors.get( 0 );
+
+        assertTrue( error instanceof LdapSchemaViolationException );
+    }
+
+
+    /**
+     * Try to inject an AttributeType which is a NO-USER-MODIFICATION and userApplication
+     */
+    @Test
+    public void testAddAttributeTypeNoSupNoUserModificationUserAplication() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( "2.5.13.1" );
+        attributeType.setOrderingOid( null );
+        attributeType.setSubstringOid( null );
+        attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
+        attributeType.setUsage( UsageEnum.USER_APPLICATIONS );
+        attributeType.setUserModifiable( false );
+
+        // It should fail
+        assertFalse( schemaManager.add( attributeType ) );
+
+        List<Throwable> errors = schemaManager.getErrors();
+        assertEquals( 1, errors.size() );
+        Throwable error = errors.get( 0 );
+
+        assertTrue( error instanceof LdapSchemaViolationException );
+    }
+
+
+    /**
+     * Try to inject an AttributeType which is a NO-USER-MODIFICATION and is operational
+     */
+    @Test
+    public void testAddAttributeTypeNoSupNoUserModificationOpAttr() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( "2.5.13.1" );
+        attributeType.setOrderingOid( null );
+        attributeType.setSubstringOid( null );
+        attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
+        attributeType.setUsage( UsageEnum.DISTRIBUTED_OPERATION );
+        attributeType.setUserModifiable( false );
+
+        // It should not fail
+        assertTrue( schemaManager.add( attributeType ) );
+
+        assertNotNull( schemaManager.lookupAttributeTypeRegistry( "1.1.0" ) );
+    }
+
+
+    /**
+     * Try to inject an AttributeType with an invalid EQUALITY MR
+     */
+    @Test
+    public void testAddAttributeTypeNoSupInvalidEqualityMR() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( "0.0" );
+        attributeType.setOrderingOid( null );
+        attributeType.setSubstringOid( null );
+        attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
+        attributeType.setUsage( UsageEnum.USER_APPLICATIONS );
+
+        // It should fail
+        assertFalse( schemaManager.add( attributeType ) );
+
+        List<Throwable> errors = schemaManager.getErrors();
+        assertEquals( 1, errors.size() );
+        Throwable error = errors.get( 0 );
+
+        assertTrue( error instanceof LdapSchemaViolationException );
+    }
+
+
+    /**
+     * Try to inject an AttributeType with an invalid ORDERING MR
+     */
+    @Test
+    public void testAddAttributeTypeNoSupInvalidOrderingMR() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( null );
+        attributeType.setOrderingOid( "0.0" );
+        attributeType.setSubstringOid( null );
+        attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
+        attributeType.setUsage( UsageEnum.USER_APPLICATIONS );
+
+        // It should fail
+        assertFalse( schemaManager.add( attributeType ) );
+
+        List<Throwable> errors = schemaManager.getErrors();
+        assertEquals( 1, errors.size() );
+        Throwable error = errors.get( 0 );
+
+        assertTrue( error instanceof LdapSchemaViolationException );
+    }
+
+
+    /**
+     * Try to inject an AttributeType with an invalid SUBSTR MR
+     */
+    @Test
+    public void testAddAttributeTypeNoSupInvalidSubstringMR() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( null );
+        attributeType.setOrderingOid( null );
+        attributeType.setSubstringOid( "0.0" );
+        attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
+        attributeType.setUsage( UsageEnum.USER_APPLICATIONS );
+
+        // It should fail
+        assertFalse( schemaManager.add( attributeType ) );
+
+        List<Throwable> errors = schemaManager.getErrors();
+        assertEquals( 1, errors.size() );
+        Throwable error = errors.get( 0 );
+
+        assertTrue( error instanceof LdapSchemaViolationException );
+    }
+
+
+    /**
+     * Try to inject an AttributeType with valid MRs
+     */
+    @Test
+    public void testAddAttributeTypeNoSupValidMR() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( "2.5.13.1" );
+        attributeType.setOrderingOid( "2.5.13.1" );
+        attributeType.setSubstringOid( "2.5.13.1" );
+        attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
+        attributeType.setUsage( UsageEnum.USER_APPLICATIONS );
+
+        // It should not fail
+        assertTrue( schemaManager.add( attributeType ) );
+
+        assertNotNull( schemaManager.lookupAttributeTypeRegistry( "1.1.0" ) );
+    }
+
+
+    //-------------------------------------------------------------------------
+    // Then, with a superior
+    //-------------------------------------------------------------------------
+    /**
+     * Try to inject an AttributeType with a superior and no Syntax : it should
+     * take its superior' syntax and MR
+     */
+    @Test
+    public void testAddAttributeTypeSupNoSyntaxNoSuperior() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( null );
+        attributeType.setOrderingOid( null );
+        attributeType.setSubstringOid( null );
+        attributeType.setSuperiorOid( "2.5.18.4" );
+        attributeType.setUsage( UsageEnum.DIRECTORY_OPERATION );
+
+        // It should not fail
+        assertTrue( schemaManager.add( attributeType ) );
+
+        AttributeType result = schemaManager.lookupAttributeTypeRegistry( "1.1.0" );
+
+        assertEquals( "1.3.6.1.4.1.1466.115.121.1.12", result.getSyntaxOid() );
+        assertEquals( "2.5.13.1", result.getEqualityOid() );
+    }
+
+
+    /**
+     * Try to inject an AttributeType with a superior and different USAGE
+     */
+    @Test
+    public void testAddAttributeTypeSupDifferentUsage() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( null );
+        attributeType.setOrderingOid( null );
+        attributeType.setSubstringOid( null );
+        attributeType.setSuperiorOid( "2.5.18.4" );
+        attributeType.setUsage( UsageEnum.DISTRIBUTED_OPERATION );
+
         // It should fail
         assertFalse( schemaManager.add( attributeType ) );
 
@@ -180,6 +388,31 @@
         Throwable error = errors.get( 0 );
 
         assertTrue( error instanceof LdapSchemaViolationException );
+    }
+
+
+    /**
+     * Try to inject an AttributeType with itself as a superior
+     */
+    @Test
+    public void testAddAttributeTypeSupWithOwnSup() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
 
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( null );
+        attributeType.setOrderingOid( null );
+        attributeType.setSubstringOid( null );
+        attributeType.setSuperiorOid( "1.1.0" );
+        attributeType.setUsage( UsageEnum.DISTRIBUTED_OPERATION );
+
+        // It should fail
+        assertFalse( schemaManager.add( attributeType ) );
+
+        List<Throwable> errors = schemaManager.getErrors();
+        assertEquals( 1, errors.size() );
+        Throwable error = errors.get( 0 );
+
+        assertTrue( error instanceof LdapSchemaViolationException );
     }
 }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AttributeType.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AttributeType.java?rev=886866&r1=886865&r2=886866&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AttributeType.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AttributeType.java Thu Dec  3 18:01:34 2009
@@ -147,37 +147,37 @@
 
     /** The serialVersionUID */
     public static final long serialVersionUID = 1L;
-    
+
     /** The syntax OID associated with this AttributeType */
     private String syntaxOid;
-    
+
     /** The syntax associated with the syntaxID */
     private LdapSyntax syntax;
-    
+
     /** The equality OID associated with this AttributeType */
     private String equalityOid;
 
     /** The equality MatchingRule associated with the equalityID */
     private MatchingRule equality;
-    
+
     /** The substring OID associated with this AttributeType */
     private String substringOid;
 
     /** The substring MatchingRule associated with the substringID */
     private MatchingRule substring;
-    
+
     /** The ordering OID associated with this AttributeType */
     private String orderingOid;
-    
+
     /** The ordering MatchingRule associated with the orderingID */
     private MatchingRule ordering;
-    
+
     /** The superior AttributeType OID */
     private String superiorOid;
-    
+
     /** The superior AttributeType */
     private AttributeType superior;
-    
+
     /** whether or not this type is single valued */
     private boolean isSingleValued = false;
 
@@ -192,7 +192,8 @@
 
     /** the length of this attribute in bytes */
     private int syntaxLength = 0;
-    
+
+
     /**
      * Creates a AttributeType object using a unique OID.
      * 
@@ -202,16 +203,16 @@
     {
         super( SchemaObjectType.ATTRIBUTE_TYPE, oid );
     }
-    
-    
+
+
     /**
      * Build the Superior AttributeType reference for an AttributeType
      */
-    private void buildSuperior(List<Throwable> errors, Registries registries )
+    private boolean buildSuperior( List<Throwable> errors, Registries registries )
     {
         AttributeType superior = null;
         AttributeTypeRegistry attributeTypeRegistry = registries.getAttributeTypeRegistry();
-        
+
         if ( superiorOid != null )
         {
             // This AT has a superior
@@ -222,32 +223,29 @@
             catch ( Exception e )
             {
                 // Not allowed.
-                String msg = "Cannot find the SUPERIOR object " + superiorOid + 
-                    " while building cross-references for the " + getName() + 
-                    " AttributeType.";
+                String msg = "Cannot find the SUPERIOR object " + superiorOid
+                    + " while building cross-references for the " + getName() + " AttributeType.";
 
-                Throwable error = new LdapSchemaViolationException( 
-                    msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
                 errors.add( error );
                 LOG.info( msg );
-                
+
                 // Get out now
-                return;
+                return false;
             }
-            
+
             if ( superior != null )
             {
                 this.superior = superior;
-                
+
                 // Recursively update the superior if not already done. We don't recurse
                 // if the superior's superior is not null, as it means it has already been
                 // handled.
-                if ( //( ( registries.getUsing( superior ) == null ) || registries.getUsing( superior ).isEmpty() ) && 
-                     ( superior.getSuperior() == null ) )
+                if ( superior.getSuperior() == null )
                 {
                     registries.buildReference( errors, superior );
                 }
-                
+
                 // Update the descendant MAP
                 try
                 {
@@ -257,28 +255,30 @@
                 {
                     errors.add( ne );
                     LOG.info( ne.getMessage() );
+                    return false;
                 }
-                
+
                 // Check for cycles now
                 Set<String> superiors = new HashSet<String>();
                 superiors.add( oid );
                 AttributeType tmp = superior;
-                
+                boolean isOk = true;
+
                 while ( tmp != null )
                 {
                     if ( superiors.contains( tmp.getOid() ) )
                     {
                         // There is a cycle : bad bad bad !
                         // Not allowed.
-                        String msg = "A cycle has been detected in the superior hierarchyOid" + 
-                            " while building cross-references for the " + getName() + 
-                            " AttributeType.";
+                        String msg = "A cycle has been detected in the superior hierarchyOid"
+                            + " while building cross-references for the " + getName() + " AttributeType.";
 
-                        Throwable error = new LdapSchemaViolationException( 
-                            msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                        Throwable error = new LdapSchemaViolationException( msg,
+                            ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
                         errors.add( error );
                         LOG.info( msg );
-                        
+                        isOk = false;
+
                         break;
                     }
                     else
@@ -287,35 +287,33 @@
                         tmp = tmp.getSuperior();
                     }
                 }
-                
+
                 superiors.clear();
-                
-                return;
+
+                return isOk;
             }
             else
             {
                 // Not allowed.
-                String msg = "Cannot find the SUPERIOR object " + superiorOid + 
-                    " while building cross-references for the " + getName() + 
-                    " AttributeType.";
+                String msg = "Cannot find the SUPERIOR object " + superiorOid
+                    + " while building cross-references for the " + getName() + " AttributeType.";
 
-                Throwable error = new LdapSchemaViolationException( 
-                    msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
                 errors.add( error );
                 LOG.info( msg );
-                
+
                 // Get out now
-                return;
+                return false;
             }
         }
         else
         {
             // No superior, just return
-            return;
+            return true;
         }
     }
 
-    
+
     /**
      * Build the SYNTAX reference for an AttributeType
      */
@@ -324,7 +322,7 @@
         if ( syntaxOid != null )
         {
             LdapSyntax syntax = null;
-            
+
             try
             {
                 syntax = registries.getLdapSyntaxRegistry().lookup( syntaxOid );
@@ -332,17 +330,15 @@
             catch ( NamingException ne )
             {
                 // Not allowed.
-                String msg = "Cannot find a Syntax object " + syntaxOid + 
-                    " while building cross-references for the " + getName() + 
-                    " AttributeType.";
+                String msg = "Cannot find a Syntax object " + syntaxOid + " while building cross-references for the "
+                    + getName() + " AttributeType.";
 
-                Throwable error = new LdapSchemaViolationException( 
-                    msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
                 errors.add( error );
                 LOG.info( msg );
                 return;
             }
-            
+
             if ( syntax != null )
             {
                 // Update the Syntax reference
@@ -351,12 +347,10 @@
             else
             {
                 // Not allowed.
-                String msg = "Cannot find a Syntax object " + syntaxOid + 
-                " while building cross-references for the " + getName() + 
-                " AttributeType.";
+                String msg = "Cannot find a Syntax object " + syntaxOid + " while building cross-references for the "
+                    + getName() + " AttributeType.";
 
-                Throwable error = new LdapSchemaViolationException( 
-                    msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
                 errors.add( error );
                 LOG.info( msg );
                 return;
@@ -368,23 +362,23 @@
             if ( superior != null )
             {
                 this.syntax = superior.getSyntax();
+                this.syntaxOid = this.syntax.getOid();
             }
             else
             {
                 // Not allowed.
-                String msg = "The AttributeType " + getName() + " must have " +
-                    "a syntax OID or a superior, it does not have any.";
-    
-                Throwable error = new LdapSchemaViolationException( 
-                    msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                String msg = "The AttributeType " + getName() + " must have "
+                    + "a syntax OID or a superior, it does not have any.";
+
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
                 errors.add( error );
                 LOG.info( msg );
                 return;
             }
         }
     }
-    
-    
+
+
     /**
      * Build the EQUALITY MR reference for an AttributeType
      */
@@ -394,7 +388,7 @@
         if ( equalityOid != null )
         {
             MatchingRule equality = null;
-            
+
             try
             {
                 equality = registries.getMatchingRuleRegistry().lookup( equalityOid );
@@ -402,17 +396,15 @@
             catch ( NamingException ne )
             {
                 // Not allowed.
-                String msg = "Cannot find an Equality MatchingRule object for " + equalityOid + 
-                    " while building cross-references for the " + getName() + 
-                    " AttributeType.";
+                String msg = "Cannot find an Equality MatchingRule object for " + equalityOid
+                    + " while building cross-references for the " + getName() + " AttributeType.";
 
-                Throwable error = new LdapSchemaViolationException( 
-                    msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
                 errors.add( error );
                 LOG.info( msg );
                 return;
             }
-            
+
             if ( equality != null )
             {
                 this.equality = equality;
@@ -420,12 +412,10 @@
             else
             {
                 // Not allowed.
-                String msg = "Cannot find an EQUALITY MatchingRule instance for " + equalityOid + 
-                    " while building cross-references for the " + getName() + 
-                    " AttributeType.";
+                String msg = "Cannot find an EQUALITY MatchingRule instance for " + equalityOid
+                    + " while building cross-references for the " + getName() + " AttributeType.";
 
-                Throwable error = new LdapSchemaViolationException( 
-                    msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
                 errors.add( error );
                 LOG.info( msg );
             }
@@ -436,11 +426,12 @@
             if ( ( superior != null ) && ( superior.getEquality() != null ) )
             {
                 this.equality = superior.getEquality();
+                this.equalityOid = this.equality.getOid();
             }
         }
     }
-    
-    
+
+
     /**
      * Build the ORDERING MR reference for an AttributeType
      */
@@ -449,7 +440,7 @@
         if ( orderingOid != null )
         {
             MatchingRule ordering = null;
-            
+
             try
             {
                 ordering = registries.getMatchingRuleRegistry().lookup( orderingOid );
@@ -457,17 +448,15 @@
             catch ( NamingException ne )
             {
                 // Not allowed.
-                String msg = "Cannot find a Ordering MatchingRule object for " + orderingOid + 
-                    " while building cross-references for the " + getName() + 
-                    " AttributeType.";
+                String msg = "Cannot find a Ordering MatchingRule object for " + orderingOid
+                    + " while building cross-references for the " + getName() + " AttributeType.";
 
-                Throwable error = new LdapSchemaViolationException( 
-                    msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
                 errors.add( error );
                 LOG.info( msg );
                 return;
             }
-            
+
             if ( ordering != null )
             {
                 this.ordering = ordering;
@@ -475,12 +464,10 @@
             else
             {
                 // Not allowed.
-                String msg = "Cannot find an ORDERING MatchingRule instance for " + orderingOid + 
-                    " while building cross-references for the " + getName() + 
-                    " AttributeType.";
+                String msg = "Cannot find an ORDERING MatchingRule instance for " + orderingOid
+                    + " while building cross-references for the " + getName() + " AttributeType.";
 
-                Throwable error = new LdapSchemaViolationException( 
-                    msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
                 errors.add( error );
                 LOG.info( msg );
             }
@@ -491,11 +478,12 @@
             if ( ( superior != null ) && ( superior.getOrdering() != null ) )
             {
                 this.ordering = superior.getOrdering();
+                this.orderingOid = this.ordering.getOid();
             }
         }
     }
 
-    
+
     /**
      * Build the SUBSTR MR reference for an AttributeType
      */
@@ -505,7 +493,7 @@
         if ( substringOid != null )
         {
             MatchingRule substring = null;
-            
+
             try
             {
                 substring = registries.getMatchingRuleRegistry().lookup( substringOid );
@@ -513,17 +501,15 @@
             catch ( NamingException ne )
             {
                 // Not allowed.
-                String msg = "Cannot find a SUBSTR MatchingRule object for " + substringOid + 
-                    " while building cross-references for the " + getName() + 
-                    " AttributeType.";
+                String msg = "Cannot find a SUBSTR MatchingRule object for " + substringOid
+                    + " while building cross-references for the " + getName() + " AttributeType.";
 
-                Throwable error = new LdapSchemaViolationException( 
-                    msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
                 errors.add( error );
                 LOG.info( msg );
                 return;
             }
-            
+
             if ( substring != null )
             {
                 this.substring = substring;
@@ -531,12 +517,10 @@
             else
             {
                 // Not allowed.
-                String msg = "Cannot find a SUBSTR MatchingRule instance for " + substringOid + 
-                    " while building cross-references for the " + getName() + 
-                    " AttributeType.";
+                String msg = "Cannot find a SUBSTR MatchingRule instance for " + substringOid
+                    + " while building cross-references for the " + getName() + " AttributeType.";
 
-                Throwable error = new LdapSchemaViolationException( 
-                    msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
                 errors.add( error );
                 LOG.info( msg );
                 return;
@@ -548,11 +532,12 @@
             if ( ( superior != null ) && ( superior.getSubstring() != null ) )
             {
                 this.substring = superior.getSubstring();
+                this.substringOid = this.substring.getOid();
             }
         }
     }
 
-    
+
     /**
      * Check the constraints for the Usage field.
      */
@@ -562,30 +547,28 @@
         if ( ( superior != null ) && ( usage != superior.getUsage() ) )
         {
             // This is an error
-            String msg = "The attributeType " + getName() + " must have the same USAGE than its superior"; 
+            String msg = "The attributeType " + getName() + " must have the same USAGE than its superior";
 
-            Throwable error = new LdapSchemaViolationException( 
-                msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+            Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
             errors.add( error );
             LOG.info( msg );
             return;
         }
-        
+
         // Now, check that the AttributeType's USAGE does not conflict
         if ( !isUserModifiable() && ( usage == UsageEnum.USER_APPLICATIONS ) )
         {
             // Cannot have a not user modifiable AT which is not an operational AT
-            String msg = "The attributeType " + getName() + " is a USER-APPLICATION attribute, " +
-                "it must be USER-MODIFIABLE"; 
-            
-            Throwable error = new LdapSchemaViolationException( 
-                msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+            String msg = "The attributeType " + getName() + " is a USER-APPLICATION attribute, "
+                + "it must be USER-MODIFIABLE";
+
+            Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
             errors.add( error );
             LOG.info( msg );
         }
     }
-    
-    
+
+
     /**
      * Check the constraints for the Collective field.
      */
@@ -603,17 +586,16 @@
         if ( isCollective() && ( usage != UsageEnum.USER_APPLICATIONS ) )
         {
             // An AttributeType which is collective must be a USER attributeType
-            String msg = "The attributeType " + getName() + " is a COLLECTIVE AttributeType, " +
-                ", it must be a USER-APPLICATION attributeType too.";
-            
-            Throwable error = new LdapSchemaViolationException( 
-                msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+            String msg = "The attributeType " + getName() + " is a COLLECTIVE AttributeType, "
+                + ", it must be a USER-APPLICATION attributeType too.";
+
+            Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
             errors.add( error );
             LOG.info( msg );
         }
     }
-    
-    
+
+
     /**
      * Inject the registries into this Object, updating the references to
      * other SchemaObject.
@@ -629,31 +611,35 @@
         if ( registries != null )
         {
             AttributeTypeRegistry attributeTypeRegistry = registries.getAttributeTypeRegistry();
-            
+
             // The superior
-            buildSuperior( errors, registries );
-            
+            if ( !buildSuperior( errors, registries ) )
+            {
+                // We have had errors, let's stop here as we need a correct superior to continue
+                return;
+            }
+
             // The Syntax
             buildSyntax( errors, registries );
-            
+
             // The EQUALITY matching rule
             buildEquality( errors, registries );
-            
+
             // The ORDERING matching rule
             buildOrdering( errors, registries );
-            
+
             // The SUBSTR matching rule
             buildSubstring( errors, registries );
-            
+
             // Check the USAGE
             checkUsage( errors, registries );
-            
+
             // Check the COLLECTIVE element
             checkCollective( errors, registries );
-            
+
             // Inject the attributeType into the oid/normalizer map
             attributeTypeRegistry.addMappingFor( this );
-    
+
             // Register this AttributeType into the Descendant map
             attributeTypeRegistry.registerDescendants( this, superior );
 
@@ -665,32 +651,32 @@
              */
             if ( equality != null )
             {
-               registries. addReference( this, equality );
+                registries.addReference( this, equality );
             }
-            
+
             if ( ordering != null )
             {
                 registries.addReference( this, ordering );
             }
-            
+
             if ( substring != null )
             {
                 registries.addReference( this, substring );
             }
-            
+
             if ( syntax != null )
             {
                 registries.addReference( this, syntax );
             }
-            
+
             if ( superior != null )
             {
                 registries.addReference( this, superior );
             }
         }
     }
-    
-    
+
+
     /**
      * Gets whether or not this AttributeType is single-valued.
      * 
@@ -716,7 +702,7 @@
         }
     }
 
-    
+
     /**
      * Gets whether or not this AttributeType can be modified by a user.
      * 
@@ -727,7 +713,7 @@
         return canUserModify;
     }
 
-    
+
     /**
      * Tells if this AttributeType can be modified by a user or not
      *
@@ -740,7 +726,7 @@
             this.canUserModify = canUserModify;
         }
     }
-    
+
 
     /**
      * Gets whether or not this AttributeType is a collective attribute.
@@ -762,8 +748,8 @@
     {
         this.isCollective = collective;
     }
-    
-    
+
+
     /**
      * Sets the collective flag
      *
@@ -776,8 +762,8 @@
             this.isCollective = collective;
         }
     }
-    
-    
+
+
     /**
      * Determines the usage for this AttributeType.
      * 
@@ -806,8 +792,8 @@
             this.usage = usage;
         }
     }
-    
-    
+
+
     /**
      * Updates the AttributeType usage, one of :<br>
      * <li>USER_APPLICATIONS
@@ -822,7 +808,7 @@
     {
         this.usage = usage;
     }
-    
+
 
     /**
      * Gets a length limit for this AttributeType.
@@ -833,8 +819,8 @@
     {
         return syntaxLength;
     }
-    
-    
+
+
     /**
      * Sets the length limit of this AttributeType based on its associated
      * syntax.
@@ -848,8 +834,8 @@
             this.syntaxLength = length;
         }
     }
-    
-    
+
+
     /**
      * Gets the the superior AttributeType of this AttributeType.
      * 
@@ -860,7 +846,7 @@
         return superior;
     }
 
-    
+
     /**
      * Gets the OID of the superior AttributeType for this AttributeType.
      * 
@@ -871,7 +857,7 @@
         return superiorOid;
     }
 
-    
+
     /**
      * Gets the Name of the superior AttributeType for this AttributeType.
      * 
@@ -889,7 +875,7 @@
         }
     }
 
-    
+
     /**
      * Sets the superior AttributeType OID of this AttributeType
      *
@@ -902,7 +888,7 @@
             this.superiorOid = superiorOid;
         }
     }
-    
+
 
     /**
      * Sets the superior for this AttributeType
@@ -917,7 +903,7 @@
             this.superiorOid = superior.getOid();
         }
     }
-    
+
 
     /**
      * Sets the superior oid for this AttributeType
@@ -997,7 +983,7 @@
             this.syntaxOid = syntaxOid;
         }
     }
-    
+
 
     /**
      * Sets the Syntax for this AttributeType
@@ -1013,7 +999,7 @@
         }
     }
 
-    
+
     /**
      * Update the associated Syntax, even if the SchemaObject is readOnly
      *
@@ -1025,7 +1011,7 @@
         this.syntaxOid = syntax.getOid();
     }
 
-    
+
     /**
      * Gets the MatchingRule for this AttributeType used for equality matching.
      * 
@@ -1078,7 +1064,7 @@
             this.equalityOid = equalityOid;
         }
     }
-    
+
 
     /**
      * Sets the Equality MR for this AttributeType
@@ -1093,7 +1079,7 @@
             this.equalityOid = equality.getOid();
         }
     }
-    
+
 
     /**
      * Update the associated Equality MatchingRule, even if the SchemaObject is readOnly
@@ -1105,7 +1091,7 @@
         this.equality = equality;
         this.equalityOid = equality.getOid();
     }
-    
+
 
     /**
      * Gets the MatchingRule for this AttributeType used for Ordering matching.
@@ -1159,7 +1145,7 @@
             this.orderingOid = orderingOid;
         }
     }
-    
+
 
     /**
      * Sets the Ordering MR for this AttributeType
@@ -1175,7 +1161,7 @@
         }
     }
 
-    
+
     /**
      * Update the associated Ordering MatchingRule, even if the SchemaObject is readOnly
      *
@@ -1187,7 +1173,7 @@
         this.orderingOid = ordering.getOid();
     }
 
-    
+
     /**
      * Gets the MatchingRule for this AttributeType used for Substr matching.
      * 
@@ -1240,7 +1226,7 @@
             this.substringOid = substrOid;
         }
     }
-    
+
 
     /**
      * Sets the Substr MR for this AttributeType
@@ -1286,7 +1272,7 @@
         return isAncestorOrEqual( this, descendant );
     }
 
-    
+
     /**
      * Checks to see if this AttributeType is the descendant of another
      * attributeType.
@@ -1337,8 +1323,8 @@
     {
         return objectType + " " + DescriptionUtils.getDescription( this );
     }
-    
-    
+
+
     /**
      * Copy an AttributeType
      */
@@ -1348,25 +1334,25 @@
 
         // Copy the SchemaObject common data
         copy.copy( this );
-        
+
         // Copy the canUserModify flag
         copy.canUserModify = canUserModify;
-        
+
         // Copy the isCollective flag
         copy.isCollective = isCollective;
-        
+
         // Copy the isSingleValue flag
         copy.isSingleValued = isSingleValued;
-        
+
         // Copy the USAGE type
         copy.usage = usage;
-        
+
         // All the references to other Registries object are set to null,
         // all the OIDs are copied
         // The EQUALITY MR
         copy.equality = null;
         copy.equalityOid = equalityOid;
-        
+
         // The ORDERING MR
         copy.ordering = null;
         copy.orderingOid = orderingOid;
@@ -1378,16 +1364,16 @@
         // The SUP AT
         copy.superior = null;
         copy.superiorOid = superiorOid;
-        
+
         // The SYNTAX
         copy.syntax = null;
         copy.syntaxOid = syntaxOid;
         copy.syntaxLength = syntaxLength;
-        
+
         return copy;
     }
-    
-    
+
+
     /**
      * {@inheritDoc}
      */
@@ -1395,7 +1381,7 @@
     {
         // Clear the common elements
         super.clear();
-        
+
         // Clear the references
         equality = null;
         ordering = null;
@@ -1403,8 +1389,8 @@
         superior = null;
         syntax = null;
     }
-    
-    
+
+
     /**
      * @see Object#equals(Object)
      */
@@ -1419,39 +1405,39 @@
         {
             return false;
         }
-        
-        AttributeType that = (AttributeType)o;
-        
+
+        AttributeType that = ( AttributeType ) o;
+
         // The COLLECTIVE
         if ( isCollective != that.isCollective )
         {
             return false;
         }
-        
+
         // The SINGLE_VALUE
         if ( isSingleValued != that.isSingleValued )
         {
             return false;
         }
-        
+
         // The NO_USER_MODIFICATION
         if ( canUserModify != that.canUserModify )
         {
             return false;
         }
-        
+
         // The USAGE
         if ( usage != that.usage )
         {
             return false;
         }
-        
+
         // The equality
         if ( !compareOid( equalityOid, that.equalityOid ) )
         {
             return false;
         }
-        
+
         if ( equality != null )
         {
             if ( !equality.equals( that.equality ) )
@@ -1466,7 +1452,7 @@
                 return false;
             }
         }
-        
+
         // The ordering
         if ( !compareOid( orderingOid, that.orderingOid ) )
         {
@@ -1487,13 +1473,13 @@
                 return false;
             }
         }
-        
+
         // The substring
         if ( !compareOid( substringOid, that.substringOid ) )
         {
             return false;
         }
-        
+
         if ( substring != null )
         {
             if ( !substring.equals( that.substring ) )
@@ -1514,7 +1500,7 @@
         {
             return false;
         }
-        
+
         if ( superior != null )
         {
             if ( !superior.equals( that.superior ) )
@@ -1529,24 +1515,24 @@
                 return false;
             }
         }
-        
+
         // The syntax
         if ( !compareOid( syntaxOid, that.syntaxOid ) )
         {
             return false;
         }
-        
+
         if ( syntaxLength != that.syntaxLength )
         {
             return false;
         }
-        
+
         if ( syntax == null )
         {
             return that.syntax == null;
         }
 
-        if ( syntax.equals(  that.syntax ) )
+        if ( syntax.equals( that.syntax ) )
         {
             return syntaxLength == that.syntaxLength;
         }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultAttributeTypeRegistry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultAttributeTypeRegistry.java?rev=886866&r1=886865&r2=886866&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultAttributeTypeRegistry.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultAttributeTypeRegistry.java Thu Dec  3 18:01:34 2009
@@ -46,22 +46,22 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev: 828111 $
  */
-public class DefaultAttributeTypeRegistry extends DefaultSchemaObjectRegistry<AttributeType> 
-    implements AttributeTypeRegistry
+public class DefaultAttributeTypeRegistry extends DefaultSchemaObjectRegistry<AttributeType> implements
+    AttributeTypeRegistry
 {
     /** static class logger */
     private static final Logger LOG = LoggerFactory.getLogger( DefaultAttributeTypeRegistry.class );
 
     /** Speedup for DEBUG mode */
     private static final boolean IS_DEBUG = LOG.isDebugEnabled();
-    
+
     /** cached Oid/normalizer mapping */
     private transient Map<String, OidNormalizer> oidNormalizerMap;
-    
+
     /** maps OIDs to a Set of descendants for that OID */
-    private Map<String,Set<AttributeType>> oidToDescendantSet;
+    private Map<String, Set<AttributeType>> oidToDescendantSet;
+
 
-    
     /**
      * Creates a new default AttributeTypeRegistry instance.
      */
@@ -69,10 +69,10 @@
     {
         super( SchemaObjectType.ATTRIBUTE_TYPE, new OidRegistry() );
         oidNormalizerMap = new HashMap<String, OidNormalizer>();
-        oidToDescendantSet = new HashMap<String,Set<AttributeType>>();
+        oidToDescendantSet = new HashMap<String, Set<AttributeType>>();
     }
-    
-    
+
+
     /**
      * {@inheritDoc}
      */
@@ -80,8 +80,8 @@
     {
         return Collections.unmodifiableMap( oidNormalizerMap );
     }
-    
-    
+
+
     /**
      * {@inheritDoc}
      */
@@ -91,15 +91,15 @@
         {
             String oid = getOidByName( ancestorId );
             Set<AttributeType> descendants = oidToDescendantSet.get( oid );
-            return (descendants != null) && !descendants.isEmpty();
+            return ( descendants != null ) && !descendants.isEmpty();
         }
         catch ( NamingException ne )
         {
             throw new NoSuchAttributeException( ne.getMessage() );
         }
     }
-    
-    
+
+
     /**
      * {@inheritDoc}
      */
@@ -110,12 +110,12 @@
         {
             String oid = getOidByName( ancestorId );
             Set<AttributeType> descendants = oidToDescendantSet.get( oid );
-            
+
             if ( descendants == null )
             {
                 return Collections.EMPTY_SET.iterator();
             }
-            
+
             return descendants.iterator();
         }
         catch ( NamingException ne )
@@ -123,20 +123,19 @@
             throw new NoSuchAttributeException( ne.getMessage() );
         }
     }
-    
-    
+
+
     /**
      * {@inheritDoc}
      */
-    public void registerDescendants( AttributeType attributeType, AttributeType ancestor ) 
-        throws NamingException
+    public void registerDescendants( AttributeType attributeType, AttributeType ancestor ) throws NamingException
     {
         // add this attribute to descendant list of other attributes in superior chain
         if ( ancestor == null )
         {
             return;
         }
-        
+
         // Get the ancestor's descendant, if any
         Set<AttributeType> descendants = oidToDescendantSet.get( ancestor.getOid() );
 
@@ -146,10 +145,11 @@
             descendants = new HashSet<AttributeType>( 1 );
             oidToDescendantSet.put( ancestor.getOid(), descendants );
         }
-        
+
         // Add the current type as a descendant
         descendants.add( attributeType );
-        
+
+        /*
         try
         {
             // And recurse until we reach the top of the hierarchy
@@ -159,34 +159,34 @@
         {
             throw new NoSuchAttributeException( ne.getMessage() );
         }
+        */
     }
-    
-    
+
+
     /**
      * {@inheritDoc}
      */
-    public void unregisterDescendants( AttributeType attributeType, AttributeType ancestor ) 
-        throws NamingException
+    public void unregisterDescendants( AttributeType attributeType, AttributeType ancestor ) throws NamingException
     {
         // add this attribute to descendant list of other attributes in superior chain
         if ( ancestor == null )
         {
             return;
         }
-        
+
         // Get the ancestor's descendant, if any
         Set<AttributeType> descendants = oidToDescendantSet.get( ancestor.getOid() );
 
         if ( descendants != null )
         {
             descendants.remove( attributeType );
-            
+
             if ( descendants.size() == 0 )
             {
                 oidToDescendantSet.remove( descendants );
             }
         }
-        
+
         try
         {
             // And recurse until we reach the top of the hierarchy
@@ -197,8 +197,8 @@
             throw new NoSuchAttributeException( ne.getMessage() );
         }
     }
-    
-    
+
+
     /**
      * {@inheritDoc}
      */
@@ -207,17 +207,17 @@
         try
         {
             AttributeType removed = super.unregister( numericOid );
-    
+
             removeMappingFor( removed );
-            
+
             // Deleting an AT which might be used as a superior means we have
             // to recursively update the descendant map. We also have to remove
             // the at.oid -> descendant relation
             oidToDescendantSet.remove( numericOid );
-            
+
             // Now recurse if needed
             unregisterDescendants( removed, removed.getSuperior() );
-            
+
             return removed;
         }
         catch ( NamingException ne )
@@ -226,7 +226,7 @@
         }
     }
 
-    
+
     /**
      * {@inheritDoc}
      */
@@ -238,7 +238,8 @@
 
         if ( equality == null )
         {
-            LOG.debug( "Attribute {} does not have an EQUALITY MatchingRule : using NoopNormalizer", attributeType.getName() );
+            LOG.debug( "Attribute {} does not have an EQUALITY MatchingRule : using NoopNormalizer", attributeType
+                .getName() );
             oidNormalizer = new OidNormalizer( oid, new NoOpNormalizer( attributeType.getOid() ) );
         }
         else
@@ -247,7 +248,7 @@
         }
 
         oidNormalizerMap.put( oid, oidNormalizer );
-        
+
         // Also inject the attributeType's short names in the map
         for ( String name : attributeType.getNames() )
         {
@@ -265,7 +266,7 @@
         {
             return;
         }
-        
+
         oidNormalizerMap.remove( attributeType.getOid() );
 
         // We also have to remove all the short names for this attribute
@@ -283,7 +284,7 @@
     {
         try
         {
-           return super.lookup( oid );
+            return super.lookup( oid );
         }
         catch ( NamingException ne )
         {
@@ -291,21 +292,21 @@
         }
     }
 
-    
+
     /**
      * {@inheritDoc}
      */
     public AttributeTypeRegistry copy()
     {
         DefaultAttributeTypeRegistry copy = new DefaultAttributeTypeRegistry();
-        
+
         // Copy the base data
         copy.copy( this );
-        
+
         return copy;
     }
-    
-    
+
+
     /**
      * {@inheritDoc}
      */
@@ -313,21 +314,21 @@
     {
         // First clear the shared elements
         super.clear();
-        
+
         // clear the OidNormalizer map
         oidNormalizerMap.clear();
-        
+
         // and clear the descendant
         for ( String oid : oidToDescendantSet.keySet() )
         {
             Set<AttributeType> descendants = oidToDescendantSet.get( oid );
-            
+
             if ( descendants != null )
             {
                 descendants.clear();
             }
         }
-        
+
         oidToDescendantSet.clear();
     }
 }



Mime
View raw message