/[classpath]/classpath/gnu/CORBA/gnuAny.java
ViewVC logotype

Diff of /classpath/gnu/CORBA/gnuAny.java

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

revision 1.1.2.5 by gnu_andrew, Tue Sep 20 18:46:22 2005 UTC revision 1.1.2.6 by gnu_andrew, Wed Nov 2 00:43:23 2005 UTC
# Line 39  exception statement from your version. * Line 39  exception statement from your version. *
39  package gnu.CORBA;  package gnu.CORBA;
40    
41  import gnu.CORBA.CDR.Vio;  import gnu.CORBA.CDR.Vio;
42  import gnu.CORBA.CDR.cdrBufInput;  import gnu.CORBA.CDR.BufferredCdrInput;
43  import gnu.CORBA.CDR.cdrBufOutput;  import gnu.CORBA.CDR.BufferedCdrOutput;
44    import gnu.CORBA.typecodes.PrimitiveTypeCode;
45    import gnu.CORBA.typecodes.StringTypeCode;
46    
47  import org.omg.CORBA.Any;  import org.omg.CORBA.Any;
48  import org.omg.CORBA.AnyHolder;  import org.omg.CORBA.AnyHolder;
# Line 63  import org.omg.CORBA.TCKind; Line 65  import org.omg.CORBA.TCKind;
65  import org.omg.CORBA.TypeCode;  import org.omg.CORBA.TypeCode;
66  import org.omg.CORBA.TypeCodeHolder;  import org.omg.CORBA.TypeCodeHolder;
67  import org.omg.CORBA.ValueBaseHolder;  import org.omg.CORBA.ValueBaseHolder;
 import org.omg.CORBA.portable.BoxedValueHelper;  
