You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by er...@apache.org on 2006/08/17 02:44:26 UTC
svn commit: r432083 -
/directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
Author: ersiner
Date: Wed Aug 16 17:44:26 2006
New Revision: 432083
URL: http://svn.apache.org/viewvc?rev=432083&view=rev
Log:
Fix for DIRSERVER-614
Modified:
directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
Modified: directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java?rev=432083&r1=432082&r2=432083&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java (original)
+++ directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java Wed Aug 16 17:44:26 2006
@@ -653,6 +653,8 @@
NamingEnumeration changes = mods.getIDs();
+ Attributes tmpEntryForAdd = (Attributes)entry.clone();
+
while ( changes.hasMore() )
{
String id = ( String ) changes.next();
@@ -662,6 +664,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 )
{
@@ -677,6 +684,11 @@
}
}
+ if ( modOp == DirContext.ADD_ATTRIBUTE )
+ {
+ assertNumberOfAttributeValuesValid( tmpEntryForAdd );
+ }
+
if ( modOp == DirContext.REMOVE_ATTRIBUTE )
{
SchemaChecker.preventRdnChangeOnModifyRemove( name, modOp, mods );
@@ -687,6 +699,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
@@ -881,10 +894,7 @@
{
tmpEntry.remove( change.getID() );
}
- else
- {
- attr = new LockableAttributeImpl( change.getID() );
- }
+ attr = new LockableAttributeImpl( change.getID() );
NamingEnumeration values = change.getAll();
@@ -950,6 +960,8 @@
}
}
}
+
+ assertNumberOfAttributeValuesValid( tmpEntry );
next.modify( name, mods );
}
@@ -1085,10 +1097,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.
*/