[jboss-cvs] Repository SVN: r379 - in jacorb: 2.2.4jboss.patch2 and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri May 4 20:54:59 EDT 2007


Author: reverbel
Date: 2007-05-04 20:54:58 -0400 (Fri, 04 May 2007)
New Revision: 379

Added:
   jacorb/2.2.4jboss.patch2/
   jacorb/2.2.4jboss.patch2/README
   jacorb/2.2.4jboss.patch2/component-info.xml
   jacorb/2.2.4jboss.patch2/lib/
   jacorb/2.2.4jboss.patch2/lib/idl.jar
   jacorb/2.2.4jboss.patch2/lib/idl_g.jar
   jacorb/2.2.4jboss.patch2/lib/jacorb.jar
   jacorb/2.2.4jboss.patch2/lib/jacorb_g.jar
   jacorb/2.2.4jboss.patch2/resources/
   jacorb/2.2.4jboss.patch2/resources/CSI.idl
   jacorb/2.2.4jboss.patch2/resources/CosTransactions.idl
   jacorb/2.2.4jboss.patch2/resources/jacorb.properties
   jacorb/2.2.4jboss.patch2/resources/orb.idl
Log:
Added patched version of JacORB 2.2.4 with fix for JBCTS-563. The patched
jacorb.jar identifies itself as "JacORB V 2.2.4 (JBoss patch 2)".


