org.apache.directory.shared.ldap.util
Class AttributeUtils

java.lang.Object
  extended by org.apache.directory.shared.ldap.util.AttributeUtils

public class AttributeUtils
extends java.lang.Object

A set of utility fuctions for working with Attributes.

Version:
$Rev: 498847 $
Author:
Apache Directory Project

Constructor Summary
AttributeUtils()
           
 
Method Summary
static java.lang.Object cloneValue(java.lang.Object value)
          Clone the value.
static boolean containsAnyValues(javax.naming.directory.Attribute attr, java.lang.Object[] compared, AttributeType type)
           
static boolean containsValue(javax.naming.directory.Attribute attr, java.lang.Object compared, AttributeType type)
           
static boolean containsValueCaseIgnore(javax.naming.directory.Attribute attr, java.lang.Object value)
          Check if an attribute contains a value.
static boolean equals(java.lang.Object value1, java.lang.Object value2)
          Compare two values and return true if they are equal.
static javax.naming.directory.Attribute getAttribute(javax.naming.directory.Attributes attrs, AttributeType type)
          Utility method to extract an attribute from Attributes object using all combinationos of the name including aliases.
static javax.naming.directory.Attribute getAttribute(ModificationItemImpl[] mods, AttributeType type)
          Utility method to extract an attribute from an array of modifications.
static javax.naming.directory.Attribute getDifference(javax.naming.directory.Attribute attr0, javax.naming.directory.Attribute attr1)
          Creates a new attribute which contains the values representing the difference of two attributes.
static javax.naming.directory.Attribute getUnion(javax.naming.directory.Attribute attr0, javax.naming.directory.Attribute attr1)
          Creates a new attribute which contains the values representing the union of two attributes.
static javax.naming.directory.Attribute toAttributeImpl(javax.naming.directory.Attribute attribute)
          Switch from a BasicAttribute to a LockableAttributeImpl.
static javax.naming.directory.Attributes toAttributesImpl(javax.naming.directory.Attributes attributes)
          Switch from a BasicAttributes to a LockableAttributesImpl.
static java.lang.String toString(javax.naming.directory.Attribute attribute)
          Return a string representing the attributes
static java.lang.String toString(javax.naming.directory.Attributes attributes)
          Return a string representing the attributes
static java.lang.String toString(java.lang.String tabs, javax.naming.directory.Attribute attribute)
          Return a string representing the attributes with tabs in front of the string
static java.lang.String toString(java.lang.String tabs, javax.naming.directory.Attributes attributes)
          Return a string representing the attributes with tabs in front of the string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AttributeUtils

public AttributeUtils()
Method Detail

equals

public static final boolean equals(java.lang.Object value1,
                                   java.lang.Object value2)
Compare two values and return true if they are equal.

Parameters:
value1 - The first value
value2 - The second value
Returns:
true if both value are null or if they are equal.

cloneValue

public static final java.lang.Object cloneValue(java.lang.Object value)
Clone the value. An attribute value is supposed to be either a String or a byte array. If it's a String, then we just return it ( as String is immutable, we don't need to copy it). If it's a bu=yte array, we create a new byte array and copy the bytes into it.

Parameters:
value - The value to clone
Returns:
The cloned value

toAttributeImpl

public static final javax.naming.directory.Attribute toAttributeImpl(javax.naming.directory.Attribute attribute)
Switch from a BasicAttribute to a LockableAttributeImpl. This is necessary to allow cloning to be correctly handled.

Parameters:
attribute - The attribute to transform
Returns:
A instance of LockableAttributeImpl

toAttributesImpl

public static final javax.naming.directory.Attributes toAttributesImpl(javax.naming.directory.Attributes attributes)
Switch from a BasicAttributes to a LockableAttributesImpl. This is necessary to allow cloning to be correctly handled.

Parameters:
attributes - The attributes to transform
Returns:
A instance of LockableAttributesImpl

getAttribute

public static final javax.naming.directory.Attribute getAttribute(javax.naming.directory.Attributes attrs,
                                                                  AttributeType type)
Utility method to extract an attribute from Attributes object using all combinationos of the name including aliases.

Parameters:
attrs - the Attributes to get the Attribute object from
type - the attribute type specification
Returns:
an Attribute with matching the attributeType spec or null

getAttribute

public static final javax.naming.directory.Attribute getAttribute(ModificationItemImpl[] mods,
                                                                  AttributeType type)
Utility method to extract an attribute from an array of modifications.

Parameters:
mods - the array of ModificationItems to extract the Attribute from.
type - the attributeType spec of the Attribute to extract
Returns:
the extract Attribute or null if no such attribute exists

containsValue

public static final boolean containsValue(javax.naming.directory.Attribute attr,
                                          java.lang.Object compared,
                                          AttributeType type)
                                   throws javax.naming.NamingException
Throws:
javax.naming.NamingException

containsValueCaseIgnore

public static final boolean containsValueCaseIgnore(javax.naming.directory.Attribute attr,
                                                    java.lang.Object value)
Check if an attribute contains a value. The test is case insensitive, and the value is supposed to be a String. If the value is a byte[], then the case sensitivity is useless.

Parameters:
attr - The attribute to check
value - The value to look for
Returns:
true if the value is present in the attribute
Throws:
javax.naming.NamingException

containsAnyValues

public static boolean containsAnyValues(javax.naming.directory.Attribute attr,
                                        java.lang.Object[] compared,
                                        AttributeType type)
                                 throws javax.naming.NamingException
Throws:
javax.naming.NamingException

getDifference

public static javax.naming.directory.Attribute getDifference(javax.naming.directory.Attribute attr0,
                                                             javax.naming.directory.Attribute attr1)
                                                      throws javax.naming.NamingException
Creates a new attribute which contains the values representing the difference of two attributes. If both attributes are null then we cannot determine the attribute ID and an IllegalArgumentException is raised. Note that the order of arguments makes a difference.

Parameters:
attr0 - the first attribute
attr1 - the second attribute
Returns:
a new attribute with the difference of values from both attribute arguments
Throws:
javax.naming.NamingException - if there are problems accessing attribute values

getUnion

public static javax.naming.directory.Attribute getUnion(javax.naming.directory.Attribute attr0,
                                                        javax.naming.directory.Attribute attr1)
                                                 throws javax.naming.NamingException
Creates a new attribute which contains the values representing the union of two attributes. If one attribute is null then the resultant attribute returned is a copy of the non-null attribute. If both are null then we cannot determine the attribute ID and an IllegalArgumentException is raised.

Parameters:
attr0 - the first attribute
attr1 - the second attribute
Returns:
a new attribute with the union of values from both attribute arguments
Throws:
javax.naming.NamingException - if there are problems accessing attribute values

toString

public static java.lang.String toString(java.lang.String tabs,
                                        javax.naming.directory.Attribute attribute)
Return a string representing the attributes with tabs in front of the string

Parameters:
tabs - Spaces to be added before the string
attributes - The attributes to print
Returns:
A string

toString

public static java.lang.String toString(javax.naming.directory.Attribute attribute)
Return a string representing the attributes

Parameters:
attributes - The attributes to print
Returns:
A string

toString

public static java.lang.String toString(java.lang.String tabs,
                                        javax.naming.directory.Attributes attributes)
Return a string representing the attributes with tabs in front of the string

Parameters:
tabs - Spaces to be added before the string
attributes - The attributes to print
Returns:
A string

toString

public static java.lang.String toString(javax.naming.directory.Attributes attributes)
Return a string representing the attributes

Parameters:
attributes - The attributes to print
Returns:
A string


Copyright © 2004-2011. All Rights Reserved.