You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2006/09/01 19:11:33 UTC

svn commit: r439381 - in /directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src: main/java/ main/java/org/ main/java/org/apache/ main/java/org/apache/directory/ main/java/org/apache/directory/shared/ main/java/org/apache/directory/shared/ldap/ main/...

Author: elecharny
Date: Fri Sep  1 10:11:31 2006
New Revision: 439381

URL: http://svn.apache.org/viewvc?rev=439381&view=rev
Log:
Added some packages and classes : first drop for messages rewritting

Added:
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/exceptions/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/exceptions/InvalidObjectException.java
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/exceptions/LdapException.java
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/Control.java
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/Message.java
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/MessageException.java
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/ResultCode.java
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/abandon/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/add/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/bind/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/compare/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/del/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/extended/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/extended/operation/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/modify/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/modifydn/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/search/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/unbind/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/primitive/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/primitive/OID.java
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/utils/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/utils/StringTools.java
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/test/java/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/test/java/org/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/test/java/org/apache/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/test/java/org/apache/directory/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/test/java/org/apache/directory/shared/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/test/java/org/apache/directory/shared/ldap/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/test/java/org/apache/directory/shared/ldap/primitives/
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/test/java/org/apache/directory/shared/ldap/primitives/OIDTest.java

Added: directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/exceptions/InvalidObjectException.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/exceptions/InvalidObjectException.java?rev=439381&view=auto
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/exceptions/InvalidObjectException.java (added)
+++ directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/exceptions/InvalidObjectException.java Fri Sep  1 10:11:31 2006
@@ -0,0 +1,32 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.ldap.exceptions;
+
+import javax.naming.NamingException;
+
+public class InvalidObjectException extends NamingException {
+    static final long serialVersionUID = 2L;
+
+    public InvalidObjectException(String explanation)
+    {
+        super( explanation );
+    }
+
+}

Added: directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/exceptions/LdapException.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/exceptions/LdapException.java?rev=439381&view=auto
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/exceptions/LdapException.java (added)
+++ directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/exceptions/LdapException.java Fri Sep  1 10:11:31 2006
@@ -0,0 +1,41 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.ldap.exceptions;
+
+import org.apache.directory.shared.ldap.messages.ResultCode;
+
+/**
+ * An interface for exceptions which add LDAP specific information to
+ * Exceptions.
+ * 
+ * @see <a
+ *      href="http://java.sun.com/j2se/1.4.2/docs/guide/jndi/jndi-ldap-gl.html#EXCEPT">
+ *      LDAP ResultCode to JNDI Exception Mappings</a>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface LdapException
+{
+    /**
+     * Gets the LDAP result code that would be associated with this exception.
+     * 
+     * @return the LDAP result code corresponding to this exception type.
+     */
+    public ResultCode getResultCode();
+}

Added: directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/Control.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/Control.java?rev=439381&view=auto
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/Control.java (added)
+++ directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/Control.java Fri Sep  1 10:11:31 2006
@@ -0,0 +1,180 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.ldap.messages;
+
+import org.apache.directory.shared.ldap.utils.StringTools;
+
+public class Control implements javax.naming.ldap.Control {
+    static final long serialVersionUID = 2L;
+
+    // ~ Instance fields
+    // ----------------------------------------------------------------------------
+
+    /** The control type */
+    private String controlType;
+
+    /** The criticality (default value is false) */
+    private boolean criticality = false;
+
+    /** Optionnal control value */
+    private Object controlValue;
+
+    /** Optionnal control value in encoded form */
+    private byte[] encodedValue;
+
+    // ~ Methods
+    // ------------------------------------------------------------------------------------
+
+    /**
+     * Get the control type
+     * 
+     * @return A string which represent the control type
+     */
+    public String getID()
+    {
+        return ( controlType == null ? "" : controlType.toString() );
+    }
+
+
+    /**
+     * Set the control type
+     * 
+     * @param controlType
+     *            An OID to store
+     */
+    public void setControlType( String controlType )
+    {
+        this.controlType = controlType;
+    }
+
+
+    /**
+     * Get the control value
+     * 
+     * @return The control value
+     */
+    public byte[] getControlValue()
+    {
+        if ( controlValue == null )
+        {
+            return StringTools.EMPTY_BYTES;
+        }
+        else if ( controlValue instanceof String )
+        {
+            return StringTools.getBytesUtf8( ( String ) controlValue );
+        }
+        else
+        {
+            return (byte[])controlValue;
+        }
+    }
+
+
+    /**
+     * Set the encoded control value
+     * 
+     * @param encodedValue
+     *            The encoded control value to store
+     */
+    public void setEncodedValue( byte[] encodedValue )
+    {
+        this.encodedValue = encodedValue;
+    }
+
+
+    /**
+     * Get the raw control encoded bytes
+     * 
+     * @return the encoded bytes for the control
+     */
+    public byte[] getEncodedValue()
+    {
+        if ( encodedValue == null )
+        {
+            return StringTools.EMPTY_BYTES;
+        }
+
+        return encodedValue;
+    }
+
+
+    /**
+     * Set the control value
+     * 
+     * @param controlValue
+     *            The control value to store
+     */
+    public void setControlValue( Object controlValue )
+    {
+        this.controlValue = controlValue;
+    }
+
+
+    /**
+     * Get the criticality
+     * 
+     * @return <code>true</code> if the criticality flag is true.
+     */
+    public boolean isCritical()
+    {
+        return criticality;
+    }
+
+
+    /**
+     * Set the criticality
+     * 
+     * @param criticality
+     *            The criticality value
+     */
+    public void setCriticality( boolean criticality )
+    {
+        this.criticality = criticality;
+    }
+
+    /**
+     * Return a String representing a Control
+     */
+    public String toString()
+    {
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( "    Control\n" );
+        sb.append( "        Control type : '" ).append( controlType != null ? controlType.toString() : "null" ).append(
+            "'\n" );
+        sb.append( "        Criticality : '" ).append( criticality ).append( "'\n" );
+
+        if ( controlValue != null )
+        {
+            if ( controlValue instanceof byte[] )
+            {
+                sb.append( "        Control value : '" ).append( StringTools.dumpBytes( ( byte[] ) controlValue ) )
+                    .append( "'\n" );
+            }
+            else
+            {
+                sb.append( "        Control value : '" ).append( controlValue ).append( "'\n" );
+            }
+        }
+
+        return sb.toString();
+    }
+
+}