68  import org.omg.CORBA.portable.Streamable;  import org.omg.CORBA.portable.Streamable;
69    
70  import java.io.Serializable;  import java.io.Serializable;
# Line 89  import java.util.zip.Adler32; Line 90  import java.util.zip.Adler32;
90  public class gnuAny  public class gnuAny
91    extends Any    extends Any
92  {  {
93      /**
94       * Use serialVersionUID for interoperability.
95       */
96      private static final long serialVersionUID = 1;
97      
98    /**    /**
99     * The value, returned by {@link #type()} if the value has been     * The value, returned by {@link #type()} if the value has been
100     * not intialized.     * not intialized.
101     */     */
102    protected static final TypeCode nullType =    protected static final TypeCode nullType =
103      new primitiveTypeCode(TCKind.tk_null);      new PrimitiveTypeCode(TCKind.tk_null);
104    
105    /**    /**
106     * The Streamable, representing the value, held by this gnuAny.     * The Streamable, representing the value, held by this gnuAny.
# Line 133  public class gnuAny Line 139  public class gnuAny
139     */     */
140    public gnuAny Clone()    public gnuAny Clone()
141    {    {
142      cdrBufOutput out = new cdrBufOutput();      BufferedCdrOutput out = new BufferedCdrOutput();
143      out.setOrb(orb);      out.setOrb(orb);
144      out.write_any(this);      out.write_any(this);
145    
146      cdrBufInput in = new cdrBufInput(out.buffer.toByteArray());      BufferredCdrInput in = new BufferredCdrInput(out.buffer.toByteArray());
147      in.setOrb(orb);      in.setOrb(orb);
148      return (gnuAny) in.read_any();      return (gnuAny) in.read_any();
149    }    }
# Line 148  public class gnuAny Line 154  public class gnuAny
154     */     */
155    public org.omg.CORBA.portable.InputStream create_input_stream()    public org.omg.CORBA.portable.InputStream create_input_stream()
156    {    {
157      if (has instanceof universalHolder)      if (has instanceof GeneralHolder)
158        {        {
159          universalHolder u = (universalHolder) has;          GeneralHolder u = (GeneralHolder) has;
160          return u.getInputStream();          return u.getInputStream();
161        }        }
162      else      else
163        {        {
164          cdrBufOutput out = new cdrBufOutput();          BufferedCdrOutput out = new BufferedCdrOutput();
165          out.setOrb(orb);          out.setOrb(orb);
166          write_value(out);          write_value(out);
167    
168          cdrBufInput in = new cdrBufInput(out.buffer.toByteArray());          BufferredCdrInput in = new BufferredCdrInput(out.buffer.toByteArray());
169          in.setOrb(orb);          in.setOrb(orb);
170          return in;          return in;
171        }        }
# Line 170  public class gnuAny Line 176  public class gnuAny
176     */     */
177    public org.omg.CORBA.portable.OutputStream create_output_stream()    public org.omg.CORBA.portable.OutputStream create_output_stream()
178    {    {
179      cdrBufOutput stream = new cdrBufOutput();      BufferedCdrOutput stream = new BufferedCdrOutput();
180      stream.setOrb(orb);      stream.setOrb(orb);
181      return stream;      return stream;
182    }    }
# Line 190  public class gnuAny Line 196  public class gnuAny
196        if (has.equals(((gnuAny) other).has))        if (has.equals(((gnuAny) other).has))
197          return true;          return true;
198    
199      cdrBufOutput a = new cdrBufOutput();      BufferedCdrOutput a = new BufferedCdrOutput();
200      a.setOrb(orb);      a.setOrb(orb);
201      write_value(a);      write_value(a);
202    
203      cdrBufOutput b = new cdrBufOutput();      BufferedCdrOutput b = new BufferedCdrOutput();
204      b.setOrb(orb);      b.setOrb(orb);
205      other.write_value(b);      other.write_value(b);
206    
# Line 215  public class gnuAny Line 221  public class gnuAny
221        {        {
222          Adler32 adler = new Adler32();          Adler32 adler = new Adler32();
223    
224          cdrBufOutput a = new cdrBufOutput();          BufferedCdrOutput a = new BufferedCdrOutput();
225          a.setOrb(orb);          a.setOrb(orb);
226          write_value(a);          write_value(a);
227                    
# Line 250  public class gnuAny Line 256  public class gnuAny
256        }        }
257      catch (ClassCastException ex)      catch (ClassCastException ex)
258        {        {
259          throw new BAD_OPERATION();          BAD_OPERATION bad = new BAD_OPERATION();
260            bad.initCause(ex);
261            bad.minor = Minor.Any;
262            throw bad;
263        }        }
264    }    }
265    
# Line 315  public class gnuAny Line 324  public class gnuAny
324        }        }
325      catch (Exception ex)      catch (Exception ex)
326        {        {
327          return new BAD_OPERATION("Value type expected");          BAD_OPERATION bad = new BAD_OPERATION("Value type expected");
328            bad.minor = Minor.Any;
329            bad.initCause(ex);
330            throw bad;
331        }        }
332    }    }
333    
# Line 682  public class gnuAny Line 694  public class gnuAny
694      else      else
695        has = new StringHolder(x);        has = new StringHolder(x);
696    
697      typecode = new stringTypeCode(TCKind.tk_string);      typecode = new StringTypeCode(TCKind.tk_string);
698    }    }
699    
700    /** {@inheritDoc} */    /** {@inheritDoc} */
# Line 769  public class gnuAny Line 781  public class gnuAny
781            }            }
782          else          else
783            {            {
784              has = holderFactory.createHolder(a_type);              has = HolderLocator.createHolder(a_type);
785              if (has == null)              if (has == null)
786                {                {
787                  // Use the Universal Holder that reads till the end of stream.                  // Use the Universal Holder that reads till the end of stream.
788                  // This works with the extract/insert pair of the typical                  // This works with the extract/insert pair of the typical
789                  // Helper.                  // Helper.
790                  cdrBufOutput buffer = new cdrBufOutput();                  BufferedCdrOutput buffer = new BufferedCdrOutput();
791                  buffer.setOrb(orb);                  buffer.setOrb(orb);
792                  has = new universalHolder(buffer);                  has = new GeneralHolder(buffer);
793                }                }
794            }            }
795          type(a_type);          type(a_type);
796    
797          if (!(has instanceof universalHolder) &&          if (!(has instanceof GeneralHolder) &&
798              (kind == TCKind._tk_value_box))              (kind == TCKind._tk_value_box))
799            {            {
800              // The streamable only contains operations for              // The streamable only contains operations for
801              // reading the value, not the value header.              // reading the value, not the value header.
802              Field vField = has.getClass().getField("value");              Field vField = has.getClass().getField("value");
803    
804              BoxedValueHelper helper;              Object content = Vio.read(input, a_type.id());
   
             try  
               {  
                 Class helperClass =  
                   Class.forName(ObjectCreator.toHelperName(a_type.id()));  
                 helper = (BoxedValueHelper) helperClass.newInstance();  
               }  
             catch (Exception ex)  
               {  
                 helper = null;  
               }  
   
             Object content = Vio.read(input, helper);  
805              vField.set(has, content);              vField.set(has, content);
806            }            }
807          else          else
# Line 811  public class gnuAny Line 810  public class gnuAny
810      catch (Exception ex)      catch (Exception ex)
811        {        {
812          MARSHAL m = new MARSHAL();          MARSHAL m = new MARSHAL();
813            m.minor = Minor.Any;
814          m.initCause(ex);          m.initCause(ex);
815          throw m;          throw m;
816        }        }
# Line 823  public class gnuAny Line 823  public class gnuAny
823        return typecode;        return typecode;
824      else if (xKind >= 0)      else if (xKind >= 0)
825        {        {
826          typecode = new primitiveTypeCode(TCKind.from_int(xKind));          typecode = new PrimitiveTypeCode(TCKind.from_int(xKind));
827          return typecode;          return typecode;
828        }        }
829      else      else
# Line 856  public class gnuAny Line 856  public class gnuAny
856    
857    /**    /**
858     * Check if the current value if the value of the given kind.     * Check if the current value if the value of the given kind.
859       *
860     * @param kind a kind to check.     * @param kind a kind to check.
861     * @throws BAD_OPERATION if the value is not set of is different kind.     * @throws BAD_OPERATION if the value is not set of is different kind.
862     */     */
863    protected void check(int kind)    protected void check(int kind)
864                  throws BAD_OPERATION      throws BAD_OPERATION
865    {    {
866      if (has == null)      if (has == null)
867        throw new BAD_OPERATION("value not set");        {
868            BAD_OPERATION bad = new BAD_OPERATION("value not set");
869            bad.minor = Minor.Any;
870            throw bad;
871          }
872    
873      if (xKind >= 0)      if (xKind >= 0)
874        {        {
875          if (xKind != kind)          if (xKind != kind)
876            if (!(            if (!(xKind == TCKind._tk_alias && has._type().kind().value() == kind))
877                  xKind == TCKind._tk_alias &&              {
878                  has._type().kind().value() == kind                BAD_OPERATION bad = new BAD_OPERATION("Extracting "
879                )                  + TypeKindNamer.nameIt(kind) + " when stored "
880               )                  + TypeKindNamer.nameIt(xKind));
881              throw new BAD_OPERATION("Extracting " + typeNamer.nameIt(kind) +                bad.minor = Minor.Any;
882                                      " when stored " + typeNamer.nameIt(xKind)                throw bad;
883                                     );              }
884        }        }
885      else      else
886        {        {
887          if (type().kind().value() != kind)          if (type().kind().value() != kind)
888            if (!(            if (!(type().kind().value() == TCKind._tk_alias && has._type().kind().value() == kind))
889                  type().kind().value() == TCKind._tk_alias &&              {
890                  has._type().kind().value() == kind                BAD_OPERATION bad = new BAD_OPERATION("Extracting "
891                )                  + TypeKindNamer.nameIt(kind) + " stored "
892               )                  + TypeKindNamer.nameIt(type()));
893              throw new BAD_OPERATION("Extracting " + typeNamer.nameIt(kind) +                bad.minor = Minor.Any;
894                                      " stored " + typeNamer.nameIt(type())                throw bad;
895                                     );              }
896        }        }
897    }    }
898    

Legend:
Removed from v.1.1.2.5  
changed lines
  Added in v.1.1.2.6

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