org.apache.directory.api.ldap.model.entry
Class AttributeUtils

java.lang.Object
  extended by org.apache.directory.api.ldap.model.entry.AttributeUtils

public final class AttributeUtils
extends Object

A set of utility fuctions for working with Attributes.

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 boolean containsValueCaseIgnore(Attribute attr, Object value)
          Check if an attribute contains a value.
static String parseAttribute(byte[] str, org.apache.directory.api.util.Position pos, boolean withOption)
          Parse an attribute.
static Attribute toApiAttribute(Attribute jndiAttribute)
          Convert a JNDI Attribute to an LDAP API Attribute
static Attributes toAttributes(Entry entry)
          Converts an Entry to an Attributes.
static Attributes toCaseInsensitive(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 Entry toEntry(Attributes attributes, Dn dn)
          Convert a BasicAttributes or a AttributesImpl to an Entry
static Attribute toJndiAttribute(Attribute attribute)
          Converts an Attribute to a JNDI Attribute.
 
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

containsValueCaseIgnore

public static boolean containsValueCaseIgnore(Attribute attr,
                                              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

toCaseInsensitive

public static Attributes toCaseInsensitive(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

parseAttribute

public static String parseAttribute(byte[] str,
                                    org.apache.directory.api.util.Position pos,
                                    boolean withOption)
                             throws 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:
ParseException

applyModification

public static void applyModification(Entry entry,
                                     Modification modification)
                              throws LdapException
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:
LdapException - if some operation fails.

toEntry

public static Entry toEntry(Attributes attributes,
                            Dn dn)
                     throws LdapException
Convert a BasicAttributes or a AttributesImpl to an Entry

Parameters:
attributes - the BasicAttributes or AttributesImpl instance to convert
dn - The Dn which is needed by the Entry
Returns:
An instance of a Entry object
Throws:
LdapException - If we get an invalid attribute

toAttributes

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

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

toJndiAttribute

public static Attribute toJndiAttribute(Attribute attribute)
Converts an Attribute to a JNDI Attribute.

Parameters:
attribute - the Attribute to convert
Returns:
the equivalent JNDI Attribute

toApiAttribute

public static Attribute toApiAttribute(Attribute jndiAttribute)
                                throws LdapInvalidAttributeValueException
Convert a JNDI Attribute to an LDAP API Attribute

Parameters:
jndiAttribute - the JNDI Attribute instance to convert
Returns:
An instance of a LDAP API Attribute object
Throws:
LdapInvalidAttributeValueException


Copyright © 2003-2013 The Apache Software Foundation. All Rights Reserved.