public class LdapName extends Object implements Name
This class resolves a few ambiguities found in RFC 2253 as follows:
String names passed to LdapName
or returned by it
use the full 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 is "generous" in accepting invalid names.
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.
When names are tested for equality, attribute types, both binary and string values, are 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.
The components of a LDAP name, that is, RDNs, are numbered. The indexes of a LDAP name with n RDNs range from 0 to n-1. This range may be written as [0,n). The right most RDN is at index 0, and the left most RDN is at index n-1. For example, the distinguished name: "CN=Steve Kille, O=Isode Limited, C=GB" is numbered in the following sequence ranging from 0 to 2: {C=GB, O=Isode Limited, CN=Steve Kille}. An empty LDAP name is represented by an empty RDN list.
Concurrent multithreaded read-only access of an instance of LdapName need not be synchronized.
Unless otherwise noted, the behavior of passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown.
Constructor and Description |
---|
LdapName(List<Rdn> rdns)
Constructs an LDAP name given its parsed RDN components.
|
LdapName(String name)
Constructs an LDAP name from the given distinguished name.
|
Modifier and Type | Method and Description |
---|---|
Name |
add(int posn,
Rdn comp)
Adds a single RDN at a specified position within this
LDAP name.
|
Name |
add(int posn,
String comp)
Adds a single component at a specified position within this
LDAP name.
|
Name |
add(Rdn comp)
Adds a single RDN to the end of this LDAP name.
|
Name |
add(String comp)
Adds a single component to the end of this LDAP name.
|
Name |
addAll(int posn,
List<Rdn> suffixRdns)
Adds the RDNs of a name -- in order -- at a specified position
within this name.
|
Name |
addAll(int posn,
Name suffix)
Adds the components of a name -- in order -- at a specified position
within this name.
|
Name |
addAll(List<Rdn> suffixRdns)
Adds the RDNs of a name -- in order -- to the end of this name.
|
Name |
addAll(Name suffix)
Adds the components of a name -- in order -- to the end of this name.
|
Object |
clone()
Generates a new copy of this name.
|
int |
compareTo(Object obj)
Compares this LdapName with the specified Object for order.
|
boolean |
endsWith(List<Rdn> rdns)
Determines whether the specified RDN sequence forms a suffix of this
LDAP name.
|
boolean |
endsWith(Name n)
Determines whether this LDAP name ends with a specified
LDAP name suffix.
|
boolean |
equals(Object obj)
Determines whether two LDAP names are equal.
|
String |
get(int posn)
Retrieves a component of this LDAP name as a string.
|
Enumeration<String> |
getAll()
Retrieves the components of this name as an enumeration
of strings.
|
Name |
getPrefix(int posn)
Creates a name whose components consist of a prefix of the
components of this LDAP name.
|
Rdn |
getRdn(int posn)
Retrieves an RDN of this LDAP name as an Rdn.
|
List<Rdn> |
getRdns()
Retrieves the list of relative distinguished names.
|
Name |
getSuffix(int posn)
Creates a name whose components consist of a suffix of the
components in this LDAP name.
|
int |
hashCode()
Computes the hash code of this LDAP name.
|
boolean |
isEmpty()
Determines whether this LDAP name is empty.
|
Object |
remove(int posn)
Removes a component from this LDAP name.
|
int |
size()
Retrieves the number of components in this LDAP name.
|
boolean |
startsWith(List<Rdn> rdns)
Determines whether the specified RDN sequence forms a prefix of this
LDAP name.
|
boolean |
startsWith(Name n)
Determines whether this LDAP name starts with a specified LDAP name
prefix.
|
String |
toString()
Returns a string representation of this LDAP name in a format
defined by RFC 2253
and described in the class description.
|
public LdapName(String name) throws InvalidNameException
name
- This is a non-null distinguished name formatted
according to the rules defined in
RFC 2253.InvalidNameException
- if a syntax violation is detected.Rdn.escapeValue(Object value)
public int size()
public boolean isEmpty()
public Enumeration<String> getAll()
public String get(int posn)
get
in interface Name
posn
- The 0-based index of the component to retrieve.
Must be in the range [0,size()).IndexOutOfBoundsException
- if posn is outside the
specified range.public Rdn getRdn(int posn)
posn
- The 0-based index of the RDN to retrieve.
Must be in the range [0,size()).IndexOutOfBoundsException
- if posn is outside the
specified range.public Name getPrefix(int posn)
getPrefix
in interface Name
posn
- The 0-based index of the component at which to stop.
Must be in the range [0,size()].IndexOutOfBoundsException
- If posn is outside the specified range.public Name getSuffix(int posn)
getSuffix
in interface Name
posn
- The 0-based index of the component at which to start.
Must be in the range [0,size()].IndexOutOfBoundsException
- If posn is outside the specified range.public boolean startsWith(Name n)
startsWith
in interface Name
n
- The LDAP name to check.getPrefix(int posn)
public boolean startsWith(List<Rdn> rdns)
rdns
- The sequence of Rdns to check.public boolean endsWith(Name n)
endsWith
in interface Name
n
- The LDAP name to check.getSuffix(int posn)
public boolean endsWith(List<Rdn> rdns)
rdns
- The sequence of Rdns to check.public Name addAll(Name suffix) throws InvalidNameException
addAll
in interface Name
suffix
- The non-null components to add.InvalidNameException
- if suffix is not a valid LDAP
name, or if the addition of the components would violate the
syntax rules of this LDAP name.public Name addAll(List<Rdn> suffixRdns)
suffixRdns
- The non-null suffix Rdns to add.public Name addAll(int posn, Name suffix) throws InvalidNameException
addAll
in interface Name
suffix
- The non-null components to add.posn
- The index at which to add the new component.
Must be in the range [0,size()].InvalidNameException
- if suffix is not a valid LDAP
name, or if the addition of the components would violate the
syntax rules of this LDAP name.IndexOutOfBoundsException
- If posn is outside the specified range.public Name addAll(int posn, List<Rdn> suffixRdns)
suffixRdns
- The non-null suffix Rdns to add.posn
- The index at which to add the suffix RDNs.
Must be in the range [0,size()].IndexOutOfBoundsException
- If posn is outside the specified range.public Name add(String comp) throws InvalidNameException
add
in interface Name
comp
- The non-null component to add.InvalidNameException
- If adding comp at end of the name
would violate the name's syntax.public Name add(Rdn comp)
comp
- The non-null RDN to add.public Name add(int posn, String comp) throws InvalidNameException
add
in interface Name
comp
- The non-null component to add.posn
- The index at which to add the new component.
Must be in the range [0,size()].IndexOutOfBoundsException
- If posn is outside the specified range.InvalidNameException
- If adding comp at the
specified position would violate the name's syntax.public Name add(int posn, Rdn comp)
comp
- The non-null RDN to add.posn
- The index at which to add the new RDN.
Must be in the range [0,size()].IndexOutOfBoundsException
- If posn is outside the specified range.public Object remove(int posn) throws InvalidNameException
remove
in interface Name
posn
- The index of the component to remove.
Must be in the range [0,size()).IndexOutOfBoundsException
- if posn is outside the specified range.InvalidNameException
- if deleting the component
would violate the syntax rules of the name.public List<Rdn> getRdns()
Rdn
.public Object clone()
public String toString()
public boolean equals(Object obj)
Two LDAP names are equal if each RDN in one is equal
to the corresponding RDN in the other. This implies
both have the same number of RDNs, and each RDN's
equals() test against the corresponding RDN in the other
name returns true. See Rdn.equals(Object obj)
for a definition of RDN equality.
equals
in class Object
obj
- The possibly null object to compare against.hashCode()
public int compareTo(Object obj)
If obj is null or not an instance of LdapName, ClassCastException is thrown.
Ordering of LDAP names follows the lexicographical rules for
string comparison, with the extension that this applies to all
the RDNs in the LDAP name. All the RDNs are lined up in their
specified order and compared lexicographically.
See Rdn.compareTo(Object obj)
for RDN comparison rules.
If this LDAP name is lexicographically lesser than obj, a negative number is returned. If this LDAP name is lexicographically greater than obj, a positive number is returned.
compareTo
in interface Comparable<Object>
compareTo
in interface Name
obj
- The non-null LdapName instance to compare against.ClassCastException
- if obj is null or not a LdapName.Comparable.compareTo(Object)
public int hashCode()
hashCode
in class Object
equals(java.lang.Object)
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2024, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.