KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > orb > Any


1 package org.jacorb.orb;
2
3 /*
4  * JacORB - the free Java ORB
5  *
6  * Copyright (C) 1997-2004 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 import org.omg.CORBA.*;
24 import java.util.*;
25
26 /**
27  * CORBA any
28  *
29  * @author Gerald Brose
30  * $Id: Any.java,v 1.42 2004/05/06 12:40:00 nicolas Exp $
31  */

32
33 public final class Any
34     extends org.omg.CORBA.Any JavaDoc
35 {
36     private org.omg.CORBA.TypeCode JavaDoc typeCode;
37     private java.lang.Object JavaDoc value;
38     private org.omg.CORBA.ORB JavaDoc orb;
39
40     Any (org.omg.CORBA.ORB JavaDoc orb)
41     {
42         this.orb = orb;
43         typeCode = orb.get_primitive_tc (org.omg.CORBA.TCKind.tk_null);
44     }
45
46     public TCKind kind()
47     {
48         return typeCode.kind();
49     }
50
51     public org.omg.CORBA.TypeCode JavaDoc type()
52     {
53         return typeCode;
54     }
55
56     public org.omg.CORBA.TypeCode JavaDoc originalType()
57     {
58       return TypeCode.originalType(typeCode);
59     }
60
61     public void type (org.omg.CORBA.TypeCode JavaDoc t)
62     {
63         typeCode = t;
64         value = null;
65     }
66
67     public java.lang.Object JavaDoc value()
68     {
69         return value;
70     }
71
72     public int _get_TCKind()
73     {
74         return org.omg.CORBA.TCKind._tk_any;
75     }
76
77     private void tc_error (String JavaDoc s)
78     {
79         throw new BAD_OPERATION (s);
80     }
81
82     private void checkExtract (int value, String JavaDoc s)
83     {
84        if (originalType().kind().value() != value)
85        {
86            throw new BAD_OPERATION (s);
87        }
88     }
89
90     public boolean equal (org.omg.CORBA.Any JavaDoc a)
91     {
92         if (a == null)
93         {
94            throw new BAD_PARAM ("Null passed to Any equal operation");
95         }
96
97         if (!typeCode.equal (a.type()))
98         {
99             return false;
100         }
101
102         int kind = originalType().kind().value();
103         switch (kind)
104         {
105             case TCKind._tk_null:
106             case TCKind._tk_void:
107                 return true;
108             case TCKind._tk_short:
109                 return extract_short() == a.extract_short();
110             case TCKind._tk_long:
111                 return extract_long() == a.extract_long();
112             case TCKind._tk_longlong:
113                 return extract_longlong() == a.extract_longlong();
114             case TCKind._tk_ushort:
115                 return extract_ushort() == a.extract_ushort();
116             case TCKind._tk_ulong:
117                 return extract_ulong() == a.extract_ulong();
118             case TCKind._tk_ulonglong:
119                 return extract_ulonglong() == a.extract_ulonglong();
120             case TCKind._tk_float:
121                 return extract_float() == a.extract_float();
122             case TCKind._tk_double:
123                 return extract_double() == a.extract_double();
124             case TCKind._tk_fixed:
125                 return extract_fixed().equals( a.extract_fixed() );
126             case TCKind._tk_boolean:
127                 return extract_boolean() == a.extract_boolean();
128             case TCKind._tk_char:
129                 return extract_char() == a.extract_char();
130             case TCKind._tk_wchar:
131                 return extract_wchar() == a.extract_wchar();
132             case TCKind._tk_octet:
133                 return extract_octet() == a.extract_octet();
134             case TCKind._tk_any:
135                 return extract_any().equals( a.extract_any() );
136             case TCKind._tk_TypeCode:
137                 return extract_TypeCode().equal( a.extract_TypeCode() );
138             case TCKind._tk_Principal:
139                 throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("Principal deprecated");
140             case TCKind._tk_objref:
141                 return extract_Object().equals( a.extract_Object() );
142             case TCKind._tk_string:
143                 return extract_string().equals( a.extract_string() );
144             case TCKind._tk_wstring:
145                 return extract_wstring().equals( a.extract_wstring() );
146             case TCKind._tk_array:
147             case TCKind._tk_sequence:
148             case TCKind._tk_struct:
149             case TCKind._tk_except:
150             case TCKind._tk_enum:
151             case TCKind._tk_union:
152             {
153                 CDROutputStream out1, out2;
154                 if( !( orb instanceof org.jacorb.orb.ORB ))
155                 {
156                     out1 = new CDROutputStream();
157                     out2 = new CDROutputStream();
158                 }
159                 else
160                 {
161                     out1 = new CDROutputStream(orb);
162                     out2 = new CDROutputStream(orb);
163                 }
164                 write_value( out1 );
165                 a.write_value( out2 );
166
167                 if( out1.size() != out2.size() )
168                     return false;
169
170                 return Arrays.equals( out1.getBufferCopy(),
171                                        out2.getBufferCopy());
172
173             }
174             default:
175                 throw new BAD_TYPECODE("Cannot compare anys with TypeCode kind " + kind);
176         }
177     }
178
179     public boolean equals (java.lang.Object JavaDoc obj)
180     {
181         if( obj instanceof org.omg.CORBA.Any JavaDoc)
182             return equal((org.omg.CORBA.Any JavaDoc)obj);
183         else
184             return false;
185     }
186
187     public int hashCode()
188     {
189         return value.hashCode();
190     }
191
192     public String JavaDoc toString()
193     {
194         if( value != null )
195             return value.toString();
196         else
197             return "null";
198     }
199
200     // short
201

202     public void insert_short (short s)
203     {
204         value = new Short JavaDoc (s);
205         typeCode = orb.get_primitive_tc (TCKind.tk_short);
206     }
207
208     public short extract_short()
209         throws org.omg.CORBA.BAD_OPERATION JavaDoc
210     {
211         checkExtract (TCKind._tk_short, "Cannot extract short");
212         if (value instanceof CDROutputStream)
213         {
214            return create_input_stream().read_short();
215         }
216         return ((Short JavaDoc)value).shortValue();
217     }
218
219     // ushort
220

221     public void insert_ushort (short s)
222     {
223         value = new Short JavaDoc (s);
224         typeCode = orb.get_primitive_tc (TCKind.tk_ushort);
225     }
226
227     public short extract_ushort()
228     {
229         checkExtract (TCKind._tk_ushort, "Cannot extract ushort");
230         if (value instanceof CDROutputStream)
231         {
232            return create_input_stream().read_ushort();
233         }
234         return ((Short JavaDoc)value).shortValue();
235     }
236
237     // long
238

239     public void insert_long (int i)
240     {
241         value = new Integer JavaDoc (i);
242         typeCode = orb.get_primitive_tc (TCKind.tk_long);
243     }
244
245     public int extract_long()
246     {
247         checkExtract (TCKind._tk_long, "Cannot extract long");
248         if (value instanceof CDROutputStream)
249         {
250            return create_input_stream().read_long();
251         }
252         return ((Integer JavaDoc)value).intValue();
253     }
254
255     // ulong
256

257     public void insert_ulong (int i)
258     {
259         value = new Integer JavaDoc (i);
260         typeCode = orb.get_primitive_tc( TCKind.tk_ulong );
261     }
262
263     public int extract_ulong()
264     {
265         checkExtract (TCKind._tk_ulong, "Cannot extract ulong");
266         if (value instanceof CDROutputStream)
267         {
268            return create_input_stream().read_ulong();
269         }
270         return ((Integer JavaDoc)value).intValue();
271     }
272
273     // longlong
274

275     public void insert_longlong (long l)
276     {
277         value = new Long JavaDoc (l);
278         typeCode = orb.get_primitive_tc (TCKind.tk_longlong);
279     }
280
281     public long extract_longlong()
282     {
283         checkExtract (TCKind._tk_longlong, "Cannot extract longlong");
284         if (value instanceof CDROutputStream)
285         {
286            return create_input_stream().read_longlong();
287         }
288         return ((Long JavaDoc)value).longValue();
289     }
290
291     // ulonglong
292

293     public void insert_ulonglong (long l)
294     {
295         value = new Long JavaDoc (l);
296         typeCode = orb.get_primitive_tc (TCKind.tk_ulonglong);
297     }
298
299     public long extract_ulonglong()
300     {
301         checkExtract (TCKind._tk_ulonglong, "Cannot extract ulonglong");
302         if (value instanceof CDROutputStream)
303         {
304            return create_input_stream().read_ulonglong();
305         }
306         return ((Long JavaDoc)value).longValue();
307     }
308
309     // float
310

311     public void insert_float (float f)
312     {
313         value = new Float JavaDoc (f);
314         typeCode = orb.get_primitive_tc (TCKind.tk_float);
315     }
316
317     public float extract_float()
318     {
319         checkExtract (TCKind._tk_float, "Cannot extract float");
320         if (value instanceof CDROutputStream)
321         {
322            return create_input_stream().read_float();
323         }
324         return ((Float JavaDoc)value).floatValue();
325     }
326
327     // double
328

329     public void insert_double (double d)
330     {
331         value = new Double JavaDoc (d);
332         typeCode = orb.get_primitive_tc (TCKind.tk_double);
333     }
334
335     public double extract_double()
336     {
337         checkExtract (TCKind._tk_double, "Cannot extract double");
338         if (value instanceof CDROutputStream)
339         {
340            return create_input_stream().read_double();
341         }
342         return ((Double JavaDoc)value).doubleValue();
343     }
344
345
346     /**
347      * <code>insert_boolean</code> inserts a Boolean into this Any.
348      *
349      * @param b a <code>boolean</code> value
350      */

351     public void insert_boolean (boolean b)
352     {
353         // Equivilant to the static valueOf factory which is only
354
// available post 1.4.
355
value = (b ? Boolean.TRUE : Boolean.FALSE );
356         typeCode = orb.get_primitive_tc (TCKind.tk_boolean);
357     }
358
359     public boolean extract_boolean()
360     {
361         checkExtract (TCKind._tk_boolean, "Cannot extract boolean");
362         if (value instanceof CDROutputStream)
363         {
364            return create_input_stream().read_boolean();
365         }
366         return ((Boolean JavaDoc)value).booleanValue();
367     }
368
369     // char
370

371     public void insert_char (char c)
372     {
373         value = new Character JavaDoc (c);
374         typeCode = orb.get_primitive_tc (TCKind.tk_char);
375     }
376
377     public char extract_char()
378     {
379         checkExtract (TCKind._tk_char, "Cannot extract char");
380         if (value instanceof CDROutputStream)
381         {
382            return create_input_stream().read_char();
383         }
384         return ((Character JavaDoc)value).charValue();
385     }
386
387     public void insert_wchar (char c)
388     {
389         value = new Character JavaDoc (c);
390         typeCode = orb.get_primitive_tc (TCKind.tk_wchar);
391     }
392
393     public char extract_wchar()
394     {
395         checkExtract (TCKind._tk_wchar, "Cannot extract wchar");
396         if (value instanceof CDROutputStream)
397         {
398            return create_input_stream().read_wchar();
399         }
400         return ((Character JavaDoc)value).charValue();
401     }
402
403     // octet
404

405     public void insert_octet (byte b)
406     {
407         value = new Byte JavaDoc (b);
408         typeCode = orb.get_primitive_tc (TCKind.tk_octet);
409     }
410
411     public byte extract_octet()
412     {
413         checkExtract (TCKind._tk_octet, "Cannot extract octet");
414         if (value instanceof CDROutputStream)
415         {
416            return create_input_stream().read_octet();
417         }
418         return ((Byte JavaDoc)value).byteValue();
419     }
420
421     // any
422

423     public void insert_any (org.omg.CORBA.Any JavaDoc a)
424     {
425         value = a;
426         typeCode = orb.get_primitive_tc (TCKind.tk_any);
427     }
428
429     public org.omg.CORBA.Any JavaDoc extract_any()
430     {
431         checkExtract (TCKind._tk_any, "Cannot extract any");
432         if (value instanceof CDROutputStream)
433         {
434            return create_input_stream().read_any();
435         }
436         return (org.omg.CORBA.Any JavaDoc)value;
437     }
438
439     // TypeCode
440

441     public void insert_TypeCode (org.omg.CORBA.TypeCode JavaDoc tc)
442     {
443         value = tc;
444         typeCode = orb.get_primitive_tc (TCKind.tk_TypeCode);
445     }
446
447     public org.omg.CORBA.TypeCode JavaDoc extract_TypeCode()
448     {
449         checkExtract (TCKind._tk_TypeCode, "Cannot extract TypeCode");
450         if (value instanceof CDROutputStream)
451         {
452            return create_input_stream().read_TypeCode();
453         }
454         return (org.omg.CORBA.TypeCode JavaDoc)value;
455     }
456
457     // string
458

459     public void insert_string (String JavaDoc s)
460     {
461         value = s;
462         typeCode = orb.create_string_tc (0);
463     }
464
465     public String JavaDoc extract_string()
466     {
467         checkExtract (TCKind._tk_string, "Cannot extract string");
468         return value.toString();
469     }
470
471     public void insert_wstring (String JavaDoc s)
472     {
473         value = s;
474         typeCode = orb.create_wstring_tc (0);
475     }
476
477     public String JavaDoc extract_wstring()
478     {
479         checkExtract (TCKind._tk_wstring, "Cannot extract wstring");
480         return value.toString();
481     }
482
483     // fixed
484

485     public void insert_fixed (java.math.BigDecimal JavaDoc _value)
486     {
487         value = _value;
488         typeCode = (new org.omg.CORBA.FixedHolder JavaDoc(_value))._type();
489     }
490
491    public void insert_fixed(java.math.BigDecimal JavaDoc _value,
492                             org.omg.CORBA.TypeCode JavaDoc type)
493    {
494        try
495        {
496           String JavaDoc val = _value.toString();
497           int extra = _value.scale() - type.fixed_scale();
498           if ( extra > 0 )
499           {
500              // truncate the value to fit the scale of the typecode
501
val = val.substring( 0, val.length() - extra );
502           }
503           else if ( extra < 0 )
504           {
505              StringBuffer JavaDoc sb = new StringBuffer JavaDoc (val);
506
507              // add the decimal point if necessary
508
if ( val.indexOf('.') == -1 )
509              {
510                 sb.append(".");
511              }
512
513              // pad the value with zeros to fit the scale of the typecode
514
for ( int i = extra; i < 0; i++ )
515              {
516                 sb.append("0");
517              }
518              val = sb.toString();
519           }
520           _value = new java.math.BigDecimal JavaDoc( val );
521
522           org.omg.CORBA.FixedHolder JavaDoc holder =
523              new org.omg.CORBA.FixedHolder JavaDoc( _value );
524           org.omg.CORBA.TypeCode JavaDoc tc = holder._type();
525
526           if ( tc.fixed_digits() > type.fixed_digits() )
527           {
528              throw new org.omg.CORBA.BAD_TYPECODE JavaDoc();
529           }
530        }
531        catch ( org.omg.CORBA.TypeCodePackage.BadKind JavaDoc bk )
532        {
533           throw new org.omg.CORBA.BAD_TYPECODE JavaDoc();
534        }
535        value = _value;
536        typeCode = type;
537    }
538
539     public java.math.BigDecimal JavaDoc extract_fixed()
540     {
541         checkExtract (TCKind._tk_fixed, "Cannot extract fixed");
542         if (value instanceof CDROutputStream)
543         {
544            return create_input_stream().read_fixed();
545         }
546         return (java.math.BigDecimal JavaDoc)value;
547     }
548
549     // obj refs
550

551     public void insert_Object(org.omg.CORBA.Object JavaDoc o)
552     {
553         value = o;
554
555         org.omg.CORBA.ORB JavaDoc orb = null;
556         String JavaDoc typeId = null;
557         String JavaDoc name = "";
558
559         if (value == null)
560         {
561            orb = org.omg.CORBA.ORB.init();
562            typeId = "IDL:omg.org/CORBA/Object:1.0";
563            name = "Object";
564         }
565         else
566         {
567            orb = ((org.omg.CORBA.portable.ObjectImpl JavaDoc)o)._orb();
568            typeId = ((org.omg.CORBA.portable.ObjectImpl JavaDoc)o)._ids()[0];
569
570            // check if the repository Id is in IDL format
571
if (typeId.startsWith("IDL:"))
572            {
573               // parse the interface name from a repository Id string
574
// like "IDL:some.prefix/Some/Module/TheInterfaceName"
575
name = typeId.substring(4, typeId.lastIndexOf (':'));
576               name = name.substring(name.lastIndexOf ('/') + 1);
577            }
578            else if (typeId.startsWith("RMI:"))
579            {
580               // parse the interface name from a repository Id string
581
// like "RMI:some.java.package.TheInterfaceName"
582
name = typeId.substring(4, typeId.lastIndexOf(':'));
583               name = name.substring(name.lastIndexOf('.') + 1);
584            }
585            else
586            {
587               throw new org.omg.CORBA.BAD_PARAM JavaDoc("Unknown repository id format");
588            }
589         }
590         typeCode = orb.create_interface_tc( typeId , name );
591     }
592
593     public void insert_Object (org.omg.CORBA.Object JavaDoc o,
594                                org.omg.CORBA.TypeCode JavaDoc type)
595     {
596         if( type.kind().value() != TCKind._tk_objref )
597             tc_error("Illegal, non-object TypeCode!");
598
599         if( value == null )
600         {
601             orb = org.omg.CORBA.ORB.init();
602         }
603         else
604         {
605             orb = ((org.omg.CORBA.portable.ObjectImpl JavaDoc)o)._orb();
606         }
607         value = o;
608         typeCode = type;
609     }
610
611     public org.omg.CORBA.Object JavaDoc extract_Object()
612     {
613         checkExtract (TCKind._tk_objref, "Cannot extract object");
614         if (value instanceof CDROutputStream)
615         {
616            return create_input_stream().read_Object();
617         }
618         return (org.omg.CORBA.Object JavaDoc)value;
619     }
620
621     // workaround: as long as local objects don't have stubs, we need to
622
// return *Java* objects
623

624     public java.lang.Object JavaDoc extract_objref()
625     {
626         checkExtract (TCKind._tk_objref, "Cannot extract object");
627         return value;
628     }
629
630     // Principal (deprecated)
631

632     public void insert_Principal (org.omg.CORBA.Principal JavaDoc p)
633     {
634         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("Principal deprecated");
635     }
636
637     public org.omg.CORBA.Principal JavaDoc extract_Principal()
638     {
639         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("Principal deprecated");
640     }
641
642     public void insert_Streamable (org.omg.CORBA.portable.Streamable JavaDoc s)
643     {
644         value = s;
645         typeCode = s._type();
646     }
647
648     public org.omg.CORBA.portable.Streamable JavaDoc extract_Streamable()
649         throws org.omg.CORBA.BAD_INV_ORDER JavaDoc
650     {
651         try
652         {
653             return (org.omg.CORBA.portable.Streamable JavaDoc)value;
654         }
655         catch ( ClassCastException JavaDoc cce )
656         {
657             throw new org.omg.CORBA.BAD_INV_ORDER JavaDoc();
658         }
659     }
660
661     public java.io.Serializable JavaDoc extract_Value()
662         throws org.omg.CORBA.BAD_OPERATION JavaDoc
663     {
664         int kind = typeCode.kind().value();
665         if (kind != TCKind._tk_value &&
666         kind != TCKind._tk_value_box &&
667         kind != TCKind._tk_abstract_interface &&
668             kind != TCKind._tk_null)
669     {
670             tc_error ("Cannot extract value!");
671     }
672         return (java.io.Serializable JavaDoc)value;
673     }
674
675
676     public void insert_Value(java.io.Serializable JavaDoc value)
677     {
678         if (value != null)
679         {
680             this.value = value;
681             this.typeCode = TypeCode.create_tc (value.getClass());
682         }
683         else
684         {
685             this.value = null;
686             this.typeCode = new TypeCode (TCKind._tk_null);
687         }
688     }
689
690     public void insert_Value(java.io.Serializable JavaDoc value, org.omg.CORBA.TypeCode JavaDoc type)
691         throws org.omg.CORBA.MARSHAL JavaDoc
692     {
693         this.value = value;
694         this.typeCode = type;
695     }
696
697     // portable
698

699     public org.omg.CORBA.portable.OutputStream JavaDoc create_output_stream()
700     {
701         if(!( orb instanceof org.jacorb.orb.ORB ))
702             value = new CDROutputStream();
703         else
704             value = new CDROutputStream(orb);
705         return (CDROutputStream)value;
706     }
707
708     public org.omg.CORBA.portable.InputStream JavaDoc create_input_stream()
709     {
710         if( value instanceof org.jacorb.orb.CDROutputStream )
711         {
712             return new org.jacorb.orb.CDRInputStream( orb, ((CDROutputStream)value).getBufferCopy());
713         }
714         else
715         {
716             org.jacorb.orb.CDROutputStream out;
717             if( !( orb instanceof org.jacorb.orb.ORB ))
718                 out = new org.jacorb.orb.CDROutputStream();
719             else
720                 out = new org.jacorb.orb.CDROutputStream(orb);
721             write_value(out);
722             return new org.jacorb.orb.CDRInputStream(orb, out.getBufferCopy());
723         }
724     }
725
726     public void read_value (org.omg.CORBA.portable.InputStream JavaDoc input,
727                             org.omg.CORBA.TypeCode JavaDoc type)
728         throws org.omg.CORBA.MARSHAL JavaDoc
729     {
730         if (type == null)
731         {
732            throw new org.omg.CORBA.BAD_PARAM JavaDoc("TypeCode is null");
733         }
734         typeCode = type;
735
736         int kind = type.kind().value();
737         switch (kind)
738         {
739         case TCKind._tk_null:
740             break;
741         case TCKind._tk_void:
742             break;
743         case TCKind._tk_short:
744             insert_short( input.read_short());
745             break;
746         case TCKind._tk_long:
747             insert_long( input.read_long());
748             break;
749         case TCKind._tk_longlong:
750             insert_longlong( input.read_longlong());
751             break;
752         case TCKind._tk_ushort:
753             insert_ushort(input.read_ushort());
754             break;
755         case TCKind._tk_ulong:
756             insert_ulong( input.read_ulong());
757             break;
758         case TCKind._tk_ulonglong:
759             insert_ulonglong( input.read_ulonglong());
760             break;
761         case TCKind._tk_float:
762             insert_float( input.read_float());
763             break;
764         case TCKind._tk_double:
765             insert_double( input.read_double());
766             break;
767         case TCKind._tk_fixed:
768             try
769             {
770                // move the decimal based on the scale
771
java.math.BigDecimal JavaDoc fixed = input.read_fixed();
772                int scale = (int)type.fixed_scale();
773                insert_fixed( fixed.movePointLeft( scale ), type );
774             }
775             catch( org.omg.CORBA.TypeCodePackage.BadKind JavaDoc bk ){}
776             break;
777         case TCKind._tk_boolean:
778             insert_boolean( input.read_boolean());
779             break;
780         case TCKind._tk_char:
781             insert_char( input.read_char());
782             break;
783         case TCKind._tk_wchar:
784             insert_wchar( input.read_wchar());
785             break;
786         case TCKind._tk_octet:
787             insert_octet( input.read_octet());
788             break;
789         case TCKind._tk_any:
790             insert_any( input.read_any());
791             break;
792         case TCKind._tk_TypeCode:
793             insert_TypeCode( input.read_TypeCode());
794             break;
795         case TCKind._tk_Principal:
796             throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("Principal deprecated");
797         case TCKind._tk_objref:
798             insert_Object( input.read_Object());
799             break;
800         case TCKind._tk_string:
801             insert_string( input.read_string());
802             break;
803         case TCKind._tk_wstring:
804             insert_wstring( input.read_wstring());
805             break;
806         case TCKind._tk_array:
807         case TCKind._tk_sequence:
808         case TCKind._tk_struct:
809         case TCKind._tk_except:
810         case TCKind._tk_enum:
811         case TCKind._tk_union:
812         case TCKind._tk_alias:
813             if(! (orb instanceof org.jacorb.orb.ORB) )
814                 value = new CDROutputStream();
815             else
816                 value = new CDROutputStream(orb);
817             ((CDROutputStream)value).write_value(type, input);
818             break;
819         case TCKind._tk_value:
820         case TCKind._tk_value_box:
821             insert_Value
822                 (((org.omg.CORBA_2_3.portable.InputStream JavaDoc)input).read_value(),
823                  type);
824             break;
825         case TCKind._tk_abstract_interface:
826            java.lang.Object JavaDoc obj =
827               ((org.omg.CORBA_2_3.portable.InputStream JavaDoc)input).read_abstract_interface();
828            if (obj instanceof org.omg.CORBA.Object JavaDoc)
829               insert_Object((org.omg.CORBA.Object JavaDoc)obj);
830            else
831               insert_Value((java.io.Serializable JavaDoc)obj);
832            break;
833         default:
834             throw new BAD_TYPECODE("Cannot handle TypeCode with kind " + kind);
835         }
836     }
837
838     public void write_value (org.omg.CORBA.portable.OutputStream JavaDoc output)
839     {
840         int kind = typeCode.kind().value();
841
842         switch (kind)
843         {
844         case TCKind._tk_null:
845             break;
846         case TCKind._tk_void:
847             break;
848         case TCKind._tk_short:
849             output.write_short(extract_short());
850             break;
851         case TCKind._tk_long:
852             output.write_long(extract_long());
853             break;
854         case TCKind._tk_longlong:
855             output.write_longlong(extract_longlong());
856             break;
857         case TCKind._tk_ushort:
858             output.write_ushort(extract_ushort());
859             break;
860         case TCKind._tk_ulong:
861             output.write_ulong(extract_ulong());
862             break;
863         case TCKind._tk_ulonglong:
864             output.write_ulonglong(extract_ulonglong());
865             break;
866         case TCKind._tk_float:
867             output.write_float(extract_float());
868             break;
869         case TCKind._tk_double:
870             output.write_double(extract_double());
871             break;
872         case TCKind._tk_fixed:
873             output.write_fixed(extract_fixed());
874             break;
875         case TCKind._tk_boolean:
876             output.write_boolean(extract_boolean());
877             break;
878         case TCKind._tk_char:
879             output.write_char(extract_char());
880             break;
881         case TCKind._tk_wchar:
882             output.write_wchar(extract_wchar());
883             break;
884         case TCKind._tk_octet:
885             output.write_octet(extract_octet());
886             break;
887         case TCKind._tk_any:
888             output.write_any(extract_any());
889             break;
890         case TCKind._tk_TypeCode:
891             output.write_TypeCode(extract_TypeCode());
892             break;
893         case TCKind._tk_Principal:
894             throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("Principal deprecated");
895         case TCKind._tk_objref:
896             output.write_Object(extract_Object());
897             break;
898         case TCKind._tk_string:
899             output.write_string(extract_string());
900             break;
901         case TCKind._tk_wstring:
902             output.write_wstring(extract_wstring());
903             break;
904         case TCKind._tk_struct:
905         case TCKind._tk_except:
906         case TCKind._tk_enum:
907         case TCKind._tk_union:
908         case TCKind._tk_array:
909         case TCKind._tk_sequence:
910         case TCKind._tk_alias:
911             try
912             {
913                 if (value instanceof org.omg.CORBA.portable.Streamable JavaDoc)
914                 {
915                     org.omg.CORBA.portable.Streamable JavaDoc s =
916                         (org.omg.CORBA.portable.Streamable JavaDoc)value;
917                     s._write(output);
918                 }
919                 else if (value instanceof org.omg.CORBA.portable.OutputStream JavaDoc)
920                 {
921                     // Use ORB from CDROutputStream if Any has been created
922
// from ORBSingleton.
923

924                     org.omg.CORBA.ORB JavaDoc toUse = orb;
925                     if (! (toUse instanceof org.jacorb.orb.ORB))
926                     {
927                         toUse = ((CDROutputStream)output).orb();
928                     }
929                     CDROutputStream os = (CDROutputStream)value;
930                     CDRInputStream in = new CDRInputStream(toUse, os.getBufferCopy());
931
932                     in.read_value (typeCode, output);
933                 }
934                 break;
935             }
936             catch( Exception JavaDoc e )
937             {
938                 e.printStackTrace();
939                 throw new INTERNAL( e.getMessage());
940             }
941         case TCKind._tk_value:
942         case TCKind._tk_value_box:
943             ((org.omg.CORBA_2_3.portable.OutputStream JavaDoc)output)
944                 .write_value((java.io.Serializable JavaDoc)value);
945             break;
946         case TCKind._tk_abstract_interface:
947             ((org.omg.CORBA_2_3.portable.OutputStream JavaDoc)output)
948                 .write_abstract_interface(value);
949             break;
950         default:
951             throw new BAD_TYPECODE("Cannot handle TypeCode with kind " + kind);
952         }
953     }
954
955     // other, proprietary
956

957     public void insert_void()
958     {
959         value = null;
960         typeCode = orb.get_primitive_tc(TCKind.tk_void);
961     }
962
963     /**
964      * Convenience method for making a shallow copy of an Any.
965      */

966     public void insert_object(org.omg.CORBA.TypeCode JavaDoc typeCode,
967                               java.lang.Object JavaDoc value)
968     {
969         insert_object( typeCode, null, value );
970     }
971
972     /**
973      * Convenience method for making a shallow copy of an Any.
974      */

975     public void insert_object(org.omg.CORBA.TypeCode JavaDoc typeCode,
976                               org.omg.CORBA.ORB JavaDoc orb,
977                               java.lang.Object JavaDoc value)
978     {
979         this.typeCode = typeCode;
980         if( orb != null )
981             this.orb = orb;
982         this.value = value;
983     }
984 }
985
Popular Tags