Added: directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/Message.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/Message.java?rev=439381&view=auto
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/Message.java (added)
+++ directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/Message.java Fri Sep  1 10:11:31 2006
@@ -0,0 +1,77 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.ldap.messages;
+
+import java.util.Map;
+
+import javax.naming.ldap.Control;
+
+import org.apache.directory.shared.ldap.primitive.OID;
+
+/**
+ * Root interface for all LDAP message type interfaces.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface Message {
+    /**
+     * Gets the controls associated with this message mapped by OID.
+     * 
+     * @return Map of OID strings to Control object instances.
+     * @see Control
+     */
+    Map<OID, Control> getControls();
+
+
+    /**
+     * Adds a control to this Message.
+     * 
+     * @param control
+     *            the control to add.
+     * @throws MessageException
+     *             if controls cannot be added to this Message or the control is
+     *             not known etc.
+     */
+    void add( Control control ) throws MessageException;
+
+
+    /**
+     * Deletes a control removing it from this Message.
+     * 
+     * @param control
+     *            the control to remove.
+     * @throws MessageException
+     *             if controls cannot be added to this Message or the control is
+     *             not known etc.
+     */
+    void remove( Control control ) throws MessageException;
+
+
+    /**
+     * Gets the session unique message sequence id for this message. Requests
+     * and their responses if any have the same message id. Clients at the
+     * initialization of a session start with the first message's id set to 1
+     * and increment it with each transaction.
+     * 
+     * @return the session unique message id.
+     */
+    int getMessageId();
+
+}

Added: directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/MessageException.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/MessageException.java?rev=439381&view=auto
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/MessageException.java (added)
+++ directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/MessageException.java Fri Sep  1 10:11:31 2006
@@ -0,0 +1,32 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.ldap.messages;
+
+import javax.naming.NamingException;
+
+public class MessageException extends NamingException {
+    static final long serialVersionUID = 1L;
+
+    public MessageException(String explanation)
+    {
+        super( explanation );
+    }
+
+}

Added: directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/ResultCode.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/ResultCode.java?rev=439381&view=auto
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/ResultCode.java (added)
+++ directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/ResultCode.java Fri Sep  1 10:11:31 2006
@@ -0,0 +1,24 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.ldap.messages;
+
+public enum ResultCode {
+
+}

