org.ldaptive
Class LdapAttribute

java.lang.Object
  extended by org.ldaptive.AbstractLdapBean
      extended by org.ldaptive.LdapAttribute
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
UnicodePwdAttribute

public class LdapAttribute
extends AbstractLdapBean

Simple bean representing an ldap attribute. Contains a name and a collection of values.

Version:
$Revision: 3189 $ $Date: 2016-11-01 17:21:43 -0400 (Tue, 01 Nov 2016) $
Author:
Middleware Services
See Also:
Serialized Form

Constructor Summary
LdapAttribute()
          Default constructor.
LdapAttribute(boolean binary)
          Creates a new ldap attribute.
LdapAttribute(SortBehavior sb)
          Creates a new ldap attribute.
LdapAttribute(SortBehavior sb, boolean binary)
          Creates a new ldap attribute.
LdapAttribute(String name)
          Creates a new ldap attribute.
LdapAttribute(String name, byte[]... values)
          Creates a new ldap attribute.
LdapAttribute(String name, String... values)
          Creates a new ldap attribute.
 
Method Summary
 void addBinaryValue(byte[]... value)
          Adds the supplied byte array as a value for this attribute.
 void addBinaryValues(Collection<byte[]> values)
          Adds all the byte arrays in the supplied collection as values for this attribute.
 void addStringValue(String... value)
          Adds the supplied string as a value for this attribute.
 void addStringValues(Collection<String> values)
          Adds all the strings in the supplied collection as values for this attribute.
<T> void
addValue(ValueTranscoder<T> transcoder, T... value)
          Adds the supplied values for this attribute by encoding them with the supplied transcoder.
<T> void
addValues(ValueTranscoder<T> transcoder, Collection<T> values)
          Adds all the values in the supplied collection for this attribute by encoding them with the supplied transcoder.
 void clear()
          Removes all the values in this ldap attribute.
static LdapAttribute createLdapAttribute(SortBehavior sb, String name, Collection<Object> values)
          Creates a new ldap attribute.
protected
<E> Collection<E>
createSortBehaviorCollection(Class<E> c)
          Returns an implementation of collection for the sort behavior of this bean.
 boolean equals(Object o)
          
static String escapeValue(String value)
          Escapes the supplied string value per RFC 4514 section 2.4.
 byte[] getBinaryValue()
          Returns a single byte array value of this attribute.
 Collection<byte[]> getBinaryValues()
          Returns the values of this attribute as byte arrays.
 String getName()
          Returns the name of this attribute.
 String getName(boolean withOptions)
          Returns the name of this attribute with or without options.
 String[] getOptions()
          Returns the options for this attribute.
 String getStringValue()
          Returns a single string value of this attribute.
 Collection<String> getStringValues()
          Returns the values of this attribute as strings.
<T> T
getValue(ValueTranscoder<T> transcoder)
          Returns a single decoded value of this attribute.
<T> Collection<T>
getValues(ValueTranscoder<T> transcoder)
          Returns the values of this attribute decoded by the supplied transcoder.
 int hashCode()
           
 boolean isBinary()
          Returns whether this ldap attribute contains a value of type byte[].
 void removeBinaryValue(byte[]... value)
          Removes the supplied value from the attribute values if it exists.
 void removeBinaryValues(Collection<byte[]> values)
          Removes the supplied values from the attribute values if they exists.
 void removeStringValue(String... value)
          Removes the supplied value from the attribute values if it exists.
 void removeStringValues(Collection<String> values)
          Removes the supplied values from the attribute values if they exists.
 void setName(String name)
          Sets the name of this attribute.
 int size()
          Returns the number of values in this ldap attribute.
 String toString()
          
 
Methods inherited from class org.ldaptive.AbstractLdapBean
getSortBehavior
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LdapAttribute

public LdapAttribute()
Default constructor.


LdapAttribute

public LdapAttribute(SortBehavior sb)
Creates a new ldap attribute.

Parameters:
sb - sort behavior of this attribute

LdapAttribute

public LdapAttribute(boolean binary)
Creates a new ldap attribute.

Parameters:
binary - whether this attribute contains binary values

LdapAttribute

public LdapAttribute(SortBehavior sb,
                     boolean binary)
Creates a new ldap attribute.

Parameters:
sb - sort behavior of this attribute
binary - whether this attribute contains binary values

LdapAttribute

public LdapAttribute(String name)
Creates a new ldap attribute.

Parameters:
name - of this attribute

LdapAttribute

public LdapAttribute(String name,
                     String... values)
Creates a new ldap attribute.

Parameters:
name - of this attribute
values - of this attribute

LdapAttribute

public LdapAttribute(String name,
                     byte[]... values)
Creates a new ldap attribute.

Parameters:
name - of this attribute
values - of this attribute
Method Detail

getName

public String getName()
Returns the name of this attribute. Includes options if they exist.

Returns:
attribute name

getName

public String getName(boolean withOptions)
Returns the name of this attribute with or without options.

Parameters:
withOptions - whether options should be included in the name
Returns:
attribute name