Added: jacorb/2.2.4jboss.patch2/README
===================================================================
--- jacorb/2.2.4jboss.patch2/README	                        (rev 0)
+++ jacorb/2.2.4jboss.patch2/README	2007-05-05 00:54:58 UTC (rev 379)
@@ -0,0 +1,5747 @@
+The files jacorb.jar and idl.jar in this directory are a patched version of 
+JacORB 2.2.4. The patched libraries identify themselves as 
+
+        JacORB V 2.2.4 (JBoss patch 2), www.jacorb.org
+
+Instructions for generating these files are included below.
+
+Kudos to the JacORB team, for this great open-source ORB.
+
+Special thanks to:
+
+        Gerald Brose, for creating JacORB
+
+        Andre Spiegel, for his work on OBV in JacORB
+
+Francisco
+
+---------------------------------------------------------------------------
+
+ *** How to generate the jacorb.jar and idl.jar files in this directory ***
+
+(1) Obtain a JacORB 2.2.4+ source tree, with the following commands:
+
+cvs -d :pserver:anonymous at www.jacorb.org/cvsroot/jacorb checkout -r Root_RELEASE_2_2_5_BRANCH JacORB
+
+cd JacORB
+
+cvs update -r1.1 src/org/jacorb/util/Stack.java
+
+(2) Apply the patchfile below:
+
+Index: src/org/jacorb/orb/CDRInputStream.java
+===================================================================
+RCS file: /cvsroot/jacorb/JacORB/src/org/jacorb/orb/CDRInputStream.java,v
+retrieving revision 1.97
+diff -u -r1.97 CDRInputStream.java
+--- src/org/jacorb/orb/CDRInputStream.java	31 May 2006 13:08:14 -0000	1.97
++++ src/org/jacorb/orb/CDRInputStream.java	5 May 2007 00:36:08 -0000
+@@ -21,12 +21,17 @@
+  */
+ 
+ import java.io.IOException;
++import java.io.Serializable;
++import java.math.BigDecimal;
+ import java.util.*;
+ 
+ import org.apache.avalon.framework.configuration.*;
+ import org.apache.avalon.framework.logger.*;
+ 
+ import org.jacorb.orb.giop.CodeSet;
++import org.jacorb.orb.giop.GIOPConnection;
++import org.jacorb.util.ObjectUtil;
++import org.jacorb.util.Stack;
+ import org.jacorb.util.ValueHandler;
+ 
+ import org.omg.CORBA.BAD_PARAM;
+@@ -45,7 +50,7 @@
+  * Read CDR encoded data
+  *
+  * @author Gerald Brose, FU Berlin
+- * $Id: CDRInputStream.java,v 1.97 2006/05/31 13:08:14 alphonse.bendt Exp $
++ * $Id: CDRInputStream.java,v 1.115 2007/04/27 19:14:06 francisco Exp $
+  */
+ 
+ public class CDRInputStream
+@@ -53,25 +58,23 @@
+ {
+     /**
+      * <code>encaps_stack</code> is used to saving/restoring
+-     * encapsulation information. Do NOT access this variable directly.
+-     * It is initialized on demand. Use the method {@link #getEncapsStack()}
++     * encapsulation information.
+      */
+     private Stack encaps_stack;
+ 
++
+     /**
+-     * <code>recursiveTCMap</code> is used to to remember the original
+-     * TCs for a given ID that is used in a recursive/repeated TC. Do
+-     * NOT access this variable directly. It is initialized on demand.
+-     * Use the method {@link #getRecursiveTCMap()}
++     * This Map is basically a one-entry map pool to be used in
++     * read_TypeCode() as the repeatedTCMap.
+      */
+-    private Map recursiveTCMap;
++    private Map repeatedTCMap;
+ 
+     /**
+      * <code>cachedTypecodes</code> stores a mapping of ID/Typecode to
+      * speed reading from the stream. Do NOT access this variable directly. It
+      * is initialized on demand. Use the methods
+-     * {@link #getCachedTypecode(String id)} and
+-     * {@link #putCachedTypecode(String id, org.omg.CORBA.TypeCode result)}
++     * {@link #getCachedTypecode(Object id)} and
++     * {@link #putCachedTypecode(Object id, Pair result)}
+      * Skip amount is
+      * skip (size - ((pos - start_pos) - 4 - 4));
+      * EncapsulationSize -
+@@ -145,24 +148,40 @@
+     /** Ending position of the current chunk */
+     private int chunk_end_pos = -1;   // -1 means we're not within a chunk
+ 
++    /**
++     * <code>codesetEnabled</code> denotes whether codeset marshalling is enabled.
++     */
++    private boolean codesetEnabled;
+ 
+     /**
+      * for this stream to be able to return a live object reference, a
+      * full ORB (not the Singleton!) must be known. If this stream is
+      * used only to demarshal base type data, the Singleton is enough
+      */
+-    private org.omg.CORBA.ORB orb = null;
++    private final org.omg.CORBA.ORB orb;
+ 
+     /**
+      * this is the lowest possible value_tag indicating the
+      * begin of a valuetype (15.3.4)
+      */
+-    private static final int max_block_size = 0x7fffff00;
++    private static final int MAX_BLOCK_SIZE = 0x7fffff00;
+ 
++    /**
++     * fixes RMI/IIOP related interoperability issues with the
++     * sun the orb that occured
++     * while receiving serialized collections.
++     * see mailing list for details:
++     * {@link http://lists.spline.inf.fu-berlin.de/mailman/htdig/jacorb-developer/2006-May/008251.html}
++     */
+     private boolean sunInteropFix;
+ 
++
++    private Map tcMap;
++
+     public CDRInputStream(final org.omg.CORBA.ORB orb, final byte[] buf)
+     {
++        super();
++
+         buffer = buf;
+         // orb may be null!
+         if (orb != null)
+@@ -183,7 +202,9 @@
+             }
+         }
+         else
++        {
+             this.orb = org.omg.CORBA.ORB.init();
++        }
+     }
+ 
+     public CDRInputStream(final org.omg.CORBA.ORB orb,
+@@ -194,6 +215,10 @@
+         this.littleEndian = littleEndian;
+     }
+ 
++    public CDRInputStream(byte[] buffer, boolean littleEndian)
++    {
++        this(null, buffer, littleEndian);
++    }
+ 
+     /**
+      * This stream is self-configuring, i.e. configure() is private
+@@ -203,9 +228,12 @@
+     private void configure(Configuration configuration)
+         throws ConfigurationException
+     {
++        final org.jacorb.config.Configuration jacorbConfig = (org.jacorb.config.Configuration)configuration;
+         logger =
+-            ((org.jacorb.config.Configuration)configuration).getNamedLogger("jacorb.orb.cdr");
++            jacorbConfig.getNamedLogger("jacorb.orb.cdr");
+ 
++        codesetEnabled  =
++            configuration.getAttribute("jacorb.codeset","on").equals("on");
+         cometInteropFix =
+             configuration.getAttribute("jacorb.interop.comet","off").equals("on");
+         laxBooleanEncoding =
+@@ -217,39 +245,6 @@
+     }
+ 
+ 
+-
+-
+-    /**
+-     * <code>getEncapsStack</code> is used to initialize encaps_stack
+-     * on demand.
+-     *
+-     * @return a <code>Stack</code> value
+-     */
+-    private Stack getEncapsStack()
+-    {
+-        if (encaps_stack == null)
+-        {
+-            encaps_stack = new Stack();
+-        }
+-        return encaps_stack;
+-    }
+-
+-
+-    /**
+-     * Gets the Map that keeps track of recursive TypeCodes.
+-     *
+-     * @return a <code>Map</code> value
+-     */
+-    private Map getRecursiveTCMap()
+-    {
+-        if (recursiveTCMap == null)
+-        {
+-            recursiveTCMap = new HashMap();
+-        }
+-        return recursiveTCMap;
+-    }
+-
+-
+     /**
+      * Gets the Map that is used to demarshal shared valuetype instances.
+      *
+@@ -302,24 +297,30 @@
+      * <code>getCachedTypecode</code> to retrieve a value from cachedTypecodes.
+      * It may initialize the value on demand.
+      *
+-     * @param id a <code>String</code> value
++     * @param id a <code>Object</code> value, can be String (id) or actual TypeCode
++     * for sequence/array tcs
+      * @return a <code>org.omg.CORBA.TypeCode</code> value, possibly null.
+      */
+-    private org.omg.CORBA.TypeCode getCachedTypecode( String id )
++    private Pair getCachedTypecode( Object id )
+     {
+-        org.omg.CORBA.TypeCode result = null;
++        final Pair result;
+ 
+         if ( cacheTypecodes )
+         {
+             if ( cachedTypecodes == null )
+             {
+                 cachedTypecodes = new HashMap();
++                result = null;
+             }
+             else
+             {
+-                result = ( org.omg.CORBA.TypeCode )cachedTypecodes.get( id );
++                result = ( Pair )cachedTypecodes.get( id );
+             }
+         }
++        else
++        {
++            result = null;
++        }
+         return result;
+     }
+ 
+@@ -328,10 +329,10 @@
+      * <code>putCachedTypecode</code> is used to store typecodes within the
+      * cachedTypecodes. It will only do it cacheTypecodes is on.
+      *
+-     * @param id a <code>String</code> value
+-     * @param result an <code>org.omg.CORBA.TypeCode</code> value
++     * @param id a <code>String</code> or <code>TypeCode</code> value
++     * @param result an Pair value
+      */
+-    private void putCachedTypecode( String id, org.omg.CORBA.TypeCode result)
++    private void putCachedTypecode( Object id, Pair result)
+     {
+         if ( cacheTypecodes )
+         {
+@@ -353,24 +354,31 @@
+     }
+ 
+     public void close()
+-        throws IOException
+     {
+         // Don't need to call super.close as super is noop.
++
+         if( closed )
+         {
+             return;
+         }
+ 
+-        BufferManager.getInstance().returnBuffer(buffer);
++        // commented out as this caused test failures.
++        // as the buffer has been passed into this CDRInputStream
++        // we cannot assume ownership of the buffer here (alphonse).
++        // BufferManager.getInstance().returnBuffer(buffer);
+ 
++        buffer = null;
+         encaps_stack = null;
+-        recursiveTCMap = null;
+         closed = true;
++
++        if (tcMap != null)
++        {
++            tcMap.clear();
++        }
+     }
+ 
+     public org.omg.CORBA.ORB orb()
+     {
+-        if (orb == null) orb = org.omg.CORBA.ORB.init(new String[]{}, null);
+         return orb;
+     }
+ 
+@@ -384,26 +392,28 @@
+        (final boolean _littleEndian, final byte[] _buffer, final int _pos)
+     {
+         if (_littleEndian)
++        {
+             return (((_buffer[_pos+3] & 0xff) << 24) +
+                     ((_buffer[_pos+2] & 0xff) << 16) +
+                     ((_buffer[_pos+1] & 0xff) <<  8) +
+                     ((_buffer[_pos]   & 0xff) <<  0));
+-        else
+-            return (((_buffer[_pos]   & 0xff) << 24) +
+-                    ((_buffer[_pos+1] & 0xff) << 16) +
+-                    ((_buffer[_pos+2] & 0xff) <<  8) +
+-                    ((_buffer[_pos+3] & 0xff) <<  0));
++        }
++        return (((_buffer[_pos]   & 0xff) << 24) +
++                ((_buffer[_pos+1] & 0xff) << 16) +
++                ((_buffer[_pos+2] & 0xff) <<  8) +
++                ((_buffer[_pos+3] & 0xff) <<  0));
+     }
+ 
+     private static final short _read2int
+        (final boolean _littleEndian, final byte[] _buffer, final int _pos)
+     {
+         if (_littleEndian)
++        {
+             return  (short)(((_buffer[_pos+1] & 0xff) << 8) +
+                             ((_buffer[_pos]   & 0xff) << 0));
+-        else
+-            return (short)(((_buffer[_pos ]    & 0xff) << 8) +
+-                           ((_buffer[_pos + 1] & 0xff) << 0));
++        }
++        return (short)(((_buffer[_pos ]    & 0xff) << 8) +
++                ((_buffer[_pos + 1] & 0xff) << 0));
+     }
+ 
+     private final int _read_long()
+@@ -421,12 +431,10 @@
+     {
+         if (littleEndian)
+         {
+-            return ((long) _read_long() & 0xFFFFFFFFL) + ((long) _read_long() << 32);
+-        }
+-        else
+-        {
+-            return ((long) _read_long() << 32) + ((long) _read_long() & 0xFFFFFFFFL);
++            return (_read_long() & 0xFFFFFFFFL) + ((long) _read_long() << 32);
+         }
++
++        return ((long) _read_long() << 32) + (_read_long() & 0xFFFFFFFFL);
+     }
+ 
+     private final void handle_chunking()
+@@ -445,7 +453,7 @@
+ 
+                 // tag is an end tag
+ 
+-                if ( ! (-tag <= valueNestingLevel))
++                if (-tag > valueNestingLevel)
+                 {
+                     throw new INTERNAL
+                     (
+@@ -454,7 +462,7 @@
+                         valueNestingLevel
+                     );
+                 }
+-                valueNestingLevel = - tag;
++                valueNestingLevel = -tag;
+                 valueNestingLevel--;
+ 
+                 if (valueNestingLevel > 0)
+@@ -463,17 +471,17 @@
+                     handle_chunking();
+                 }
+             }
+-            else if (tag < 0x7fffff00)
++            else if (tag > 0 && tag < 0x7fffff00)
+             {
+                 // tag is the chunk size tag of another chunk
+ 
+                 chunk_end_pos = pos + tag;
+             }
+-            else // (tag >= 0x7fffff00)
++            else // (tag == 0 || tag >= 0x7fffff00)
+             {
+-                // tag is the value tag of a nested value
++                // tag is the null value tag or the value tag of a nested value
+ 
+-                pos = saved_pos;      // "unread" the value tag
++                pos = saved_pos;      // "unread" the tag
+                 index = saved_index;
+             }
+         }
+@@ -503,7 +511,9 @@
+         int start = ei.start;
+ 
+         if( pos < start + size )
++        {
+             pos = start + size;
++        }
+ 
+         index = ei.index + size;
+     }
+@@ -565,7 +575,7 @@
+ 
+ 
+     /*
+-     * Return a copy of the current buffer. Currently only used by ProxyImpl.
++     * Return a copy of the current buffer.
+      *
+      * @return a <code>byte[]</code> value.
+      */
+@@ -596,10 +606,14 @@
+         throws java.io.IOException
+     {
+         if( closed )
++        {
+             throw new java.io.IOException("Stream already closed!");
++        }
+ 
+         if( available() < 1 )
++        {
+             return -1;
++        }
+ 
+         ++index;
+         return buffer[pos++]; // read_index++];
+@@ -616,7 +630,7 @@
+ 
+     /**
+      * Has the effect of read(b, 0, b.length);
+-     * @see #read
++     * @see #read(byte[], int, int)
+      */
+     public int read(final byte[] b)
+         throws java.io.IOException
+@@ -678,33 +692,27 @@
+     {
+         handle_chunking();
+         index++;
+-        byte bb = buffer[pos++];
++        byte value = buffer[pos++];
+ 
+-        if (bb == 0)
++        if (value == 0)
+         {
+             return false;
+         }
+-        else
++
++        if (value == 1)
+         {
+-            if (bb == 1)
+-            {
+-                return true;
+-            }
+-            else
+-            {
+-                if (laxBooleanEncoding)
+-                {
+-                    // Technically only valid values are 0 (false) and 1 (true)
+-                    // however some ORBs send values other than 1 for true.
+-                    return true;
+-                }
+-                else
+-                {
+-                    throw new MARSHAL("Unexpected boolean value: " + bb
+-                                      + " pos: " + pos + " index: " + index);
+-                }
+-            }
++            return true;
++        }
++
++        if (laxBooleanEncoding)
++        {
++            // Technically only valid values are 0 (false) and 1 (true)
++            // however some ORBs send values other than 1 for true.
++            return true;
+         }
++
++        throw new MARSHAL("Unexpected boolean value: " + value
++                + " pos: " + pos + " index: " + index);
+     }
+ 
+     /** arrays */
+@@ -734,17 +742,43 @@
+         }
+     }
+ 
++
++    /**
++     * <code>read_char</code> reads a character from the stream.
++     *
++     * @return a <code>char</code> value
++     */
+     public final char read_char()
+     {
+         handle_chunking();
++
+         index++;
+-        return (char)(0xff & buffer[pos++]);
++        return (char)(buffer[pos++] & 0xFF);
+     }
+ 
++
++    /**
++     * <code>read_char_array</code> reads an character array from the stream.
++     *
++     * @param value a <code>char[]</code>, the result array.
++     * @param offset an <code>int</code>, an offset into <code>value</code>
++     * @param length an <code>int</code>, the length of the array to read
++     */
+     public final void read_char_array
+-       (final char[] value, final int offset, final int length)
++        (final char[] value, final int offset, final int length)
+     {
++        if (value == null)
++        {
++            throw new MARSHAL("Cannot marshall result into null array.");
++        }
++        else if ( offset + length > value.length || length < 0 || offset < 0 )
++        {
++            throw new MARSHAL
++                ("Cannot marshall as indices for array are out bounds.");
++        }
++
+         handle_chunking();
++
+         for (int j = offset; j < offset + length; j++)
+         {
+             index++;
+@@ -761,7 +795,9 @@
+        (final double[] value, final int offset, final int length)
+     {
+         if (length == 0)
++        {
+             return;
++        }
+ 
+         handle_chunking();
+ 
+@@ -778,12 +814,32 @@
+         }
+     }
+ 
+-    public final java.math.BigDecimal read_fixed()
++    public final BigDecimal read_fixed()
+     {
+         handle_chunking();
+ 
+-        StringBuffer sb = new StringBuffer();
++        final StringBuffer sb = new StringBuffer();
++
++        final int c = read_fixed_internal(sb);
++
++        final java.math.BigDecimal result =
++            new java.math.BigDecimal( new java.math.BigInteger( sb.toString()));
++
++        return read_fixed_negate(c, result);
++    }
++
++    private BigDecimal read_fixed_negate(final int c, final java.math.BigDecimal result)
++    {
++        if( c == 0xD )
++        {
++            return result.negate();
++        }
++
++        return result;
++    }
+ 
++    private int read_fixed_internal(StringBuffer sb)
++    {
+         int b = buffer[pos++];
+         int c = b & 0x0F; // second half byte
+         index++;
+@@ -791,23 +847,33 @@
+         while(true)
+         {
+             c = (b & 0xF0) >>> 4;
+-            sb.append(c );
++            sb.append(c);
++
+             c = b & 0x0F;
+             if( c == 0xC || c == 0xD )
++            {
+                 break;
++            }
+             sb.append(c );
++
+             b = buffer[pos++];
+             index++;
+         }
++        return c;
++    }
++
++    public final java.math.BigDecimal read_fixed(short digits, short scale)
++    {
++        handle_chunking();
+ 
+-        java.math.BigDecimal result =
+-        new java.math.BigDecimal( new java.math.BigInteger( sb.toString()));
++        final StringBuffer sb = new StringBuffer();
+ 
+-        if( c == 0xD )
+-            return result.negate();
+-        else
+-            return result;
++        final int c = read_fixed_internal(sb);
++
++        final java.math.BigDecimal result =
++            new java.math.BigDecimal( new java.math.BigInteger( sb.toString()), scale);
+ 
++        return read_fixed_negate(c, result);
+     }
+ 
+     public final float read_float()
+@@ -819,7 +885,9 @@
+        (final float[] value, final int offset, final int length)
+     {
+         if (length == 0)
++        {
+             return;
++        }
+ 
+         handle_chunking();
+ 
+@@ -860,7 +928,9 @@
+        (final int[] value, final int offset, final int length)
+     {
+         if (length == 0)
++        {
+             return;
++        }
+ 
+         handle_chunking();
+ 
+@@ -894,19 +964,19 @@
+ 
+         if (littleEndian)
+         {
+-            return ((long) _read_long() & 0xFFFFFFFFL) + ((long) _read_long() << 32);
+-        }
+-        else
+-        {
+-            return ((long) _read_long() << 32) + ((long) _read_long() & 0xFFFFFFFFL);
++            return (_read_long() & 0xFFFFFFFFL) + ((long) _read_long() << 32);
+         }
++
++        return ((long) _read_long() << 32) + (_read_long() & 0xFFFFFFFFL);
+     }
+ 
+     public final void read_longlong_array
+         (final long[] value, final int offset, final int length)
+     {
+         if (length == 0)
++        {
+             return;
++        }
+ 
+         handle_chunking();
+ 
+@@ -921,7 +991,7 @@
+         {
+             for(int j=offset; j < offset+length; j++)
+             {
+-                value[j] = ( (long) _read_long() & 0xFFFFFFFFL) +
++                value[j] = ( _read_long() & 0xFFFFFFFFL) +
+                     ((long) _read_long() << 32);
+             }
+         }
+@@ -930,7 +1000,7 @@
+             for(int j=offset; j < offset+length; j++)
+             {
+                 value[j] = ((long) _read_long() << 32) +
+-                    ((long) _read_long() & 0xFFFFFFFFL);
++                    (_read_long() & 0xFFFFFFFFL);
+             }
+         }
+ 
+@@ -955,15 +1025,13 @@
+         {
+             return null;
+         }
+-        else
+-        {
+-            return ((org.jacorb.orb.ORB)orb)._getObject( pior );
+-        }
++
++        return ((org.jacorb.orb.ORB)orb)._getObject( pior );
+     }
+ 
+-    public org.omg.CORBA.Object read_Object(final java.lang.Class clz)
++    public org.omg.CORBA.Object read_Object(final java.lang.Class clazz)
+     {
+-        if (org.omg.CORBA.portable.ObjectImpl.class.isAssignableFrom(clz))
++        if (org.omg.CORBA.portable.ObjectImpl.class.isAssignableFrom(clazz))
+         {
+             org.omg.CORBA.Object obj = read_Object();
+             if (obj instanceof org.omg.CORBA.portable.ObjectImpl)
+@@ -971,7 +1039,7 @@
+                 org.omg.CORBA.portable.ObjectImpl stub = null;
+                 try
+                 {
+-                    stub = (org.omg.CORBA.portable.ObjectImpl)clz.newInstance();
++                    stub = (org.omg.CORBA.portable.ObjectImpl)clazz.newInstance();
+                 }
+                 catch (InstantiationException e)
+                 {
+@@ -985,17 +1053,14 @@
+                      ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate());
+                 return stub;
+             }
+-            else
+-            {
+-                return obj;
+-            }
++            return obj;
+         }
+-        else if (clz.isInterface() &&
+-                 java.rmi.Remote.class.isAssignableFrom(clz))
++        else if (clazz.isInterface() &&
++                 java.rmi.Remote.class.isAssignableFrom(clazz))
+         {
+             return (org.omg.CORBA.Object)
+                 org.jacorb.util.ValueHandler.portableRemoteObject_narrow(
+-                                                           read_Object(), clz);
++                                                           read_Object(), clazz);
+         }
+         else
+         {
+@@ -1054,7 +1119,9 @@
+         (final short[] value, final int offset, final int length)
+     {
+         if (length == 0)
++        {
+             return;
++        }
+ 
+         handle_chunking();
+ 
+@@ -1075,6 +1142,14 @@
+         index += length * 2;
+     }
+ 
++
++    /**
++     * <code>read_string</code> reads a string from the buffer. It is optimized
++     * for whether it is reading a blank string, and whether codeset translation
++     * is active.
++     *
++     * @return a <code>String</code> value, possibly blank, never null.
++     */
+     public final String read_string()
+     {
+         String result = null;
+@@ -1094,13 +1169,18 @@
+ 
+         index += (size + 4);
+         pos += (size + 4);
+-        String csname = CodeSet.csName(codeSet);
++
+ 
+         if ((size > 0) &&
+             (buffer[ start + size - 1 ] == 0))
+         {
+             size --;
+         }
++        // Optimize for empty strings.
++        if (size == 0)
++        {
++            return "";
++        }
+ 
+         if(start + size > buffer.length)
+         {
+@@ -1111,40 +1191,79 @@
+             throw new MARSHAL ("Invalid size for string extraction");
+         }
+ 
+-        try {
+-          result = new String (buffer, start, size, csname);
++        if (codesetEnabled)
++        {
++            String csname = CodeSet.csName(codeSet);
++
++            try
++            {
++                result = new String (buffer, start, size, csname);
++            }
++            catch (java.io.UnsupportedEncodingException ex)
++            {
++                if (logger != null && logger.isErrorEnabled())
++                {
++                    logger.error("Charset " + csname + " is unsupported");
++                    result = "";
++                }
++            }
+         }
+-        catch (java.io.UnsupportedEncodingException ex) {
+-            if (logger != null && logger.isErrorEnabled()) {
+-                logger.error("Charset " + csname + " is unsupported");
+-                result = "";
++        else
++        {
++            char[] buf = new char[size];
++
++            for (int i=0; i<size; i++)
++            {
++                buf[i] = (char)(0xff & buffer[start + i]);
+             }
++            result = new String(buf);
+         }
++
+         return result;
+     }
+ 
+ 
+     public final org.omg.CORBA.TypeCode read_TypeCode()
+     {
+-        Map tcMap = new HashMap();
+-        org.omg.CORBA.TypeCode result = read_TypeCode( tcMap );
++        if (tcMap == null)
++        {
++            // Initialise tcMap. We keep it for the lifetime of this
++            // stream so it is possible to examine any found recursive
++            // typecodes.
++            tcMap = new TreeMap();
++        }
+ 
+-        return result;
++        if (repeatedTCMap == null)
++        {
++            repeatedTCMap = new HashMap();
++        }
++
++        try
++        {
++            return read_TypeCode( tcMap, repeatedTCMap );
++        }
++        finally
++        {
++            repeatedTCMap.clear();
++        }
+     }
+ 
+-    private final org.omg.CORBA.TypeCode read_TypeCode(final Map tcMap )
++    private final org.omg.CORBA.TypeCode read_TypeCode(final Map recursiveTCMap,
++                                                       final Map repeatedTCMap )
+     {
+-        String  id           = null;
+-        String  name         = null;
+-        int     member_count = 0;
+-        int     length       = 0;
+-        int     size         = 0;
+-        org.omg.CORBA.TypeCode result = null;
+-        org.omg.CORBA.TypeCode content_type = null;
+-        String[] member_names = null;
++        final String id;
++        final String name;
++        final Pair cachedObject;
++        final int member_count;
++        final int length;
++        final int size;
++        final org.omg.CORBA.TypeCode result;
++        final org.omg.CORBA.TypeCode content_type;
++        final String[] member_names;
+ 
+-        int kind = read_long();
+-        int start_pos = pos - 4;
++        final int kind = read_long();
++        final int start_pos = pos - 4;
++        final Integer startPosition = ObjectUtil.newInteger( start_pos );
+ 
+         if (logger != null && logger.isDebugEnabled())
+         {
+@@ -1153,175 +1272,147 @@
+ 
+         switch( kind )
+         {
+-            case TCKind._tk_null:
+-            case TCKind._tk_void:
+-            case TCKind._tk_short:
+-            case TCKind._tk_long:
+-            case TCKind._tk_ushort:
+-            case TCKind._tk_ulong:
+-            case TCKind._tk_float:
+-            case TCKind._tk_double:
+-            case TCKind._tk_boolean:
+-            case TCKind._tk_char:
+-            case TCKind._tk_octet:
+-            case TCKind._tk_any:
+-            case TCKind._tk_TypeCode:
+-            case TCKind._tk_longlong:
+-            case TCKind._tk_ulonglong:
+-            case TCKind._tk_wchar:
+-            case TCKind._tk_Principal:
++            case -1:                     //0xffffffff:
+             {
+-                result = orb.get_primitive_tc
+-                    (org.omg.CORBA.TCKind.from_int (kind));
+-                break;
+-            }
+-            case TCKind._tk_objref:
+-            {
+-                size = openEncapsulation();
+-                id = validateID (read_string());
+-                result = getCachedTypecode( id );
++                // recursive or repeated TC
++                int negative_offset = read_long();
++
++                final Integer origTCStartPos = ObjectUtil.newInteger(pos - 4 + negative_offset);
+ 
+-                if (result != null)
++                // need to check for repeated typecode first since a recursive
++                // typecode may also be repeated (i.e. both maps have an entry
++                // for the given origTCStartPos), but if we find an entry in
++                // the repeatedTCMap, we know the typecode must have
++                // completely been read already, so the marker can't indicate
++                // a recursive typecode
++                final org.omg.CORBA.TypeCode repeatedTC =
++                    (org.omg.CORBA.TypeCode)repeatedTCMap.get(origTCStartPos);
++
++                if (repeatedTC != null)
+                 {
+-                    // Skip buffer - see cachedTypecodes for calculation.
+-                    skip (size - ((pos - start_pos) - 4 - 4));
++                    result = repeatedTC;
++                    break;
+                 }
+-                else
++
++                final String recursiveId = (String) recursiveTCMap.get(origTCStartPos);
++                if (recursiveId != null)
+                 {
+-                    name = validateName (read_string());
+-                    result = orb.create_interface_tc (id, name);
+-                    putCachedTypecode( id, result );
++                    try
++                    {
++                        result = orb.create_recursive_tc(recursiveId);
++                        break;
++                    }
++                    catch(org.omg.CORBA.SystemException e)
++                    {
++                        throw new MARSHAL(
++                            "Failed to create recursive typecode: " +
++                            e);
++                    }
+                 }
+-                closeEncapsulation();
++
++                //if we end up here, we didn't find an entry in either
++                //repeatedTCMap and recursiveTCMap
++                throw new MARSHAL(
++                    "Found indirection marker, but no corresponding "+
++                    "original typecode (pos: " + origTCStartPos + ")" );
++            }
++            case TCKind._tk_null:           // 0
++            case TCKind._tk_void:           // 1
++            case TCKind._tk_short:          // 2
++            case TCKind._tk_long:           // 3
++            case TCKind._tk_ushort:         // 4
++            case TCKind._tk_ulong:          // 5
++            case TCKind._tk_float:          // 6
++            case TCKind._tk_double:         // 7
++            case TCKind._tk_boolean:        // 8
++            case TCKind._tk_char:           // 9
++            case TCKind._tk_octet:          // 10
++            case TCKind._tk_any:            // 11
++            case TCKind._tk_TypeCode:       // 12
++            case TCKind._tk_Principal:      // 13
++            {
++                result = orb.get_primitive_tc(org.omg.CORBA.TCKind.from_int (kind));
+                 break;
+             }
+-            case TCKind._tk_struct:
++            case TCKind._tk_objref:         // 14
+             {
+                 size = openEncapsulation();
+                 id = validateID (read_string());
+-                result = getCachedTypecode( id );
++                cachedObject = getCachedTypecode( id );
+ 
+-                if (result != null)
++                if (cachedObject == null)
+                 {
+-                    // Skip buffer - see cachedTypecodes for calculation.
+-                    skip (size - ((pos - start_pos) - 4 - 4));
+-                    tcMap.put( new Integer( start_pos ), id );
++                    name = validateName (read_string ());
++                    result = orb.create_interface_tc (id, name);
++                    putCachedTypecode (id, new Pair( result, startPosition ));
+                 }
+                 else
+                 {
+-                    name = validateName (read_string());
+-                    member_count = read_long();
+-
+-                    tcMap.put( new Integer( start_pos ), id );
+-
+-                    StructMember[] struct_members = new StructMember[member_count];
+-                    for( int i = 0; i < member_count; i++)
+-                    {
+-                        struct_members[i] = new StructMember
+-                        (
+-                            read_string(),
+-                            read_TypeCode (tcMap),
+-                            null
+-                        );
+-                    }
+-                    result = ((ORBSingleton) orb).create_struct_tc(id, name, struct_members, false);
+-                    putCachedTypecode( id, result );
++                    final int skipAmount = calcSkipAmount(size, start_pos);
++                    skip(skipAmount);
++                    result = cachedObject.typeCode;
+                 }
+-                getRecursiveTCMap().put (id, result);
++
+                 closeEncapsulation();
+                 break;
+             }
+-            case TCKind._tk_except:
++            case TCKind._tk_struct:         // 15
+             {
+                 size = openEncapsulation();
+                 id = validateID (read_string());
+-                result = getCachedTypecode( id );
++                cachedObject = getCachedTypecode( id );
+ 
+-                if (result != null)
+-                {
+-                    // Skip buffer - see cachedTypecodes for calculation.
+-                    skip (size - ((pos - start_pos) - 4 - 4));
+-                    tcMap.put( new Integer( start_pos ), id );
+-                }
+-                else
++                if (cachedObject == null)
+                 {
+                     name = validateName (read_string());
+                     member_count = read_long();
++                    recursiveTCMap.put( startPosition, id );
++                    StructMember[] struct_members = new StructMember[member_count];
+ 
+-                    tcMap.put( new Integer( start_pos ), id );
+-
+-                    StructMember[] members = new StructMember[member_count];
+                     for( int i = 0; i < member_count; i++)
+                     {
+-                        members[i] = new StructMember
++                        struct_members[i] = new StructMember
+                         (
+                             read_string(),
+-                            read_TypeCode(tcMap),
++                            read_TypeCode (recursiveTCMap, repeatedTCMap),
+                             null
+                         );
+                     }
+-                    result = ((ORBSingleton)orb).create_exception_tc (id, name, members, false);
+-                    putCachedTypecode( id, result );
+-                }
+-                getRecursiveTCMap().put (id, result);
+-                closeEncapsulation();
+-                break;
+-            }
+-            case TCKind._tk_enum:
+-            {
+-                size = openEncapsulation();
+-                id = validateID (read_string());
+-                result = getCachedTypecode( id );
+ 
+-                if (result != null)
+-                {
+-                    skip (size - ((pos - start_pos) - 4 - 4));
+-                    tcMap.put( new Integer( start_pos ), id );
++                    result = ((ORBSingleton) orb).create_struct_tc(id, name, struct_members, false);
++                    putCachedTypecode (id, new Pair( result, startPosition ));
+                 }
+                 else
+                 {
+-                    name = validateName (read_string());
+-                    member_count = read_long();
+-
+-                    tcMap.put( new Integer( start_pos ), id );
+-
+-                    member_names = new String[member_count];
+-                    for( int i = 0; i < member_count; i++)
+-                    {
+-                        member_names[i] = read_string();
+-                    }
+-                    result = ((ORBSingleton)orb).create_enum_tc (id, name, member_names, false);
+-                    putCachedTypecode( id, result );
++                    final int skipAmount =  calcSkipAmount(size, start_pos);
++                    updateTcMap( recursiveTCMap, start_pos, skipAmount, cachedObject.position );
++                    skip (skipAmount);
++                    recursiveTCMap.put( startPosition, id );
++                    result = cachedObject.typeCode;
+                 }
+-                getRecursiveTCMap().put (id, result);
++
+                 closeEncapsulation();
+                 break;
+             }
+-            case TCKind._tk_union:
++            case TCKind._tk_union:          // 16
+             {
+                 size = openEncapsulation();
+                 id = validateID (read_string());
+-                result = getCachedTypecode( id );
++                cachedObject = getCachedTypecode( id );
+ 
+-                if (result != null)
+-                {
+-                    // Skip buffer - see cachedTypecodes for calculation.
+-                    skip (size - ((pos - start_pos) - 4 - 4));
+-                    tcMap.put( new Integer( start_pos ), id );
+-                }
+-                else
++                if (cachedObject == null)
+                 {
+                     name = validateName (read_string());
+ 
+-                    tcMap.put( new Integer( start_pos ), id );
++                    recursiveTCMap.put(startPosition, id );
+ 
+-                    org.omg.CORBA.TypeCode discriminator_type = read_TypeCode(tcMap);
++                    org.omg.CORBA.TypeCode discriminator_type = read_TypeCode(recursiveTCMap, repeatedTCMap);
+                     // Use the dealiased discriminator type for the label types.
+                     // This works because the JacORB IDL compiler ignores any aliasing
+                     // of label types and only the discriminator type is passed on the
+                     // wire.
+                     org.omg.CORBA.TypeCode orig_disc_type =
+-                    TypeCode.originalType(discriminator_type);
++                        TypeCode.originalType(discriminator_type);
+ 
+                     int default_index = read_long();
+                     member_count = read_long();
+@@ -1346,101 +1437,216 @@
+                         (
+                             read_string(),
+                             label,
+-                            read_TypeCode(tcMap),
++                            read_TypeCode(recursiveTCMap, repeatedTCMap),
+                             null
+                         );
+                     }
+ 
+                     result = ((ORBSingleton)orb).create_union_tc(id, name, discriminator_type, union_members, false);
+-                    putCachedTypecode( id, result );
++                    putCachedTypecode (id, new Pair( result, startPosition ));
++                }
++                else
++                {
++                    final int skipAmount = calcSkipAmount(size, start_pos);
++                    updateTcMap(recursiveTCMap, start_pos, skipAmount, cachedObject.position );
++                    skip (skipAmount);
++                    recursiveTCMap.put( startPosition, id );
++                    result = cachedObject.typeCode;
+                 }
+-                getRecursiveTCMap().put (id, result);
++
+                 closeEncapsulation();
+                 break;
+             }
+-            case TCKind._tk_string:
+-            {
+-                result = orb.create_string_tc(read_long());
+-                break;
+-            }
+-            case TCKind._tk_wstring:
++            case TCKind._tk_enum:           // 17
+             {
+-                result = orb.create_wstring_tc(read_long());
+-                break;
+-            }
+-            case TCKind._tk_fixed:
++                size = openEncapsulation();
++                id = validateID (read_string());
++                cachedObject = getCachedTypecode( id );
++
++                if (cachedObject == null)
++                {
++                    name = validateName (read_string());
++                    member_count = read_long();
++                    member_names = new String[member_count];
++
++                    for( int i = 0; i < member_count; i++)
++                    {
++                        member_names[i] = read_string();
++                    }
++
++                    result = ((ORBSingleton)orb).create_enum_tc (id, name, member_names, false);
++                    putCachedTypecode (id, new Pair( result, startPosition ));
++                }
++                else
++                {
++                    final int skipAmount = calcSkipAmount(size, start_pos);
++                    skip (skipAmount);
++                    result = cachedObject.typeCode;
++                }
++                closeEncapsulation();
++                break;
++            }
++            case TCKind._tk_string:         // 18
+             {
+-                result = orb.create_fixed_tc(read_ushort(), read_short() );
++                result = orb.create_string_tc(read_long());
+                 break;
+             }
+-            case TCKind._tk_array:
++            case TCKind._tk_sequence:       // 19
+             {
+-                openEncapsulation();
++                size = openEncapsulation();
++                content_type = read_TypeCode(recursiveTCMap, repeatedTCMap);
++                cachedObject = getCachedTypecode(content_type);
+ 
+-                content_type = read_TypeCode(tcMap);
+-                length = read_long();
++                if (cachedObject == null)
++                {
++                    length = read_long();
++                    result = orb.create_sequence_tc(length, content_type);
++                    putCachedTypecode(result, new Pair(result, startPosition));
++                }
++                else
++                {
++                    final int skipAmount = calcSkipAmount(size, start_pos);
++                    skip (skipAmount);
++                    result = cachedObject.typeCode;
++                }
+ 
+                 closeEncapsulation();
+-                result = orb.create_array_tc(length, content_type);
++
+                 break;
+             }
+-            case TCKind._tk_sequence:
++            case TCKind._tk_array:          // 20
+             {
+-                openEncapsulation();
++                size = openEncapsulation();
++                content_type = read_TypeCode(recursiveTCMap, repeatedTCMap);
++                cachedObject = getCachedTypecode(content_type);
+ 
+-                content_type = read_TypeCode(tcMap);
+-                length = read_long();
++                if (cachedObject == null)
++                {
++                    result = orb.create_array_tc(read_long(), content_type );
++
++                    // Store in cache
++                    putCachedTypecode (result, new Pair( result, startPosition ));
++                }
++                else
++                {
++                    int skipAmount = calcSkipAmount(size, start_pos);
++
++                    skip (skipAmount);
++                    result = cachedObject.typeCode;
++                }
+ 
+                 closeEncapsulation();
+ 
+-                result = orb.create_sequence_tc(length, content_type);
+                 break;
+             }
+-            case TCKind._tk_alias:
++            case TCKind._tk_alias:          // 21
+             {
+                 size = openEncapsulation();
+                 id = validateID (read_string());
+-                result = getCachedTypecode( id );
++                cachedObject = getCachedTypecode( id );
+ 
+-                if (result != null)
+-                {
+-                    // Skip buffer - see cachedTypecodes for calculation.
+-                    skip (size - ((pos - start_pos) - 4 - 4));
+-                    tcMap.put( new Integer( start_pos ), id );
+-                }
+-                else
++                if (cachedObject == null)
+                 {
+                     name = validateName (read_string());
+ 
+-                    tcMap.put( new Integer( start_pos ), id );
++                    recursiveTCMap.put(startPosition, id );
+ 
+-                    content_type = read_TypeCode( tcMap );
++                    content_type = read_TypeCode( recursiveTCMap, repeatedTCMap);
+                     result = orb.create_alias_tc (id, name, content_type );
+-                    putCachedTypecode( id, result );
++                    putCachedTypecode (id, new Pair( result, startPosition ));
++                }
++                else
++                {
++                    final int skipAmount = calcSkipAmount(size, start_pos);
++                    updateTcMap(recursiveTCMap, start_pos, skipAmount, cachedObject.position );
++                    skip (skipAmount);
++                    recursiveTCMap.put( startPosition, id );
++                    result = cachedObject.typeCode;
+                 }
+-                getRecursiveTCMap().put (id , result);
+                 closeEncapsulation();
+                 break;
+             }
+-            case TCKind._tk_value:
++            case TCKind._tk_except:         // 22
+             {
+                 size = openEncapsulation();
+                 id = validateID (read_string());
+-                result = getCachedTypecode( id );
++                cachedObject = getCachedTypecode( id );
+ 
+-                if (result != null)
++                if (cachedObject == null)
+                 {
+-                    skip (size - ((pos - start_pos) - 4 - 4));
+-                    tcMap.put( new Integer( start_pos ), id );
++                    name = validateName (read_string());
++                    member_count = read_long();
++
++                    recursiveTCMap.put(startPosition, id );
++
++                    StructMember[] members = new StructMember[member_count];
++                    for( int i = 0; i < member_count; i++)
++                    {
++                        members[i] = new StructMember
++                        (
++                            read_string(),
++                            read_TypeCode(recursiveTCMap, repeatedTCMap),
++                            null
++                        );
++                    }
++                    result = ((ORBSingleton)orb).create_exception_tc (id, name, members, false);
++
++                    // Store in cache
++                    putCachedTypecode (id, new Pair( result, startPosition ));
+                 }
+                 else
+                 {
++                    final int skipAmount = calcSkipAmount(size, start_pos);
++                    updateTcMap(recursiveTCMap, start_pos, skipAmount, cachedObject.position );
++                    skip (skipAmount);
++                    recursiveTCMap.put( startPosition, id );
++                    result = cachedObject.typeCode;
++                }
++
++                closeEncapsulation();
++                break;
++            }
++            case TCKind._tk_longlong:       // 23
++            case TCKind._tk_ulonglong:      // 24
++            {
++                result = orb.get_primitive_tc
++                (org.omg.CORBA.TCKind.from_int (kind));
++                break;
++            }
++            case TCKind._tk_longdouble:     //25
++            {
++                throw new MARSHAL("Cannot handle TypeCode with kind " + kind);
++            }
++            case TCKind._tk_wchar:          // 26
++            {
++                result = orb.get_primitive_tc
++                (org.omg.CORBA.TCKind.from_int (kind));
++                break;
++            }
++            case TCKind._tk_wstring:        // 27
++            {
++                result = orb.create_wstring_tc(read_long());
++                break;
++            }
++            case TCKind._tk_fixed:          // 28
++            {
++                result = orb.create_fixed_tc(read_ushort(), read_short() );
++                break;
++            }
++            case TCKind._tk_value:          // 29
++            {
++                size = openEncapsulation();
++                id = validateID (read_string());
++                cachedObject = getCachedTypecode( id );
++
++                if (cachedObject == null)
++                {
+                     name = validateName (read_string());
+ 
+-                    tcMap.put( new Integer( start_pos ), id );
++                    recursiveTCMap.put(startPosition, id);
+ 
+                     short type_modifier = read_short();
+-                    org.omg.CORBA.TypeCode concrete_base_type = read_TypeCode( tcMap );
++                    org.omg.CORBA.TypeCode concrete_base_type = read_TypeCode( recursiveTCMap, repeatedTCMap);
+                     member_count = read_long();
+                     ValueMember[] vMembers = new ValueMember[member_count];
+ 
+@@ -1452,93 +1658,79 @@
+                             null, // id
+                             null, // defined_in
+                             null, // version
+-                            read_TypeCode (tcMap),
++                            read_TypeCode (recursiveTCMap, repeatedTCMap),
+                             null, // type_def
+                             read_short()
+                         );
+                     }
+                     result = orb.create_value_tc
+                         (id, name, type_modifier, concrete_base_type, vMembers);
+-                    putCachedTypecode( id, result );
++                    putCachedTypecode (id, new Pair( result, startPosition ));
++                }
++                else
++                {
++                    final int skipAmount = calcSkipAmount(size, start_pos);
++                    updateTcMap(recursiveTCMap, start_pos, skipAmount, cachedObject.position );
++                    skip (skipAmount);
++                    recursiveTCMap.put( startPosition, id );
++                    result = cachedObject.typeCode;
+                 }
+-                getRecursiveTCMap().put( id , result );
+                 closeEncapsulation();
+                 break;
+             }
+-            case TCKind._tk_value_box:
++            case TCKind._tk_value_box:      // 30
+             {
+                 size = openEncapsulation();
+                 id = validateID (read_string());
+-                result = getCachedTypecode( id );
++                cachedObject = getCachedTypecode( id );
+ 
+-                if (result != null)
+-                {
+-                    // Skip buffer - see cachedTypecodes for calculation.
+-                    skip (size - ((pos - start_pos) - 4 - 4));
+-                    tcMap.put( new Integer( start_pos ), id );
+-                }
+-                else
++                if (cachedObject == null)
+                 {
+                     name = validateName (read_string());
+ 
+-                    tcMap.put( new Integer( start_pos ), id );
++                    recursiveTCMap.put(startPosition, id);
+ 
+-                    content_type = read_TypeCode( tcMap );
++                    content_type = read_TypeCode( recursiveTCMap, repeatedTCMap);
+                     result = orb.create_value_box_tc (id, name, content_type);
+-                    putCachedTypecode( id, result );
++                    putCachedTypecode (id, new Pair( result, startPosition ));
++                }
++                else
++                {
++                    final int skipAmount = calcSkipAmount(size, start_pos);
++                    updateTcMap(recursiveTCMap, start_pos, skipAmount, cachedObject.position );
++                    skip (skipAmount);
++                    recursiveTCMap.put( startPosition, id );
++                    result = cachedObject.typeCode;
+                 }
+-                getRecursiveTCMap().put( id , result );
+                 closeEncapsulation();
+                 break;
+             }
+-            case TCKind._tk_abstract_interface:
++            case TCKind._tk_native:         //31
++            {
++                throw new MARSHAL("Cannot handle TypeCode with kind " + kind);
++            }
++            case TCKind._tk_abstract_interface:     // 32
+             {
+                 size = openEncapsulation();
+                 id = validateID (read_string());
+-                result = getCachedTypecode( id );
++                cachedObject = getCachedTypecode( id );
+ 
+-                if (result != null)
+-                {
+-                    // Skip buffer - see cachedTypecodes for calculation.
+-                    skip (size - ((pos - start_pos) - 4 - 4));
+-                }
+-                else
++                if (cachedObject == null)
+                 {
+                     name = validateName (read_string());
++                    recursiveTCMap.put(startPosition, id);
+                     result = orb.create_abstract_interface_tc (id, name);
+-                    putCachedTypecode( id, result );
++                    putCachedTypecode (id, new Pair( result, startPosition ));
+                 }
+-                closeEncapsulation();
+-                break;
+-            }
+-            case 0xffffffff:
+-            {
+-                /* recursive TC */
+-                int negative_offset = read_long();
+-                String recursiveId =
+-                    (String)tcMap.get( new Integer( pos - 4 + negative_offset ) );
+-
+-                if (recursiveId == null)
+-                {
+-                    throw new INTERNAL
+-                    (
+-                        "No recursive TypeCode! (pos: " +
+-                        (pos - 4 + negative_offset) +
+-                        ")"
+-                    );
+-                }
+-
+-                // look up TypeCode in map to check if it's repeated
+-                org.omg.CORBA.TypeCode rec_tc =
+-                    (org.omg.CORBA.TypeCode)( getRecursiveTCMap().get( recursiveId ) );
+-
+-                if (rec_tc == null)
++                else
+                 {
+-                    // TypeCode is not in map so it is recursive
+-                    rec_tc = orb.create_recursive_tc( recursiveId );
++                    final int skipAmount = calcSkipAmount(size, start_pos);
++                    updateTcMap (recursiveTCMap, start_pos, skipAmount, cachedObject.position);
++                    skip (skipAmount);
++                    recursiveTCMap.put (startPosition, id);
++                    result = cachedObject.typeCode;
+                 }
+-
+-                result = rec_tc;
++                closeEncapsulation();
+                 break;
+             }
+             default:
+@@ -1547,9 +1739,64 @@
+                 throw new MARSHAL("Cannot handle TypeCode with kind " + kind);
+             }
+         }
++
++        repeatedTCMap.put(startPosition, result);
+         return result;
+     }
+ 
++    /**
++     * see cachedTypecodes for calculation.
++     * @param size
++     * @param start_pos
++     */
++    private int calcSkipAmount(final int size, final int start_pos)
++    {
++        return (size - ((pos - start_pos) - 4 - 4));
++    }
++
++    /**
++     * <code>updateTcMap</code> is used during cached typecodes. As a cached
++     * typecode is being used we may miss placing markers for the recursive
++     * tcMap. Therefore, by recording the original typecodes start, and as we
++     * know the length it is possible find and calculate and extra positions
++     * that should be added.
++     *
++     * @param tcMap a <code>Map</code> value which may be updated.
++     * @param new_start an <code>int</code> value
++     * @param size an <code>int</code> value
++     * @param old_start an <code>Integer</code> value
++     */
++    private void updateTcMap(final Map tcMap,
++                             final int new_start,
++                             final int size,
++                             final Integer old_start )
++    {
++        final SortedMap sortedMap = ((TreeMap)tcMap).subMap
++            ( old_start, ObjectUtil.newInteger( size + old_start.intValue() ) );
++
++        // If we have found anything between the original start position and the size.
++        if( sortedMap.size() > 0 )
++        {
++            final TreeMap toMerge = new TreeMap();
++            final Iterator iterator = sortedMap.entrySet().iterator();
++
++            while( iterator.hasNext() )
++            {
++                final Map.Entry entry = (Map.Entry)iterator.next();
++
++                int value = ((Integer)entry.getKey()).intValue();
++                // This calculation is the offset; the distance between the missing
++                // tc and the original start added onto the new start.
++                toMerge.put
++                (
++                    ObjectUtil.newInteger( new_start + (value - old_start.intValue() ) ),
++                    entry.getValue()
++                );
++            }
++            tcMap.putAll( toMerge );
++        }
++    }
++
+     public final int read_ulong()
+     {
+         handle_chunking();
+@@ -1574,7 +1821,9 @@
+         (final int[] value, final int offset, final int length)
+     {
+         if (length == 0)
++        {
+             return;
++        }
+ 
+         handle_chunking();
+ 
+@@ -1607,19 +1856,19 @@
+ 
+         if (littleEndian)
+         {
+-            return ((long) _read_long() & 0xFFFFFFFFL) + ((long) _read_long() << 32);
+-        }
+-        else
+-        {
+-            return ((long) _read_long() << 32) + ((long) _read_long() & 0xFFFFFFFFL);
++            return (_read_long() & 0xFFFFFFFFL) + ((long) _read_long() << 32);
+         }
++
++        return ((long) _read_long() << 32) + (_read_long() & 0xFFFFFFFFL);
+     }
+ 
+     public final void read_ulonglong_array
+         (final long[] value, final int offset, final int length)
+     {
+         if (length == 0)
++        {
+             return;
++        }
+ 
+         handle_chunking();
+ 
+@@ -1634,7 +1883,7 @@
+         {
+             for (int j = offset; j < offset+length; j++)
+             {
+-                value[j] = ( (long) _read_long() & 0xFFFFFFFFL) +
++                value[j] = ( _read_long() & 0xFFFFFFFFL) +
+                     ((long) _read_long() << 32);
+             }
+         }
+@@ -1643,7 +1892,7 @@
+             for (int j = offset; j < offset+length; j++)
+             {
+                 value[j] = ((long) _read_long() << 32) +
+-                    ((long) _read_long() & 0xFFFFFFFFL);
++                    (_read_long() & 0xFFFFFFFFL);
+             }
+         }
+ 
+@@ -1671,7 +1920,9 @@
+         (final short[] value, final int offset, final int length)
+     {
+         if (length == 0)
++        {
+             return;
++        }
+ 
+         handle_chunking();
+ 
+@@ -1705,10 +1956,8 @@
+ 
+             return read_wchar (wchar_little_endian);
+         }
+-        else
+-        {
+-            return read_wchar (littleEndian);
+-        }
++
++        return read_wchar (littleEndian);
+     }
+ 
+     /**
+@@ -1723,7 +1972,6 @@
+         return buffer[ pos++ ];
+     }
+ 
+-
+     private final char read_wchar(final boolean wchar_little_endian)
+     {
+         switch( codeSetW )
+@@ -1736,49 +1984,51 @@
+                                        " only allows 2 Byte encodings for wchar, but the selected TCSW is UTF-8" );
+                 }
+ 
+-                short b = (short) (0xff & buffer[pos++]);
++                short value = (short) (0xff & buffer[pos++]);
+                 index++;
+ 
+-                if( (b & 0x80) == 0 )
++                if( (value & 0x80) == 0 )
+                 {
+-                    return (char) b;
++                    return (char) value;
+                 }
+-                else if( (b & 0xe0) == 0xc0 )
++                else if( (value & 0xe0) == 0xc0 )
+                 {
+                     index++;
+-                    return (char)(((b & 0x1F) << 6) |
+-                                  ((short)buffer[pos++] & 0x3F));
++                    return (char)(((value & 0x1F) << 6) |
++                                  (buffer[pos++] & 0x3F));
+                 }
+                 else
+                 {
+                     index += 2;
+                     short b2 = (short)(0xff & buffer[pos++]);
+-                    return (char)(( ( b & 0x0F) << 12) |
++                    return (char)(( ( value & 0x0F) << 12) |
+                                   ( (b2 & 0x3F) << 6) |
+-                                  ( (short)buffer[pos++] & 0x3F));
++                                  ( buffer[pos++] & 0x3F));
+                 }
+             }
+             case CodeSet.UTF16 :
+             {
+-                char c;
++                char value;
+ 
+                 if( wchar_little_endian )
+                 {
+-                    c = (char) ( (buffer[ pos++ ] & 0xFF) |
++                    value = (char) ( (buffer[ pos++ ] & 0xFF) |
+                                  (buffer[ pos++ ] << 8) );
+                 }
+                 else
+                 {
+-                    c = (char) ( (buffer[ pos++ ] << 8) |
++                    value = (char) ( (buffer[ pos++ ] << 8) |
+                                  (buffer[ pos++ ] & 0xFF) );
+                 }
+ 
+                 index += 2;
+-                return c;
++                return value;
++            }
++            default:
++            {
++                throw new MARSHAL( "Bad CodeSet: " + codeSetW );
+             }
+         }
+-
+-        throw new MARSHAL( "Bad CodeSet: " + codeSetW );
+     }
+ 
+     /**
+@@ -1790,11 +2040,6 @@
+      */
+     private final boolean readBOM()
+     {
+-        /*
+-          if( !use_BOM )
+-          return false;
+-        */
+-
+         if( (buffer[ pos     ] == (byte) 0xFE) &&
+             (buffer[ pos + 1 ] == (byte) 0xFF) )
+         {
+@@ -1829,7 +2074,9 @@
+     {
+         handle_chunking();
+         for(int j=offset; j < offset+length; j++)
++        {
+             value[j] = read_wchar(); // inlining later...
++        }
+     }
+ 
+     public final String read_wstring()
+@@ -1930,7 +2177,9 @@
+         throws IOException
+     {
+         if( pos < 0 )
++        {
+             throw new MARSHAL("Mark has not been set!");
++        }
+         pos = marked_pos;
+         index = marked_index;
+     }
+@@ -1952,142 +2201,115 @@
+      * from this CDRInputStream, and remarshals it to the given OutputStream,
+      * <code>out</code>.  Called from Any.
+      */
+-    final void read_value(final org.omg.CORBA.TypeCode tc,
++    final void read_value(final org.omg.CORBA.TypeCode typeCode,
+                           final org.omg.CORBA.portable.OutputStream out)
+     {
+-        if (tc == null)
++        if (typeCode == null)
+         {
+             throw new BAD_PARAM("TypeCode is null");
+         }
+ 
+-        int kind = tc.kind().value();
++        int kind = typeCode.kind().value();
+ 
+         try
+         {
+             switch (kind)
+             {
+-                case TCKind._tk_null:
+-                case TCKind._tk_void:
+-                break;
+-                case TCKind._tk_boolean:
+-                out.write_boolean( read_boolean());
+-                break;
+-                case TCKind._tk_char:
+-                out.write_char( read_char());
+-                break;
+-                case TCKind._tk_wchar:
+-                out.write_wchar( read_wchar());
+-                break;
+-                case TCKind._tk_octet:
+-                out.write_octet( read_octet());
+-                break;
+-                case TCKind._tk_ushort:
+-                out.write_ushort( read_ushort());
+-                break;
+-                case TCKind._tk_short:
+-                out.write_short( read_short());
+-                break;
+-                case TCKind._tk_long:
+-                out.write_long( read_long());
+-                break;
+-                case TCKind._tk_ulong:
+-                out.write_ulong( read_ulong());
+-                break;
+-                case TCKind._tk_float:
+-                out.write_float( read_float());
+-                break;
+-                case TCKind._tk_double:
+-                out.write_double( read_double());
+-                break;
+-                case TCKind._tk_longlong:
+-                out.write_longlong( read_longlong());
+-                break;
+-                case TCKind._tk_ulonglong:
+-                out.write_ulonglong( read_ulonglong());
+-                break;
+-                case TCKind._tk_any:
+-                out.write_any( read_any());
+-                break;
+-                case TCKind._tk_TypeCode:
+-                out.write_TypeCode( read_TypeCode());
+-                break;
+-                case TCKind._tk_Principal:
+-                throw new NO_IMPLEMENT ("Principal deprecated");
+-                case TCKind._tk_objref:
+-                out.write_Object( read_Object());
+-                break;
+-                case TCKind._tk_string:
+-                out.write_string( read_string());
+-                break;
+-                case TCKind._tk_wstring:
+-                out.write_wstring( read_wstring());
+-                break;
+-                case TCKind._tk_fixed:
+-                out.write_fixed (read_fixed());
+-                break;
+-                case TCKind._tk_array:
++                case TCKind._tk_null:       // 0
++                    // fallthrough
++                case TCKind._tk_void:       // 1
+                 {
+-                    int length = tc.length();
+-                    for( int i = 0; i < length; i++ )
+-                        read_value( tc.content_type(), out );
+                     break;
+                 }
+-                case TCKind._tk_sequence:
++                case TCKind._tk_short:      // 2
+                 {
+-                    int len = read_long();
+-                    out.write_long(len);
+-                    for( int i = 0; i < len; i++ )
+-                        read_value( tc.content_type(), out );
++                    out.write_short( read_short());
+                     break;
+                 }
+-                case TCKind._tk_except:
+-                out.write_string( read_string());
+-                // don't break, fall through to ...
+-                case TCKind._tk_struct:
++                case TCKind._tk_long:       // 3
+                 {
+-                    for( int i = 0; i < tc.member_count(); i++)
+-                        read_value( tc.member_type(i), out );
++                    out.write_long( read_long());
+                     break;
+                 }
+-                case TCKind._tk_enum:
+-                out.write_long( read_long() );
+-                break;
+-                case TCKind._tk_alias:
++                case TCKind._tk_ushort:     // 4
+                 {
+-                    read_value( tc.content_type(), out  );
++                    out.write_ushort( read_ushort());
+                     break;
+                 }
+-                case TCKind._tk_value_box:
++                case TCKind._tk_ulong:      // 5
+                 {
+-                    String id = tc.id();
+-                    org.omg.CORBA.portable.BoxedValueHelper helper =
+-                        ((org.jacorb.orb.ORB)orb).getBoxedValueHelper(id);
+-                    if (helper == null)
++                    out.write_ulong( read_ulong());
++                    break;
++                }
++                case TCKind._tk_float:      // 6
++                {
++                    out.write_float( read_float());
++                    break;
++                }
++                case TCKind._tk_double:     // 7
++                {
++                    out.write_double( read_double());
++                    break;
++                }
++                case TCKind._tk_boolean:    // 8
++                {
++                    out.write_boolean( read_boolean());
++                    break;
++                }
++                case TCKind._tk_char:       // 9
++                {
++                    out.write_char( read_char());
++                    break;
++                }
++                case TCKind._tk_octet:      // 10
++                {
++                    out.write_octet( read_octet());
++                    break;
++                }
++                case TCKind._tk_any:        // 11
++                {
++                    out.write_any( read_any());
++                    break;
++                }
++                case TCKind._tk_TypeCode:   // 12
++                {
++                    out.write_TypeCode( read_TypeCode());
++                    break;
++                }
++                case TCKind._tk_Principal:  // 13
++                {
++                    throw new NO_IMPLEMENT ("Principal deprecated");
++                }
++                case TCKind._tk_objref:     // 14
++                {
++                    out.write_Object( read_Object());
++                    break;
++                }
++                case TCKind._tk_struct:     // 15
++                {
++                    for( int i = 0; i < typeCode.member_count(); i++)
+                     {
+-                        throw new MARSHAL ("No BoxedValueHelper for id " + id);
++                        read_value( typeCode.member_type(i), out );
+                     }
+-                    java.io.Serializable value = read_value(helper);
+-                    ((org.omg.CORBA_2_3.portable.OutputStream)out)
+-                    .write_value(value, helper);
+                     break;
+                 }
+-                case TCKind._tk_union:
++                case TCKind._tk_union:      // 16
+                 {
+-                    org.omg.CORBA.TypeCode disc = tc.discriminator_type();
++                    org.omg.CORBA.TypeCode disc = typeCode.discriminator_type();
+                     disc = TypeCode.originalType(disc);
+-                    int def_idx = tc.default_index();
++                    int def_idx = typeCode.default_index();
+                     int member_idx = -1;
+                     switch( disc.kind().value() )
+                     {
+-                        case TCKind._tk_short:
++                        case TCKind._tk_short:  // 2
+                         {
+                             short s = read_short();
+                             out.write_short(s);
+-                            for(int i = 0 ; i < tc.member_count() ; i++)
++                            for(int i = 0 ; i < typeCode.member_count() ; i++)
+                             {
+                                 if(i != def_idx)
+                                 {
+-                                    if(s == tc.member_label(i).extract_short())
++                                    if(s == typeCode.member_label(i).extract_short())
+                                     {
+                                         member_idx = i;
+                                         break;
+@@ -2097,15 +2319,15 @@
+                             break;
+                         }
+ 
+-                        case TCKind._tk_long:
++                        case TCKind._tk_long:   // 3
+                         {
+                             int s = read_long();
+                             out.write_long(s);
+-                            for(int i = 0 ; i < tc.member_count() ; i++)
++                            for(int i = 0 ; i < typeCode.member_count() ; i++)
+                             {
+                                 if(i != def_idx)
+                                 {
+-                                    if(s == tc.member_label(i).extract_long())
++                                    if(s == typeCode.member_label(i).extract_long())
+                                     {
+                                         member_idx = i;
+                                         break;
+@@ -2114,15 +2336,15 @@
+                             }
+                             break;
+                         }
+-                        case TCKind._tk_ushort:
++                        case TCKind._tk_ushort: // 4
+                         {
+                             short s = read_ushort();
+                             out.write_ushort(s);
+-                            for(int i = 0 ; i < tc.member_count() ; i++)
++                            for(int i = 0 ; i < typeCode.member_count() ; i++)
+                             {
+                                 if(i != def_idx)
+                                 {
+-                                    if(s == tc.member_label(i).extract_ushort())
++                                    if(s == typeCode.member_label(i).extract_ushort())
+                                     {
+                                         member_idx = i;
+                                         break;
+@@ -2132,15 +2354,15 @@
+                             break;
+                         }
+ 
+-                        case TCKind._tk_ulong:
++                        case TCKind._tk_ulong:  // 5
+                         {
+                             int s = read_ulong();
+                             out.write_ulong(s);
+-                            for(int i = 0 ; i < tc.member_count() ; i++)
++                            for(int i = 0 ; i < typeCode.member_count() ; i++)
+                             {
+                                 if(i != def_idx)
+                                 {
+-                                    if(s == tc.member_label(i).extract_ulong())
++                                    if(s == typeCode.member_label(i).extract_ulong())
+                                     {
+                                         member_idx = i;
+                                         break;
+@@ -2149,15 +2371,22 @@
+                             }
+                             break;
+                         }
+-                        case TCKind._tk_longlong:
++                        case TCKind._tk_float:      // 6
++                            // fallthrough
++                        case TCKind._tk_double:     // 7
+                         {
+-                            long s = read_longlong();
+-                            out.write_longlong(s);
+-                            for(int i = 0 ; i < tc.member_count() ; i++)
++                            throw new MARSHAL(
++                                "Invalid union discriminator type: " + disc);
++                        }
++                        case TCKind._tk_boolean:    // 8
++                        {
++                            boolean b = read_boolean();
++                            out.write_boolean( b );
++                            for(int i = 0 ; i < typeCode.member_count() ; i++)
+                             {
+-                                if(i != def_idx)
++                                if( i != def_idx)
+                                 {
+-                                    if(s == tc.member_label(i).extract_longlong())
++                                    if( b == typeCode.member_label(i).extract_boolean() )
+                                     {
+                                         member_idx = i;
+                                         break;
+@@ -2166,15 +2395,15 @@
+                             }
+                             break;
+                         }
+-                        case TCKind._tk_ulonglong:
++                        case TCKind._tk_char:   // 9
+                         {
+-                            long s = read_ulonglong();
+-                            out.write_ulonglong(s);
+-                            for(int i = 0 ; i < tc.member_count() ; i++)
++                            char s = read_char();
++                            out.write_char(s);
++                            for(int i = 0 ; i < typeCode.member_count() ; i++)
+                             {
+                                 if(i != def_idx)
+                                 {
+-                                    if(s == tc.member_label(i).extract_ulonglong())
++                                    if(s == typeCode.member_label(i).extract_char())
+                                     {
+                                         member_idx = i;
+                                         break;
+@@ -2183,15 +2412,34 @@
+                             }
+                             break;
+                         }
+-                        case TCKind._tk_char:
++                        case TCKind._tk_octet:      // 10
++                            // fallthrough
++                        case TCKind._tk_any:        // 11
++                            // fallthrough
++                        case TCKind._tk_TypeCode:   // 12
++                            // fallthrough
++                        case TCKind._tk_Principal:  // 13
++                            // fallthrough
++                        case TCKind._tk_objref:     // 14
++                            // fallthrough
++                        case TCKind._tk_struct:     // 15
++                            // fallthrough
++                        case TCKind._tk_union:      // 16
+                         {
+-                            char s = read_char();
+-                            out.write_char(s);
+-                            for(int i = 0 ; i < tc.member_count() ; i++)
++                            throw new MARSHAL(
++                                "Invalid union discriminator type: " + disc);
++                        }
++                        case TCKind._tk_enum:       // 17
++                        {
++                            int s = read_long();
++                            out.write_long(s);
++                            for( int i = 0 ; i < typeCode.member_count() ; i++)
+                             {
+-                                if(i != def_idx)
++                                if( i != def_idx)
+                                 {
+-                                    if(s == tc.member_label(i).extract_char())
++                                    int label =
++                                    typeCode.member_label(i).create_input_stream().read_long();
++                                    if(s == label)
+                                     {
+                                         member_idx = i;
+                                         break;
+@@ -2200,15 +2448,28 @@
+                             }
+                             break;
+                         }
+-                        case TCKind._tk_boolean:
++                        case TCKind._tk_string:     // 18
++                            // fallthrough
++                        case TCKind._tk_sequence:   // 19
++                            // fallthrough
++                        case TCKind._tk_array:      // 20
++                            // fallthrough
++                        case TCKind._tk_alias:      // 21
++                            // fallthrough
++                        case TCKind._tk_except:     // 22
+                         {
+-                            boolean b = read_boolean();
+-                            out.write_boolean( b );
+-                            for(int i = 0 ; i < tc.member_count() ; i++)
++                            throw new MARSHAL(
++                                "Invalid union discriminator type: " + disc);
++                        }
++                        case TCKind._tk_longlong:  // 23
++                        {
++                            long s = read_longlong();
++                            out.write_longlong(s);
++                            for(int i = 0 ; i < typeCode.member_count() ; i++)
+                             {
+-                                if( i != def_idx)
++                                if(i != def_idx)
+                                 {
+-                                    if( b == tc.member_label(i).extract_boolean() )
++                                    if(s == typeCode.member_label(i).extract_longlong())
+                                     {
+                                         member_idx = i;
+                                         break;
+@@ -2217,17 +2478,15 @@
+                             }
+                             break;
+                         }
+-                        case TCKind._tk_enum:
++                        case TCKind._tk_ulonglong:  // 24
+                         {
+-                            int s = read_long();
+-                            out.write_long(s);
+-                            for( int i = 0 ; i < tc.member_count() ; i++)
++                            long s = read_ulonglong();
++                            out.write_ulonglong(s);
++                            for(int i = 0 ; i < typeCode.member_count() ; i++)
+                             {
+-                                if( i != def_idx)
++                                if(i != def_idx)
+                                 {
+-                                    int label =
+-                                    tc.member_label(i).create_input_stream().read_long();
+-                                    if(s == label)
++                                    if(s == typeCode.member_label(i).extract_ulonglong())
+                                     {
+                                         member_idx = i;
+                                         break;
+@@ -2237,35 +2496,119 @@
+                             break;
+                         }
+                         default:
+-                        throw new MARSHAL("Invalid union discriminator type: " + disc);
++                        {
++                            throw new MARSHAL("Invalid union discriminator type: " + disc);
++                        }
+                     } // switch
+ 
+                     if( member_idx != -1 )
+                     {
+-                        read_value( tc.member_type( member_idx ), out );
++                        read_value( typeCode.member_type( member_idx ), out );
+                     }
+                     else if( def_idx != -1 )
+                     {
+-                        read_value( tc.member_type( def_idx ), out );
++                        read_value( typeCode.member_type( def_idx ), out );
+                     }
+                     break;
+                 }
+-                case 0xffffffff:
++                case TCKind._tk_enum:       // 17
+                 {
+-                    org.omg.CORBA.TypeCode _tc =
+-                        (org.omg.CORBA.TypeCode)(getRecursiveTCMap().get ( tc.id() ));
+-
++                    out.write_long( read_long() );
++                    break;
++                }
++                case TCKind._tk_string:     // 18
++                {
++                    out.write_string( read_string());
++                    break;
++                }
++                case TCKind._tk_sequence:   // 19
++                {
++                    int len = read_long();
++                    out.write_long(len);
++                    for( int i = 0; i < len; i++ )
++                    {
++                        read_value( typeCode.content_type(), out );
++                    }
++                    break;
++                }
++                case TCKind._tk_array:      // 20
++                {
++                    int length = typeCode.length();
++                    for( int i = 0; i < length; i++ )
++                    {
++                        read_value( typeCode.content_type(), out );
++                    }
++                    break;
++                }
++                case TCKind._tk_alias:      // 21
++                {
++                    read_value( typeCode.content_type(), out  );
++                    break;
++                }
++                case TCKind._tk_except:     // 22
++                {
++                    out.write_string( read_string());
+ 
+-                    if( _tc == null )
++                    for( int i = 0; i < typeCode.member_count(); i++)
+                     {
+-                        throw new MARSHAL("No recursive TC found for " + tc.id());
++                        read_value( typeCode.member_type(i), out );
+                     }
+ 
+-                    read_value( _tc , out );
++                    break;
++                }
++                case TCKind._tk_longlong:   // 23
++                {
++                    out.write_longlong( read_longlong());
++                    break;
++                }
++                case TCKind._tk_ulonglong:  // 24
++                {
++                    out.write_ulonglong( read_ulonglong());
++                    break;
++                }
++                case TCKind._tk_longdouble: // 25
++                {
++                    throw new org.omg.CORBA.BAD_TYPECODE(
++                        "type longdouble not supported in java");
++                }
++                case TCKind._tk_wchar:      // 26
++                {
++                    out.write_wchar( read_wchar());
++                    break;
++                }
++                case TCKind._tk_wstring:    // 27
++                {
++                    out.write_wstring( read_wstring());
++                    break;
++                }
++                case TCKind._tk_fixed:      // 28
++                {
++                    out.write_fixed (read_fixed());
++                    break;
++                }
++                case TCKind._tk_value:      // 29
++                {
++                    Serializable val = read_value();
++                    ((org.omg.CORBA_2_3.portable.OutputStream)out).write_value(val, typeCode.id());
++                    break;
++                }
++                case TCKind._tk_value_box:  // 30
++                {
++                    String id = typeCode.id();
++                    org.omg.CORBA.portable.BoxedValueHelper helper =
++                        ((org.jacorb.orb.ORB)orb).getBoxedValueHelper(id);
++                    if (helper == null)
++                    {
++                        throw new MARSHAL ("No BoxedValueHelper for id " + id);
++                    }
++                    java.io.Serializable value = read_value(helper);
++                    ((org.omg.CORBA_2_3.portable.OutputStream)out).write_value(value, helper);
+                     break;
+                 }
+                 default:
+-                throw new MARSHAL("Cannot handle TypeCode with kind " + kind);
++                {
++                    throw new MARSHAL("Cannot handle TypeCode with kind " + kind);
++                }
+             }
+         }
+         catch (BadKind ex)
+@@ -2280,7 +2623,6 @@
+         }
+     }
+ 
+-
+     public java.io.Serializable read_value()
+     {
+         int tag = read_long();
+@@ -2304,7 +2646,9 @@
+         tag = tag & 0xfffffff6;
+ 
+         if (tag == 0x7fffff00)
++        {
+             throw new MARSHAL ("missing value type information");
++        }
+         else if (tag == 0x7fffff02)
+         {
+             return read_typed_value(start_offset, codebase);
+@@ -2314,20 +2658,21 @@
+             return read_multi_typed_value( start_offset, codebase );
+         }
+         else
++        {
+             throw new MARSHAL("unknown value tag: 0x" +
+                               Integer.toHexString(theTag) + " (offset=0x" +
+                               Integer.toHexString(start_offset) + ")");
++        }
+     }
+ 
+     /**
+      * Overrides read_value(java.io.Serializable value) in
+      * org.omg.CORBA_2_3.portable.InputStream
+      */
+-
+     public java.io.Serializable read_value(final String rep_id)
+     {
+         int tag = read_long();
+-        int start_offset = pos - 4;
++        final int start_offset = pos - 4;
+ 
+         if (tag == 0xffffffff)
+         {
+@@ -2340,7 +2685,7 @@
+             return null;
+         }
+ 
+-        String codebase = ((tag & 1) != 0) ? read_codebase() : null;
++        final String codebase = ((tag & 1) != 0) ? read_codebase() : null;
+         chunkedValue = ((tag & 8) != 0);
+ 
+         int theTag = tag;
+@@ -2380,7 +2725,6 @@
+      * Overrides read_value(value) in
+      * org.omg.CORBA_2_3.portable.InputStream
+      */
+-
+     public java.io.Serializable read_value(java.io.Serializable value)
+     {
+         if (value instanceof org.omg.CORBA.portable.Streamable)
+@@ -2430,8 +2774,8 @@
+ 
+         if (tag == 0x7fffff00)
+         {
+-            return read_untyped_value ( new String[]{ ValueHandler.getRMIRepositoryID(clz) },
+-                                        start_offset, codebase);
++            return read_untyped_value (new String[]{ValueHandler.getRMIRepositoryID(clz)},
++                                                    start_offset, codebase);
+         }
+         else if (tag == 0x7fffff02)
+         {
+@@ -2444,8 +2788,10 @@
+         else
+         {
+             throw new MARSHAL("unknown value tag: 0x" +
+-                              Integer.toHexString(theTag) + " (offset=0x" +
+-                              Integer.toHexString(start_offset) + ")");
++                              Integer.toHexString(theTag) +
++                              " (offset=0x" +
++                              Integer.toHexString(start_offset) +
++                              ")");
+         }
+     }
+ 
+@@ -2453,8 +2799,6 @@
+      * Overrides read_value(factory) in
+      * org.omg.CORBA_2_3.portable.InputStream
+      */
+-
+-
+     public java.io.Serializable read_value
+         (final org.omg.CORBA.portable.BoxedValueHelper factory)
+     {
+@@ -2484,7 +2828,7 @@
+ 
+             if( result != null )
+             {
+-                getValueMap().put (new Integer(start_offset), result);
++                getValueMap().put(ObjectUtil.newInteger(start_offset), result);
+             }
+ 
+             return result;
+@@ -2498,9 +2842,11 @@
+             return read_typed_value(start_offset, codebase);
+         }
+         else
++        {
+             throw new MARSHAL("unknown value tag: 0x" +
+                               Integer.toHexString(theTag) + " (offset=0x" +
+                               Integer.toHexString(start_offset) + ")");
++        }
+     }
+ 
+     /**
+@@ -2510,71 +2856,52 @@
+      * `index'.
+      */
+     private java.io.Serializable read_untyped_value(final String[] repository_ids,
+-                                                     final int index,
+-                                                     final String codebase)
++                                                    final int index,
++                                                    final String codebase)
+     {
+         java.io.Serializable result = null;
+ 
+         if (chunkedValue || valueNestingLevel > 0)
+         {
+             valueNestingLevel++;
+-            int chunk_size_tag = readChunkSizeTag();
+-            chunk_end_pos = pos + chunk_size_tag;
++            readChunkSizeTag();
+         }
+ 
+-        for (int r = 0; r < repository_ids.length; r++)
++        for (int i = 0; i < repository_ids.length; i++)
+         {
+-            if (repository_ids[r].equals("IDL:omg.org/CORBA/WStringValue:1.0"))
++            if (repository_ids[i].equals("IDL:omg.org/CORBA/WStringValue:1.0"))
+             {
+                 // special handling of strings, according to spec
+                 result = read_wstring();
+                 break;
+             }
+-            else if (repository_ids[r].startsWith("RMI:javax.rmi.CORBA.ClassDesc:"))
++            else if (repository_ids[i].startsWith("RMI:javax.rmi.CORBA.ClassDesc:"))
+             {
+                 // special handling of java.lang.Class instances
+-                String classCodebase = (String)read_value(String.class);
+-                String reposId = (String)read_value(String.class);
+-                String className =
++                final String classCodebase = (String)read_value(String.class);
++                final String reposId = (String)read_value(String.class);
++                final String className =
+                     org.jacorb.ir.RepositoryID.className(reposId, null);
+-                ClassLoader ctxcl =
+-                    Thread.currentThread().getContextClassLoader();
+ 
+                 try
+                 {
+-                    if (ctxcl != null)
+-                    {
+-                        try
+-                        {
+-                            result = ctxcl.loadClass(className);
+-                        }
+-                        catch (ClassNotFoundException cnfe)
+-                        {
+-                            result = ValueHandler.loadClass(className,
+-                                                            classCodebase,
+-                                                            null);
+-                        }
+-                    }
+-                    else
+-                    {
+-                        result = ValueHandler.loadClass(className,
+-                                                        classCodebase,
+-                                                        null);
+-                    }
++                    result = loadClass(className, classCodebase);
+                 }
+                 catch (ClassNotFoundException e)
+                 {
+-                    if( r < repository_ids.length-1 )
++                    if( i < repository_ids.length-1 )
++                    {
+                         continue;
+-                    else
+-                        throw new MARSHAL("class not found: " + className);
++                    }
++
++                    throw new MARSHAL("class not found: " + className);
+                 }
+                 break;
+             }
+-            else if (repository_ids[r].startsWith ("IDL:"))
++            else if (repository_ids[i].startsWith ("IDL:"))
+             {
+                 org.omg.CORBA.portable.ValueFactory factory =
+-                    ((org.omg.CORBA_2_3.ORB)orb()).lookup_value_factory (repository_ids[r]);
++                    ((org.omg.CORBA_2_3.ORB)orb()).lookup_value_factory (repository_ids[i]);
+ 
+                 if (factory != null)
+                 {
+@@ -2582,78 +2909,49 @@
+                     result = factory.read_value (this);
+                     break;
+                 }
+-                else
++
++                if( i < repository_ids.length-1 )
+                 {
+-                    if( r < repository_ids.length-1 )
+-                        continue;
+-                    else
+-                        throw new MARSHAL ("No factory found for: " + repository_ids[0] );
++                    continue;
+                 }
++
++                throw new MARSHAL ("No factory found for: " + repository_ids[0] );
+             }
+             else // RMI
+             {
+-                // Load the value's class, using the context class loader
+-                // of the current thread if possible.  Here's Francisco
+-                // Reverbel's <reverbel at ime.usp.br> explanation of why
+-                // this is needed in JBoss:
+-
+-                // "It seems that ValueHandler.loadClass() uses the thread
+-                // context classloader only after it looks for other
+-                // classloaders in the call stack (weird). In some
+-                // situations (when EJBs are undeployed and then
+-                // redeployed) it finds in the call stack a classloader
+-                // used for an undeployed EJB. A value of class Foo is
+-                // then unmarshalled with type
+-                // classloaderOfEJB1:Foo, when the expected type is
+-                // classloaderOfEJB2:Foo. I am getting ClassCastExceptions is this
+-                // situation.
+-                // Explicitly using the thread context class loader in the
+-                // first place solves the problem."
+-
+-                String className =
+-                org.jacorb.ir.RepositoryID.className(repository_ids[r], null);
+-
+-                Class c = null;
+-                //#ifjdk 1.2
+-                ClassLoader ctxcl = Thread.currentThread().getContextClassLoader();
+-                //#else
+-                //# ClassLoader ctxcl = null;
+-                //#endif
++                final String className =
++                    org.jacorb.ir.RepositoryID.className(repository_ids[i], null);
++
+                 try
+                 {
+-                    if (ctxcl != null)
+-                    {
+-                        try
+-                        {
+-                            c = ctxcl.loadClass(className);
+-                        }
+-                        catch (ClassNotFoundException cnfe)
+-                        {
+-                            c = ValueHandler.loadClass(className, codebase, null);
+-                        }
+-                    }
+-                    else
+-                    {
+-                        c = ValueHandler.loadClass(className, codebase, null);
+-                    }
++                    final Class clazz = loadClass(className, codebase);
+ 
+-                    if (IDLEntity.class.isAssignableFrom(c))
++                    if (IDLEntity.class.isAssignableFrom(clazz))
+                     {
+                         java.lang.reflect.Method readMethod = null;
+-                        if (c != org.omg.CORBA.Any.class)
++                        if (clazz != org.omg.CORBA.Any.class)
+                         {
+-                            String helperClassName = c.getName() + "Helper";
++                            String helperClassName = clazz.getName() + "Helper";
+ 
+                             try
+                             {
+-                                Class helperClass =
+-                                c.getClassLoader().loadClass(
+-                                    helperClassName);
++                                final ClassLoader classLoader = clazz.getClassLoader();
++                                final Class helperClass;
++                                if (classLoader == null)
++                                {
++                                    helperClass = ObjectUtil.classForName(helperClassName);
++                                }
++                                else
++                                {
++                                    helperClass =
++                                        classLoader.loadClass(helperClassName);
++                                }
++
+                                 Class[] paramTypes = {
+                                     org.omg.CORBA.portable.InputStream.class
+                                 };
+                                 readMethod =
+-                                helperClass.getMethod("read", paramTypes);
++                                    helperClass.getMethod("read", paramTypes);
+                             }
+                             catch (ClassNotFoundException e)
+                             {
+@@ -2692,52 +2990,100 @@
+                         }
+                     }
+                     else
+-                        result = ValueHandler.readValue(this, index, c,
+-                                                        repository_ids[r],
++                    {
++                        result = ValueHandler.readValue(this, index, clazz,
++                                                        repository_ids[i],
+                                                         null);
++                    }
+                 }
+                 catch (ClassNotFoundException e)
+                 {
+-                    if( r < repository_ids.length-1 )
++                    if( i < repository_ids.length-1 )
++                    {
+                         continue;
+-                    else
+-                        throw new MARSHAL ("class not found: " + className);
+-                }
++                    }
+ 
++                    throw new MARSHAL ("class not found: " + className);
++                }
+             }
+         }
+ 
+         // value type instances may be null...
+         if( result != null )
+         {
+-            getValueMap().put (new Integer (index), result);
++            getValueMap().put(ObjectUtil.newInteger(index), result);
+         }
+ 
+         return result;
+     }
+ 
++    /** Load the value's class, using the context class loader
++     *  of the current thread if possible.  Here's Francisco
++     *  Reverbel's <reverbel at ime.usp.br> explanation of why
++     *  this is needed in JBoss:
++     *
++     *  "It seems that ValueHandler.loadClass() uses the thread
++     *  context classloader only after it looks for other
++     *  classloaders in the call stack (weird). In some
++     *  situations (when EJBs are undeployed and then
++     *  redeployed) it finds in the call stack a classloader
++     *  used for an undeployed EJB. A value of class Foo is
++     *  then unmarshalled with type
++     *  classloaderOfEJB1:Foo, when the expected type is
++     *  classloaderOfEJB2:Foo. I am getting ClassCastExceptions is this
++     *  situation.
++     *  Explicitly using the thread context class loader in the
++     *  first place solves the problem."
++     */
++    private Class loadClass(String className, final String codebase) throws ClassNotFoundException
++    {
++        Class clazz;
++        //#ifjdk 1.2
++        ClassLoader clazzLoader = Thread.currentThread().getContextClassLoader();
++        //#else
++        //# ClassLoader ctxcl = null;
++        //#endif
++
++        if (clazzLoader == null)
++        {
++            clazz = ValueHandler.loadClass(className, codebase, null);
++        }
++        else
++        {
++            try
++            {
++                clazz = clazzLoader.loadClass(className);
++            }
++            catch (ClassNotFoundException e)
++            {
++                clazz = ValueHandler.loadClass(className, codebase, null);
++            }
++        }
++        return clazz;
++    }
++
+     /**
+      * try to read in the chunk size.
+      * special handling if there's no chunk size
+      * in the stream.
+      */
+-    private int readChunkSizeTag()
++    private void readChunkSizeTag()
+     {
+         int savedPos = pos;
+         int savedIndex = index;
+         int chunk_size_tag = read_long();
+ 
+-        if (!sunInteropFix || chunk_size_tag > 0 && chunk_size_tag < max_block_size)
++        if (!sunInteropFix || chunk_size_tag > 0 && chunk_size_tag < MAX_BLOCK_SIZE)
+         {
+-            // looks like the correct chunk size
+-            return chunk_size_tag;
++            // valid chunk size: set the ending position of the chunk 
++        	chunk_end_pos = pos + chunk_size_tag;
+         }
+-        else
++        else 
+         {
+-            // reset buffer
+-            pos = savedPos;
+-            index = savedIndex;
+-            return max_block_size;
++        	// reset buffer and remember that we're not within a chunk
++        	pos = savedPos;
++        	index = savedIndex;
++        	chunk_end_pos = -1;
+         }
+     }
+ 
+@@ -2746,7 +3092,6 @@
+      * by a single RepositoryID.  It is assumed that the tag and the codebase
+      * of the value have already been read.
+      */
+-
+     private java.io.Serializable read_typed_value( final int index,
+                                                    final String codebase)
+     {
+@@ -2758,7 +3103,6 @@
+      * by an array of RepositoryIDs.  It is assumed that the tag and the codebase
+      * of the value have already been read.
+      */
+-
+     private java.io.Serializable read_multi_typed_value( final int index,
+                                                          final String codebase)
+     {
+@@ -2766,7 +3110,9 @@
+         String[] ids = new String[ id_count ];
+ 
+         for( int i = 0; i < id_count; i++ )
++        {
+             ids[i] = read_repository_id();
++        }
+ 
+         return read_untyped_value (ids, index, codebase);
+     }
+@@ -2785,23 +3131,22 @@
+             int index = read_long();
+             index = index + pos - 4;
+ 
+-            String repId = (String)getRepIdMap().get (new Integer(index));
++            String repId = (String)getRepIdMap().get(ObjectUtil.newInteger(index));
+             if (repId == null)
++            {
+                 throw new MARSHAL("stale RepositoryID indirection");
+-            else
+-                return repId;
+-        }
+-        else
+-        {
+-            // a new id
+-            pos -= 4;
+-            index -= 4;
+-            int start_offset = pos;
+-            String repId = read_string();
+-
+-            getRepIdMap().put (new Integer(start_offset), repId);
++            }
+             return repId;
+         }
++
++        // a new id
++        pos -= 4;
++        index -= 4;
++        int start_offset = pos;
++        String repId = read_string();
++
++        getRepIdMap().put(ObjectUtil.newInteger(start_offset), repId);
++        return repId;
+     }
+ 
+     /**
+@@ -2817,23 +3162,22 @@
+             // indirection
+             int index = read_long();
+             index = index + pos - 4;
+-            String codebase = (String)getCodebaseMap().get (new Integer(index));
++            String codebase = (String)getCodebaseMap().get(ObjectUtil.newInteger(index));
+             if (codebase == null)
++            {
+                 throw
+                 new MARSHAL("stale codebase indirection");
+-            else
+-                return codebase;
+-        }
+-        else
+-        {
+-            // a new codebase string
+-            pos -= 4;
+-            index -= 4;
+-            int start_offset = pos;
+-            String codebase = read_string();
+-            getCodebaseMap().put (new Integer(start_offset), codebase);
++            }
++
+             return codebase;
+         }
++        // a new codebase string
++        pos -= 4;
++        index -= 4;
++        int start_offset = pos;
++        String codebase = read_string();
++        getCodebaseMap().put (ObjectUtil.newInteger(start_offset), codebase);
++        return codebase;
+     }
+ 
+     /**
+@@ -2845,9 +3189,10 @@
+         // indirection
+         int index = read_long();
+         index = index + pos - 4;
+-        java.lang.Object value = getValueMap().get (new Integer(index));
+-        if (value == null) {
++        java.lang.Object value = getValueMap().get (ObjectUtil.newInteger(index));
+ 
++        if (value == null)
++        {
+             // Java to IDL Language Mapping, v1.1, page 1-44:
+             //
+             // "The ValueHandler object may receive an IndirectionException
+@@ -2864,11 +3209,11 @@
+ 
+             throw new org.omg.CORBA.portable.IndirectionException (index);
+         }
+-        else
+-            return (java.io.Serializable)value;
++
++        return (java.io.Serializable)value;
+     }
+ 
+-    private String validateName (String name)
++    private String validateName(String name)
+     {
+         if (name != null && name.length() == 0)
+         {
+@@ -2877,16 +3222,15 @@
+         return name;
+     }
+ 
+-    private String validateID (String id)
++    private String validateID(String id)
+     {
+         if (id == null || id.length() == 0)
+         {
+-            id = "IDL:";
++            return "IDL:";
+         }
+         return id;
+     }
+ 
+-
+     /**
+      * Reads an abstract interface from this stream. The abstract interface
+      * Reads an abstract interface from this stream. The abstract interface
+@@ -2894,7 +3238,6 @@
+      * union contains a CORBA object reference, or false if the union contains
+      * a value.
+      */
+-
+     public java.lang.Object read_abstract_interface()
+     {
+         return read_boolean() ? (java.lang.Object)read_Object()
+@@ -2907,14 +3250,12 @@
+      * union contains a CORBA object reference, or false if the union contains
+      * a value.
+      */
+-
+-    public java.lang.Object read_abstract_interface(final java.lang.Class clz)
++    public java.lang.Object read_abstract_interface(final java.lang.Class clazz)
+     {
+-        return read_boolean() ? (java.lang.Object)read_Object(clz)
+-        : (java.lang.Object)read_value(clz);
++        return read_boolean() ? (java.lang.Object)read_Object(clazz)
++        : (java.lang.Object)read_value(clazz);
+     }
+ 
+-
+     public int get_pos()
+     {
+         return pos;
+@@ -2926,9 +3267,46 @@
+      * store an object into the map before actually reading its state.
+      * This is essential for unmarshalling recursive values.
+      */
+-
+     public void register_value(final java.io.Serializable value)
+     {
+-        getValueMap().put(new Integer(currentValueIndex), value);
++        getValueMap().put(ObjectUtil.newInteger(currentValueIndex), value);
++    }
++
++    /**
++     * <code>Pair</code> is merely a private storage class used by
++     * {@link #cachedTypecodes}.
++     */
++    private static final class Pair
++    {
++        /**
++         * <code>first</code> is the typecode we are caching.
++         */
++        public final org.omg.CORBA.TypeCode typeCode;
++        /**
++         * <code>second</code> is the location the original typecode was found.
++         */
++        public final Integer position;
++
++        /**
++         * Create a new <code>Pair</code>.
++         *
++         * @param typeCode an <code>org.omg.CORBA.TypeCode</code> value
++         * @param position an <code>Integer</code> value
++         */
++        public Pair( org.omg.CORBA.TypeCode typeCode, Integer position )
++        {
++            this.typeCode = typeCode;
++            this.position = position;
++        }
++
++        /**
++         * <code>toString</code> used for debugging ONLY.
++         *
++         * @return a <code>String</code> value
++         */
++        public String toString()
++        {
++            return (typeCode + " and " + position );
++        }
+     }
+ }
+Index: src/org/jacorb/orb/CDROutputStream.java
+===================================================================
+RCS file: /cvsroot/jacorb/JacORB/src/org/jacorb/orb/CDROutputStream.java,v
+retrieving revision 1.106
+diff -u -r1.106 CDROutputStream.java
+--- src/org/jacorb/orb/CDROutputStream.java	17 May 2006 13:14:37 -0000	1.106
++++ src/org/jacorb/orb/CDROutputStream.java	5 May 2007 00:36:08 -0000
+@@ -21,20 +21,23 @@
+  */
+ 
+ import java.io.*;
++import java.math.BigDecimal;
+ import java.util.*;
+ 
+ import org.apache.avalon.framework.configuration.*;
+ 
+ import org.jacorb.ir.RepositoryID;
+ import org.jacorb.orb.giop.CodeSet;
++import org.jacorb.orb.giop.GIOPConnection;
+ import org.jacorb.util.ValueHandler;
+ import org.jacorb.util.ObjectUtil;
+ 
+ import org.omg.CORBA.BAD_PARAM;
+ import org.omg.CORBA.CODESET_INCOMPATIBLE;
++import org.omg.CORBA.DATA_CONVERSION;
++import org.omg.CORBA.INTERNAL;
+ import org.omg.CORBA.MARSHAL;
+ import org.omg.CORBA.NO_IMPLEMENT;
+-import org.omg.CORBA.INTERNAL;
+ import org.omg.CORBA.TCKind;
+ import org.omg.CORBA.TypeCodePackage.BadKind;
+ import org.omg.CORBA.TypeCodePackage.Bounds;
+@@ -44,7 +47,7 @@
+ 
+ /**
+  * @author Gerald Brose,  1999
+- * @version $Id: CDROutputStream.java,v 1.106 2006/05/17 13:14:37 alphonse.bendt Exp $
++ * @version $Id: CDROutputStream.java,v 1.123 2007/04/26 23:07:26 francisco Exp $
+  *
+  * A stream for CDR marshalling.
+  *
+@@ -83,13 +86,6 @@
+      */
+     private Stack encaps_stack;
+ 
+-    /**
+-     * <code>recursiveTCMap</code> is used to remember the original TCs for a
+-     * given ID that is used in a recursive/repeated TC. Do NOT access this
+-     * variable directly. It is initialised on demand. Use the method
+-     * {@link #getRecursiveTCMap() getRecursiveTCMap()}
+-     */
+-    private Map recursiveTCMap;
+ 
+     /**
+      * <code>valueMap</code> is used to maps all value objects that have
+@@ -124,6 +120,18 @@
+      */
+     private Map cachedTypecodes;
+ 
++    /**
++     * This Map is basically a one-entry map pool to be used in
++     * write_TypeCode() as the repeatedTCMap.
++     */
++    private Map repeatedTCMap;
++
++    /**
++     * This Map is basically a one-entry map pool to be used in
++     * write_TypeCode() as the recursiveTCMap.
++     */
++    private Map recursiveTCMap;
++
+     /** Remembers the starting position of the current chunk. */
+     private int chunk_size_tag_pos = -1;   // -1 means we're not within a chunk
+     private int chunk_size_tag_index;
+@@ -138,7 +146,7 @@
+     /** True if write_value_internal called writeReplace */
+     private boolean writeReplaceCalled = false;
+ 
+-    private List deferredArrayQueue = new ArrayList();
++    private final List deferredArrayQueue = new ArrayList();
+ 
+     private org.omg.CORBA.ORB orb = null;
+ 
+@@ -148,6 +156,11 @@
+         to be bitwise or'ed into value tags. */
+     private int chunkingFlag = 0;
+ 
++    /**
++     * <code>codesetEnabled</code> denotes whether codeset marshalling is enabled.
++     */
++    private boolean codesetEnabled;
++
+     /** configurable properties */
+     private boolean useBOM = false;
+     private boolean chunkCustomRmiValuetypes = false;
+@@ -164,8 +177,10 @@
+      */
+ 
+     public void configure(Configuration configuration)
+-        throws ConfigurationException
+     {
++       codesetEnabled  =
++            configuration.getAttribute("jacorb.codeset","on").equals("on");
++
+         useBOM =
+             configuration.getAttribute("jacorb.use_bom","off").equals("on");
+ 
+@@ -176,6 +191,7 @@
+ 
+         useIndirection =
+            !( configuration.getAttribute("jacorb.interop.indirection_encoding_disable","off").equals("on"));
++
+     }
+ 
+     private static class DeferredWriteFrame
+@@ -188,6 +204,8 @@
+         public DeferredWriteFrame( int write_pos, int start,
+                                    int length, byte[] buf )
+         {
++            super();
++
+             this.write_pos = write_pos;
+             this.start = start;
+             this.length = length;
+@@ -205,6 +223,7 @@
+ 
+     public CDROutputStream()
+     {
++        super();
+         bufMgr = BufferManager.getInstance(); // the BufferManager will be configured by now!
+         buffer = bufMgr.getPreferredMemoryBuffer();
+     }
+@@ -220,14 +239,7 @@
+         if (orb != null )
+         {
+             this.orb = orb;
+-            try
+-            {
+-                configure(((org.jacorb.orb.ORB)orb).getConfiguration());
+-            }
+-            catch( ConfigurationException ce )
+-            {
+-                throw new INTERNAL("ConfigurationException: " + ce);
+-            }
++            configure(((org.jacorb.orb.ORB)orb).getConfiguration());
+         }
+     }
+ 
+@@ -240,6 +252,8 @@
+ 
+     public CDROutputStream(final byte[] buf)
+     {
++        super();
++
+         bufMgr = BufferManager.getInstance();
+         buffer = buf;
+     }
+@@ -271,21 +285,6 @@
+ 
+ 
+     /**
+-     * Gets the Map that is used to store recursive TypeCodes.
+-     *
+-     * @return a <code>Map</code> value
+-     */
+-    private Map getRecursiveTCMap()
+-    {
+-        if (recursiveTCMap == null)
+-        {
+-            recursiveTCMap = new HashMap();
+-        }
+-        return recursiveTCMap;
+-    }
+-
+-
+-    /**
+      * Gets the Map that is used to detect reference sharing when
+      * marshaling valuetype instances.
+      *
+@@ -295,7 +294,7 @@
+     {
+         if (valueMap == null)
+         {
+-            valueMap = ObjectUtil.createIdentityHashMap();
++            valueMap = new IdentityHashMap();
+         }
+         return valueMap;
+     }
+@@ -352,7 +351,7 @@
+ 
+         DeferredWriteFrame next_frame = null;
+ 
+-        if( deferredArrayQueue != null && deferredArrayQueue.size() > 0 )
++        if(deferredArrayQueue.size() > 0 )
+         {
+             // find the first frame that falls within the current window,
+             // i.e. that need s to be written
+@@ -376,7 +375,6 @@
+ 
+         while( write_idx < start + length )
+         {
+-
+             if( next_frame != null && write_idx == next_frame.write_pos )
+             {
+                 if ( ! (next_frame.length <= start + length - write_idx))
+@@ -394,8 +392,7 @@
+                 next_frame = null;
+ 
+                 // and look up the next frame
+-                if( deferredArrayQueue != null &&
+-                    list_idx < deferredArrayQueue.size() )
++                if(list_idx < deferredArrayQueue.size() )
+                 {
+                     next_frame = (DeferredWriteFrame)deferredArrayQueue.get( list_idx++ );
+                     if( next_frame.write_pos > start + length )
+@@ -454,10 +451,7 @@
+ 
+         buffer = null;
+         closed = true;
+-        if (deferredArrayQueue != null)
+-        {
+-            deferredArrayQueue.clear();
+-        }
++        deferredArrayQueue.clear();
+         deferred_writes = 0;
+     }
+ 
+@@ -508,11 +502,9 @@
+ 
+     private final void check(final int i)
+     {
+-        byte [] new_buf;
+-
+         if (buffer == null || (pos + i + 2) > buffer.length)
+         {
+-            new_buf = bufMgr.getBuffer( pos+i+2, true);
++            final byte[] new_buf = bufMgr.getBuffer( pos+i+2, true);
+ 
+             if (buffer != null)
+             {
+@@ -522,7 +514,6 @@
+             bufMgr.returnBuffer (buffer, true);
+ 
+             buffer = new_buf;
+-            new_buf = null;
+         }
+     }
+ 
+@@ -573,7 +564,7 @@
+ 
+         // set up new indirection maps for this encapsulation
+ 
+-        valueMap = ObjectUtil.createIdentityHashMap();
++        valueMap = new IdentityHashMap();
+         repIdMap = new HashMap();
+         codebaseMap = new HashMap();
+ 
+@@ -609,7 +600,10 @@
+     public final void endEncapsulation()
+     {
+         if( encaps_start == -1 )
++        {
+             throw new MARSHAL("Too many end-of-encapsulations");
++        }
++
+         if( encaps_stack == null )
+         {
+             throw new MARSHAL("Internal Error - closeEncapsulation failed");
+@@ -638,16 +632,16 @@
+ 
+     public byte[] getBufferCopy()
+     {
+-        ByteArrayOutputStream bos =
+-            new ByteArrayOutputStream();
++        final ByteArrayOutputStream bos =
++            new ByteArrayOutputStream(size());
+ 
+         try
+         {
+             write( bos, 0, size());
+         }
+-        catch( IOException io )
++        catch( IOException e )
+         {
+-            //            Debug.output(1, io );
++            throw new INTERNAL("should not happen: " + e.toString());
+         }
+ 
+         return bos.toByteArray();
+@@ -665,10 +659,7 @@
+ 
+     public void reset()
+     {
+-        if (deferredArrayQueue != null)
+-        {
+-            deferredArrayQueue.clear();
+-        }
++        deferredArrayQueue.clear();
+         pos = 0;
+         deferred_writes = 0;
+         index = 0;
+@@ -745,12 +736,10 @@
+             }
+             return new CDRInputStream(orb(), baos.toByteArray());
+         }
+-        else
+-        {
+-            byte[] result = new byte[index + 1];
+-            System.arraycopy(buffer, 0, result, 0, result.length);
+-            return new CDRInputStream(orb, result);
+-        }
++
++        byte[] result = new byte[index + 1];
++        System.arraycopy(buffer, 0, result, 0, result.length);
++        return new CDRInputStream(orb, result);
+     }
+ 
+     public final void write_any(final org.omg.CORBA.Any value)
+@@ -764,9 +753,13 @@
+         check(1);
+ 
+         if( value )
++        {
+             buffer[pos++] = 1;
++        }
+         else
++        {
+             buffer[pos++] = 0;
++        }
+         index++;
+     }
+ 
+@@ -781,9 +774,13 @@
+             for( int i = offset; i < offset+length; i++ )
+             {
+                 if( value[i] )
++                {
+                     buffer[pos++] = 1;
++                }
+                 else
++                {
+                     buffer[pos++] = 0;
++                }
+             }
+             index += length;
+         }
+@@ -791,83 +788,114 @@
+ 
+ 
+     /**
+-     * Writes char according to specified encoding.
++     * <code>write_char</code> writes a character to the output stream. If
++     * codeset translation is active then it will use String and an encoding to
++     * get the bytes. It can then do a test for whether to throw DATA_CONVERSION.
++     *
++     * @param c a <code>char</code> value
+      */
+-    public final void write_char(final char c)
++    public final void write_char (final char c)
+     {
+-        check( 1 );
+-
+-        int too_large_mask =
+-            (codeSet == CodeSet.ISO8859_1)?
+-        0xFF00 : //ISO8859-1
+-        0xFF80; //UTF-8
+-
+-        if( (c & too_large_mask) != 0 )//Are there any 1s in the MSB?
+-        {
+-            throw new org.omg.CORBA.DATA_CONVERSION(
+-                "char (" + c +
+-                ") out of range for " +
+-                CodeSet.csName( codeSet) );
++        // According to 15.3.1.6 of CORBA 3.0 'a single instance of the char type
++        // may only hold one octet of any multi-byte character encoding.'
++        // Therefore we ensure that we are in the single byte range i.e.
++        // less than 0xFF or \377.
++        if (c > '\377')
++        {
++            throw new DATA_CONVERSION ("Char " + c + " out of range");
+         }
+ 
++        check( 1 );
++        buffer[pos++] = (byte)c;
+         index++;
+-        buffer[ pos++ ] = (byte) c;
+     }
+ 
++
+     public final void write_char_array
+        (final char[] value, final int offset, final int length)
+     {
+         if( value == null )
+-            throw new MARSHAL( "Null References" );
++        {
++            throw new MARSHAL("Cannot marshall null array.");
++        }
++        else if ( offset + length > value.length || length < 0 || offset < 0 )
++        {
++            throw new MARSHAL
++                ("Cannot marshall as indices for array are out bounds.");
++        }
+ 
+-        //no alignment necessary
+         check( length );
+ 
+-        int too_large_mask =
+-            (codeSet == CodeSet.ISO8859_1)?
+-        0xFF00 : //ISO8859-1
+-        0xFF80; //UTF-8
+-
+-
+-        for( int i = offset; i < offset+length; i++)
++        for (int i=offset; i < length+offset; i++)
+         {
+-            if( (value[i] & too_large_mask) != 0 )
++            if (value[i] > '\377')
+             {
+-                throw new MARSHAL("char (" + value[i] +
+-                                  ") out of range for " +
+-                                  CodeSet.csName( codeSet ));
++                throw new DATA_CONVERSION ("Char " + value[i] + " out of range");
+             }
+-
+-            buffer[ pos++ ] = (byte) value[i];
++            buffer[pos++] = (byte)value[i];
+         }
+-
+-        index += length;
++        index+=length;
+     }
+ 
++
++    /**
++     * <code>write_string</code> writes a string to the output stream. It is
++     * optimised for whether it is writing a blank string or for whether codeset
++     * translation is active.
++     *
++     * @param s a <code>String</code> value
++     */
+     public final void write_string(final String s)
+     {
++        // size leaves room for ulong, plus the string itself (one or more
++        // bytes per char in the string, depending on the codeset), plus the
++        // terminating NUL char
++        int size;
++        // sizePosition is the position in the buffer for the size to be
++        // written.
++        int sizePosition;
++
+         if( s == null )
+         {
+-            throw new MARSHAL("Null References");
++            throw new MARSHAL("Cannot marshall null string.");
+         }
+ 
+-        // size indicator ulong + length in chars( i.e. bytes for type char)
+-        // incl. terminating NUL char
+-        int size = 4 + s.length() + 1;
+-        check( size, 4 );
++        if (codesetEnabled)
++        {
++            // in the worst case (UTF-8) a string char might take up to 3 bytes
++            size = 4 + 3 * s.length() + 1;
++        }
++        else
++        {
++            // just one byte per string char
++            size = 4 + s.length() + 1;
++        }
++        check(size, 4);
++        sizePosition = pos;
+ 
+-        int sizepos = pos;
+         pos += 4;
+         index += 4;
+ 
+-        char ch;
+         for (int i = 0; i < s.length(); i++)
+-            write_char_i(s.charAt(i),false,false, codeSet);
++        {
++            if (codesetEnabled)
++            {
++                write_char_i(s.charAt(i),false,false, codeSet);
++            }
++            else
++            {
++                buffer[pos++] = (byte)s.charAt(i);
++                index++;
++            }
++        }
+ 
+         buffer[ pos++ ] = (byte) 0; //terminating NUL char
+         index ++;
+-        size = pos - (sizepos + 4); // compute translated size
+-        _write4int( buffer,sizepos,size);
++
++        // Now write the size back in.
++        size = pos - (sizePosition + 4); // compute translated size
++
++        _write4int( buffer, sizePosition, size);
+     }
+ 
+     public final void write_wchar(final char c)
+@@ -898,10 +926,11 @@
+                     if( giop_minor == 2 && write_length_indicator )
+                     {
+                         //the chars length in bytes
+-                        write_octet( (byte) 1 );
++                        buffer[pos++] = (byte) 1;
++                        index++;
+                     }
+ 
+-                    buffer[ pos++ ] = (byte) c;
++                    buffer[pos++] = (byte) c;
+                     index++;
+                 }
+                 else if( c > 0x07FF )
+@@ -909,7 +938,8 @@
+                     if( giop_minor == 2 && write_length_indicator )
+                     {
+                         //the chars length in bytes
+-                        write_octet( (byte) 3 );
++                        buffer[pos++] = (byte) 3;
++                        index++;
+                     }
+ 
+                     buffer[pos++]=(byte)(0xE0 | ((c >> 12) & 0x0F));
+@@ -923,7 +953,8 @@
+                     if( giop_minor == 2 && write_length_indicator )
+                     {
+                         //the chars length in bytes
+-                        write_octet( (byte) 2 );
++                        buffer[pos++] = (byte) 2 ;
++                        index++;
+                     }
+ 
+                     buffer[pos++]=(byte)(0xC0 | ((c >>  6) & 0x1F));
+@@ -940,7 +971,8 @@
+                     if( write_length_indicator )
+                     {
+                         //the chars length in bytes
+-                        write_octet( (byte) 2 );
++                        buffer[pos++] = (byte) 2;
++                        index++;
+                     }
+ 
+                     if( write_bom )
+@@ -976,12 +1008,16 @@
+        (final char[] value, final int offset, final int length)
+     {
+         if( value == null )
++        {
+             throw new MARSHAL("Null References");
++        }
+ 
+         check( length * 3 );
+ 
+         for( int i = offset; i < offset+length; i++)
++        {
+             write_wchar( value[i] );
++        }
+     }
+ 
+     public final void write_wstring(final String s)
+@@ -1083,13 +1119,14 @@
+         }
+     }
+ 
++    public final void write_fixed(BigDecimal value, short digits, short scale)
++    {
++        write_fixed(value);
++    }
++
+     public final void write_fixed(final java.math.BigDecimal value)
+     {
+-        //#ifjdk 1.2
+         String v = value.unscaledValue().toString();
+-        //#else
+-        //# String v = value.movePointRight(value.scale()).toString();
+-        //#endif
+         byte [] representation;
+         int b, c;
+ 
+@@ -1133,7 +1170,6 @@
+         System.arraycopy(representation,0,buffer,pos,representation.length);
+         index += representation.length;
+         pos += representation.length;
+-
+     }
+ 
+     public final void write_float(final float value)
+@@ -1257,7 +1293,6 @@
+ 
+     public void write_Object(final org.omg.CORBA.Object value)
+     {
+-
+         if( value == null )
+         {
+             IORHelper.write(this, null_ior );
+@@ -1265,10 +1300,15 @@
+         else
+         {
+             if( value instanceof org.omg.CORBA.LocalObject )
++            {
+                 throw new MARSHAL("Attempt to serialize a locality-constrained object.");
++            }
+             org.omg.CORBA.portable.ObjectImpl obj =
+                 (org.omg.CORBA.portable.ObjectImpl)value;
+-            IORHelper.write(this, ((Delegate)obj._get_delegate()).getIOR()  );
++
++            IOR intermediary = ((Delegate)obj._get_delegate()).getIOR();
++
++            IORHelper.write(this, intermediary);
+         }
+     }
+ 
+@@ -1362,332 +1402,557 @@
+         }
+     }
+ 
+-    public final void write_TypeCode (org.omg.CORBA.TypeCode value)
++    public final void write_TypeCode (org.omg.CORBA.TypeCode typeCode)
+     {
+-        String   id                   = null;
+-        org.omg.CORBA.TypeCode cached = null;
+-
+-        try
+-        {
+-            // Get the id for this typecode.
+-            id = value.id();
+-        }
+-        // Masking on purpose as only determining whether to cache here.
+-        catch (BadKind e)
+-        {
+-        }
+-
+-        if (compactTypeCodes > 0 && id != null)
++        if (compactTypeCodes > 0)
+         {
+-            if (cachedTypecodes == null)
++            final String id;
++            try
+             {
+-                cachedTypecodes = new HashMap();
++                switch (typeCode.kind().value())
++                {
++                    case TCKind._tk_objref:   //14
++                    case TCKind._tk_struct:   //15
++                    case TCKind._tk_union:    //16
++                    case TCKind._tk_enum:     //17
++                    {
++                        id = typeCode.id();
++                        break;
++                    }
++                    case TCKind._tk_string:   //18
++                    case TCKind._tk_sequence: //19
++                    case TCKind._tk_array:    //20
++                    {
++                        id = null;
++                        break; //dummy cases for optimized switch
++                    }
++                    case TCKind._tk_alias:    //21
++                    case TCKind._tk_except:   //22
++                    {
++                        id = typeCode.id();
++                        break;
++                    }
++                    case TCKind._tk_longlong:  // 23
++                    case TCKind._tk_ulonglong: // 24
++                    case TCKind._tk_longdouble:// 25
++                    case TCKind._tk_wchar:     // 26
++                    case TCKind._tk_wstring:   // 27
++                    case TCKind._tk_fixed:     // 28
++                    {
++                        id = null;
++                        break; //dummy cases for optimized switch
++                    }
++                    case TCKind._tk_value:     // 29
++                    case TCKind._tk_value_box: // 30
++                    {
++                        id = typeCode.id();
++                        break;
++                    }
++                    case TCKind._tk_native:    // 31
++                    {
++                        id = null;
++                        break; //dummy cases for optimized switch
++                    }
++                    case TCKind._tk_abstract_interface: //32
++                    case TCKind._tk_local_interface:    //33
++                    {
++                        id = typeCode.id();
++                        break;
++                    }
++                    default:
++                    {
++                        id = null;
++                        break; //TC has no id
++                    }
++                }
+             }
+-            else
++            catch(org.omg.CORBA.TypeCodePackage.BadKind e)
+             {
+-                // We may previously have already compacted and cached this
+-                // typecode.
+-                cached = (org.omg.CORBA.TypeCode)cachedTypecodes.get (id);
++                throw new INTERNAL("should never happen");
+             }
+ 
+-            // If we don't have a cached value get the compact form and
+-            // cache it.
+-            if (cached == null)
+-            {
+-                value = value.get_compact_typecode();
+-                cachedTypecodes.put (id, value);
+-            }
+-            else
++            if (id != null)
+             {
+-                value = cached;
++                final org.omg.CORBA.TypeCode cached;
++
++                if (cachedTypecodes == null)
++                {
++                    cachedTypecodes = new HashMap();
++                    cached = null;
++                }
++                else
++                {
++                    // We may previously have already compacted and cached this
++                    // typecode.
++                    cached = (org.omg.CORBA.TypeCode)cachedTypecodes.get(id);
++                }
++
++                // If we don't have a cached value get the compact form and
++                // cache it.
++                if (cached == null)
++                {
++                    typeCode = typeCode.get_compact_typecode();
++                    cachedTypecodes.put(id, typeCode);
++                }
++                else
++                {
++                    typeCode = cached;
++                }
+             }
+         }
+-        write_TypeCode (value, null);
++
++        if (repeatedTCMap == null)
++        {
++            repeatedTCMap = new HashMap();
++        }
++
++        if (recursiveTCMap == null)
++        {
++            recursiveTCMap = new HashMap();
++        }
++
++        try
++        {
++            write_TypeCode(typeCode, recursiveTCMap, repeatedTCMap);
++        }
++        finally
++        {
++            repeatedTCMap.clear();
++            recursiveTCMap.clear();
++        }
+     }
+ 
+-    private final void writeRecursiveTypeCode
+-       (final org.omg.CORBA.TypeCode value, final Map tcMap) throws BadKind
++    private final void writeIndirectionMarker(final Object key,
++                                              final Map indirectionTCMap)
+     {
+         write_long( -1 ); // recursion marker
+         int negative_offset =
+-            ((Integer) tcMap.get( value.id())).intValue() - size() - 4;
++            ((Integer) indirectionTCMap.get(key)).intValue() - pos - 4;
++
++        write_long( negative_offset );
++    }
++
++
++    private final void writeIndirectionMarker(final org.omg.CORBA.TypeCode value,
++                                              final Map recursiveTCMap,
++                                              boolean typeCodeKey)
++        throws BadKind
++    {
++        final java.lang.Object key;
++
++        /* Sequence and array tcs will be stored under the actual TypeCode as they
++         * do not have IDs.
++         */
++        if (typeCodeKey)
++        {
++            key = value;
++        }
++        else
++        {
++            key = value.id();
++        }
++
++        write_long( -1 ); // recursion marker
++        int negative_offset = ((Integer) recursiveTCMap.get(key)).intValue() - pos - 4;
+ 
+         write_long( negative_offset );
+     }
+ 
+-    private final void write_TypeCode
+-       (final org.omg.CORBA.TypeCode value, Map tcMap)
++    private final void write_TypeCode(final org.omg.CORBA.TypeCode typeCode,
++                                      final Map recursiveTCMap,
++                                      final Map repeatedTCMap)
+     {
+-        if (value == null)
++        if (typeCode == null)
+         {
+             throw new BAD_PARAM("TypeCode is null");
+         }
+ 
+-        int _kind = value.kind().value();
+-        int _mc; // member count
++        int _kind = -1;
++        final int _memberCount;
+ 
+         try
+         {
+-            if( TypeCode.isRecursive(value) &&
+-                tcMap != null &&
+-                tcMap.containsKey( value.id()) )
++            if(TypeCode.isRecursive(typeCode) && recursiveTCMap.containsKey( typeCode.id()) )
+             {
+-                writeRecursiveTypeCode( value, tcMap );
++                writeIndirectionMarker( typeCode.id(), recursiveTCMap );
+             }
+             else
+             {
++                _kind = typeCode.kind().value();
+                 // regular TypeCodes
+                 switch( _kind )
+                 {
+-                    case 0:
+-                    case 1:
+-                    case 2:
+-                    case 3:
+-                    case 4:
+-                    case 5:
+-                    case 6:
+-                    case 7:
+-                    case 8:
+-                    case 9:
+-                    case 10:
+-                    case 11:
+-                    case 12:
+-                    case 13:
+-                    case 23:
+-                    case 24:
+-                    case 25:
+-                    case 26:
+-                    write_long( _kind  );
+-                    break;
+-                    case TCKind._tk_objref:
+-                    write_long( _kind  );
+-                    beginEncapsulation();
+-                    write_string( value.id() );
+-                    write_string( value.name() );
+-                    endEncapsulation();
+-                    break;
+-                    case TCKind._tk_struct:
+-                    case TCKind._tk_except:
+-                    if (useIndirection && tcMap != null &&
+-                        tcMap.containsKey (value.id()))
++                    case 0:  //_tk_null
++                    case 1:  //_tk_void
++                    case 2:  //_tk_short
++                    case 3:  //_tk_long
++                    case 4:  //_tk_ushort
++                    case 5:  //_tk_ulong
++                    case 6:  //_tk_float
++                    case 7:  //_tk_double
++                    case 8:  //_tk_boolean
++                    case 9:  //_tk_char
++                    case 10: //_tk_octet
++                    case 11: //_tk_any
++                    case 12: //_tk_TypeCode
++                    case 13: //_tk_Principal
+                     {
+-                        writeRecursiveTypeCode( value, tcMap );
++                        write_long( _kind  );
++                        break;
+                     }
+-                    else
++                    case TCKind._tk_objref: // 14
+                     {
+-                        write_long( _kind  );
+-                        if (tcMap == null)
++                        if (useIndirection && repeatedTCMap.containsKey(typeCode))
+                         {
+-                            tcMap = new HashMap();
++                            writeIndirectionMarker(typeCode, repeatedTCMap);
+                         }
+-                        tcMap.put( value.id(), new Integer( pos ) );
+-                        getRecursiveTCMap().put( value.id(), value );
+-
+-                        beginEncapsulation();
+-                        write_string(value.id());
+-                        write_string(value.name());
+-                        _mc = value.member_count();
+-                        write_long(_mc);
+-                        for( int i = 0; i < _mc; i++)
++                        else
+                         {
+-                            write_string( value.member_name(i) );
+-                            write_TypeCode( value.member_type(i), tcMap );
++                            write_long( _kind  );
++
++                            // remember tc start pos before we start writing it
++                            // out
++                            Integer tcStartPos = ObjectUtil.newInteger(pos);
++                            recursiveTCMap.put(typeCode.id(), tcStartPos);
++
++                            beginEncapsulation();
++                            write_string( typeCode.id() );
++                            write_string( typeCode.name() );
++                            endEncapsulation();
++
++                            //add typecode to cache not until here to account for
++                            //recursive TCs
++                            repeatedTCMap.put(typeCode, tcStartPos);
+                         }
+-                        endEncapsulation();
+-                    }
+-                    break;
+-                    case TCKind._tk_enum:
+-                    if (useIndirection && tcMap != null &&
+-                        tcMap.containsKey (value.id()))
+-                    {
+-                        writeRecursiveTypeCode( value, tcMap );
++                        break;
+                     }
+-                    else
++                    case TCKind._tk_struct: // 15
+                     {
+-                        write_long( _kind  );
+-                        if (tcMap == null)
++                        if (useIndirection && repeatedTCMap.containsKey(typeCode))
+                         {
+-                            tcMap = new HashMap();
++                            writeIndirectionMarker(typeCode, repeatedTCMap);
+                         }
+-                        tcMap.put( value.id(), new Integer( pos ) );
+-                        getRecursiveTCMap().put( value.id(), value );
+-
+-                        beginEncapsulation();
+-                        write_string( value.id());
+-                        write_string( value.name());
+-                        _mc = value.member_count();
+-                        write_long(_mc);
+-                        for( int i = 0; i < _mc; i++)
++                        else
+                         {
+-                            write_string( value.member_name(i) );
++                            write_long( _kind  );
++
++                            final Integer tcStartPos = ObjectUtil.newInteger( pos );
++                            recursiveTCMap.put( typeCode.id(), tcStartPos );
++
++                            beginEncapsulation();
++                            write_string(typeCode.id());
++                            write_string(typeCode.name());
++                            _memberCount = typeCode.member_count();
++                            write_long(_memberCount);
++                            for( int i = 0; i < _memberCount; i++)
++                            {
++                                write_string( typeCode.member_name(i) );
++                                write_TypeCode( typeCode.member_type(i), recursiveTCMap, repeatedTCMap );
++                            }
++                            endEncapsulation();
++
++                            // add typecode to cache not until here to account for
++                            // recursive TCs
++                            repeatedTCMap.put(typeCode, tcStartPos);
+                         }
+-                        endEncapsulation();
++                        break;
+                     }
+-                    break;
+-                    case TCKind._tk_union:
+-                    if (useIndirection && tcMap != null &&
+-                        tcMap.containsKey (value.id()))
++                    case TCKind._tk_union: // 16
+                     {
+-                        writeRecursiveTypeCode( value, tcMap );
++                        if (useIndirection && repeatedTCMap.containsKey(typeCode))
++                        {
++                            writeIndirectionMarker(typeCode, repeatedTCMap);
++                        }
++                        else
++                        {
++                            write_long( _kind  );
++                            // remember tc start pos before we start writing it
++                            // out
++                            final Integer tcStartPos = ObjectUtil.newInteger( pos );
++                            recursiveTCMap.put( typeCode.id(), tcStartPos );
++
++                            beginEncapsulation();
++                            write_string( typeCode.id() );
++                            write_string( typeCode.name() );
++
++                            write_TypeCode(typeCode.discriminator_type(),
++                                    recursiveTCMap,
++                                    repeatedTCMap);
++                            write_long( typeCode.default_index());
++                            _memberCount = typeCode.member_count();
++                            write_long(_memberCount);
++                            for( int i = 0; i < _memberCount; i++)
++                            {
++                                if( i == typeCode.default_index() )
++                                {
++                                    write_octet((byte)0);
++                                }
++                                else
++                                {
++                                    typeCode.member_label(i).write_value( this );
++                                }
++                                write_string( typeCode.member_name(i));
++                                write_TypeCode( typeCode.member_type(i), recursiveTCMap, repeatedTCMap );
++                            }
++                            endEncapsulation();
++
++                            // add typecode to cache not until here to account
++                            // for recursive TCs
++                            repeatedTCMap.put(typeCode, tcStartPos);
++                        }
++                        break;
+                     }
+-                    else
++                    case TCKind._tk_enum: // 17
+                     {
+-                        write_long( _kind  );
+-                        if (tcMap == null)
++                        if (useIndirection && repeatedTCMap.containsKey(typeCode))
+                         {
+-                            tcMap = new HashMap();
++                            writeIndirectionMarker(typeCode, repeatedTCMap);
+                         }
+-                        tcMap.put( value.id(), new Integer( pos ) );
+-                        getRecursiveTCMap().put( value.id() , value );
++                        else
++                        {
++                            write_long( _kind  );
+ 
+-                        beginEncapsulation();
+-                        write_string( value.id() );
+-                        write_string( value.name() );
++                            final Integer tcStartPos = ObjectUtil.newInteger( pos );
++                            recursiveTCMap.put( typeCode.id(), tcStartPos );
+ 
+-                        write_TypeCode( value.discriminator_type());
+-                        write_long( value.default_index());
+-                        _mc = value.member_count();
+-                        write_long(_mc);
+-                        for( int i = 0; i < _mc; i++)
+-                        {
+-                            if( i == value.default_index() )
+-                            {
+-                                write_octet((byte)0);
+-                            }
+-                            else
++                            beginEncapsulation();
++                            write_string( typeCode.id());
++                            write_string( typeCode.name());
++                            _memberCount = typeCode.member_count();
++                            write_long(_memberCount);
++                            for( int i = 0; i < _memberCount; i++)
+                             {
+-                                value.member_label(i).write_value( this );
++                                write_string( typeCode.member_name(i) );
+                             }
+-                            write_string( value.member_name(i));
+-                            write_TypeCode( value.member_type(i), tcMap );
++                            endEncapsulation();
++
++                            repeatedTCMap.put(typeCode, tcStartPos);
+                         }
+-                        endEncapsulation();
+-                    }
+-                    break;
+-                    case TCKind._tk_wstring:
+-                    case TCKind._tk_string:
+-                    write_long( _kind  );
+-                    write_long(value.length());
+-                    break;
+-                    case TCKind._tk_fixed:
+-                    write_long( _kind  );
+-                    write_ushort( value.fixed_digits() );
+-                    write_short( value.fixed_scale() );
+-                    break;
+-                    case TCKind._tk_array:
+-                    case TCKind._tk_sequence:
+-                    write_long( _kind  );
+-                    beginEncapsulation();
+-                    write_TypeCode( value.content_type(), tcMap);
+-                    write_long(value.length());
+-                    endEncapsulation();
+-                    break;
+-                    case TCKind._tk_alias:
+-                    if (useIndirection && tcMap != null &&
+-                        tcMap.containsKey (value.id()))
+-                    {
+-                        writeRecursiveTypeCode( value, tcMap );
++                        break;
+                     }
+-                    else
++                    case TCKind._tk_string: // 18
+                     {
+                         write_long( _kind  );
+-                        if (tcMap == null)
++                        write_long(typeCode.length());
++                        break;
++                    }
++                    case TCKind._tk_sequence: // 19
++                        // fallthrough
++                    case TCKind._tk_array: // 20
++                    {
++                        // Sequence and array TypeCodes don't have an id
++                        // so we need to store using the actual TypeCode
++                        if (useIndirection && repeatedTCMap.containsKey(typeCode))
+                         {
+-                            tcMap = new HashMap();
++                            writeIndirectionMarker(typeCode, repeatedTCMap, true);
+                         }
+-                        tcMap.put( value.id(), new Integer( pos ) );
+-                        getRecursiveTCMap().put( value.id(), value );
++                        else
++                        {
++                            write_long( _kind  );
++
++                            // remember tc start pos before we start writing it
++                            // out
++                            Integer tcStartPos = ObjectUtil.newInteger(pos);
++                            recursiveTCMap.put(typeCode, tcStartPos);
++
++                            beginEncapsulation();
++                            write_TypeCode( typeCode.content_type(), recursiveTCMap, repeatedTCMap);
++                            write_long(typeCode.length());
++                            endEncapsulation();
+ 
+-                        beginEncapsulation();
+-                        write_string(value.id());
+-                        write_string(value.name());
+-                        write_TypeCode( value.content_type(), tcMap);
+-                        endEncapsulation();
++                            //add typecode to cache not until here to account
++                            //for recursive TCs
++                            repeatedTCMap.put(typeCode, tcStartPos);
++                        }
++                        break;
+                     }
+-                    break;
+-                    case TCKind._tk_value:
+-                    if (useIndirection && tcMap != null &&
+-                        tcMap.containsKey (value.id()))
++                    case TCKind._tk_alias: // 21
+                     {
+-                        writeRecursiveTypeCode( value, tcMap );
++                        if (useIndirection && repeatedTCMap.containsKey(typeCode))
++                        {
++                            writeIndirectionMarker(typeCode, repeatedTCMap);
++                        }
++                        else
++                        {
++                            write_long( _kind  );
++
++                            // remember tc start pos before we start writing it
++                            // out
++                            Integer tcStartPos = ObjectUtil.newInteger(pos);
++                            recursiveTCMap.put(typeCode, tcStartPos);
++
++                            beginEncapsulation();
++                            write_string(typeCode.id());
++                            write_string(typeCode.name());
++                            write_TypeCode( typeCode.content_type(), recursiveTCMap, repeatedTCMap);
++                            endEncapsulation();
++
++                            //add typecode to cache not until here to account
++                            //for recursive TCs
++                            repeatedTCMap.put(typeCode, tcStartPos);
++                        }
++                        break;
+                     }
+-                    else
++                    case TCKind._tk_except: // 22
+                     {
+-                        write_long( _kind  );
+-                        if (tcMap == null)
++                        if (useIndirection && repeatedTCMap.containsKey(typeCode))
+                         {
+-                            tcMap = new HashMap();
++                            writeIndirectionMarker(typeCode, repeatedTCMap);
+                         }
+-                        tcMap.put( value.id(), new Integer( pos ) );
+-                        getRecursiveTCMap().put( value.id(), value );
+-
+-                        beginEncapsulation();
+-                        write_string(value.id());
+-                        write_string(value.name());
+-                        write_short( value.type_modifier() );
+-                        org.omg.CORBA.TypeCode base = value.concrete_base_type();
+-                        if (base != null)
+-                            write_TypeCode(base, tcMap);
+                         else
+-                            write_long (TCKind._tk_null);
+-                        _mc = value.member_count();
+-                        write_long(_mc);
+-                        for( int i = 0; i < _mc; i++)
+                         {
+-                            write_string( value.member_name(i) );
+-                            write_TypeCode( value.member_type(i), tcMap );
+-                            write_short( value.member_visibility(i) );
++                            write_long( _kind  );
++
++                            // remember tc start pos before we start writing it
++                            // out
++                            Integer tcStartPos = ObjectUtil.newInteger(pos);
++                            recursiveTCMap.put(typeCode, tcStartPos);
++
++                            beginEncapsulation();
++                            write_string(typeCode.id());
++                            write_string(typeCode.name());
++                            _memberCount = typeCode.member_count();
++                            write_long(_memberCount);
++                            for( int i = 0; i < _memberCount; i++)
++                            {
++                                write_string( typeCode.member_name(i) );
++                                write_TypeCode( typeCode.member_type(i), recursiveTCMap, repeatedTCMap );
++                            }
++                            endEncapsulation();
++
++                            //add typecode to cache not until here to account
++                            //for recursive TCs
++                            repeatedTCMap.put(typeCode, tcStartPos);
+                         }
+-                        endEncapsulation();
++                        break;
+                     }
+-                    break;
+-                    case TCKind._tk_value_box:
+-                    if (useIndirection && tcMap != null &&
+-                        tcMap.containsKey (value.id()))
++                    case TCKind._tk_longlong: // 23
++                        // fallthrough
++                    case TCKind._tk_ulonglong: // 24
+                     {
+-                        writeRecursiveTypeCode( value, tcMap );
++                        write_long( _kind  );
++                        break;
+                     }
+-                    else
++                    case TCKind._tk_longdouble: // 25
+                     {
+-                        write_long( _kind  );
+-                        if (tcMap == null)
+-                        {
+-                            tcMap = new HashMap();
+-                        }
+-                        tcMap.put( value.id(), new Integer( pos ) );
+-                        getRecursiveTCMap().put( value.id(), value );
+-
+-                        beginEncapsulation();
+-                        write_string(value.id());
+-                        write_string(value.name());
+-                        write_TypeCode( value.content_type(), tcMap);
+-                        endEncapsulation();
++                        throw new MARSHAL("Cannot handle TypeCode with kind: " + _kind);
+                     }
+-                    break;
+-                    case TCKind._tk_abstract_interface:
+-                    if (useIndirection && tcMap != null &&
+-                        tcMap.containsKey (value.id()))
++                    case TCKind._tk_wchar: // 26
+                     {
+-                        writeRecursiveTypeCode( value, tcMap );
++                        write_long( _kind  );
++                        break;
+                     }
+-                    else
++                    case TCKind._tk_wstring: // 27
+                     {
+                         write_long( _kind  );
+-                        if (tcMap == null)
++                        write_long(typeCode.length());
++                        break;
++                    }
++                    case TCKind._tk_fixed: //28
++                    {
++                        write_long( _kind  );
++                        write_ushort( typeCode.fixed_digits() );
++                        write_short( typeCode.fixed_scale() );
++                        break;
++                    }
++                    case TCKind._tk_value: // 29
++                    {
++                        if (useIndirection &&
++                                repeatedTCMap.containsKey(typeCode))
++                        {
++                            writeIndirectionMarker(typeCode, repeatedTCMap);
++                        }
++                        else
++                        {
++                            write_long( _kind  );
++
++                            final Integer tcStartPos = ObjectUtil.newInteger( pos );
++                            recursiveTCMap.put( typeCode.id(), tcStartPos );
++
++                            beginEncapsulation();
++                            write_string(typeCode.id());
++                            write_string(typeCode.name());
++                            write_short( typeCode.type_modifier() );
++                            final org.omg.CORBA.TypeCode baseType = typeCode.concrete_base_type();
++                            if (baseType == null)
++                            {
++                                write_long (TCKind._tk_null);
++                            }
++                            else
++                            {
++                                write_TypeCode(baseType, recursiveTCMap, repeatedTCMap);
++                            }
++                            _memberCount = typeCode.member_count();
++                            write_long(_memberCount);
++                            for( int i = 0; i < _memberCount; i++)
++                            {
++                                write_string( typeCode.member_name(i) );
++                                write_TypeCode( typeCode.member_type(i), recursiveTCMap, repeatedTCMap );
++                                write_short( typeCode.member_visibility(i) );
++                            }
++                            endEncapsulation();
++
++                            // add typecode to cache not until here to account
++                            // for recursive TCs
++                            repeatedTCMap.put(typeCode, tcStartPos);
++                        }
++                        break;
++                    }
++                    case TCKind._tk_value_box: // 30
++                    {
++                        if (useIndirection && repeatedTCMap.containsKey(typeCode))
+                         {
+-                            tcMap = new HashMap();
++                            writeIndirectionMarker(typeCode, repeatedTCMap);
+                         }
+-                        tcMap.put( value.id(), new Integer( pos ) );
+-                        getRecursiveTCMap().put( value.id(), value );
++                        else
++                        {
++                            write_long( _kind  );
++                            final Integer tcStartPos = ObjectUtil.newInteger( pos );
++                            recursiveTCMap.put( typeCode.id(), tcStartPos );
+ 
+-                        beginEncapsulation();
+-                        write_string(value.id());
+-                        write_string(value.name());
+-                        endEncapsulation();
++                            beginEncapsulation();
++                            write_string(typeCode.id());
++                            write_string(typeCode.name());
++                            write_TypeCode( typeCode.content_type(), recursiveTCMap, repeatedTCMap);
++                            endEncapsulation();
++
++                            // add typecode to cache not until here to account
++                            // for recursive TCs
++                            repeatedTCMap.put(typeCode, tcStartPos);
++                        }
++                        break;
++                    }
++                    case TCKind._tk_native:
++                    {
++                        throw new MARSHAL("Cannot handle TypeCode with kind: " + _kind);
++                    }
++                    case TCKind._tk_abstract_interface:
++                    {
++                        if (useIndirection && repeatedTCMap.containsKey(typeCode))
++                        {
++                            writeIndirectionMarker(typeCode, repeatedTCMap);
++                        }
++                        else
++                        {
++                            write_long( _kind  );
++                            final Integer tcStartPos = ObjectUtil.newInteger( pos );
++                            recursiveTCMap.put( typeCode.id(), tcStartPos );
++
++                            beginEncapsulation();
++                            write_string(typeCode.id());
++                            write_string(typeCode.name());
++                            endEncapsulation();
++
++                            // add typecode to cache not until here to account
++                            // for recursive TCs
++                            repeatedTCMap.put(typeCode, tcStartPos);
++                        }
++                        break;
+                     }
+-                    break;
+                     default:
+-                    throw new MARSHAL ("Cannot handle TypeCode with kind: " + _kind);
++                    {
++                        throw new MARSHAL ("Cannot handle TypeCode with kind: " + _kind);
++                    }
+                 }
+             }
+         }
+@@ -1741,140 +2006,116 @@
+      * InputStream <code>in</code> and remarshals it to this CDROutputStream.
+      * Called from Any.
+      */
+-    public final void write_value ( final org.omg.CORBA.TypeCode tc,
+-                                    final org.omg.CORBA.portable.InputStream in )
++    public final void write_value ( final org.omg.CORBA.TypeCode typeCode,
++                                    final org.omg.CORBA.portable.InputStream input )
+     {
+-        if (tc == null)
++        if (typeCode == null)
+         {
+             throw new BAD_PARAM("TypeCode is null");
+         }
+ 
+-        int kind = tc.kind().value();
++        int kind = typeCode.kind().value();
+ 
+         try
+         {
+             switch (kind)
+             {
+-                case TCKind._tk_null:
+-                case TCKind._tk_void:
+-                break;
+-                case TCKind._tk_boolean:
+-                write_boolean( in.read_boolean());
+-                break;
+-                case TCKind._tk_char:
+-                write_char( in.read_char());
+-                break;
+-                case TCKind._tk_wchar:
+-                write_wchar( in.read_wchar());
+-                break;
+-                case TCKind._tk_octet:
+-                write_octet( in.read_octet());
+-                break;
+-                case TCKind._tk_short:
+-                write_short( in.read_short());
+-                break;
+-                case TCKind._tk_ushort:
+-                write_ushort(in.read_ushort());
+-                break;
+-                case TCKind._tk_long:
+-                write_long( in.read_long());
+-                break;
+-                case TCKind._tk_ulong:
+-                write_ulong( in.read_ulong());
+-                break;
+-                case TCKind._tk_float:
+-                write_float( in.read_float());
+-                break;
+-                case TCKind._tk_double:
+-                write_double(in.read_double());
+-                break;
+-                case TCKind._tk_longlong:
+-                write_longlong(in.read_longlong());
+-                break;
+-                case TCKind._tk_ulonglong:
+-                write_ulonglong( in.read_ulonglong());
+-                break;
+-                case TCKind._tk_any:
+-                write_any( in.read_any());
+-                break;
+-                case TCKind._tk_TypeCode:
+-                write_TypeCode(in.read_TypeCode());
+-                break;
+-                case TCKind._tk_Principal:
+-                throw new NO_IMPLEMENT ("Principal deprecated");
+-                case TCKind._tk_objref:
+-                write_Object( in.read_Object());
+-                break;
+-                case TCKind._tk_string:
+-                write_string( in.read_string());
+-                break;
+-                case TCKind._tk_wstring:
+-                write_wstring( in.read_wstring());
+-                break;
+-                case TCKind._tk_fixed:
+-                write_fixed (in.read_fixed());
+-                break;
+-                case TCKind._tk_array:
++                case TCKind._tk_null:   // 0
++                    // fallthrough
++                case TCKind._tk_void:       // 1
+                 {
+-                    int length = tc.length();
+-                    if( tc.content_type().kind().value() == TCKind._tk_octet )
+-                    {
+-                        check( length );
+-                        in.read_octet_array( buffer, pos, length);
+-                        index+= length;
+-                        pos += length;
+-                    }
+-                    else
+-                    {
+-                        for( int i = 0; i < length; i++ )
+-                            write_value( tc.content_type(), in );
+-                    }
+                     break;
+                 }
+-                case TCKind._tk_sequence:
++                case TCKind._tk_short:      // 2
+                 {
+-                    int len = in.read_long();
+-                    write_long(len);
+-
+-                    org.omg.CORBA.TypeCode content_tc = tc.content_type();
+-                    for( int i = 0; i < len; i++ )
+-                        write_value(  content_tc, in );
+-
++                    write_short( input.read_short());
++                    break;
++                }
++                case TCKind._tk_long:       // 3
++                {
++                    write_long( input.read_long());
++                    break;
++                }
++                case TCKind._tk_ushort:     // 4
++                {
++                    write_ushort(input.read_ushort());
++                    break;
++                }
++                case TCKind._tk_ulong:      // 5
++                {
++                    write_ulong( input.read_ulong());
++                    break;
++                }
++                case TCKind._tk_float:      // 6
++                {
++                    write_float( input.read_float());
++                    break;
++                }
++                case TCKind._tk_double:     // 7
++                {
++                    write_double(input.read_double());
+                     break;
+                 }
+-                case TCKind._tk_except:
+-                write_string( in.read_string());
+-                // don't break, fall through to ...
+-                case TCKind._tk_struct:
++                case TCKind._tk_boolean:    // 8
+                 {
+-                    for( int i = 0; i < tc.member_count(); i++)
+-                        write_value( tc.member_type(i), in );
++                    write_boolean( input.read_boolean());
+                     break;
+                 }
+-                case TCKind._tk_enum:
++                case TCKind._tk_char:       // 9
+                 {
+-                    write_long( in.read_long() );
++                    write_char( input.read_char());
+                     break;
+                 }
+-                case TCKind._tk_union:
++                case TCKind._tk_octet:      // 10
+                 {
+-                    org.omg.CORBA.TypeCode disc =
+-                        (org.omg.CORBA.TypeCode) tc.discriminator_type();
++                    write_octet( input.read_octet());
++                    break;
++                }
++                case TCKind._tk_any:        // 11
++                {
++                    write_any( input.read_any());
++                    break;
++                }
++                case TCKind._tk_TypeCode:   // 12
++                {
++                    write_TypeCode(input.read_TypeCode());
++                    break;
++                }
++                case TCKind._tk_Principal:  // 13
++                {
++                    throw new NO_IMPLEMENT ("Principal deprecated");
++                }
++                case TCKind._tk_objref:     // 14
++                {
++                    write_Object( input.read_Object());
++                    break;
++                }
++                case TCKind._tk_struct:     // 15
++                {
++                    for( int i = 0; i < typeCode.member_count(); i++)
++                    {
++                        write_value( typeCode.member_type(i), input );
++                    }
++                    break;
++                }
++                case TCKind._tk_union:      // 16
++                {
++                    org.omg.CORBA.TypeCode disc = typeCode.discriminator_type();
+                     disc = TypeCode.originalType(disc);
+-                    int def_idx = tc.default_index();
++                    int def_idx = typeCode.default_index();
+                     int member_idx = -1;
+ 
+                     switch( disc.kind().value() )
+                     {
+-                        case TCKind._tk_short:
++                        case TCKind._tk_short:      // 2
+                         {
+-                            short s = in.read_short();
++                            short s = input.read_short();
+                             write_short(s);
+-                            for(int i = 0 ; i < tc.member_count() ; i++)
++                            for(int i = 0 ; i < typeCode.member_count() ; i++)
+                             {
+                                 if(i != def_idx)
+                                 {
+-                                    if(s == tc.member_label(i).extract_short())
++                                    if(s == typeCode.member_label(i).extract_short())
+                                     {
+                                         member_idx = i;
+                                         break;
+@@ -1883,15 +2124,15 @@
+                             }
+                             break;
+                         }
+-                        case TCKind._tk_ushort:
++                        case TCKind._tk_long:       // 3
+                         {
+-                            short s = in.read_ushort();
+-                            write_ushort(s);
+-                            for(int i = 0 ; i < tc.member_count() ; i++)
++                            int s = input.read_long();
++                            write_long(s);
++                            for(int i = 0 ; i < typeCode.member_count() ; i++)
+                             {
+                                 if(i != def_idx)
+                                 {
+-                                    if(s == tc.member_label(i).extract_ushort())
++                                    if(s == typeCode.member_label(i).extract_long())
+                                     {
+                                         member_idx = i;
+                                         break;
+@@ -1900,15 +2141,15 @@
+                             }
+                             break;
+                         }
+-                        case TCKind._tk_long:
++                        case TCKind._tk_ushort:     // 4
+                         {
+-                            int s = in.read_long();
+-                            write_long(s);
+-                            for(int i = 0 ; i < tc.member_count() ; i++)
++                            short s = input.read_ushort();
++                            write_ushort(s);
++                            for(int i = 0 ; i < typeCode.member_count() ; i++)
+                             {
+                                 if(i != def_idx)
+                                 {
+-                                    if(s == tc.member_label(i).extract_long())
++                                    if(s == typeCode.member_label(i).extract_ushort())
+                                     {
+                                         member_idx = i;
+                                         break;
+@@ -1917,15 +2158,15 @@
+                             }
+                             break;
+                         }
+-                        case TCKind._tk_ulong:
++                        case TCKind._tk_ulong:      // 5
+                         {
+-                            int s = in.read_ulong();
++                            int s = input.read_ulong();
+                             write_ulong(s);
+-                            for(int i = 0 ; i < tc.member_count() ; i++)
++                            for(int i = 0 ; i < typeCode.member_count() ; i++)
+                             {
+                                 if(i != def_idx)
+                                 {
+-                                    if(s == tc.member_label(i).extract_ulong())
++                                    if(s == typeCode.member_label(i).extract_ulong())
+                                     {
+                                         member_idx = i;
+                                         break;
+@@ -1934,15 +2175,22 @@
+                             }
+                             break;
+                         }
+-                        case TCKind._tk_longlong:
++                        case TCKind._tk_float:      // 6
++                            // fallthrough
++                        case TCKind._tk_double:     // 7
+                         {
+-                            long s = in.read_longlong();
+-                            write_longlong(s);
+-                            for(int i = 0 ; i < tc.member_count() ; i++)
++                            throw new MARSHAL(
++                                "Invalid union discriminator type: " + disc);
++                        }
++                        case TCKind._tk_boolean:    // 8
++                        {
++                            boolean s = input.read_boolean();
++                            write_boolean(s);
++                            for(int i = 0 ; i < typeCode.member_count() ; i++)
+                             {
+                                 if(i != def_idx)
+                                 {
+-                                    if(s == tc.member_label(i).extract_longlong())
++                                    if(s == typeCode.member_label(i).extract_boolean())
+                                     {
+                                         member_idx = i;
+                                         break;
+@@ -1951,15 +2199,15 @@
+                             }
+                             break;
+                         }
+-                        case TCKind._tk_ulonglong:
++                        case TCKind._tk_char:       // 9
+                         {
+-                            long s = in.read_ulonglong();
+-                            write_ulonglong(s);
+-                            for(int i = 0 ; i < tc.member_count() ; i++)
++                            char s = input.read_char();
++                            write_char(s);
++                            for(int i = 0 ; i < typeCode.member_count() ; i++)
+                             {
+                                 if(i != def_idx)
+                                 {
+-                                    if(s == tc.member_label(i).extract_ulonglong())
++                                    if(s == typeCode.member_label(i).extract_char())
+                                     {
+                                         member_idx = i;
+                                         break;
+@@ -1968,15 +2216,32 @@
+                             }
+                             break;
+                         }
+-                        case TCKind._tk_boolean:
++                        case TCKind._tk_octet:      // 10
++                        case TCKind._tk_any:        // 11
++                        case TCKind._tk_TypeCode:   // 12
++                        case TCKind._tk_Principal:  // 13
++                        case TCKind._tk_objref:     // 14
++                        case TCKind._tk_struct:     // 15
++                        case TCKind._tk_union:      // 16
+                         {
+-                            boolean s = in.read_boolean();
+-                            write_boolean(s);
+-                            for(int i = 0 ; i < tc.member_count() ; i++)
++                            throw new MARSHAL(
++                                "Invalid union discriminator type: " + disc);
++                        }
++                        case TCKind._tk_enum:       // 17
++                        {
++                            int s = input.read_long();
++                            write_long(s);
++                            for( int i = 0 ; i < typeCode.member_count(); i++ )
+                             {
+-                                if(i != def_idx)
++                                if( i != def_idx)
+                                 {
+-                                    if(s == tc.member_label(i).extract_boolean())
++                                    int label =
++                                    typeCode.member_label(i).create_input_stream().read_long();
++                                    /*  we  have to  use  the any's  input
++                                        stream   because   enums  are   not
++                                        inserted as longs */
++
++                                    if( s == label)
+                                     {
+                                         member_idx = i;
+                                         break;
+@@ -1985,21 +2250,24 @@
+                             }
+                             break;
+                         }
+-                        case TCKind._tk_enum:
++                        case TCKind._tk_string:     // 18
++                        case TCKind._tk_sequence:   // 19
++                        case TCKind._tk_array:      // 20
++                        case TCKind._tk_alias:      // 21
++                        case TCKind._tk_except:     // 22
+                         {
+-                            int s = in.read_long();
+-                            write_long(s);
+-                            for( int i = 0 ; i < tc.member_count(); i++ )
++                            throw new MARSHAL(
++                                "Invalid union discriminator type: " + disc);
++                        }
++                        case TCKind._tk_longlong:   // 23
++                        {
++                            long s = input.read_longlong();
++                            write_longlong(s);
++                            for(int i = 0 ; i < typeCode.member_count() ; i++)
+                             {
+-                                if( i != def_idx)
++                                if(i != def_idx)
+                                 {
+-                                    int label =
+-                                    tc.member_label(i).create_input_stream().read_long();
+-                                    /*  we  have to  use  the any's  input
+-                                        stream   because   enums  are   not
+-                                        inserted as longs */
+-
+-                                    if( s == label)
++                                    if(s == typeCode.member_label(i).extract_longlong())
+                                     {
+                                         member_idx = i;
+                                         break;
+@@ -2008,15 +2276,15 @@
+                             }
+                             break;
+                         }
+-                        case TCKind._tk_char:
++                        case TCKind._tk_ulonglong:  // 24
+                         {
+-                            char s = in.read_char();
+-                            write_char(s);
+-                            for(int i = 0 ; i < tc.member_count() ; i++)
++                            long s = input.read_ulonglong();
++                            write_ulonglong(s);
++                            for(int i = 0 ; i < typeCode.member_count() ; i++)
+                             {
+                                 if(i != def_idx)
+                                 {
+-                                    if(s == tc.member_label(i).extract_char())
++                                    if(s == typeCode.member_label(i).extract_ulonglong())
+                                     {
+                                         member_idx = i;
+                                         break;
+@@ -2026,7 +2294,9 @@
+                             break;
+                         }
+                         default:
+-                        throw new MARSHAL("Invalid union discriminator type: " + disc);
++                        {
++                            throw new MARSHAL("Invalid union discriminator type: " + disc);
++                        }
+                     }
+ 
+                     // write the member or default value, if any
+@@ -2038,45 +2308,124 @@
+ 
+                     if( member_idx != -1 )
+                     {
+-                        write_value( tc.member_type( member_idx ), in );
++                        write_value( typeCode.member_type( member_idx ), input );
+                     }
+                     else if( def_idx != -1 )
+                     {
+-                        write_value( tc.member_type( def_idx ), in );
++                        write_value( typeCode.member_type( def_idx ), input );
++                    }
++                    break;
++                }
++                case TCKind._tk_enum:       // 17
++                {
++                    write_long( input.read_long() );
++                    break;
++                }
++                case TCKind._tk_string:     // 18
++                {
++                    write_string( input.read_string());
++                    break;
++                }
++                case TCKind._tk_sequence:   // 19
++                {
++                    int len = input.read_long();
++                    write_long(len);
++
++                    org.omg.CORBA.TypeCode content_tc = typeCode.content_type();
++                    for( int i = 0; i < len; i++ )
++                    {
++                        write_value(content_tc, input);
+                     }
++
+                     break;
+                 }
+-                case TCKind._tk_alias:
++                case TCKind._tk_array:      // 20
+                 {
+-                    write_value( tc.content_type(), in );
++                    int length = typeCode.length();
++                    if( typeCode.content_type().kind().value() == TCKind._tk_octet )
++                    {
++                        check( length );
++                        input.read_octet_array( buffer, pos, length);
++                        index+= length;
++                        pos += length;
++                    }
++                    else
++                    {
++                        for( int i = 0; i < length; i++ )
++                        {
++                            write_value( typeCode.content_type(), input );
++                        }
++                    }
++                    break;
++                }
++                case TCKind._tk_alias:      // 21
++                {
++                    write_value( typeCode.content_type(), input );
++                    break;
++                }
++                case TCKind._tk_except:     // 22
++                {
++                    write_string( input.read_string());
++                    for (int i = 0; i < typeCode.member_count(); i++)
++                    {
++                        write_value(typeCode.member_type(i), input);
++                    }
++                    break;
++                }
++                case TCKind._tk_longlong:   // 23
++                {
++                    write_longlong(input.read_longlong());
++                    break;
++                }
++                case TCKind._tk_ulonglong:  // 24
++                {
++                    write_ulonglong( input.read_ulonglong());
++                    break;
++                }
++                case TCKind._tk_longdouble: // 25
++                {
++                    throw new org.omg.CORBA.BAD_TYPECODE(
++                        "type longdouble not supported in java");
++                }
++                case TCKind._tk_wchar:      // 26
++                {
++                    write_wchar( input.read_wchar());
++                    break;
++                }
++                case TCKind._tk_wstring:    // 27
++                {
++                    write_wstring( input.read_wstring());
++                    break;
++                }
++                case TCKind._tk_fixed:      // 28
++                {
++                    write_fixed (input.read_fixed());
++                    break;
++                }
++                case TCKind._tk_value:      // 29
++                {
++                    final Serializable val = ((org.omg.CORBA_2_3.portable.InputStream)input).read_value();
++                    write_value(val, typeCode.id());
+                     break;
+                 }
+                 case TCKind._tk_value_box:
+                 {
+-                    String id = tc.id();
++                    String id = typeCode.id();
+                     org.omg.CORBA.portable.BoxedValueHelper helper =
+                         ((org.jacorb.orb.ORB)orb()).getBoxedValueHelper(id);
+                     if (helper == null)
+-                        throw new RuntimeException
+-                            ("No BoxedValueHelper for id " + id);
++                    {
++                        throw new MARSHAL("No BoxedValueHelper for id " + id);
++                    }
+                     java.io.Serializable value =
+-                        ((org.omg.CORBA_2_3.portable.InputStream)in).read_value(helper);
++                        ((org.omg.CORBA_2_3.portable.InputStream)input).read_value(helper);
+                     write_value (value, helper);
+                     break;
+                 }
+-                case 0xffffffff:
++                default:
+                 {
+-                    org.omg.CORBA.TypeCode _tc =
+-                        (org.omg.CORBA.TypeCode)( getRecursiveTCMap().get( tc.id() ) );
+-                    if( _tc == null )
+-                    {
+-                        throw new MARSHAL("Recursive TypeCode not found for " + tc.id());
+-                    }
+-                    write_value( _tc , in );
+-                    break;
++                    throw new MARSHAL("Cannot handle TypeCode with kind " + kind);
+                 }
+-                default:
+-                throw new MARSHAL("Cannot handle TypeCode with kind " + kind);
+             }
+         }
+         catch (BadKind ex)
+@@ -2098,21 +2447,25 @@
+     public void write_value(final java.io.Serializable value)
+     {
+         if (!write_special_value (value))
++        {
+             write_value_internal (value,
+                                   ValueHandler.getRMIRepositoryID (value.getClass()));
++        }
+     }
+ 
+     public void write_value(final java.io.Serializable value,
+-                             final org.omg.CORBA.portable.BoxedValueHelper factory)
++                            final org.omg.CORBA.portable.BoxedValueHelper factory)
+     {
+         if (!write_special_value (value))
+         {
+-            check(7,4);
+-            getValueMap().put (value, new Integer(pos));
+             write_previous_chunk_size();
++            check(7,4);
++            getValueMap().put (value, ObjectUtil.newInteger(pos));
+             if ((value instanceof org.omg.CORBA.portable.IDLEntity) ||
+                 (value instanceof java.lang.String))
++            {
+                 write_long (0x7fffff00 | chunkingFlag);
++            }
+             else
+             {
+                 // repository id is required for RMI: types
+@@ -2126,19 +2479,25 @@
+     }
+ 
+     public void write_value(final java.io.Serializable value,
+-                             final java.lang.Class clz)
++                            final java.lang.Class clazz)
+     {
+         if (!write_special_value (value))
+         {
+-            Class c = value.getClass();
+-            String repId = ValueHandler.getRMIRepositoryID(c);
+-            if (c == clz && !repId.startsWith("RMI:"))
++            final Class _clazz = value.getClass();
++            final String repId = ValueHandler.getRMIRepositoryID(_clazz);
++            if (_clazz == clazz && !repId.startsWith("RMI:"))
++            {
+                 // the repository id is required for "RMI:" valuetypes
+                 write_value_internal (value, null);
+-            else if (clz.isInstance (value))
++            }
++            else if (clazz.isInstance (value))
++            {
+                 write_value_internal (value, repId);
++            }
+             else
++            {
+                 throw new BAD_PARAM();
++            }
+         }
+     }
+ 
+@@ -2146,7 +2505,9 @@
+                              final String repository_id)
+     {
+         if (!write_special_value (value))
++        {
+             write_value_internal (value, repository_id);
++        }
+     }
+ 
+     /**
+@@ -2162,20 +2523,16 @@
+             write_long (0x00000000);
+             return true;
+         }
+-        else
+-        {
+-            Integer index = (Integer)getValueMap().get (value);
+-            if (index != null)
+-            {
+ 
+-                // value has already been written -- make an indirection
+-                write_long (0xffffffff);
+-                write_long (index.intValue() - size());
+-                return true;
+-            }
+-            else
+-                return false;
++        Integer index = (Integer)getValueMap().get (value);
++        if (index != null)
++        {
++            // value has already been written -- make an indirection
++            write_long (0xffffffff);
++            write_long (index.intValue() - size());
++            return true;
+         }
++        return false;
+     }
+ 
+     /**
+@@ -2197,7 +2554,7 @@
+                 pos += remainder;
+             }
+ 
+-            getRepIdMap().put (repository_id, new Integer(pos));
++            getRepIdMap().put (repository_id, ObjectUtil.newInteger(pos));
+             write_string (repository_id);
+         }
+         else
+@@ -2235,7 +2592,7 @@
+                 pos += remainder;
+             }
+ 
+-            getCodebaseMap().put (codebase, new Integer(pos));
++            getCodebaseMap().put (codebase, ObjectUtil.newInteger(pos));
+             write_string (codebase);
+         }
+         else
+@@ -2252,7 +2609,6 @@
+      */
+     private void write_value_header(final String[] repository_ids)
+     {
+-        write_previous_chunk_size();
+         if (repository_ids != null)
+         {
+             if( repository_ids.length > 1 )
+@@ -2274,20 +2630,19 @@
+             }
+         }
+         else
++        {
+             write_long (0x7fffff00 | chunkingFlag);
++        }
+     }
+ 
+     /**
+      * Writes to this stream a value header with the specified `repository_id'.
+      * and `codebase' string.
+      */
+-
+-    private void write_value_header
+-       (final String[] repository_ids, final String codebase)
++    private void write_value_header(final String[] repository_ids, final String codebase)
+     {
+         if (codebase != null)
+         {
+-            write_previous_chunk_size();
+             if ( repository_ids != null )
+             {
+                 if( repository_ids.length > 1 )
+@@ -2318,7 +2673,9 @@
+             }
+         }
+         else
++        {
+             write_value_header (repository_ids);
++        }
+     }
+ 
+     /**
+@@ -2333,8 +2690,9 @@
+     private void write_value_internal(final java.io.Serializable value,
+                                        final String repository_id)
+     {
++    	write_previous_chunk_size();
+         check(7,4);
+-        getValueMap().put(value, new Integer(pos));
++        getValueMap().put(value, ObjectUtil.newInteger(pos));
+ 
+         if (value.getClass() == String.class)
+         {
+@@ -2379,24 +2737,24 @@
+         {
+             String[] repository_ids =
+                 (repository_id == null) ? null : new String[]{ repository_id };
+-            Class cls = value.getClass();
+-            String codebase = ValueHandler.getCodebase(cls);
++            Class clazz = value.getClass();
++            String codebase = ValueHandler.getCodebase(clazz);
+             if (value instanceof org.omg.CORBA.portable.IDLEntity)
+             {
+                 java.lang.reflect.Method writeMethod = null;
+-                if (cls != org.omg.CORBA.Any.class)
++                if (clazz != org.omg.CORBA.Any.class)
+                 {
+-                    String helperClassName = cls.getName() + "Helper";
++                    String helperClassName = clazz.getName() + "Helper";
+ 
+                     try
+                     {
+                         Class helperClass =
+-                            (cls.getClassLoader() != null)
+-                                ? cls.getClassLoader().loadClass(helperClassName)
++                            (clazz.getClassLoader() != null)
++                                ? clazz.getClassLoader().loadClass(helperClassName)
+                                 : ObjectUtil.classForName(helperClassName);
+ 
+                         Class[] paramTypes =
+-                            { org.omg.CORBA.portable.OutputStream.class, cls };
++                            { org.omg.CORBA.portable.OutputStream.class, clazz };
+                         writeMethod = helperClass.getMethod("write", paramTypes);
+                     }
+                     catch (ClassNotFoundException e)
+@@ -2441,40 +2799,50 @@
+                 {
+                     writeValueNestingLevel++;
+                     if (chunkCustomRmiValuetypes
+-                        && ValueHandler.isCustomMarshaled(cls))
++                        && ValueHandler.isCustomMarshaled(clazz))
++                    {
+                         chunkingFlag = 0x00000008;
+-                    write_value_header( repository_ids, codebase );
+-                    start_chunk();
++                    }
++
++                    Serializable newValue = value;
+                     if (!writeReplaceCalled)
+                     {
+                         // writeReplace must be called only once for this value
+-                        java.io.Serializable newValue =
+-                            ValueHandler.writeReplace(value);
++                        newValue = ValueHandler.writeReplace(value);
+                         writeReplaceCalled = true; // won't call it again
++                    }
++
++                    if (newValue != value)
++                    {
++                        // recompute codebase and/or repositoryID as might have changed
++                        String new_rep_id =
++                            ValueHandler.getRMIRepositoryID(newValue.getClass());
++                        repository_ids =
++                            (new_rep_id == null) ? null : new String []{new_rep_id};
++                        clazz = newValue.getClass();
++                        codebase = ValueHandler.getCodebase(clazz);
++                    }
+ 
+-                        if (newValue != value)
++                    write_value_header( repository_ids, codebase );
++                    start_chunk();
++
++                    if (newValue != value)
++                    {
++                        // look at the new value
++                        Integer index = (Integer)getValueMap().get(newValue);
++                        if (index != null)
+                         {
+-                            // look at the new value
+-                            Integer index = (Integer)getValueMap().get(newValue);
+-                            if (index != null)
+-                            {
+-                                // previously marshaled value -- make an indirection
+-                                write_long (0xffffffff);
+-                                write_long (index.intValue() - size());
+-                            }
+-                            else if (value instanceof org.omg.CORBA.Object)
+-                            {
+-                                write_Object((org.omg.CORBA.Object)newValue);
+-                            }
+-                            else
+-                            {
+-                                ValueHandler.writeValue(this, newValue);
+-                            }
++                            // previously marshaled value -- make an indirection
++                            write_long (0xffffffff);
++                            write_long (index.intValue() - size());
++                        }
++                        else if (newValue instanceof org.omg.CORBA.Object)
++                        {
++                            write_Object((org.omg.CORBA.Object)newValue);
+                         }
+                         else
+                         {
+-                            // writeReplace did't make a difference
+-                            ValueHandler.writeValue(this, value);
++                            ValueHandler.writeValue(this, newValue);
+                         }
+                     }
+                     else
+@@ -2488,7 +2856,9 @@
+                 finally
+                 {
+                     if (--writeValueNestingLevel == 0)
++                    {
+                         writeReplaceCalled = false;
++                    }
+                 }
+             }
+         }
+@@ -2533,9 +2903,9 @@
+      */
+     private void write_previous_chunk_size()
+     {
+-        if( chunk_size_tag_pos != -1 )
++        if (chunk_size_tag_pos != -1)
+         {
+-            if ( pos == chunk_octets_pos)
++            if (pos == chunk_octets_pos)
+             {
+                 // empty chunk: erase chunk size tag
+                 pos = chunk_size_tag_pos;      // the tag will be overwritten
+@@ -2544,19 +2914,9 @@
+             else
+             {
+                 // go to the beginning of the chunk and write the size tag
+-
+-                // check(7, 4); // DO NOT align to a 4-byte boundary
+-
+-                int current_pos = pos;
+-                int current_idx = index;
+-
+-                pos = chunk_size_tag_pos;
+-                index = chunk_size_tag_index;
+-                write_long( current_pos - chunk_octets_pos );
+-
+-                pos = current_pos;
+-                index = current_idx;
+-
++                rewrite_long(chunk_size_tag_pos,
++                             chunk_size_tag_index,
++                             pos - chunk_octets_pos);
+             }
+             chunk_size_tag_pos = -1; // no chunk is currently open
+         }
+@@ -2569,13 +2929,33 @@
+         chunk_size_tag_index = index;
+ 
+         // insert four bytes here as a place-holder
+-        write_long( 0 ); // need to go back later and write the actual size
++        write_long(0); // need to go back later and write the actual size
+ 
+         // remember starting position of chunk data
+         chunk_octets_pos = pos;
+     }
+ 
+     /**
++     * Writes a CORBA long value to (write_pos, write_index) without clearing
++     * the buffer padding. In the case of a non-sequential write, clearing
++     * buffer positions after the data just written is likely to erase data
++     * previously written.
++     */
++    private final void rewrite_long(int write_pos,
++                                    int write_index,
++                                    final int value)
++    {
++        final int align = 4;
++        int remainder = align - (write_index % align);
++        if (remainder != align)
++        {
++            write_index += remainder;
++            write_pos += remainder;
++        }
++        _write4int(buffer, write_pos, value);
++    }
++
++    /**
+      * Writes an abstract interface to this stream. The abstract interface is
+      * written as a union with a boolean discriminator, which is true if the
+      * union contains a CORBA object reference, or false if the union contains
+@@ -2594,4 +2974,5 @@
+             write_value((java.io.Serializable)object);
+         }
+     }
++
+ }
+Index: src/org/jacorb/orb/Delegate.java
+===================================================================
+RCS file: /cvsroot/jacorb/JacORB/src/org/jacorb/orb/Delegate.java,v
+retrieving revision 1.121
+diff -u -r1.121 Delegate.java
+--- src/org/jacorb/orb/Delegate.java	22 May 2006 15:03:50 -0000	1.121
++++ src/org/jacorb/orb/Delegate.java	5 May 2007 00:36:08 -0000
+@@ -1515,13 +1515,7 @@
+                                          replyEndTime,
+                                          p.get_object_key(), p.getEffectiveProfile().version().minor );
+ 
+-            try{
+-            // TODO
+-                ros.configure(configuration);
+-            } catch (ConfigurationException e)
+-            {
+-                throw new RuntimeException();
+-            }
++            ros.configure(configuration);
+ 
+             // CodeSets are only negotiated once per connection,
+             // not for each individual request
+Index: src/org/jacorb/orb/dsi/ServerRequest.java
+===================================================================
+RCS file: /cvsroot/jacorb/JacORB/src/org/jacorb/orb/dsi/ServerRequest.java,v
+retrieving revision 1.39
+diff -u -r1.39 ServerRequest.java
+--- src/org/jacorb/orb/dsi/ServerRequest.java	19 May 2006 20:14:50 -0000	1.39
++++ src/org/jacorb/orb/dsi/ServerRequest.java	5 May 2007 00:36:08 -0000
+@@ -431,13 +431,8 @@
+                                   in.isLocateRequest(),
+                                   logger );
+ 
+-        try
+-        {
+-            out.configure(orb.getConfiguration());
+-        } catch (ConfigurationException e)
+-        {
+-            throw new RuntimeException();
+-        }
++        out.configure(orb.getConfiguration());
++
+         return out;
+     }
+ 
+Index: src/org/jacorb/orb/giop/GIOPConnection.java
+===================================================================
+RCS file: /cvsroot/jacorb/JacORB/src/org/jacorb/orb/giop/GIOPConnection.java,v
+retrieving revision 1.52
+diff -u -r1.52 GIOPConnection.java
+--- src/org/jacorb/orb/giop/GIOPConnection.java	9 Jan 2006 16:32:54 -0000	1.52
++++ src/org/jacorb/orb/giop/GIOPConnection.java	5 May 2007 00:36:08 -0000
+@@ -43,7 +43,7 @@
+  * Created: Sun Aug 12 21:30:48 2002
+  *
+  * @author Nicolas Noffke
+- * @version $Id: GIOPConnection.java,v 1.52 2006/01/09 16:32:54 andre.spiegel Exp $
++ * @version $Id: GIOPConnection.java,v 1.52.2.1 2006/07/07 09:03:23 andre.spiegel Exp $
+  */
+ 
+ public abstract class GIOPConnection
+@@ -377,16 +377,20 @@
+         }
+         else
+         {
+-            if (logger.isErrorEnabled())
++            if (logger.isDebugEnabled())
+             {
+-                logger.error( "Failed to read GIOP message, incorrect magic number" );
++                logger.debug("GIOPConnection.getMessage(): invalid header read: " + msg_header.value );
+             }
+ 
+-            if (logger.isDebugEnabled())
++            if (logger.isErrorEnabled())
+             {
+-                logger.debug("GIOPConnection.getMessage()" + msg_header.value );
++                logger.error( "Failed to read GIOP message, incorrect magic number --> connection closed" );
+             }
+-
++            //close transport connection, there is nearly no chance to sync with
++            //peer on this connection again
++            close();
++            //signal GIOPConnectionManager to throw this connection away
++            this.streamClosed();
+             return null;
+         }
+     }
+Index: src/org/jacorb/orb/giop/LocateRequestInputStream.java
+===================================================================
+RCS file: /cvsroot/jacorb/JacORB/src/org/jacorb/orb/giop/LocateRequestInputStream.java,v
+retrieving revision 1.16
+diff -u -r1.16 LocateRequestInputStream.java
+--- src/org/jacorb/orb/giop/LocateRequestInputStream.java	6 May 2004 12:40:00 -0000	1.16
++++ src/org/jacorb/orb/giop/LocateRequestInputStream.java	5 May 2007 00:36:08 -0000
+@@ -89,10 +89,6 @@
+         {
+             close();
+         }
+-        catch( java.io.IOException iox )
+-        {
+-            //ignore
+-        }
+         finally
+         {
+             super.finalize();
+Index: src/org/jacorb/orb/giop/ReplyInputStream.java
+===================================================================
+RCS file: /cvsroot/jacorb/JacORB/src/org/jacorb/orb/giop/ReplyInputStream.java,v
+retrieving revision 1.22
+diff -u -r1.22 ReplyInputStream.java
+--- src/org/jacorb/orb/giop/ReplyInputStream.java	18 Nov 2004 23:27:20 -0000	1.22
++++ src/org/jacorb/orb/giop/ReplyInputStream.java	5 May 2007 00:36:08 -0000
+@@ -173,10 +173,6 @@
+         {
+             close();
+         }
+-        catch( java.io.IOException iox )
+-        {
+-            //ignore
+-        }
+         finally
+         {
+             super.finalize();
+Index: src/org/jacorb/orb/giop/RequestInputStream.java
+===================================================================
+RCS file: /cvsroot/jacorb/JacORB/src/org/jacorb/orb/giop/RequestInputStream.java,v
+retrieving revision 1.18
+diff -u -r1.18 RequestInputStream.java
+--- src/org/jacorb/orb/giop/RequestInputStream.java	6 May 2004 12:40:00 -0000	1.18
++++ src/org/jacorb/orb/giop/RequestInputStream.java	5 May 2007 00:36:08 -0000
+@@ -178,10 +178,6 @@
+         {
+             close();
+         }
+-        catch( java.io.IOException iox )
+-        {
+-            //ignore
+-        }
+         finally
+         {
+             super.finalize();
+Index: src/org/jacorb/util/ObjectUtil.java
+===================================================================
+RCS file: /cvsroot/jacorb/JacORB/src/org/jacorb/util/ObjectUtil.java,v
+retrieving revision 1.17
+diff -u -r1.17 ObjectUtil.java
+--- src/org/jacorb/util/ObjectUtil.java	21 Oct 2005 21:06:25 -0000	1.17
++++ src/org/jacorb/util/ObjectUtil.java	5 May 2007 00:36:09 -0000
+@@ -20,19 +20,27 @@
+  *   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+  */
+ 
+-import java.util.*;
++import java.io.BufferedReader;
++import java.io.IOException;
++import java.net.MalformedURLException;
++import java.net.URL;
+ 
+ /**
+  * @author Gerald Brose, FU Berlin
+- * @version $Id: ObjectUtil.java,v 1.17 2005/10/21 21:06:25 alphonse.bendt Exp $
++ * @version $Id: ObjectUtil.java,v 1.21 2006/11/30 13:11:07 alphonse.bendt Exp $
+  */
+ 
+ public class ObjectUtil
+ {
+-    private static Class identityHashMapClass = null;
+     //for byte -> hexchar
+     private static final char[] lookup =
+         new char[]{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
++
++    private ObjectUtil()
++    {
++        // utility class
++    }
++
+     /**
+      * @return the contents of the resource as a string, or null
+      * if the contents of the resource could not be located using url
+@@ -40,31 +48,42 @@
+     public static final String readURL( String url )
+         throws java.io.IOException
+     {
++        final BufferedReader reader = new BufferedReader(newInputStreamReader(url));
++
++        try
++        {
++            return reader.readLine();
++        }
++        finally
++        {
++            reader.close();
++        }
++    }
++
++    private static java.io.InputStreamReader newInputStreamReader(String url) throws MalformedURLException, IOException
++    {
+         String token = "file://";
+-        String line = "";
+         java.io.InputStreamReader isr = null;
+-        if (url.startsWith (token))
++        if (url.startsWith(token))
++        {
+             try
+             {
+-                isr = new java.io.FileReader (url.substring(token.length()));
++                isr = new java.io.FileReader(url.substring(token.length()));
+             }
+             catch (Exception e)
+             {
+-                System.out.println ("Tried and failed to open file: " +
++                System.out.println ("Tried and failed to open file: " + // NOPMD
+                                     url.substring(token.length()));
+                 // no worries, let the URL handle it
+             }
++        }
++
+         if (isr == null)
+         {
+-            java.net.URL u = new java.net.URL(url);
+-            isr = new java.io.InputStreamReader(u.openStream());
++            java.net.URL urlCopy = new java.net.URL(url);
++            isr = new java.io.InputStreamReader(urlCopy.openStream());
+         }
+-
+-        java.io.BufferedReader in = new java.io.BufferedReader(isr);
+-        line = in.readLine();
+-
+-        in.close();
+-        return line;
++        return isr;
+     }
+ 
+     /**
+@@ -115,7 +134,10 @@
+         throws ClassNotFoundException, IllegalArgumentException
+     {
+         if (name == null)
++        {
+             throw new IllegalArgumentException("Class name must not be null!");
++        }
++
+         try
+         {
+             // Here we prefer classLoader.loadClass() over the three-argument
+@@ -134,45 +156,7 @@
+         }
+     }
+ 
+-    /**
+-     * Creates an IdentityHashMap, using either the JDK 1.4 class or
+-     * JacORB's drop-in replacement class if the former is not available.
+-     *
+-     * @return a newly created IdentityHashMap instance
+-     */
+-    public static Map createIdentityHashMap()
+-    {
+-        if (identityHashMapClass == null)
+-        {
+-            try
+-            {
+-                identityHashMapClass =
+-                    ObjectUtil.classForName("java.util.IdentityHashMap");
+-            }
+-            catch (ClassNotFoundException ex)
+-            {
+-                try
+-                {
+-                    identityHashMapClass =
+-                        ObjectUtil.classForName("org.jacorb.util.IdentityHashMap");
+-                }
+-                catch (ClassNotFoundException e)
+-                {
+-                    throw new RuntimeException(e.toString());
+-                }
+-            }
+-        }
+-        try
+-        {
+-            return (Map)identityHashMapClass.newInstance();
+-        }
+-        catch (Exception exc)
+-        {
+-            throw new RuntimeException(exc.toString());
+-        }
+-    }
+-
+-    public static String bufToString( byte bs[],
++    public static String bufToString( byte values[],
+             int start,
+             int len)
+     {
+@@ -184,12 +168,12 @@
+             if ((i % 16 ) == 0)
+             {
+                 result.append( chars.toString() );
+-                result.append( "\n" ); 
++                result.append( '\n' );
+                 chars.setLength(0);
+             }
+ 
+-            chars.append( toAscii( bs[i] ));
+-            result.append(  toHex( bs[i] ));
++            chars.append( toAscii( values[i] ));
++            result.append(  toHex( values[i] ));
+ 
+             if ( (i % 4) == 3 )
+             {
+@@ -215,7 +199,7 @@
+             {
+                 pad += 1;
+             }
+-            
++
+             for ( int i = 0; i < pad; i++ )
+             {
+                 chars.insert( 0, ' ' );
+@@ -230,33 +214,33 @@
+     /**
+      * <code>toHex</code> converts a byte into a readable string.
+      *
+-     * @param b a <code>byte</code> value
++     * @param value a <code>byte</code> value
+      * @return a <code>String</code> value
+      */
+ 
+-    public static final String toHex(byte b)
++    public static final String toHex(byte value)
+     {
+-        StringBuffer sb = new StringBuffer();
++        final StringBuffer buffer = new StringBuffer();
+ 
+-        int upper = (b >> 4) & 0x0F;
+-        sb.append( lookup[upper] );
++        int upper = (value >> 4) & 0x0F;
++        buffer.append( lookup[upper] );
+ 
+-        int lower = b & 0x0F;
+-        sb.append( lookup[lower] );
++        int lower = value & 0x0F;
++        buffer.append( lookup[lower] );
+ 
+-        sb.append( ' ' );
++        buffer.append( ' ' );
+ 
+-        return sb.toString();
++        return buffer.toString();
+     }
+ 
+ 
+-    public static final char toAscii(byte b)
++    public static final char toAscii(byte value)
+     {
+-        if ( b > (byte) 31 &&  b < (byte) 127)
++        if ( value > (byte) 31 &&  value < (byte) 127)
+         {
+-            return (char) b;
++            return (char) value;
+         }
+-        
++
+         return '.';
+     }
+ 
+@@ -276,13 +260,33 @@
+             {
+                 int idx = args[i].indexOf('=');
+                 if (idx < 3 )
++                {
+                     continue;
++                }
+                 String key = args[i].substring(2,idx);
+ 
+-                System.out.println("putting: " + key + "," + args[i].substring(idx+1));
+                 props.put(key, args[i].substring(idx+1));
+             }
+         }
+         return props;
++    }
++
++    public static URL getResource(String name)
++    {
++        if (Thread.currentThread().getContextClassLoader() != null)
++        {
++            return Thread.currentThread().getContextClassLoader().getResource(name);
++        }
++        return ObjectUtil.class.getResource(name);
++    }
++
++    /**
++     * factory method to create Integers from ints.
++     * should be used throughout the code to prepare
++     * transition to JDK 1.5 (Integer.valueOf(int))
++     */
++    public static Integer newInteger(int value)
++    {
++        return new Integer(value); // NOPMD
+     }
+ }
+Index: src/org/jacorb/util/Version.java
+===================================================================
+RCS file: /cvsroot/jacorb/JacORB/src/org/jacorb/util/Version.java,v
+retrieving revision 1.29
+diff -u -r1.29 Version.java
+--- src/org/jacorb/util/Version.java	10 Dec 2005 15:56:10 -0000	1.29
++++ src/org/jacorb/util/Version.java	5 May 2007 00:36:09 -0000
+@@ -28,7 +28,7 @@
+  */
+ public final class Version
+ {
+-    public static final String version = "2.2.3";
+-    public static final String date = "10-Dec-2005";
++    public static final String version = "2.2.4 (JBoss patch 2)";
++    public static final String date = "04-May-2007";
+     public static final String longVersion = version + ", " + date;
+ }

Added: jacorb/2.2.4jboss.patch2/component-info.xml
===================================================================
--- jacorb/2.2.4jboss.patch2/component-info.xml	                        (rev 0)
+++ jacorb/2.2.4jboss.patch2/component-info.xml	2007-05-05 00:54:58 UTC (rev 379)
@@ -0,0 +1,33 @@
+<project name="jacorb-component-info">
+
+   <component id="jacorb"
+      licenseType="lgpl"
+      version="2.2.4jboss.patch2"
+      projectHome="http://www.jacorb.org"
+      description="Java implementation of the OMG's CORBA standard.">
+
+      <!-- Built using JDK 1.4 -->
+      <artifact id="idl.jar"/>
+      <artifact id="idl_g.jar"/>
+      <artifact id="jacorb.jar"/>
+      <artifact id="jacorb_g.jar"/>
+      <artifact id="orb.idl"/>
+      <artifact id="CSI.idl"/>
+      <artifact id="CosTransactions.idl"/>
+      <artifact id="jacorb.properties"/>
+      <import componentref="apache-avalon">
+         <compatible version="4.1.5"/>
+         <compatible version="4.1.5-brew"/>
+      </import>
+      <import componentref="apache-avalon-logkit">
+         <compatible version="1.2"/>
+         <compatible version="1.2-brew"/>
+      </import>
+      <export>
+         <include input="jacorb.jar"/>
+         <include input="jacorb_g.jar"/>         
+         <include input="idl.jar"/>
+      </export>
+   </component>
+
+</project>

Added: jacorb/2.2.4jboss.patch2/lib/idl.jar
===================================================================
(Binary files differ)


Property changes on: jacorb/2.2.4jboss.patch2/lib/idl.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: jacorb/2.2.4jboss.patch2/lib/idl_g.jar
===================================================================
(Binary files differ)


Property changes on: jacorb/2.2.4jboss.patch2/lib/idl_g.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: jacorb/2.2.4jboss.patch2/lib/jacorb.jar
===================================================================
(Binary files differ)


Property changes on: jacorb/2.2.4jboss.patch2/lib/jacorb.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: jacorb/2.2.4jboss.patch2/lib/jacorb_g.jar
===================================================================
(Binary files differ)


Property changes on: jacorb/2.2.4jboss.patch2/lib/jacorb_g.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: jacorb/2.2.4jboss.patch2/resources/CSI.idl
===================================================================
--- jacorb/2.2.4jboss.patch2/resources/CSI.idl	                        (rev 0)
+++ jacorb/2.2.4jboss.patch2/resources/CSI.idl	2007-05-05 00:54:58 UTC (rev 379)
@@ -0,0 +1,202 @@
+#ifndef _CSI_IDL_
+#define _CSI_IDL_
+
+#pragma prefix "omg.org"
+
+module CSI {
+
+    // The OMG VMCID; same value as CORBA::OMGVMCID. Do not change ever.
+
+    const unsigned long OMGVMCID = 0x4F4D0;
+
+    // An X509CertificateChain contains an ASN.1 BER encoded SEQUENCE 
+    // [1..MAX] OF X.509 certificates encapsulated in a sequence of octets. The
+    // subject's certificate shall come first in the list. Each following 
+    // certificate shall directly certify the one preceding it. The ASN.1
+    // representation of Certificate is as defined in [IETF RFC 2459].
+
+    typedef sequence <octet> X509CertificateChain; 
+
+    // an X.501 type name or Distinguished Name encapsulated in a sequence of
+    // octets containing the ASN.1 encoding.
+
+    typedef sequence <octet> X501DistinguishedName;
+
+    // UTF-8 Encoding of String
+
+    typedef sequence <octet> UTF8String;
+
+    // ASN.1 Encoding of an OBJECT IDENTIFIER
+
+    typedef sequence <octet> OID;
+
+    typedef sequence <OID> OIDList;
+
+    // A sequence of octets containing a GSStoken. Initial context tokens are
+    // ASN.1 encoded as defined in [IETF RFC 2743] Section 3.1, 
+    // "Mechanism-Independent token Format", pp. 81-82. Initial context tokens
+    // contain an ASN.1 tag followed by a token length, a mechanism identifier,
+    // and a mechanism-specific token (i.e. a GSSUP::InitialContextToken). The
+    // encoding of all other GSS tokens (e.g. error tokens and final context
+    // tokens) is mechanism dependent.
+
+    typedef sequence <octet> GSSToken;
+
+    // An encoding of a GSS Mechanism-Independent Exported Name Object as
+    // defined in [IETF RFC 2743] Section 3.2, "GSS Mechanism-Independent
+    // Exported Name Object Format," p. 84.
+
+    typedef sequence <octet> GSS_NT_ExportedName;
+
+    typedef sequence <GSS_NT_ExportedName> GSS_NT_ExportedNameList;
+
+    // The MsgType enumeration defines the complete set of service context
+    // message types used by the CSI context management protocols, including
+    // those message types pertaining only to the stateful application of the 
+    // protocols (to insure proper alignment of the identifiers between
+    // stateless and stateful implementations). Specifically, the 
+    // MTMessageInContext is not sent by stateless clients (although it may
+    // be received by stateless targets).
+
+    typedef short MsgType;
+      
+    const MsgType MTEstablishContext = 0;
+    const MsgType MTCompleteEstablishContext = 1;      
+    const MsgType MTContextError = 4; 
+    const MsgType MTMessageInContext = 5;
+
+    // The ContextId type is used carry session identifiers. A stateless 
+    // application of the service context protocol is indicated by a session
+    // identifier value of 0.
+
+    typedef unsigned long long ContextId;
+
+    // The AuthorizationElementType defines the contents and encoding of
+    // the_element field of the AuthorizationElement.
+
+    // The high order 20-bits of each AuthorizationElementType constant
+    // shall contain the Vendor Minor Codeset ID (VMCID) of the
+    // organization that defined the element type. The low order 12 bits
+    // shall contain the organization-scoped element type identifier. The
+    // high-order 20 bits of all element types defined by the OMG shall
+    // contain the VMCID allocated to the OMG (that is, 0x4F4D0).
+      
+    typedef unsigned long AuthorizationElementType;
+
+    // An AuthorizationElementType of X509AttributeCertChain indicates that 
+    // the_element field of the AuthorizationElement contains an ASN.1 BER
+    // SEQUENCE composed of an (X.509) AttributeCertificate followed by a
+    // SEQUENCE OF (X.509) Certificate. The two-part SEQUENCE is encapsulated
+    // in an octet stream. The chain of identity certificates is provided
+    // to certify the attribute certificate. Each certificate in the chain 
+    // shall directly certify the one preceding it. The first certificate
+    // in the chain shall certify the attribute certificate. The ASN.1
+    // representation of (X.509) Certificate is as defined in [IETF RFC 2459].
+    // The ASN.1 representation of (X.509) AtributeCertificate is as defined
+    // in [IETF ID PKIXAC].  
+
+    const AuthorizationElementType X509AttributeCertChain = OMGVMCID | 1;
+
+    typedef sequence <octet> AuthorizationElementContents;
+
+    // The AuthorizationElement contains one element of an authorization token.
+    // Each element of an authorization token is logically a PAC.
+
+    struct AuthorizationElement {
+	AuthorizationElementType   the_type;
+	AuthorizationElementContents   the_element;
+    };
+
+    // The AuthorizationToken is made up of a sequence of 
+    // AuthorizationElements
+
+    typedef sequence <AuthorizationElement> AuthorizationToken;
+      
+    typedef unsigned long IdentityTokenType;
+
+    // Additional standard identity token types shall only be defined by the
+    // OMG. All IdentityTokenType constants shall be a power of 2.
+
+    const IdentityTokenType ITTAbsent = 0;      
+    const IdentityTokenType ITTAnonymous = 1;
+    const IdentityTokenType ITTPrincipalName = 2;
+    const IdentityTokenType ITTX509CertChain = 4;
+    const IdentityTokenType ITTDistinguishedName = 8;
+
+    typedef sequence <octet> IdentityExtension;
+      
+    union IdentityToken switch ( IdentityTokenType ) {
+	case ITTAbsent: boolean absent;
+	case ITTAnonymous: boolean anonymous;
+        case ITTPrincipalName: GSS_NT_ExportedName principal_name;
+	case ITTX509CertChain: X509CertificateChain certificate_chain;
+	case ITTDistinguishedName: X501DistinguishedName dn;
+	default: IdentityExtension id;
+    };
+
+    struct EstablishContext {
+	ContextId client_context_id;
+	AuthorizationToken authorization_token;
+	IdentityToken identity_token;
+	GSSToken client_authentication_token;
+    };
+      
+    struct CompleteEstablishContext {
+	ContextId client_context_id;
+	boolean context_stateful;
+	GSSToken final_context_token;
+    };
+
+    struct ContextError {
+	ContextId client_context_id;
+	long major_status;
+	long minor_status;
+	GSSToken error_token;
+    };
+
+    // Not sent by stateless clients. If received by a stateless server, a
+    // ContextError message should be returned, indicating the session does
+    // not exist.
+      
+    struct MessageInContext {
+	ContextId client_context_id;
+	boolean discard_context;
+    };
+      
+    union SASContextBody switch ( MsgType ) {
+	case MTEstablishContext: EstablishContext establish_msg;
+	case MTCompleteEstablishContext: CompleteEstablishContext complete_msg;
+	case MTContextError: ContextError error_msg;
+	case MTMessageInContext: MessageInContext in_context_msg;
+    };
+
+    // The following type represents the string representation of an ASN.1
+    // OBJECT IDENTIFIER (OID). OIDs are represented by the string "oid:"
+    // followed by the integer base 10 representation of the OID separated
+    // by dots. For example, the OID corresponding to the OMG is represented
+    // as: "oid:2.23.130"     
+
+    typedef string StringOID;
+
+    // The GSS Object Identifier for the KRB5 mechanism is:
+    // { iso(1) member-body(2) United States(840) mit(113554) infosys(1)
+    // gssapi(2) krb5(2) }
+
+    const StringOID KRB5MechOID = "oid:1.2.840.113554.1.2.2";
+
+    // The GSS Object Identifier for name objects of the Mechanism-idependent
+    // Exported Name Object type is:
+    // { iso(1) org(3) dod(6) internet(1) security(5) nametypes(6)
+    // gss-api-exported-name(4) }
+
+    const StringOID GSS_NT_Export_Name_OID = "oid:1.3.6.1.5.6.4";
+
+    // The GSS Object Identifier for the scoped-username name form is:
+    // { iso-itu-t (2) international-organization (23) omg (130) security (1)
+    // naming (2) scoped-username(1) }
+
+    const StringOID GSS_NT_Scoped_Username_OID = "oid:2.23.130.1.2.1";
+
+}; // CSI
+
+#endif

Added: jacorb/2.2.4jboss.patch2/resources/CosTransactions.idl
===================================================================
--- jacorb/2.2.4jboss.patch2/resources/CosTransactions.idl	                        (rev 0)
+++ jacorb/2.2.4jboss.patch2/resources/CosTransactions.idl	2007-05-05 00:54:58 UTC (rev 379)
@@ -0,0 +1,206 @@
+//File: CosTransactions.idl
+//Part of the Transaction Service
+
+#ifndef _COS_TRANSACTIONS_IDL_
+#define _COS_TRANSACTIONS_IDL_
+
+#include <orb.idl>
+
+#pragma prefix "omg.org"
+
+module CosTransactions {
+
+	// Forward references for interfaces defined later in module
+	interface Current;
+	interface TransactionFactory;
+	interface Control;
+	interface Terminator;
+	interface Coordinator;
+	interface RecoveryCoordinator;
+	interface Resource;
+	interface Synchronization;
+	interface SubtransactionAwareResource;
+	interface TransactionalObject; 
+
+	// DATATYPES 
+	enum Status {
+		StatusActive,
+		StatusMarkedRollback,
+		StatusPrepared,
+		StatusCommitted,
+		StatusRolledBack,
+		StatusUnknown,
+		StatusNoTransaction,
+		StatusPreparing,
+		StatusCommitting,
+		StatusRollingBack
+	};
+
+	enum Vote {
+		VoteCommit,
+		VoteRollback,
+		VoteReadOnly
+	};
+
+	// Structure definitions
+	struct otid_t {
+		long formatID; /*format identifier. 0 is OSI TP */
+		long bqual_length;
+		sequence <octet> tid;
+	};
+	struct TransIdentity {
+		Coordinator coord;
+		Terminator term;
+		otid_t otid;
+	};
+	struct PropagationContext {
+		unsigned long timeout;
+		TransIdentity current;
+		sequence <TransIdentity> parents;
+		any implementation_specific_data;
+	};
+
+	// Heuristic exceptions
+	exception HeuristicRollback {};
+	exception HeuristicCommit {};
+	exception HeuristicMixed {};
+	exception HeuristicHazard {};
+
+	// Other transaction-specific exceptions
+	exception SubtransactionsUnavailable {};
+	exception NotSubtransaction {};
+	exception Inactive {};
+	exception NotPrepared {};
+	exception NoTransaction {};
+	exception InvalidControl {};
+	exception Unavailable {};
+	exception SynchronizationUnavailable {};
+	
+	// Current transaction 
+	interface Current : CORBA::Current {
+		void begin()
+			raises(SubtransactionsUnavailable);
+		void commit(in boolean report_heuristics)
+			raises(
+				NoTransaction,
+				HeuristicMixed,
+				HeuristicHazard
+			);
+		void rollback()
+			raises(NoTransaction);
+		void rollback_only()
+			raises(NoTransaction);
+
+		Status get_status();
+		string get_transaction_name();
+		void set_timeout(in unsigned long seconds);
+		Control get_control();
+		Control suspend();
+		void resume(in Control which)
+			raises(InvalidControl);
+	};
+
+
+	interface TransactionFactory {
+		Control create(in unsigned long time_out);
+		Control recreate(in PropagationContext ctx);
+	};
+
+	interface Control {
+		Terminator get_terminator()
+			raises(Unavailable);
+		Coordinator get_coordinator()
+			raises(Unavailable);
+	};
+
+	interface Terminator {
+		void commit(in boolean report_heuristics)
+			raises(
+				HeuristicMixed,
+				HeuristicHazard
+			);
+		void rollback();
+	};
+
+	interface Coordinator {
+
+		Status get_status();
+		Status get_parent_status();
+		Status get_top_level_status();
+
+		boolean is_same_transaction(in Coordinator tc);
+		boolean is_related_transaction(in Coordinator tc);
+		boolean is_ancestor_transaction(in Coordinator tc);
+		boolean is_descendant_transaction(in Coordinator tc);
+		boolean is_top_level_transaction();
+
+		unsigned long hash_transaction();
+		unsigned long hash_top_level_tran();
+
+		RecoveryCoordinator register_resource(in Resource r)
+			raises(Inactive);
+
+		void register_synchronization (in Synchronization sync)
+			raises(Inactive, SynchronizationUnavailable);
+
+		void register_subtran_aware(in SubtransactionAwareResource r)
+			raises(Inactive, NotSubtransaction);
+
+		void rollback_only()
+			raises(Inactive);
+
+		string get_transaction_name();
+		Control create_subtransaction()
+			raises(SubtransactionsUnavailable, Inactive);
+
+		PropagationContext get_txcontext ()
+			raises(Unavailable);
+	};
+
+	interface RecoveryCoordinator {
+		Status replay_completion(in Resource r)
+			raises(NotPrepared);
+	};
+
+	interface Resource {
+		Vote prepare()
+			raises(
+				HeuristicMixed,
+				HeuristicHazard
+			);
+		void rollback()
+			raises(
+				HeuristicCommit,
+				HeuristicMixed,
+				HeuristicHazard
+			);
+		void commit()
+			raises(
+				NotPrepared,
+				HeuristicRollback,
+				HeuristicMixed,
+				HeuristicHazard
+			);
+		void commit_one_phase()
+			raises(
+				HeuristicHazard
+			);
+		void forget();
+	};
+
+	interface TransactionalObject {
+	};
+
+	interface Synchronization : TransactionalObject {
+		void before_completion();
+		void after_completion(in CosTransactions::Status status);
+	};
+
+	interface SubtransactionAwareResource : Resource {
+		void commit_subtransaction(in Coordinator parent);
+		void rollback_subtransaction();
+	};
+
+}; // End of CosTransactions Module
+
+#endif /* ifndef _COS_TRANSACTIONS_IDL_ */

Added: jacorb/2.2.4jboss.patch2/resources/jacorb.properties
===================================================================
--- jacorb/2.2.4jboss.patch2/resources/jacorb.properties	                        (rev 0)
+++ jacorb/2.2.4jboss.patch2/resources/jacorb.properties	2007-05-05 00:54:58 UTC (rev 379)
@@ -0,0 +1,429 @@
+##  $Id: jacorb.properties,v 1.1 2006/08/04 18:22:26 reverbel Exp $
+
+###############################################################################
+##                                                                           ##
+##               JacORB configuration for the JBoss server                   ##
+##                                                                           ##
+###############################################################################
+
+########################################
+#
+# options to control the configuration stage
+#
+########################################
+
+# where to look for ORB config files?
+#jacorb.config.dir=e:/JacORB_CONFIG_FEATURE
+
+# controls log output (to the console!) during the configuration stage.
+# This can help to find out which config files are actually loaded!
+#    0   : nothing is logged
+#    1,2 : only errors
+#    3,4 : info (which config files were loaded)
+jacorb.config.log.verbosity=0
+# If you set the property above to nonzero, the messages 
+#
+#     "jacorb.home unset! Will use '.'" 
+#
+# and 
+#
+#     "File ./jacorb.properties for configuration jacorb not found"
+#
+# will appear at the console when the JBoss server starts. These messages 
+# can be safely ignored.
+
+########################################
+#                                      #
+#   Initial references configuration   #
+#                                      #
+########################################
+
+ORBInitRef.NameService=corbaloc::localhost:3528/JBoss/Naming/root
+
+########################################
+#                                      #
+#      Export of corbaloc IORs         #
+#                                      #
+########################################
+
+# the object key mapping below permit clients of a name service to
+# access it using corbaloc::ipaddress:portnum/NameService
+jacorb.orb.objectKeyMap.NameService=JBoss/Naming/root
+
+##################################
+#                                #
+#   ORB version number output    #
+#                                #
+##################################
+
+# if on, the ORB's version number is printed whenever the ORB is initialized
+jacorb.orb.print_version=off
+
+##################################
+#                                #
+#   Debug output configuration   #
+#                                #
+##################################
+
+# Logging levels for the ORB instance that runs within the JBoss application 
+# server are not defined in this file anymore. Instead of specifiyng logging
+# levels here, you should use category elements in file log4j.xml to limit the
+# logging output of the various JacORB categories (jacorb, jacorb.orb, 
+# jacorb.orb.factory, jacorb.orb.interceptors, jacorb.orb.giop, jacorb.orb.iiop,
+# jacorb.giop.conn, jacorb.poa, jacorb.naming). Examples:
+#
+# <category name="jacorb">
+#    <priority value="WARN"/>
+# </category>
+#
+# <category name="jacorb.poa">
+#    <priority value="DEBUG"/>
+# </category>
+#
+# The above for is the server-side ORB only. At the client side, JacORB logging
+# levels should still be defined via *.log.verbosity properties, in a 
+# client-side orb.properties or <ORBid>.properties (e.g., jacorb.properties) 
+# file. 
+
+# hexdump outgoing messages
+jacorb.debug.dump_outgoing_messages=off
+
+# hexdump incoming messages
+jacorb.debug.dump_incoming_messages=off
+
+##################################################
+#                                                #
+#    WARNING: The following properties should    #
+#    only be edited by the expert user. They     #
+#    can be left untouched in most cases!        #
+#                                                #
+##################################################
+
+################################
+#                              #
+#   Basic ORB Configuration    #
+#                              #
+################################
+
+# the GIOP minor version number to use for newly created IORs
+jacorb.giop_minor_version=2
+
+# number of retries if connection cannot directly be established
+jacorb.retries=5
+
+# how many msecs. do we wait between retries
+jacorb.retry_interval=500
+
+# size of network buffers for outgoing messages
+jacorb.outbuf_size=2048
+
+# log2 of maximum buffer size managed by the internal
+# buffer manager.
+#
+# This is NOT the maximum buffer size that
+# can be used, but just the largest size of buffers that
+# will be kept and managed. This value will be added to
+# an internal constant of 5, so the real value in bytes
+# is 2**(5+maxManagedBufSize-1). You only need to increase this
+# value if you are dealing with LOTS of LARGE data structures.
+# You may decrease it to make the buffer manager release large
+# buffers immediately rather than keeping them for later
+# reuse.
+jacorb.maxManagedBufSize=24
+# If this value is 0 an extra unlimited size buffer cache is created
+# for the CDROutputStreams. If this value is > 0 then the cache will
+# be purged every x msecs.
+jacorb.bufferManagerMaxFlush=-1
+
+# Normally, a jacorb server will close the TCP/IP connection right
+# after sending a CloseConnection message. However, it may
+# occasionally happen that the client sends a message into the closed
+# connection because it hasn't handled the CloseConnection yet. To
+# avoid this situation, closing of the TCP/IP connection can be delayed.
+#jacorb.connection.delay_close=on
+#jacorb.connection.timeout_after_closeconnection=20000
+
+# Wait the specified number of msecs for a reply to a request. If
+# exceeded, a org.omg.CORBA.TIMEOUT exception will be thrown
+#jacorb.connection.client.pending_reply_timeout=0
+
+# Client-side connection idle timeout. Set to a non-zero value
+# to close an idle connection after so many msecs. Default is zero,
+# meaning a connection will be kept open indefinitely, or until
+# the OS decides to close it.
+#jacorb.connection.client.idle_timeout=0
+
+# Server-side connection idle timeout. Set to a non-zero value
+# to close an idle connection after so many msecs. Default is zero,
+# meaning a connection will be kept open indefinitely, or until
+# the OS decides to close it.
+#jacorb.connection.server.timeout=10000
+
+# Max no of accepted connections on the server.
+#jacorb.connection.max_server_connections=
+
+# Max number of connection threads.
+#jacorb.connection.max_threads=
+
+# The number of msecs that are waited until the next attempt to find
+# an idle connection is made (i.e. do not continuously spin)
+#jacorb.connection.wait_for_idle_interval=500
+
+# The class name of the SelectionStrategy class
+#jacorb.connection.selection_strategy_class=
+
+# The class name of the StatisticsProvider class
+#jacorb.connection.statistics_provider_class=
+
+#jacorb.reference_caching=off
+
+#
+# The following property specifies the class which is used for
+# reference caching. WeakHashtable uses WeakReferences, so entries
+# get gc'ed if only the Hashtable has a reference to them. This
+# is useful if you have many references to short-living non-persistent
+# CORBA objects. It is only available for java 1.2 and above.
+#
+# On the other hand the standard Hashtable keeps the references until
+# they are explicitely deleted by calling _release(). This is useful
+# for persistent and long-living CORBA objects.
+#
+#jacorb.hashtable_class=org.jacorb.util.WeakHashtable
+#
+jacorb.hashtable_class=java.util.Hashtable
+
+# use GIOP 1.2 byte order markers (since CORBA 2.4-5)
+jacorb.use_bom=off
+
+# add additional IIOP 1.0 profiles even if we are using IIOP 1.2
+jacorb.giop.add_1_0_profiles=off
+
+# Use DNS names in IORs
+jacorb.dns.enable=off
+
+# Compact Typecodes (0 - off, 1 - partial (not member_names), 2 - all)
+jacorb.compactTypecodes=0
+
+# Cache typecode on read
+jacorb.cacheTypecodes=off
+
+# Cache poa names
+jacorb.cachePoaNames=off
+
+###########################################
+#                                         #
+#         Interoperability                #
+#                                         #
+###########################################
+
+# Turn off indirection encoding for repeated typecodes. This fixes
+# interoperability with certain broken ORB's eg. Orbix2000
+jacorb.interop.indirection_encoding_disable=off
+
+# Iona Comet CORBA/COM bridge can incorrectly encode buffer lengths.
+# Enabling this property adds additional length checking and adjustment
+# for interoperability with Comet.
+jacorb.interop.comet=off
+
+# Some ORBs do not set a byte value of 1 as a CDR encoded boolean true
+# value. Enabling this property interprets any non zero CDR encoded
+# boolean value as true.
+jacorb.interop.lax_boolean_encoding=off
+
+# Control whether the method create_abstract_interface_tc performs
+# a validity check on the name parameter or not. Turning this check
+# off circumvents a bug in Sun's implementation of javax.rmi.CORBA.ValueHander,
+# which occasionally passes an invalid name (an empty string) to
+# ORBSingleton.create_abstract_interface_tc. If you are using RMI valuetypes,
+# you should turn this property off. JBoss uses RMI (and RMI valuetypes), so
+# you should NOT turned this property on!
+jacorb.interop.strict_check_on_tc_creation=off
+
+# Custom-marshalled RMI valuetypes should be encoded as chunks, but some
+# ORBs are not able to decode chunked values. Disable this property for
+# interoperability with the ORB in Sun's JDK 1.4.2.
+jacorb.interop.chunk_custom_rmi_valuetypes=on
+
+# RMI/IIOP data encoded as chunks should contain the length of the chunk. 
+# The ORB in Sun's JDK does not always send the length always. Enable this 
+# property for interoperability with the Sun ORB.
+jacorb.interop.sun=on
+
+###########################################
+#                                         #
+#         Socket Factories                #
+#                                         #
+###########################################
+
+# A factory design pattern is used for the creation of sockets and server
+# sockets.
+# The jacorb.net.socket_factory property can be used to configure
+# a socket factory that must implement the operations defined in the
+# interface org.jacorb.orb.factory.SocketFactory.
+# The jacorb.net.server_socket_factory property can be used to configure a
+# server socket factory that must implement the operations defined in the
+# interface org.jacorb.orb.factory.ServerSocketFactory.
+#
+#jacorb.net.socket_factory=org.jacorb.orb.factory.DefaultSocketFactory
+#jacorb.net.server_socket_factory=org.jacorb.orb.factory.DefaultServerSocketFactory
+#jacorb.net.socket_factory=org.jacorb.orb.factory.PortRangeSocketFactory
+#jacorb.net.server_socket_factory=org.jacorb.orb.factory.PortRangeServerSocketFactory
+#
+# Additional socket factores are supported that allow for the configuration
+# of maximum and minimum port numbers that can be used. This can be used to
+# enable firewall traversal via a fixed port range. To use these socket factories
+# configure one or both of the following property pairs. The first property pair
+# configures the client socket factory and the second pair the server socket
+# factory.
+#
+#jacorb.net.socket_factory.port.min
+#jacorb.net.socket_factory.port.max
+#jacorb.net.server_socket_factory.port.min
+#jacorb.net.server_socket_factory.port.max
+
+###########################################
+#                                         #
+#         BiDirectional GIOP              #
+#                                         #
+###########################################
+
+# uncomment this initializer if you want to use BiDirectional GIOP
+
+#org.omg.PortableInterceptor.ORBInitializerClass.bidir_init=org.jacorb.orb.connection.BiDirConnectionInitializer
+
+
+###########################################
+#                                         #
+#       Proxy address in IOR              #
+#                                         #
+###########################################
+
+#
+# with these two properties it is possible to
+# tell the ORB what IP/port IORs should contain,
+# if the ServerSockets IP/port can't be used
+# (e.g. for traffic through a firewall).
+#
+# WARNING: this is just "dumb" replacing, so you
+# have to take care of your configuration!
+#
+
+#jacorb.ior_proxy_host=1.2.3.4
+#jacorb.ior_proxy_port=4711
+
+
+###########################################
+#                                         #
+#   The Object Adapter Internet Address   #
+#                                         #
+###########################################
+
+# IP address on multi-homed host (this gets encoded in
+# object references). NOTE: Adresses like 127.0.0.X
+# will only be accessible from the same machine!
+#OAIAddr=127.0.0.1
+
+# This are the IIOP ports officially assigned to JBoss by IANA:
+OAPort=3528
+OASSLPort=3529
+
+############################
+#                          #
+#   Default Interceptors   #
+#   Please leave them in!  #
+#                          #
+############################
+org.omg.PortableInterceptor.ORBInitializerClass.standard_init=org.jacorb.orb.standardInterceptors.IORInterceptorInitializer
+
+###############################################
+#                                             #
+#   Implementation Repository Configuration   #
+#                                             #
+###############################################
+# Switch off to avoid contacting the ImR on every server start-up
+jacorb.use_imr=off
+
+# the implementation name, should be set to a different
+# name in the code of persistent servers
+jacorb.implname=JBoss
+
+#########################
+#                       #
+#   SSL Configuration   #
+#                       #
+#########################
+
+# This interceptor must be set if programs need access to
+# certificates using the CORBA Security API, SSL works also
+# without this interceptor
+
+#org.omg.PortableInterceptor.ORBInitializerClass.ForwardInit=org.jacorb.security.ssl.sun_jsse.SecurityServiceInitializer
+
+# qualified classname of access decision object
+#jacorb.security.access_decision=org.jacorb.security.level2.AccessDecisionImpl
+
+# list of qualified classnames of principal authenticator objects,
+# separated by commas (no whitespaces!). The first entry (that can
+# be successfully created) will be available through the
+# principal_authenticator property.
+# jacorb.security.principal_authenticator=org.jacorb.security.level2.PrincipalAuthenticatorImpl
+
+# the qualified classname of the ssl socket factory class
+jacorb.ssl.socket_factory=org.jboss.iiop.jacorb.SSLSocketFactory
+
+# the qualified classname of the ssl server socket factory class
+jacorb.ssl.server_socket_factory=org.jboss.iiop.jacorb.SSLServerSocketFactory
+
+# change to "on" to enable SSL
+jacorb.security.support_ssl=off
+
+# IIOP/SSL parameters (numbers are hex values, without the leading "0x"):
+# EstablishTrustInTarget = 20
+# EstablishTrustInClient = 40
+# mutual authentication = 60
+
+jacorb.security.ssl.client.supported_options=60
+jacorb.security.ssl.client.required_options=0
+
+jacorb.security.ssl.server.supported_options=60
+jacorb.security.ssl.server.required_options=0
+
+#org.omg.PortableInterceptor.ORBInitializerClass.ForwardInit=org.jacorb.security.ssl.sun_jsse.SecurityServiceInitializer
+
+# tell JacORB not to add SSL components to IORs (an IORinterceptor will do it)
+jacorb.security.ssl_components_added_by_ior_interceptor=on
+
+#########################
+#                       #
+#   POA Configuration   #
+#                       #
+#########################
+
+# displays a GUI monitoring tool for servers
+jacorb.poa.monitoring=off
+
+# thread pool configuration for request processing
+jacorb.poa.thread_pool_max=8
+jacorb.poa.thread_pool_min=2
+
+# if set, request processing threads in thePOA
+# will run at this priority. If not set or invalid,
+# MAX_PRIORITY will be used.
+#jacorb.poa.thread_priority=
+
+# Properties controlling the POA's request queue.  If queue_wait is off,
+# then if there are more than queue_max requests in the queue, the
+# client gets TRANSIENT exceptions for any requests.  If queue_wait is on,
+# then the call blocks at the server side until no more than queue_min
+# requests are left in the queue.  The new request is then delivered as usual.
+jacorb.poa.queue_wait=off
+jacorb.poa.queue_max=100
+jacorb.poa.queue_min=10
+
+##################################
+#                                #
+#   Logger Factory Configuration #
+#                                #
+##################################
+
+jacorb.log.loggerFactory=org.jboss.util.Log4jLoggerFactory

Added: jacorb/2.2.4jboss.patch2/resources/orb.idl
===================================================================
--- jacorb/2.2.4jboss.patch2/resources/orb.idl	                        (rev 0)
+++ jacorb/2.2.4jboss.patch2/resources/orb.idl	2007-05-05 00:54:58 UTC (rev 379)
@@ -0,0 +1,177 @@
+
+// Some definitions from the CORBA module as needed
+// by other modules. This file is for declaration
+// purposes only!!
+
+// $Id: orb.idl,v 1.1 2006/08/04 18:22:26 reverbel Exp $
+
+#ifndef _MYORB_IDL
+#define _MYORB_IDL
+
+/*
+  the following pragma is proprietary to JacORB. It ensures
+  that no code is ever generated when this file is included in
+  other files even when the -all compiler option is set
+ */
+
+#pragma inhibit_code_generation
+#pragma prefix "omg.org"
+
+
+module CORBA 
+{
+    typedef unsigned short ServiceOption;
+    typedef unsigned short ServiceDetailType;
+
+    // for PortableInterceptors
+    typedef sequence<string> StringSeq;
+    typedef sequence<wstring> WStringSeq;
+    typedef sequence<octet> OctetSeq;
+
+    typedef unsigned long PolicyType;
+	
+    // actually, Current is pseudo, but we need it this way so everything compiles
+    interface Current {}; 
+
+    pseudo interface Environment{};
+    pseudo interface NamedValue {};
+    pseudo interface NVList {};	
+
+    // not suitable for deriving user-defined interfaces !
+    enum TCKind { 
+	tk_null, tk_void, 
+	tk_short, tk_long, tk_ushort, tk_ulong, 
+	tk_float, tk_double, tk_boolean, tk_char, 
+	tk_octet, tk_any, tk_TypeCode, tk_Principal, tk_objref, 
+	tk_struct, tk_union, tk_enum, tk_string, 
+	tk_sequence, tk_array, tk_alias, tk_except, 
+	tk_longlong, tk_ulonglong, tk_longdouble,
+	tk_wchar, tk_wstring, tk_fixed, tk_value,
+	tk_value_box,
+	tk_native, tk_abstract_interface,
+        tk_local_interface // latest addition
+    };
+    
+    // not suitable for deriving user-defined interfaces
+    typedef string Identifier;
+    typedef string RepositoryId;
+
+    pseudo interface TypeCode { // PIDL
+	exception Bounds {};
+	exception BadKind {};
+	
+	// for all TypeCode kinds
+	boolean equal (in TypeCode tc);
+	TCKind kind ();
+
+	boolean equivalent(in TypeCode tc);
+	TypeCode get_compact_typecode();
+
+	// for tk_objref, tk_struct, tk_union, tk_enum, 
+	// tk_alias, and tk_except
+	RepositoryId id () raises (BadKind);
+	
+	// for tk_objref, tk_struct, tk_union, tk_enum, 
+	// tk_alias, and tk_except
+	Identifier name () raises (BadKind);
+	
+	// for tk_struct, tk_union, tk_enum, and tk_except
+	unsigned long member_count () raises (BadKind);
+	Identifier member_name (in unsigned long index) 
+	    raises (BadKind, Bounds);
+	
+	// for tk_struct, tk_union, and tk_except
+	TypeCode member_type (in unsigned long index) 
+	    raises (BadKind, Bounds);
+	
+	// for tk_union
+	any member_label (in unsigned long index) 
+	    raises (BadKind, Bounds);
+	TypeCode discriminator_type () raises (BadKind);
+	long default_index () raises (BadKind); 
+	
+	// for tk_string, tk_sequence, and tk_array
+	unsigned long length () raises (BadKind);
+	
+	// for tk_sequence, tk_array, and tk_alias
+	TypeCode content_type () raises (BadKind);
+       	
+    };
+
+
+    interface InterfaceDef     {};
+
+    /* this is the original PIDL from the lang. mapping, 
+       but we do not use it! Instead...
+
+    pseudo interface Principal
+    { 
+	attribute sequence<octet> name;
+    };
+    */
+
+    /* ... we use this little hack. It saves us fiddling with 
+       the generated code that uses  Principals. Actually, we 
+       should not be doing this....
+    */
+
+    typedef sequence<octet> Principal;
+
+    interface IDLType {};
+
+    enum OperationMode {OP_NORMAL, OP_ONEWAY};
+    enum ParameterMode {PARAM_IN, PARAM_OUT, PARAM_INOUT};
+
+    struct ParameterDescription {
+	Identifier name; 
+	TypeCode type; 
+	IDLType type_def;
+	ParameterMode mode;
+    };
+    typedef sequence <ParameterDescription> ParDescriptionSeq;
+	
+    interface Policy
+    {
+	readonly attribute PolicyType policy_type;
+	Policy copy();
+	void destroy();
+    };
+	
+    typedef sequence <Policy> PolicyList;
+
+    interface DomainManager
+    {
+	Policy get_domain_policy(in PolicyType policy_type);
+    };
+
+    interface ConstructionPolicy: Policy
+    {
+	void make_domain_manager(in InterfaceDef object_type,
+				 in boolean constr_policy);
+    };
+
+    typedef sequence <DomainManager> DomainManagersList;
+	
+
+    typedef short PolicyErrorCode;
+    const PolicyErrorCode BAD_POLICY = 0;
+    // ... to be continued
+
+    exception PolicyError
+    {
+	PolicyErrorCode reason;
+    };
+
+    exception UserException {};
+    pseudo interface ExceptionList {};
+
+
+    valuetype WStringValue {
+       public wstring value;
+    };
+
+
+};
+
+
+#endif /* _MYORB_IDL */




More information about the jboss-cvs-commits mailing list