Author: akarasulu Date: Sat Feb 3 20:21:14 2007 New Revision: 503353 URL: http://svn.apache.org/viewvc?view=rev&rev=503353 Log: adding method from ServerUtils here since it does not need server deps to function Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java?view=diff&rev=503353&r1=503352&r2=503353 ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java Sat Feb 3 20:21:14 2007 @@ -43,6 +43,39 @@ public class AttributeUtils { /** + * Correctly removes an attribute from an entry using it's attributeType information. + * + * @param type the attributeType of the attribute to remove + * @param entry the entry to remove the attribute from + * @return the Attribute that is removed + * @throws NamingException if there are problems accessing the attribute + */ + public static Attribute removeAttribute( AttributeType type, Attributes entry ) throws NamingException + { + Attribute attr = entry.get( type.getOid() ); + if ( attr == null ) + { + String[] aliases = type.getNames(); + for ( int ii = 0; ii < aliases.length; ii++ ) + { + attr = entry.get( aliases[ii] ); + if ( attr != null ) + { + return entry.remove( attr.getID() ); + } + } + } + + if ( attr == null ) + { + return null; + } + + return entry.remove( attr.getID() ); + } + + + /** * Compare two values and return true if they are equal. * * @param value1 The first value