directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r234313 [2/2] - in /directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber: digester/ digester/rules/ primitives/
Date Sun, 21 Aug 2005 18:46:38 GMT
Added: directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/ByteAccumulator.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/ByteAccumulator.java?rev=234313&view=auto
==============================================================================
--- directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/ByteAccumulator.java (added)
+++ directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/ByteAccumulator.java Sun Aug 21 11:46:27 2005
@@ -0,0 +1,316 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.asn1.ber.digester.rules ;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.commons.lang.ArrayUtils;
+
+
+/**
+ * Gathers bytes from buffers while dynamically growing to accomodate a new size.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 157644 $
+ */
+public class ByteAccumulator
+{
+    /** the default initial size */
+    private static final int DEFAULT_INIT_SIZE = 0 ;
+    /** the default initial size */
+    private static final int DEFAULT_INCREMENT = 100 ;
+
+    /** the accumulator's backing store */
+    private byte[] bs ;
+    /** the current position of the accumulator */
+    private int pos ;
+    /** the growth increment used to augment the backing store */
+    private int increment ;
+    /** the initial size of the backing store */
+    private int initial = DEFAULT_INIT_SIZE ;
+
+
+    // -----------------------------------------------------------------------
+    // C O N S T R U C T O R S
+    // -----------------------------------------------------------------------
+
+    /**
+     * Creates a ByteAccumulator used to gather bytes from various sources
+     * with a default initial size and a default growth increment.
+     */
+    public ByteAccumulator()
+    {
+        bs = ArrayUtils.EMPTY_BYTE_ARRAY ;
+        pos = 0 ;
+        initial = DEFAULT_INIT_SIZE ;
+        increment = DEFAULT_INCREMENT ;
+    }
+
+
+    /**
+     * Creates a ByteAccumulator used to gather bytes from various sources
+     * with a default initial size and a default growth increment.
+     *
+     * @param initial the initial size for the backing store
+     */
+    ByteAccumulator( int initial )
+    {
+        if ( initial <= 0 )
+        {
+            bs = ArrayUtils.EMPTY_BYTE_ARRAY ;
+            this.initial = 0 ;
+        }
+        else
+        {
+            bs = new byte[initial] ;
+            this.initial = initial ;
+        }
+
+        pos = 0 ;
+        increment = DEFAULT_INCREMENT ;
+    }
+
+
+    /**
+     * Fills this accumulator with the content of the argument buffer into
+     * this accumulator.  The buffer argument is fully drained when this
+     * operation completes.
+     *
+     * @param buf the buffer to fill into this accumulator
+     */
+    public void fill( ByteBuffer buf )
+    {
+        while ( buf.hasRemaining() )
+        {
+            if ( pos >= bs.length )
+            {
+                int size = 0 ;
+
+                if ( buf.remaining() > increment )
+                {
+                    size = bs.length + buf.remaining() ;
+                }
+                else
+                {
+                    size = bs.length + increment ;
+                }
+
+                byte[] dest = new byte[ size ] ;
+                System.arraycopy( bs, 0, dest, 0, bs.length ) ;
+                bs = dest ;
+            }
+
+            /*
+             * Find out how much space we have left and if it can hold the
+             * remaining contents of the buffer.
+             */
+            int spaceLeft = bs.length - pos ;
+            if ( buf.remaining() <= spaceLeft )
+            {
+                int remaining = buf.remaining() ;
+                buf.get( bs, pos, remaining ) ;
+                pos += remaining ;
+                return ;
+            }
+
+            /*
+             * there are more bytes in the buffer than we have space so we read
+             * as much as we can into the empty space filling it up all the way
+             * until another cycle of this loop allocates more space.
+             */
+            buf.get( bs, pos, spaceLeft ) ;
+            pos += spaceLeft ;
+        }
+    }
+
+
+    /**
+     * Wraps a ByteBuffer around the populated bytes of this ByteAccumulator
+     * and resets the backing store to a newly allocated byte array of initial
+     * size.
+     *
+     * @return the compacted byte[] wrapped as a ByteBuffer
+     */
+    public ByteBuffer drain()
+    {
+        ByteBuffer compacted ;
+
+        if ( pos == bs.length )
+        {
+            compacted = ByteBuffer.wrap( bs ) ;
+        }
+        else
+        {
+            compacted = ByteBuffer.wrap( bs, 0, pos ) ;
+        }
+
+        if ( initial <= 0 )
+        {
+            bs = ArrayUtils.EMPTY_BYTE_ARRAY ;
+        }
+        else
+        {
+            bs = new byte[initial] ;
+        }
+
+        pos = 0 ;
+        return compacted ;
+    }
+
+
+    /**
+     * Wraps a ByteBuffer around the populated bytes of this ByteAccumulator
+     * and resets the backing store to a newly allocated byte array of initial
+     * size.
+     *
+     * @return the compacted byte[] wrapped as a ByteBuffer
+     */
+    public ByteBuffer drain( int initial )
+    {
+        ByteBuffer compacted ;
+
+        if ( pos == bs.length )
+        {
+            compacted = ByteBuffer.wrap( bs ) ;
+        }
+        else
+        {
+            compacted = ByteBuffer.wrap( bs, 0, pos ) ;
+        }
+
+        if ( initial <= 0 )
+        {
+            bs = ArrayUtils.EMPTY_BYTE_ARRAY ;
+        }
+        else
+        {
+            bs = new byte[initial] ;
+        }
+
+        pos = 0 ;
+        return compacted ;
+    }
+
+
+    /**
+     * Allocates memory to handle a capacity without the need to grow.
+     * This serves to control growth for more efficient use.
+     *
+     * @param capacity the capacity to hold without the need to grow
+     */
+    public void ensureCapacity( int capacity )
+    {
+        if ( bs.length < capacity )
+        {
+            byte[] newArray = new byte[capacity] ;
+
+            if ( bs != ArrayUtils.EMPTY_BYTE_ARRAY )
+            {
+                System.arraycopy( bs, 0, newArray, 0, pos + 1 ) ;
+            }
+
+            bs = newArray ;
+        }
+    }
+
+
+    /**
+     * The growth increment by which the backing store is augmented.
+     *
+     * @return the number of bytes to grow the backing store by
+     */
+    public int getGrowthIncrement()
+    {
+        return increment ;
+    }
+
+
+    /**
+     * The initial size of the backing store.
+     *
+     * @return the initial size in bytes of the backing store
+     */
+    public int getInitialSize()
+    {
+        return initial ;
+    }
+
+
+    /**
+     * The current capacity of the backing store which may change as this
+     * accumulator is filled with bytes.
+     *
+     * @return the current capacity in bytes
+     */
+    public int getCapacity()
+    {
+        return bs.length ;
+    }
+
+
+    /**
+     * The remaining free space that can be filled before having to grow the
+     * backing store of the accumulator.
+     *
+     * @return the remaining free space until the next growth spurt
+     */
+    public int getRemainingSpace()
+    {
+        return bs.length - pos ;
+    }
+
+
+    /**
+     * The current position within the backing store marking the point to
+     * which this accumulator is filled.
+     *
+     * @return the current fill position
+     */
+    public int getPosition()
+    {
+        return pos ;
+    }
+
+
+    /**
+     * Gets a compacted copy of this ByteAccumulator's backing store.  The
+     * compacted byte array is equal to the amount of bytes put into this
+     * ByteAccumulator which may still have free space to populate since the
+     * last growth took place.
+     *
+     * @return the compacted copy of this ByteAccumulator
+     */
+/*
+    public byte[] getCompactedCopy()
+    {
+        byte[] compacted ;
+
+        if ( pos == bs.length )
+        {
+            compacted = (byte[]) bs.clone() ;
+        }
+        else
+        {
+            compacted = new byte[pos+1] ;
+        }
+
+        System.arraycopy( bs, 0, compacted, 0, pos + 1 ) ;
+        return compacted ;
+    }
+*/
+}

