public class DistinguishedName extends Object implements Name
Name
corresponding to an LDAP path. A
Distinguished Name manipulation implementation is included in JDK1.5
(LdapName), but not in prior releases.
A DistinguishedName
is particularly useful when building or
modifying an LDAP path dynamically, as escaping will be taken care of.
A path is split into several names. The Name
interface specifies that
the most significant part be in position 0.
Example:
Name
instances, and consequently DistinguishedName
instances are naturally mutable, which is useful when constructing
DistinguishedNames. Example:
DistinguishedName path = new DistinguishedName("dc=jayway,dc=se"); path.add("ou", "People"); path.add("uid", "adam.skogman"); String dn = path.toString();will render
uid=adam.skogman,ou=People,dc=jayway,dc=se
.
NOTE: The fact that DistinguishedName instances are mutable needs to
be taken into careful account, as this means that they may be modified
involuntarily. This means that whenever a DistinguishedName
instance is kept for reference (e.g. for identification of a domain entry) or
as a constant, you should consider getting an immutable copy of the instance
using immutableDistinguishedName()
or
immutableDistinguishedName(String)
.
NB:As of version 1.3 the default toString representation of
DistinguishedName now defaults to a compact one, without spaces between the
respective RDNs. For backward compatibility, set the
SPACED_DN_FORMAT_PROPERTY
("org.springframework.ldap.core.spacedDnFormat") to
true
.
LdapName
,
LdapUtils.newLdapName(javax.naming.Name)
,
LdapUtils.newLdapName(String)
,
LdapUtils.emptyLdapName()
,
Serialized FormModifier and Type | Field and Description |
---|---|
static DistinguishedName |
EMPTY_PATH
Deprecated.
An empty, unmodifiable DistinguishedName.
|
static String |
KEY_CASE_FOLD_LOWER
Deprecated.
|
static String |
KEY_CASE_FOLD_NONE
Deprecated.
|
static String |
KEY_CASE_FOLD_PROPERTY
Deprecated.
System property that will be inspected to determine whether creating a
DistinguishedName will convert the keys to lowercase, convert
the keys to uppercase, or leave the keys as they were in the
original String, ie none.
|
static String |
KEY_CASE_FOLD_UPPER
Deprecated.
|
static String |
SPACED_DN_FORMAT_PROPERTY
Deprecated.
System property that will be inspected to determine whether
toString() will format the DN with spaces after each comma or
use a more compact representation, i.e.:
uid=adam.skogman, ou=People, dc=jayway, dc=se rather than
uid=adam.skogman,ou=People,dc=jayway,dc=se . |
Constructor and Description |
---|
DistinguishedName()
Deprecated.
Construct a new DistinguishedName with no components.
|
DistinguishedName(List list)
Deprecated.
|
DistinguishedName(Name name)
Deprecated.
Construct a new
DistinguishedName from the supplied
Name . |
DistinguishedName(String path)
Deprecated.
Construct a new
DistinguishedName from a String. |
Modifier and Type | Method and Description |
---|---|
void |
add(int idx,
LdapRdn rdn)
Deprecated.
Add the supplied
LdapRdn att the specified index. |
Name |
add(int index,
String string)
Deprecated.
|
void |
add(LdapRdn rdn)
Deprecated.
Add the supplied
LdapRdn last in the list of Rdns. |
Name |
add(String string)
Deprecated.
|
void |
add(String key,
String value)
Deprecated.
Add a new
LdapRdn using the supplied key and value. |
Name |
addAll(int arg0,
Name name)
Deprecated.
|
Name |
addAll(Name name)
Deprecated.
|
DistinguishedName |
append(DistinguishedName path)
Deprecated.
Add an LDAP path last in this DistinguishedName.
|
DistinguishedName |
append(String key,
String value)
Deprecated.
Append a new
LdapRdn using the supplied key and value. |
Object |
clone()
Deprecated.
|
int |
compareTo(Object obj)
Deprecated.
Compare this instance to another object.
|
boolean |
contains(DistinguishedName path)
Deprecated.
Determines if this
DistinguishedName path contains another
path. |
String |
encode()
Deprecated.
Builds a complete LDAP path, ldap encoded, useful as a DN.
|
boolean |
endsWith(Name name)
Deprecated.
Determines if this
DistinguishedName ends with a certian
path. |
boolean |
equals(Object obj)
Deprecated.
|
String |
get(int index)
Deprecated.
|
Enumeration |
getAll()
Deprecated.
|
LdapRdn |
getLdapRdn(int index)
Deprecated.
Get the
LdapRdn at a specified position. |
LdapRdn |
getLdapRdn(String key)
Deprecated.
Get the
LdapRdn with the specified key. |
List |
getNames()
Deprecated.
Get the name
List . |
Name |
getPrefix(int index)
Deprecated.
|
Name |
getSuffix(int index)
Deprecated.
|
String |
getValue(String key)
Deprecated.
Get the value of the
LdapRdnComponent with the specified key
(Attribute value). |
int |
hashCode()
Deprecated.
|
DistinguishedName |
immutableDistinguishedName()
Deprecated.
Return an immutable copy of this instance.
|
static DistinguishedName |
immutableDistinguishedName(String dnString)
Deprecated.
Create an immutable DistinguishedName instance, suitable as a constant.
|
boolean |
isEmpty()
Deprecated.
|
protected void |
parse(String path)
Deprecated.
Parse the supplied String and make this instance represent the
corresponding distinguished name.
|
void |
prepend(DistinguishedName path)
Deprecated.
Add an LDAP path first in this DistinguishedName.
|
Object |
remove(int arg0)
Deprecated.
|
LdapRdn |
removeFirst()
Deprecated.
Remove the first part of this
DistinguishedName . |
void |
removeFirst(Name path)
Deprecated.
Remove the supplied path from the beginning of this
DistinguishedName if this instance starts with
path . |
LdapRdn |
removeLast()
Deprecated.
Remove the last part of this
DistinguishedName . |
int |
size()
Deprecated.
|
boolean |
startsWith(Name name)
Deprecated.
|
String |
toCompactString()
Deprecated.
Get the compact String representation of this
DistinguishedName . |
String |
toString()
Deprecated.
Get the String representation of this
DistinguishedName . |
String |
toUrl()
Deprecated.
Builds a complete LDAP path, ldap and url encoded.
|
public static final String SPACED_DN_FORMAT_PROPERTY
toString()
will format the DN with spaces after each comma or
use a more compact representation, i.e.:
uid=adam.skogman, ou=People, dc=jayway, dc=se
rather than
uid=adam.skogman,ou=People,dc=jayway,dc=se
. A value other
than null or blank will trigger the spaced format. Default is the compact
representation.
Valid values are:
toCompactString()
,
Constant Field Valuespublic static final String KEY_CASE_FOLD_PROPERTY
Valid values are:
KEY_CASE_FOLD_LOWER
,
KEY_CASE_FOLD_UPPER
,
KEY_CASE_FOLD_NONE
,
Constant Field Valuespublic static final String KEY_CASE_FOLD_LOWER
public static final String KEY_CASE_FOLD_UPPER
public static final String KEY_CASE_FOLD_NONE
public static final DistinguishedName EMPTY_PATH
public DistinguishedName()
public DistinguishedName(String path)
DistinguishedName
from a String.path
- a String corresponding to a (syntactically) valid LDAP path.public DistinguishedName(List list)
list
- the components that this instance will consist of.protected final void parse(String path)
path
- the LDAP path to parse.public LdapRdn getLdapRdn(int index)
LdapRdn
at a specified position.public LdapRdn getLdapRdn(String key)
LdapRdn
with the specified key. If there are several
Rdn
s with the same key, the first one found (in order of
significance) will be returned.key
- Attribute name of the LdapRdn
to retrieve.LdapRdn
with the requested key.IllegalArgumentException
- if no Rdn matches the given key.public String getValue(String key)
LdapRdnComponent
with the specified key
(Attribute value). If there are several Rdns with the same key, the value
of the first one found (in order of significance) will be returned.key
- Attribute name of the LdapRdn
to retrieve.IllegalArgumentException
- if no Rdn matches the given key.public List getNames()
List
.LdapRdn
s that this
DistinguishedName
consists of.public String toString()
DistinguishedName
.
Depending on the setting of property
org.springframework.ldap.core.spacedDnFormat
a space will be
added after each comma, to make the result more readable. Default is
compact representation, i.e. without any spaces.toString
in class Object
DistinguishedName
.SPACED_DN_FORMAT_PROPERTY
public String toCompactString()
DistinguishedName
. Add no space after each comma, to make it
compact.DistinguishedName
.public String encode()
public String toUrl()
public boolean contains(DistinguishedName path)
DistinguishedName
path contains another
path.path
- the path to check.true
if the supplied path is conained in this
instance, false
otherwise.public DistinguishedName append(DistinguishedName path)
DistinguishedName name1 = new DistinguishedName("c=SE, dc=jayway, dc=se"); DistinguishedName name2 = new DistinguishedName("ou=people"); name1.append(name2);will result in
ou=people, c=SE, dc=jayway, dc=se
path
- the path to append.public DistinguishedName append(String key, String value)
LdapRdn
using the supplied key and value.public void prepend(DistinguishedName path)
DistinguishedName name1 = new DistinguishedName("ou=people"); DistinguishedName name2 = new DistinguishedName("c=SE, dc=jayway, dc=se"); name1.prepend(name2);will result in
ou=people, c=SE, dc=jayway, dc=se
path
- the path to prepend.public LdapRdn removeFirst()
DistinguishedName
.public void removeFirst(Name path)
DistinguishedName
if this instance starts with
path
. Useful for stripping base path suffix from a
DistinguishedName
.path
- the path to remove from the beginning of this instance.public Object clone()
clone
in interface Name
clone
in class Object
Object.clone()
public boolean equals(Object obj)
equals
in class Object
Object.equals(java.lang.Object)
public int hashCode()
hashCode
in class Object
Object.hashCode()
public int compareTo(Object obj)
compareTo
in interface Comparable<Object>
compareTo
in interface Name
Name.compareTo(java.lang.Object)
public Enumeration getAll()
public boolean startsWith(Name name)
startsWith
in interface Name
public boolean endsWith(Name name)
DistinguishedName
ends with a certian
path.
If the argument path is empty (no names in path) this method will return
false
.public Name addAll(Name name) throws InvalidNameException
addAll
in interface Name
InvalidNameException
public Name addAll(int arg0, Name name) throws InvalidNameException
addAll
in interface Name
InvalidNameException
public Name add(String string) throws InvalidNameException
add
in interface Name
InvalidNameException
public Name add(int index, String string) throws InvalidNameException
add
in interface Name
InvalidNameException
public Object remove(int arg0) throws InvalidNameException
remove
in interface Name
InvalidNameException
public LdapRdn removeLast()
DistinguishedName
.LdapRdn
.public void add(String key, String value)
LdapRdn
using the supplied key and value.public void add(LdapRdn rdn)
LdapRdn
last in the list of Rdns.rdn
- the LdapRdn
to add.public void add(int idx, LdapRdn rdn)
LdapRdn
att the specified index.idx
- the index at which to add the LdapRdn.rdn
- the LdapRdn to add.public DistinguishedName immutableDistinguishedName()
public static final DistinguishedName immutableDistinguishedName(String dnString)
dnString
- the DN string to parse.