netscape.ldap.util

Class DN

Implemented Interfaces:
Serializable

public final class DN
extends java.lang.Object
implements Serializable

Objects of this class represent distinguished names (DN). A distinguished name is used to identify an entry in a directory.

The netscape.ldap.LDAPDN class uses this class internally. In most cases, when working with DNs in the LDAP Java classes, you should use the netscape.ldap.LDAPDN class.

The following DNs are examples of the different formats for DNs that may appear:

Version:
1.0
See Also:
LDAPDN

Field Summary

static char[]
ESCAPED_CHAR
Array of the characters that may be escaped in a DN.
static int
OSF
Type specifying a DN in the OSF format.
static int
RFC
Type specifying a DN in the RFC format.

Constructor Summary

DN()
Constructs an empty DN object.
DN(String dn)
Constructs a DN object from the specified distinguished name.

Method Summary

void
addRDN(RDN rdn)
Adds the specified relative distinguished name (RDN) to the current DN.
void
addRDNToBack(RDN rdn)
Adds the specified relative distinguished name (RDN) to the end of the current DN.
void
addRDNToFront(RDN rdn)
Adds the specified relative distinguished name (RDN) to the beginning of the current DN.
boolean
contains(DN dn)
Deprecated. Please use isDescendantOf() instead.
int
countRDNs()
Returns the number of components that make up the current DN.
boolean
equals(DN dn)
Determines if the current DN is equal to the specified DN.
String[]
explodeDN(boolean noTypes)
Returns an array of the individual components that make up the current distinguished name.
int
getDNType()
Gets the type of format used for the DN (RFC format or OSF format).
DN
getParent()
Gets the parent DN for this DN.
Vector
getRDNs()
Returns a list of the components (RDN objects) that make up the current DN.
static boolean
isDN(String dn)
Determines if the given string is an distinguished name or not.
boolean
isDescendantOf(DN dn)
Determines if this DN is a descendant of the given DN.
boolean
isRFC()
Determines if the DN is in RFC 1485 format.
void
setDNType(int type)
Sets the type of format used for the DN (RFC format or OSF format).
String
toOSFString()
Returns the DN in OSF format.
String
toRFCString()
Returns the DN in RFC 1485 format.
String
toString()
Returns the string representation of the DN in its original format.

Field Details

ESCAPED_CHAR

public static final char[] ESCAPED_CHAR
Array of the characters that may be escaped in a DN.

OSF

public static int OSF
Type specifying a DN in the OSF format.


RFC

public static int RFC
Type specifying a DN in the RFC format.

Constructor Details

DN

public DN()
Constructs an empty DN object.

DN

public DN(String dn)
Constructs a DN object from the specified distinguished name. The string representation of the DN can be in RFC 1485 or OSF format.

Parameters:
dn - string representation of the distinguished name

Method Details

addRDN

public void addRDN(RDN rdn)
Adds the specified relative distinguished name (RDN) to the current DN. If the DN is in RFC 1485 format, the RDN is added to the beginning of the DN. If the DN is in OSF format, the RDN is appended to the end of the DN.

Parameters:
rdn - the relative distinguished name to add to the current DN
See Also:
RDN

addRDNToBack

public void addRDNToBack(RDN rdn)
Adds the specified relative distinguished name (RDN) to the end of the current DN.

Parameters:
rdn - the relative distinguished name to append to the current DN
See Also:
RDN

addRDNToFront

public void addRDNToFront(RDN rdn)
Adds the specified relative distinguished name (RDN) to the beginning of the current DN.

Parameters:
rdn - the relative distinguished name to add to the beginning of the current DN
See Also:
RDN

contains

public boolean contains(DN dn)

Deprecated. Please use isDescendantOf() instead.

Determines if the given DN is under the subtree defined by this DN.

For example, the following section of code determines if the DN specified by dn1 is under the subtree specified by dn2.

    DN dn1 = new DN("uid=bjensen, ou=People, o=Airius.com");
    DN dn2 = new DN("ou=People, o=Airius.com");

    boolean isContain = dn1.contains(dn2)
 
In this case, since "uid=bjensen, ou=People, o=Airius.com" is an entry under the subtree "ou=People, o=Airius.com", the value of isContain is true.

Parameters:
dn - the DN of a subtree to check
Returns:
true if the current DN belongs to the subtree specified by dn.

countRDNs

public int countRDNs()
Returns the number of components that make up the current DN.
Returns:
the number of components in this DN.

equals

public boolean equals(DN dn)
Determines if the current DN is equal to the specified DN.
Parameters:
dn - DN to compare against the current DN
Returns:
true if the two DNs are the same.

explodeDN

public String[] explodeDN(boolean noTypes)
Returns an array of the individual components that make up the current distinguished name.
Parameters:
noTypes - specify true to remove the attribute type and equals sign (for example, "cn=") from each component

getDNType

public int getDNType()
Gets the type of format used for the DN (RFC format or OSF format).

Returns:
one of the following constants: DN.RFC (if the DN is in RFC format) or DN.OSF (if the DN is in OSF format).

getParent

public DN getParent()
Gets the parent DN for this DN.

For example, the following section of code gets the parent DN of "uid=bjensen, ou=People, o=Airius.com."

    DN dn = new DN("uid=bjensen, ou=People, o=Airius.com");
    DN parent = dn.getParent();
 
The parent DN in this example is "ou=People, o=Airius.com".

Returns:
DN of the parent of this DN.

getRDNs

public Vector getRDNs()
Returns a list of the components (RDN objects) that make up the current DN.
Returns:
a list of the components of this DN.

isDN

public static boolean isDN(String dn)
Determines if the given string is an distinguished name or not.
Parameters:
dn - distinguished name
Returns:
true or false.

isDescendantOf

public boolean isDescendantOf(DN dn)
Determines if this DN is a descendant of the given DN.

For example, the following section of code determines if the DN specified by dn1 is a descendant of the DN specified by dn2.

    DN dn1 = new DN("uid=bjensen, ou=People, o=Airius.com");
    DN dn2 = new DN("ou=People, o=Airius.com");

    boolean isDescendant = dn1.isDescendantOf(dn2)
 
In this case, since "uid=bjensen, ou=People, o=Airius.com" is an entry under the subtree "ou=People, o=Airius.com", the value of isDescendant is true.

In the case where the given DN is equal to this DN it returns false.

Parameters:
dn - the DN of a subtree to check
Returns:
true if the current DN is a descendant of the DN specified by dn.

isRFC

public boolean isRFC()
Determines if the DN is in RFC 1485 format.
Returns:
true if the DN is in RFC 1485 format.

setDNType

public void setDNType(int type)
Sets the type of format used for the DN (RFC format or OSF format).

Parameters:
type - one of the following constants: DN.RFC (to use the RFC format) or DN.OSF (to use the OSF format)

toOSFString

public String toOSFString()
Returns the DN in OSF format.
Returns:
the DN in OSF format.

toRFCString

public String toRFCString()
Returns the DN in RFC 1485 format.
Returns:
the DN in RFC 1485 format.

toString

public String toString()
Returns the string representation of the DN in its original format. (For example, if the DN object was constructed from a DN in RFC 1485 format, this method returns the DN in RFC 1485 format.
Returns:
the string representation of the DN.