/[classpath]/classpath/gnu/CORBA/CDR/cdrOutput.java
ViewVC logotype

Diff of /classpath/gnu/CORBA/CDR/cdrOutput.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.9 by audriusa, Sun Aug 28 11:23:36 2005 UTC revision 1.10 by audriusa, Sun Oct 2 19:58:00 2005 UTC
# Line 39  exception statement from your version. * Line 39  exception statement from your version. *
39  package gnu.CORBA.CDR;  package gnu.CORBA.CDR;
40    
41  import gnu.CORBA.BigDecimalHelper;  import gnu.CORBA.BigDecimalHelper;
 import gnu.CORBA.GIOP.CharSets_OSF;  
 import gnu.CORBA.GIOP.cxCodeSet;  
 import gnu.CORBA.Poa.gnuServantObject;  
42  import gnu.CORBA.IOR;  import gnu.CORBA.IOR;
43  import gnu.CORBA.Simple_delegate;  import gnu.CORBA.IorProvider;
44  import gnu.CORBA.TypeCodeHelper;  import gnu.CORBA.TypeCodeHelper;
45  import gnu.CORBA.Unexpected;  import gnu.CORBA.Unexpected;
46  import gnu.CORBA.Version;  import gnu.CORBA.Version;
47  import gnu.CORBA.primitiveTypeCode;  import gnu.CORBA.primitiveTypeCode;
48    import gnu.CORBA.GIOP.CharSets_OSF;
49    import gnu.CORBA.GIOP.cxCodeSet;
50    
51  import org.omg.CORBA.Any;  import org.omg.CORBA.Any;
52  import org.omg.CORBA.BAD_OPERATION;  import org.omg.CORBA.BAD_OPERATION;
53  import org.omg.CORBA.Context;  import org.omg.CORBA.Context;
54  import org.omg.CORBA.ContextList;  import org.omg.CORBA.ContextList;
55    import org.omg.CORBA.DataInputStream;
56  import org.omg.CORBA.MARSHAL;  import org.omg.CORBA.MARSHAL;
57  import org.omg.CORBA.NO_IMPLEMENT;  import org.omg.CORBA.NO_IMPLEMENT;
58  import org.omg.CORBA.ORB;  import org.omg.CORBA.ORB;
59  import org.omg.CORBA.TCKind;  import org.omg.CORBA.TCKind;
60  import org.omg.CORBA.TypeCode;  import org.omg.CORBA.TypeCode;
 import org.omg.CORBA.TypeCodePackage.BadKind;  
61  import org.omg.CORBA.UserException;  import org.omg.CORBA.UserException;
62    import org.omg.CORBA.TypeCodePackage.BadKind;
63  import org.omg.CORBA.portable.Delegate;  import org.omg.CORBA.portable.Delegate;
64  import org.omg.CORBA.portable.ObjectImpl;  import org.omg.CORBA.portable.ObjectImpl;
65  import org.omg.CORBA.portable.OutputStream;  import org.omg.CORBA.portable.OutputStream;
# Line 68  import org.omg.CORBA.portable.Streamable Line 68  import org.omg.CORBA.portable.Streamable
68  import java.io.IOException;  import java.io.IOException;
69  import java.io.OutputStreamWriter;  import java.io.OutputStreamWriter;
70  import java.io.Serializable;  import java.io.Serializable;
   
