directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r938123 - in /directory/shared/trunk: i18n/src/main/java/org/apache/directory/shared/i18n/ i18n/src/main/resources/org/apache/directory/shared/i18n/ ldap/src/main/java/org/apache/directory/shared/ldap/entry/ ldap/src/main/java/org/apache/di...
Date Mon, 26 Apr 2010 16:57:06 GMT
Author: elecharny
Date: Mon Apr 26 16:57:06 2010
New Revision: 938123

URL: http://svn.apache.org/viewvc?rev=938123&view=rev
Log:
o Added some more error messages
o Started to move the remove() operations from Server to Client Entry

Modified:
    directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java
    directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultServerEntry.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/ServerEntry.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntry.java

Modified: directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java?rev=938123&r1=938122&r2=938123&view=diff
==============================================================================
--- directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java (original)
+++ directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java Mon
Apr 26 16:57:06 2010
@@ -599,10 +599,10 @@ public class I18n
     public static final String ERR_04454 = "ERR_04454";
     public static final String ERR_04455 = "ERR_04455";
     public static final String ERR_04456 = "ERR_04456";
-    public static final String ERR_04457 = "ERR_04457";
+    public static final String ERR_04457_NULL_ATTRIBUTE_ID = "ERR_04457_NULL_ATTRIBUTE_ID";
     public static final String ERR_04458 = "ERR_04458";
     public static final String ERR_04459 = "ERR_04459";
-    public static final String ERR_04460 = "ERR_04460";
+    public static final String ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED = "ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED";
     public static final String ERR_04461 = "ERR_04461";
     public static final String ERR_04462 = "ERR_04462";
     public static final String ERR_04463 = "ERR_04463";
@@ -619,6 +619,7 @@ public class I18n
     public static final String ERR_04474 = "ERR_04474";
     public static final String ERR_04475 = "ERR_04475";
     public static final String ERR_04476 = "ERR_04476";
+    public static final String ERR_04477_NO_VALID_AT_FOR_THIS_ID = "ERR_04477_NO_VALID_AT_FOR_THIS_ID";
 
 	// ldap-constants
 	public static final String ERR_05001 = "ERR_05001";

Modified: directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties
URL: http://svn.apache.org/viewvc/directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties?rev=938123&r1=938122&r2=938123&view=diff
==============================================================================
--- directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties
(original)
+++ directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties
Mon Apr 26 16:57:06 2010
@@ -558,12 +558,12 @@ ERR_04453=The upID ({0}) is not an OID o
 ERR_04454=Cannot use standard serialization for a ServerAttribute
 ERR_04455=The ID ''{0}''is incompatible with the AttributeType's id ''{1}''
 ERR_04456=An ID cannnot be null, empty, or resolved to an emtpy value when trimmed
-ERR_04457=The ID should not be null or empty
+ERR_04457_NULL_ATTRIBUTE_ID=The ID should not be null or empty
 ERR_04458=Cannot add an attribute without an ID
 ERR_04459=We have had an error while adding the ''{0}'' AttributeType : {1}
-ERR_04460=The attributeType should not be null
+ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED=The attributeType should not be null
 ERR_04461=Only String values supported for objectClass attribute
-ERR_04462=The ServerAttribute list should not contain null elements
+ERR_04462=The EntryAttribute list should not contain null elements
 ERR_04463=The ''{0}'' id is not compatible with the ''{1}'' attribute type
 ERR_04464=Error while adding values into the ''{0}'' attribute. Error \: {1} 
 ERR_04465=The removal of values for the missing ''{0}'' attribute is not possible
@@ -578,6 +578,7 @@ ERR_04473=Not a valid value
 ERR_04474=Expected string to normalize
 ERR_04475=Expected byte[] to normalize
 ERR_04476=Cannot set an AttributeType {0} when another one ({1}) is already present
+ERR_04477_NO_VALID_AT_FOR_THIS_ID=Cannot find a valid AttributeType for the ''{0}'' id
 
 # ldap-constants
 ERR_05001=Unknown AuthenticationLevel {0}

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultServerEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultServerEntry.java?rev=938123&r1=938122&r2=938123&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultServerEntry.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultServerEntry.java
Mon Apr 26 16:57:06 2010
@@ -457,233 +457,6 @@ public final class DefaultServerEntry ex
      * <code>false</code>
      * </p> 
      *
