org.springframework.ldap.support
Class DistinguishedName

java.lang.Object
  extended by org.springframework.ldap.support.DistinguishedName
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<java.lang.Object>, javax.naming.Name

public class DistinguishedName
extends java.lang.Object
implements javax.naming.Name

Default implementation of a Name corresponding to an LDAP path. A DistinguishedName implementation is included in JDK1.5 (LdapName), but not in prior releases. An 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, i.e. The path: uid=adam.skogman, ou=People, ou=EU Name[0]: ou=EU Name[1]: ou=People Name[2]: uid=adam.skogman

Useful for parsing and building LDAP paths.

 DistinguishedName path = new DistinguishedName();
 path.addLast("cn", entry.getUid());
 path.addLast("ou", "users");
 path.append(new DistinguishedName(helpdesk.getSomeSuffix()));
 String dn = path.toString();
 

Author:
Adam Skogman, Mattias Arthursson
See Also:
Serialized Form

Field Summary
static DistinguishedName EMPTY_PATH
          An empty, unmodifiable DistinguishedName.
 
Constructor Summary
DistinguishedName()
          Construct a new DistinguishedName with no components.
DistinguishedName(java.util.List list)
          Construct a new DistinguishedName from the supplied List of LdapRdn objects.
DistinguishedName(javax.naming.Name name)
          Construct a new DistinguishedName from the supplied Name.
DistinguishedName(java.lang.String path)
          Construct a new DistinguishedName from a String.
 
Method Summary
 void add(int idx, LdapRdn rdn)
          Add the supplied LdapRdn att the specified index.
 javax.naming.Name add(int index, java.lang.String string)
           
 void add(LdapRdn rdn)
          Add the supplied LdapRdn last in the list of Rdns.
 javax.naming.Name add(java.lang.String string)
           
 void add(java.lang.String key, java.lang.String value)
          Add a new LdapRdn using the supplied key and value.
 javax.naming.Name addAll(int arg0, javax.naming.Name name)
           
 javax.naming.Name addAll(javax.naming.Name name)
           
 void append(DistinguishedName path)
          Add a LDAP path first
 java.lang.Object clone()
           
 int compareTo(java.lang.Object obj)
          Compare this instance to another object.
 boolean contains(DistinguishedName path)
          Determines if a ldap path contains another path.
 java.lang.String encode()
          Builds a complete LDAP path, ldap encoded, useful as a DN.
 boolean endsWith(javax.naming.Name name)
          Determines if this ldap path ends with a certian path.
 boolean equals(java.lang.Object obj)
           
 java.lang.String get(int index)
           
 java.util.Enumeration getAll()
           
 LdapRdn getLdapRdn(int index)
          Get the LdapRdn at a specified position.
 java.util.List getNames()
          Get the name list.
 javax.naming.Name getPrefix(int index)
           
 javax.naming.Name getSuffix(int index)
           
 int hashCode()
           
 boolean isEmpty()
           
protected  void parse(java.lang.String path)
          Parse the supplied String and make this instance represent the corresponding distinguished name.
 void prepend(DistinguishedName path)
          Add a LDAP path first
 java.lang.Object remove(int arg0)
           
 LdapRdn removeFirst()
          Remove the first part of this DistinguishedName.
 void removeFirst(javax.naming.Name path)
          Remove the supplied path from the beginning of this DistinguishedName if this instance starts with .
 LdapRdn removeLast()
          Remove the ldast part of this DistinguishedName.
 int size()
           
 boolean startsWith(javax.naming.Name name)
           
 java.lang.String toString()
          Get the String representation of this DistinguishedName.
 java.lang.String toUrl()
          Builds a complete LDAP path, ldap and url encoded.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY_PATH

public static final DistinguishedName EMPTY_PATH
An empty, unmodifiable DistinguishedName.

Constructor Detail

DistinguishedName

public DistinguishedName()
Construct a new DistinguishedName with no components.


DistinguishedName

public DistinguishedName(java.lang.String path)
Construct a new DistinguishedName from a String.

Parameters:
path - a String corresponding to a (syntactically) valid LDAP path.

DistinguishedName

public DistinguishedName(java.util.List list)
Construct a new DistinguishedName from the supplied List of LdapRdn objects.

Parameters:
list - the components that this instance will consist of.

DistinguishedName

public DistinguishedName(javax.naming.Name name)
Construct a new DistinguishedName from the supplied Name. The parts of the supplied Name must be syntactically correct LdapRdns.

Parameters:
name - the Name to construct a new DistinguishedName from.
Method Detail

parse

protected void parse(java.lang.String path)
Parse the supplied String and make this instance represent the corresponding distinguished name.

Parameters:
path - the LDAP path to parse.

getLdapRdn

public LdapRdn getLdapRdn(int index)
Get the LdapRdn at a specified position.

