directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 9764 - in incubator/directory/snickers/branches/chunking/ber/src: java/org/apache/snickers/ber java/org/apache/snickers/ber/primitives test/org/apache/snickers/ber
Date Sat, 27 Mar 2004 00:34:48 GMT
Author: akarasulu
Date: Fri Mar 26 16:34:47 2004
New Revision: 9764

Added:
   incubator/directory/snickers/branches/chunking/ber/src/java/org/apache/snickers/ber/primitives/PrimitiveType.java
Modified:
   incubator/directory/snickers/branches/chunking/ber/src/java/org/apache/snickers/ber/TypeClass.java
   incubator/directory/snickers/branches/chunking/ber/src/test/org/apache/snickers/ber/TagTest.java
   incubator/directory/snickers/branches/chunking/ber/src/test/org/apache/snickers/ber/TupleTest.java
Log:
Fixed dependency issues with last commit to the Binary class.


Modified: incubator/directory/snickers/branches/chunking/ber/src/java/org/apache/snickers/ber/TypeClass.java
==============================================================================
--- incubator/directory/snickers/branches/chunking/ber/src/java/org/apache/snickers/ber/TypeClass.java
(original)
+++ incubator/directory/snickers/branches/chunking/ber/src/java/org/apache/snickers/ber/TypeClass.java
Fri Mar 26 16:34:47 2004
@@ -20,7 +20,6 @@
 import java.util.Map ;
 import java.util.List ;
 
-import org.apache.commons.codec.binary.Binary ;
 import org.apache.commons.lang.enum.EnumUtils ;
 import org.apache.commons.lang.enum.ValuedEnum ;
 
@@ -44,11 +43,11 @@
     /** value for the universal type class */
     public static final int UNIVERSAL_VAL = 0 ;
     /** value for the application type class */
-    public static final int APPLICATION_VAL = Binary.BIT_6 ;
+    public static final int APPLICATION_VAL = 0x40 ;
     /** value for the context specific type class */
-    public static final int CONTEXT_SPECIFIC_VAL = Binary.BIT_7 ;
+    public static final int CONTEXT_SPECIFIC_VAL = 0x80 ;
     /** value for the private type class */
-    public static final int PRIVATE_VAL = Binary.BIT_6 | Binary.BIT_7 ;
+    public static final int PRIVATE_VAL = 0xc0 ;
 
     /** enum for the universal type class */
     public static final TypeClass UNIVERSAL = 

Added: incubator/directory/snickers/branches/chunking/ber/src/java/org/apache/snickers/ber/primitives/PrimitiveType.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/chunking/ber/src/java/org/apache/snickers/ber/primitives/PrimitiveType.java
Fri Mar 26 16:34:47 2004
@@ -0,0 +1,136 @@
+/*
+ *   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.snickers.ber.primitives;
+
+
+import java.util.Map ;
+import java.util.List ;
+
+import org.apache.commons.lang.enum.EnumUtils ;
+import org.apache.commons.lang.enum.ValuedEnum ;
+
+
+/**
+ * Type safe enum for an ASN.1 primitive types.  This can be take one of the 
+ * following values: 
+ * <ul>
+ * <li></li>
+ * <li></li>
+ * <li></li>
+ * <li></li>
+ * <li></li>
+ * <li></li>
+ * <li></li>
+ * <li></li>
+ * <li></li>
+ * <li></li>
+ * <li></li>
+ * <li></li>
+ * </ul>
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
+ * @version $Rev: 9747 $
+ */
+public class PrimitiveType extends ValuedEnum
+{
+    /** value for the x type */
+    public static final int x_VAL = 0 ;
+
+    /** enum for the universal type class */
+    public static final PrimitiveType x = 
+        new PrimitiveType( "x", x_VAL ) ;
+    
+    /**
+     * 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 PrimitiveType( final String name, final int value )
+    {
+        super( name, value ) ;
+    }
+    
+    
+    /**
+     * Gets the enumeration type for the primitive type regardless of case.
+     * 
+     * @param primitiveType the primitive type name
+     * @return the PrimitiveType for the name
+     */
+    public static PrimitiveType getTypeClass( String primitiveType )
+    {
+        // check first using == since it will be the predominate use case
+        if ( primitiveType == x.getName() )
+        {
+            return x ;
+        }
+        
+        if ( primitiveType.equalsIgnoreCase( PrimitiveType.x.getName() ) )
+        {
+            return PrimitiveType.x ;
+        }
+        
+        throw new IllegalArgumentException( "Unknown primitive type name"
+            + primitiveType ) ;
+    }
+    
+    
+    /**
+     * Gets a List of the enumerations for ASN.1 primitive types.
+     * 
+     * @return the List of enumerations possible for ASN.1 primitive types
+     */
+    public static List list()
+    {
+        return EnumUtils.getEnumList( PrimitiveType.class ) ;
+    }
+    
+    
+    /**
+     * Gets the Map of TypeClass objects by name using the TypeClass class.
+     * 
+     * @return the Map by name of TypeClass
+     */
+    public static Map map()
+    {
+        return EnumUtils.getEnumMap( PrimitiveType.class ) ;
+    }
+
+
+    /**
+     * Gets the ASN.1 primitive type's enum using an id value.
+     * 
+     * @param octet the first octet of the TLV
+     * @return the TypeClass enumeration for the ASN.1 type's class
+     */
+    public static PrimitiveType getPrimitiveType( int value )
+    {
+        PrimitiveType type = null ;
+        
+        switch ( value )
+        {
+            case( x_VAL ):
+                type = x ;
+                break ;
+        }
+        
+        return type ;
+    }
+}

