Author: elecharny
Date: Sun Jul 3 07:22:05 2005
New Revision: 208919
URL: http://svn.apache.org/viewcvs?rev=208919&view=rev
Log:
Refactored the LdapDN class to inherit from the RelativeLdapDN class, as a RDN is a name component,
and a DN is a list of RDN.
Modified:
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/LdapDN.java
Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/LdapDN.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/LdapDN.java?rev=208919&r1=208918&r2=208919&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/LdapDN.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/LdapDN.java
Sun Jul 3 07:22:05 2005
@@ -17,11 +17,8 @@
package org.apache.asn1.ldap.codec.primitives;
import org.apache.asn1.DecoderException;
-import org.apache.asn1.ldap.codec.utils.DNUtils;
-import org.apache.asn1.util.MutableString;
import org.apache.asn1.util.StringUtils;
-
/**
* This class parses a DN.
*
@@ -52,7 +49,7 @@
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public class LdapDN extends MutableString
+public class LdapDN extends RelativeLdapDN
{
//~ Static fields/initializers -----------------------------------------------------------------
@@ -66,393 +63,6 @@
public transient static final LdapDN EMPTY_STRING = new LdapDN();
//~ Methods ------------------------------------------------------------------------------------
-
- /**
- * Walk the buffer while the current char is a Space char
- * <p>
- * <spaces> ::= ' ' <spaces> | e
- * </p>
- *
- * @param bytes The buffer to parse
- * @param pos The current position in the byte buffer
- * @return The new position in the byte buffer
- */
- private static int parseSpaces( byte[] bytes, int pos )
- {
-
- while ( StringUtils.isCharASCII( bytes, pos, ' ' ) )
- {
- pos++;
- }
-
- return pos;
- }
-
- /**
- * Parse this rule : <br>
- * <p>
- * <attributeValue> ::= <pairs-or-strings> | '#' <hexstring>
|'"' <quotechar-or-pairs> '"' <br>
- * <pairs-or-strings> ::= '\' <pairchar> <pairs-or-strings>
| <stringchar> <pairs-or-strings> | | e <br>
- * <quotechar-or-pairs> ::= <quotechar> <quotechar-or-pairs>
| '\' <pairchar> <quotechar-or-pairs> | e <br>
- * </p>
- *
- * @param bytes The buffer to parse
- * @param pos The current position in the byte buffer
- * @return The new position in the byte buffer, or -1 if the rule does not apply to the
byte buffer
- */
- private static int parseAttributeValue( byte[] bytes, int pos )
- {
- if ( StringUtils.isCharASCII( bytes, pos, '#' ) )
- {
- pos++;
-
- // <attributeValue> ::= '#' <hexstring>
- if ( ( pos = DNUtils.parseHexString( bytes, pos ) ) == -1 )
- {
-
- return -1;
- }
-
- return parseSpaces( bytes, pos );
- }
- else if ( StringUtils.isCharASCII( bytes, pos, '"' ) )
- {
- pos++;
- int nbBytes = 0;
-
- // <attributeValue> ::= '"' <quotechar-or-pair> '"'
- // <quotechar-or-pairs> ::= <quotechar> <quotechar-or-pairs>
| '\' <pairchar> <quotechar-or-pairs> | e
- while ( true )
- {
- if ( StringUtils.isCharASCII( bytes, pos, '\\' ) )
- {
- pos++;
-
- if ( DNUtils.isPairChar( bytes, pos ) )
- {
- pos++;
- }
- else
- {
- return -1;
- }
- }
- else if ( (nbBytes = DNUtils.isQuoteChar( bytes, pos ) ) != -1 )
- {
- pos += nbBytes;
- }
- else
- {
- break;
- }
- }
-
- if ( StringUtils.isCharASCII( bytes, pos, '"' ) )
- {
- pos++;
-
- return parseSpaces( bytes, pos );
- }
- else
- {
- return -1;
- }
- }
- else
- {
- while ( true )
- {
- if ( StringUtils.isCharASCII( bytes, pos, '\\' ) )
- {
- // '\' <pairchar> <pairs-or-strings>
- pos++;
-
- if ( DNUtils.isPairChar( bytes, pos ) == false )
- {
- return -1;
- }
- else
- {
- pos++;
- }
- }
- else
- {
- int nbBytes = 0;
-
- // <stringchar> <pairs-or-strings>
- if ( (nbBytes = DNUtils.isStringChar( bytes, pos )) != -1)
- {
- // A special case : if we have some spaces before the '+' character,
- // we MUST skip them.
- int initPos = pos;
-
- if ( StringUtils.isCharASCII( bytes, pos, ' ') )
- {
- pos = parseSpaces( bytes, pos );
-
- if ( ( DNUtils.isStringChar( bytes, pos ) == -1 ) &&
- ( StringUtils.isCharASCII( bytes, pos, '\\' ) == false
) )
- {
- // Ok, we are done with the stringchar.
- return pos;
- }
- }
- else
- {
- // An unicode char could be more than one byte long
- pos += nbBytes;
- }
- }
- else
- {
- return pos;
- }
- }
- }
- }
- }
-
- /**
- * Parse this rule : <br>
- * <p>
- * <oidPrefix> ::= 'OID.' | 'oid.' | e
- * </p>
- *
- * @param bytes The buffer to parse
- * @param pos The current position in the byte buffer
- * @return The new position in the byte buffer, or -1 if the rule does not apply to the
byte buffer
- */
- private static int parseOidPrefix( byte[] bytes, int pos )
- {
-
- if ( ( StringUtils.areEquals( bytes, pos, OID_LOWER ) == -1 ) &&
- ( StringUtils.areEquals( bytes, pos, OID_UPPER ) == -1 ) )
- {
-
- return -1;
- }
- else
- {
- pos += 4;
-
- return pos;
- }
- }
-
- /**
- * Parse this rule : <br>
- * <p>
- * <oidValue> ::= [0-9] <digits> <oids>
- * </p>
- *
- * @param bytes The buffer to parse
- * @param pos The current position in the byte buffer
- * @return The new position in the byte buffer, or -1 if the rule does not apply to the
byte buffer
- */
- private static int parseOidValue(byte[] bytes, int pos)
- {
- // <attributType> ::= [0-9] <digits> <oids>
- if ( StringUtils.isDigit( bytes, pos ) == false )
- {
-
- // Nope... An error
- return -1;
- }
- else
- {
-
- // Let's process an oid
- pos++;
-
- while ( StringUtils.isDigit( bytes, pos ) )
- {
- pos++;
- }
-
- // <oids> ::= '.' [0-9] <digits> <oids> | e
- if ( StringUtils.isCharASCII( bytes, pos, '.' ) == false )
- {
-
- return pos;
- }
- else
- {
-
- do
- {
- pos++;
-
- if ( StringUtils.isDigit( bytes, pos ) == false )
- {
-
- return -1;
- }
- else
- {
- pos++;
-
- while ( StringUtils.isDigit( bytes, pos ) )
- {
- pos++;
- }
- }
- }
- while ( StringUtils.isCharASCII( bytes, pos, '.' ) );
-
- return pos;
- }
- }
- }
-
- /**
- * Parse this rule : <br>
- * <p>
- * <attributType> ::= [a-zA-Z] <keychars> |
- * <oidPrefix> [0-9] <digits> <oids>
| [0-9] <digits> <oids>
- * </p>
- *
- * The string *MUST* be an ASCII string, not an unicode string.
- *
- * @param bytes The buffer to parse
- * @param pos The current position in the byte buffer
- * @return The new position in the byte buffer, or -1 if the rule does not apply to the
byte buffer
- */
- private static int parseAttributeType( byte[] bytes, int pos )
- {
-
- // <attributType> ::= [a-zA-Z] <keychars> | <oidPrefix> [0-9] <digits>
<oids> | [0-9] <digits> <oids>
-
- if ( StringUtils.isAlphaASCII( bytes, pos ))
- {
- // <attributType> ::= [a-zA-Z] <keychars> | <oidPrefix> [0-9]
<digits> <oids>
-
- // We have got an Alpha char, it may be the begining of an OID ?
- int oldPos = pos;
-
- if ( ( pos = parseOidPrefix( bytes, oldPos ) ) != -1 )
- {
- return parseOidValue(bytes, pos);
- }
- else
- {
- // It's not an oid, it's a String (ASCII)
- // <attributType> ::= [a-zA-Z] <keychars>
- // <keychars> ::= [a-zA-Z] <keychar> | [0-9] <keychar>
| '-' <keychar> | e
- pos = oldPos + 1;
-
- while ( StringUtils.isAlphaDigitMinus( bytes, pos ) )
- {
- pos++;
- }
-
- return pos;
- }
- }
- else
- {
-
- // An oid
- // <attributType> ::= [0-9] <digits> <oids>
- return parseOidValue(bytes, pos);
- }
- }
-
- /**
- * Parse this rule : <br>
- * <p>
- * <attributeTypeAndValues> ::= <spaces> '+' <spaces>
<attributeType> <spaces> '=' <spaces> <attributeValue>
<attributeTypeAndValues> | e
- * </p>
- *
- * @param bytes The buffer to parse
- * @param pos The current position in the byte buffer
- * @return The new position in the byte buffer, or -1 if the rule does not apply to the
byte buffer
- */
- private static int parseAttributeTypeAndValues( byte[] bytes, int pos )
- {
-
- while ( true )
- {
- pos = parseSpaces( bytes, pos );
-
- if ( StringUtils.isCharASCII( bytes, pos, '+' ) )
- {
- pos++;
- }
- else
- {
-
- // <attributeTypeAndValues> ::= e
- return pos;
- }
-
- pos = parseSpaces( bytes, pos );
-
- if ( ( pos = parseAttributeType( bytes, pos ) ) == -1 )
- {
-
- return -1;
- }
-
- pos = parseSpaces( bytes, pos );
-
- if ( StringUtils.isCharASCII( bytes, pos, '=' ) )
- {
- pos++;
- }
- else
- {
-
- return -1;
- }
-
- pos = parseSpaces( bytes, pos );
-
- return parseAttributeValue( bytes, pos );
- }
- }
-
- /**
- * Parse this rule : <br>
- * <p>
- * <name-component> ::= <attributeType> <spaces>
'=' <spaces> <attributeValue> <attributeTypeAndValues>
- * </p>
- *
- * @param bytes The buffer to parse
- * @param pos The current position in the buffer
- * @return The new position in the byte buffer, or -1 if the rule does not apply to the
byte buffer
- */
- private static int parseNameComponent( byte[] bytes, int pos )
- {
-
- if ( ( pos = parseAttributeType( bytes, pos ) ) == -1 )
- {
-
- return -1;
- }
-
- pos = parseSpaces( bytes, pos );
-
- if ( StringUtils.isCharASCII( bytes, pos, '=' ) == false )
- {
-
- return -1;
- }
- else
- {
- pos++;
- }
-
- pos = parseSpaces( bytes, pos );
-
- if ( ( pos = parseAttributeValue( bytes, pos ) ) == -1 )
- {
-
- return -1;
- }
-
- return parseAttributeTypeAndValues( bytes, pos );
- }
/**
* Construct an empty LdapDN object
|