Package org.ldaptive

Class LdapAttribute

    • 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
      • 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.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode 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
      • 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 uses Object.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 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