directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1244561 - in /directory: apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/ shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/ shared/trunk/ldap/model/src/main/java/or...
Date Wed, 15 Feb 2012 16:11:17 GMT
Author: elecharny
Date: Wed Feb 15 16:11:17 2012
New Revision: 1244561

URL: http://svn.apache.org/viewvc?rev=1244561&view=rev
Log:
o Moved the addToRegistries() method out of ObjectClass to a dedicated helper class (ObjectClassHelper)
o Create a sub-package helper in registries for the helper classes
o Removed a useless import
o Fixed a test

Added:
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/registries/helper/
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/registries/helper/AttributeTypeHelper.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/registries/helper/ObjectClassHelper.java
Modified:
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SchemaSearchIT.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/AbstractSchemaObject.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/AttributeType.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/ObjectClass.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/registries/Registries.java
    directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/shared/ldap/schemamanager/impl/DefaultSchemaManager.java
    directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/shared/ldap/schemaloader/SchemaManagerAddTest.java

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SchemaSearchIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SchemaSearchIT.java?rev=1244561&r1=1244560&r2=1244561&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SchemaSearchIT.java (original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SchemaSearchIT.java Wed Feb 15 16:11:17 2012
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ * 
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ * 
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.server.operations.search;
 
@@ -45,7 +45,7 @@ import org.junit.runner.RunWith;
 
 
 /**
- * Test case with different search operations on the cn=schema entry. 
+ * Test case with different search operations on the cn=schema entry.
  * Created to demonstrate DIRSERVER-1055
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
@@ -246,8 +246,8 @@ public void testRequestAllOperationalAtt
 
 
 /**
- * Test case for DIRSERVER-1083: Search on an custom attribute added to 
- * the dynamic schema fails when no result is found. 
+ * Test case for DIRSERVER-1083: Search on an custom attribute added to
+ * the dynamic schema fails when no result is found.
  */
 @Test
 public void testSearchingNewSchemaElements() throws Exception
@@ -291,7 +291,7 @@ public void testSearchingNewSchemaElemen
 
 
 /**
- * Test case for DIRSERVER-: Ensure that schema entry is returned, 
+ * Test case for DIRSERVER-: Ensure that schema entry is returned,
  * even if no ManageDsaIT decorator is present in the search request.
  */
 @Test
@@ -326,7 +326,7 @@ public void testRequestWithoutManageDsaI
 
 
 /**
- * Test a search done on cn=schema 
+ * Test a search done on cn=schema
  */
 @Test
 public void testSubSchemaSubEntrySearch() throws Exception
@@ -349,7 +349,7 @@ public void testSubSchemaSubEntrySearch(
     while ( ocs.hasMore() )
     {
         String oc = ( String ) ocs.nextElement();
-        if ( oc.contains( "2.5.6.6" ) )
+        if ( oc.startsWith( "( 2.5.6.6" ) )
         {
             assertEquals(
                 "( 2.5.6.6 NAME 'person' DESC 'RFC2256: a person' SUP top STRUCTURAL MUST ( sn $ cn ) MAY ( userPassword $ telephoneNumber $ seeAlso $ description ) X-SCHEMA 'core' )",

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/AbstractSchemaObject.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/AbstractSchemaObject.java?rev=1244561&r1=1244560&r2=1244561&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/AbstractSchemaObject.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/AbstractSchemaObject.java Wed Feb 15 16:11:17 2012
@@ -924,6 +924,12 @@ public abstract class AbstractSchemaObje
         // Clear the names
         names.clear();
     }
+    
+    
+    public void unlock()
+    {
+        locked = false;
+    }
 
 
     /**

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/AttributeType.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/AttributeType.java?rev=1244561&r1=1244560&r2=1244561&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/AttributeType.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/AttributeType.java Wed Feb 15 16:11:17 2012
@@ -1231,10 +1231,4 @@ public class AttributeType extends Abstr
             return false;
         }
     }
-    
-    
-    public void unlock()
-    {
-        locked = false;
-    }
 }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/ObjectClass.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/ObjectClass.java?rev=1244561&r1=1244560&r2=1244561&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/ObjectClass.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/ObjectClass.java Wed Feb 15 16:11:17 2012
@@ -25,9 +25,6 @@ import java.util.List;
 
 import org.apache.directory.shared.i18n.I18n;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
-import org.apache.directory.shared.ldap.model.exception.LdapSchemaException;
-import org.apache.directory.shared.ldap.model.exception.LdapSchemaExceptionCodes;
-import org.apache.directory.shared.ldap.model.schema.registries.AttributeTypeRegistry;
 import org.apache.directory.shared.ldap.model.schema.registries.ObjectClassRegistry;
 import org.apache.directory.shared.ldap.model.schema.registries.Registries;
 
@@ -120,267 +117,6 @@ public class ObjectClass extends Abstrac
     }
 
 
-    private void buildSuperiors( List<Throwable> errors, Registries registries )
-    {
-        ObjectClassRegistry ocRegistry = registries.getObjectClassRegistry();
-
-        if ( superiorOids != null )
-        {
-            superiors = new ArrayList<ObjectClass>( superiorOids.size() );
-
-            for ( String superiorName : superiorOids )
-            {
-                try
-                {
-                    ObjectClass superior = ocRegistry.lookup( ocRegistry.getOidByName( superiorName ) );
-
-                    // Before adding the superior, check that the ObjectClass type is consistent
-                    switch ( objectClassType )
-                    {
-                        case ABSTRACT:
-                            if ( superior.objectClassType != ObjectClassTypeEnum.ABSTRACT )
-                            {
-                                // An ABSTRACT OC can only inherit from ABSTRACT OCs
-                                String msg = I18n.err( I18n.ERR_04318, oid, superior.getObjectType(), superior );
-
-                                LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                                    LdapSchemaExceptionCodes.OC_ABSTRACT_MUST_INHERIT_FROM_ABSTRACT_OC, msg );
-                                ldapSchemaException.setSourceObject( this );
-                                errors.add( ldapSchemaException );
-                                return;
-                            }
-
-                            break;
-
-                        case AUXILIARY:
-                            if ( superior.objectClassType == ObjectClassTypeEnum.STRUCTURAL )
-                            {
-                                // An AUXILIARY OC cannot inherit from STRUCTURAL OCs
-                                String msg = I18n.err( I18n.ERR_04319, oid, superior );
-
-                                LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                                    LdapSchemaExceptionCodes.OC_AUXILIARY_CANNOT_INHERIT_FROM_STRUCTURAL_OC, msg );
-                                ldapSchemaException.setSourceObject( this );
-                                errors.add( ldapSchemaException );
-                                return;
-                            }
-
-                            break;
-
-                        case STRUCTURAL:
-                            if ( superior.objectClassType == ObjectClassTypeEnum.AUXILIARY )
-                            {
-                                // A STRUCTURAL OC cannot inherit from AUXILIARY OCs
-                                String msg = I18n.err( I18n.ERR_04320, oid, superior );
-
-                                LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                                    LdapSchemaExceptionCodes.OC_STRUCTURAL_CANNOT_INHERIT_FROM_AUXILIARY_OC, msg );
-                                ldapSchemaException.setSourceObject( this );
-                                errors.add( ldapSchemaException );
-                                return;
-                            }
-
-                            break;
-                    }
-
-                    superiors.add( superior );
-                }
-                catch ( LdapException ne )
-                {
-                    // Cannot find the OC
-                    String msg = I18n.err( I18n.ERR_04321, oid, superiorName );
-
-                    LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                        LdapSchemaExceptionCodes.OC_NONEXISTENT_SUPERIOR, msg, ne );
-                    ldapSchemaException.setSourceObject( this );
-                    ldapSchemaException.setRelatedId( superiorName );
-                    errors.add( ldapSchemaException );
-                    return;
-                }
-            }
-        }
-    }
-
-
-    private void buildMay( List<Throwable> errors, Registries registries )
-    {
-        AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry();
-
-        if ( mayAttributeTypeOids != null )
-        {
-            mayAttributeTypes = new ArrayList<AttributeType>( mayAttributeTypeOids.size() );
-
-            for ( String mayAttributeTypeName : mayAttributeTypeOids )
-            {
-                try
-                {
-                    AttributeType attributeType = atRegistry.lookup( mayAttributeTypeName );
-
-                    if ( attributeType.isCollective() )
-                    {
-                        // Collective Attributes are not allowed in MAY or MUST
-                        String msg = I18n.err( I18n.ERR_04485_COLLECTIVE_NOT_ALLOWED_IN_MAY, mayAttributeTypeName, oid );
-
-                        LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                            LdapSchemaExceptionCodes.OC_COLLECTIVE_NOT_ALLOWED_IN_MAY, msg );
-                        ldapSchemaException.setSourceObject( this );
-                        ldapSchemaException.setRelatedId( mayAttributeTypeName );
-                        errors.add( ldapSchemaException );
-                        break;
-                    }
-
-                    if ( mayAttributeTypes.contains( attributeType ) )
-                    {
-                        // Already registered : this is an error
-                        String msg = I18n.err( I18n.ERR_04322, oid, mayAttributeTypeName );
-
-                        LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                            LdapSchemaExceptionCodes.OC_DUPLICATE_AT_IN_MAY, msg );
-                        ldapSchemaException.setSourceObject( this );
-                        ldapSchemaException.setRelatedId( mayAttributeTypeName );
-                        errors.add( ldapSchemaException );
-                        break;
-                    }
-
-                    mayAttributeTypes.add( attributeType );
-                }
-                catch ( LdapException ne )
-                {
-                    // Cannot find the AT
-                    String msg = I18n.err( I18n.ERR_04323, oid, mayAttributeTypeName );
-
-                    LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                        LdapSchemaExceptionCodes.OC_NONEXISTENT_MAY_AT, msg, ne );
-                    ldapSchemaException.setSourceObject( this );
-                    ldapSchemaException.setRelatedId( mayAttributeTypeName );
-                    errors.add( ldapSchemaException );
-                    break;
-                }
-            }
-        }
-    }
-
-
-    private void buildMust( List<Throwable> errors, Registries registries )
-    {
-        AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry();
-
-        if ( mustAttributeTypeOids != null )
-        {
-            mustAttributeTypes = new ArrayList<AttributeType>( mustAttributeTypeOids.size() );
-
-            for ( String mustAttributeTypeName : mustAttributeTypeOids )
-            {
-                try
-                {
-                    AttributeType attributeType = atRegistry.lookup( mustAttributeTypeName );
-
-                    if ( attributeType.isCollective() )
-                    {
-                        // Collective Attributes are not allowed in MAY or MUST
-                        String msg = I18n.err( I18n.ERR_04484_COLLECTIVE_NOT_ALLOWED_IN_MUST, mustAttributeTypeName,
-                            oid );
-
-                        LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                            LdapSchemaExceptionCodes.OC_COLLECTIVE_NOT_ALLOWED_IN_MUST, msg );
-                        ldapSchemaException.setSourceObject( this );
-                        ldapSchemaException.setRelatedId( mustAttributeTypeName );
-                        errors.add( ldapSchemaException );
-                        break;
-                    }
-
-                    if ( mustAttributeTypes.contains( attributeType ) )
-                    {
-                        // Already registered : this is an error
-                        String msg = I18n.err( I18n.ERR_04324, oid, mustAttributeTypeName );
-
-                        LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                            LdapSchemaExceptionCodes.OC_DUPLICATE_AT_IN_MUST, msg );
-                        ldapSchemaException.setSourceObject( this );
-                        ldapSchemaException.setRelatedId( mustAttributeTypeName );
-                        errors.add( ldapSchemaException );
-                        break;
-                    }
-
-                    // Check that the MUST AT is not also present in the MAY AT
-                    if ( mayAttributeTypes.contains( attributeType ) )
-                    {
-                        // Already registered : this is an error
-                        String msg = I18n.err( I18n.ERR_04325, oid, mustAttributeTypeName );
-
-                        LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                            LdapSchemaExceptionCodes.OC_DUPLICATE_AT_IN_MAY_AND_MUST,
-                            msg );
-                        ldapSchemaException.setSourceObject( this );
-                        ldapSchemaException.setRelatedId( mustAttributeTypeName );
-                        errors.add( ldapSchemaException );
-                        break;
-                    }
-
-                    mustAttributeTypes.add( attributeType );
-                }
-                catch ( LdapException ne )
-                {
-                    // Cannot find the AT
-                    String msg = I18n.err( I18n.ERR_04326, oid, mustAttributeTypeName );
-
-                    LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                        LdapSchemaExceptionCodes.OC_NONEXISTENT_MUST_AT, msg, ne );
-                    ldapSchemaException.setSourceObject( this );
-                    ldapSchemaException.setRelatedId( mustAttributeTypeName );
-                    errors.add( ldapSchemaException );
-                    break;
-                }
-            }
-        }
-    }
-
-
-    /**
-     * Inject the ObjectClass into the registries, updating the references to
-     * other SchemaObject
-     *
-     * @param errors The errors we got while adding the ObjectClass to the registries
-     * @param registries The Registries
-     * @throws Exception on failure
-     *
-     */
-    public void addToRegistries( List<Throwable> errors, Registries registries ) throws LdapException
-    {
-        if ( registries != null )
-        {
-            // The superiors
-            buildSuperiors( errors, registries );
-
-            // The MAY AttributeTypes
-            buildMay( errors, registries );
-
-            // The MUST AttributeTypes
-            buildMust( errors, registries );
-
-            /**
-             * Add the OC references (using and usedBy) :
-             * OC -> AT (MAY and MUST)
-             * OC -> OC (SUPERIORS)
-             */
-            for ( AttributeType mayAttributeType : mayAttributeTypes )
-            {
-                registries.addReference( this, mayAttributeType );
-            }
-
-            for ( AttributeType mustAttributeType : mustAttributeTypes )
-            {
-                registries.addReference( this, mustAttributeType );
-            }
-
-            for ( ObjectClass superiorObjectClass : superiors )
-            {
-                registries.addReference( this, superiorObjectClass );
-            }
-        }
-    }
-
-
     /**
      * Remove the ObjectClass from the registries, updating the references to
      * other SchemaObject.

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/registries/Registries.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/registries/Registries.java?rev=1244561&r1=1244560&r2=1244561&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/registries/Registries.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/registries/Registries.java Wed Feb 15 16:11:17 2012
@@ -52,7 +52,8 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.schema.SchemaObject;
 import org.apache.directory.shared.ldap.model.schema.SchemaObjectWrapper;
 import org.apache.directory.shared.ldap.model.schema.SyntaxChecker;
-import org.apache.directory.shared.ldap.model.schema.UsageEnum;
+import org.apache.directory.shared.ldap.model.schema.registries.helper.AttributeTypeHelper;
+import org.apache.directory.shared.ldap.model.schema.registries.helper.ObjectClassHelper;
 import org.apache.directory.shared.util.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -563,75 +564,6 @@ public class Registries implements Schem
             delReference( attributeType, attributeType.getSuperior() );
         }
     }
-
-
-    /**
-     * Some specific controls must be checked :
-     * - an AT must have either a SYNTAX or a SUP. If there is no SYNTAX, then
-     * the AT will take it's superior SYNTAX;
-     * - if there is no EQUALITY, ORDERING or SUBSTRING MR, and if there is
-     * a SUP, then the AT will use its parent MR, if any;
-     * - if an AT has a superior, then its usage must be the same than its
-     * superior Usage;
-     * - if an AT is COLLECTIVE, then its usage must be userApplications;
-     * - if an AT is NO-USER-MODIFICATION, then its usage must be one of
-     * directoryOperation, distributedOperation or dSAOperation;
-     * - if an AT has a superior, and if its superior is COLLECTIVE, then
-     * the AT will be COLLECTIVE too
-     * 
-     *
-    private void buildRecursiveAttributeTypeReferences( List<Throwable> errors, Set<String> done, AttributeType attributeType )
-    {
-        buildReference( errors, attributeType );
-        // An attributeType has references on Syntax, MatchingRule and itself
-        try
-        {
-            attributeType.addToRegistries( this );
-        }
-        catch ( LdapException ne )
-        {
-            String msg = "Cannot build the AttributeType references for the object " + attributeType.getName() +
-                ", error : " + ne.getMessage();
-            
-            Throwable error = new LdapSchemaViolationException(
-                msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
-            errors.add( error );
-            LOG.info( msg );
-        }
-        
-        // First, check if the AT has a superior
-        //buildSuperior( errors, done, attributeType );
-        
-        // The LdapSyntax (cannot be null)
-        //buildSyntax( errors, attributeType );
-        
-        // The equality MR.
-        //buildEquality( errors, attributeType );
-
-        // The ORDERING MR.
-        //buildOrdering( errors, attributeType );
-        
-        // The SUBSTR MR.
-        //buildSubstring( errors, attributeType );
-        
-        // Last, not least, check some of the other constraints
-        //checkUsage( errors, attributeType );
-        //checkCollective( errors, attributeType );
-        
-        // Update the dedicated fields
-        /*try
-        {
-            attributeTypeRegistry.addMappingFor( attributeType );
-        }
-        catch ( LdapException ne )
-        {
-            errors.add( ne );
-            LOG.info( ne.getMessage() );
-        }
-        
-        // Update the cross references
-        addCrossReferences( attributeType );
-    }
     
     
     /**
@@ -730,13 +662,19 @@ public class Registries implements Schem
     {
         try
         {
-            if ( schemaObject instanceof AttributeType )
-            {
-                addToRegistries( (AttributeType)schemaObject, errors, this );
-            }
-            else
+            switch ( schemaObject.getObjectType() )
             {
-                schemaObject.addToRegistries( errors, this );
+                case ATTRIBUTE_TYPE :
+                    AttributeTypeHelper.addToRegistries( (AttributeType)schemaObject, errors, this );
+                    break;
+                    
+                case OBJECT_CLASS :
+                    ObjectClassHelper.addToRegistries( (ObjectClass)schemaObject, errors, this );
+                    break;
+                    
+                default :
+                    schemaObject.addToRegistries( errors, this );
+                    break;
             }
         }
         catch ( LdapException ne )
@@ -1357,7 +1295,7 @@ public class Registries implements Schem
         // All is done for this ObjectClass, let's apply the registries
         try
         {
-            objectClass.addToRegistries( errors, this );
+            ObjectClassHelper.addToRegistries( objectClass, errors, this );
         }
         catch ( LdapException ne )
         {
@@ -2852,546 +2790,6 @@ public class Registries implements Schem
     }
 
 
-    /**
-     * {@inheritDoc}
-     *
-     * If one of the referenced SchemaObject does not exist (SUP, EQUALITY, ORDERING, SUBSTR, SYNTAX),
-     * an exception is thrown.
-     */
-    public void addToRegistries( AttributeType attributeType, List<Throwable> errors, Registries registries ) throws LdapException
-    {
-        if ( registries != null )
-        {
-            attributeType.unlock();
-            AttributeTypeRegistry attributeTypeRegistry = registries.getAttributeTypeRegistry();
-
-            // The superior
-            if ( !buildSuperior( attributeType, errors, registries ) )
-            {
-                // We have had errors, let's stop here as we need a correct superior to continue
-                attributeType.lock();
-                return;
-            }
-
-            // The Syntax
-            buildSyntax( attributeType, errors, registries );
-
-            // The EQUALITY matching rule
-            buildEquality( attributeType, errors, registries );
-
-            // The ORDERING matching rule
-            buildOrdering( attributeType, errors, registries );
-
-            // The SUBSTR matching rule
-            buildSubstring( attributeType, errors, registries );
-
-            // Check the USAGE
-            checkUsage( attributeType, errors );
-
-            // Check the COLLECTIVE element
-            checkCollective( attributeType, errors );
-
-            // Inject the attributeType into the oid/normalizer map
-            attributeTypeRegistry.addMappingFor( attributeType );
-
-            // Register this AttributeType into the Descendant map
-            attributeTypeRegistry.registerDescendants( attributeType, attributeType.getSuperior() );
-
-            /**
-             * Add the AT references (using and usedBy) :
-             * AT -> MR (for EQUALITY, ORDERING and SUBSTR)
-             * AT -> S
-             * AT -> AT
-             */
-            if ( attributeType.getEquality() != null )
-            {
-                registries.addReference( attributeType, attributeType.getEquality() );
-            }
-
-            if ( attributeType.getOrdering() != null )
-            {
-                registries.addReference( attributeType, attributeType.getOrdering() );
-            }
-
-            if ( attributeType.getSubstring() != null )
-            {
-                registries.addReference( attributeType, attributeType.getSubstring() );
-            }
-
-            if ( attributeType.getSyntax() != null )
-            {
-                registries.addReference( attributeType, attributeType.getSyntax() );
-            }
-
-            if ( attributeType.getSuperior() != null )
-            {
-                registries.addReference( attributeType, attributeType.getSuperior() );
-            }
-            
-            attributeType.lock();
-        }
-    }
-
-
-    /**
-     * Build the Superior AttributeType reference for an AttributeType
-     */
-    private boolean buildSuperior( AttributeType attributeType, List<Throwable> errors, Registries registries )
-    {
-        AttributeType currentSuperior = null;
-        AttributeTypeRegistry attributeTypeRegistry = registries.getAttributeTypeRegistry();
-        
-        String superiorOid = attributeType.getSuperiorOid();
-
-        if ( superiorOid != null )
-        {
-            // This AT has a superior
-            try
-            {
-                currentSuperior = attributeTypeRegistry.lookup( superiorOid );
-            }
-            catch ( Exception e )
-            {
-                // Not allowed.
-                String msg = I18n.err( I18n.ERR_04303, superiorOid, attributeType.getName() );
-
-                LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                    LdapSchemaExceptionCodes.AT_NONEXISTENT_SUPERIOR, msg, e );
-                ldapSchemaException.setSourceObject( attributeType );
-                ldapSchemaException.setRelatedId( superiorOid );
-                errors.add( ldapSchemaException );
-                LOG.info( msg );
-
-                // Get out now
-                return false;
-            }
-
-            if ( currentSuperior != null )
-            {
-                // a special case : if the superior is collective, this is an error
-                if ( currentSuperior.isCollective() )
-                {
-                    String msg = I18n.err( I18n.ERR_04482_CANNOT_SUBTYPE_COLLECTIVE,
-                        currentSuperior, attributeType.getName() );
-
-                    LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                        LdapSchemaExceptionCodes.AT_CANNOT_SUBTYPE_COLLECTIVE_AT, msg );
-                    ldapSchemaException.setSourceObject( attributeType );
-                    errors.add( ldapSchemaException );
-                    LOG.info( msg );
-                    return false;
-                }
-
-                attributeType.setSuperior( currentSuperior );
-
-                // 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 ( currentSuperior.getSuperior() == null )
-                {
-                    registries.buildReference( errors, currentSuperior );
-                }
-
-                // Update the descendant MAP
-                try
-                {
-                    attributeTypeRegistry.registerDescendants( attributeType, currentSuperior );
-                }
-                catch ( LdapException ne )
-                {
-                    errors.add( ne );
-                    LOG.info( ne.getMessage() );
-                    return false;
-                }
-
-                // Check for cycles now
-                Set<String> superiors = new HashSet<String>();
-                superiors.add( attributeType.getOid() );
-                AttributeType tmp = currentSuperior;
-                boolean isOk = true;
-
-                while ( tmp != null )
-                {
-                    if ( superiors.contains( tmp.getOid() ) )
-                    {
-                        // There is a cycle : bad bad bad !
-                        // Not allowed.
-                        String msg = I18n.err( I18n.ERR_04304, attributeType.getName() );
-
-                        LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                            LdapSchemaExceptionCodes.AT_CYCLE_TYPE_HIERARCHY, msg );
-                        ldapSchemaException.setSourceObject( attributeType );
-                        errors.add( ldapSchemaException );
-                        LOG.info( msg );
-                        isOk = false;
-
-                        break;
-                    }
-                    else
-                    {
-                        superiors.add( tmp.getOid() );
-                        tmp = tmp.getSuperior();
-                    }
-                }
-
-                superiors.clear();
-
-                return isOk;
-            }
-            else
-            {
-                // Not allowed.
-                String msg = I18n.err( I18n.ERR_04305, superiorOid, attributeType.getName() );
-
-                LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                    LdapSchemaExceptionCodes.AT_NONEXISTENT_SUPERIOR, msg );
-                ldapSchemaException.setSourceObject( attributeType );
-                ldapSchemaException.setRelatedId( superiorOid );
-                errors.add( ldapSchemaException );
-                LOG.info( msg );
-
-                // Get out now
-                return false;
-            }
-        }
-        else
-        {
-            // No superior, just return
-            return true;
-        }
-    }
-
-
-    /**
-     * Build the SYNTAX reference for an AttributeType
-     */
-    private void buildSyntax( AttributeType attributeType, List<Throwable> errors, Registries registries )
-    {
-        String syntaxOid = attributeType.getSyntaxOid();
-        
-        if ( syntaxOid != null )
-        {
-            LdapSyntax currentSyntax = null;
-
-            try
-            {
-                currentSyntax = registries.getLdapSyntaxRegistry().lookup( syntaxOid );
-            }
-            catch ( LdapException ne )
-            {
-                // Not allowed.
-                String msg = I18n.err( I18n.ERR_04306, syntaxOid, attributeType.getName() );
-
-                LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                    LdapSchemaExceptionCodes.AT_NONEXISTENT_SYNTAX, msg, ne );
-                ldapSchemaException.setSourceObject( attributeType );
-                ldapSchemaException.setRelatedId( syntaxOid );
-                errors.add( ldapSchemaException );
-                LOG.info( msg );
-                return;
-            }
-
-            if ( currentSyntax != null )
-            {
-                // Update the Syntax reference
-                attributeType.setSyntax( currentSyntax );
-            }
-            else
-            {
-                // Not allowed.
-                String msg = I18n.err( I18n.ERR_04306, syntaxOid, attributeType.getName() );
-
-                LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                    LdapSchemaExceptionCodes.AT_NONEXISTENT_SYNTAX, msg );
-                ldapSchemaException.setSourceObject( attributeType );
-                ldapSchemaException.setRelatedId( syntaxOid );
-                errors.add( ldapSchemaException );
-                LOG.info( msg );
-                return;
-            }
-        }
-        else
-        {
-            // We inherit from the superior's syntax, if any
-            if ( attributeType.getSuperior() != null )
-            {
-                attributeType.setSyntax( attributeType.getSuperior().getSyntax() );
-            }
-            else
-            {
-                // Not allowed.
-                String msg = I18n.err( I18n.ERR_04307, attributeType.getName() );
-
-                LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                    LdapSchemaExceptionCodes.AT_SYNTAX_OR_SUPERIOR_REQUIRED, msg );
-                ldapSchemaException.setSourceObject( attributeType );
-                errors.add( ldapSchemaException );
-                LOG.info( msg );
-                return;
-            }
-        }
-    }
-    
-    
-
-
-    /**
-     * Build the EQUALITY MR reference for an AttributeType
-     */
-    private void buildEquality( AttributeType attributeType, List<Throwable> errors, Registries registries )
-    {
-        String equalityOid = attributeType.getEqualityOid();
-        
-        // The equality MR. It can be null
-        if ( equalityOid != null )
-        {
-            MatchingRule currentEquality = null;
-
-            try
-            {
-                currentEquality = registries.getMatchingRuleRegistry().lookup( equalityOid );
-            }
-            catch ( LdapException ne )
-            {
-                // Not allowed.
-                String msg = I18n.err( I18n.ERR_04308, equalityOid, attributeType.getName() );
-
-                LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                    LdapSchemaExceptionCodes.AT_NONEXISTENT_EQUALITY_MATCHING_RULE, msg, ne );
-                ldapSchemaException.setSourceObject( attributeType );
-                ldapSchemaException.setRelatedId( equalityOid );
-                errors.add( ldapSchemaException );
-                LOG.info( msg );
-                return;
-            }
-
-            if ( currentEquality != null )
-            {
-                attributeType.setEquality( currentEquality );
-            }
-            else
-            {
-                // Not allowed.
-                String msg = I18n.err( I18n.ERR_04309, equalityOid, attributeType.getName() );
-
-                LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                    LdapSchemaExceptionCodes.AT_NONEXISTENT_EQUALITY_MATCHING_RULE, msg );
-                ldapSchemaException.setSourceObject( attributeType );
-                ldapSchemaException.setRelatedId( equalityOid );
-                errors.add( ldapSchemaException );
-                LOG.info( msg );
-            }
-        }
-        else
-        {
-            AttributeType superior = attributeType.getSuperior();
-            
-            // If the AT has a superior, take its Equality MR if any
-            if ( ( superior != null ) && ( superior.getEquality() != null ) )
-            {
-                attributeType.setEquality( superior.getEquality() );
-            }
-        }
-    }
-
-
-    /**
-     * Build the SUBSTR MR reference for an AttributeType
-     */
-    private void buildSubstring( AttributeType attributeType, List<Throwable> errors, Registries registries )
-    {
-        String substringOid = attributeType.getSubstringOid();
-        
-        // The Substring MR. It can be null
-        if ( substringOid != null )
-        {
-            MatchingRule currentSubstring = null;
-
-            try
-            {
-                currentSubstring = registries.getMatchingRuleRegistry().lookup( substringOid );
-            }
-            catch ( LdapException ne )
-            {
-                // Not allowed.
-                String msg = I18n.err( I18n.ERR_04312, substringOid, attributeType.getName() );
-
-                LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                    LdapSchemaExceptionCodes.AT_NONEXISTENT_SUBSTRING_MATCHING_RULE, msg, ne );
-                ldapSchemaException.setSourceObject( attributeType );
-                ldapSchemaException.setRelatedId( substringOid );
-                errors.add( ldapSchemaException );
-                LOG.info( msg );
-                return;
-            }
-
-            if ( currentSubstring != null )
-            {
-                attributeType.setSubstring( currentSubstring );
-            }
-            else
-            {
-                // Not allowed.
-                String msg = I18n.err( I18n.ERR_04313, substringOid, attributeType.getName() );
-
-                LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                    LdapSchemaExceptionCodes.AT_NONEXISTENT_SUBSTRING_MATCHING_RULE, msg );
-                ldapSchemaException.setSourceObject( attributeType );
-                ldapSchemaException.setRelatedId( substringOid );
-                errors.add( ldapSchemaException );
-                LOG.info( msg );
-                return;
-            }
-        }
-        else
-        {
-            AttributeType superior = attributeType.getSuperior();
-            
-            // If the AT has a superior, take its Substring MR if any
-            if ( ( superior != null ) && ( superior.getSubstring() != null ) )
-            {
-                attributeType.setSubstring( superior.getSubstring() );
-            }
-        }
-    }
-    
-    
-
-
-
-
-    /**
-     * Build the ORDERING MR reference for an AttributeType
-     */
-    private void buildOrdering( AttributeType attributeType, List<Throwable> errors, Registries registries )
-    {
-        String orderingOid = attributeType.getOrderingOid();
-        
-        if ( orderingOid != null )
-        {
-            MatchingRule currentOrdering = null;
-
-            try
-            {
-                currentOrdering = registries.getMatchingRuleRegistry().lookup( orderingOid );
-            }
-            catch ( LdapException ne )
-            {
-                // Not allowed.
-                String msg = I18n.err( I18n.ERR_04310, orderingOid, attributeType.getName() );
-
-                LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                    LdapSchemaExceptionCodes.AT_NONEXISTENT_ORDERING_MATCHING_RULE, msg, ne );
-                ldapSchemaException.setSourceObject( attributeType );
-                ldapSchemaException.setRelatedId( orderingOid );
-                errors.add( ldapSchemaException );
-                LOG.info( msg );
-                return;
-            }
-
-            if ( currentOrdering != null )
-            {
-                attributeType.setOrdering( currentOrdering );
-            }
-            else
-            {
-                // Not allowed.
-                String msg = I18n.err( I18n.ERR_04311, orderingOid, attributeType.getName() );
-
-                LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                    LdapSchemaExceptionCodes.AT_NONEXISTENT_ORDERING_MATCHING_RULE, msg );
-                ldapSchemaException.setSourceObject( attributeType );
-                ldapSchemaException.setRelatedId( orderingOid );
-                errors.add( ldapSchemaException );
-                LOG.info( msg );
-            }
-        }
-        else
-        {
-            AttributeType superior = attributeType.getSuperior();
-            
-            // If the AT has a superior, take its Ordering MR if any
-            if ( ( superior != null ) && ( superior.getOrdering() != null ) )
-            {
-                attributeType.setOrdering( superior.getOrdering() );
-            }
-        }
-    }
-
-    
-    /**
-     * Check the constraints for the Usage field.
-     */
-    private void checkUsage( AttributeType attributeType, List<Throwable> errors )
-    {
-        AttributeType superior = attributeType.getSuperior();
-        
-        // Check that the AT usage is the same that its superior
-        if ( ( superior != null ) && ( attributeType.getUsage() != superior.getUsage() ) )
-        {
-            // This is an error
-            String msg = I18n.err( I18n.ERR_04314, attributeType.getName() );
-
-            LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                LdapSchemaExceptionCodes.AT_MUST_HAVE_SAME_USAGE_THAN_SUPERIOR, msg );
-            ldapSchemaException.setSourceObject( attributeType );
-            errors.add( ldapSchemaException );
-            LOG.info( msg );
-            return;
-        }
-
-        // Now, check that the AttributeType's USAGE does not conflict
-        if ( !attributeType.isUserModifiable() && ( attributeType.getUsage() == UsageEnum.USER_APPLICATIONS ) )
-        {
-            // Cannot have a not user modifiable AT which is not an operational AT
-            String msg = I18n.err( I18n.ERR_04315, attributeType.getName() );
-
-            LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                LdapSchemaExceptionCodes.AT_USER_APPLICATIONS_USAGE_MUST_BE_USER_MODIFIABLE, msg );
-            ldapSchemaException.setSourceObject( attributeType );
-            errors.add( ldapSchemaException );
-            LOG.info( msg );
-        }
-    }
-
-
-    /**
-     * Check the constraints for the Collective field.
-     */
-    private void checkCollective( AttributeType attributeType, List<Throwable> errors )
-    {
-        AttributeType superior = attributeType.getSuperior();
-
-        if ( ( superior != null ) && superior.isCollective() )
-        {
-            // An AttributeType will be collective if its superior is collective
-            attributeType.setCollective( true );
-        }
-
-        if ( attributeType.isCollective() && ( attributeType.getUsage() != UsageEnum.USER_APPLICATIONS ) )
-        {
-            // An AttributeType which is collective must be a USER attributeType
-            String msg = I18n.err( I18n.ERR_04316, attributeType.getName() );
-
-            LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                LdapSchemaExceptionCodes.AT_COLLECTIVE_MUST_HAVE_USER_APPLICATIONS_USAGE, msg );
-            ldapSchemaException.setSourceObject( attributeType );
-            errors.add( ldapSchemaException );
-            LOG.info( msg );
-        }
-
-        if ( attributeType.isCollective() && attributeType.isSingleValued() )
-        {
-            // A collective attribute must be multi-valued
-            String msg = I18n.err( I18n.ERR_04483_COLLECTIVE_NOT_MULTI_VALUED, attributeType.getName() );
-
-            LdapSchemaException ldapSchemaException = new LdapSchemaException(
-                LdapSchemaExceptionCodes.AT_COLLECTIVE_CANNOT_BE_SINGLE_VALUED, msg );
-            ldapSchemaException.setSourceObject( attributeType );
-            errors.add( ldapSchemaException );
-            LOG.info( msg );
-        }
-    }
 
 
     /**

Added: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/registries/helper/AttributeTypeHelper.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/registries/helper/AttributeTypeHelper.java?rev=1244561&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/registries/helper/AttributeTypeHelper.java (added)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/registries/helper/AttributeTypeHelper.java Wed Feb 15 16:11:17 2012
@@ -0,0 +1,605 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.directory.shared.ldap.model.schema.registries.helper;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.exception.LdapSchemaException;
+import org.apache.directory.shared.ldap.model.exception.LdapSchemaExceptionCodes;
+import org.apache.directory.shared.ldap.model.schema.AttributeType;
+import org.apache.directory.shared.ldap.model.schema.LdapSyntax;
+import org.apache.directory.shared.ldap.model.schema.MatchingRule;
+import org.apache.directory.shared.ldap.model.schema.UsageEnum;
+import org.apache.directory.shared.ldap.model.schema.registries.AttributeTypeRegistry;
+import org.apache.directory.shared.ldap.model.schema.registries.Registries;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * An helper class used to store all the methods associated with an AttributeType
+ * in relation with the Registries and SchemaManager.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AttributeTypeHelper
+{
+    /** A logger for this class */
+    private static final Logger LOG = LoggerFactory.getLogger( AttributeTypeHelper.class );
+
+    /**
+     * {@inheritDoc}
+     *
+     * If one of the referenced SchemaObject does not exist (SUP, EQUALITY, ORDERING, SUBSTR, SYNTAX),
+     * an exception is thrown.
+     */
+    public static void addToRegistries( AttributeType attributeType, List<Throwable> errors, Registries registries ) throws LdapException
+    {
+        if ( registries != null )
+        {
+            try
+            {
+                attributeType.unlock();
+                AttributeTypeRegistry attributeTypeRegistry = registries.getAttributeTypeRegistry();
+    
+                // The superior
+                if ( !buildSuperior( attributeType, errors, registries ) )
+                {
+                    // We have had errors, let's stop here as we need a correct superior to continue
+                    return;
+                }
+    
+                // The Syntax
+                buildSyntax( attributeType, errors, registries );
+    
+                // The EQUALITY matching rule
+                buildEquality( attributeType, errors, registries );
+    
+                // The ORDERING matching rule
+                buildOrdering( attributeType, errors, registries );
+    
+                // The SUBSTR matching rule
+                buildSubstring( attributeType, errors, registries );
+    
+                // Check the USAGE
+                checkUsage( attributeType, errors );
+    
+                // Check the COLLECTIVE element
+                checkCollective( attributeType, errors );
+    
+                // Inject the attributeType into the oid/normalizer map
+                attributeTypeRegistry.addMappingFor( attributeType );
+    
+                // Register this AttributeType into the Descendant map
+                attributeTypeRegistry.registerDescendants( attributeType, attributeType.getSuperior() );
+    
+                /**
+                 * Add the AT references (using and usedBy) :
+                 * AT -> MR (for EQUALITY, ORDERING and SUBSTR)
+                 * AT -> S
+                 * AT -> AT
+                 */
+                if ( attributeType.getEquality() != null )
+                {
+                    registries.addReference( attributeType, attributeType.getEquality() );
+                }
+    
+                if ( attributeType.getOrdering() != null )
+                {
+                    registries.addReference( attributeType, attributeType.getOrdering() );
+                }
+    
+                if ( attributeType.getSubstring() != null )
+                {
+                    registries.addReference( attributeType, attributeType.getSubstring() );
+                }
+    
+                if ( attributeType.getSyntax() != null )
+                {
+                    registries.addReference( attributeType, attributeType.getSyntax() );
+                }
+    
+                if ( attributeType.getSuperior() != null )
+                {
+                    registries.addReference( attributeType, attributeType.getSuperior() );
+                }
+            }
+            finally
+            {
+                attributeType.lock();
+            }
+        }
+    }
+
+
+    /**
+     * Build the Superior AttributeType reference for an AttributeType
+     */
+    private static boolean buildSuperior( AttributeType attributeType, List<Throwable> errors, Registries registries )
+    {
+        AttributeType currentSuperior = null;
+        AttributeTypeRegistry attributeTypeRegistry = registries.getAttributeTypeRegistry();
+        
+        String superiorOid = attributeType.getSuperiorOid();
+
+        if ( superiorOid != null )
+        {
+            // This AT has a superior
+            try
+            {
+                currentSuperior = attributeTypeRegistry.lookup( superiorOid );
+            }
+            catch ( Exception e )
+            {
+                // Not allowed.
+                String msg = I18n.err( I18n.ERR_04303, superiorOid, attributeType.getName() );
+
+                LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                    LdapSchemaExceptionCodes.AT_NONEXISTENT_SUPERIOR, msg, e );
+                ldapSchemaException.setSourceObject( attributeType );
+                ldapSchemaException.setRelatedId( superiorOid );
+                errors.add( ldapSchemaException );
+                LOG.info( msg );
+
+                // Get out now
+                return false;
+            }
+
+            if ( currentSuperior != null )
+            {
+                // a special case : if the superior is collective, this is an error
+                if ( currentSuperior.isCollective() )
+                {
+                    String msg = I18n.err( I18n.ERR_04482_CANNOT_SUBTYPE_COLLECTIVE,
+                        currentSuperior, attributeType.getName() );
+
+                    LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                        LdapSchemaExceptionCodes.AT_CANNOT_SUBTYPE_COLLECTIVE_AT, msg );
+                    ldapSchemaException.setSourceObject( attributeType );
+                    errors.add( ldapSchemaException );
+                    LOG.info( msg );
+                    
+                    return false;
+                }
+
+                attributeType.setSuperior( currentSuperior );
+
+                // 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 ( currentSuperior.getSuperior() == null )
+                {
+                    registries.buildReference( errors, currentSuperior );
+                }
+
+                // Update the descendant MAP
+                try
+                {
+                    attributeTypeRegistry.registerDescendants( attributeType, currentSuperior );
+                }
+                catch ( LdapException ne )
+                {
+                    errors.add( ne );
+                    LOG.info( ne.getMessage() );
+                    
+                    return false;
+                }
+
+                // Check for cycles now
+                Set<String> superiors = new HashSet<String>();
+                superiors.add( attributeType.getOid() );
+                AttributeType tmp = currentSuperior;
+                boolean isOk = true;
+
+                while ( tmp != null )
+                {
+                    if ( superiors.contains( tmp.getOid() ) )
+                    {
+                        // There is a cycle : bad bad bad !
+                        // Not allowed.
+                        String msg = I18n.err( I18n.ERR_04304, attributeType.getName() );
+
+                        LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                            LdapSchemaExceptionCodes.AT_CYCLE_TYPE_HIERARCHY, msg );
+                        ldapSchemaException.setSourceObject( attributeType );
+                        errors.add( ldapSchemaException );
+                        LOG.info( msg );
+                        isOk = false;
+
+                        break;
+                    }
+                    else
+                    {
+                        superiors.add( tmp.getOid() );
+                        tmp = tmp.getSuperior();
+                    }
+                }
+
+                superiors.clear();
+
+                return isOk;
+            }
+            else
+            {
+                // Not allowed.
+                String msg = I18n.err( I18n.ERR_04305, superiorOid, attributeType.getName() );
+
+                LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                    LdapSchemaExceptionCodes.AT_NONEXISTENT_SUPERIOR, msg );
+                ldapSchemaException.setSourceObject( attributeType );
+                ldapSchemaException.setRelatedId( superiorOid );
+                errors.add( ldapSchemaException );
+                LOG.info( msg );
+
+                // Get out now
+                return false;
+            }
+        }
+        else
+        {
+            // No superior, just return
+            return true;
+        }
+    }
+
+
+    /**
+     * Build the SYNTAX reference for an AttributeType
+     */
+    private static void buildSyntax( AttributeType attributeType, List<Throwable> errors, Registries registries )
+    {
+        String syntaxOid = attributeType.getSyntaxOid();
+        
+        if ( syntaxOid != null )
+        {
+            LdapSyntax currentSyntax = null;
+
+            try
+            {
+                currentSyntax = registries.getLdapSyntaxRegistry().lookup( syntaxOid );
+            }
+            catch ( LdapException ne )
+            {
+                // Not allowed.
+                String msg = I18n.err( I18n.ERR_04306, syntaxOid, attributeType.getName() );
+
+                LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                    LdapSchemaExceptionCodes.AT_NONEXISTENT_SYNTAX, msg, ne );
+                ldapSchemaException.setSourceObject( attributeType );
+                ldapSchemaException.setRelatedId( syntaxOid );
+                errors.add( ldapSchemaException );
+                LOG.info( msg );
+                
+                return;
+            }
+
+            if ( currentSyntax != null )
+            {
+                // Update the Syntax reference
+                attributeType.setSyntax( currentSyntax );
+            }
+            else
+            {
+                // Not allowed.
+                String msg = I18n.err( I18n.ERR_04306, syntaxOid, attributeType.getName() );
+
+                LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                    LdapSchemaExceptionCodes.AT_NONEXISTENT_SYNTAX, msg );
+                ldapSchemaException.setSourceObject( attributeType );
+                ldapSchemaException.setRelatedId( syntaxOid );
+                errors.add( ldapSchemaException );
+                LOG.info( msg );
+                
+                return;
+            }
+        }
+        else
+        {
+            // We inherit from the superior's syntax, if any
+            if ( attributeType.getSuperior() != null )
+            {
+                attributeType.setSyntax( attributeType.getSuperior().getSyntax() );
+            }
+            else
+            {
+                // Not allowed.
+                String msg = I18n.err( I18n.ERR_04307, attributeType.getName() );
+
+                LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                    LdapSchemaExceptionCodes.AT_SYNTAX_OR_SUPERIOR_REQUIRED, msg );
+                ldapSchemaException.setSourceObject( attributeType );
+                errors.add( ldapSchemaException );
+                LOG.info( msg );
+                
+                return;
+            }
+        }
+    }
+    
+    
+    /**
+     * Build the EQUALITY MR reference for an AttributeType
+     */
+    private static void buildEquality( AttributeType attributeType, List<Throwable> errors, Registries registries )
+    {
+        String equalityOid = attributeType.getEqualityOid();
+        
+        // The equality MR. It can be null
+        if ( equalityOid != null )
+        {
+            MatchingRule currentEquality = null;
+
+            try
+            {
+                currentEquality = registries.getMatchingRuleRegistry().lookup( equalityOid );
+            }
+            catch ( LdapException ne )
+            {
+                // Not allowed.
+                String msg = I18n.err( I18n.ERR_04308, equalityOid, attributeType.getName() );
+
+                LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                    LdapSchemaExceptionCodes.AT_NONEXISTENT_EQUALITY_MATCHING_RULE, msg, ne );
+                ldapSchemaException.setSourceObject( attributeType );
+                ldapSchemaException.setRelatedId( equalityOid );
+                errors.add( ldapSchemaException );
+                LOG.info( msg );
+                
+                return;
+            }
+
+            if ( currentEquality != null )
+            {
+                attributeType.setEquality( currentEquality );
+                
+                // Restore the old equality OID to preserve the user's provided value
+                attributeType.setEqualityOid( equalityOid );
+            }
+            else
+            {
+                // Not allowed.
+                String msg = I18n.err( I18n.ERR_04309, equalityOid, attributeType.getName() );
+
+                LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                    LdapSchemaExceptionCodes.AT_NONEXISTENT_EQUALITY_MATCHING_RULE, msg );
+                ldapSchemaException.setSourceObject( attributeType );
+                ldapSchemaException.setRelatedId( equalityOid );
+                errors.add( ldapSchemaException );
+                LOG.info( msg );
+            }
+        }
+        else
+        {
+            AttributeType superior = attributeType.getSuperior();
+            
+            // If the AT has a superior, take its Equality MR if any
+            if ( ( superior != null ) && ( superior.getEquality() != null ) )
+            {
+                attributeType.setEquality( superior.getEquality() );
+            }
+        }
+    }
+
+
+    /**
+     * Build the SUBSTR MR reference for an AttributeType
+     */
+    private static void buildSubstring( AttributeType attributeType, List<Throwable> errors, Registries registries )
+    {
+        String substringOid = attributeType.getSubstringOid();
+        
+        // The Substring MR. It can be null
+        if ( substringOid != null )
+        {
+            MatchingRule currentSubstring = null;
+
+            try
+            {
+                currentSubstring = registries.getMatchingRuleRegistry().lookup( substringOid );
+            }
+            catch ( LdapException ne )
+            {
+                // Not allowed.
+                String msg = I18n.err( I18n.ERR_04312, substringOid, attributeType.getName() );
+
+                LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                    LdapSchemaExceptionCodes.AT_NONEXISTENT_SUBSTRING_MATCHING_RULE, msg, ne );
+                ldapSchemaException.setSourceObject( attributeType );
+                ldapSchemaException.setRelatedId( substringOid );
+                errors.add( ldapSchemaException );
+                LOG.info( msg );
+                
+                return;
+            }
+
+            if ( currentSubstring != null )
+            {
+                attributeType.setSubstring( currentSubstring );
+            }
+            else
+            {
+                // Not allowed.
+                String msg = I18n.err( I18n.ERR_04313, substringOid, attributeType.getName() );
+
+                LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                    LdapSchemaExceptionCodes.AT_NONEXISTENT_SUBSTRING_MATCHING_RULE, msg );
+                ldapSchemaException.setSourceObject( attributeType );
+                ldapSchemaException.setRelatedId( substringOid );
+                errors.add( ldapSchemaException );
+                LOG.info( msg );
+                
+                return;
+            }
+        }
+        else
+        {
+            AttributeType superior = attributeType.getSuperior();
+            
+            // If the AT has a superior, take its Substring MR if any
+            if ( ( superior != null ) && ( superior.getSubstring() != null ) )
+            {
+                attributeType.setSubstring( superior.getSubstring() );
+            }
+        }
+    }
+    
+    
+
+
+
+
+    /**
+     * Build the ORDERING MR reference for an AttributeType
+     */
+    private static void buildOrdering( AttributeType attributeType, List<Throwable> errors, Registries registries )
+    {
+        String orderingOid = attributeType.getOrderingOid();
+        
+        if ( orderingOid != null )
+        {
+            MatchingRule currentOrdering = null;
+
+            try
+            {
+                currentOrdering = registries.getMatchingRuleRegistry().lookup( orderingOid );
+            }
+            catch ( LdapException ne )
+            {
+                // Not allowed.
+                String msg = I18n.err( I18n.ERR_04310, orderingOid, attributeType.getName() );
+
+                LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                    LdapSchemaExceptionCodes.AT_NONEXISTENT_ORDERING_MATCHING_RULE, msg, ne );
+                ldapSchemaException.setSourceObject( attributeType );
+                ldapSchemaException.setRelatedId( orderingOid );
+                errors.add( ldapSchemaException );
+                LOG.info( msg );
+                
+                return;
+            }
+
+            if ( currentOrdering != null )
+            {
+                attributeType.setOrdering( currentOrdering );
+            }
+            else
+            {
+                // Not allowed.
+                String msg = I18n.err( I18n.ERR_04311, orderingOid, attributeType.getName() );
+
+                LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                    LdapSchemaExceptionCodes.AT_NONEXISTENT_ORDERING_MATCHING_RULE, msg );
+                ldapSchemaException.setSourceObject( attributeType );
+                ldapSchemaException.setRelatedId( orderingOid );
+                errors.add( ldapSchemaException );
+                LOG.info( msg );
+            }
+        }
+        else
+        {
+            AttributeType superior = attributeType.getSuperior();
+            
+            // If the AT has a superior, take its Ordering MR if any
+            if ( ( superior != null ) && ( superior.getOrdering() != null ) )
+            {
+                attributeType.setOrdering( superior.getOrdering() );
+            }
+        }
+    }
+
+    
+    /**
+     * Check the constraints for the Usage field.
+     */
+    private static void checkUsage( AttributeType attributeType, List<Throwable> errors )
+    {
+        AttributeType superior = attributeType.getSuperior();
+        
+        // Check that the AT usage is the same that its superior
+        if ( ( superior != null ) && ( attributeType.getUsage() != superior.getUsage() ) )
+        {
+            // This is an error
+            String msg = I18n.err( I18n.ERR_04314, attributeType.getName() );
+
+            LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                LdapSchemaExceptionCodes.AT_MUST_HAVE_SAME_USAGE_THAN_SUPERIOR, msg );
+            ldapSchemaException.setSourceObject( attributeType );
+            errors.add( ldapSchemaException );
+            LOG.info( msg );
+            
+            return;
+        }
+
+        // Now, check that the AttributeType's USAGE does not conflict
+        if ( !attributeType.isUserModifiable() && ( attributeType.getUsage() == UsageEnum.USER_APPLICATIONS ) )
+        {
+            // Cannot have a not user modifiable AT which is not an operational AT
+            String msg = I18n.err( I18n.ERR_04315, attributeType.getName() );
+
+            LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                LdapSchemaExceptionCodes.AT_USER_APPLICATIONS_USAGE_MUST_BE_USER_MODIFIABLE, msg );
+            ldapSchemaException.setSourceObject( attributeType );
+            errors.add( ldapSchemaException );
+            LOG.info( msg );
+        }
+    }
+
+
+    /**
+     * Check the constraints for the Collective field.
+     */
+    private static void checkCollective( AttributeType attributeType, List<Throwable> errors )
+    {
+        AttributeType superior = attributeType.getSuperior();
+
+        if ( ( superior != null ) && superior.isCollective() )
+        {
+            // An AttributeType will be collective if its superior is collective
+            attributeType.setCollective( true );
+        }
+
+        if ( attributeType.isCollective() && ( attributeType.getUsage() != UsageEnum.USER_APPLICATIONS ) )
+        {
+            // An AttributeType which is collective must be a USER attributeType
+            String msg = I18n.err( I18n.ERR_04316, attributeType.getName() );
+
+            LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                LdapSchemaExceptionCodes.AT_COLLECTIVE_MUST_HAVE_USER_APPLICATIONS_USAGE, msg );
+            ldapSchemaException.setSourceObject( attributeType );
+            errors.add( ldapSchemaException );
+            LOG.info( msg );
+        }
+
+        if ( attributeType.isCollective() && attributeType.isSingleValued() )
+        {
+            // A collective attribute must be multi-valued
+            String msg = I18n.err( I18n.ERR_04483_COLLECTIVE_NOT_MULTI_VALUED, attributeType.getName() );
+
+            LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                LdapSchemaExceptionCodes.AT_COLLECTIVE_CANNOT_BE_SINGLE_VALUED, msg );
+            ldapSchemaException.setSourceObject( attributeType );
+            errors.add( ldapSchemaException );
+            LOG.info( msg );
+        }
+    }
+}

