directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r208919 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/LdapDN.java
Date Sun, 03 Jul 2005 14:22:05 GMT
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>
-     * &lt;spaces&gt;    ::= ' ' &lt;spaces&gt; | 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>
-     * &lt;attributeValue&gt;     ::= &lt;pairs-or-strings&gt; | '#' &lt;hexstring&gt;
|'"' &lt;quotechar-or-pairs&gt; '"' <br>
-     * &lt;pairs-or-strings&gt;    ::= '\' &lt;pairchar&gt; &lt;pairs-or-strings&gt;
| &lt;stringchar&gt; &lt;pairs-or-strings&gt; |  | e <br>
-     * &lt;quotechar-or-pairs&gt;    ::= &lt;quotechar&gt; &lt;quotechar-or-pairs&gt;
| '\' &lt;pairchar&gt; &lt;quotechar-or-pairs&gt; | 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>
-     * &lt;oidPrefix&gt; ::= '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>
-     * &lt;oidValue&gt; ::= [0-9] &lt;digits&gt; &lt;oids&gt; 
-     * </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>
-     * &lt;attributType&gt; ::= [a-zA-Z] &lt;keychars&gt; | 
-     * 							&lt;oidPrefix&gt; [0-9] &lt;digits&gt; &lt;oids&gt;
| [0-9] &lt;digits&gt; &lt;oids&gt;
-     * </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>
-     * &lt;attributeTypeAndValues&gt;    ::= &lt;spaces&gt; '+' &lt;spaces&gt;
&lt;attributeType&gt; &lt;spaces&gt; '=' &lt;spaces&gt; &lt;attributeValue&gt;
&lt;attributeTypeAndValues&gt; | 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>
-     * &lt;name-component&gt;    ::= &lt;attributeType&gt; &lt;spaces&gt;
'=' &lt;spaces&gt; &lt;attributeValue&gt; &lt;attributeTypeAndValues&gt;
-     * </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



Mime
View raw message