APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.naming.ldap

public Class Rdn

extends Object
implements Serializable, Comparable<Object>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable, java.io.Serializable
Imports
java.util.Iterator, .NoSuchElementException, .ArrayList, .Locale, .Collections, javax.naming.InvalidNameException, .NamingEnumeration, .NamingException, javax.naming.directory.BasicAttributes, .Attributes, .Attribute, java.io.Serializable, .ObjectOutputStream, .ObjectInputStream, .IOException

This class represents a relative distinguished name, or RDN, which is a component of a distinguished name as specified by RFC 2253. An example of an RDN is "OU=Sales+CN=J.Smith". In this example, the RDN consist of multiple attribute type/value pairs. The RDN is parsed as described in the class description for LdapName.

The Rdn class represents an RDN as attribute type/value mappings, which can be viewed using Attributes. In addition, it contains convenience methods that allow easy retrieval of type and value when the Rdn consist of a single type/value pair, which is how it appears in a typical usage. It also contains helper methods that allow escaping of the unformatted attribute value and unescaping of the value formatted according to the escaping syntax defined in RFC2253. For methods that take or return attribute value as an Object, the value is either a String (in unescaped form) or a byte array.

Rdn will properly parse all valid RDNs, but does not attempt to detect all possible violations when parsing invalid RDNs. It is "generous" in accepting invalid RDNs. The "validity" of a name is determined ultimately when it is supplied to an LDAP server, which may accept or reject the name based on factors such as its schema information and interoperability considerations.

The following code example shows how to construct an Rdn using the constructor that takes type and value as arguments:

     Rdn rdn = new Rdn("cn", "Juicy, Fruit");
     System.out.println(rdn.toString());
The last line will print cn=Juicy\, Fruit. The unescapeValue() method can be used to unescape the escaped comma resulting in the original value "Juicy, Fruit". The escapeValue() method adds the escape back preceding the comma.

This class can be instantiated by a string representation of the RDN defined in RFC 2253 as shown in the following code example:

     Rdn rdn = new Rdn("cn=Juicy\\, Fruit");
     System.out.println(rdn.toString());
The last line will print cn=Juicy\, Fruit.

Concurrent multithreaded read-only access of an instance of Rdn need not be synchronized.

Unless otherwise noted, the behavior of passing a null argument to a constructor or method in this class will cause NullPointerException to be thrown.

Since
1.5

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final int
private transient ArrayList<Rdn.RdnEntry>
private static final String
private static final long

Constructor Summary

AccessConstructor and Description
public
Rdn(Attributes
The non-null and non-empty attributes containing type/value mappings.
attrSet
)

Constructs an Rdn from the given attribute set.

public
Rdn(String
The non-null and non-empty RFC2253 formatted string.
rdnString
)

Constructs an Rdn from the given string.

public
Rdn(Rdn
The non-null Rdn to be copied.
rdn
)

Constructs an Rdn from the given rdn.

public
Rdn(String
The non-null and non-empty string attribute type.
type
,
Object
The non-null and non-empty attribute value.
value
)

Constructs an Rdn from the given attribute type and value.

pack-priv
Rdn()

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

A negative integer, zero, or a positive integer as this Rdn is less than, equal to, or greater than the given Object.
compareTo
(Object
The non-null object to compare against.
obj
)

Implements java.lang.Comparable.compareTo.

Compares this Rdn with the specified Object for order.

private static byte[]
decodeHexPairs(char[] chars, int beg, int end)

public boolean

Returns:

true if the specified object is equal to this Rdn.
equals
(Object
object to be compared for equality with this Rdn.
obj
)

Overrides java.lang.Object.equals.

Compares the specified Object with this Rdn for equality.

private static String
escapeBinaryValue(byte[] val)

private static String
public static String

Returns:

Escaped string value.
escapeValue
(Object
The non-null object to be escaped.
val
)

Given the value of an attribute, returns a string escaped according to the rules specified in RFC 2253.

public String

Returns:

The non-null attribute type.
getType
()

Retrieves one of this Rdn's type.

private static byte[]
getUtf8Octets(char[] chars, int beg, int end)

public Object

Returns:

The non-null attribute value.
getValue
()

Retrieves one of this Rdn's value.

public int

Returns:

An int representing the hash code of this Rdn.
hashCode
()

Overrides java.lang.Object.hashCode.

Returns the hash code of this RDN.

private boolean
private static boolean
isWhitespace(char c)

pack-priv Rdn
put(String type, Object value)

