org.apache.directory.shared.ldap.name
Class Rdn

java.lang.Object
  extended byorg.apache.directory.shared.ldap.name.Rdn
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable, java.io.Serializable

public class Rdn
extends java.lang.Object
implements java.lang.Cloneable, java.lang.Comparable, java.io.Serializable

This class store the name-component part or the following BNF grammar (as of RFC2253, par. 3, and RFC1779, fig. 1) :
- <name-component> ::= <attributeType> <spaces> '=' <spaces> <attributeValue> <attributeTypeAndValues>
- <attributeTypeAndValues> ::= <spaces> '+' <spaces> <attributeType> <spaces> '=' <spaces> <attributeValue> <attributeTypeAndValues> | e
- <attributeType> ::= [a-zA-Z] <keychars> | <oidPrefix> [0-9] <digits> <oids> | [0-9] <digits> <oids>
- <keychars> ::= [a-zA-Z] <keychars> | [0-9] <keychars> | '-' <keychars> | e
- <oidPrefix> ::= 'OID.' | 'oid.' | e
- <oids> ::= '.' [0-9] <digits> <oids> | e
- <attributeValue> ::= <pairs-or-strings> | '#' <hexstring> |'"' <quotechar-or-pairs> '"'
- <pairs-or-strings> ::= '\' <pairchar> <pairs-or-strings> | <stringchar> <pairs-or-strings> | e
- <quotechar-or-pairs> ::= <quotechar> <quotechar-or-pairs> | '\' <pairchar> <quotechar-or-pairs> | e
- <pairchar> ::= ',' | '=' | '+' | '<' | '>' | '#' | ';' | '\' | '"' | [0-9a-fA-F] [0-9a-fA-F]
- <hexstring> ::= [0-9a-fA-F] [0-9a-fA-F] <hexpairs>
- <hexpairs> ::= [0-9a-fA-F] [0-9a-fA-F] <hexpairs> | e
- <digits> ::= [0-9] <digits> | e
- <stringchar> ::= [0x00-0xFF] - [,=+<>#;\"\n\r]
- <quotechar> ::= [0x00-0xFF] - [\"]
- <separator> ::= ',' | ';'
- <spaces> ::= ' ' <spaces> | e

A RDN is a part of a DN. It can be composed of many types, as in the RDN following RDN :
ou=value + cn=other value

or
ou=value + ou=another value

In this case, we have to store an 'ou' and a 'cn' in the RDN.

The types are case insensitive.
Spaces before and after types and values are not stored.
Spaces before and after '+' are not stored.

Thus, we can consider that the following RDNs are equals :

'ou=test 1'
' ou=test 1'
'ou =test 1'
'ou= test 1'
'ou=test 1 '
' ou = test 1 '

So are the following :

'ou=test 1+cn=test 2'
'ou = test 1 + cn = test 2'
' ou =test 1+ cn =test 2 '
'cn = test 2 +ou = test 1'

but the following are not equal :
'ou=test 1'
'ou=test 1'
because we have more than one spaces inside the value.

The Rdn is composed of one or more AttributeTypeAndValue (atav) Those atavs are ordered in the alphabetical natural order : a < b < c ... < z As the type are not case sensitive, we can say that a = A

Author:
Apache Directory Project
See Also:
Serialized Form

Field Summary
static int EQUALS
           
static int INFERIOR
           
static int SUPERIOR
           
static int UNDEFINED
          CompareTo() results
 
Constructor Summary
Rdn()
          A empty constructor.
Rdn(byte[] bytes)
          A constructor that parse a RDN from a byte array.
Rdn(Rdn rdn)
          Constructs an Rdn from the given rdn.
Rdn(java.lang.String rdn)
          A constructor that parse a String RDN
Rdn(java.lang.String type, java.lang.String value)
          A constructor that constructs a RDN from a type and a value.
 
Method Summary
 void clear()
          Clear the RDN, removing all the AttributeTypeAndValues.
 java.lang.Object clone()
          Clone the Rdn
 int compareTo(java.lang.Object object)
          Compares two RDNs.
 boolean equals(java.lang.Object rdn)
          Compares the specified Object with this Rdn for equality.
static java.lang.String escapeValue(java.lang.Object attrValue)
          Transform a value in a String, accordingly to RFC 2253
 AttributeTypeAndValue getAtav()
          Return the unique AttributeTypeAndValue, or the first one of we have more than one
 AttributeTypeAndValue getAttributeTypeAndValue(java.lang.String type)
          Get the AttributeTypeAndValue which type is given as an argument.
 int getNbAtavs()
           
 java.lang.String getType()
          Return the type, or the first one of we have more than one (the lowest)
 java.lang.String getUpName()
          Returns a String representation of the RDN
 java.lang.String getValue()
          Return the value, or the first one of we have more than one (the lowest)
 java.lang.String getValue(java.lang.String type)
          Get the Value of the AttributeTypeAndValue which type is given as an argument.
 int hashcode()
          Returns the hash code of this RDN.
 java.util.Iterator iterator()
          Retrieves the components of this name as an enumeration of strings.
 void setUpName(java.lang.String upName)
          Set the User Provided Name
 int size()
          Get the number of Attribute type and value of this Rdn
 javax.naming.directory.Attributes toAttributes()
          Transform the Rdn into an javax.naming.directory.Attributes
 java.lang.String toString()
          Returns a String representation of the RDN
static java.lang.Object unescapeValue(java.lang.String value)
          Unescape the given string according to RFC 2253 If in form, a LDAP string representation asserted value can be obtained by replacing (left-to-right, non-recursively) each appearing in the as follows: replace with ; replace with ; replace with the octet indicated by the If in form, a BER representation can be obtained from converting each of the to the octet indicated by the
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

UNDEFINED

public static final int UNDEFINED
CompareTo() results

See Also:
Constant Field Values

SUPERIOR

public static final int SUPERIOR
See Also:
Constant Field Values

INFERIOR

public static final int INFERIOR
See Also:
Constant Field Values

EQUALS

public static final int EQUALS
See Also:
Constant Field Values
Constructor Detail

Rdn

public Rdn()
A empty constructor.


Rdn

public Rdn(java.lang.String rdn)
    throws javax.naming.InvalidNameException
A constructor that parse a String RDN

Parameters:
rdn - The String containing the RDN to parse
Throws:
javax.naming.InvalidNameException - If the RDN is invalid

Rdn

public Rdn(byte[] bytes)
    throws javax.naming.InvalidNameException
A constructor that parse a RDN from a byte array. This method is called when whe get a LdapMessage which contains a byte array representing the ASN.1 RelativeRDN

Throws:
javax.naming.InvalidNameException - If the RDN is invalid

Rdn

public Rdn(java.lang.String type,
           java.lang.String value)
    throws javax.naming.InvalidNameException
A constructor that constructs a RDN from a type and a value. Constructs an Rdn from the given attribute type and value. The string attribute values are not interpretted as RFC 2253 formatted RDN strings. That is, the values are used literally (not parsed) and assumed to be unescaped.

Parameters:
type - The type of the RDN
value - The value of the RDN
Throws:
javax.naming.InvalidNameException - If the RDN is invalid

Rdn

public Rdn(Rdn rdn)
Constructs an Rdn from the given rdn. The contents of the rdn are simply copied into the newly created

Parameters:
rdn - The non-null Rdn to be copied.
Method Detail

clear

public void clear()
Clear the RDN, removing all the AttributeTypeAndValues.


getValue

public java.lang.String getValue(java.lang.String type)
                          throws javax.naming.InvalidNameException
Get the Value of the AttributeTypeAndValue which type is given as an argument.

Parameters:
type - The type of the NameArgument
Returns:
The Value to be returned, or null if none found.
Throws:
javax.naming.InvalidNameException

getAttributeTypeAndValue

public AttributeTypeAndValue getAttributeTypeAndValue(java.lang.String type)
Get the AttributeTypeAndValue which type is given as an argument. If we have more than one value associated with the type, we will return only the first one.

Parameters:
type - The type of the NameArgument to be returned
Returns:
The AttributeTypeAndValue, of null if none is found.

iterator

public java.util.Iterator iterator()
Retrieves the components of this name as an enumeration of strings. The effect on the enumeration of updates to this name is undefined. If the name has zero components, an empty (non-null) enumeration is returned.

Returns:
an enumeration of the components of this name, each a string

clone

public java.lang.Object clone()
Clone the Rdn


compareTo

public int compareTo(java.lang.Object object)
Compares two RDNs. They are equals if : - their have the same number of NC (AttributeTypeAndValue) - each ATAVs are equals - comparizon of type are done case insensitive - each value is equel, case sensitive - Order of ATAV is not important If the RDNs are not equals, a positive number is returned if the first RDN is greated, negative otherwise

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
object -
Returns:
0 if both rdn are equals. -1 if the current RDN is inferior, 1 if teh current Rdn is superioir, UNDIFIED otherwise.

toString

public java.lang.String toString()
Returns a String representation of the RDN


getUpName

public java.lang.String getUpName()
Returns a String representation of the RDN


setUpName

public void setUpName(java.lang.String upName)
Set the User Provided Name


getNbAtavs

public int getNbAtavs()
Returns:
Returns the nbAtavs.

getAtav

public AttributeTypeAndValue getAtav()
Return the unique AttributeTypeAndValue, or the first one of we have more than one

Returns:
The first AttributeTypeAndValue of this RDN

getType

public java.lang.String getType()
Return the type, or the first one of we have more than one (the lowest)

Returns:
The first type of this RDN

getValue

public java.lang.String getValue()
Return the value, or the first one of we have more than one (the lowest)

Returns:
The first value of this RDN

equals

public boolean equals(java.lang.Object rdn)
Compares the specified Object with this Rdn for equality. Returns true if the given object is also a Rdn and the two Rdns represent the same attribute type and value mappings. The order of components in multi-valued Rdns is not significant.

Parameters:
rdn - Rdn to be compared for equality with this Rdn
Returns:
true if the specified object is equal to this Rdn

hashcode

public int hashcode()
Returns the hash code of this RDN. Two RDNs that are equal (according to the equals method) will have the same hash code.


size

public int size()
Get the number of Attribute type and value of this Rdn

Returns:
The number of ATAVs in this Rdn

toAttributes

public javax.naming.directory.Attributes toAttributes()
Transform the Rdn into an javax.naming.directory.Attributes

Returns:
An attributes structure containing all the ATAVs

unescapeValue

public static java.lang.Object unescapeValue(java.lang.String value)
                                      throws java.lang.IllegalArgumentException
Unescape the given string according to RFC 2253 If in form, a LDAP string representation asserted value can be obtained by replacing (left-to-right, non-recursively) each appearing in the as follows: replace with ; replace with ; replace with the octet indicated by the If in form, a BER representation can be obtained from converting each of the to the octet indicated by the

Parameters:
value - The value to be unescaped
Returns:
Returns a string value as a String, and a binary value as a byte array.
Throws:
java.lang.IllegalArgumentException - - When an Illegal value is provided.

escapeValue

public static java.lang.String escapeValue(java.lang.Object attrValue)
Transform a value in a String, accordingly to RFC 2253

Parameters:
attrValue - The attribute value to be escaped
Returns:
The escaped string value.


Copyright © 2003-2006 . All Rights Reserved.