-     * @param attributeType The attribute type  
-     * @param values the values to be removed
-     * @return <code>true</code> if at least a value is removed, <code>false</code>
-     * if not all the values have been removed or if the attribute does not exist. 
-     */
-    public boolean remove( AttributeType attributeType, byte[]... values ) throws LdapException
-    {
-        if ( attributeType == null )
-        {
-            return false;
-        }
-        
-        try
-        {
-            EntryAttribute attribute = attributes.get( attributeType.getOid() );
-            
-            if ( attribute == null )
-            {
-                // Can't remove values from a not existing attribute !
-                return false;
-            }
-            
-            int nbOldValues = attribute.size();
-            
-            // Remove the values
-            attribute.remove( values );
-            
-            if ( attribute.size() == 0 )
-            {
-                // No mare values, remove the attribute
-                attributes.remove( attributeType.getOid() );
-                
-                return true;
-            }
-            
-            if ( nbOldValues != attribute.size() )
-            {
-                // At least one value have been removed, return true.
-                return true;
-            }
-            else
-            {
-                // No values have been removed, return false.
-                return false;
-            }
-        }
-        catch ( IllegalArgumentException iae )
-        {
-            LOG.error( I18n.err( I18n.ERR_04465, attributeType ) );
-            return false;
-        }
-    }
-    
-    
-    /**
-     * <p>
-     * Removes the specified String values from an attribute.
-     * </p>
-     * <p>
-     * If at least one value is removed, this method returns <code>true</code>.
-     * </p>
-     * <p>
-     * If there is no more value after having removed the values, the attribute
-     * will be removed too.
-     * </p>
-     * <p>
-     * If the attribute does not exist, nothing is done and the method returns 
-     * <code>false</code>
-     * </p> 
-     *
-     * @param attributeType The attribute type  
-     * @param values the values to be removed
-     * @return <code>true</code> if at least a value is removed, <code>false</code>
-     * if not all the values have been removed or if the attribute does not exist. 
-     */
-    public boolean remove( AttributeType attributeType, String... values ) throws LdapException
-    {
-        if ( attributeType == null )
-        {
-            return false;
-        }
-        
-        try
-        {
-            EntryAttribute attribute = attributes.get( attributeType.getOid() );
-            
-            if ( attribute == null )
-            {
-                // Can't remove values from a not existing attribute !
-                return false;
-            }
-            
-            int nbOldValues = attribute.size();
-            
-            // Remove the values
-            attribute.remove( values );
-            
-            if ( attribute.size() == 0 )
-            {
-                // No mare values, remove the attribute
-                attributes.remove( attributeType.getOid() );
-                
-                return true;
-            }
-            
-            if ( nbOldValues != attribute.size() )
-            {
-                // At least one value have been removed, return true.
-                return true;
-            }
-            else
-            {
-                // No values have been removed, return false.
-                return false;
-            }
-        }
-        catch ( IllegalArgumentException iae )
-        {
-            LOG.error( I18n.err( I18n.ERR_04465, attributeType ) );
-            return false;
-        }
-    }
-    
-    
-    /**
-     * <p>
-     * Removes the specified values from an attribute.
-     * </p>
-     * <p>
-     * If at least one value is removed, this method returns <code>true</code>.
-     * </p>
-     * <p>
-     * If there is no more value after having removed the values, the attribute
-     * will be removed too.
-     * </p>
-     * <p>
-     * If the attribute does not exist, nothing is done and the method returns 
-     * <code>false</code>
-     * </p> 
-     *
-     * @param attributeType The attribute type  
-     * @param values the values to be removed
-     * @return <code>true</code> if at least a value is removed, <code>false</code>
-     * if not all the values have been removed or if the attribute does not exist. 
-     */
-    public boolean remove( AttributeType attributeType, Value<?>... values ) throws
LdapException
-    {
-        if ( attributeType == null )
-        {
-            return false;
-        }
-        
-        try
-        {
-            EntryAttribute attribute = attributes.get( attributeType.getOid() );
-            
-            if ( attribute == null )
-            {
-                // Can't remove values from a not existing attribute !
-                return false;
-            }
-            
-            int nbOldValues = attribute.size();
-            
-            // Remove the values
-            attribute.remove( values );
-            
-            if ( attribute.size() == 0 )
-            {
-                // No mare values, remove the attribute
-                attributes.remove( attributeType.getOid() );
-                
-                return true;
-            }
-            
-            if ( nbOldValues != attribute.size() )
-            {
-                // At least one value have been removed, return true.
-                return true;
-            }
-            else
-            {
-                // No values have been removed, return false.
-                return false;
-            }
-        }
-        catch ( IllegalArgumentException iae )
-        {
-            LOG.error( I18n.err( I18n.ERR_04465, attributeType ) );
-            return false;
-        }
-    }
-    
-    
-    public List<EntryAttribute> remove( EntryAttribute... attributes ) throws LdapException
-    {
-        List<EntryAttribute> removedAttributes = new ArrayList<EntryAttribute>();
-        
-        for ( EntryAttribute serverAttribute:attributes )
-        {
-            if ( this.attributes.containsKey( ((EntryAttribute)serverAttribute).getAttributeType().getOid()
) )
-            {
-                this.attributes.remove( ((EntryAttribute)serverAttribute).getAttributeType().getOid()
);
-                removedAttributes.add( serverAttribute );
-            }
-        }
-        
-        return removedAttributes;
-    }
-
-
-    /**
-     * <p>
-     * Removes the specified binary values from an attribute.
-     * </p>
-     * <p>
-     * If at least one value is removed, this method returns <code>true</code>.
-     * </p>
-     * <p>
-     * If there is no more value after having removed the values, the attribute
-     * will be removed too.
-     * </p>
-     * <p>
-     * If the attribute does not exist, nothing is done and the method returns 
-     * <code>false</code>
-     * </p> 
-     *
      * @param upId The attribute ID 
      * @param values the values to be removed
      * @return <code>true</code> if at least a value is removed, <code>false</code>
@@ -796,114 +569,6 @@ public final class DefaultServerEntry ex
     
     /**
      * <p>
-     * Removes the attribute with the specified AttributeTypes. 
-     * </p>
-     * <p>
-     * The removed attribute are returned by this method. 
-     * </p>
-     * <p>
-     * If there is no attribute with the specified AttributeTypes,
-     * the return value is <code>null</code>.
-     * </p>
-     *
-     * @param attributes the AttributeTypes to be removed
-     * @return the removed attributes, if any, as a list; otherwise <code>null</code>
-     */
-    public List<EntryAttribute> removeAttributes( AttributeType... attributes )
-    {
-        if ( ( attributes == null ) || ( attributes.length == 0 ) )
-        {
-            return null;
-        }
-        
-        List<EntryAttribute> removed = new ArrayList<EntryAttribute>( attributes.length
);
-        
-        for ( AttributeType attributeType:attributes )
-        {
-            if ( attributeType == null )
-            {
-                continue;
-            }
-            
-            EntryAttribute attr = this.attributes.remove( attributeType.getOid() );
-            
-            if ( attr != null )
-            {
-                removed.add( attr );
-            }
-        }
-        
-        if ( removed.size() == 0 )
-        {
-            return null;
-        }
-        else
-        {
-            return removed;
-        }
-    }
-    
-    
-    /**
-     * <p>
-     * Removes the attribute with the specified alias. 
-     * </p>
-     * <p>
-     * The removed attribute are returned by this method. 
-     * </p>
-     * <p>
-     * If there is no attribute with the specified alias,
-     * the return value is <code>null</code>.
-     * </p>
-     *
-     * @param attributes an aliased name of the attribute to be removed
-     * @return the removed attributes, if any, as a list; otherwise <code>null</code>
-     */
-    public List<EntryAttribute> removeAttributes( String... attributes )
-    {
-        if ( attributes.length == 0 )
-        {
-            return null;
-        }
-        
-        List<EntryAttribute> removed = new ArrayList<EntryAttribute>( attributes.length
);
-        
-        for ( String attribute:attributes )
-        {
-            AttributeType attributeType = null;
-            
-            try
-            {
-                attributeType = schemaManager.lookupAttributeTypeRegistry( attribute );
-            }
-            catch ( LdapException ne )
-            {
-                String message = "The attribute '" + attribute + "' does not exist in the
entry";
-                LOG.warn( message );
-                continue;
-            }
-    
-            EntryAttribute attr = this.attributes.remove( attributeType.getOid() );
-            
-            if ( attr != null )
-            {
-                removed.add( attr );
-            }
-        }
-        
-        if ( removed.size() == 0 )
-        {
-            return null;
-        }
-        else
-        {
-            return removed;
-        }
-    }
-
-
-    /**
-     * <p>
      * Put some new attributes using the attributeTypes. 
      * No value is inserted. 
      * </p>

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java?rev=938123&r1=938122&r2=938123&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java
Mon Apr 26 16:57:06 2010
@@ -570,14 +570,104 @@ public interface Entry extends Cloneable
 
 
     /**
-      * Removes the specified attributes. The removed attributes are
-      * returned by this method. If there were no attribute the return value
-      * is <code>null</code>.
-      *
-      * @param attributes the attributes to be removed
-      * @return the removed attribute, if exists; otherwise <code>null</code>
-      */
+     * <p>
+     * Removes the specified binary values from an attribute.
+     * </p>
+     * <p>
+     * If at least one value is removed, this method returns <code>true</code>.
+     * </p>
+     * <p>
+     * If there is no more value after having removed the values, the attribute
+     * will be removed too.
+     * </p>
+     * <p>
+     * If the attribute does not exist, nothing is done and the method returns 
+     * <code>false</code>
+     * </p> 
+     *
+     * @param attributeType The attribute type  
+     * @param values the values to be removed
+     * @return <code>true</code> if at least a value is removed, <code>false</code>
+     * if not all the values have been removed or if the attribute does not exist. 
+     */
+    boolean remove( AttributeType attributeType, byte[]... values ) throws LdapException;
+
+    
+    /**
+     * <p>
+     * Removes the specified String values from an attribute.
+     * </p>
+     * <p>
+     * If at least one value is removed, this method returns <code>true</code>.
+     * </p>
+     * <p>
+     * If there is no more value after having removed the values, the attribute
+     * will be removed too.
+     * </p>
+     * <p>
+     * If the attribute does not exist, nothing is done and the method returns 
+     * <code>false</code>
+     * </p> 
+     *
+     * @param attributeType The attribute type  
+     * @param values the values to be removed
+     * @return <code>true</code> if at least a value is removed, <code>false</code>
+     * if not all the values have been removed or if the attribute does not exist. 
+     */
+    boolean remove( AttributeType attributeType, String... values ) throws LdapException;
+
+    
+    /**
+     * <p>
+     * Removes the specified values from an attribute.
+     * </p>
+     * <p>
+     * If at least one value is removed, this method returns <code>true</code>.
+     * </p>
+     * <p>
+     * If there is no more value after having removed the values, the attribute
+     * will be removed too.
+     * </p>
+     * <p>
+     * If the attribute does not exist, nothing is done and the method returns 
+     * <code>false</code>
+     * </p> 
+     *
+     * @param attributeType The attribute type  
+     * @param values the values to be removed
+     * @return <code>true</code> if at least a value is removed, <code>false</code>
+     * if not all the values have been removed or if the attribute does not exist. 
+     */
+    boolean remove( AttributeType attributeType, Value<?>... values ) throws LdapException;
+
+    
+    /**
+     * Removes the specified attributes. The removed attributes are
+     * returned by this method. If there were no attribute the return value
+     * is <code>null</code>.
+     *
+     * @param attributes the attributes to be removed
+     * @return the removed attribute, if exists; otherwise <code>null</code>
+     */
     List<EntryAttribute> remove( EntryAttribute... attributes ) throws LdapException;