Added: directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/primitive/OID.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/primitive/OID.java?rev=439381&view=auto
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/primitive/OID.java (added)
+++ directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/primitive/OID.java Fri Sep  1 10:11:31 2006
@@ -0,0 +1,636 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.ldap.primitive;
+
+import org.apache.directory.shared.ldap.exceptions.InvalidObjectException;
+
+/**
+ * This class implement an OID (Object Identifier). 
+ * 
+ * An OID is encoded as a list of bytes representing integers. 
+ * 
+ * An OID has a numeric representation where number are separated 
+ * with dots : 
+ * SPNEGO Oid = 1.3.6.1.5.5.2 
+ * 
+ * Translating from a byte list to a dot separated list of number 
+ * follows the rules : 
+ *  - the first number is in [0..2]
+ *  - the second number is in [0..39] if the first number is
+ * 0 or 1
+ *  - the first byte has a value equal to : number 1 * 40 + number two
+ *  - the upper bit of a byte is set if the next byte is a part of 
+ *  the number 
+ *  
+ *  For instance, the SPNEGO Oid (1.3.6.1.5.5.2) will be encoded : 
+ *  1.3 -> 0x2B (1*40 + 3 = 43 = 0x2B) 
+ *  .6 -> 0x06 
+ *  .1 -> 0x01 
+ *  .5 -> 0x05 
+ *  .5 -> 0x05 
+ *  .2 -> 0x02 
+ *  
+ *  The Kerberos V5 Oid (1.2.840.48018.1.2.2) will be encoded : 
+ *  1.2 -> 0x2A (1*40 + 2 = 42 = 0x2A) 
+ *  840 -> 0x86 0x48 (840 = 6 * 128 + 72 = (0x06 | 0x80) 0x48 = 0x86 0x48 
+ *  48018 -> 0x82 0xF7 0x12 (2 * 128 * 128 + 119 * 128 + 18 = (0x02 | 0x80)
+ * (0x77 | 0x80) 0x12
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class OID {
+    private static final long serialVersionUID = 1L;
+
+    // ~ Instance fields
+    // ----------------------------------------------------------------------------
+
+    /** The OID as a array of int */
+    private long[] oidValues;
+
+
+    // ~ Constructors
+    // -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new OID object.
+     */
+    public OID()
+    {
+
+        // We should not create this kind of object directly, it must
+        // be created through the factory.
+    }
+
+
+    /**
+     * Create a new OID object from a byte array
+     * 
+     * @param oid
+     */
+    public OID(byte[] oid)
+    {
+        setOID( oid );
+    }
+
+
+    /**
+     * Create a new OID object from a String
+     * 
+     * @param oid
+     *            The String which is supposed to be an OID
+     */
+    public OID(String oid) throws InvalidObjectException
+    {
+        setOID( oid );
+    }
+
+
+    // ~ Methods
+    // ------------------------------------------------------------------------------------
+    /**
+     * Set the OID. It will be translated from a byte array to an internal
+     * representation.
+     * 
+     * @param oid
+     *            The bytes containing the OID
+     */
+    public void setOID( byte[] oid )
+    {
+
+        if ( oid == null )
+        {
+            throw new IllegalArgumentException( "Null OID" );
+        }
+
+        if ( oid.length < 1 )
+        {
+            throw new IllegalArgumentException( "Invalid OID : " + oid );
+        }
+
+        // First, we have to calculate the number of int to allocate
+        int nbValues = 1;
+
+        int pos = 0;
+
+        while ( pos < oid.length )
+        {
+
+            if ( oid[pos] >= 0 )
+            {
+                nbValues++;
+            }
+
+            pos++;
+        }
+
+        oidValues = new long[nbValues];
+
+        nbValues = 0;
+        pos = 0;
+
+        int accumulator = 0;
+
+        if ( ( oid[0] < 0 ) || ( oid[0] >= 80 ) )
+        {
+            oidValues[nbValues++] = 2;
+
+            while ( pos < oid.length )
+            {
+
+                if ( oid[pos] >= 0 )
+                {
+                    oidValues[nbValues++] = ( ( accumulator << 7 ) + oid[pos] ) - 80;
+                    accumulator = 0;
+                    pos++;
+                    break;
+                }
+                else
+                {
+                    accumulator = ( accumulator << 7 ) + ( oid[pos] & 0x007F );
+                }
+
+                pos++;
+            }
+        }
+        else if ( oid[0] < 40 )
+        {
+            oidValues[nbValues++] = 0;
+            oidValues[nbValues++] = oid[pos++]; // itu-t
+        }
+        else
+        // oid[0] is < 80
+        {
+            oidValues[nbValues++] = 1;
+            oidValues[nbValues++] = oid[pos++] - 40; // iso
+        }
+
+        while ( pos < oid.length )
+        {
+
+            if ( oid[pos] >= 0 )
+            {
+                oidValues[nbValues++] = ( accumulator << 7 ) + oid[pos];
+                accumulator = 0;
+            }
+            else
+            {
+                accumulator = ( accumulator << 7 ) + ( oid[pos] & 0x007F );
+            }
+
+            pos++;
+        }
+    }
+
+
+    /**
+     * Set the OID. It will be translated from a String to an internal
+     * representation. The syntax will be controled in respect with this rule :
+     * OID = ( [ '0' | '1' ] '.' [ 0 .. 39 ] | '2' '.' int) ( '.' int )*
+     * 
+     * @param oid
+     *            The String containing the OID
+     */
+    public void setOID( String oid ) throws InvalidObjectException
+    {
+
+        if ( ( oid == null ) || ( oid.length() == 0 ) )
+        {
+            throw new IllegalArgumentException( "Null OID" );
+        }
+
+        int nbValues = 1;
+        byte[] bytes = oid.getBytes();
+        boolean dotSeen = false;
+
+        // Count the number of int to allocate.
+        for ( int i = 0; i < bytes.length; i++ )
+        {
+
+            if ( bytes[i] == '.' )
+            {
+
+                if ( dotSeen )
+                {
+
+                    // Two dots, that's an error !
+                    throw new InvalidObjectException( "Invalid OID : " + oid );
+                }
+
+                nbValues++;
+                dotSeen = true;
+            }
+            else
+            {
+                dotSeen = false;
+            }
+        }
+
+        // We must have at least 2 ints
+        if ( nbValues < 2 )
+        {
+            throw new InvalidObjectException( "Invalid OID : " + oid );
+        }
+
+        oidValues = new long[nbValues];
+
+        int pos = 0;
+        int intPos = 0;
+
+        // This flag is used to forbid a second value above 39 if the
+        // first value is 0 or 1 (itu_t or iso arcs)
+        boolean ituOrIso = false;
+
+        // The first value
+        switch ( bytes[pos] )
+        {
+
+            case '0': // itu-t
+            case '1': // iso
+                ituOrIso = true;
+            // fallthrough
+
+            case '2': // joint-iso-itu-t
+                oidValues[intPos++] = bytes[pos++] - '0';
+                break;
+
+            default: // error, this value is not allowed
+                throw new InvalidObjectException( "Invalid OID : " + oid );
+        }
+
+        // We must have a dot
+        if ( bytes[pos++] != '.' )
+        {
+            throw new InvalidObjectException( "Invalid OID : " + oid );
+        }
+
+        dotSeen = true;
+
+        int value = 0;
+
+        for ( int i = pos; i < bytes.length; i++ )
+        {
+
+            if ( bytes[i] == '.' )
+            {
+
+                if ( dotSeen )
+                {
+
+                    // Two dots, that's an error !
+                    throw new InvalidObjectException( "Invalid OID : " + oid );
+                }
+
+                if ( ituOrIso && value > 39 )
+                {
+                    throw new InvalidObjectException( "Invalid OID : " + oid );
+                }
+                else
+                {
+                    ituOrIso = false;
+                }
+
+                nbValues++;
+                dotSeen = true;
+                oidValues[intPos++] = value;
+                value = 0;
+            }
+            else if ( ( bytes[i] >= 0x30 ) && ( bytes[i] <= 0x39 ) )
+            {
+                dotSeen = false;
+                value = ( ( value * 10 ) + bytes[i] ) - '0';
+
+            }
+            else
+            {
+
+                // We don't have a number, this is an error
+                throw new InvalidObjectException( "Invalid OID : " + oid );
+            }
+        }
+
+        oidValues[intPos++] = value;
+    }
+
+
+    /**
+     * Get an array of int from the OID
+     * 
+     * @return An array of int representing the OID
+     */
+    public long[] getOIDValues()
+    {
+        return oidValues;
+    }
+
+
+    /**
+     * Get the number of bytes necessary to store the OID
+     * 
+     * @return An int representing the length of the OID
+     */
+    public int getOIDLength()
+    {
+        long value = oidValues[0] * 40 + oidValues[1];
+        int nbBytes = 0;
+
+        if ( value < 128 )
+        {
+            nbBytes = 1;
+        }
+        else if ( value < 16384 )
+        {
+            nbBytes = 2;
+        }
+        else if ( value < 2097152 )
+        {
+            nbBytes = 3;
+        }
+        else if ( value < 268435456 )
+        {
+            nbBytes = 4;
+        }
+        else
+        {
+            nbBytes = 5;
+        }
+
+        for ( int i = 2; i < oidValues.length; i++ )
+        {
+            value = oidValues[i];
+
+            if ( value < 128 )
+            {
+                nbBytes += 1;
+            }
+            else if ( value < 16384 )
+            {
+                nbBytes += 2;
+            }
+            else if ( value < 2097152 )
+            {
+                nbBytes += 3;
+            }
+            else if ( value < 268435456 )
+            {
+                nbBytes += 4;
+            }
+            else
+            {
+                nbBytes += 5;
+            }
+        }
+
+        return nbBytes;
+    }
+
+
+    /**
+     * Get an array of bytes from the OID
+     * 
+     * @return An array of int representing the OID
+     */
+    public byte[] getOID()
+    {
+        long value = oidValues[0] * 40 + oidValues[1];
+        long firstValues = value;
+
+        byte[] bytes = new byte[getOIDLength()];
+        int pos = 0;
+
+        if ( oidValues[0] < 2 )
+        {
+            bytes[pos++] = ( byte ) ( oidValues[0] * 40 + oidValues[1] );
+        }
+        else
+        {
+            if ( firstValues < 128 )
+            {
+                bytes[pos++] = ( byte ) ( firstValues );
+            }
+            else if ( firstValues < 16384 )
+            {
+                bytes[pos++] = ( byte ) ( ( firstValues >> 7 ) | 0x0080 );
+                bytes[pos++] = ( byte ) ( firstValues & 0x007F );
+            }
+            else if ( value < 2097152 )
+            {
+                bytes[pos++] = ( byte ) ( ( firstValues >> 14 ) | 0x0080 );
+                bytes[pos++] = ( byte ) ( ( ( firstValues >> 7 ) & 0x007F ) | 0x0080 );
+                bytes[pos++] = ( byte ) ( firstValues & 0x007F );
+            }
+            else if ( value < 268435456 )
+            {
+                bytes[pos++] = ( byte ) ( ( firstValues >> 21 ) | 0x0080 );
+                bytes[pos++] = ( byte ) ( ( ( firstValues >> 14 ) & 0x007F ) | 0x0080 );
+                bytes[pos++] = ( byte ) ( ( ( firstValues >> 7 ) & 0x007F ) | 0x0080 );
+                bytes[pos++] = ( byte ) ( firstValues & 0x007F );
+            }
+            else
+            {
+                bytes[pos++] = ( byte ) ( ( firstValues >> 28 ) | 0x0080 );
+                bytes[pos++] = ( byte ) ( ( ( firstValues >> 21 ) & 0x007F ) | 0x0080 );
+                bytes[pos++] = ( byte ) ( ( ( firstValues >> 14 ) & 0x007F ) | 0x0080 );
+                bytes[pos++] = ( byte ) ( ( ( firstValues >> 7 ) & 0x007F ) | 0x0080 );
+                bytes[pos++] = ( byte ) ( firstValues & 0x007F );
+            }
+        }
+
+        for ( int i = 2; i < oidValues.length; i++ )
+        {
+            value = oidValues[i];
+
+            if ( value < 128 )
+            {
+                bytes[pos++] = ( byte ) ( value );
+            }
+            else if ( value < 16384 )
+            {
+                bytes[pos++] = ( byte ) ( ( value >> 7 ) | 0x0080 );
+                bytes[pos++] = ( byte ) ( value & 0x007F );
+            }
+            else if ( value < 2097152 )
+            {
+                bytes[pos++] = ( byte ) ( ( value >> 14 ) | 0x0080 );
+                bytes[pos++] = ( byte ) ( ( ( value >> 7 ) & 0x007F ) | 0x0080 );
+                bytes[pos++] = ( byte ) ( value & 0x007F );
+            }
+            else if ( value < 268435456 )
+            {
+                bytes[pos++] = ( byte ) ( ( value >> 21 ) | 0x0080 );
+                bytes[pos++] = ( byte ) ( ( ( value >> 14 ) & 0x007F ) | 0x0080 );
+                bytes[pos++] = ( byte ) ( ( ( value >> 7 ) & 0x007F ) | 0x0080 );
+                bytes[pos++] = ( byte ) ( value & 0x007F );
+            }
+            else
+            {
+                bytes[pos++] = ( byte ) ( ( value >> 28 ) | 0x0080 );
+                bytes[pos++] = ( byte ) ( ( ( value >> 21 ) & 0x007F ) | 0x0080 );
+                bytes[pos++] = ( byte ) ( ( ( value >> 14 ) & 0x007F ) | 0x0080 );
+                bytes[pos++] = ( byte ) ( ( ( value >> 7 ) & 0x007F ) | 0x0080 );
+                bytes[pos++] = ( byte ) ( value & 0x007F );
+            }
+        }
+
+        return bytes;
+    }
+
+
+    /**
+     * Get the OID as a String
+     * 
+     * @return A String representing the OID
+     */
+    public String toString()
+    {
+
+        StringBuffer sb = new StringBuffer();
+
+        if ( oidValues != null )
+        {
+            sb.append( oidValues[0] );
+
+            for ( int i = 1; i < oidValues.length; i++ )
+            {
+                sb.append( '.' ).append( oidValues[i] );
+            }
+        }
+
+        return sb.toString();
+    }
+
+
+    /**
+     * Check if the given string is a valid OID
+     * @param oid The string to control
+     * @return <code>true</code> or <code>false</code>
+     */
+    public static boolean isOID( String oid )
+    {
+        if ( ( oid == null ) || ( oid.length() == 0 ) )
+        {
+            return false;
+        }
+
+        int nbValues = 1;
+        byte[] bytes = oid.getBytes();
+        boolean dotSeen = false;
+
+        // Count the number of int to allocate.
+        for ( int i = 0; i < bytes.length; i++ )
+        {
+
+            if ( bytes[i] == '.' )
+            {
+
+                if ( dotSeen )
+                {
+
+                    // Two dots, that's an error !
+                    return false;
+                }
+
+                nbValues++;
+                dotSeen = true;
+            }
+            else
+            {
+                dotSeen = false;
+            }
+        }
+
+        // We must have at least 2 ints
+        if ( nbValues < 2 )
+        {
+            return false;
+        }
+
+        int pos = 0;
+
+        // This flag is used to forbid a second value above 39 if the
+        // first value is 0 or 1 (itu_t or iso arcs)
+        boolean ituOrIso = false;
+
+        // The first value
+        switch ( bytes[pos++] )
+        {
+
+            case '0': // itu-t
+            case '1': // iso
+                ituOrIso = true;
+            // fallthrough
+
+            case '2': // joint-iso-itu-t
+                break;
+
+            default: // error, this value is not allowed
+                return false;
+        }
+
+        // We must have a dot
+        if ( bytes[pos++] != '.' )
+        {
+            return false;
+        }
+
+        dotSeen = true;
+
+        long value = 0;
+
+        for ( int i = pos; i < bytes.length; i++ )
+        {
+
+            if ( bytes[i] == '.' )
+            {
+
+                if ( dotSeen )
+                {
+                    // Two dots, that's an error !
+                    return false;
+                }
+
+                if ( ituOrIso && value > 39 )
+                {
+                    return false;
+                }
+                else
+                {
+                    ituOrIso = false;
+                }
+
+                nbValues++;
+                dotSeen = true;
+                value = 0;
+            }
+            else if ( ( bytes[i] >= 0x30 ) && ( bytes[i] <= 0x39 ) )
+            {
+                dotSeen = false;
+
+                value = ( ( value * 10 ) + bytes[i] ) - '0';
+            }
+            else
+            {
+                // We don't have a number, this is an error
+                return false;
+            }
+        }
+
+        return true;
+    }
+}