71  import java.math.BigDecimal;  import java.math.BigDecimal;
72    
73  /**  /**
# Line 79  import java.math.BigDecimal; Line 78  import java.math.BigDecimal;
78   * The same class also implements the {@link DataInputStream},   * The same class also implements the {@link DataInputStream},
79   * providing support for writing the value type objects   * providing support for writing the value type objects
80   * in a user defined way.   * in a user defined way.
81     *
82     * TODO This class uses 16 bits per Unicode character only, as it was until
83     * jdk 1.4 inclusive.
84   *   *
85   * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)   * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
86   */   */
# Line 87  public abstract class cdrOutput Line 89  public abstract class cdrOutput
89    implements org.omg.CORBA.DataOutputStream    implements org.omg.CORBA.DataOutputStream
90  {  {
91    /**    /**
92       * The runtime, associated with this stream. This field is only used when
93       * reading and writing value types and filled-in in gnu.CORBA.CDR.Vio.
94       */
95      public transient gnuRuntime runtime;  
96      
97      /**
98     * This instance is used to convert primitive data types into the     * This instance is used to convert primitive data types into the
99     * byte sequences.     * byte sequences.
100     */     */
# Line 168  public abstract class cdrOutput Line 176  public abstract class cdrOutput
176     * stream is different from 0.     * stream is different from 0.
177     */     */
178    public abstract void setOffset(int an_offset);    public abstract void setOffset(int an_offset);
179      
180      /**
181       * Clone all important settings to another stream.
182       */
183      public void cloneSettings(cdrOutput stream)
184      {
185        stream.setBigEndian(!little_endian);
186        stream.setCodeSet(getCodeSet());
187        stream.setVersion(giop);
188        stream.setOrb(orb);
189      }  
190    
191    /**    /**
192     * Set the current code set context.     * Set the current code set context.
# Line 313  public abstract class cdrOutput Line 332  public abstract class cdrOutput
332    }    }
333    
334    /**    /**
335    * Read the CORBA object. The object is written     * Read the CORBA object. The object is written form of the plain (not a
336    * form of the plain (not a string-encoded) IOR profile without the     * string-encoded) IOR profile without the heading endian indicator. The
337    * heading endian indicator. The responsible method for reading such     * responsible method for reading such data is {@link IOR.write_no_endian}.
338    * data is {@link IOR.write_no_endian}.     *
339    *     * The null value is written as defined in OMG specification (zero length
340    * The null value is written as defined in OMG specification     * string, followed by an empty set of profiles).
341    * (zero length string, followed by an empty set of profiles).     */
   */  
342    public void write_Object(org.omg.CORBA.Object x)    public void write_Object(org.omg.CORBA.Object x)
343    {    {
344      if (x == null)      ORB w_orb = orb;
345        if (x instanceof IorProvider)
346        {        {
347          IOR.write_null(this);          ((IorProvider) x).getIor()._write_no_endian(this);
348          return;          return;
349        }        }
350      else if (x instanceof gnuServantObject)      else if (x == null)
351        {        {
352          // The ORB may be different if several ORBs coexist          IOR.write_null(this);
         // in the same machine.  
         gnuServantObject g = (gnuServantObject) x;  
         IOR ior = g.orb.getLocalIor(x);  
         ior._write_no_endian(this);  
353          return;          return;
354        }        }
355      else if (x instanceof ObjectImpl)      else if (x instanceof ObjectImpl)
356        {        {
357          Delegate d = ((ObjectImpl) x)._get_delegate();          Delegate d = ((ObjectImpl) x)._get_delegate();
358    
359          if (d instanceof Simple_delegate)          if (d instanceof IorProvider)
360            {            {
361              Simple_delegate ido = (Simple_delegate) d;              ((IorProvider) d).getIor()._write_no_endian(this);
             ido.getIor()._write_no_endian(this);  
362              return;              return;
363            }            }
364            else
365              {
366                ORB d_orb = d.orb(x);
367                if (d_orb != null)
368                  w_orb = d_orb;
369              }
370        }        }
371    
372      // Either this is not an ObjectImpl or it has the      // Either this is not an ObjectImpl or it has the
373      // unexpected delegate. Try to convert via ORBs      // unexpected delegate. Try to convert via ORBs
374      // object_to_string().      // object_to_string().
375      if (orb != null)      if (w_orb != null)
376        {        {
377          IOR ior = IOR.parse(orb.object_to_string(x));          IOR ior = IOR.parse(w_orb.object_to_string(x));
378          ior._write_no_endian(this);          ior._write_no_endian(this);
379          return;          return;
380        }        }
381      else      else
382        throw new BAD_OPERATION("Please set the ORB for this stream.");        throw new BAD_OPERATION(
383            "Please set the ORB for this stream, cannot write "
384              + x.getClass().getName());
385    }    }
386    
387    /**    /**
# Line 874  public abstract class cdrOutput Line 896  public abstract class cdrOutput
896    }    }
897    
898    /**    /**
899     * Writes the character as two byte short integer (Unicode value),     * Writes the character as two byte short integer (Unicode value), high byte
900     * high byte first. Writes in Big Endian, but never writes the     * first. Writes in Big Endian, but never writes the endian indicator.
901     * endian indicator.     *
902     *     * The character is always written using the native UTF-16BE charset because
903     * The character is always written using the native UTF-16BE charset     * its size under arbitrary encoding is not evident.
    * because its size under arbitrary encoding is not evident.  
904     */     */
905    public void write_wchar(char x)    public void write_wchar(char x)
906    {    {
907      try      try
908        {        {
909          if (giop.until_inclusive(1, 1))          if (giop.until_inclusive(1, 1))
910            align(2);            {
911                align(2);
912    
913          if (wide_native)              if (wide_native)
914            b.writeShort(x);                b.writeShort(x);
915                else
916                  {
917                    OutputStreamWriter ow = new OutputStreamWriter(
918                      (OutputStream) b, wide_charset);
919                    ow.write(x);
920                    ow.flush();
921                  }
922              }
923            else if (wide_native)
924              {
925                b.writeByte(2);
926                b.writeChar(x);
927              }
928          else          else
929            {            {
930              OutputStreamWriter ow =              String encoded = new String(new char[] { x });
931                new OutputStreamWriter((OutputStream) b, wide_charset);              byte[] bytes = encoded.getBytes(wide_charset);
932              ow.write(x);              b.write(bytes.length + 2);
933              ow.flush();              b.write(bytes);
934            }            }
935        }        }
936      catch (IOException ex)      catch (IOException ex)
# Line 906  public abstract class cdrOutput Line 941  public abstract class cdrOutput
941    
942    /**    /**
943     * Write the array of wide chars.     * Write the array of wide chars.
944     *     *
945     * @param chars the array of wide chars     * @param chars the array of wide chars
946     * @param offset offset     * @param offset offset
947     * @param length length     * @param length length
948     *     *
949     * The char array is always written using the native UTF-16BE charset     * The char array is always written using the native UTF-16BE charset because
950     * because the character size under arbitrary encoding is not evident.     * the character size under arbitrary encoding is not evident.
951     */     */
952    public void write_wchar_array(char[] chars, int offset, int length)    public void write_wchar_array(char[] chars, int offset, int length)
953    {    {
# Line 998  public abstract class cdrOutput Line 1033  public abstract class cdrOutput
1033    /** {@inheritDoc} */    /** {@inheritDoc} */
1034    public void write_Abstract(java.lang.Object value)    public void write_Abstract(java.lang.Object value)
1035    {    {
1036      write_Abstract(value);      write_abstract_interface(value);
1037    }    }
1038    
1039    /** {@inheritDoc} */    /** {@inheritDoc} */
1040    public void write_Value(Serializable value)    public void write_Value(Serializable value)
1041    {    {
1042      write_Value(value);      write_value(value);
1043    }    }
1044  }  }

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26