private void
readObject(ObjectInputStream
the ObjectInputStream to read from
s
)

The readObject method is called to restore the state of the Rdn from a stream.

public int

Returns:

The non-negative number of type/value pairs in this Rdn.
size
()

Retrieves the number of attribute type/value pairs in this Rdn.

pack-priv void
sort()

public Attributes

Returns:

The non-null attributes containing the type/value mappings of this Rdn.
toAttributes
()

Retrieves the Attributes view of the type/value mappings contained in this Rdn.

public String

Returns:

The string representation of the Rdn.
toString
()

Overrides java.lang.Object.toString.

Returns this Rdn as a string represented in a format defined by RFC 2253 and described in the class description for LdapName.

public static Object

Returns:

Unescaped value.
unescapeValue
(String
The non-null string to be unescaped.
val
)

Given an attribute value string formatted according to the rules specified in RFC 2253, returns the unformatted value.

private void
writeObject(ObjectOutputStream
the ObjectOutputStream to write to
s
)

The writeObject method is called to save the state of the Rdn to a stream.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

DEFAULT_SIZEback to summary
private static final int DEFAULT_SIZE
entriesback to summary
private transient ArrayList<Rdn.RdnEntry> entries
escapeesback to summary
private static final String escapees
serialVersionUIDback to summary
private static final long serialVersionUID
Annotations
@Serial

Constructor Detail

Rdnback to summary
public Rdn(Attributes attrSet) throws InvalidNameException

Constructs an Rdn from the given attribute set. See Attributes.

The string attribute values are not interpreted as RFC 2253 formatted RDN strings. That is, the values are used literally (not parsed) and assumed to be unescaped.

Parameters
attrSet:Attributes

The non-null and non-empty attributes containing type/value mappings.

Exceptions
InvalidNameException:
If contents of attrSet cannot be used to construct a valid RDN.
Rdnback to summary
public Rdn(String rdnString) throws InvalidNameException

Constructs an Rdn from the given string. This constructor takes a string formatted according to the rules defined in RFC 2253 and described in the class description for javax.naming.ldap.LdapName.

Parameters
rdnString:String

The non-null and non-empty RFC2253 formatted string.

Exceptions
InvalidNameException:
If a syntax error occurs during parsing of the rdnString.
Rdnback to summary
public Rdn(Rdn rdn)

Constructs an Rdn from the given rdn. The contents of the rdn are simply copied into the newly created Rdn.

Parameters
rdn:Rdn

The non-null Rdn to be copied.

Rdnback to summary
public Rdn(String type, Object value) throws InvalidNameException

Constructs an Rdn from the given attribute type and value. The string attribute values are not interpreted as RFC 2253 formatted RDN strings. That is, the values are used literally (not parsed) and assumed to be unescaped.

Parameters
type:String

The non-null and non-empty string attribute type.

value:Object

The non-null and non-empty attribute value.

Exceptions
InvalidNameException:
If type/value cannot be used to construct a valid RDN.
See Also
toString()
Rdnback to summary
pack-priv Rdn()

Method Detail

compareToback to summary
public int compareTo(Object obj)

Implements java.lang.Comparable.compareTo.

Compares this Rdn with the specified Object for order. Returns a negative integer, zero, or a positive integer as this Rdn is less than, equal to, or greater than the given Object.

If obj is null or not an instance of Rdn, ClassCastException is thrown.

The attribute type and value pairs of the RDNs are lined up against each other and compared lexicographically. The order of components in multi-valued Rdns (such as "ou=Sales+cn=Bob") is not significant.

Parameters
obj:Object

The non-null object to compare against.

Returns:int

A negative integer, zero, or a positive integer as this Rdn is less than, equal to, or greater than the given Object.

Exceptions
ClassCastException:
if obj is null or not a Rdn.
decodeHexPairsback to summary
private static byte[] decodeHexPairs(char[] chars, int beg, int end)
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Compares the specified Object with this Rdn for equality. Returns true if the given object is also a Rdn and the two Rdns represent the same attribute type and value mappings. The order of components in multi-valued Rdns (such as "ou=Sales+cn=Bob") is not significant.

Type and value equality matching is done as below:

  • The types are compared for equality with their case ignored.
  • String values with different but equivalent usage of quoting, escaping, or UTF8-hex-encoding are considered equal. The case of the values is ignored during the comparison.

If obj is null or not an instance of Rdn, false is returned.

Parameters
obj:Object

object to be compared for equality with this Rdn.

Returns:boolean

