public class Dn extends Object implements Iterable<Rdn>, Externalizable
Modifier and Type | Field and Description |
---|---|
static Dn |
EMPTY_DN
A null Dn
|
static int |
EQUAL
Value returned by the compareTo method if values are equals
|
static int |
NOT_EQUAL
Value returned by the compareTo method if values are not equals
|
static Dn |
ROOT_DSE
The rootDSE
|
Constructor and Description |
---|
Dn()
Construct an empty Dn object
|
Dn(Rdn... rdns)
Creates a Dn from a list of Rdns.
|
Dn(Rdn rdn,
Dn dn)
Creates a Dn concatenating a Rdn and a Dn.
|
Dn(SchemaManager schemaManager)
Construct an empty Schema aware Dn object
|
Dn(SchemaManager schemaManager,
Dn dn)
Construct an empty Schema aware Dn object
|
Dn(SchemaManager schemaManager,
Rdn... rdns)
Creates a Schema aware Dn from a list of Rdns.
|
Dn(SchemaManager schemaManager,
String... upRdns)
Creates a new instance of schema aware Dn, using varargs to declare the RDNs.
|
Dn(String... upRdns)
Creates a new instance of Dn, using varargs to declare the RDNs.
|
Modifier and Type | Method and Description |
---|---|
Dn |
add(Dn suffix)
Add a suffix to the Dn.
|
Dn |
add(Rdn newRdn)
Adds a single Rdn to the (leaf) end of this name.
|
Dn |
add(String comp)
Add a suffix to the Dn.
|
boolean |
equals(Object obj) |
Dn |
getAncestorOf(Dn descendant)
Get the ancestor of a given DN, using the descendant DN.
|
Dn |
getAncestorOf(String descendant)
Get the ancestor of a given DN, using the descendant DN.
|
Dn |
getDescendantOf(Dn ancestor)
Get the descendant of a given DN, using the ancestr DN.
|
Dn |
getDescendantOf(String ancestor)
Get the descendant of a given DN, using the ancestr DN.
|
String |
getEscaped() |
String |
getName()
Get the user provided Dn
|
String |
getNormName()
Get the normalized Dn
|
Dn |
getParent()
Gets the parent Dn of this Dn.
|
Rdn |
getRdn()
Retrieves the last (leaf) component of this name.
|
Rdn |
getRdn(int posn)
Retrieves a component of this name.
|
List<Rdn> |
getRdns()
Retrieves all the components of this name.
|
SchemaManager |
getSchemaManager()
Get the associated SchemaManager if any.
|
int |
hashCode()
Gets the hash code of this Dn.
|
boolean |
isAncestorOf(Dn dn)
Tells if the current Dn is a parent of another Dn.
For instance, dc=com is a ancestor of dc=example, dc=com |
boolean |
isAncestorOf(String dn)
Tells if the current Dn is a parent of another Dn.
For instance, dc=com is a ancestor of dc=example, dc=com |
boolean |
isDescendantOf(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=com |
boolean |
isDescendantOf(String dn)
Tells if a Dn is a child of another Dn.
For instance, dc=example, dc=com is a descendant of dc=com |
boolean |
isEmpty()
Tells if the Dn contains no Rdn
|
static boolean |
isNullOrEmpty(Dn dn)
Check if a DistinguishedName is null or empty.
|
boolean |
isRootDse()
Tells if the Dn is the RootDSE Dn (ie, an empty Dn)
|
boolean |
isSchemaAware()
Tells if the Dn is schema aware
|
static boolean |
isValid(SchemaManager schemaManager,
String name)
Check if a DistinguishedName is syntactically valid.
|
static boolean |
isValid(String name)
Check if a DistinguishedName is syntactically valid.
|
Iterator<Rdn> |
iterator()
Iterate over the inner Rdn.
|
void |
readExternal(ObjectInput in) |
int |
size()
Get the number of RDNs present in the DN
|
String |
toString()
Return the user provided Dn as a String.
|
void |
writeExternal(ObjectOutput out) |
forEach, spliterator
public static final int NOT_EQUAL
public static final int EQUAL
public Dn()
public Dn(SchemaManager schemaManager)
schemaManager
- The SchemaManager to usepublic Dn(SchemaManager schemaManager, Dn dn) throws LdapInvalidDnException
schemaManager
- The SchemaManager to usedn
- The Dn to useLdapInvalidDnException
- If the Dn is invalidpublic Dn(String... upRdns) throws LdapInvalidDnException
String exampleName = "example"; String baseDn = "dc=apache,dc=org"; Dn dn = new Dn( DefaultSchemaManager.INSTANCE, "cn=Test", "ou", exampleName, baseDn);
upRdns
- The list of String composing the DnLdapInvalidDnException
- If the resulting Dn is invalidpublic Dn(SchemaManager schemaManager, String... upRdns) throws LdapInvalidDnException
String exampleName = "example"; String baseDn = "dc=apache,dc=org"; Dn dn = new Dn( DefaultSchemaManager.INSTANCE, "cn=Test", "ou", exampleName, baseDn);
schemaManager
- the schema managerupRdns
- The list of String composing the DnLdapInvalidDnException
- If the resulting Dn is invalidpublic Dn(Rdn... rdns) throws LdapInvalidDnException
rdns
- the list of Rdns to be used for the DnLdapInvalidDnException
- If the resulting Dn is invalidpublic Dn(Rdn rdn, Dn dn) throws LdapInvalidDnException
rdn
- the Rdn to add to the Dndn
- the DnLdapInvalidDnException
- If the resulting Dn is invalidpublic Dn(SchemaManager schemaManager, Rdn... rdns) throws LdapInvalidDnException
schemaManager
- The SchemaManager to userdns
- the list of Rdns to be used for the DnLdapInvalidDnException
- If the resulting Dn is invalidpublic SchemaManager getSchemaManager()
public int hashCode()
hashCode
in class Object
Object.hashCode()
public String getNormName()
public String getEscaped()
public int size()
public boolean isAncestorOf(String dn)
dn
- The childpublic boolean isAncestorOf(Dn dn)
dn
- The childpublic boolean isDescendantOf(String dn)
dn
- The parentpublic boolean isDescendantOf(Dn dn)
dn
- The parentpublic boolean isEmpty()
true
if the Dn is emptypublic boolean isRootDse()
true
if the Dn is the RootDSE's Dnpublic Rdn getRdn(int posn)
posn
- the 0-based index of the component to retrieve. Must be in the
range [0,size()).ArrayIndexOutOfBoundsException
- if posn is outside the specified rangepublic Rdn getRdn()
public List<Rdn> getRdns()
public Dn getDescendantOf(String ancestor) throws LdapInvalidDnException
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"
ancestor
- The parent DNLdapInvalidDnException
- If the Dn is invalidpublic Dn getDescendantOf(Dn ancestor) throws LdapInvalidDnException
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"
ancestor
- The parent DNLdapInvalidDnException
- If the Dn is invalidpublic Dn getAncestorOf(String descendant) throws LdapInvalidDnException
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"
descendant
- The child DNLdapInvalidDnException
- If the Dn is invalidpublic Dn getAncestorOf(Dn descendant) throws LdapInvalidDnException
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"
descendant
- The child DNLdapInvalidDnException
- If the Dn is invalidpublic Dn add(Dn suffix) throws LdapInvalidDnException
suffix
- the suffix to addLdapInvalidDnException
- If the resulting Dn is not validpublic Dn add(String comp) throws LdapInvalidDnException
comp
- the suffix to addLdapInvalidDnException
- If the resulting Dn is not validpublic Dn add(Rdn newRdn) throws LdapInvalidDnException
newRdn
- the Rdn to addLdapInvalidDnException
- If the Dn is invalidpublic Dn getParent()
public boolean equals(Object obj)
equals
in class Object
true
if the two instances are equalsObject.equals(java.lang.Object)
public boolean isSchemaAware()
true
if the Dn is schema aware.public Iterator<Rdn> iterator()
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
public static boolean isNullOrEmpty(Dn dn)
dn
- The Dn to checktrue
if the Dn is null or empty, false
otherwisepublic static boolean isValid(String name)
name
- The Dn to validatetrue
if the Dn is valid, false
otherwisepublic static boolean isValid(SchemaManager schemaManager, String name)
schemaManager
- The SchemaManager to usename
- The Dn to validatetrue
if the Dn is valid, false
otherwisepublic void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal
in interface Externalizable
IOException
ClassNotFoundException
public void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
IOException
Copyright © 2003–2020 The Apache Software Foundation. All rights reserved.