Modified: incubator/directory/snickers/branches/chunking/ber/src/test/org/apache/snickers/ber/TagTest.java
==============================================================================
--- incubator/directory/snickers/branches/chunking/ber/src/test/org/apache/snickers/ber/TagTest.java
(original)
+++ incubator/directory/snickers/branches/chunking/ber/src/test/org/apache/snickers/ber/TagTest.java
Fri Mar 26 16:34:47 2004
@@ -18,7 +18,6 @@
 
 
 import org.apache.commons.lang.ArrayUtils ;
-import org.apache.commons.codec.binary.Binary ;
 import org.apache.commons.collections.primitives.ArrayByteList ;
 
 import junit.framework.TestCase ;
@@ -34,6 +33,14 @@
 public class TagTest extends TestCase
 {
 
+    private static final int BIT_7 = 0x80;
+    private static final int BIT_6 = 0x40;
+    private static final int BIT_4 = 0x10;
+    private static final int BIT_3 = 0x08;
+    private static final int BIT_2 = 0x04;
+    private static final int BIT_1 = 0x02;
+    private static final int BIT_0 = 0x01;
+    private static final int BIT_5 = 0x20;
     public static void main(String[] args)
     {
         junit.textui.TestRunner.run(TagTest.class);
@@ -72,37 +79,37 @@
     
     public void testIsPrimitive() throws Exception
     {
-        byte octet = Binary.BIT_5 ;
+        byte octet = BIT_5 ;
         
         assertFalse( Tag.isPrimitive( octet ) ) ;
-        assertFalse( Tag.isPrimitive( Binary.BIT_5 ) ) ;
+        assertFalse( Tag.isPrimitive( BIT_5 ) ) ;
         
         assertTrue( Tag.isPrimitive( 0 ) ) ;
-        assertTrue( Tag.isPrimitive( Binary.BIT_0 ) ) ;
-        assertTrue( Tag.isPrimitive( Binary.BIT_1 ) ) ;
-        assertTrue( Tag.isPrimitive( Binary.BIT_2 ) ) ;
-        assertTrue( Tag.isPrimitive( Binary.BIT_3 ) ) ;
-        assertTrue( Tag.isPrimitive( Binary.BIT_4 ) ) ;
-        assertTrue( Tag.isPrimitive( Binary.BIT_6 ) ) ;
-        assertTrue( Tag.isPrimitive( Binary.BIT_7 ) ) ;
+        assertTrue( Tag.isPrimitive( BIT_0 ) ) ;
+        assertTrue( Tag.isPrimitive( BIT_1 ) ) ;
+        assertTrue( Tag.isPrimitive( BIT_2 ) ) ;
+        assertTrue( Tag.isPrimitive( BIT_3 ) ) ;
+        assertTrue( Tag.isPrimitive( BIT_4 ) ) ;
+        assertTrue( Tag.isPrimitive( BIT_6 ) ) ;
+        assertTrue( Tag.isPrimitive( BIT_7 ) ) ;
     }
 
 
     public void testIsConstructed() throws Exception
     {
-        byte octet = Binary.BIT_5 ;
+        byte octet = BIT_5 ;
         
         assertTrue( Tag.isConstructed( octet ) ) ;
-        assertTrue( Tag.isConstructed( Binary.BIT_5 ) ) ;
+        assertTrue( Tag.isConstructed( BIT_5 ) ) ;
         
         assertFalse( Tag.isConstructed( 0 ) ) ;
-        assertFalse( Tag.isConstructed( Binary.BIT_0 ) ) ;
-        assertFalse( Tag.isConstructed( Binary.BIT_1 ) ) ;
-        assertFalse( Tag.isConstructed( Binary.BIT_2 ) ) ;
-        assertFalse( Tag.isConstructed( Binary.BIT_3 ) ) ;
-        assertFalse( Tag.isConstructed( Binary.BIT_4 ) ) ;
-        assertFalse( Tag.isConstructed( Binary.BIT_6 ) ) ;
-        assertFalse( Tag.isConstructed( Binary.BIT_7 ) ) ;
+        assertFalse( Tag.isConstructed( BIT_0 ) ) ;
+        assertFalse( Tag.isConstructed( BIT_1 ) ) ;
+        assertFalse( Tag.isConstructed( BIT_2 ) ) ;
+        assertFalse( Tag.isConstructed( BIT_3 ) ) ;
+        assertFalse( Tag.isConstructed( BIT_4 ) ) ;
+        assertFalse( Tag.isConstructed( BIT_6 ) ) ;
+        assertFalse( Tag.isConstructed( BIT_7 ) ) ;
     }
     
     

Modified: incubator/directory/snickers/branches/chunking/ber/src/test/org/apache/snickers/ber/TupleTest.java
==============================================================================
--- incubator/directory/snickers/branches/chunking/ber/src/test/org/apache/snickers/ber/TupleTest.java
(original)
+++ incubator/directory/snickers/branches/chunking/ber/src/test/org/apache/snickers/ber/TupleTest.java
Fri Mar 26 16:34:47 2004
@@ -829,6 +829,19 @@
             assertNotNull( e ) ;
         }
     }
