Class Dn
java.lang.Object
org.apache.directory.api.ldap.model.name.Dn
- All Implemented Interfaces:
Externalizable, Serializable, Iterable<Rdn>
The Dn class contains a Dn (Distinguished Name). This class is immutable.
Its specification can be found in RFC 2253, "UTF-8 String Representation of Distinguished Names".
We will store two representation of a Dn :
Rdn[n], Rdn[n-1], ... Rdn[1], Rdn[0]
It represents a position in a hierarchy, in which the root is the last Rdn (Rdn[0]) and the leaf is the first Rdn (Rdn[n]).
Its specification can be found in RFC 2253, "UTF-8 String Representation of Distinguished Names".
We will store two representation of a Dn :
- a user Provider representation, which is the parsed String given by a user
- an internal representation.
Rdn[n], Rdn[n-1], ... Rdn[1], Rdn[0]
It represents a position in a hierarchy, in which the root is the last Rdn (Rdn[0]) and the leaf is the first Rdn (Rdn[n]).
- Author:
- Apache Directory Project
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DnA null Dnstatic final intValue returned by the compareTo method if values are equalsprotected static final org.slf4j.LoggerThe LoggerFactory used by this classstatic final intValue returned by the compareTo method if values are not equalsThe RDNs that are elements of the Dn
NOTE THAT THESE ARE IN THE OPPOSITE ORDER FROM THAT IMPLIED BY THE JAVADOC!static final DnThe rootDSE -
Constructor Summary
ConstructorsConstructorDescriptionDn()Construct an empty Dn objectCreates a new instance of Dn, using varargs to declare the RDNs.Creates a Dn from a list of Rdns.Creates a Dn concatenating a Rdn and a Dn.Dn(SchemaManager schemaManager) Construct an empty Schema aware Dn objectDn(SchemaManager schemaManager, byte[] bytes) Creates a new instance of schema aware Dn, from a byte[] representation of an UTF-8 String.Dn(SchemaManager schemaManager, String... upRdns) Creates a new instance of schema aware Dn, using varargs to declare the RDNs.Dn(SchemaManager schemaManager, Dn dn) Construct an empty Schema aware Dn objectDn(SchemaManager schemaManager, Rdn... rdns) Creates a Schema aware Dn from a list of Rdns. -
Method Summary
Modifier and TypeMethodDescriptionAdds a single Rdn to the (leaf) end of this name.Adds all RDNs of the provided DN to the (leaf) end of this name.Adds a single Rdn to the (leaf) end of this name.booleangetAncestorOf(String descendant) Get the ancestor of a given DN, using the descendant DN.getAncestorOf(Dn descendant) Get the ancestor of a given DN, using the descendant DN.getDescendantOf(String ancestor) Get the descendant of a given DN, using the ancestr DN.getDescendantOf(Dn ancestor) Get the descendant of a given DN, using the ancestor DN.getName()Get the user provided DnGet the normalized DnGets the parent Dn of this Dn.getRdn()Retrieves the last (leaf) component of this name.getRdn(int posn) Retrieves a component of this name.getRdns()Retrieves all the components of this name.Get the associated SchemaManager if any.inthashCode()Gets the hash code of this Dn.booleanisAncestorOf(String dn) Tells if the current Dn is a parent of another Dn.
For instance, dc=com is a ancestor of dc=example, dc=combooleanisAncestorOf(Dn dn) Tells if the current Dn is a parent of another Dn.
For instance, dc=com is a ancestor of dc=example, dc=combooleanisDescendantOf(String dn) Tells if a Dn is a child of another Dn.
For instance, dc=example, dc=com is a descendant of dc=combooleanisDescendantOf(Dn dn) Tells if a Dn is a child of another Dn.
For instance, dc=example, dc=apache, dc=com is a descendant of dc=combooleanisEmpty()Tells if the Dn contains no Rdnstatic booleanisNullOrEmpty(Dn dn) Check if a DistinguishedName is null or empty.booleanTells if the Dn is the RootDSE Dn (ie, an empty Dn)booleanTells if the Dn is schema awarestatic booleanCheck if a DistinguishedName is syntactically valid.static booleanisValid(SchemaManager schemaManager, String name) Check if a DistinguishedName is syntactically valid.iterator()Iterate over the inner Rdn.voidintsize()Get the number of RDNs present in the DNtoString()Return the user provided Dn as a String.voidMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
LOG
protected static final org.slf4j.Logger LOGThe LoggerFactory used by this class -
NOT_EQUAL
public static final int NOT_EQUALValue returned by the compareTo method if values are not equals- See Also:
-
EQUAL
public static final int EQUALValue returned by the compareTo method if values are equals- See Also:
-
rdns
The RDNs that are elements of the Dn
NOTE THAT THESE ARE IN THE OPPOSITE ORDER FROM THAT IMPLIED BY THE JAVADOC!
Rdn[0] is rdns.get(n) and Rdn[n] is rdns.get(0)
For instance,if the Dn is "dc=c, dc=b, dc=a", then the RDNs are stored as :- [0] : dc=c
- [1] : dc=b
- [2] : dc=a
-
EMPTY_DN
A null Dn -
ROOT_DSE
The rootDSE
-
-
Constructor Details
-
Dn
public Dn()Construct an empty Dn object -
Dn
Construct an empty Schema aware Dn object- Parameters:
schemaManager- The SchemaManager to use
-
Dn
Construct an empty Schema aware Dn object- Parameters:
schemaManager- The SchemaManager to usedn- The Dn to use- Throws:
LdapInvalidDnException- If the Dn is invalid
-
Dn
Creates a new instance of Dn, using varargs to declare the RDNs. Each String is either a full Rdn, or a couple of AttributeType DI and a value. If the String contains a '=' symbol, the the constructor will assume that the String arg contains a full Rdn, otherwise, it will consider that the following arg is the value.
The created Dn is Schema aware.
An example of usage would be :String exampleName = "example"; String baseDn = "dc=apache,dc=org"; Dn dn = new Dn( DefaultSchemaManager.INSTANCE, "cn=Test", "ou", exampleName, baseDn);- Parameters:
upRdns- The list of String composing the Dn- Throws:
LdapInvalidDnException- If the resulting Dn is invalid
-
Dn
Creates a new instance of schema aware Dn, using varargs to declare the RDNs. Each String is either a full Rdn, or a couple of AttributeType and a value.
If the String contains a '=' symbol, the the constructor will assume that the String arg contains a full Rdn, otherwise, it will consider that the following arg is the value.
The created Dn is Schema aware.
An example of usage would be :String exampleName = "example"; String baseDn = "dc=apache,dc=org"; Dn dn = new Dn( DefaultSchemaManager.INSTANCE, "cn=Test", "ou", exampleName, baseDn);which will create the "cn=Test,ou=example" Dn.
If one single String is passed as an argument, then it will be considered as a full Dn.
Note that the method expect to receive a full Dn (one single value has been passed), many RDNs (in a <type> = <value> form) or pairs of attributeType/values.
It does not support receiving an incorrect RDN like "cn=" or "cn=test,dc="- Parameters:
schemaManager- the schema managerupRdns- The list of String composing the Dn- Throws:
LdapInvalidDnException- If the resulting Dn is invalid
-
Dn
Creates a new instance of schema aware Dn, from a byte[] representation of an UTF-8 String.- Parameters:
schemaManager- the schema managerbytes- The byte[] containing the DN as an UTF-8 encoded value- Throws:
LdapInvalidDnException- If the resulting Dn is invalid
-
Dn
Creates a Dn from a list of Rdns.- Parameters:
rdns- the list of Rdns to be used for the Dn- Throws:
LdapInvalidDnException- If the resulting Dn is invalid
-
Dn
Creates a Dn concatenating a Rdn and a Dn.- Parameters:
rdn- the Rdn to add to the Dndn- the Dn- Throws:
LdapInvalidDnException- If the resulting Dn is invalid
-
Dn
Creates a Schema aware Dn from a list of Rdns.- Parameters:
schemaManager- The SchemaManager to userdns- the list of Rdns to be used for the Dn- Throws:
LdapInvalidDnException- If the resulting Dn is invalid
-
-
Method Details
-
getSchemaManager
Get the associated SchemaManager if any.- Returns:
- The SchemaManager
-
hashCode
-
getName
-
getNormName
-
getEscaped
- Returns:
- The RDN as an escaped String
-
size
public int size()Get the number of RDNs present in the DN- Returns:
- The umber of RDNs in the DN
-
isAncestorOf
Tells if the current Dn is a parent of another Dn.
For instance, dc=com is a ancestor of dc=example, dc=com- Parameters:
dn- The child- Returns:
- true if the current Dn is a parent of the given Dn
-
isAncestorOf
Tells if the current Dn is a parent of another Dn.
For instance, dc=com is a ancestor of dc=example, dc=com- Parameters:
dn- The child- Returns:
- true if the current Dn is a parent of the given Dn
-
isDescendantOf
Tells if a Dn is a child of another Dn.
For instance, dc=example, dc=com is a descendant of dc=com- Parameters:
dn- The parent- Returns:
- true if the current Dn is a child of the given Dn
-
isDescendantOf
Tells if a Dn is a child of another Dn.
For instance, dc=example, dc=apache, dc=com is a descendant of dc=com- Parameters:
dn- The parent- Returns:
- true if the current Dn is a child of the given Dn
-
isEmpty
public boolean isEmpty()Tells if the Dn contains no Rdn- Returns:
trueif the Dn is empty
-
isRootDse
public boolean isRootDse()Tells if the Dn is the RootDSE Dn (ie, an empty Dn)- Returns:
trueif the Dn is the RootDSE's Dn
-
getRdn
Retrieves a component of this name.- Parameters:
posn- the 0-based index of the component to retrieve. Must be in the range [0,size()).- Returns:
- the component at index posn
- Throws:
ArrayIndexOutOfBoundsException- if posn is outside the specified range
-
getRdn
Retrieves the last (leaf) component of this name.- Returns:
- the last component of this Dn
-
getRdns
-
getDescendantOf
Get the descendant of a given DN, using the ancestr DN. Assuming that a DN has two parts :
DN = [descendant DN][ancestor DN]
To get back the descendant from the full DN, you just pass the ancestor DN as a parameter. Here is a working example :Dn dn = new Dn( "cn=test, dc=server, dc=directory, dc=apache, dc=org" ); Dn descendant = dn.getDescendantOf( "dc=apache, dc=org" ); // At this point, the descendant contains cn=test, dc=server, dc=directory"
- Parameters:
ancestor- The parent DN- Returns:
- The part of the DN that is the descendant
- Throws:
LdapInvalidDnException- If the Dn is invalid
-
getDescendantOf
Get the descendant of a given DN, using the ancestor DN. Assuming that a DN has two parts :
DN = [descendant DN][ancestor DN]
To get back the descendant from the full DN, you just pass the ancestor DN as a parameter. Here is a working example :Dn dn = new Dn( "cn=test, dc=server, dc=directory, dc=apache, dc=org" ); Dn descendant = dn.getDescendantOf( "dc=apache, dc=org" ); // At this point, the descendant contains cn=test, dc=server, dc=directory"
- Parameters:
ancestor- The parent DN- Returns:
- The part of the DN that is the descendant
- Throws:
LdapInvalidDnException- If the Dn is invalid
-
getAncestorOf
Get the ancestor of a given DN, using the descendant DN. Assuming that a DN has two parts :
DN = [descendant DN][ancestor DN]
To get back the ancestor from the full DN, you just pass the descendant DN as a parameter. Here is a working example :Dn dn = new Dn( "cn=test, dc=server, dc=directory, dc=apache, dc=org" ); Dn ancestor = dn.getAncestorOf( "cn=test, dc=server, dc=directory" ); // At this point, the ancestor contains "dc=apache, dc=org"
- Parameters:
descendant- The child DN- Returns:
- The part of the DN that is the ancestor
- Throws:
LdapInvalidDnException- If the Dn is invalid
-
getAncestorOf
Get the ancestor of a given DN, using the descendant DN. Assuming that a DN has two parts :
DN = [descendant DN][ancestor DN]
To get back the ancestor from the full DN, you just pass the descendant DN as a parameter. Here is a working example :Dn dn = new Dn( "cn=test, dc=server, dc=directory, dc=apache, dc=org" ); Dn ancestor = dn.getAncestorOf( new Dn( "cn=test, dc=server, dc=directory" ) ); // At this point, the ancestor contains "dc=apache, dc=org"
- Parameters:
descendant- The child DN- Returns:
- The part of the DN that is the ancestor
- Throws:
LdapInvalidDnException- If the Dn is invalid
-
add
Adds all RDNs of the provided DN to the (leaf) end of this name. For instance, if the current Dn is "dc=example,dc=com", and the rdns "ou=people", then the resulting Dn will be "ou=people,dc=example,dc=com".- Parameters:
rdns- the RDNs to add- Returns:
- the updated cloned Dn
- Throws:
LdapInvalidDnException- If the resulting Dn is not valid
-
add
Adds a single Rdn to the (leaf) end of this name. For instance, if the current Dn is "dc=example,dc=com", and the rdn "ou=people", then the resulting Dn will be "ou=people,dc=example,dc=com".- Parameters:
rdn- the Rdn to add- Returns:
- the updated cloned Dn
- Throws:
LdapInvalidDnException- If the resulting Dn is not valid
-
add
Adds a single Rdn to the (leaf) end of this name.- Parameters:
newRdn- the Rdn to add- Returns:
- the updated cloned Dn
- Throws:
LdapInvalidDnException- If the Dn is invalid
-
getParent
Gets the parent Dn of this Dn. Null if this Dn doesn't have a parent, i.e. because it is the empty Dn.
The Parent is the right part of the Dn, when the Rdn has been removed.- Returns:
- the parent Dn of this Dn
-
equals
-
isSchemaAware
public boolean isSchemaAware()Tells if the Dn is schema aware- Returns:
trueif the Dn is schema aware.
-
iterator
Iterate over the inner Rdn. The Rdn are returned from the rightmost to the leftmost. For instance, the following code :
Dn dn = new Dn( "sn=test, dc=apache, dc=org ); for ( Rdn rdn : dn ) { System.out.println( rdn.toString() ); }will produce this output :
dc=org dc=apache sn=test
-
isNullOrEmpty
Check if a DistinguishedName is null or empty.- Parameters:
dn- The Dn to check- Returns:
trueif the Dn is null or empty,falseotherwise
-
isValid
Check if a DistinguishedName is syntactically valid.- Parameters:
name- The Dn to validate- Returns:
trueif the Dn is valid,falseotherwise
-
isValid
Check if a DistinguishedName is syntactically valid.- Parameters:
schemaManager- The SchemaManager to usename- The Dn to validate- Returns:
trueif the Dn is valid,falseotherwise
-
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
toString
-