Class Rdn
java.lang.Object
org.apache.directory.api.ldap.model.name.Rdn
- All Implemented Interfaces:
Externalizable, Serializable, Cloneable, Comparable<Rdn>, Iterable<Ava>
public class Rdn
extends Object
implements Cloneable, Externalizable, Iterable<Ava>, Comparable<Rdn>
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 Ava. Those Avas are ordered in the alphabetical natural order : a < b < c ... < z As the type are not case sensitive, we can say that a = A
This class is immutable.
- <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 Ava. Those Avas are ordered in the alphabetical natural order : a < b < c ... < z As the type are not case sensitive, we can say that a = A
This class is immutable.
- Author:
- Apache Directory Project
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final RdnAn empty Rdnstatic final intConstant used in comparisonsstatic final intConstant used in comparisonsprotected static final org.slf4j.LoggerThe LoggerFactory used by this classstatic final intConstant used in comparisonsstatic final intCompareTo() results -
Constructor Summary
ConstructorsConstructorDescriptionRdn()A empty constructor.A constructor that parse a String representing a Rdn.A constructor that constructs a Rdn from a type and a value.Creates a new RDN from a list of AVAConstructs an Rdn from the given rdn.Rdn(SchemaManager schemaManager) Creates a new schema aware instance of Rdn.Rdn(SchemaManager schemaManager, String rdn) A constructor that parse a String representing a schema aware Rdn.Rdn(SchemaManager schemaManager, String upType, String upValue) A constructor that constructs a schema aware Rdn from a type and a value.Rdn(SchemaManager schemaManager, Ava... avas) Creates a new schema aware RDN from a list of AVARdn(SchemaManager schemaManager, Rdn rdn) Constructs an Rdn from the given rdn. -
Method Summary
Modifier and TypeMethodDescriptionclone()Clone the RdnintCompare the current RDN with the provided one.intdeserialize(byte[] buffer, int pos) Deserialize a RDN from a byte[], starting at a given positionbooleanCompares the specified Object with this Rdn for equality.static StringescapeValue(byte[] attrValue) Transform a value in a String, accordingly to RFC 2253static StringescapeValue(String value) Transform a value in a String, accordingly to RFC 2253getAva()Return the unique Ava, or the first one of we have more than onegetAva(int pos) Return the Nth AvaGet the Ava which type is given as an argument.getName()Return the normalized type, or the first one of we have more than one (the lowest)getType()Return the user provided type, or the first one of we have more than one (the lowest)getValue()Return the User Provided value, as a StringGet the value of the Ava which type is given as an argument.inthashCode()Gets the hashcode of this rdn.booleanTells if the Rdn is schema aware.static booleanValidate a NameComponent :static booleanisValid(SchemaManager schemaManager, String rdn) Validate a NameComponent :iterator()Retrieves the components of this Rdn as an iterator of Avas.voidWe read back the data to create a new RDB.intserialize(byte[] buffer, int pos) Serialize a RDN into a byte[]intsize()Get the number of Avas of this RdntoString()static ObjectunescapeValue(String value) Unescape the given string according to RFC 2253 If in <string> form, a LDAP string representation asserted value can be obtained by replacing (left-to-right, non-recursively) each <pair> appearing in the <string> as follows: replace <ESC><ESC> with <ESC> replace <ESC><special> with <special> replace <ESC><hexpair> with the octet indicated by the <hexpair> If in <hexstring> form, a BER representation can be obtained from converting each <hexpair> of the <hexstring> to the octet indicated by the <hexpair>voidA Rdn is composed of on to many Avas (AttributeType And Value).Methods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
LOG
protected static final org.slf4j.Logger LOGThe LoggerFactory used by this class -
EMPTY_RDN
An empty Rdn -
UNDEFINED
public static final int UNDEFINEDCompareTo() results- See Also:
-
SUPERIOR
public static final int SUPERIORConstant used in comparisons- See Also:
-
INFERIOR
public static final int INFERIORConstant used in comparisons- See Also:
-
EQUAL
public static final int EQUALConstant used in comparisons- See Also:
-
-
Constructor Details
-
Rdn
public Rdn()A empty constructor. -
Rdn
Creates a new schema aware instance of Rdn.- Parameters:
schemaManager- the schema manager
-
Rdn
A constructor that parse a String representing a schema aware Rdn.- Parameters:
schemaManager- the schema managerrdn- the String containing the Rdn to parse- Throws:
LdapInvalidDnException- if the Rdn is invalid
-
Rdn
A constructor that parse a String representing a Rdn.- Parameters:
rdn- the String containing the Rdn to parse- Throws:
LdapInvalidDnException- if the Rdn is invalid
-
Rdn
public Rdn(SchemaManager schemaManager, String upType, String upValue) throws LdapInvalidDnException, LdapInvalidAttributeValueException A constructor that constructs a schema aware Rdn from a type and a value.The string attribute values are not interpreted as RFC 414 formatted Rdn strings. That is, the values are used literally (not parsed) and assumed to be un-escaped.
- Parameters:
schemaManager- the schema managerupType- the user provided type of the RdnupValue- the user provided value of the Rdn- Throws:
LdapInvalidDnException- if the Rdn is invalidLdapInvalidAttributeValueException- If the given AttributeType or value are invalid
-
Rdn
public Rdn(String upType, String upValue) throws LdapInvalidDnException, LdapInvalidAttributeValueException A constructor that constructs a Rdn from a type and a value.- Parameters:
upType- the user provided type of the RdnupValue- the user provided value of the Rdn- Throws:
LdapInvalidDnException- if the Rdn is invalidLdapInvalidAttributeValueException- If the given AttributeType or Value are incorrect- See Also:
-
Rdn
Creates a new schema aware RDN from a list of AVA- Parameters:
schemaManager- The schemaManager to useavas- The AVA that will be used- Throws:
LdapInvalidDnException- If the RDN is invalid
-
Rdn
Creates a new RDN from a list of AVA- Parameters:
avas- The AVA that will be used- Throws:
LdapInvalidDnException- If the RDN is invalid
-
Rdn
Constructs an Rdn from the given rdn. The content of the rdn is simply copied into the newly created Rdn.- Parameters:
rdn- The non-null Rdn to be copied.
-
Rdn
Constructs an Rdn from the given rdn. The content of the rdn is simply copied into the newly created Rdn.- Parameters:
schemaManager- The SchemaManagerrdn- The non-null Rdn to be copied.- Throws:
LdapInvalidDnException- If the given Rdn is invalid
-
-
Method Details
-
getValue
Get the value of the Ava 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:
LdapInvalidDnException- if the Rdn is invalid
-
getAva
-
iterator
Retrieves the components of this Rdn as an iterator of Avas. The effect on the iterator of updates to this Rdn is undefined. If the Rdn has zero components, an empty (non-null) iterator is returned. -
clone
-
getName
- Returns:
- the user provided name
-
getNormName
- Returns:
- the normalized name
-
getAva
Return the unique Ava, or the first one of we have more than one- Returns:
- The first Ava of this Rdn
-
getAva
Return the Nth Ava- Parameters:
pos- The Ava we are looking for- Returns:
- The Ava at the given position in this Rdn
-
getType
Return the user provided type, or the first one of we have more than one (the lowest)- Returns:
- The first user provided type of this Rdn
-
getNormType
Return the normalized type, or the first one of we have more than one (the lowest)- Returns:
- The first normalized type of this Rdn
-
getValue
Return the User Provided value, as a String- Returns:
- The first User provided value of this Rdn
-
equals
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. -
size
public int size()Get the number of Avas of this Rdn- Returns:
- The number of Avas in this Rdn
-
unescapeValue
Unescape the given string according to RFC 2253 If in <string> form, a LDAP string representation asserted value can be obtained by replacing (left-to-right, non-recursively) each <pair> appearing in the <string> as follows:- replace <ESC><ESC> with <ESC>
- replace <ESC><special> with <special>
- replace <ESC><hexpair> with the octet indicated by the <hexpair>
- Parameters:
value- The value to be unescaped- Returns:
- Returns a string value as a String, and a binary value as a byte array.
- Throws:
IllegalArgumentException- When an Illegal value is provided.
-
escapeValue
-
getEscaped
- Returns:
- The RDN as an escaped String
-
escapeValue
Transform a value in a String, accordingly to RFC 2253- Parameters:
attrValue- The attribute value to be escaped- Returns:
- The escaped string value.
-
isSchemaAware
public boolean isSchemaAware()Tells if the Rdn is schema aware.- Returns:
trueif the Rdn is schema aware
-
isValid
Validate a NameComponent :
<name-component> ::= <attributeType> <spaces> '=' <spaces> <attributeValue> <nameComponents>
- Parameters:
rdn- The string to parse- Returns:
trueif the Rdn is valid
-
isValid
Validate a NameComponent :
<name-component> ::= <attributeType> <spaces> '=' <spaces> <attributeValue> <nameComponents>
- Parameters:
schemaManager- The Schemamanager to userdn- The string to parse- Returns:
trueif the Rdn is valid
-
hashCode
-
serialize
Serialize a RDN into a byte[]- Parameters:
buffer- The buffer which will contain the serilaized form of this RDNpos- The position in the buffer where to store the RDN- Returns:
- The new position in the byte[]
- Throws:
IOException- If the serialization failed
-
deserialize
public int deserialize(byte[] buffer, int pos) throws IOException, LdapInvalidAttributeValueException Deserialize a RDN from a byte[], starting at a given position- Parameters:
buffer- The buffer containing the RDNpos- The position in the buffer- Returns:
- The new position
- Throws:
IOException- If the serialized value is not a RDNLdapInvalidAttributeValueException- If the serialized RDN is invalid
-
writeExternal
A Rdn is composed of on to many Avas (AttributeType And Value). We should write all those Avas sequencially, following the structure :- parentId The parent entry's Id
- nbAvas The number of Avas to write. Can't be 0.
- upName The User provided Rdn
- Avas
For each Ava :- start The position of this Ava in the upName string
- length The Ava user provided length
- Call the Ava write method The Ava itself
- Specified by:
writeExternalin interfaceExternalizable- Parameters:
out- The stream into which the serialized Rdn will be put- Throws:
IOException- If the stream can't be written- See Also:
-
readExternal
We read back the data to create a new RDB. The structure read is exposed in thewriteExternal(ObjectOutput)method- Specified by:
readExternalin interfaceExternalizable- Parameters:
in- The input stream from which the Rdn will be read- Throws:
IOException- If we can't read from the input streamClassNotFoundException- If we can't create a new Rdn- See Also:
-
compareTo
Compare the current RDN with the provided one.- Specified by:
compareToin interfaceComparable<Rdn>- Parameters:
otherRdn- The RDN we want to compare to- Returns:
- a negative value if the current RDN is below the provided one, a positive value if it's above and 0 if they are equal.
-
toString
-