Added: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/registries/helper/ObjectClassHelper.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/registries/helper/ObjectClassHelper.java?rev=1244561&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/registries/helper/ObjectClassHelper.java (added)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/registries/helper/ObjectClassHelper.java Wed Feb 15 16:11:17 2012
@@ -0,0 +1,350 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.directory.shared.ldap.model.schema.registries.helper;
+
+import java.util.List;
+
+import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.exception.LdapSchemaException;
+import org.apache.directory.shared.ldap.model.exception.LdapSchemaExceptionCodes;
+import org.apache.directory.shared.ldap.model.schema.AttributeType;
+import org.apache.directory.shared.ldap.model.schema.ObjectClass;
+import org.apache.directory.shared.ldap.model.schema.ObjectClassTypeEnum;
+import org.apache.directory.shared.ldap.model.schema.registries.AttributeTypeRegistry;
+import org.apache.directory.shared.ldap.model.schema.registries.ObjectClassRegistry;
+import org.apache.directory.shared.ldap.model.schema.registries.Registries;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * An helper class used to store all the methods associated with an ObjectClass
+ * in relation with the Registries and SchemaManager.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ObjectClassHelper
+{
+    /** A logger for this class */
+    private static final Logger LOG = LoggerFactory.getLogger( ObjectClassHelper.class );
+
+    /**
+     * Inject the ObjectClass into the registries, updating the references to
+     * other SchemaObject
+     *
+     * @param errors The errors we got while adding the ObjectClass to the registries
+     * @param registries The Registries
+     * @throws Exception on failure
+     */
+    public static void addToRegistries( ObjectClass objectClass, List<Throwable> errors, Registries registries ) throws LdapException
+    {
+        if ( registries != null )
+        {
+            try
+            {
+                objectClass.unlock();
+                
+                // The superiors
+                buildSuperiors( objectClass, errors, registries );
+    
+                // The MAY AttributeTypes
+                buildMay( objectClass, errors, registries );
+    
+                // The MUST AttributeTypes
+                buildMust( objectClass, errors, registries );
+    
+                /**
+                 * Add the OC references (using and usedBy) :
+                 * OC -> AT (MAY and MUST)
+                 * OC -> OC (SUPERIORS)
+                 */
+                for ( AttributeType mayAttributeType : objectClass.getMayAttributeTypes() )
+                {
+                    registries.addReference( objectClass, mayAttributeType );
+                }
+    
+                for ( AttributeType mustAttributeType : objectClass.getMustAttributeTypes() )
+                {
+                    registries.addReference( objectClass, mustAttributeType );
+                }
+    
+                for ( ObjectClass superiorObjectClass : objectClass.getSuperiors() )
+                {
+                    registries.addReference( objectClass, superiorObjectClass );
+                }
+            }
+            finally
+            {
+                objectClass.lock();
+            }
+        }
+    }
+
+
+    /**
+     * Build the references to this ObjectClass SUPERIORS, checking that the type
+     * hierarchy is correct.
+     */
+    private static void buildSuperiors( ObjectClass objectClass, List<Throwable> errors, Registries registries )
+    {
+        ObjectClassRegistry ocRegistry = registries.getObjectClassRegistry();
+        List<String> superiorOids = objectClass.getSuperiorOids();
+
+        if ( superiorOids != null )
+        {
+            objectClass.getSuperiors().clear();
+
+            for ( String superiorName : superiorOids )
+            {
+                try
+                {
+                    ObjectClass superior = ocRegistry.lookup( ocRegistry.getOidByName( superiorName ) );
+
+                    // Before adding the superior, check that the ObjectClass type is consistent
+                    switch ( objectClass.getType() )
+                    {
+                        case ABSTRACT:
+                            if ( superior.getType() != ObjectClassTypeEnum.ABSTRACT )
+                            {
+                                // An ABSTRACT OC can only inherit from ABSTRACT OCs
+                                String msg = I18n.err( I18n.ERR_04318, objectClass.getOid(), superior.getObjectType(), superior );
+
+                                LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                                    LdapSchemaExceptionCodes.OC_ABSTRACT_MUST_INHERIT_FROM_ABSTRACT_OC, msg );
+                                ldapSchemaException.setSourceObject( objectClass );
+                                errors.add( ldapSchemaException );
+                                LOG.info( msg );
+
+                                continue;
+                            }
+
+                            break;
+
+                        case AUXILIARY:
+                            if ( superior.getType() == ObjectClassTypeEnum.STRUCTURAL )
+                            {
+                                // An AUXILIARY OC cannot inherit from STRUCTURAL OCs
+                                String msg = I18n.err( I18n.ERR_04319, objectClass.getOid(), superior );
+
+                                LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                                    LdapSchemaExceptionCodes.OC_AUXILIARY_CANNOT_INHERIT_FROM_STRUCTURAL_OC, msg );
+                                ldapSchemaException.setSourceObject( objectClass );
+                                errors.add( ldapSchemaException );
+                                LOG.info( msg );
+
+                                continue;
+                            }
+
+                            break;
+
+                        case STRUCTURAL:
+                            if ( superior.getType() == ObjectClassTypeEnum.AUXILIARY )
+                            {
+                                // A STRUCTURAL OC cannot inherit from AUXILIARY OCs
+                                String msg = I18n.err( I18n.ERR_04320, objectClass.getOid(), superior );
+
+                                LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                                    LdapSchemaExceptionCodes.OC_STRUCTURAL_CANNOT_INHERIT_FROM_AUXILIARY_OC, msg );
+                                ldapSchemaException.setSourceObject( objectClass );
+                                errors.add( ldapSchemaException );
+                                LOG.info( msg );
+
+                                continue;
+                            }
+
+                            break;
+                    }
+
+                    objectClass.getSuperiors().add( superior );
+                }
+                catch ( LdapException ne )
+                {
+                    // Cannot find the OC
+                    String msg = I18n.err( I18n.ERR_04321, objectClass.getOid(), superiorName );
+
+                    LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                        LdapSchemaExceptionCodes.OC_NONEXISTENT_SUPERIOR, msg, ne );
+                    ldapSchemaException.setSourceObject( objectClass );
+                    ldapSchemaException.setRelatedId( superiorName );
+                    errors.add( ldapSchemaException );
+                    LOG.info( msg );
+
+                    return;
+                }
+            }
+        }
+    }
+
+
+    /**
+     * Build and check the MUST AT for this ObjectClass.
+     */
+    private static void buildMust( ObjectClass objectClass, List<Throwable> errors, Registries registries )
+    {
+        AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry();
+        List<String> mustAttributeTypeOids = objectClass.getMustAttributeTypeOids();
+
+        if ( mustAttributeTypeOids != null )
+        {
+            objectClass.getMustAttributeTypes().clear();
+
+            for ( String mustAttributeTypeName : mustAttributeTypeOids )
+            {
+                try
+                {
+                    AttributeType attributeType = atRegistry.lookup( mustAttributeTypeName );
+
+                    if ( attributeType.isCollective() )
+                    {
+                        // Collective Attributes are not allowed in MAY or MUST
+                        String msg = I18n.err( I18n.ERR_04484_COLLECTIVE_NOT_ALLOWED_IN_MUST, mustAttributeTypeName,
+                            objectClass.getOid() );
+
+                        LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                            LdapSchemaExceptionCodes.OC_COLLECTIVE_NOT_ALLOWED_IN_MUST, msg );
+                        ldapSchemaException.setSourceObject( objectClass );
+                        ldapSchemaException.setRelatedId( mustAttributeTypeName );
+                        errors.add( ldapSchemaException );
+                        LOG.info( msg );
+
+                        break;
+                    }
+
+                    if ( objectClass.getMustAttributeTypes().contains( attributeType ) )
+                    {
+                        // Already registered : this is an error
+                        String msg = I18n.err( I18n.ERR_04324, objectClass.getOid(), mustAttributeTypeName );
+
+                        LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                            LdapSchemaExceptionCodes.OC_DUPLICATE_AT_IN_MUST, msg );
+                        ldapSchemaException.setSourceObject( objectClass );
+                        ldapSchemaException.setRelatedId( mustAttributeTypeName );
+                        errors.add( ldapSchemaException );
+                        LOG.info( msg );
+
+                        break;
+                    }
+
+                    // Check that the MUST AT is not also present in the MAY AT
+                    if ( objectClass.getMayAttributeTypes().contains( attributeType ) )
+                    {
+                        // Already registered : this is an error
+                        String msg = I18n.err( I18n.ERR_04325, objectClass.getOid(), mustAttributeTypeName );
+
+                        LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                            LdapSchemaExceptionCodes.OC_DUPLICATE_AT_IN_MAY_AND_MUST,
+                            msg );
+                        ldapSchemaException.setSourceObject( objectClass );
+                        ldapSchemaException.setRelatedId( mustAttributeTypeName );
+                        errors.add( ldapSchemaException );
+                        LOG.info( msg );
+
+                        break;
+                    }
+
+                    objectClass.getMustAttributeTypes().add( attributeType );
+                }
+                catch ( LdapException ne )
+                {
+                    // Cannot find the AT
+                    String msg = I18n.err( I18n.ERR_04326, objectClass.getOid(), mustAttributeTypeName );
+
+                    LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                        LdapSchemaExceptionCodes.OC_NONEXISTENT_MUST_AT, msg, ne );
+                    ldapSchemaException.setSourceObject( objectClass );
+                    ldapSchemaException.setRelatedId( mustAttributeTypeName );
+                    errors.add( ldapSchemaException );
+                    LOG.info( msg );
+
+                    break;
+                }
+            }
+        }
+    }
+    
+    
+    /**
+     * Build and check the MAY AT for this ObjectClass
+     */
+    private static void buildMay( ObjectClass objectClass, List<Throwable> errors, Registries registries )
+    {
+        AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry();
+        List<String> mayAttributeTypeOids = objectClass.getMayAttributeTypeOids();
+
+        if ( mayAttributeTypeOids != null )
+        {
+            objectClass.getMayAttributeTypes().clear();
+
+            for ( String mayAttributeTypeName : mayAttributeTypeOids )
+            {
+                try
+                {
+                    AttributeType attributeType = atRegistry.lookup( mayAttributeTypeName );
+
+                    if ( attributeType.isCollective() )
+                    {
+                        // Collective Attributes are not allowed in MAY or MUST
+                        String msg = I18n.err( I18n.ERR_04485_COLLECTIVE_NOT_ALLOWED_IN_MAY, mayAttributeTypeName, objectClass.getOid() );
+
+                        LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                            LdapSchemaExceptionCodes.OC_COLLECTIVE_NOT_ALLOWED_IN_MAY, msg );
+                        ldapSchemaException.setSourceObject( objectClass );
+                        ldapSchemaException.setRelatedId( mayAttributeTypeName );
+                        errors.add( ldapSchemaException );
+                        LOG.info( msg );
+
+                        break;
+                    }
+
+                    if ( objectClass.getMayAttributeTypes().contains( attributeType ) )
+                    {
+                        // Already registered : this is an error
+                        String msg = I18n.err( I18n.ERR_04322, objectClass.getOid(), mayAttributeTypeName );
+
+                        LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                            LdapSchemaExceptionCodes.OC_DUPLICATE_AT_IN_MAY, msg );
+                        ldapSchemaException.setSourceObject( objectClass );
+                        ldapSchemaException.setRelatedId( mayAttributeTypeName );
+                        errors.add( ldapSchemaException );
+                        LOG.info( msg );
+
+                        break;
+                    }
+
+                    objectClass.getMayAttributeTypes().add( attributeType );
+                }
+                catch ( LdapException ne )
+                {
+                    // Cannot find the AT
+                    String msg = I18n.err( I18n.ERR_04323, objectClass.getOid(), mayAttributeTypeName );
+
+                    LdapSchemaException ldapSchemaException = new LdapSchemaException(
+                        LdapSchemaExceptionCodes.OC_NONEXISTENT_MAY_AT, msg, ne );
+                    ldapSchemaException.setSourceObject( objectClass );
+                    ldapSchemaException.setRelatedId( mayAttributeTypeName );
+                    errors.add( ldapSchemaException );
+                    LOG.info( msg );
+
+                    break;
+                }
+            }
+        }
+    }
+}