Added: directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/ObjectCreateRule.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/ObjectCreateRule.java?rev=234313&view=auto
==============================================================================
--- directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/ObjectCreateRule.java (added)
+++ directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/ObjectCreateRule.java Sun Aug 21 11:46:27 2005
@@ -0,0 +1,82 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.asn1.ber.digester.rules ;
+
+
+import org.apache.asn1.ber.TypeClass;
+import org.apache.asn1.ber.digester.AbstractRule;
+import org.apache.asn1.ber.digester.BERDigester;
+import org.apache.commons.lang.exception.NestableRuntimeException;
+
+
+/**
+ * Rule implementation that creates a new object and pushes it onto the
+ * object stack when a TLV is encountered.  When the TLV is complete,
+ * the object will be popped off of the stack.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Direclectory Project</a>
+ * @version $Rev: 157644 $
+ */
+public class ObjectCreateRule extends AbstractRule
+{
+    /** the class of object to instantiate and push */
+    private final Class clazz ;
+
+
+    /**
+     * Creates a rule that creates an instance of an object when the tag
+     *
+     * @param clazz the class to create an instance of.
+     */
+    public ObjectCreateRule( BERDigester digester, Class clazz )
+    {
+        this.clazz = clazz ;
+        setDigester( digester ) ;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#tag(int, boolean,
+     * org.apache.asn1.ber.TypeClass)
+     */
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        try
+        {
+            Object obj = clazz.newInstance() ;
+            getDigester().push( obj ) ;
+        }
+        catch ( InstantiationException e )
+        {
+            throw new NestableRuntimeException( e ) ;
+        }
+        catch ( IllegalAccessException e )
+        {
+            throw new NestableRuntimeException( e ) ;
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        getDigester().pop() ;
+    }
+}
+

Added: directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/Octets2StringRule.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/Octets2StringRule.java?rev=234313&view=auto
==============================================================================
--- directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/Octets2StringRule.java (added)
+++ directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/Octets2StringRule.java Sun Aug 21 11:46:27 2005
@@ -0,0 +1,71 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.asn1.ber.digester.rules ;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.asn1.ber.TagEnum;
+
+
+/**
+ * Rule that collects octets and leaves octets as a string on the stack.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory
+ *         Project</a>
+ * @version $Rev: 157644 $
+ */
+public class Octets2StringRule extends PrimitiveOctetStringRule
+{
+    public Octets2StringRule()
+    {
+        super();
+    }
+
+
+    public Octets2StringRule( TagEnum tag )
+    {
+        super( tag );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        super.finish() ;
+
+        // pop the ByteBuffer the super method pushed
+        ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ;
+
+        byte[] octets = null ;
+        if ( buf.limit() == buf.capacity() && buf.hasArray() )
+        {
+            // use the backing store
+            octets = buf.array() ;
+        }
+        else
+        {
+            // copy because we don't have accessible array or data < array
+            octets = new byte[buf.remaining()] ;
+            buf.get( octets ) ;
+        }
+
+        getDigester().push( new String( octets ) ) ;
+    }
+}

Added: directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/PopOnFinish.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/PopOnFinish.java?rev=234313&view=auto
==============================================================================
--- directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/PopOnFinish.java (added)
+++ directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/PopOnFinish.java Sun Aug 21 11:46:27 2005
@@ -0,0 +1,40 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.asn1.ber.digester.rules;
+
+
+import org.apache.asn1.ber.digester.AbstractRule;
+
+
+/**
+ * Document this class.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory
+ *         Project</a>
+ * @version $Rev: 157644 $
+ */
+public class PopOnFinish extends AbstractRule
+{
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        super.finish() ;
+        getDigester().pop() ;
+    }
+}