Parameters:
index - the LdapRdn to retrieve.
Returns:
the LdapRdn at the requested position.

getNames

public java.util.List getNames()
Get the name list.

Returns:
the list of LdapRdns that this DistinguishedName consists of.

toString

public java.lang.String toString()
Get the String representation of this DistinguishedName.

Overrides:
toString in class java.lang.Object
Returns:
a syntactically correct, escaped String representation of the DistinguishedName.

encode

public java.lang.String encode()
Builds a complete LDAP path, ldap encoded, useful as a DN. Always uses lowercase, always separates with ", " i.e. comma and a space.

Returns:
the LDAP path.

toUrl

public java.lang.String toUrl()
Builds a complete LDAP path, ldap and url encoded. Separates only with ",".

Returns:
the LDAP path, for use in an url.

contains

public boolean contains(DistinguishedName path)
Determines if a ldap path contains another path.

Parameters:
path - the path to check.
Returns:
true if the supplied path is conained in this instance, false otherwise.

append

public void append(DistinguishedName path)
Add a LDAP path first

Parameters:
path -

prepend

public void prepend(DistinguishedName path)
Add a LDAP path first

Parameters:
path -

removeFirst

public LdapRdn removeFirst()
Remove the first part of this DistinguishedName.

Returns:
the removed entry.

removeFirst

public void removeFirst(javax.naming.Name path)
Remove the supplied path from the beginning of this DistinguishedName if this instance starts with . Useful for stripping base path suffix from a DistinguishedName.

Parameters:
path - the path to remove from the beginning of this instance.

clone

public java.lang.Object clone()
Specified by:
clone in interface javax.naming.Name
Overrides:
clone in class java.lang.Object
See Also:
Object.clone()

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

compareTo

public int compareTo(java.lang.Object obj)
Compare this instance to another object. Note that the comparison is done in order of significance, so the most significant Rdn is compared first, then the second and so on.

Specified by:
compareTo in interface java.lang.Comparable<java.lang.Object>
Specified by:
compareTo in interface javax.naming.Name
See Also:
Name.compareTo(java.lang.Object)

size

public int size()
Specified by:
size in interface javax.naming.Name

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface javax.naming.Name

getAll

public java.util.Enumeration getAll()
Specified by:
getAll in interface javax.naming.Name

get

public java.lang.String get(int index)
Specified by:
get in interface javax.naming.Name

getPrefix

public javax.naming.Name getPrefix(int index)
Specified by:
getPrefix in interface javax.naming.Name

getSuffix

public javax.naming.Name getSuffix(int index)
Specified by:
getSuffix in interface javax.naming.Name

startsWith

public boolean startsWith(javax.naming.Name name)
Specified by:
startsWith in interface javax.naming.Name

endsWith

public boolean endsWith(javax.naming.Name name)
Determines if this ldap path ends with a certian path. If the argument path is empty (no names in path) this methid will return false.

Specified by:
endsWith in interface javax.naming.Name
Parameters:
name - The suffix to check for

addAll

public javax.naming.Name addAll(javax.naming.Name name)
                         throws javax.naming.InvalidNameException
Specified by:
addAll in interface javax.naming.Name
Throws:
javax.naming.InvalidNameException

addAll

public javax.naming.Name addAll(int arg0,
                                javax.naming.Name name)
                         throws javax.naming.InvalidNameException
Specified by:
addAll in interface javax.naming.Name
Throws:
javax.naming.InvalidNameException

add

public javax.naming.Name add(java.lang.String string)
                      throws javax.naming.InvalidNameException
Specified by:
add in interface javax.naming.Name
Throws:
javax.naming.InvalidNameException

add

public javax.naming.Name add(int index,
                             java.lang.String string)
                      throws javax.naming.InvalidNameException
Specified by:
add in interface javax.naming.Name
Throws:
javax.naming.InvalidNameException

remove

public java.lang.Object remove(int arg0)
                        throws javax.naming.InvalidNameException
Specified by:
remove in interface javax.naming.Name
Throws:
javax.naming.InvalidNameException

removeLast

public LdapRdn removeLast()
Remove the ldast part of this DistinguishedName.

Returns:
the removed LdapRdn.

add

public void add(java.lang.String key,
                java.lang.String value)
Add a new LdapRdn using the supplied key and value.

Parameters:
key - the key of the LdapRdn.
value - the value of the LdapRdn.

add

public void add(LdapRdn rdn)
Add the supplied LdapRdn last in the list of Rdns.

Parameters:
rdn - the LdapRdn to add.

add

public void add(int idx,
                LdapRdn rdn)
Add the supplied LdapRdn att the specified index.

Parameters:
idx - the index at which to add the LdapRdn.
rdn - the LdapRdn to add.


Copyright 2002-2006. All Rights Reserved.