+    
+
+    /**
+     * <p>
+     * Removes the attribute with the specified AttributeTypes. 
+     * </p>
+     * <p>
+     * The removed attribute are returned by this method. 
+     * </p>
+     * <p>
+     * If there is no attribute with the specified AttributeTypes,
+     * the return value is <code>null</code>.
+     * </p>
+     *
+     * @param attributes the AttributeTypes to be removed
+     * @return the removed attributes, if any, as a list; otherwise <code>null</code>
+     */
+    List<EntryAttribute> removeAttributes( AttributeType... attributes );
 
 
     /**

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/ServerEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/ServerEntry.java?rev=938123&r1=938122&r2=938123&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/ServerEntry.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/ServerEntry.java
Mon Apr 26 16:57:06 2010
@@ -46,107 +46,6 @@ public interface ServerEntry extends Ent
     
     /**
      * <p>
-     * Removes the specified binary values from an attribute.
-     * </p>
-     * <p>
-     * If at least one value is removed, this method returns <code>true</code>.
-     * </p>
-     * <p>
-     * If there is no more value after having removed the values, the attribute
-     * will be removed too.
-     * </p>
-     * <p>
-     * If the attribute does not exist, nothing is done and the method returns 
-     * <code>false</code>
-     * </p> 
-     *
-     * @param attributeType The attribute type  
-     * @param values the values to be removed
-     * @return <code>true</code> if at least a value is removed, <code>false</code>
-     * if not all the values have been removed or if the attribute does not exist. 
-     */
-    boolean remove( AttributeType attributeType, byte[]... values ) throws LdapException;
-
-    
-    /**
-     * <p>
-     * Removes the specified String values from an attribute.
-     * </p>
-     * <p>
-     * If at least one value is removed, this method returns <code>true</code>.
-     * </p>
-     * <p>
-     * If there is no more value after having removed the values, the attribute
-     * will be removed too.
-     * </p>
-     * <p>
-     * If the attribute does not exist, nothing is done and the method returns 
-     * <code>false</code>
-     * </p> 
-     *
-     * @param attributeType The attribute type  
-     * @param values the values to be removed
-     * @return <code>true</code> if at least a value is removed, <code>false</code>
-     * if not all the values have been removed or if the attribute does not exist. 
-     */
-    boolean remove( AttributeType attributeType, String... values ) throws LdapException;
-
-    
-    /**
-     * <p>
-     * Removes the specified values from an attribute.
-     * </p>
-     * <p>
-     * If at least one value is removed, this method returns <code>true</code>.
-     * </p>
-     * <p>
-     * If there is no more value after having removed the values, the attribute
-     * will be removed too.
-     * </p>
-     * <p>
-     * If the attribute does not exist, nothing is done and the method returns 
-     * <code>false</code>
-     * </p> 
-     *
-     * @param attributeType The attribute type  
-     * @param values the values to be removed
-     * @return <code>true</code> if at least a value is removed, <code>false</code>
-     * if not all the values have been removed or if the attribute does not exist. 
-     */
-    boolean remove( AttributeType attributeType, Value<?>... values ) throws LdapException;
-
-    
-    /**
-     * Removes the specified attributes. The removed attributes are
-     * returned by this method. If there were no attribute the return value
-     * is <code>null</code>.
-     *
-     * @param attributes the attributes to be removed
-     * @return the removed attribute, if exists; otherwise <code>null</code>
-     */
-    List<EntryAttribute> remove( EntryAttribute... attributes ) throws LdapException;
-    
-
-    /**
-     * <p>
-     * Removes the attribute with the specified AttributeTypes. 
-     * </p>
-     * <p>
-     * The removed attribute are returned by this method. 
-     * </p>
-     * <p>
-     * If there is no attribute with the specified AttributeTypes,
-     * the return value is <code>null</code>.
-     * </p>
-     *
-     * @param attributes the AttributeTypes to be removed
-     * @return the removed attributes, if any, as a list; otherwise <code>null</code>
-     */
-    List<EntryAttribute> removeAttributes( AttributeType... attributes );
-
-
-    /**
-     * <p>
      * Put some new attributes using the attributeTypes. 
      * No value is inserted. 
      * </p>

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntry.java?rev=938123&r1=938122&r2=938123&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntry.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntry.java
Mon Apr 26 16:57:06 2010
@@ -248,7 +248,7 @@ public class DefaultClientEntry implemen
     {
         if ( StringTools.isEmpty( StringTools.trim( upId ) ) )
         {
-            String message = I18n.err( I18n.ERR_04457 );
+            String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
             LOG.error( message );
             throw new IllegalArgumentException( message );
         }
@@ -267,7 +267,7 @@ public class DefaultClientEntry implemen
     {
         if ( attributeType == null )
         {
-            String message = I18n.err( I18n.ERR_04460 );
+            String message = I18n.err( I18n.ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED );
             LOG.error( message );
             throw new IllegalArgumentException( message );
         }
@@ -305,7 +305,7 @@ public class DefaultClientEntry implemen
     {    
         if ( attributeType == null )
         {
-            String message = I18n.err( I18n.ERR_04460 );
+            String message = I18n.err( I18n.ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED );
             LOG.error( message );
             throw new IllegalArgumentException( message );
         }
@@ -335,7 +335,7 @@ public class DefaultClientEntry implemen
     {
         if ( attributeType == null )
         {
-            String message = I18n.err( I18n.ERR_04460 );
+            String message = I18n.err( I18n.ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED );
             LOG.error( message );
             throw new IllegalArgumentException( message );
         }
@@ -398,7 +398,7 @@ public class DefaultClientEntry implemen
     {
         if ( attributeType == null )
         {
-            String message = I18n.err( I18n.ERR_04460 );
+            String message = I18n.err( I18n.ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED );
             LOG.error( message );
             throw new IllegalArgumentException( message );
         }
@@ -428,7 +428,7 @@ public class DefaultClientEntry implemen
     {
         if ( attributeType == null )
         {
-            String message = I18n.err( I18n.ERR_04460 );
+            String message = I18n.err( I18n.ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED );
             LOG.error( message );
             throw new IllegalArgumentException( message );
         }
@@ -517,7 +517,7 @@ public class DefaultClientEntry implemen
     {
         if ( StringTools.isEmpty( upId ) )
         {
-            String message = I18n.err( I18n.ERR_04460 );
+            String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
             LOG.error( message );
             throw new IllegalArgumentException( message );
         }
@@ -559,7 +559,7 @@ public class DefaultClientEntry implemen
     {
         if ( StringTools.isEmpty( upId ) )
         {
-            String message = I18n.err( I18n.ERR_04460 );
+            String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
             LOG.error( message );
             throw new IllegalArgumentException( message );
         }
@@ -601,7 +601,7 @@ public class DefaultClientEntry implemen
     {
         if ( StringTools.isEmpty( upId ) )
         {
-            String message = I18n.err( I18n.ERR_04460 );
+            String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
             LOG.error( message );
             throw new IllegalArgumentException( message );
         }
@@ -1062,7 +1062,7 @@ public class DefaultClientEntry implemen
     {
         if ( StringTools.isEmpty( upId ) )
         {
-            String message = I18n.err( I18n.ERR_04460 );
+            String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
             LOG.error( message );
             throw new IllegalArgumentException( message );
         }
@@ -1101,7 +1101,7 @@ public class DefaultClientEntry implemen
     {
         if ( StringTools.isEmpty( upId ) )
         {
-            String message = I18n.err( I18n.ERR_04460 );
+            String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
             LOG.error( message );
             throw new IllegalArgumentException( message );
         }
@@ -1140,7 +1140,7 @@ public class DefaultClientEntry implemen
     {
         if ( StringTools.isEmpty( upId ) )
         {
-            String message = I18n.err( I18n.ERR_04460 );
+            String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
             LOG.error( message );
             throw new IllegalArgumentException( message );
         }
@@ -1302,7 +1302,7 @@ public class DefaultClientEntry implemen
             }
             catch ( Exception e )
             {
-                String message = I18n.err( I18n.ERR_04460 );
+                String message = I18n.err( I18n.ERR_04477_NO_VALID_AT_FOR_THIS_ID );
                 LOG.error( message );
                 throw new IllegalArgumentException( message );
             }
@@ -1352,7 +1352,7 @@ public class DefaultClientEntry implemen
             }
             catch ( Exception e )
             {
-                String message = I18n.err( I18n.ERR_04460 );
+                String message = I18n.err( I18n.ERR_04477_NO_VALID_AT_FOR_THIS_ID );
                 LOG.error( message );
                 throw new IllegalArgumentException( message );
             }
@@ -1395,7 +1395,7 @@ public class DefaultClientEntry implemen
             }
             catch ( Exception e )
             {
-                String message = I18n.err( I18n.ERR_04460 );
+                String message = I18n.err( I18n.ERR_04477_NO_VALID_AT_FOR_THIS_ID );
                 LOG.error( message );
                 throw new IllegalArgumentException( message );
             }
@@ -1432,12 +1432,35 @@ public class DefaultClientEntry implemen
     {
         List<EntryAttribute> removedAttributes = new ArrayList<EntryAttribute>();
         
-        for ( EntryAttribute attribute:attributes )
+        if ( schemaManager == null )
         {
-            if ( contains( attribute.getId() ) )
+            for ( EntryAttribute attribute:attributes )
             {
-                this.attributes.remove( attribute.getId() );
-                removedAttributes.add( attribute );
+                if ( contains( attribute.getId() ) )
+                {
+                    this.attributes.remove( attribute.getId() );
+                    removedAttributes.add( attribute );
+                }
+            }
+        }
+        else
+        {
+            for ( EntryAttribute attribute:attributes )
+            {
+                AttributeType attributeType = attribute.getAttributeType();
+                
+                if ( attributeType == null )
+                {
+                    String message = I18n.err( I18n.ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED
);
+                    LOG.error( message );
+                    throw new IllegalArgumentException( message );
+                }
+                
+                if ( this.attributes.containsKey( attributeType.getOid() ) )
+                {
+                    this.attributes.remove( attributeType.getOid() );
+                    removedAttributes.add( attribute );
+                }
             }
         }
         
@@ -1448,28 +1471,262 @@ public class DefaultClientEntry implemen
     /**
      * {@inheritDoc}
      */
