Class RDN

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<RDN>, java.util.Comparator<RDN>

    @NotMutable
    @ThreadSafety(level=COMPLETELY_THREADSAFE)
    public final class RDN
    extends java.lang.Object
    implements java.lang.Comparable<RDN>, java.util.Comparator<RDN>, java.io.Serializable
    This class provides a data structure for holding information about an LDAP relative distinguished name (RDN). An RDN consists of one or more attribute name-value pairs. See RFC 4514 for more information about representing DNs and RDNs as strings. See the documentation in the DN class for more information about DNs and RDNs.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      RDN​(java.lang.String rdnString)
      Creates a new RDN from the provided string representation.
      RDN​(java.lang.String[] attributeNames, byte[][] attributeValues)
      Creates a new (potentially multivalued) RDN.
      RDN​(java.lang.String[] attributeNames, byte[][] attributeValues, Schema schema)
      Creates a new (potentially multivalued) RDN.
      RDN​(java.lang.String[] attributeNames, java.lang.String[] attributeValues)
      Creates a new (potentially multivalued) RDN.
      RDN​(java.lang.String[] attributeNames, java.lang.String[] attributeValues, Schema schema)
      Creates a new (potentially multivalued) RDN.
      RDN​(java.lang.String attributeName, byte[] attributeValue)
      Creates a new single-valued RDN with the provided information.
      RDN​(java.lang.String attributeName, byte[] attributeValue, Schema schema)
      Creates a new single-valued RDN with the provided information.
      RDN​(java.lang.String rdnString, Schema schema)
      Creates a new RDN from the provided string representation.
      RDN​(java.lang.String rdnString, Schema schema, boolean strictNameChecking)
      Creates a new RDN from the provided string representation.
      RDN​(java.lang.String attributeName, java.lang.String attributeValue)
      Creates a new single-valued RDN with the provided information.
      RDN​(java.lang.String attributeName, java.lang.String attributeValue, Schema schema)
      Creates a new single-valued RDN with the provided information.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(RDN rdn1, RDN rdn2)
      Compares the provided RDN values to determine their relative order in a sorted list.
      static int compare​(java.lang.String s1, java.lang.String s2)
      Compares the RDN values with the provided string representations to determine their relative order in a sorted list.
      static int compare​(java.lang.String s1, java.lang.String s2, Schema schema)
      Compares the RDN values with the provided string representations to determine their relative order in a sorted list.
      int compareTo​(RDN rdn)
      Compares the provided RDN to this RDN to determine their relative order in a sorted list.
      boolean equals​(java.lang.Object o)
      Indicates whether this RDN is equal to the provided object.
      boolean equals​(java.lang.String s)
      Indicates whether the RDN with the provided string representation is equal to this RDN.
      static boolean equals​(java.lang.String s1, java.lang.String s2)
      Indicates whether the two provided strings represent the same RDN.
      java.lang.String[] getAttributeNames()
      Retrieves the set of attribute names for this RDN.
      Attribute[] getAttributes()
      Retrieves an array of the attributes that comprise this RDN.
      java.lang.String[] getAttributeValues()
      Retrieves the set of attribute values for this RDN.
      byte[][] getByteArrayAttributeValues()
      Retrieves the set of attribute values for this RDN.
      java.util.SortedSet<RDNNameValuePair> getNameValuePairs()
      Retrieves a sorted set of the name-value pairs that comprise this RDN.
      int getValueCount()
      Retrieves the number of values for this RDN.
      boolean hasAttribute​(java.lang.String attributeName)
      Indicates whether this RDN contains the specified attribute.
      boolean hasAttributeValue​(java.lang.String attributeName, byte[] attributeValue)
      Indicates whether this RDN contains the specified attribute value.
      boolean hasAttributeValue​(java.lang.String attributeName, java.lang.String attributeValue)
      Indicates whether this RDN contains the specified attribute value.
      int hashCode()
      Retrieves a hash code for this RDN.
      boolean isMultiValued()
      Indicates whether this RDN contains multiple values.
      static boolean isValidRDN​(java.lang.String s)
      Indicates whether the provided string represents a valid RDN.
      static boolean isValidRDN​(java.lang.String s, boolean strictNameChecking)
      Indicates whether the provided string represents a valid RDN.
      static java.lang.String normalize​(java.lang.String s)
      Retrieves a normalized string representation of the RDN with the provided string representation.
      static java.lang.String normalize​(java.lang.String s, Schema schema)
      Retrieves a normalized string representation of the RDN with the provided string representation.
      java.lang.String toMinimallyEncodedString()
      Retrieves a string representation of this RDN with minimal encoding for special characters.
      java.lang.String toNormalizedString()
      Retrieves a normalized string representation of this RDN.
      void toNormalizedString​(java.lang.StringBuilder buffer)
      Appends a normalized string representation of this RDN to the provided buffer.
      java.lang.String toString()
      Retrieves a string representation of this RDN.
      void toString​(java.lang.StringBuilder buffer)
      Appends a string representation of this RDN to the provided buffer.
      void toString​(java.lang.StringBuilder buffer, boolean minimizeEncoding)
      Appends a string representation of this RDN to the provided buffer.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Comparator

        reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Constructor Detail

      • RDN

        public RDN​(java.lang.String attributeName,
                   java.lang.String attributeValue)
        Creates a new single-valued RDN with the provided information.
        Parameters:
        attributeName - The attribute name for this RDN. It must not be null.
        attributeValue - The attribute value for this RDN. It must not be null.
      • RDN

        public RDN​(java.lang.String attributeName,
                   java.lang.String attributeValue,
                   Schema schema)
        Creates a new single-valued RDN with the provided information.
        Parameters:
        attributeName - The attribute name for this RDN. It must not be null.
        attributeValue - The attribute value for this RDN. It must not be null.
        schema - The schema to use to generate the normalized string representation of this RDN. It may be null if no schema is available.
      • RDN

        public RDN​(java.lang.String attributeName,
                   byte[] attributeValue)
        Creates a new single-valued RDN with the provided information.
        Parameters:
        attributeName - The attribute name for this RDN. It must not be null.
        attributeValue - The attribute value for this RDN. It must not be null.
      • RDN

        public RDN​(java.lang.String attributeName,
                   byte[] attributeValue,
                   Schema schema)
        Creates a new single-valued RDN with the provided information.
        Parameters:
        attributeName - The attribute name for this RDN. It must not be null.
        attributeValue - The attribute value for this RDN. It must not be null.
        schema - The schema to use to generate the normalized string representation of this RDN. It may be null if no schema is available.
      • RDN

        public RDN​(java.lang.String[] attributeNames,
                   java.lang.String[] attributeValues)
        Creates a new (potentially multivalued) RDN. The set of names must have the same number of elements as the set of values, and there must be at least one element in each array.
        Parameters:
        attributeNames - The set of attribute names for this RDN. It must not be null or empty.
        attributeValues - The set of attribute values for this RDN. It must not be null or empty.
      • RDN

        public RDN​(java.lang.String[] attributeNames,
                   java.lang.String[] attributeValues,
                   Schema schema)
        Creates a new (potentially multivalued) RDN. The set of names must have the same number of elements as the set of values, and there must be at least one element in each array.
        Parameters:
        attributeNames - The set of attribute names for this RDN. It must not be null or empty.
        attributeValues - The set of attribute values for this RDN. It must not be null or empty.
        schema - The schema to use to generate the normalized string representation of this RDN. It may be null if no schema is available.
      • RDN

        public RDN​(java.lang.String[] attributeNames,
                   byte[][] attributeValues)
        Creates a new (potentially multivalued) RDN. The set of names must have the same number of elements as the set of values, and there must be at least one element in each array.
        Parameters:
        attributeNames - The set of attribute names for this RDN. It must not be null or empty.
        attributeValues - The set of attribute values for this RDN. It must not be null or empty.
      • RDN

        public RDN​(java.lang.String[] attributeNames,
                   byte[][] attributeValues,
                   Schema schema)
        Creates a new (potentially multivalued) RDN. The set of names must have the same number of elements as the set of values, and there must be at least one element in each array.
        Parameters:
        attributeNames - The set of attribute names for this RDN. It must not be null or empty.
        attributeValues - The set of attribute values for this RDN. It must not be null or empty.
        schema - The schema to use to generate the normalized string representation of this RDN. It may be null if no schema is available.
      • RDN

        public RDN​(java.lang.String rdnString)
            throws LDAPException
        Creates a new RDN from the provided string representation.
        Parameters:
        rdnString - The string representation to use for this RDN. It must not be empty or null.
        Throws:
        LDAPException - If the provided string cannot be parsed as a valid RDN.
      • RDN

        public RDN​(java.lang.String rdnString,
                   Schema schema)
            throws LDAPException
        Creates a new RDN from the provided string representation.
        Parameters:
        rdnString - The string representation to use for this RDN. It must not be empty or null.
        schema - The schema to use to generate the normalized string representation of this RDN. It may be null if no schema is available.
        Throws:
        LDAPException - If the provided string cannot be parsed as a valid RDN.
      • RDN

        public RDN​(java.lang.String rdnString,
                   Schema schema,
                   boolean strictNameChecking)
            throws LDAPException
        Creates a new RDN from the provided string representation.
        Parameters:
        rdnString - The string representation to use for this RDN. It must not be empty or null.
        schema - The schema to use to generate the normalized string representation of this RDN. It may be null if no schema is available.
        strictNameChecking - Indicates whether to verify that all attribute type names are valid as per RFC 4514. If this is false, then some technically invalid characters may be accepted in attribute type names. If this is true, then names must be strictly compliant.
        Throws:
        LDAPException - If the provided string cannot be parsed as a valid RDN.
    • Method Detail

      • isValidRDN

        public static boolean isValidRDN​(java.lang.String s)
        Indicates whether the provided string represents a valid RDN.
        Parameters:
        s - The string for which to make the determination. It must not be null.
        Returns:
        true if the provided string represents a valid RDN, or false if not.
      • isValidRDN

        public static boolean isValidRDN​(java.lang.String s,
                                         boolean strictNameChecking)
        Indicates whether the provided string represents a valid RDN.
        Parameters:
        s - The string for which to make the determination. It must not be null.
        strictNameChecking - Indicates whether to verify that all attribute type names are valid as per RFC 4514. If this is false, then some technically invalid characters may be accepted in attribute type names. If this is true, then names must be strictly compliant.
        Returns:
        true if the provided string represents a valid RDN, or false if not.
      • isMultiValued

        public boolean isMultiValued()
        Indicates whether this RDN contains multiple values.
        Returns:
        true if this RDN contains multiple values, or false if not.
      • getValueCount

        public int getValueCount()
        Retrieves the number of values for this RDN.
        Returns:
        The number of values for this RDN.
      • getAttributes

        public Attribute[] getAttributes()
        Retrieves an array of the attributes that comprise this RDN.
        Returns:
        An array of the attributes that comprise this RDN.
      • getAttributeNames

        public java.lang.String[] getAttributeNames()
        Retrieves the set of attribute names for this RDN.
        Returns:
        The set of attribute names for this RDN.
      • getAttributeValues

        public java.lang.String[] getAttributeValues()
        Retrieves the set of attribute values for this RDN.
        Returns:
        The set of attribute values for this RDN.
      • getByteArrayAttributeValues

        public byte[][] getByteArrayAttributeValues()
        Retrieves the set of attribute values for this RDN.
        Returns:
        The set of attribute values for this RDN.
      • getNameValuePairs

        public java.util.SortedSet<RDNNameValuePairgetNameValuePairs()
        Retrieves a sorted set of the name-value pairs that comprise this RDN.
        Returns:
        A sorted set of the name-value pairs that comprise this RDN.
      • hasAttribute

        public boolean hasAttribute​(java.lang.String attributeName)
        Indicates whether this RDN contains the specified attribute.
        Parameters:
        attributeName - The name of the attribute for which to make the determination.
        Returns:
        true if RDN contains the specified attribute, or false if not.
      • hasAttributeValue

        public boolean hasAttributeValue​(java.lang.String attributeName,
                                         java.lang.String attributeValue)
        Indicates whether this RDN contains the specified attribute value.
        Parameters:
        attributeName - The name of the attribute for which to make the determination.
        attributeValue - The attribute value for which to make the determination.
        Returns:
        true if RDN contains the specified attribute, or false if not.
      • hasAttributeValue

        public boolean hasAttributeValue​(java.lang.String attributeName,
                                         byte[] attributeValue)
        Indicates whether this RDN contains the specified attribute value.
        Parameters:
        attributeName - The name of the attribute for which to make the determination.
        attributeValue - The attribute value for which to make the determination.
        Returns:
        true if RDN contains the specified attribute, or false if not.
      • toString

        public java.lang.String toString()
        Retrieves a string representation of this RDN.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string representation of this RDN.
      • toMinimallyEncodedString

        public java.lang.String toMinimallyEncodedString()
        Retrieves a string representation of this RDN with minimal encoding for special characters. Only those characters specified in RFC 4514 section 2.4 will be escaped. No escaping will be used for non-ASCII characters or non-printable ASCII characters.
        Returns:
        A string representation of this RDN with minimal encoding for special characters.
      • toString

        public void toString​(java.lang.StringBuilder buffer)
        Appends a string representation of this RDN to the provided buffer.
        Parameters:
        buffer - The buffer to which the string representation is to be appended.
      • toString

        public void toString​(java.lang.StringBuilder buffer,
                             boolean minimizeEncoding)
        Appends a string representation of this RDN to the provided buffer.
        Parameters:
        buffer - The buffer to which the string representation is to be appended.
        minimizeEncoding - Indicates whether to restrict the encoding of special characters to the bare minimum required by LDAP (as per RFC 4514 section 2.4). If this is true, then only leading and trailing spaces, double quotes, plus signs, commas, semicolons, greater-than, less-than, and backslash characters will be encoded.
      • toNormalizedString

        public java.lang.String toNormalizedString()
        Retrieves a normalized string representation of this RDN.
        Returns:
        A normalized string representation of this RDN.
      • toNormalizedString

        public void toNormalizedString​(java.lang.StringBuilder buffer)
        Appends a normalized string representation of this RDN to the provided buffer.
        Parameters:
        buffer - The buffer to which the normalized string representation is to be appended.
      • normalize

        public static java.lang.String normalize​(java.lang.String s)
                                          throws LDAPException
        Retrieves a normalized string representation of the RDN with the provided string representation.
        Parameters:
        s - The string representation of the RDN to normalize. It must not be null.
        Returns:
        The normalized string representation of the RDN with the provided string representation.
        Throws:
        LDAPException - If the provided string cannot be parsed as an RDN.
      • normalize

        public static java.lang.String normalize​(java.lang.String s,
                                                 Schema schema)
                                          throws LDAPException
        Retrieves a normalized string representation of the RDN with the provided string representation.
        Parameters:
        s - The string representation of the RDN to normalize. It must not be null.
        schema - The schema to use to generate the normalized string representation of the RDN. It may be null if no schema is available.
        Returns:
        The normalized string representation of the RDN with the provided string representation.
        Throws:
        LDAPException - If the provided string cannot be parsed as an RDN.
      • hashCode

        public int hashCode()
        Retrieves a hash code for this RDN.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        The hash code for this RDN.
      • equals

        public boolean equals​(java.lang.Object o)
        Indicates whether this RDN is equal to the provided object. The given object will only be considered equal to this RDN if it is also an RDN with the same set of names and values.
        Specified by:
        equals in interface java.util.Comparator<RDN>
        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - The object for which to make the determination.
        Returns:
        true if the provided object can be considered equal to this RDN, or false if not.
      • equals

        public boolean equals​(java.lang.String s)
                       throws LDAPException
        Indicates whether the RDN with the provided string representation is equal to this RDN.
        Parameters:
        s - The string representation of the DN to compare with this RDN.
        Returns:
        true if the DN with the provided string representation is equal to this RDN, or false if not.
        Throws:
        LDAPException - If the provided string cannot be parsed as an RDN.
      • equals

        public static boolean equals​(java.lang.String s1,
                                     java.lang.String s2)
                              throws LDAPException
        Indicates whether the two provided strings represent the same RDN.
        Parameters:
        s1 - The string representation of the first RDN for which to make the determination. It must not be null.
        s2 - The string representation of the second RDN for which to make the determination. It must not be null.
        Returns:
        true if the provided strings represent the same RDN, or false if not.
        Throws:
        LDAPException - If either of the provided strings cannot be parsed as an RDN.
      • compareTo

        public int compareTo​(RDN rdn)
        Compares the provided RDN to this RDN to determine their relative order in a sorted list.
        Specified by:
        compareTo in interface java.lang.Comparable<RDN>
        Parameters:
        rdn - The RDN to compare against this RDN. It must not be null.
        Returns:
        A negative integer if this RDN should come before the provided RDN in a sorted list, a positive integer if this RDN should come after the provided RDN in a sorted list, or zero if the provided RDN can be considered equal to this RDN.
      • compare

        public int compare​(RDN rdn1,
                           RDN rdn2)
        Compares the provided RDN values to determine their relative order in a sorted list.
        Specified by:
        compare in interface java.util.Comparator<RDN>
        Parameters:
        rdn1 - The first RDN to be compared. It must not be null.
        rdn2 - The second RDN to be compared. It must not be null.
        Returns:
        A negative integer if the first RDN should come before the second RDN in a sorted list, a positive integer if the first RDN should come after the second RDN in a sorted list, or zero if the two RDN values can be considered equal.
      • compare

        public static int compare​(java.lang.String s1,
                                  java.lang.String s2)
                           throws LDAPException
        Compares the RDN values with the provided string representations to determine their relative order in a sorted list.
        Parameters:
        s1 - The string representation of the first RDN to be compared. It must not be null.
        s2 - The string representation of the second RDN to be compared. It must not be null.
        Returns:
        A negative integer if the first RDN should come before the second RDN in a sorted list, a positive integer if the first RDN should come after the second RDN in a sorted list, or zero if the two RDN values can be considered equal.
        Throws:
        LDAPException - If either of the provided strings cannot be parsed as an RDN.
      • compare

        public static int compare​(java.lang.String s1,
                                  java.lang.String s2,
                                  Schema schema)
                           throws LDAPException
        Compares the RDN values with the provided string representations to determine their relative order in a sorted list.
        Parameters:
        s1 - The string representation of the first RDN to be compared. It must not be null.
        s2 - The string representation of the second RDN to be compared. It must not be null.
        schema - The schema to use to generate the normalized string representations of the RDNs. It may be null if no schema is available.
        Returns:
        A negative integer if the first RDN should come before the second RDN in a sorted list, a positive integer if the first RDN should come after the second RDN in a sorted list, or zero if the two RDN values can be considered equal.
        Throws:
        LDAPException - If either of the provided strings cannot be parsed as an RDN.