public class DN extends Object implements Cloneable, Serializable, Comparable<DN>, Iterable<RDN>
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)
|
Constructor and Description |
---|
DN()
Construct an empty DN object
|
DN(DN dn)
Copies a DN to an DN.
|
DN(String... upRdns)
Creates a new instance of DN, using varargs to declare the RDNs.
|
DN(String upName)
Parse a String and checks that it is a valid DN
|
Modifier and Type | Method and Description |
---|---|
DN |
add(int pos,
RDN newRdn)
Adds a single RDN to a specific position.
|
DN |
add(int posn,
String comp) |
DN |
add(RDN newRdn)
Adds a single RDN to the (leaf) end of this name.
|
DN |
add(String comp) |
DN |
addAll(DN suffix) |
DN |
addAll(int posn,
DN dn) |
DN |
addAll(int posn,
Name name) |
DN |
addAllNormalized(int posn,
DN name)
Adds the components of a name -- in order -- at a specified position
within this name.
|
DN |
addNormalized(RDN newRdn)
Adds a single normalized RDN to the (leaf) end of this name.
|
Object |
clone() |
int |
compareTo(DN dn) |
boolean |
equals(Object obj) |
static DN |
fromName(Name name)
Convert a
Name to a DN |
String |
get(int posn)
Get the given RDN as a String.
|
Enumeration<RDN> |
getAllRdn()
Retrieves the components of this name as an enumeration of strings.
|
static byte[] |
getBytes(DN dn)
Get an UTF-8 representation of the normalized form of the DN
|
String |
getName()
Get the initial DN
|
static int |
getNbBytes(DN dn)
Get the number of bytes necessary to store this DN
|
String |
getNormName()
Get the normalized DN
|
DN |
getPrefix(int posn) |
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.
|
DN |
getSuffix(int posn) |
int |
hashCode()
Gets the hash code of this name.
|
boolean |
hasSuffix(DN dn)
Determines whether this name has a specific suffix.
|
boolean |
isChildOf(DN dn)
Tells if a DN is a child of another DN.
For instance, dc=example, dc=com is a child of dc=com |
boolean |
isChildOf(String dn)
Tells if a DN is a child of another DN.
For instance, dc=example, dc=com is a child of dc=com |
boolean |
isEmpty()
return true if this DN contains no RDNs
|
boolean |
isNormalized()
Tells if the DN has already been normalized or not
|
boolean |
isParentOf(DN dn)
Tells if the current DN is a parent of another DN.
For instance, dc=com is a parent of dc=example, dc=com |
boolean |
isParentOf(String dn)
Tells if the current DN is a parent of another DN.
For instance, dc=com is a parent of dc=example, dc=com |
static boolean |
isValid(String dn)
Check if a DistinguishedName is syntactically valid.
|
Iterator<RDN> |
iterator() |
static DN |
normalize(DN dn,
Map<String,OidNormalizer> oidsMap)
Change the internal DN, using the OID instead of the first name or other
aliases.
|
DN |
normalize(Map<String,OidNormalizer> oidsMap)
Change the internal DN, using the OID instead of the first name or other
aliases.
|
static DN |
normalize(String name,
Map<String,OidNormalizer> oidsMap)
Static factory which creates a normalized DN from a String and a Map of OIDs.
|
void |
readExternal(ObjectInput in) |
RDN |
remove(int posn) |
int |
size() |
static Name |
toName(DN dn)
Convert a DN to a
Name |
String |
toString()
Return the normalized 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 static final DN EMPTY_DN
public DN()
public DN(DN dn) throws LdapInvalidDnException
name
- composed of String name components.LdapInvalidDnException
- If the Name is invalid.public DN(String upName) throws LdapInvalidDnException
<distinguishedName> ::= <name> | e
<name> ::= <name-component> <name-components>
<name-components> ::= <spaces> <separator>
<spaces> <name-component> <name-components> | e
upName
- The String that contains the DN.LdapInvalidNameException
- if the String does not contain a valid DN.LdapInvalidDnException
public DN(String... upRdns) throws LdapInvalidDnException
String exampleName = "example"; String baseDn = "dc=apache,dc=org"; DN dn = new DN( "cn=Test", "ou", exampleName, baseDn);
upNames
- LdapInvalidDnException
public static DN normalize(String name, Map<String,OidNormalizer> oidsMap) throws LdapInvalidDnException
name
- The DN as a StringoidsMap
- The OID mappingLdapInvalidNameException
- If the DN is invalid.LdapInvalidDnException
- If something went wrong.public String toString()
public int hashCode()
hashCode
in class Object
Object.hashCode()
public String getName()
public String getNormName()
public int size()
public static int getNbBytes(DN dn)
dn
- The DN.public static byte[] getBytes(DN dn)
dn
- The DN.public boolean isParentOf(String dn)
dn
- The childpublic boolean isParentOf(DN dn)
dn
- The childpublic boolean isChildOf(String dn)
dn
- The parentpublic boolean isChildOf(DN dn)
dn
- The parentpublic boolean hasSuffix(DN dn)
dn
- the name to checkpublic boolean isEmpty()
public String get(int posn)
dc=example,dc=apache,dc=orgthen :
get(0)
will return dc=orgget(1)
will return dc=apacheget(2)
will return dc=exampleposn
- The position of the wanted RDN in the DN.public 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 Enumeration<RDN> getAllRdn()
public DN getPrefix(int posn)
public DN getSuffix(int posn)
public DN addAllNormalized(int posn, DN name) throws LdapInvalidDnException
posn
- the index in this name at which to add the new components.
Must be in the range [0,size()]. Note this is from the opposite end as rnds.get(posn)name
- the components to addArrayIndexOutOfBoundsException
- if posn is outside the specified rangeLdapInvalidDnException
- if n is not a valid name, or if the addition of
the components would violate the syntax rules of this namepublic DN addAll(DN suffix) throws LdapInvalidDnException
LdapInvalidDnException
public DN addAll(int posn, Name name) throws InvalidNameException, LdapInvalidDnException
public DN addAll(int posn, DN dn) throws LdapInvalidDnException
LdapInvalidDnException
public DN add(String comp) throws LdapInvalidDnException
LdapInvalidDnException
public DN add(RDN newRdn)
newRdn
- the RDN to addpublic DN add(int pos, RDN newRdn)
newRdn
- the RDN to addpos
- The position where we want to add the Rdnpublic DN addNormalized(RDN newRdn)
newRdn
- the RDN to addpublic DN add(int posn, String comp) throws LdapInvalidDnException
LdapInvalidDnException
public RDN remove(int posn) throws LdapInvalidDnException
LdapInvalidDnException
public boolean equals(Object obj)
equals
in class Object
true
if the two instances are equalsObject.equals(java.lang.Object)
public int compareTo(DN dn)
compareTo
in interface Comparable<DN>
public static DN normalize(DN dn, Map<String,OidNormalizer> oidsMap) throws LdapInvalidDnException
dn
- The DN to transform.oidsMap
- The mapping between names and oids.LdapInvalidDnException
- If something went wrong.public DN normalize(Map<String,OidNormalizer> oidsMap) throws LdapInvalidDnException
oidsMap
- The mapping between names and oids.LdapInvalidDnException
- If something went wrong.public static boolean isValid(String dn)
dn
- The DN to validatetrue>
if the DN is valid, false
otherwisepublic boolean isNormalized()
true
if the DN is already normalized.public void writeExternal(ObjectOutput out) throws IOException
out
- The stream in which the DN will be serializedIOException
- If the serialization failWe have to store a DN data efficiently. Here is the structure :
- upName
The User provided DN
- normName
May be null if the normName is equaivalent to
the upName
- rdns
The rdn's List.
for each rdn :
- call the RDN write method
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
in
- The stream from which the DN is readIOException
- If the stream can't be readClassNotFoundException
- If the RDN can't be createdWe read back the data to create a new DN. The structure
read is exposed in the {@link DN#writeExternal(ObjectOutput)}
method
public static DN fromName(Name name)
Name
to a DNname
- The Name to convertpublic static Name toName(DN dn)
Name
name
- The DN to convertCopyright © 2003-2012 Apache Software Foundation. All Rights Reserved.