Added: directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/PrimitiveBooleanRule.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/PrimitiveBooleanRule.java?rev=234313&view=auto
==============================================================================
--- directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/PrimitiveBooleanRule.java (added)
+++ directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/PrimitiveBooleanRule.java Sun Aug 21 11:46:27 2005
@@ -0,0 +1,154 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.asn1.ber.digester.rules ;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.asn1.ber.TagEnum;
+import org.apache.asn1.ber.TypeClass;
+import org.apache.asn1.ber.digester.AbstractRule;
+import org.apache.asn1.ber.primitives.PrimitiveUtils;
+import org.apache.asn1.ber.primitives.UniversalTag;
+
+
+/**
+ * A rule to Decode a BER encoded ASN.1 INTEGER into a Java primitive int.
+ * <p>
+ * The bytes to form the integer are extracted from the BER value which may
+ * arrive in multiple chunks.  The individual bytes are temporarily stored
+ * within a 4 byte array while incrementing a counter to track the capture.
+ * Once gathered the bytes are decoded into a int in the finish
+ * </p>
+ * <p>
+ * As a side effect once the decode is complete, the primitive value is pushed
+ * onto the primitive int stack to be utilized by other rules later.  If there
+ * is a loss of precision where the ASN.1 INTEGER is larger or smaller than
+ * the maximum or minimum value of a Java primitive integer an exception is
+ * thrown.
+ * </p>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory
+ * Project</a>
+ * @version $Rev: 157644 $
+ */
+public class PrimitiveBooleanRule extends AbstractRule
+{
+    /** the octet for the Java primitive boolean */
+    private byte value = 0 ;
+    /** boolean flag to determine if we have read the single octet */
+    private boolean octetSet = false ;
+    /** the tag this rule accepts */
+    private final TagEnum tag ;
+
+
+    // -----------------------------------------------------------------------
+    // C O N S T R U C T O R S
+    // -----------------------------------------------------------------------
+
+
+    /**
+     * Creates a default primitive boolean decoding rule that only accepts
+     * tags of UniversalTag.BOOLEAN.
+     */
+    public PrimitiveBooleanRule()
+    {
+        tag = UniversalTag.BOOLEAN ;
+    }
+
+
+    /**
+     * Creates a default primitive integer decoding rule that only accepts
+     * tags of UniversalTag.INTEGER.
+     */
+    public PrimitiveBooleanRule( TagEnum tag )
+    {
+        this.tag = tag ;
+    }
+
+
+    // -----------------------------------------------------------------------
+    // Rule Implementation
+    // -----------------------------------------------------------------------
+
+
+    /* (non-Javadoc)
+     * @see org.apache.asn1.ber.digester.Rule#tag(int, boolean,
+     * org.apache.asn1.ber.TypeClass)
+     */
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        if ( id != tag.getTagId() )
+        {
+            throw new IllegalArgumentException(
+                    "Expecting " + tag.getName()
+                    + " with an id of " + tag.getTagId()
+                    + " but instead got a tag id of " + id ) ;
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.asn1.ber.digester.Rule#length(int)
+     */
+    public void length( int length )
+    {
+        if ( length != 1 )
+        {
+            throw new IllegalArgumentException( "The target primitive for this "
+                + "rule only requires a single octet with a length of 1.  "
+                + "The length of the field however is " + length ) ;
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.asn1.ber.digester.Rule#value(java.nio.ByteBuffer)
+     */
+    public void value( ByteBuffer buf )
+    {
+        if ( octetSet )
+        {
+            throw new IllegalArgumentException( "The target primitive for this "
+                + "rule only requires a single octet with a length of 1.  "
+                + "That octet has already been set." ) ;
+        }
+
+        while ( buf.hasRemaining() )
+        {
+            value = buf.get() ;
+            octetSet = true ;
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.asn1.ber.digester.Rule#finish()
+     */
+    public void finish()
+    {
+        if ( getDigester() != null )
+        {
+            getDigester().pushBoolean(
+                    PrimitiveUtils.berDecodeBoolean( value ) ) ;
+        }
+
+        // cleanup
+        this.value = 0 ;
+        this.octetSet = false ;
+    }
+}

Added: directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/PrimitiveEnumDecodeRule.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/PrimitiveEnumDecodeRule.java?rev=234313&view=auto
==============================================================================
--- directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/PrimitiveEnumDecodeRule.java (added)
+++ directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/PrimitiveEnumDecodeRule.java Sun Aug 21 11:46:27 2005
@@ -0,0 +1,48 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.asn1.ber.digester.rules ;
+
+
+import org.apache.asn1.ber.TagEnum;
+import org.apache.asn1.ber.primitives.UniversalTag;
+
+
+/**
+ * Rule for decoding an ASN.1 ENUMERATED type.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 157644 $
+ */
+public class PrimitiveEnumDecodeRule extends PrimitiveIntDecodeRule
+{
+    /**
+     * Simply uses the UniversalTag.ENUMERATED tag instead of int.
+     */
+    public PrimitiveEnumDecodeRule()
+    {
+        super( UniversalTag.ENUMERATED ) ;
+    }
+
+
+    /**
+     * Simply uses the UniversalTag.ENUMERATED tag instead of int.
+     */
+    public PrimitiveEnumDecodeRule( TagEnum tag )
+    {
+        super( tag ) ;
+    }
+}

Added: directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/PrimitiveIntDecodeRule.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/PrimitiveIntDecodeRule.java?rev=234313&view=auto
==============================================================================
--- directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/PrimitiveIntDecodeRule.java (added)
+++ directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/PrimitiveIntDecodeRule.java Sun Aug 21 11:46:27 2005
@@ -0,0 +1,171 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.asn1.ber.digester.rules ;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.asn1.ber.TagEnum;
+import org.apache.asn1.ber.TypeClass;
+import org.apache.asn1.ber.digester.AbstractRule;
+import org.apache.asn1.ber.primitives.PrimitiveUtils;
+import org.apache.asn1.ber.primitives.UniversalTag;
+
+
+/**
+ * A rule to Decode a BER encoded ASN.1 INTEGER into a Java primitive int.
+ * <p>
+ * The bytes to form the integer are extracted from the BER value which may
+ * arrive in multiple chunks.  The individual bytes are temporarily stored
+ * within a 4 byte array while incrementing a counter to track the capture.
+ * Once gathered the bytes are decoded into a int in the finish
+ * </p>
+ * <p>
+ * As a side effect once the decode is complete, the primitive value is pushed
+ * onto the primitive int stack to be utilized by other rules later.  If there
+ * is a loss of precision where the ASN.1 INTEGER is larger or smaller than
+ * the maximum or minimum value of a Java primitive integer an exception is
+ * thrown.
+ * </p>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 157644 $
+ */
+public class PrimitiveIntDecodeRule extends AbstractRule
+{
+    /** the bytes used to form the Java primitive integer */
+    private final byte[] value = new byte[4] ;
+    /** the current 8 bit position to fill in the integer */
+    private int pos ;
+    /** the number of bytes we must read */
+    private int length ;
+    /** the tag this rule accepts */
+    private final TagEnum tag ;
+
+
+    // -----------------------------------------------------------------------
+    // C O N S T R U C T O R S
+    // -----------------------------------------------------------------------
+
+
+    /**
+     * Creates a default primitive integer decoding rule that only accepts
+     * tags of UniversalTag.INTEGER.
+     */
+    public PrimitiveIntDecodeRule()
+    {
+        tag = UniversalTag.INTEGER ;
+    }
+
+
+    /**
+     * Creates a default primitive integer decoding rule that only accepts
+     * tags of UniversalTag.INTEGER.
+     */
+    public PrimitiveIntDecodeRule( TagEnum tag )
+    {
+        this.tag = tag ;
+    }
+
+
+    // -----------------------------------------------------------------------
+    // Rule Implementation
+    // -----------------------------------------------------------------------
+
+
+    /* (non-Javadoc)
+     * @see org.apache.asn1.ber.digester.Rule#tag(int, boolean,
+     * org.apache.asn1.ber.TypeClass)
+     */
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        if ( id != tag.getTagId() )
+        {
+            throw new IllegalArgumentException(
+                    "Expecting " + tag.getName()
+                    + " with an id of " + tag.getTagId()
+                    + " but instead got a tag id of " + id ) ;
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.asn1.ber.digester.Rule#length(int)
+     */
+    public void length( int length )
+    {
+        if ( length > 4 || length < 0 )
+        {
+            throw new IllegalArgumentException( "The target primitive for this "
+                + "rule can only hold integers of 32 bits or 4 bytes.  "
+                + "The length of the field however is " + length ) ;
+        }
+
+        this.length = length ;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.asn1.ber.digester.Rule#value(java.nio.ByteBuffer)
+     */
+    public void value( ByteBuffer buf )
+    {
+        if ( buf == null )
+        {
+            return ;
+        }
+
+        while ( buf.hasRemaining() && ( pos + 1 ) <= length )
+        {
+            value[pos] = buf.get() ;
+            pos++ ;
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.asn1.ber.digester.Rule#finish()
+     */
+    public void finish()
+    {
+        // decode and push primitive integer onto stack
+        int numba = PrimitiveUtils.decodeInt( this.value, 0, this.length ) ;
+
+        if ( getDigester() != null )
+        {
+            getDigester().pushInt( numba ) ;
+        }
+
+        // cleanup
+        this.pos = 0 ;
+        this.length = 0 ;
+    }
+
+
+    /**
+     * Used for testing to check and see if a value of the byte buffer has
+     * been set after a value event.
+     *
+     * @param bite the byte value to check
+     * @param ii the index to check the byte for in the values array
+     * @return true if the byte value matches the byte value in the array
+     */
+    boolean equals( byte bite, int ii )
+    {
+        return value[ii] == bite ;
+    }
+}

Added: directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/PrimitiveOctetStringRule.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/PrimitiveOctetStringRule.java?rev=234313&view=auto
==============================================================================
--- directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/PrimitiveOctetStringRule.java (added)
+++ directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/digester/rules/PrimitiveOctetStringRule.java Sun Aug 21 11:46:27 2005
@@ -0,0 +1,214 @@
+/*
+ *   Copyright 2004-2005 The Apache Software Foundation
+ *
+ *   Licensed 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.asn1.ber.digester.rules ;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.asn1.ber.Length;
+import org.apache.asn1.ber.TagEnum;
+import org.apache.asn1.ber.TypeClass;
+import org.apache.asn1.ber.digester.AbstractRule;
+import org.apache.asn1.ber.primitives.UniversalTag;
+
+
+/**
+ * A rule that collects the value bytes of an ASN.1 OCTET STRING and pushes
+ * the buffer of bytes onto the digester's Object stack as a ByteBuffer.
+ * <p>
+ * This rule can only handle primitive octet strings.  Constructed OCTET STRING
+ * values are simply ignored by this rule rather than throwing exceptions.
+ * </p>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 157644 $
+ */
+public class PrimitiveOctetStringRule extends AbstractRule
+{
+    /** used to accumulate value bytes */
+    private final ByteAccumulator accumulator = new ByteAccumulator( 0 ) ;
+    /** used to determine if our type is constructed or primitive */
+    private boolean isConstructed = false ;
+    /** the tag to be accepted which defaults to an UNIVERSAL OCTET_STRING */
+    private final TagEnum tag ;
+
+
+    // -----------------------------------------------------------------------
+    // C O N S T R U C T O R S
+    // -----------------------------------------------------------------------
+
+
+    /**
+     * Creates a rule using defaults where only the OCTET_STRING tag id
+     * is accepted.
+     */
+    public PrimitiveOctetStringRule()
+    {
+        tag = UniversalTag.OCTET_STRING ;
+    }
+
+
+    /**
+     * Creates a rule where only a specific tag is accepted.  Sometimes
+     * OCTET_STRING fields are tagged with application specific tags.  In
+     * this case we match for a different tag.
+     *
+     * @param tag the tag to accept
+     */
+    public PrimitiveOctetStringRule( TagEnum tag )
+    {
+        this.tag = tag ;
+    }
+
+
+    // -----------------------------------------------------------------------
+    // Rule event method overrides
+    // -----------------------------------------------------------------------
+
+
+    /**
+     * Rejects tag id's that are not equal to this Rules's id.
+     *
+     * @see org.apache.asn1.ber.digester.Rule#tag(int, boolean,
+     * org.apache.asn1.ber.TypeClass)
+     */
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        isConstructed = ! isPrimitive ;
+
+        if ( isConstructed )
+        {
+            return ;
+        }
+
+        if ( this.tag.getTagId() != id )
+        {
+            throw new IllegalArgumentException(
+                    "Expecting " + this.tag.getName()
+                    + " with an id of " + this.tag.getTagId()
+                    + " but instead got a tag id of " + id ) ;
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#length(int)
+     */
+    public void length( int length )
+    {
+        if ( isConstructed )
+        {
+            return ;
+        }
+
+        // @todo Length should not be visible outside of the digester
+        // package.  The digester or a contants interface should contain
+        // these constants.
+        if ( Length.INDEFINITE != length )
+        {
+            accumulator.ensureCapacity( length ) ;
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#value(java.nio.ByteBuffer)
+     */
+    public void value( ByteBuffer buf )
+    {
+        if ( isConstructed )
+        {
+            return ;
+        }
+
+        if ( buf == null || !buf.hasRemaining() )
+        {
+            return ;
+        }
+
+        accumulator.fill( buf ) ;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        if ( isConstructed )
+        {
+            return ;
+        }
+
+        // push the octet string onto the digester's object stack
+        getDigester().push( accumulator.drain( 0 ) ) ;
+
+        // clean up
+        isConstructed = false ;
+    }
+
+
+    // -----------------------------------------------------------------------
+    // Protected Methods
+    // -----------------------------------------------------------------------
+
+
+    /**
+     * Gets the ByteAccumulator used by this octet string gathering rule.
+     *
+     * @return the accumulator used to store octets
+     */
+    protected ByteAccumulator getAccumulator()
+    {
+        return accumulator ;
+    }
+
+
+    /**
+     * Gets whether or not the current TLV for this octet string is
+     * constructed.
+     *
+     * @return true if it's constructed, false otherwise
+     */
+    protected boolean isConstructed()
+    {
+        return isConstructed ;
+    }
+
+
+    /**
+     * Gets whether or not the current TLV for this octet string is
+     * constructed.
+     *
+     * @param isConstructed true to set to constructed, false otherwise
+     */
+    protected void setConstructed( boolean isConstructed )
+    {
+        this.isConstructed = isConstructed ;
+    }
+
+
+    /**
+     * Gets the tag associated with this rule.
+     *
+     * @return the tag associated with this rule
+     */
+    protected TagEnum getTag()
+    {
+        return tag ;
+    }
+}

Added: directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/primitives/ContextSpecificTag.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/primitives/ContextSpecificTag.java?rev=234313&view=auto
==============================================================================
--- directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/primitives/ContextSpecificTag.java (added)
+++ directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/primitives/ContextSpecificTag.java Sun Aug 21 11:46:27 2005
@@ -0,0 +1,40 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.asn1.ber.primitives ;
+
+
+import org.apache.asn1.ber.Tag;
+import org.apache.asn1.ber.TagEnum;
+import org.apache.asn1.ber.TypeClass;
+
+
+/**
+ * Easy to use tag with public constructor for the CONTEXT_SPECIFIC type class.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory
+ *         Project</a>
+ * @version $Rev: 157644 $
+ */
+public class ContextSpecificTag extends TagEnum
+{
+    public ContextSpecificTag( int id, boolean isConstructed )
+    {
+        super( ( isConstructed ? "constructed " : "primitive " )
+                + "[" + id + "]", Tag.getIntEncodedTag(
+                        TypeClass.CONTEXT_SPECIFIC, id, isConstructed ), id );
+    }
+}

Added: directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/primitives/PrimitiveUtils.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/primitives/PrimitiveUtils.java?rev=234313&view=auto
==============================================================================
--- directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/primitives/PrimitiveUtils.java (added)
+++ directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/primitives/PrimitiveUtils.java Sun Aug 21 11:46:27 2005
@@ -0,0 +1,209 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.asn1.ber.primitives ;
+
+
+/**
+ * Utilities for decoding and encoding primitive constructs.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 157644 $
+ */
+public class PrimitiveUtils
+{
+    private static final int ONE_BYTE_MAX   =  (1<<7)-1;
+    private static final int ONE_BYTE_MIN   = -(1<<7);
+    private static final int TWO_BYTE_MAX   =  (1<<15)-1;
+    private static final int TWO_BYTE_MIN   = -(1<<15);
+    private static final int THREE_BYTE_MAX =  (1<<23)-1;
+    private static final int THREE_BYTE_MIN = -(1<<23);
+    private static final int FOUR_BYTE_MAX  =  Integer.MAX_VALUE;
+    private static final int FOUR_BYTE_MIN  =  Integer.MIN_VALUE;
+    private static final byte[] TRUE_ARRAY = new byte[] { ( byte ) 0xFF };
+    private static final byte[] FALSE_ARRAY = new byte[] { ( byte ) 0x00 };
+
+
+
+    public static boolean berDecodeBoolean( byte value )
+    {
+        if ( value == 0 )
+        {
+            return false ;
+        }
+
+        return true ;
+    }
+
+
+    /**
+     * Encodes a boolean as a byte following the stricter CER and DER
+     * requirements where true must be a value of 0xFF and false is 0x00.
+     *
+     * @param bool the boolean to encode
+     * @return 0xFF if bool is true, 0x00 if the bool is false
+     */
+    public static byte encodeBooleanAsByte( boolean bool )
+    {
+        return bool ? ( byte ) 0xFF : ( byte ) 0;
+    }
+
+
+    /**
+     * Encodes a boolean as a byte[] with one byte following the stricter CER
+     * and DER requirements where true must be a value of 0xFF and false is
+     * 0x00.  Although there is alway one byte returned we return a byte [] as
+     * a convenience since most of the time a byte[] is expected after encoding
+     * a primitive type.
+     *
+     * @param bool the boolean to encode
+     * @return a byte array of length 1 where the single byte is 0xFF if bool
+     * is true, 0x00 if the bool is false
+     */
+    public static byte[] encodeBoolean( boolean bool )
+    {
+        return bool ? TRUE_ARRAY : FALSE_ARRAY ;
+    }
+
+
+    public static boolean derCerDecodeBoolean( byte value )
+    {
+        if ( value == 0 )
+        {
+            return false ;
+        }
+        else if ( value == 0xFF )
+        {
+            return true ;
+        }
+        else
+        {
+            String msg = "For DER and CER encodings of boolean values the only "
+                    + " permisable values are 0x00 for false and 0xFF for true."
+                    + " A value of " + value + " is not allowed!" ;
+            throw new IllegalArgumentException( msg ) ;
+        }
+    }
+
+
+    public static byte[] encodeInt( int source )
+    {
+        byte[] encoded = null;
+
+        if ( source >= ONE_BYTE_MIN && source <= ONE_BYTE_MAX )
+        {
+            encoded = new byte[1];
+            encoded[0] = ( byte ) source;
+        }
+        else if ( source >= TWO_BYTE_MIN && source <= TWO_BYTE_MAX )
+        {
+            encoded = new byte[2];
+            encoded[1] = ( byte ) source;
+            encoded[0] = ( byte ) ( source >> 8 );
+        }
+        else if ( source >= THREE_BYTE_MIN && source <= THREE_BYTE_MAX )
+        {
+            encoded = new byte[3];
+            encoded[2] = ( byte ) source;
+            encoded[1] = ( byte ) ( source >> 8 );
+            encoded[0] = ( byte ) ( source >> 16 );
+        }
+        else if ( source >= FOUR_BYTE_MIN && source <= FOUR_BYTE_MAX )
+        {
+            encoded = new byte[4];
+            encoded[3] = ( byte ) source;
+            encoded[2] = ( byte ) ( source >> 8 );
+            encoded[1] = ( byte ) ( source >> 16 );
+            encoded[0] = ( byte ) ( source >> 24 );
+        }
+
+        return encoded;
+    }
+
+
+    /**
+     * Decodes a BER encoded ASN.1 INTEGER into a Java primitive int.
+     *
+     * @param bites the bytes containing the encoded ASN.1 INTEGER
+     * @param offset the offset from zero where the bytes begin
+     * @param length the length of the bytes to read from the offset
+     * @return the decoded primitive int or zero if the length is 0
+     * @throws IllegalArgumentException if the length is not within
+     * range [0-4]
+     * @throws IndexOutOfBoundsException if offset is less than 0 or
+     * it is greater than bites.length - length
+     */
+    public static int decodeInt( byte[] bites, int offset, int length )
+    {
+        int value = 0 ;
+
+        if ( length == 0 )
+        {
+            return 0 ;
+        }
+
+        switch( length )
+        {
+            case( 1 ):
+                if ( ( bites[offset+0] & 0x80 ) == 0x80 )
+                {
+                    value |= bites[offset+0] | 0xffffff00 ;
+                }
+                else
+                {
+                    value |= bites[offset+0] & 0x000000ff ;
+                }
+
+                break ;
+            case( 2 ):
+                if ( ( bites[offset+0] & 0x80 ) == 0x80 )
+                {
+                    value |= ( bites[offset+0] << 8 ) | 0xffff0000 ;
+                }
+                else
+                {
+                    value |= ( bites[offset+0] << 8 ) ;
+                }
+
+                value |= ( bites[offset+1] & 0x000000ff );
+                break ;
+            case( 3 ):
+                if ( ( bites[offset+0] & 0x80 ) == 0x80 )
+                {
+                    value |= ( bites[offset+0] << 16 ) | 0xff000000 ;
+                }
+                else
+                {
+                    value |= ( bites[offset+0] << 16 ) ;
+                }
+
+                value |= ( bites[offset+1] << 8 ) & 0x0000ff00;
+                value |= bites[offset+2] & 0x000000ff;
+                break ;
+            case( 4 ):
+                value |= ( bites[offset+0] << 24 ) & 0xff000000;
+                value |= ( bites[offset+1] << 16 ) & 0x00ff0000;
+                value |= ( bites[offset+2] << 8 )  & 0x0000ff00;
+                value |= bites[offset+3] & 0x000000ff;
+                break ;
+            default:
+                throw new IllegalArgumentException(
+                        "Length should be in range [0-4]" ) ;
+        }
+
+        return value ;
+    }
+}

Added: directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/primitives/UniversalTag.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/primitives/UniversalTag.java?rev=234313&view=auto
==============================================================================
--- directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/primitives/UniversalTag.java (added)
+++ directory/asn1/branches/asn1-new-ber/ber/src/java/org/apache/asn1/ber/primitives/UniversalTag.java Sun Aug 21 11:46:27 2005
@@ -0,0 +1,618 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.asn1.ber.primitives ;
+
+
+import java.util.Map ;
+import java.util.List ;
+
+import org.apache.commons.lang.enum.EnumUtils ;
+
+import org.apache.asn1.ber.TagEnum ;
+
+
+/**
+ * Type safe enum for ASN.1 UNIVERSAL class tags.  The tags values are
+ * constructed using the SNACC representation for tags without the 
+ * primitive/constructed bit.  This is done because several bit, octet and
+ * character string types can be encoded as primitives or as constructed types 
+ * to chunk the value out.
+ * <p>
+ * These tags can have one of the following values:
+ * <p>
+ * <table border=1 cellspacing=1 width=60% >
+ * <tr><th>Id</th><th>Usage</th></tr>
+ * <tr><td>[UNIVERSAL 0]</td>       <td>reserved for BER</td></tr>
+ * <tr><td>[UNIVERSAL 1]</td>       <td>BOOLEAN</td></tr>
+ * <tr><td>[UNIVERSAL 2]</td>       <td>INTEGER</td></tr>
+ * <tr><td>[UNIVERSAL 3]</td>       <td>BIT STRING</td></tr>
+ * <tr><td>[UNIVERSAL 4]</td>       <td>OCTET STRING</td></tr>
+ * <tr><td>[UNIVERSAL 5]</td>       <td>NULL</td></tr>
+ * <tr><td>[UNIVERSAL 6]</td>       <td>OBJECT IDENTIFIER</td></tr>
+ * <tr><td>[UNIVERSAL 7]</td>       <td>ObjectDescriptor</td></tr>
+ * <tr><td>[UNIVERSAL 8]</td>       <td>EXTERNAL, INSTANCE OF</td></tr>
+ * <tr><td>[UNIVERSAL 9]</td>       <td>REAL</td></tr>
+ * <tr><td>[UNIVERSAL 10]</td>      <td>ENUMERATED</td></tr>
+ * <tr><td>[UNIVERSAL 11]</td>      <td>EMBEDDED PDV</td></tr>
+ * <tr><td>[UNIVERSAL 12]</td>      <td>UTF8String</td></tr>
+ * <tr><td>[UNIVERSAL 13]</td>      <td>RELATIVE-OID</td></tr>
+ * <tr><td>[UNIVERSAL 14]</td>      <td>reserved for future use</td></tr>
+ * <tr><td>[UNIVERSAL 15]</td>      <td>reserved for future use</td></tr>
+ * <tr><td>[UNIVERSAL 16]</td>      <td>SEQUENCE, SEQUENCE OF</td></tr>
+ * <tr><td>[UNIVERSAL 17]</td>      <td>SET, SET OF</td></tr>
+ * <tr><td>[UNIVERSAL 18]</td>      <td>NumericString</td></tr>
+ * <tr><td>[UNIVERSAL 19]</td>      <td>PrintableString</td></tr>
+ * <tr><td>[UNIVERSAL 20]</td>      <td>TeletexString, T61String</td></tr>
+ * <tr><td>[UNIVERSAL 21]</td>      <td>VideotexString</td></tr>
+ * <tr><td>[UNIVERSAL 22]</td>      <td>IA5String</td></tr>
+ * <tr><td>[UNIVERSAL 23]</td>      <td>UTCTime</td></tr>
+ * <tr><td>[UNIVERSAL 24]</td>      <td>GeneralizedTime</td></tr>
+ * <tr><td>[UNIVERSAL 25]</td>      <td>GraphicString</td></tr>
+ * <tr><td>[UNIVERSAL 26]</td>      <td>VisibleString, ISO646String</td></tr>
+ * <tr><td>[UNIVERSAL 27]</td>      <td>GeneralString</td></tr>
+ * <tr><td>[UNIVERSAL 28]</td>      <td>UniversalString</td></tr>
+ * <tr><td>[UNIVERSAL 29]</td>      <td>CHARACTER STRING</td></tr>
+ * <tr><td>[UNIVERSAL 30]</td>      <td>BMPString</td></tr>
+ * <tr><td>[UNIVERSAL 31]</td>      <td>reserved for future use</td></tr>
+ * </table> 
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">
+ * Apache Directory Project</a>
+ * @version $Rev: 157644 $
+ */
+public class UniversalTag extends TagEnum
+{
+    /** value for the tag */
+    private static final int RESERVED0_VAL =                 0x00000000 ;
+    /** value for the tag */
+    private static final int BOOLEAN_VAL =                   0x01000000 ;
+    /** value for the tag */
+    private static final int INTEGER_VAL =                   0x02000000 ;
+    /** value for the tag */
+    private static final int BIT_STRING_VAL =                0x03000000 ;
+    /** value for the tag */
+    private static final int OCTET_STRING_VAL =              0x04000000 ;
+    /** value for the tag */
+    private static final int NULL_VAL =                      0x05000000 ;
+    /** value for the tag */
+    private static final int OBJECT_IDENTIFIER_VAL =         0x06000000 ;
+    /** value for the tag */
+    private static final int OBJECT_DESCRIPTOR_VAL =         0x07000000 ;
+    /** value for the tag */
+    private static final int EXTERNAL_INSTANCE_OF_VAL =      0x08000000 ;
+    /** value for the tag */
+    private static final int REAL_VAL =                      0x09000000 ;
+    /** value for the tag */
+    private static final int ENUMERATED_VAL =                0x0a000000 ;
+    /** value for the tag */
+    private static final int EMBEDDED_PDV_VAL =              0x0b000000 ;
+    /** value for the tag */
+    private static final int UTF8_STRING_VAL =               0x0c000000 ;
+    /** value for the tag */
+    private static final int RELATIVE_OID_VAL =              0x0d000000 ;
+    /** value for the tag */
+    private static final int RESERVED14_VAL =                0x0e000000 ;
+    /** value for the tag */
+    private static final int RESERVED15_VAL =                0x0f000000 ;
+    /** value for the tag */
+    private static final int SEQUENCE_SEQUENCE_OF_VAL =      0x10000000 ;
+    /** value for the tag */
+    private static final int SET_SET_OF_VAL =                0x11000000 ;
+    /** value for the tag */
+    private static final int NUMERIC_STRING_VAL =            0x12000000 ;
+    /** value for the tag */
+    private static final int PRINTABLE_STRING_VAL =          0x13000000 ;
+    /** value for the tag */
+    private static final int TELETEX_STRING_VAL =            0x14000000 ;
+    /** value for the tag */
+    private static final int VIDEOTEX_STRING_VAL =           0x15000000 ;
+    /** value for the tag */
+    private static final int IA5_STRING_VAL =                0x16000000 ;
+    /** value for the tag */
+    private static final int UTC_TIME_VAL =                  0x17000000 ;
+    /** value for the tag */
+    private static final int GENERALIZED_TIME_VAL =          0x18000000 ;
+    /** value for the tag */
+    private static final int GRAPHIC_STRING_VAL =            0x19000000 ;
+    /** value for the tag */
+    private static final int VISIBLE_STRING_VAL =            0x1a000000 ;
+    /** value for the tag */
+    private static final int GENERAL_STRING_VAL =            0x1b000000 ;
+    /** value for the tag */
+    private static final int UNIVERSAL_STRING_VAL =          0x1c000000 ;
+    /** value for the tag */
+    private static final int CHARACTER_STRING_VAL =          0x1d000000 ;
+    /** value for the tag */
+    private static final int BMP_STRING_VAL =                0x1e000000 ;
+    /** value for the tag */
+    private static final int RESERVED31_VAL =                0x1f000000 ;
+
+    /** value for the tag */
+    private static final int RESERVED0_ID =                 0 ;
+    /** value for the tag */
+    private static final int BOOLEAN_ID =                   1 ;
+    /** value for the tag */
+    private static final int INTEGER_ID =                   2 ;
+    /** value for the tag */
+    private static final int BIT_STRING_ID =                3 ;
+    /** value for the tag */
+    private static final int OCTET_STRING_ID =              4 ;
+    /** value for the tag */
+    private static final int NULL_ID =                      5 ;
+    /** value for the tag */
+    private static final int OBJECT_IDENTIFIER_ID =         6 ;
+    /** value for the tag */
+    private static final int OBJECT_DESCRIPTOR_ID =         7 ;
+    /** value for the tag */
+    private static final int EXTERNAL_INSTANCE_OF_ID =      8 ;
+    /** value for the tag */
+    private static final int REAL_ID =                      9 ;
+    /** value for the tag */
+    private static final int ENUMERATED_ID =                10 ;
+    /** value for the tag */
+    private static final int EMBEDDED_PDV_ID =              11 ;
+    /** value for the tag */
+    private static final int UTF8_STRING_ID =               12 ;
+    /** value for the tag */
+    private static final int RELATIVE_OID_ID =              13 ;
+    /** value for the tag */
+    private static final int RESERVED14_ID =                14 ;
+    /** value for the tag */
+    private static final int RESERVED15_ID =                15 ;
+    /** value for the tag */
+    private static final int SEQUENCE_SEQUENCE_OF_ID =      16 ;
+    /** value for the tag */
+    private static final int SET_SET_OF_ID =                17 ;
+    /** value for the tag */
+    private static final int NUMERIC_STRING_ID =            18 ;
+    /** value for the tag */
+    private static final int PRINTABLE_STRING_ID =          19 ;
+    /** value for the tag */
+    private static final int TELETEX_STRING_ID =            20 ;
+    /** value for the tag */
+    private static final int VIDEOTEX_STRING_ID =           21 ;
+    /** value for the tag */
+    private static final int IA5_STRING_ID =                22 ;
+    /** value for the tag */
+    private static final int UTC_TIME_ID =                  23 ;
+    /** value for the tag */
+    private static final int GENERALIZED_TIME_ID =          24 ;
+    /** value for the tag */
+    private static final int GRAPHIC_STRING_ID =            25 ;
+    /** value for the tag */
+    private static final int VISIBLE_STRING_ID =            26 ;
+    /** value for the tag */
+    private static final int GENERAL_STRING_ID =            27 ;
+    /** value for the tag */
+    private static final int UNIVERSAL_STRING_ID =          28 ;
+    /** value for the tag */
+    private static final int CHARACTER_STRING_ID =          29 ;
+    /** value for the tag */
+    private static final int BMP_STRING_ID =                30 ;
+    /** value for the tag */
+    private static final int RESERVED31_ID =                31 ;
+
+    /** enum for the tag */
+    public static final UniversalTag BOOLEAN = 
+        new UniversalTag( "BOOLEAN", BOOLEAN_VAL, BOOLEAN_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag RESERVED0 = 
+        new UniversalTag( "RESERVED0", RESERVED0_VAL, RESERVED0_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag INTEGER = 
+        new UniversalTag( "INTEGER", INTEGER_VAL, INTEGER_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag BIT_STRING = 
+        new UniversalTag( "BIT_STRING", BIT_STRING_VAL, BIT_STRING_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag OCTET_STRING = 
+        new UniversalTag( "OCTET_STRING", OCTET_STRING_VAL, OCTET_STRING_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag NULL = 
+        new UniversalTag( "NULL", NULL_VAL, NULL_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag OBJECT_IDENTIFIER = 
+        new UniversalTag( "OBJECT_IDENTIFIER", OBJECT_IDENTIFIER_VAL,
+                OBJECT_IDENTIFIER_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag OBJECT_DESCRIPTOR = 
+        new UniversalTag( "OBJECT_DESCRIPTOR", OBJECT_DESCRIPTOR_VAL,
+                OBJECT_DESCRIPTOR_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag EXTERNAL_INSTANCE_OF = 
+        new UniversalTag( "EXTERNAL_INSTANCE_OF", EXTERNAL_INSTANCE_OF_VAL,
+                EXTERNAL_INSTANCE_OF_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag REAL = 
+        new UniversalTag( "REAL", REAL_VAL, REAL_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag ENUMERATED = 
+        new UniversalTag( "ENUMERATED", ENUMERATED_VAL, ENUMERATED_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag EMBEDDED_PDV = 
+        new UniversalTag( "EMBEDDED_PDV", EMBEDDED_PDV_VAL, EMBEDDED_PDV_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag UTF8_STRING = 
+        new UniversalTag( "UTF8_STRING", UTF8_STRING_VAL, UTF8_STRING_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag RELATIVE_OID = 
+        new UniversalTag( "RELATIVE_OID", RELATIVE_OID_VAL, RELATIVE_OID_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag RESERVED14 = 
+        new UniversalTag( "RESERVED14", RESERVED14_VAL, RESERVED14_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag RESERVED15 = 
+        new UniversalTag( "RESERVED15", RESERVED15_VAL, RESERVED15_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag SEQUENCE_SEQUENCE_OF = 
+        new UniversalTag( "SEQUENCE_SEQUENCE_OF", SEQUENCE_SEQUENCE_OF_VAL,
+                SEQUENCE_SEQUENCE_OF_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag SET_SET_OF = 
+        new UniversalTag( "SET_SET_OF", SET_SET_OF_VAL, SET_SET_OF_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag NUMERIC_STRING = 
+        new UniversalTag( "NUMERIC_STRING", NUMERIC_STRING_VAL,
+                NUMERIC_STRING_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag PRINTABLE_STRING = 
+        new UniversalTag( "PRINTABLE_STRING", PRINTABLE_STRING_VAL,
+                PRINTABLE_STRING_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag TELETEX_STRING = 
+        new UniversalTag( "TELETEX_STRING", TELETEX_STRING_VAL,
+                TELETEX_STRING_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag VIDEOTEX_STRING = 
+        new UniversalTag( "VIDEOTEX_STRING", VIDEOTEX_STRING_VAL,
+                VIDEOTEX_STRING_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag IA5_STRING = 
+        new UniversalTag( "IA5_STRING", IA5_STRING_VAL, IA5_STRING_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag UTC_TIME = 
+        new UniversalTag( "UTC_TIME", UTC_TIME_VAL, UTC_TIME_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag GENERALIZED_TIME = 
+        new UniversalTag( "GENERALIZED_TIME", GENERALIZED_TIME_VAL,
+                GENERALIZED_TIME_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag GRAPHIC_STRING = 
+        new UniversalTag( "GRAPHIC_STRING", GRAPHIC_STRING_VAL,
+                GRAPHIC_STRING_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag VISIBLE_STRING = 
+        new UniversalTag( "VISIBLE_STRING", VISIBLE_STRING_VAL,
+                VISIBLE_STRING_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag GENERAL_STRING = 
+        new UniversalTag( "GENERAL_STRING", GENERAL_STRING_VAL,
+                GENERAL_STRING_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag UNIVERSAL_STRING = 
+        new UniversalTag( "UNIVERSAL_STRING", UNIVERSAL_STRING_VAL,
+                UNIVERSAL_STRING_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag CHARACTER_STRING = 
+        new UniversalTag( "CHARACTER_STRING", CHARACTER_STRING_VAL,
+                CHARACTER_STRING_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag BMP_STRING = 
+        new UniversalTag( "BMP_STRING", BMP_STRING_VAL, BMP_STRING_ID ) ;
+    /** enum for the tag */
+    public static final UniversalTag RESERVED31 = 
+        new UniversalTag( "RESERVED31", RESERVED31_VAL, RESERVED31_ID ) ;
+
+
+    // -----------------------------------------------------------------------
+    // C O N S T R U C T O R S
+    // -----------------------------------------------------------------------
+
+
+    /**
+     * Private constructor so no other instances can be created other than the
+     * public static constants in this class.
+     *
+     * @param name a string name for the enumeration value.
+     * @param value the integer value of the enumeration.
+     */
+    private UniversalTag( final String name, final int value, final int id )
+    {
+        super( name, value, id ) ;
+    }
+
+
+    // -----------------------------------------------------------------------
+    // Members
+    // -----------------------------------------------------------------------
+
+
+    /**
+     * Gets a List of the enumerations for ASN.1 UNIVERSAL type tags.
+     * 
+     * @return the List of enumerations possible for ASN.1 UNIVERSAL type tags
+     */
+    public static List list()
+    {
+        return EnumUtils.getEnumList( UniversalTag.class ) ;
+    }
+    
+    
+    /**
+     * Gets the Map of UniversalTag objects by name using the UniversalTag 
+     * class.
+     * 
+     * @return the Map by name of UniversalTag
+     */
+    public static Map map()
+    {
+        return EnumUtils.getEnumMap( UniversalTag.class ) ;
+    }
+
+
+    /**
+     * Gets the ASN.1 UNIVERSAL type tag's enum using a tag value.
+     * 
+     * @param value the first octet of the TLV
+     * @return the valued enum for the ASN.1 UNIVERSAL type tag
+     */
+    public static UniversalTag getUniversalTag( int value )
+    {
+        UniversalTag type = null ;
+        value &= 0xdfffffff ;
+        
+        switch ( value )
+        {
+            case( RESERVED0_VAL ):
+                type = RESERVED0 ;
+                break ;
+            case( BOOLEAN_VAL ):
+                type = BOOLEAN ;
+                break ;
+            case( INTEGER_VAL ):
+                type = INTEGER ;
+                break ;
+            case( BIT_STRING_VAL ):
+                type = BIT_STRING ;
+                break ;
+            case( OCTET_STRING_VAL ):
+                type = OCTET_STRING ;
+                break ;
+            case( NULL_VAL ):
+                type = NULL ;
+                break ;
+            case( OBJECT_IDENTIFIER_VAL ):
+                type = OBJECT_IDENTIFIER ;
+                break ;
+            case( OBJECT_DESCRIPTOR_VAL ):
+                type = OBJECT_DESCRIPTOR ;
+                break ;
+            case( EXTERNAL_INSTANCE_OF_VAL ):
+                type = EXTERNAL_INSTANCE_OF ;
+                break ;
+            case( REAL_VAL ):
+                type = REAL ;
+                break ;
+            case( ENUMERATED_VAL ):
+                type = ENUMERATED ;
+                break ;
+            case( EMBEDDED_PDV_VAL ):
+                type = EMBEDDED_PDV ;
+                break ;
+            case( UTF8_STRING_VAL ):
+                type = UTF8_STRING ;
+                break ;
+            case( RELATIVE_OID_VAL ):
+                type = RELATIVE_OID ;
+                break ;
+            case( RESERVED14_VAL ):
+                type = RESERVED14 ;
+                break ;
+            case( RESERVED15_VAL ):
+                type = RESERVED15 ;
+                break ;
+            case( SEQUENCE_SEQUENCE_OF_VAL ):
+                type = SEQUENCE_SEQUENCE_OF ;
+                break ;
+            case( SET_SET_OF_VAL ):
+                type = SET_SET_OF ;
+                break ;
+            case( NUMERIC_STRING_VAL ):
+                type = NUMERIC_STRING ;
+                break ;
+            case( PRINTABLE_STRING_VAL ):
+                type = PRINTABLE_STRING ;
+                break ;
+            case( TELETEX_STRING_VAL ):
+                type = TELETEX_STRING ;
+                break ;
+            case( VIDEOTEX_STRING_VAL ):
+                type = VIDEOTEX_STRING ;
+                break ;
+            case( IA5_STRING_VAL ):
+                type = IA5_STRING ;
+                break ;
+            case( UTC_TIME_VAL ):
+                type = UTC_TIME ;
+                break ;
+            case( GENERALIZED_TIME_VAL ):
+                type = GENERALIZED_TIME ;
+                break ;
+            case( GRAPHIC_STRING_VAL ):
+                type = GRAPHIC_STRING ;
+                break ;
+            case( VISIBLE_STRING_VAL ):
+                type = VISIBLE_STRING ;
+                break ;
+            case( GENERAL_STRING_VAL ):
+                type = GENERAL_STRING ;
+                break ;
+            case( UNIVERSAL_STRING_VAL ):
+                type = UNIVERSAL_STRING ;
+                break ;
+            case( CHARACTER_STRING_VAL ):
+                type = CHARACTER_STRING ;
+                break ;
+            case( BMP_STRING_VAL ):
+                type = BMP_STRING ;
+                break ;
+            case( RESERVED31_VAL ):
+                type = RESERVED31 ;
+                break ;
+            default:
+                String msg ;
+                if ( value < 31 && value > -1 )
+                {
+                    msg = "Looks like you're using an id instead of a tag" ;
+                }
+                else
+                {
+                    msg = "Tag value of " + value + " not recognized" ;
+                }
+
+                throw new IllegalArgumentException( msg ) ;
+        }
+        
+        return type ;
+    }
+
+
+    /**
+     * Gets the ASN.1 UNIVERSAL type tag's enum using a tag value.
+     *
+     * @param id the first octet of the TLV
+     * @return the valued enum for the ASN.1 UNIVERSAL type tag
+     */
+    public static UniversalTag getUniversalTagById( int id )
+    {
+        UniversalTag type = null ;
+
+        switch ( id )
+        {
+            case( RESERVED0_ID ):
+                type = RESERVED0 ;
+                break ;
+            case( BOOLEAN_ID ):
+                type = BOOLEAN ;
+                break ;
+            case( INTEGER_ID ):
+                type = INTEGER ;
+                break ;
+            case( BIT_STRING_ID ):
+                type = BIT_STRING ;
+                break ;
+            case( OCTET_STRING_ID ):
+                type = OCTET_STRING ;
+                break ;
+            case( NULL_ID ):
+                type = NULL ;
+                break ;
+            case( OBJECT_IDENTIFIER_ID ):
+                type = OBJECT_IDENTIFIER ;
+                break ;
+            case( OBJECT_DESCRIPTOR_ID ):
+                type = OBJECT_DESCRIPTOR ;
+                break ;
+            case( EXTERNAL_INSTANCE_OF_ID ):
+                type = EXTERNAL_INSTANCE_OF ;
+                break ;
+            case( REAL_ID ):
+                type = REAL ;
+                break ;
+            case( ENUMERATED_ID ):
+                type = ENUMERATED ;
+                break ;
+            case( EMBEDDED_PDV_ID ):
+                type = EMBEDDED_PDV ;
+                break ;
+            case( UTF8_STRING_ID ):
+                type = UTF8_STRING ;
+                break ;
+            case( RELATIVE_OID_ID ):
+                type = RELATIVE_OID ;
+                break ;
+            case( RESERVED14_ID ):
+                type = RESERVED14 ;
+                break ;
+            case( RESERVED15_ID ):
+                type = RESERVED15 ;
+                break ;
+            case( SEQUENCE_SEQUENCE_OF_ID ):
+                type = SEQUENCE_SEQUENCE_OF ;
+                break ;
+            case( SET_SET_OF_ID ):
+                type = SET_SET_OF ;
+                break ;
+            case( NUMERIC_STRING_ID ):
+                type = NUMERIC_STRING ;
+                break ;
+            case( PRINTABLE_STRING_ID ):
+                type = PRINTABLE_STRING ;
+                break ;
+            case( TELETEX_STRING_ID ):
+                type = TELETEX_STRING ;
+                break ;
+            case( VIDEOTEX_STRING_ID ):
+                type = VIDEOTEX_STRING ;
+                break ;
+            case( IA5_STRING_ID ):
+                type = IA5_STRING ;
+                break ;
+            case( UTC_TIME_ID ):
+                type = UTC_TIME ;
+                break ;
+            case( GENERALIZED_TIME_ID ):
+                type = GENERALIZED_TIME ;
+                break ;
+            case( GRAPHIC_STRING_ID ):
+                type = GRAPHIC_STRING ;
+                break ;
+            case( VISIBLE_STRING_ID ):
+                type = VISIBLE_STRING ;
+                break ;
+            case( GENERAL_STRING_ID ):
+                type = GENERAL_STRING ;
+                break ;
+            case( UNIVERSAL_STRING_ID ):
+                type = UNIVERSAL_STRING ;
+                break ;
+            case( CHARACTER_STRING_ID ):
+                type = CHARACTER_STRING ;
+                break ;
+            case( BMP_STRING_ID ):
+                type = BMP_STRING ;
+                break ;
+            case( RESERVED31_ID ):
+                type = RESERVED31 ;
+                break ;
+            default:
+                String msg ;
+                if ( id > 31 || id < 0 )
+                {
+                    msg = "Looks like you're using a tag instead of an id" ;
+                }
+                else
+                {
+                    msg = "Id of " + id + " not recognized as a universal id" ;
+                }
+
+                throw new IllegalArgumentException( msg ) ;
+        }
+
+        return type ;
+    }
+}



Mime
View raw message