APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.jndi.ldap

public final Class LdapName

extends Object
implements Name
Class Inheritance
All Implemented Interfaces
javax.naming.Name, java.lang.Comparable, java.io.Serializable, java.lang.Cloneable
Imports
java.util.Enumeration, .Vector, .Locale, javax.naming.*, javax.naming.directory.Attributes, .Attribute, .BasicAttributes

LdapName implements compound names for LDAP v3 as specified by RFC 2253.

RFC 2253 has a few ambiguities and outright inconsistencies. These are resolved as follows:

String names passed to LdapName or returned by it use the full 16-bit Unicode character set. They may also contain characters encoded into UTF-8 with each octet represented by a three-character substring such as "\\B4". They may not, however, contain characters encoded into UTF-8 with each octet represented by a single character in the string: the meaning would be ambiguous.

LdapName will properly parse all valid names, but does not attempt to detect all possible violations when parsing invalid names. It's "generous".

When names are tested for equality, attribute types and binary values are case-insensitive, and string values are by default case-insensitive. String values with different but equivalent usage of quoting, escaping, or UTF8-hex-encoding are considered equal. The order of components in multi-valued RDNs (such as "ou=Sales+cn=Bob") is not significant.

Author
Scott Seligman

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
private transient Vector<LdapName.Rdn>
pack-priv static final long
private transient String
private transient boolean

Constructor Summary

AccessConstructor and Description
public
LdapName(String
An LDAP DN. To JNDI, a compound name.
name
)

Constructs an LDAP name from the given DN.

private
private
LdapName(String name, Vector<LdapName.Rdn> rdns, int beg, int end)

Method Summary

Modifier and TypeMethod and Description
public Name
add(String comp)

Implements javax.naming.Name.add.

Adds a single component to the end of this name.

public Name
add(int pos, String comp)

Implements javax.naming.Name.add.

Adds a single component at a specified position within this name.

public Name
addAll(Name suffix)

Implements javax.naming.Name.addAll.

Adds the components of a name -- in order -- to the end of this name.

public Name
addAll(int pos, Name suffix)

Implements javax.naming.Name.addAll.

Adds the components of a name -- in order -- at a specified position within this name.

public Object
clone()

Overrides java.lang.Object.clone.

Implements javax.naming.Name.clone.

Generates a new copy of this name.

public int
compareTo(Object obj)

Implements javax.naming.Name.compareTo.

Compares this name with another name for order.

public boolean
endsWith(Name n)

Implements javax.naming.Name.endsWith.

Determines whether this name ends with a specified suffix.

public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

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

public static String
escapeAttributeValue(Object val)

Given the value of an attribute, returns a string suitable for inclusion in a DN.

public String
get(int pos)

Implements javax.naming.Name.get.

Retrieves a component of this name.

public Enumeration<String>
getAll()

Implements javax.naming.Name.getAll.

Retrieves the components of this name as an enumeration of strings.

public Name
getPrefix(int pos)

Implements javax.naming.Name.getPrefix.

Creates a name whose components consist of a prefix of the components of this name.

public Name
getSuffix(int pos)

Implements javax.naming.Name.getSuffix.

Creates a name whose components consist of a suffix of the components in this name.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean
isEmpty()

Implements javax.naming.Name.isEmpty.

Determines whether this name is empty.

private static boolean
isWhitespace(char c)

private boolean
matches(int beg, int end, Name n)

private void
private void
public Object
remove(int pos)

Implements javax.naming.Name.remove.

Removes a component from this name.

public void
setValuesCaseSensitive(boolean caseSensitive)

Controls whether string-values are treated as case-sensitive when the string values within names are compared.

public int
size()

Implements javax.naming.Name.size.

Returns the number of components in this name.

public boolean
startsWith(Name n)

Implements javax.naming.Name.startsWith.

Determines whether this name starts with a specified prefix.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public static Object
unescapeAttributeValue(String val)

Given an attribute value formatted according to RFC 2253, returns the unformatted value.

private void
writeObject(ObjectOutputStream s)

Serializes only the unparsed DN, for compactness and to avoid any implementation dependency.

Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

rdnsback to summary
private transient Vector<LdapName.Rdn> rdns
serialVersionUIDback to summary
pack-priv static final long serialVersionUID

Hides javax.naming.Name.serialVersionUID.

unparsedback to summary
private transient String unparsed
valuesCaseSensitiveback to summary
private transient boolean valuesCaseSensitive

Constructor Detail

LdapNameback to summary
public LdapName(String name) throws InvalidNameException

Constructs an LDAP name from the given DN.

Parameters
name:String

An LDAP DN. To JNDI, a compound name.

Exceptions
InvalidNameException:
if a syntax violation is detected.
LdapNameback to summary
private LdapName(String name, Vector<LdapName.Rdn> rdns)
Annotations
@SuppressWarnings:unchecked
LdapNameback to summary
private LdapName(String name, Vector<LdapName.Rdn> rdns, int beg, int end)

