Package org.ldaptive
Class LdapAttribute
- java.lang.Object
-
- org.ldaptive.AbstractLdapBean
-
- 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.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
LdapAttribute.LdapAttributeValues<T>
Simple bean for ldap attribute values.
-
Field Summary
Fields Modifier and Type Field Description private String
attributeName
Name for this attribute.private LdapAttribute.LdapAttributeValues<?>
attributeValues
Values for this attribute.private static int
HASH_CODE_SEED
hash code seed.private static long
serialVersionUID
serial version uid.
-
Constructor Summary
Constructors Constructor Description LdapAttribute()
Default constructor.LdapAttribute(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.LdapAttribute(SortBehavior sb)
Creates a new ldap attribute.LdapAttribute(SortBehavior sb, boolean binary)
Creates a new ldap attribute.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.private static <E> Comparator<E>
getComparator(Class<E> c)
Returns a comparator for the supplied class type.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
-
-
-
-
Field Detail
-
HASH_CODE_SEED
private static final int HASH_CODE_SEED
hash code seed.- See Also:
- Constant Field Values
-
serialVersionUID
private static final long serialVersionUID
serial version uid.- See Also:
- Constant Field Values
-
attributeName
private String attributeName
Name for this attribute.
-
attributeValues
private final LdapAttribute.LdapAttributeValues<?> attributeValues
Values for this attribute.
-
-
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 attributebinary
- 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 attributevalues
- of this attribute
-
LdapAttribute
public LdapAttribute(String name, byte[]... values)
Creates a new ldap attribute.- Parameters:
name
- of this attributevalues
- 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. SeegetStringValues()
.- 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. SeegetBinaryValues()
.- 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. SeegetValues(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. SeeaddStringValue(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. SeeaddBinaryValue(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 withvalue
- 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. SeeaddValue(ValueTranscoder, Object...)
.- Type Parameters:
T
- type attribute to encode- Parameters:
transcoder
- to encode value withvalues
- 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. SeeremoveStringValue(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. SeeremoveBinaryValue(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.
-
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 forSortBehavior.UNORDERED
, LinkedHashSet forSortBehavior.ORDERED
, and TreeSet forSortBehavior.SORTED
.- Type Parameters:
E
- contained in the collection- Parameters:
c
- type contained in the collection- Returns:
- collection corresponding to the sort behavior
-
getComparator
private static <E> Comparator<E> getComparator(Class<E> c)
Returns a comparator for the supplied class type. Should not be invoked for classes that have a natural ordering. Returns a comparator that usesObject.toString()
for unknown types.- Type Parameters:
E
- type of class- Parameters:
c
- type to compare- Returns:
- comparator for use with the supplied type
-
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 behaviorname
- of this attributevalues
- of this attribute- Returns:
- ldap attribute
- Throws:
IllegalArgumentException
- if values contains something other than String or byte[]
-
-