-    public List<EntryAttribute> removeAttributes( String... attributes )
+    public boolean remove( AttributeType attributeType, byte[]... values ) throws LdapException
     {
-        if ( attributes.length == 0 )
+        if ( attributeType == null )
+        {
+            return false;
+        }
+        
+        try
+        {
+            EntryAttribute attribute = attributes.get( attributeType.getOid() );
+            
+            if ( attribute == null )
+            {
+                // Can't remove values from a not existing attribute !
+                return false;
+            }
+            
+            int nbOldValues = attribute.size();
+            
+            // Remove the values
+            attribute.remove( values );
+            
+            if ( attribute.size() == 0 )
+            {
+                // No mare values, remove the attribute
+                attributes.remove( attributeType.getOid() );
+                
+                return true;
+            }
+            
+            if ( nbOldValues != attribute.size() )
+            {
+                // At least one value have been removed, return true.
+                return true;
+            }
+            else
+            {
+                // No values have been removed, return false.
+                return false;
+            }
+        }
+        catch ( IllegalArgumentException iae )
+        {
+            LOG.error( I18n.err( I18n.ERR_04465, attributeType ) );
+            return false;
+        }
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean remove( AttributeType attributeType, String... values ) throws LdapException
+    {
+        if ( attributeType == null )
+        {
+            return false;
+        }
+        
+        try
+        {
+            EntryAttribute attribute = attributes.get( attributeType.getOid() );
+            
+            if ( attribute == null )
+            {
+                // Can't remove values from a not existing attribute !
+                return false;
+            }
+            
+            int nbOldValues = attribute.size();
+            
+            // Remove the values
+            attribute.remove( values );
+            
+            if ( attribute.size() == 0 )
+            {
+                // No mare values, remove the attribute
+                attributes.remove( attributeType.getOid() );
+                
+                return true;
+            }
+            
+            if ( nbOldValues != attribute.size() )
+            {
+                // At least one value have been removed, return true.
+                return true;
+            }
+            else
+            {
+                // No values have been removed, return false.
+                return false;
+            }
+        }
+        catch ( IllegalArgumentException iae )
+        {
+            LOG.error( I18n.err( I18n.ERR_04465, attributeType ) );
+            return false;
+        }
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean remove( AttributeType attributeType, Value<?>... values ) throws
LdapException
+    {
+        if ( attributeType == null )
+        {
+            return false;
+        }
+        
+        try
+        {
+            EntryAttribute attribute = attributes.get( attributeType.getOid() );
+            
+            if ( attribute == null )
+            {
+                // Can't remove values from a not existing attribute !
+                return false;
+            }
+            
+            int nbOldValues = attribute.size();
+            
+            // Remove the values
+            attribute.remove( values );
+            
+            if ( attribute.size() == 0 )
+            {
+                // No mare values, remove the attribute
+                attributes.remove( attributeType.getOid() );
+                
+                return true;
+            }
+            
+            if ( nbOldValues != attribute.size() )
+            {
+                // At least one value have been removed, return true.
+                return true;
+            }
+            else
+            {
+                // No values have been removed, return false.
+                return false;
+            }
+        }
+        catch ( IllegalArgumentException iae )
+        {
+            LOG.error( I18n.err( I18n.ERR_04465, attributeType ) );
+            return false;
+        }
+    }
+    
+    
+    /**
+     * <p>
+     * Removes the attribute with the specified AttributeTypes. 
+     * </p>
+     * <p>
+     * The removed attribute are returned by this method. 
+     * </p>
+     * <p>
+     * If there is no attribute with the specified AttributeTypes,
+     * the return value is <code>null</code>.
+     * </p>
+     *
+     * @param attributes the AttributeTypes to be removed
+     * @return the removed attributes, if any, as a list; otherwise <code>null</code>
+     */
+    public List<EntryAttribute> removeAttributes( AttributeType... attributes )
+    {
+        if ( ( attributes == null ) || ( attributes.length == 0 ) || ( schemaManager == null
) )
         {
             return null;
         }
         
         List<EntryAttribute> removed = new ArrayList<EntryAttribute>( attributes.length
);
         
-        for ( String attribute:attributes )
+        for ( AttributeType attributeType:attributes )
         {
-            EntryAttribute attr = get( attribute );
+            if ( attributeType == null )
+            {
+                continue;
+            }
+            
+            EntryAttribute attr = this.attributes.remove( attributeType.getOid() );
             
             if ( attr != null )
             {
-                removed.add( this.attributes.remove( attr.getId() ) );
+                removed.add( attr );
             }
-            else
+        }
+        
+        if ( removed.size() == 0 )
+        {
+            return null;
+        }
+        else
+        {
+            return removed;
+        }
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public List<EntryAttribute> removeAttributes( String... attributes )
+    {
+        if ( attributes.length == 0 )
+        {
+            return null;
+        }
+        
+        List<EntryAttribute> removed = new ArrayList<EntryAttribute>( attributes.length
);
+        
+        if ( schemaManager == null )
+        {
+            for ( String attribute:attributes )
             {
-                String message = I18n.err( I18n.ERR_04137, attribute );
-                LOG.warn( message );
-                continue;
+                EntryAttribute attr = get( attribute );
+                
+                if ( attr != null )
+                {
+                    removed.add( this.attributes.remove( attr.getId() ) );
+                }
+                else
+                {
+                    String message = I18n.err( I18n.ERR_04137, attribute );
+                    LOG.warn( message );
+                    continue;
+                }
+            }
+        }
+        else
+        {
+            for ( String attribute:attributes )
+            {
+                AttributeType attributeType = null;
+                
+                try
+                {
+                    attributeType = schemaManager.lookupAttributeTypeRegistry( attribute
);
+                }
+                catch ( LdapException ne )
+                {
+                    String message = "The attribute '" + attribute + "' does not exist in
the entry";
+                    LOG.warn( message );
+                    continue;
+                }
+        
+                EntryAttribute attr = this.attributes.remove( attributeType.getOid() );
+                
+                if ( attr != null )
+                {
+                    removed.add( attr );
+                }
             }
         }
         



Mime
View raw message