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: 693837 $
Author:
Apache Directory Project

Constructor Summary
AttributeUtils()
           
 
Method Summary
static void applyModification(Entry entry, Modification modification)
          A method to apply a modification to an existing entry.
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)
          Check if an attribute contains a specific value, using the associated matchingRule for that
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 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 java.lang.String parseAttribute(java.lang.String str, Position pos, boolean withOption)
          Parse an attribute.
static void parseOID(java.lang.String str, Position pos)
          Parse an OID.
static javax.naming.directory.Attribute removeAttribute(AttributeType type, javax.naming.directory.Attributes entry)
          Correctly removes an attribute from an entry using it's attributeType information.
static java.lang.Object removeValue(javax.naming.directory.Attribute attr, java.lang.Object compared, AttributeType type)
          Check if an attribute contains a specific value and remove it using the associated matchingRule for the attribute type supplied.
static javax.naming.directory.Attribute toAttribute(EntryAttribute entryAttribute)
          Converts an EntryAttribute to an Attribute.
static javax.naming.directory.Attributes toAttributes(Entry entry)
          Converts an Entry to an Attributes.
static javax.naming.directory.Attribute toBasicAttribute(javax.naming.directory.Attribute attribute)
          Switch from a BasicAttribute to a AttributeImpl.
static javax.naming.directory.Attributes toCaseInsensitive(javax.naming.directory.Attributes attributes)
          Check if the attributes is a BasicAttributes, and if so, switch the case sensitivity to false to avoid tricky problems in the server.
static EntryAttribute toClientAttribute(javax.naming.directory.Attribute attribute)
          Convert a BasicAttribute or a AttributeImpl to a EntryAttribute
static Entry toClientEntry(javax.naming.directory.Attributes attributes, LdapDN dn)
          Convert a BasicAttributes or a AttributesImpl to a ServerEntry
static java.lang.String toString(javax.naming.directory.Attribute attribute)
          Return a string representing the attribute
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

removeAttribute

public static javax.naming.directory.Attribute removeAttribute(AttributeType type,
                                                               javax.naming.directory.Attributes entry)
Correctly removes an attribute from an entry using it's attributeType information.

Parameters:
type - the attributeType of the attribute to remove
entry - the entry to remove the attribute from
Returns:
the Attribute that is removed

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 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

toBasicAttribute

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

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

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

containsValue

public static boolean containsValue(javax.naming.directory.Attribute attr,
                                    java.lang.Object compared,
                                    AttributeType type)
                             throws javax.naming.NamingException
Check if an attribute contains a specific value, using the associated matchingRule for that

Parameters:
attr - The attribute we are searching in
compared - The object we are looking for
type - The attribute type
Returns:
true if the value exists in the attribute
Throws:
javax.naming.NamingException - If something went wrong while accessing the data

containsValueCaseIgnore

public static 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

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

toCaseInsensitive

public static javax.naming.directory.Attributes toCaseInsensitive(javax.naming.directory.Attributes attributes)
Check if the attributes is a BasicAttributes, and if so, switch the case sensitivity to false to avoid tricky problems in the server. (Ldap attributeTypes are *always* case insensitive)

Parameters:
attributes - The Attributes to check

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
attribute - The attribute to print
Returns:
A string

toString

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

Parameters:
attribute - The attribute 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

parseOID

public static void parseOID(java.lang.String str,
                            Position pos)
                     throws java.text.ParseException
Parse an OID. numericoid = number 1*( '.' number ) number = '0'-'9' / ( '1'-'9' 1*'0'-'9' )

Parameters:
str - The OID to parse
pos - The current position in the string
Throws:
java.text.ParseException - If we don't have a valid OID

parseAttribute

public static java.lang.String parseAttribute(java.lang.String str,
                                              Position pos,
                                              boolean withOption)
                                       throws java.text.ParseException
Parse an attribute. The grammar is : attributedescription = attributetype options attributetype = oid oid = descr / numericoid descr = keystring numericoid = number 1*( '.' number ) options = *( ';' option ) option = 1*keychar keystring = leadkeychar *keychar leadkeychar = 'a'-z' | 'A'-'Z' keychar = 'a'-z' | 'A'-'Z' / '0'-'9' / '-' number = '0'-'9' / ( '1'-'9' 1*'0'-'9' )

Parameters:
str - The parsed attribute,
pos - The position of the attribute in the current string
Returns:
The parsed attribute if valid
Throws:
java.text.ParseException

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

applyModification

public static void applyModification(Entry entry,
                                     Modification modification)
                              throws javax.naming.NamingException
A method to apply a modification to an existing entry.

Parameters:
entry - The entry on which we want to apply a modification
modification - the Modification to be applied
Throws:
javax.naming.NamingException - if some operation fails.

removeValue

public static java.lang.Object removeValue(javax.naming.directory.Attribute attr,
                                           java.lang.Object compared,
                                           AttributeType type)
                                    throws javax.naming.NamingException
Check if an attribute contains a specific value and remove it using the associated matchingRule for the attribute type supplied.

Parameters:
attr - the attribute we are searching in
compared - the object we are looking for
type - the attribute type
Returns:
the value removed from the attribute, otherwise null
Throws:
javax.naming.NamingException - if something went wrong while removing the value

toClientEntry

public static Entry toClientEntry(javax.naming.directory.Attributes attributes,
                                  LdapDN dn)
                           throws javax.naming.directory.InvalidAttributeIdentifierException
Convert a BasicAttributes or a AttributesImpl to a ServerEntry

Parameters:
attributes - the BasicAttributes or AttributesImpl instance to convert
registries - The registries, needed ro build a ServerEntry
dn - The DN which is needed by the ServerEntry
Returns:
An instance of a ServerEntry object
Throws:
javax.naming.directory.InvalidAttributeIdentifierException - If we get an invalid attribute

toAttributes

public static javax.naming.directory.Attributes toAttributes(Entry entry)
Converts an Entry to an Attributes.

Parameters:
entry - the Entry to convert
Returns:
the equivalent Attributes

toAttribute

public static javax.naming.directory.Attribute toAttribute(EntryAttribute entryAttribute)
Converts an EntryAttribute to an Attribute.

Parameters:
entryAttribute - the EntryAttribute to convert
Returns:
the equivalent Attribute

toClientAttribute

public static EntryAttribute toClientAttribute(javax.naming.directory.Attribute attribute)
Convert a BasicAttribute or a AttributeImpl to a EntryAttribute

Parameters:
attribute - the BasicAttributes or AttributesImpl instance to convert
attributeType -
Returns:
An instance of a ClientEntry object
Throws:
javax.naming.directory.InvalidAttributeIdentifierException - If we had an incorrect attribute


Copyright © 2003-2011 Apache Software Foundation. All Rights Reserved.