Method Detail

addback to summary
public Name add(String comp) throws InvalidNameException

Implements javax.naming.Name.add.

Doc from javax.naming.Name.add.

Adds a single component to the end of this name.

Exceptions
InvalidNameException:
if adding comp would violate the syntax rules of this name
addback to summary
public Name add(int pos, String comp) throws InvalidNameException

Implements javax.naming.Name.add.

Doc from javax.naming.Name.add.

Adds a single component at a specified position within this name. Components of this name at or after the index of the new component are shifted up by one (away from index 0) to accommodate the new component.

Exceptions
InvalidNameException:
if adding comp would violate the syntax rules of this name
addAllback to summary
public Name addAll(Name suffix) throws InvalidNameException

Implements javax.naming.Name.addAll.

Doc from javax.naming.Name.addAll.

Adds the components of a name -- in order -- to the end of this name.

Exceptions
InvalidNameException:
if suffix is not a valid name, or if the addition of the components would violate the syntax rules of this name
addAllback to summary
public Name addAll(int pos, Name suffix) throws InvalidNameException

Implements javax.naming.Name.addAll.

Doc from javax.naming.Name.addAll.

Adds the components of a name -- in order -- at a specified position within this name. Components of this name at or after the index of the first new component are shifted up (away from 0) to accommodate the new components.

Exceptions
InvalidNameException:
if n is not a valid name, or if the addition of the components would violate the syntax rules of this name
cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Implements javax.naming.Name.clone.

Doc from javax.naming.Name.clone.

Generates a new copy of this name. Subsequent changes to the components of this name will not affect the new copy, and vice versa.

compareToback to summary
public int compareTo(Object obj)

Implements javax.naming.Name.compareTo.

Doc from javax.naming.Name.compareTo.

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

As with Object.equals(), the notion of ordering for names depends on the class that implements this interface. For example, the ordering may be based on lexicographical ordering of the name components. Specific attributes of the name, such as how it treats case, may affect the ordering. In general, two names of different classes may not be compared.

endsWithback to summary
public boolean endsWith(Name n)

Implements javax.naming.Name.endsWith.

Doc from javax.naming.Name.endsWith.

Determines whether this name ends with a specified suffix. A name n is a suffix if it is equal to getSuffix(size()-n.size()).

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.

escapeAttributeValueback to summary
public static String escapeAttributeValue(Object val)

Given the value of an attribute, returns a string suitable for inclusion in a DN. If the value is a string, this is accomplished by using backslash (\) to escape the following characters:

  • leading and trailing whitespace
  • , = + < > # ; " \
If the value is a byte array, it is converted to hex notation (such as "#CEB1DF80").
getback to summary
public String get(int pos)

Implements javax.naming.Name.get.

Doc from javax.naming.Name.get.

Retrieves a component of this name.

getAllback to summary
public Enumeration<String> getAll()

Implements javax.naming.Name.getAll.

Doc from javax.naming.Name.getAll.

Retrieves the components of this name as an enumeration of strings. The effect on the enumeration of updates to this name is undefined. If the name has zero components, an empty (non-null) enumeration is returned.

getPrefixback to summary
public Name getPrefix(int pos)

Implements javax.naming.Name.getPrefix.

Doc from javax.naming.Name.getPrefix.

Creates a name whose components consist of a prefix of the components of this name. Subsequent changes to this name will not affect the name that is returned and vice versa.

getSuffixback to summary
public Name getSuffix(int pos)

Implements javax.naming.Name.getSuffix.

Doc from javax.naming.Name.getSuffix.

Creates a name whose components consist of a suffix of the components in this name. Subsequent changes to this name do not affect the name that is returned and vice versa.

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.
isEmptyback to summary
public boolean isEmpty()

Implements javax.naming.Name.isEmpty.

Doc from javax.naming.Name.isEmpty.

Determines whether this name is empty. An empty name is one with zero components.

isWhitespaceback to summary
private static boolean isWhitespace(char c)
matchesback to summary
private boolean matches(int beg, int end, Name n)
parseback to summary
private void parse() throws InvalidNameException
readObjectback to summary
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException
removeback to summary
public Object remove(int pos) throws InvalidNameException

Implements javax.naming.Name.remove.

Doc from javax.naming.Name.remove.

Removes a component from this name. The component of this name at the specified position is removed. Components with indexes greater than this position are shifted down (toward index 0) by one.

Exceptions
InvalidNameException:
if deleting the component would violate the syntax rules of the name
setValuesCaseSensitiveback to summary
public void setValuesCaseSensitive(boolean caseSensitive)

Controls whether string-values are treated as case-sensitive when the string values within names are compared. The default behavior is case-insensitive comparison.

sizeback to summary
public int size()

Implements javax.naming.Name.size.