true if the specified object is equal to this Rdn.

See Also
hashCode()
escapeBinaryValueback to summary
private static String escapeBinaryValue(byte[] val)
escapeStringValueback to summary
private static String escapeStringValue(String val)
escapeValueback to summary
public static String escapeValue(Object val)

Given the value of an attribute, returns a string escaped according to the rules specified in RFC 2253.

For example, if the val is "Sue, Grabbit and Runn", the escaped value returned by this method is "Sue\, Grabbit and Runn".

A string value is represented as a String and binary value as a byte array.

Parameters
val:Object

The non-null object to be escaped.

Returns:String

Escaped string value.

Exceptions
ClassCastException:
if val is not a String or byte array.
getTypeback to summary
public String getType()

Retrieves one of this Rdn's type. This is a convenience method for obtaining the type, when the RDN contains a single type and value mapping, which is the common RDN usage.

For a multi-valued RDN, the type/value pairs have no specific order defined on them. In that case, this method returns type of one of the type/value pairs. The getValue() method returns the value corresponding to the type returned by this method.

Returns:String

The non-null attribute type.

getUtf8Octetsback to summary
private static byte[] getUtf8Octets(char[] chars, int beg, int end)
getValueback to summary
public Object getValue()

Retrieves one of this Rdn's value. This is a convenience method for obtaining the value, when the RDN contains a single type and value mapping, which is the common RDN usage.

For a multi-valued RDN, this method returns value corresponding to the type returned by getType() method.

Returns:Object

The non-null attribute value.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns the hash code of this RDN. Two RDNs that are equal (according to the equals method) will have the same hash code.

Returns:int

An int representing the hash code of this Rdn.

See Also
equals
isEmptyValueback to summary
private boolean isEmptyValue(Object val)
isWhitespaceback to summary
private static boolean isWhitespace(char c)
putback to summary
pack-priv Rdn put(String type, Object value)
readObjectback to summary
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException

The readObject method is called to restore the state of the Rdn from a stream. See writeObject for a description of the serial form.

Parameters
s:ObjectInputStream

the ObjectInputStream to read from

Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs
ClassNotFoundException:
if the class of a serialized object could not be found
sizeback to summary
public int size()

Retrieves the number of attribute type/value pairs in this Rdn.

Returns:int

The non-negative number of type/value pairs in this Rdn.

sortback to summary
pack-priv void sort()
toAttributesback to summary
public Attributes toAttributes()

Retrieves the Attributes view of the type/value mappings contained in this Rdn.

Returns:Attributes

The non-null attributes containing the type/value mappings of this Rdn.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns this Rdn as a string represented in a format defined by RFC 2253 and described in the class description for LdapName.

Returns:String

The string representation of the Rdn.

unescapeValueback to summary
public static Object unescapeValue(String val)

Given an attribute value string formatted according to the rules specified in RFC 2253, returns the unformatted value. Escapes and quotes are stripped away, and hex-encoded UTF-8 is converted to equivalent UTF-16 characters. Returns a string value as a String, and a binary value as a byte array.

Legal and illegal values are defined in RFC 2253. This method is generous in accepting the values and does not catch all illegal values. Therefore, passing in an illegal value might not necessarily trigger an IllegalArgumentException.

Parameters
val:String

The non-null string to be unescaped.

Returns:Object

Unescaped value.

Exceptions
IllegalArgumentException:
When an Illegal value is provided.
writeObjectback to summary
private void writeObject(ObjectOutputStream s) throws IOException

The writeObject method is called to save the state of the Rdn to a stream. Serializes only the unparsed RDN, for compactness and to avoid any implementation dependency.

Parameters
s:ObjectOutputStream

the ObjectOutputStream to write to

Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs
Serial data
The unparsed RDN String representation.
javax.naming.ldap back to summary

private Class Rdn.RdnEntry

extends Object
implements Comparable<Rdn.RdnEntry>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable

Field Summary

Modifier and TypeField and Description
private String
private String
private Object

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public int
compareTo(Rdn.RdnEntry that)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.

public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

pack-priv String
pack-priv Object
private String
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

comparableback to summary
private String comparable
typeback to summary
private String type
valueback to summary
private Object value

Constructor Detail

RdnEntryback to summary
private RdnEntry()

Method Detail

compareToback to summary
public int compareTo(Rdn.RdnEntry that)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

getTypeback to summary
pack-priv String getType()
getValueback to summary
pack-priv Object getValue()
getValueComparableback to summary
private String getValueComparable()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.