Added: directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/utils/StringTools.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/utils/StringTools.java?rev=439381&view=auto
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/utils/StringTools.java (added)
+++ directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/utils/StringTools.java Fri Sep  1 10:11:31 2006
@@ -0,0 +1,65 @@
+package org.apache.directory.shared.ldap.utils;
+
+import java.io.UnsupportedEncodingException;
+
+public class StringTools {
+    /** Hex chars */
+    private static final byte[] HEX_CHAR = new byte[]
+        { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+
+    /**
+     * The empty byte[]
+     */
+    public static final byte[] EMPTY_BYTES = new byte[]
+        {};
+
+    /**
+     * Return UTF-8 encoded byte[] representation of a String
+     * 
+     * @param string
+     *            The string to be transformed to a byte array
+     * @return The transformed byte array
+     */
+    public static final byte[] getBytesUtf8( String string )
+    {
+        if ( string == null )
+        {
+            return new byte[0];
+        }
+
+        try
+        {
+            return string.getBytes( "UTF-8" );
+        }
+        catch ( UnsupportedEncodingException uee )
+        {
+            return EMPTY_BYTES;
+        }
+    }
+
+    /**
+     * Helper function that dump an array of bytes in hex form
+     * 
+     * @param buffer
+     *            The bytes array to dump
+     * @return A string representation of the array of bytes
+     */
+    public static final String dumpBytes( byte[] buffer )
+    {
+        if ( buffer == null )
+        {
+            return "";
+        }
+
+        StringBuffer sb = new StringBuffer();
+
+        for ( int i = 0; i < buffer.length; i++ )
+        {
+            sb.append( "0x" ).append( ( char ) ( HEX_CHAR[( buffer[i] & 0x00F0 ) >> 4] ) ).append(
+                ( char ) ( HEX_CHAR[buffer[i] & 0x000F] ) ).append( " " );
+        }
+
+        return sb.toString();
+    }
+    
+}

Added: directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/test/java/org/apache/directory/shared/ldap/primitives/OIDTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/test/java/org/apache/directory/shared/ldap/primitives/OIDTest.java?rev=439381&view=auto
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/test/java/org/apache/directory/shared/ldap/primitives/OIDTest.java (added)
+++ directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/test/java/org/apache/directory/shared/ldap/primitives/OIDTest.java Fri Sep  1 10:11:31 2006
@@ -0,0 +1,391 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.ldap.primitives;
+
+import org.apache.directory.shared.ldap.exceptions.InvalidObjectException;
+import org.apache.directory.shared.ldap.primitive.OID;
+import org.apache.directory.shared.ldap.utils.StringTools;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the OID primitive
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class OIDTest extends TestCase {
+    // ~ Methods
+    // ------------------------------------------------------------------------------------
+
+    /**
+     * Test a null OID
+     */
+    public void testOidNull()
+    {
+
+        OID oid = new OID();
+
+        try 
+        {
+        	oid.setOID( ( byte[] ) null );
+            fail( "Should not reach this point ..." );
+        }
+        catch ( IllegalArgumentException iae )
+        {
+        	assertTrue( true );
+        }
+    }
+
+
+    /**
+     * Test an empty OID
+     */
+    public void testOidEmpty()
+    {
+
+        OID oid = new OID();
+
+        try 
+        {
+	        oid.setOID( StringTools.EMPTY_BYTES );
+	        fail( "Should not reach this point ..." );
+        }
+        catch ( IllegalArgumentException iae )
+        {
+        	assertTrue( true );
+        }
+    }
+
+
+    /**
+     * Test itu-t OID tree
+     */
+    public void testOidItuT()
+    {
+
+        OID oid = new OID();
+
+        // itu-t(0), recommendation(0), series a-z (0..26)
+        for ( int i = 1; i < 27; i++ )
+        {
+            oid.setOID( new byte[]
+                { 0x00, ( byte ) i } );
+            assertEquals( "0.0." + i, oid.toString() );
+        }
+
+        // itu-t(0), question(1)
+        oid.setOID( new byte[]
+            { 0x01 } );
+        assertEquals( "0.1", oid.toString() );
+
+        // itu-t(0), administration(2), country(202 .. 748)
+        for ( int i = 202; i < 748; i++ )
+        {
+            oid.setOID( new byte[]
+                { 0x02, ( byte ) ( ( i / 128 ) | 0x0080 ), ( byte ) ( i % 128 ) } );
+            assertEquals( "0.2." + i, oid.toString() );
+        }
+
+        // itu-t(0), network-operator(3), operator(2023 .. 41363)
+        for ( int i = 2023; i < 41363; i++ )
+        {
+
+            if ( i < ( 128 * 128 ) )
+            {
+                oid.setOID( new byte[]
+                    { 0x03, ( byte ) ( ( i / 128 ) | 0x0080 ), ( byte ) ( i % 128 ) } );
+                assertEquals( "0.3." + i, oid.toString() );
+            }
+            else
+            {
+                oid.setOID( new byte[]
+                    { 0x03, ( byte ) ( ( i / ( 128 * 128 ) ) | 0x0080 ),
+                        ( byte ) ( ( ( i / 128 ) % 128 ) | 0x0080 ), ( byte ) ( i % 128 ) } );
+                assertEquals( "0.3." + i, oid.toString() );
+
+            }
+        }
+    }
+
+
+    /**
+     * Test iso OID tree
+     */
+    public void testOidIso()
+    {
+
+        OID oid = new OID();
+
+        // iso(1), standard(0)
+        oid.setOID( new byte[]
+            { 40 + 0 } );
+        assertEquals( "1.0", oid.toString() );
+
+        // iso(1), registration-authority(1)
+        oid.setOID( new byte[]
+            { 40 + 1 } );
+        assertEquals( "1.1", oid.toString() );
+
+        // iso(1), member-body(2)
+        oid.setOID( new byte[]
+            { 40 + 2 } );
+        assertEquals( "1.2", oid.toString() );
+
+        // iso(1), identified-organization(3) | org(3) | organization(3)
+        oid.setOID( new byte[]
+            { 40 + 3 } );
+        assertEquals( "1.3", oid.toString() );
+    }
+
+
+    /**
+     * Test joint-iso-itu-t OID tree
+     */
+    public void testOidJointIsoItuT()
+    {
+
+        OID oid = new OID();
+
+            // joint-iso-itu-t(2), presentation(0)
+            oid.setOID( new byte[]
+                { 80 + 0 } );
+            assertEquals( "2.0", oid.toString() );
+
+            // joint-iso-itu-t(2), asn1(1)
+            oid.setOID( new byte[]
+                { 80 + 1 } );
+            assertEquals( "2.1", oid.toString() );
+
+            // joint-iso-itu-t(2), association-control(2)
+            oid.setOID( new byte[]
+                { 80 + 2 } );
+            assertEquals( "2.2", oid.toString() );
+
+            // joint-iso-itu-t(2), reliable-transfer(3)
+            oid.setOID( new byte[]
+                { 80 + 3 } );
+            assertEquals( "2.3", oid.toString() );
+
+            // ...
+            // joint-iso-itu-t(2), upu(40)
+            oid.setOID( new byte[]
+                { 80 + 40 } );
+            assertEquals( "2.40", oid.toString() );
+
+            // ...
+            // joint-iso-itu-t(2), xxx(100)
+            oid.setOID( new byte[]
+                { ( byte ) ( 0x81 ), 0x34 } );
+            assertEquals( "2.100", oid.toString() );
+    }
+
+
+    /**
+     * Test valid String OIDs
+     */
+    public void testOidStringGood()
+    {
+
+        OID oid = new OID();
+
+        try
+        {
+            oid.setOID( "0.0" );
+            assertEquals( "0.0", oid.toString() );
+
+            oid.setOID( "0.0.0.0.0" );
+            assertEquals( "0.0.0.0.0", oid.toString() );
+
+            oid.setOID( "0.1.2.3.4" );
+            assertEquals( "0.1.2.3.4", oid.toString() );
+
+            oid.setOID( "2.123456" );
+            assertEquals( "2.123456", oid.toString() );
+
+            oid.setOID( "1.2.840.113554.1.2.2" );
+            assertEquals( "1.2.840.113554.1.2.2", oid.toString() );
+        }
+        catch ( InvalidObjectException de )
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test invalid String OIDs
+     */
+    public void testOidStringBad()
+    {
+
+        OID oid = new OID();
+
+        try
+        {
+            oid.setOID( "0" );
+        }
+        catch ( InvalidObjectException de )
+        {
+            assertTrue( true );
+        }
+
+        try
+        {
+            oid.setOID( "0." );
+        }
+        catch ( InvalidObjectException de )
+        {
+            assertTrue( true );
+        }
+
+        try
+        {
+            oid.setOID( "." );
+        }
+        catch ( InvalidObjectException de )
+        {
+            assertTrue( true );
+        }
+
+        try
+        {
+            oid.setOID( "0.1.2." );
+        }
+        catch ( InvalidObjectException de )
+        {
+            assertTrue( true );
+        }
+
+        try
+        {
+            oid.setOID( "3.1" );
+        }
+        catch ( InvalidObjectException de )
+        {
+            assertTrue( true );
+        }
+
+        try
+        {
+            oid.setOID( "0..1" );
+        }
+        catch ( InvalidObjectException de )
+        {
+            assertTrue( true );
+        }
+
+        try
+        {
+            oid.setOID( "0..12" );
+        }
+        catch ( InvalidObjectException de )
+        {
+            assertTrue( true );
+        }
+
+        try
+        {
+            oid.setOID( "0.a.2" );
+        }
+        catch ( InvalidObjectException de )
+        {
+            assertTrue( true );
+        }
+
+        try
+        {
+            oid.setOID( "0.123456" );
+        }
+        catch ( InvalidObjectException de )
+        {
+            assertTrue( true );
+        }
+
+        try
+        {
+            oid.setOID( "1.123456" );
+        }
+        catch ( InvalidObjectException de )
+        {
+            assertTrue( true );
+        }
+
+    }
+
+
+    /**
+     * Test Spnego OID
+     */
+    public void testOidSpnego()
+    {
+
+        OID oid = new OID();
+
+        oid.setOID( new byte[]
+            { 0x2b, 0x06, 0x01, 0x05, 0x05, 0x02 } );
+
+        assertEquals( "1.3.6.1.5.5.2", oid.toString() );
+    }
+
+
+    /**
+     * Test Kerberos V5 OID
+     */
+    public void testOidKerberosV5() throws InvalidObjectException
+    {
+
+        OID oid = new OID();
+
+        oid.setOID( new byte[]
+            { 0x2a, ( byte ) 0x86, 0x48, ( byte ) 0x86, ( byte ) 0xf7, 0x12, 0x01, 0x02, 0x02 } );
+
+        assertEquals( "1.2.840.113554.1.2.2", oid.toString() );
+    }
+
+
+    /**
+     * Test OIDs bytes
+     */
+    public void testOidBytes() throws InvalidObjectException
+    {
+        OID oid = new OID();
+        OID oid2 = new OID();
+
+        oid.setOID( "0.0" );
+        oid2.setOID( oid.getOID() );
+        assertEquals( oid.toString(), oid2.toString() );
+
+        oid.setOID( "0.0.0.0.0" );
+        oid2.setOID( oid.getOID() );
+        assertEquals( oid.toString(), oid2.toString() );
+
+        oid.setOID( "0.1.2.3.4" );
+        oid2.setOID( oid.getOID() );
+        assertEquals( oid.toString(), oid2.toString() );
+
+        oid.setOID( "2.123456" );
+        oid2.setOID( oid.getOID() );
+        assertEquals( oid.toString(), oid2.toString() );
+
+        oid.setOID( "1.2.840.113554.1.2.2" );
+        oid2.setOID( oid.getOID() );
+        assertEquals( oid.toString(), oid2.toString() );
+    }
+}