Doc from javax.naming.Name.size.

Returns the number of components in this name.

startsWithback to summary
public boolean startsWith(Name n)

Implements javax.naming.Name.startsWith.

Doc from javax.naming.Name.startsWith.

Determines whether this name starts with a specified prefix. A name n is a prefix if it is equal to getPrefix(n.size()).

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.

unescapeAttributeValueback to summary
public static Object unescapeAttributeValue(String val)

Given an attribute value formatted according to RFC 2253, returns the unformatted value. Returns a string value as a string, and a binary value as a byte array.

writeObjectback to summary
private void writeObject(ObjectOutputStream s) throws IOException

Serializes only the unparsed DN, for compactness and to avoid any implementation dependency.

Serial data
The DN string and a boolean indicating whether the values are case sensitive.
com.sun.jndi.ldap back to summary

pack-priv Class LdapName.DnParser

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final char[]
private int
private final int
private final String
private boolean

Constructor Summary

AccessConstructor and Description
pack-priv
DnParser(String name, boolean valuesCaseSensitive)

Method Summary

Modifier and TypeMethod and Description
private boolean
private void
pack-priv Vector<LdapName.Rdn>
pack-priv LdapName.Rdn
private String
private String
private String
private String
private LdapName.Rdn
private String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

charsback to summary
private final char[] chars
curback to summary
private int cur
lenback to summary
private final int len
nameback to summary
private final String name
valuesCaseSensitiveback to summary
private boolean valuesCaseSensitive

Constructor Detail

DnParserback to summary
pack-priv DnParser(String name, boolean valuesCaseSensitive) throws InvalidNameException

Method Detail

atTerminatorback to summary
private boolean atTerminator()
consumeWhitespaceback to summary
private void consumeWhitespace()
getDnback to summary
pack-priv Vector<LdapName.Rdn> getDn() throws InvalidNameException
getRdnback to summary
pack-priv LdapName.Rdn getRdn() throws InvalidNameException
parseAttrTypeback to summary
private String parseAttrType() throws InvalidNameException
parseAttrValueback to summary
private String parseAttrValue() throws InvalidNameException
parseBinaryAttrValueback to summary
private String parseBinaryAttrValue() throws InvalidNameException
parseQuotedAttrValueback to summary
private String parseQuotedAttrValue() throws InvalidNameException
parseRdnback to summary
private LdapName.Rdn parseRdn() throws InvalidNameException
parseStringAttrValueback to summary
private String parseStringAttrValue() throws InvalidNameException
com.sun.jndi.ldap back to summary

pack-priv Class LdapName.Rdn

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final Vector<LdapName.TypeAndValue>

Constructor Summary

AccessConstructor and Description
pack-priv
Rdn()

Method Summary

Modifier and TypeMethod and Description
pack-priv void
public int
public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

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

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

pack-priv Attributes
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

tvsback to summary
private final Vector<LdapName.TypeAndValue> tvs

Constructor Detail

Rdnback to summary
pack-priv Rdn()

Method Detail

addback to summary
pack-priv void add(LdapName.TypeAndValue tv)
compareToback to summary
public int compareTo(Object obj)
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.

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.
toAttributesback to summary
pack-priv Attributes toAttributes()
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.

com.sun.jndi.ldap back to summary

pack-priv Class LdapName.TypeAndValue

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final boolean
private String
private final String
private final String
private final boolean

Constructor Summary

AccessConstructor and Description
pack-priv
TypeAndValue(String type, String value, boolean valueCaseSensitive)

Method Summary

Modifier and TypeMethod and Description
public int
private static byte[]
decodeHexPairs(char[] chars, int beg, int end)

public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

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

private static String
escapeBinaryValue(byte[] val)

private static String
pack-priv static String
pack-priv String
pack-priv Object
private static byte[]
getUtf8Octets(char[] chars, int beg, int end)

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.

pack-priv static Object
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

binaryback to summary
private final boolean binary
comparableback to summary
private String comparable
typeback to summary
private final String type
valueback to summary
private final String value
valueCaseSensitiveback to summary
private final boolean valueCaseSensitive

Constructor Detail

TypeAndValueback to summary
pack-priv TypeAndValue(String type, String value, boolean valueCaseSensitive)

Method Detail

compareToback to summary
public int compareTo(Object obj)
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.

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.

escapeBinaryValueback to summary
private static String escapeBinaryValue(byte[] val)
escapeStringValueback to summary
private static String escapeStringValue(String val)
escapeValueback to summary
pack-priv static String escapeValue(Object val)
getTypeback to summary
pack-priv String getType()
getUnescapedValueback to summary
pack-priv Object getUnescapedValue()
getUtf8Octetsback to summary
private static byte[] getUtf8Octets(char[] chars, int beg, int end)
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.

unescapeValueback to summary
pack-priv static Object unescapeValue(String val)