+    
+    
+    String toAsciiString( int raw )
+    {
+        byte[] intBytes = new byte[4] ;
+        intBytes[0] = (byte) ( (int) 0x000000ff & raw ) ;
+        intBytes[1] = (byte) ( (int) ( 0x0000ff00 & raw ) >> 8 ) ;
+        intBytes[2] = (byte) ( (int) ( 0x00ff0000 & raw ) >> 16 ) ;
+        intBytes[3] = (byte) ( (int) ( 0xff000000 & raw ) >> 24 ) ;
+        
+        return Binary.toAsciiString( intBytes ) ;
+    }
+    
 
     public void testSetLengthBuffer()
     {
@@ -931,7 +944,7 @@
         t = new Tuple( 30, Integer.MAX_VALUE ) ;
         t.setLength( bites, 5 ) ;
         binary = toAsciiString( bites ) ;
-        assertEquals( Binary.toAsciiString( Integer.MAX_VALUE ) +
+        assertEquals( toAsciiString( Integer.MAX_VALUE ) +
                       "10000100", binary ) ;
         
         
@@ -1050,7 +1063,7 @@
         t = new Tuple( 30, Integer.MAX_VALUE ) ;
         t.setLength( bites, 5 ) ;
         binary = toAsciiString( bites ) ;
-        assertEquals( Binary.toAsciiString( Integer.MAX_VALUE ) +
+        assertEquals( toAsciiString( Integer.MAX_VALUE ) +
                       "10000100", binary ) ;
         
         

Mime
View raw message