directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ersi...@apache.org
Subject svn commit: r432086 - /directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
Date Thu, 17 Aug 2006 00:49:14 GMT
Author: ersiner
Date: Wed Aug 16 17:49:14 2006
New Revision: 432086

URL: http://svn.apache.org/viewvc?rev=432086&view=rev
Log:
Fix for DIRSERVER-614

Modified:
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java?rev=432086&r1=432085&r2=432086&view=diff
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
(original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
Wed Aug 16 17:49:14 2006
@@ -654,6 +654,8 @@
 
         NamingEnumeration changes = mods.getIDs();
         
+        Attributes tmpEntryForAdd = (Attributes)entry.clone();
+        
         while ( changes.hasMore() )
         {
             String id = ( String ) changes.next();
@@ -663,6 +665,11 @@
             {
                 throw new LdapInvalidAttributeIdentifierException( "unrecognized attributeID
" + change.getID() );
             }
+            
+            if ( modOp == DirContext.ADD_ATTRIBUTE )
+            {
+                tmpEntryForAdd.put( change );
+            }
 
             if ( modOp == DirContext.REMOVE_ATTRIBUTE && entry.get( change.getID()
) == null )
             {
@@ -678,6 +685,11 @@
             }
         }
 
+        if ( modOp == DirContext.ADD_ATTRIBUTE )
+        {
+            assertNumberOfAttributeValuesValid( tmpEntryForAdd );
+        }
+        
         if ( modOp == DirContext.REMOVE_ATTRIBUTE )
         {
             SchemaChecker.preventRdnChangeOnModifyRemove( name, modOp, mods );
@@ -688,6 +700,7 @@
         {
             SchemaChecker.preventRdnChangeOnModifyReplace( name, modOp, mods );
             SchemaChecker.preventStructuralClassRemovalOnModifyReplace( ocRegistry, name,
modOp, mods );
+            assertNumberOfAttributeValuesValid( mods );
         }
 
         // let's figure out if we need to add or take away from mods to maintain 
@@ -882,10 +895,7 @@
                     {
                         tmpEntry.remove( change.getID() );
                     }
-                    else
-                    {
-                        attr = new LockableAttributeImpl( change.getID() );
-                    }
+                    attr = new LockableAttributeImpl( change.getID() );
                     
                     NamingEnumeration values = change.getAll();
                     
@@ -951,6 +961,8 @@
                 }
             }
         }
+        
+        assertNumberOfAttributeValuesValid( tmpEntry );
 
         next.modify( name, mods );
     }
@@ -1086,10 +1098,39 @@
 
         alterObjectClasses( attrs.get( "objectClass" ), this.globalRegistries.getObjectClassRegistry()
);
         assertRequiredAttributesPresent( attrs );
+        assertNumberOfAttributeValuesValid( attrs );
         next.add(normName, attrs );
     }
     
     
+    /**
+     * Checks to see number of values of an attribute conforms to the schema
+     */
+    private void assertNumberOfAttributeValuesValid( Attributes attributes ) throws InvalidAttributeValueException,
NamingException
+    {
+        NamingEnumeration list = attributes.getAll();
+        
+        while ( list.hasMore() )
+        {
+            Attribute attribute = ( Attribute ) list.next();
+            assertNumberOfAttributeValuesValid( attribute );
+        }
+    }
+    
+    /**
+     * Checks to see numbers of values of attributes conforms to the schema
+     */
+    private void assertNumberOfAttributeValuesValid( Attribute attribute ) throws InvalidAttributeValueException,
NamingException
+    {
+        AttributeTypeRegistry registry = this.globalRegistries.getAttributeTypeRegistry();
+
+        if ( attribute.size() > 1 && registry.lookup( attribute.getID() ).isSingleValue()
)
+        {                
+            throw new InvalidAttributeValueException( "More than one value has been provided
" +
+                "for the single-valued attribute: " + attribute.getID() );
+        }
+    }
+
     /**
      * Checks to see the presence of all required attributes within an entry.
      */



Mime
View raw message