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
|
protected static org.slf4j.Logger |
LOG
The LoggerFactory used by this class
|
static int |
NOT_EQUAL
Value returned by the compareTo method if values are not equals
|
protected List<Rdn> |
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 |
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,
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) |
Dn |
add(Rdn newRdn)
Adds a single Rdn to the (leaf) end of this name.
|
Dn |
add(String comp) |
Dn |
apply(SchemaManager schemaManager)
Normalizes the Dn using the given the schema manager
|
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.
|
static byte[] |
getBytes(Dn dn)
Get an UTF-8 representation of the normalized form of the 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 |
getName()
Get the user provided Dn
|
static int |
getNbBytes(Dn dn)
Get the number of bytes necessary to store this 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(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) |
protected static final org.slf4j.Logger LOG
public static final int NOT_EQUAL
public static final int EQUAL
protected List<Rdn> rdns
public Dn()
public Dn(SchemaManager schemaManager)
schemaManager
- The SchemaManager to usepublic 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);
schemaManager
- the schema managerupRdns
- 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()
Dn dn = new Dn( schemaManager, "ou = Example , ou = com" ); assert( "2.5.4.11=example,2.5.4.11=com".equals( dn.getNormName ) );Otherwise, it will return a Dn with the AttributeType in lower case and the value trimmed :
Dn dn = new Dn( " CN = A Test " ); assertEquals( "cn=A Test", dn.getNormName() );
public int size()
public static int getNbBytes(Dn dn)
dn
- The Dn.public static byte[] getBytes(Dn dn)
dn
- The Dn.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"
LdapInvalidDnException
public 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"
LdapInvalidDnException
public 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"
LdapInvalidDnException
public 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"
LdapInvalidDnException
public Dn add(Dn suffix) throws LdapInvalidDnException
LdapInvalidDnException
public Dn add(String comp) throws LdapInvalidDnException
LdapInvalidDnException
public Dn add(Rdn newRdn) throws LdapInvalidDnException
newRdn
- the Rdn to addLdapInvalidDnException
public Dn getParent()
public boolean equals(Object obj)
equals
in class Object
true
if the two instances are equalsObject.equals(java.lang.Object)
public Dn apply(SchemaManager schemaManager) throws LdapInvalidDnException
schemaManager
- The schemaManagerto use to normalize the DnLdapInvalidDnException
- If the Dn is invalid.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)
dn
- 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-2014 The Apache Software Foundation. All Rights Reserved.