Modified: directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/shared/ldap/schemamanager/impl/DefaultSchemaManager.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/shared/ldap/schemamanager/impl/DefaultSchemaManager.java?rev=1244561&r1=1244560&r2=1244561&view=diff
==============================================================================
--- directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/shared/ldap/schemamanager/impl/DefaultSchemaManager.java (original)
+++ directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/shared/ldap/schemamanager/impl/DefaultSchemaManager.java Wed Feb 15 16:11:17 2012
@@ -83,7 +83,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.schemaloader.JarLdifSchemaLoader;
 import org.apache.directory.shared.ldap.schemaloader.SchemaEntityFactory;
 import org.apache.directory.shared.util.Strings;
-import org.apache.directory.shared.util.exception.NotImplementedException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

Modified: directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/shared/ldap/schemaloader/SchemaManagerAddTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/shared/ldap/schemaloader/SchemaManagerAddTest.java?rev=1244561&r1=1244560&r2=1244561&view=diff
==============================================================================
--- directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/shared/ldap/schemaloader/SchemaManagerAddTest.java (original)
+++ directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/shared/ldap/schemaloader/SchemaManagerAddTest.java Wed Feb 15 16:11:17 2012
@@ -612,7 +612,7 @@ public class SchemaManagerAddTest
 
         // Check that it hasen't changed
         AttributeType original = schemaManager.lookupAttributeTypeRegistry( "2.5.18.4" );
-        assertEquals( "distinguishedNameMatch", original.getEquality().getName() );
+        assertEquals( "distinguishedNameMatch", original.getEqualityOid() );
         assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
         assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
     }



Mime
View raw message