setName

public void setName(String name)
Sets the name of this attribute.

Parameters:
name - to set

getOptions

public String[] getOptions()
Returns the options for this attribute. Returns an empty array if attribute contains no options.

Returns:
options parsed from the attribute name

getStringValues

public Collection<String> getStringValues()
Returns the values of this attribute as strings. Binary data is base64 encoded. The return collection cannot be modified.

Returns:
collection of string attribute values

getStringValue

public String getStringValue()
Returns a single string value of this attribute. See getStringValues().

Returns:
single string attribute value

getBinaryValues

public Collection<byte[]> getBinaryValues()
Returns the values of this attribute as byte arrays. String data is UTF-8 encoded. The return collection cannot be modified.

Returns:
collection of byte array attribute values

getBinaryValue

public byte[] getBinaryValue()
Returns a single byte array value of this attribute. See getBinaryValues().

Returns:
single byte array attribute value

isBinary

public boolean isBinary()
Returns whether this ldap attribute contains a value of type byte[].

Returns:
whether this ldap attribute contains a value of type byte[]

getValues

public <T> Collection<T> getValues(ValueTranscoder<T> transcoder)
Returns the values of this attribute decoded by the supplied transcoder.

Type Parameters:
T - type of decoded attributes
Parameters:
transcoder - to decode attribute values with
Returns:
collection of decoded attribute values

getValue

public <T> T getValue(ValueTranscoder<T> transcoder)
Returns a single decoded value of this attribute. See getValues(ValueTranscoder).

Type Parameters:
T - type of decoded attributes
Parameters:
transcoder - to decode attribute values with
Returns:
single decoded attribute value

addStringValue

public void addStringValue(String... value)
Adds the supplied string as a value for this attribute.

Parameters:
value - to add
Throws:
NullPointerException - if value is null

addStringValues

public void addStringValues(Collection<String> values)
Adds all the strings in the supplied collection as values for this attribute. See addStringValue(String...).

Parameters:
values - to add

addBinaryValue

public void addBinaryValue(byte[]... value)
Adds the supplied byte array as a value for this attribute.

Parameters:
value - to add
Throws:
NullPointerException - if value is null

addBinaryValues

public void addBinaryValues(Collection<byte[]> values)
Adds all the byte arrays in the supplied collection as values for this attribute. See addBinaryValue(byte[][]).

Parameters:
values - to add

addValue

public <T> void addValue(ValueTranscoder<T> transcoder,
                         T... value)
Adds the supplied values for this attribute by encoding them with the supplied transcoder.

Type Parameters:
T - type attribute to encode
Parameters:
transcoder - to encode value with
value - to encode and add
Throws:
NullPointerException - if value is null

addValues

public <T> void addValues(ValueTranscoder<T> transcoder,
                          Collection<T> values)
Adds all the values in the supplied collection for this attribute by encoding them with the supplied transcoder. See addValue(ValueTranscoder, Object...).

Type Parameters:
T - type attribute to encode
Parameters:
transcoder - to encode value with
values - to encode and add

removeStringValue

public void removeStringValue(String... value)
Removes the supplied value from the attribute values if it exists.

Parameters:
value - to remove

removeStringValues

public void removeStringValues(Collection<String> values)
Removes the supplied values from the attribute values if they exists. See removeStringValue(String...).

Parameters:
values - to remove

removeBinaryValue

public void removeBinaryValue(byte[]... value)
Removes the supplied value from the attribute values if it exists.

Parameters:
value - to remove

removeBinaryValues

public void removeBinaryValues(Collection<byte[]> values)
Removes the supplied values from the attribute values if they exists. See removeBinaryValue(byte[][]).

Parameters:
values - to remove

size

public int size()
Returns the number of values in this ldap attribute.

Returns:
number of values in this ldap attribute

clear

public void clear()
Removes all the values in this ldap attribute.


equals

public boolean equals(Object o)

Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()

Overrides:
toString in class Object

createSortBehaviorCollection

protected <E> Collection<E> createSortBehaviorCollection(Class<E> c)
Returns an implementation of collection for the sort behavior of this bean. This implementation returns HashSet for SortBehavior.UNORDERED, LinkedHashSet for SortBehavior.ORDERED, and TreeSet for SortBehavior.SORTED.

Type Parameters:
E - contained in the collection
Parameters:
c - type contained in the collection
Returns:
collection corresponding to the sort behavior

createLdapAttribute

public static LdapAttribute createLdapAttribute(SortBehavior sb,
                                                String name,
                                                Collection<Object> values)
Creates a new ldap attribute. The collection of values is inspected for either String or byte[] and the appropriate attribute is created.

Parameters:
sb - sort behavior
name - of this attribute
values - of this attribute
Returns:
ldap attribute
Throws:
IllegalArgumentException - if values contains something other than String or byte[]

escapeValue

public static String escapeValue(String value)
Escapes the supplied string value per RFC 4514 section 2.4.

Parameters:
value - to escape
Returns:
escaped value


Copyright © 2003-2017 Virginia Tech. All Rights Reserved.