KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > corba > TypeCodeImpl


1 /*
2  * @(#)TypeCodeImpl.java 1.94 04/06/21
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.corba;
9
10 import java.util.HashMap JavaDoc;
11 import java.util.Map JavaDoc;
12 import java.util.Iterator JavaDoc;
13 import java.util.List JavaDoc;
14 import java.util.Collections JavaDoc;
15 import java.util.ArrayList JavaDoc;
16 import java.io.IOException JavaDoc;
17 import java.io.PrintStream JavaDoc;
18 import java.io.ByteArrayOutputStream JavaDoc;
19 import java.math.BigDecimal JavaDoc;
20 import java.math.BigInteger JavaDoc;
21
22 import org.omg.CORBA.TypeCode JavaDoc ;
23 import org.omg.CORBA.StructMember JavaDoc ;
24 import org.omg.CORBA.UnionMember JavaDoc ;
25 import org.omg.CORBA.ValueMember JavaDoc ;
26 import org.omg.CORBA.TCKind JavaDoc ;
27 import org.omg.CORBA.Any JavaDoc ;
28 import org.omg.CORBA.Principal JavaDoc ;
29 import org.omg.CORBA.BAD_TYPECODE JavaDoc ;
30 import org.omg.CORBA.BAD_PARAM JavaDoc ;
31 import org.omg.CORBA.BAD_OPERATION JavaDoc ;
32 import org.omg.CORBA.INTERNAL JavaDoc ;
33 import org.omg.CORBA.MARSHAL JavaDoc ;
34 import org.omg.CORBA.TypeCodePackage.BadKind JavaDoc ;
35 import org.omg.CORBA_2_3.portable.InputStream JavaDoc;
36 import org.omg.CORBA_2_3.portable.OutputStream JavaDoc;
37
38 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
39 import com.sun.corba.se.spi.orb.ORB;
40 import com.sun.corba.se.spi.logging.CORBALogDomains;
41
42 import com.sun.corba.se.impl.encoding.OSFCodeSetRegistry;
43 import com.sun.corba.se.impl.encoding.MarshalInputStream;
44 import com.sun.corba.se.impl.encoding.CodeSetConversion;
45 import com.sun.corba.se.impl.encoding.CDRInputStream;
46 import com.sun.corba.se.impl.encoding.CDROutputStream;
47 import com.sun.corba.se.impl.encoding.TypeCodeInputStream;
48 import com.sun.corba.se.impl.encoding.TypeCodeOutputStream;
49 import com.sun.corba.se.impl.encoding.TypeCodeReader;
50 import com.sun.corba.se.impl.encoding.WrapperInputStream;
51
52 import com.sun.corba.se.impl.logging.ORBUtilSystemException;
53
54 // no chance of subclasses, so no problems with runtime helper lookup
55
public final class TypeCodeImpl extends TypeCode JavaDoc
56 {
57     //static final boolean debug = false;
58

59     // the indirection TCKind, needed for recursive typecodes.
60
protected static final int tk_indirect = 0xFFFFFFFF;
61   
62     // typecode encodings have three different categories that determine
63
// how the encoding should be done.
64

65     private static final int EMPTY = 0; // no parameters
66
private static final int SIMPLE = 1; // simple parameters.
67
private static final int COMPLEX = 2; // complex parameters. need to
68
// use CDR encapsulation for
69
// parameters
70

71     // a table storing the encoding category for the various typecodes.
72

73     private static final int typeTable[] = {
74     EMPTY, // tk_null
75
EMPTY, // tk_void
76
EMPTY, // tk_short
77
EMPTY, // tk_long
78
EMPTY, // tk_ushort
79
EMPTY, // tk_ulong
80
EMPTY, // tk_float
81
EMPTY, // tk_double
82
EMPTY, // tk_boolean
83
EMPTY, // tk_char
84
EMPTY, // tk_octet
85
EMPTY, // tk_any
86
EMPTY, // tk_typecode
87
EMPTY, // tk_principal
88
COMPLEX, // tk_objref
89
COMPLEX, // tk_struct
90
COMPLEX, // tk_union
91
COMPLEX, // tk_enum
92
SIMPLE, // tk_string
93
COMPLEX, // tk_sequence
94
COMPLEX, // tk_array
95
COMPLEX, // tk_alias
96
COMPLEX, // tk_except
97
EMPTY, // tk_longlong
98
EMPTY, // tk_ulonglong
99
EMPTY, // tk_longdouble
100
EMPTY, // tk_wchar
101
SIMPLE, // tk_wstring
102
SIMPLE, // tk_fixed
103
COMPLEX, // tk_value
104
COMPLEX, // tk_value_box
105
COMPLEX, // tk_native
106
COMPLEX // tk_abstract_interface
107
};
108
109     // Maps TCKind values to names
110
// This is also used in AnyImpl.
111
static final String JavaDoc[] kindNames = {
112         "null",
113         "void",
114         "short",
115         "long",
116         "ushort",
117         "ulong",
118         "float",
119         "double",
120         "boolean",
121         "char",
122         "octet",
123         "any",
124         "typecode",
125         "principal",
126         "objref",
127         "struct",
128         "union",
129         "enum",
130         "string",
131         "sequence",
132         "array",
133         "alias",
134         "exception",
135         "longlong",
136         "ulonglong",
137         "longdouble",
138         "wchar",
139         "wstring",
140         "fixed",
141         "value",
142         "valueBox",
143         "native",
144         "abstractInterface"
145     };
146
147     private int _kind = 0; // the typecode kind
148

149     // data members for representing the various kinds of typecodes.
150
private String JavaDoc _id = ""; // the typecode repository id
151
private String JavaDoc _name = ""; // the typecode name
152
private int _memberCount = 0; // member count
153
private String JavaDoc _memberNames[] = null; // names of members
154
private TypeCodeImpl _memberTypes[] = null; // types of members
155
private AnyImpl _unionLabels[] = null; // values of union labels
156
private TypeCodeImpl _discriminator = null; // union discriminator type
157
private int _defaultIndex = -1; // union default index
158
private int _length = 0; // string/seq/array length
159
private TypeCodeImpl _contentType = null; // seq/array/alias type
160
// fixed
161
private short _digits = 0;
162     private short _scale = 0;
163     // value type
164
// _REVISIT_ We might want to keep references to the ValueMember classes
165
// passed in at initialization instead of copying the relevant data.
166
// Is the data immutable? What about StructMember, UnionMember etc.?
167
private short _type_modifier = -1; // VM_NONE, VM_CUSTOM,
168
// VM_ABSTRACT, VM_TRUNCATABLE
169
private TypeCodeImpl _concrete_base = null; // concrete base type
170
private short _memberAccess[] = null; // visibility of ValueMember
171
// recursive sequence support
172
private TypeCodeImpl _parent = null; // the enclosing type code
173
private int _parentOffset = 0; // the level of enclosure
174
// recursive type code support
175
private TypeCodeImpl _indirectType = null;
176
177     // caches the byte buffer written in write_value for quick remarshaling...
178
private byte[] outBuffer = null;
179     // ... but only if caching is enabled
180
private boolean cachingEnabled = false;
181
182     // the ORB instance: may be instanceof ORBSingleton or ORB
183
private ORB _orb;
184     private ORBUtilSystemException wrapper ;
185
186     ///////////////////////////////////////////////////////////////////////////
187
// Constructors...
188

189     public TypeCodeImpl(ORB orb)
190     {
191     // initialized to tk_null
192
_orb = orb;
193     wrapper = ORBUtilSystemException.get(
194         (com.sun.corba.se.spi.orb.ORB)orb, CORBALogDomains.RPC_PRESENTATION ) ;
195     }
196       
197     public TypeCodeImpl(ORB orb, TypeCode JavaDoc tc)
198     // to handle conversion of "remote" typecodes into "native" style.
199
// also see the 'convertToNative(ORB orb, TypeCode tc)' function
200
{
201     this(orb) ;
202
203     // This is a protection against misuse of this constructor.
204
// Should only be used if tc is not an instance of this class!
205
// Otherwise we run into problems with recursive/indirect type codes.
206
// _REVISIT_ We should make this constructor private
207
if (tc instanceof TypeCodeImpl) {
208         TypeCodeImpl tci = (TypeCodeImpl)tc;
209         if (tci._kind == tk_indirect)
210         throw wrapper.badRemoteTypecode() ;
211         if (tci._kind == TCKind._tk_sequence && tci._contentType == null)
212         throw wrapper.badRemoteTypecode() ;
213     }
214
215     // set up kind
216
_kind = tc.kind().value();
217
218     try {
219         // set up parameters
220
switch (_kind) {
221         case TCKind._tk_value:
222         _type_modifier = tc.type_modifier();
223         // concrete base may be null
224
TypeCode JavaDoc tccb = tc.concrete_base_type();
225         if (tccb != null) {
226             _concrete_base = convertToNative(_orb, tccb);
227         } else {
228             _concrete_base = null;
229         }
230         //_memberAccess = tc._memberAccess;
231
// Need to reconstruct _memberAccess using member_count() and member_visibility()
232
_memberAccess = new short[tc.member_count()];
233         for (int i=0; i < tc.member_count(); i++) {
234             _memberAccess[i] = tc.member_visibility(i);
235         }
236         case TCKind._tk_except:
237         case TCKind._tk_struct:
238         case TCKind._tk_union:
239         // set up member types
240
_memberTypes = new TypeCodeImpl[tc.member_count()];
241         for (int i=0; i < tc.member_count(); i++) {
242             _memberTypes[i] = convertToNative(_orb, tc.member_type(i));
243             _memberTypes[i].setParent(this);
244         }
245         case TCKind._tk_enum:
246         // set up member names
247
_memberNames = new String JavaDoc[tc.member_count()];
248         for (int i=0; i < tc.member_count(); i++) {
249             _memberNames[i] = tc.member_name(i);
250         }
251         // set up member count
252
_memberCount = tc.member_count();
253         case TCKind._tk_objref:
254         case TCKind._tk_alias:
255         case TCKind._tk_value_box:
256         case TCKind._tk_native:
257         case TCKind._tk_abstract_interface:
258         setId(tc.id());
259         _name = tc.name();
260         break;
261         }
262       
263         // set up stuff for unions
264
switch (_kind) {
265         case TCKind._tk_union:
266         _discriminator = convertToNative(_orb, tc.discriminator_type());
267         _defaultIndex = tc.default_index();
268         _unionLabels = new AnyImpl[_memberCount];
269         for (int i=0; i < _memberCount; i++)
270             _unionLabels[i] = new AnyImpl(_orb, tc.member_label(i));
271         break;
272         }
273       
274         // set up length
275
switch (_kind) {
276         case TCKind._tk_string:
277         case TCKind._tk_wstring:
278         case TCKind._tk_sequence:
279         case TCKind._tk_array:
280         _length = tc.length();
281         }
282       
283         // set up content type
284
switch (_kind) {
285         case TCKind._tk_sequence:
286         case TCKind._tk_array:
287         case TCKind._tk_alias:
288         case TCKind._tk_value_box:
289         _contentType = convertToNative(_orb, tc.content_type());
290         }
291     } catch (org.omg.CORBA.TypeCodePackage.Bounds JavaDoc e) {} catch (BadKind JavaDoc e) {}
292     // dont have to worry about these since code ensures we dont step
293
// out of bounds.
294
}
295     
296     public TypeCodeImpl(ORB orb, int creationKind)
297     // for primitive types
298
{
299     this(orb);
300
301     // private API. dont bother checking that
302
// (creationKind < 0 || creationKind > typeTable.length)
303

304     _kind = creationKind;
305
306     // do initialization for special cases
307
switch (_kind) {
308     case TCKind._tk_objref:
309         {
310         // this is being used to create typecode for CORBA::Object
311
setId("IDL:omg.org/CORBA/Object:1.0");
312         _name = "Object";
313         break;
314         }
315
316     case TCKind._tk_string:
317     case TCKind._tk_wstring:
318         {
319         _length =0;
320         break;
321         }
322
323     case TCKind._tk_value:
324         {
325         _concrete_base = null;
326         break;
327         }
328     }
329     }
330
331     public TypeCodeImpl(ORB orb,
332             int creationKind,
333             String JavaDoc id,
334             String JavaDoc name,
335             StructMember JavaDoc[] members)
336             // for structs and exceptions
337
{
338     this(orb);
339
340     if ((creationKind == TCKind._tk_struct) || (creationKind == TCKind._tk_except)) {
341         _kind = creationKind;
342         setId(id);
343         _name = name;
344         _memberCount = members.length;
345     
346         _memberNames = new String JavaDoc[_memberCount];
347         _memberTypes = new TypeCodeImpl[_memberCount];
348
349         for (int i = 0 ; i < _memberCount ; i++) {
350         _memberNames[i] = members[i].name;
351         _memberTypes[i] = convertToNative(_orb, members[i].type);
352         _memberTypes[i].setParent(this);
353         }
354     } // else initializes to null
355
}
356
357     public TypeCodeImpl(ORB orb,
358             int creationKind,
359             String JavaDoc id,
360             String JavaDoc name,
361             TypeCode JavaDoc discriminator_type,
362             UnionMember JavaDoc[] members)
363             // for unions
364
{
365     this(orb) ;
366
367     if (creationKind == TCKind._tk_union) {
368         _kind = creationKind;
369         setId(id);
370         _name = name;
371         _memberCount = members.length;
372         _discriminator = convertToNative(_orb, discriminator_type);
373
374         _memberNames = new String JavaDoc[_memberCount];
375         _memberTypes = new TypeCodeImpl[_memberCount];
376         _unionLabels = new AnyImpl[_memberCount];
377
378         for (int i = 0 ; i < _memberCount ; i++) {
379         _memberNames[i] = members[i].name;
380         _memberTypes[i] = convertToNative(_orb, members[i].type);
381         _memberTypes[i].setParent(this);
382         _unionLabels[i] = new AnyImpl(_orb, members[i].label);
383         // check whether this is the default branch.
384
if (_unionLabels[i].type().kind() == TCKind.tk_octet) {
385             if (_unionLabels[i].extract_octet() == (byte)0) {
386             _defaultIndex = i;
387             }
388         }
389         }
390     } // else initializes to null
391
}
392
393     public TypeCodeImpl(ORB orb,
394             int creationKind,
395             String JavaDoc id,
396             String JavaDoc name,
397             short type_modifier,
398             TypeCode JavaDoc concrete_base,
399             ValueMember JavaDoc[] members)
400             // for value types
401
{
402     this(orb) ;
403
404     if (creationKind == TCKind._tk_value) {
405         _kind = creationKind;
406         setId(id);
407         _name = name;
408         _type_modifier = type_modifier;
409         if (_concrete_base != null) {
410         _concrete_base = convertToNative(_orb, concrete_base);
411         }
412         _memberCount = members.length;
413
414         _memberNames = new String JavaDoc[_memberCount];
415         _memberTypes = new TypeCodeImpl[_memberCount];
416         _memberAccess = new short[_memberCount];
417
418         for (int i = 0 ; i < _memberCount ; i++) {
419         _memberNames[i] = members[i].name;
420         _memberTypes[i] = convertToNative(_orb, members[i].type);
421         _memberTypes[i].setParent(this);
422         _memberAccess[i] = members[i].access;
423         }
424     } // else initializes to null
425
}
426
427
428     public TypeCodeImpl(ORB orb,
429             int creationKind,
430             String JavaDoc id,
431             String JavaDoc name,
432             String JavaDoc[] members)
433             // for enums
434
{
435     this(orb) ;
436
437     if (creationKind == TCKind._tk_enum)
438         {
439         _kind = creationKind;
440         setId(id);
441         _name = name;
442         _memberCount = members.length;
443
444         _memberNames = new String JavaDoc[_memberCount];
445
446         for (int i = 0 ; i < _memberCount ; i++)
447             _memberNames[i] = members[i];
448         } // else initializes to null
449
}
450
451     public TypeCodeImpl(ORB orb,
452             int creationKind,
453             String JavaDoc id,
454             String JavaDoc name,
455             TypeCode JavaDoc original_type)
456             // for aliases and value boxes
457
{
458     this(orb) ;
459
460     if ( creationKind == TCKind._tk_alias || creationKind == TCKind._tk_value_box )
461         {
462         _kind = creationKind;
463         setId(id);
464         _name = name;
465         _contentType = convertToNative(_orb, original_type);
466         }
467     // else initializes to null
468

469     }
470
471     public TypeCodeImpl(ORB orb,
472             int creationKind,
473             String JavaDoc id,
474             String JavaDoc name)
475     {
476     this(orb) ;
477
478     if (creationKind == TCKind._tk_objref ||
479         creationKind == TCKind._tk_native ||
480         creationKind == TCKind._tk_abstract_interface)
481         {
482         _kind = creationKind;
483         setId(id);
484         _name = name;
485         } // else initializes to null
486
}
487
488       
489     public TypeCodeImpl(ORB orb,
490             int creationKind,
491             int bound)
492             // for strings
493
{
494     this(orb) ;
495
496     if (bound < 0)
497         throw wrapper.negativeBounds() ;
498
499     if ((creationKind == TCKind._tk_string) || (creationKind == TCKind._tk_wstring)) {
500         _kind = creationKind;
501         _length = bound;
502     } // else initializes to null
503
}
504
505     public TypeCodeImpl(ORB orb,
506             int creationKind,
507             int bound,
508             TypeCode JavaDoc element_type)
509             // for sequences and arrays
510
{
511     this(orb) ;
512
513     if ( creationKind == TCKind._tk_sequence || creationKind == TCKind._tk_array ) {
514         _kind = creationKind;
515         _length = bound;
516         _contentType = convertToNative(_orb, element_type);
517     } // else initializes to null
518
}
519       
520     public TypeCodeImpl(ORB orb,
521             int creationKind,
522             int bound,
523             int offset)
524             // for recursive sequences
525
{
526     this(orb) ;
527
528     if (creationKind == TCKind._tk_sequence) {
529         _kind = creationKind;
530         _length = bound;
531         _parentOffset = offset;
532     } // else initializes to null
533
}
534
535     public TypeCodeImpl(ORB orb,
536             String JavaDoc id)
537             // for recursive type codes
538
{
539     this(orb) ;
540
541     _kind = tk_indirect;
542     // This is the type code of the type we stand in for, not our own.
543
_id = id;
544     // Try to resolve it now. May return null in which case
545
// we try again later (see indirectType()).
546
tryIndirectType();
547     }
548
549     public TypeCodeImpl(ORB orb,
550             int creationKind,
551             short digits,
552             short scale)
553             // for fixed
554
{
555     this(orb) ;
556
557     //if (digits < 1 || digits > 31)
558
//throw new BAD_TYPECODE();
559

560     if (creationKind == TCKind._tk_fixed) {
561         _kind = creationKind;
562         _digits = digits;
563         _scale = scale;
564     } // else initializes to null
565
}
566
567     ///////////////////////////////////////////////////////////////////////////
568
// Other creation functions...
569

570     // Optimization:
571
// If we checked for and returned constant primitive typecodes
572
// here we could reduce object creation and also enable more
573
// efficient typecode comparisons for primitive typecodes.
574
//
575
protected static TypeCodeImpl convertToNative(ORB orb,
576                           TypeCode JavaDoc tc)
577     {
578     if (tc instanceof TypeCodeImpl)
579         return (TypeCodeImpl) tc;
580     else
581         return new TypeCodeImpl(orb, tc);
582     }
583
584     public static CDROutputStream newOutputStream(ORB orb) {
585     TypeCodeOutputStream tcos = new TypeCodeOutputStream((ORB)orb);
586     //if (debug) System.out.println("Created TypeCodeOutputStream " + tcos +
587
// " with no parent");
588
return tcos;
589     }
590
591     // Support for indirect/recursive type codes
592

593     private TypeCodeImpl indirectType() {
594     _indirectType = tryIndirectType();
595     if (_indirectType == null) {
596         // Nothing we can do about that.
597
throw wrapper.unresolvedRecursiveTypecode() ;
598     }
599     return _indirectType;
600     }
601
602     private TypeCodeImpl tryIndirectType() {
603     // Assert that _kind == tk_indirect
604
if (_indirectType != null)
605         return _indirectType;
606
607     setIndirectType(_orb.getTypeCode(_id));
608
609     return _indirectType;
610     }
611
612     private void setIndirectType(TypeCodeImpl newType) {
613     _indirectType = newType;
614     if (_indirectType != null) {
615         try {
616         _id = _indirectType.id();
617         } catch (BadKind JavaDoc e) {
618         // can't happen
619
throw wrapper.badkindCannotOccur() ;
620         }
621     }
622     }
623
624     private void setId(String JavaDoc newID) {
625     _id = newID;
626     if (_orb instanceof TypeCodeFactory) {
627         ((TypeCodeFactory)_orb).setTypeCode(_id, this);
628     }
629     // check whether return value != this which would indicate that the
630
// repository id isn't unique.
631
}
632
633     private void setParent(TypeCodeImpl parent) {
634     _parent = parent;
635     }
636
637     private TypeCodeImpl getParentAtLevel(int level) {
638     if (level == 0)
639         return this;
640
641     if (_parent == null)
642         throw wrapper.unresolvedRecursiveTypecode() ;
643
644     return _parent.getParentAtLevel(level - 1);
645     }
646
647     private TypeCodeImpl lazy_content_type() {
648     if (_contentType == null) {
649         if (_kind == TCKind._tk_sequence && _parentOffset > 0 && _parent != null) {
650         // This is an unresolved recursive sequence tc.
651
// Try to resolve it now if the hierarchy is complete.
652
TypeCodeImpl realParent = getParentAtLevel(_parentOffset);
653         if (realParent != null && realParent._id != null) {
654             // Create a recursive type code object as the content type.
655
// This is when the recursive sequence typecode morphes
656
// into a sequence typecode containing a recursive typecode.
657
_contentType = new TypeCodeImpl((ORB)_orb, realParent._id);
658         }
659         }
660     }
661     return _contentType;
662     }
663
664     // Other private functions
665

666     private TypeCode JavaDoc realType(TypeCode JavaDoc aType) {
667     TypeCode JavaDoc realType = aType;
668     try {
669         // Note: Indirect types are handled in kind() method
670
while (realType.kind().value() == TCKind._tk_alias) {
671         realType = realType.content_type();
672         }
673     } catch (BadKind JavaDoc bad) {
674         // impossible
675
throw wrapper.badkindCannotOccur() ;
676     }
677     return realType;
678     }
679
680     ///////////////////////////////////////////////////////////////////////////
681
// TypeCode operations
682

683     public final boolean equal(TypeCode JavaDoc tc)
684     // _REVISIT_ for all optional names/ids, we might want to check that
685
// they are equal in case both are non-nil.
686
{
687     if (tc == this)
688         return true;
689
690     try {
691
692         if (_kind == tk_indirect) {
693         //return indirectType().equal(tc);
694
if (_id != null && tc.id() != null)
695             return _id.equals(tc.id());
696         return (_id == null && tc.id() == null);
697         }
698
699         // make sure kinds are identical.
700
if (_kind != tc.kind().value()) {
701         return false;
702         }
703
704         switch (typeTable[_kind]) {
705         case EMPTY:
706         // no parameters to check.
707
return true;
708       
709         case SIMPLE:
710         switch (_kind) {
711         case TCKind._tk_string:
712         case TCKind._tk_wstring:
713             // check for bound.
714
return (_length == tc.length());
715
716         case TCKind._tk_fixed:
717             return (_digits == tc.fixed_digits() && _scale == tc.fixed_scale());
718         default:
719             return false;
720         }
721       
722         case COMPLEX:
723
724         switch(_kind) {
725
726         case TCKind._tk_objref:
727             {
728             // check for logical id.
729
if (_id.compareTo(tc.id()) == 0) {
730                 return true;
731             }
732
733             if (_id.compareTo(
734                             (_orb.get_primitive_tc(_kind)).id()) == 0)
735                         {
736                 return true;
737             }
738
739             if (tc.id().compareTo(
740                             (_orb.get_primitive_tc(_kind)).id()) == 0)
741                         {
742                 return true;
743             }
744
745             return false;
746             }
747
748         case TCKind._tk_native:
749         case TCKind._tk_abstract_interface:
750             {
751             // check for logical id.
752
if (_id.compareTo(tc.id()) != 0) {
753                 return false;
754
755             }
756             // ignore name since its optional.
757
return true;
758             }
759
760         case TCKind._tk_struct:
761         case TCKind._tk_except:
762             {
763             // check for member count
764
if (_memberCount != tc.member_count())
765                 return false;
766             // check for repository id
767
if (_id.compareTo(tc.id()) != 0)
768                 return false;
769             // check for member types.
770
for (int i = 0 ; i < _memberCount ; i++)
771                 if (! _memberTypes[i].equal(tc.member_type(i)))
772                 return false;
773             // ignore id and names since those are optional.
774
return true;
775             }
776
777         case TCKind._tk_union:
778             {
779             // check for member count
780
if (_memberCount != tc.member_count())
781                 return false;
782             // check for repository id
783
if (_id.compareTo(tc.id()) != 0)
784                 return false;
785             // check for default index
786
if (_defaultIndex != tc.default_index())
787                 return false;
788             // check for discriminator type
789
if (!_discriminator.equal(tc.discriminator_type()))
790                 return false;
791             // check for label types and values
792
for (int i = 0 ; i < _memberCount ; i++)
793                 if (! _unionLabels[i].equal(tc.member_label(i)))
794                 return false;
795             // check for branch types
796
for (int i = 0 ; i < _memberCount ; i++)
797                 if (! _memberTypes[i].equal(tc.member_type(i)))
798                 return false;
799             // ignore id and names since those are optional.
800
return true;
801             }
802
803         case TCKind._tk_enum:
804             {
805             // check for repository id
806
if (_id.compareTo(tc.id()) != 0)
807                 return false;
808             // check member count
809
if (_memberCount != tc.member_count())
810                 return false;
811             // ignore names since those are optional.
812
return true;
813             }
814
815         case TCKind._tk_sequence:
816         case TCKind._tk_array:
817             {
818             // check bound/length
819
if (_length != tc.length()) {
820                 return false;
821             }
822             // check content type
823
if (! lazy_content_type().equal(tc.content_type())) {
824                 return false;
825             }
826             // ignore id and name since those are optional.
827
return true;
828             }
829
830         case TCKind._tk_value:
831             {
832             // check for member count
833
if (_memberCount != tc.member_count())
834                 return false;
835             // check for repository id
836
if (_id.compareTo(tc.id()) != 0)
837                 return false;
838             // check for member types.
839
for (int i = 0 ; i < _memberCount ; i++)
840                 if (_memberAccess[i] != tc.member_visibility(i) ||
841                 ! _memberTypes[i].equal(tc.member_type(i)))
842                 return false;
843             if (_type_modifier == tc.type_modifier())
844                 return false;
845             // concrete_base may be null
846
TypeCode JavaDoc tccb = tc.concrete_base_type();
847             if ((_concrete_base == null && tccb != null) ||
848                 (_concrete_base != null && tccb == null) ||
849                 ! _concrete_base.equal(tccb))
850             {
851                 return false;
852             }
853             // ignore id and names since those are optional.
854
return true;
855             }
856
857         case TCKind._tk_alias:
858         case TCKind._tk_value_box:
859             {
860             // check for repository id
861
if (_id.compareTo(tc.id()) != 0) {
862                 return false;
863             }
864             // check for equality with the true type
865
return _contentType.equal(tc.content_type());
866             }
867         }
868         }
869     } catch (org.omg.CORBA.TypeCodePackage.Bounds JavaDoc e) {} catch (BadKind JavaDoc e) {}
870     // dont have to worry about these since the code ensures these dont
871
// arise.
872
return false;
873     }
874
875     /**
876     * The equivalent operation is used by the ORB when determining type equivalence
877     * for values stored in an IDL any.
878     */

879     public boolean equivalent(TypeCode JavaDoc tc) {
880     if (tc == this) {
881         return true;
882     }
883
884     // If the result of the kind operation on either TypeCode is tk_alias, recursively
885
// replace the TypeCode with the result of calling content_type, until the kind
886
// is no longer tk_alias.
887
// Note: Always resolve indirect types first!
888
TypeCode JavaDoc myRealType = (_kind == tk_indirect ? indirectType() : this);
889     myRealType = realType(myRealType);
890     TypeCode JavaDoc otherRealType = realType(tc);
891
892     // If results of the kind operation on each typecode differ,
893
// equivalent returns false.
894
if (myRealType.kind().value() != otherRealType.kind().value()) {
895         return false;
896     }
897
898     String JavaDoc myID = null;
899     String JavaDoc otherID = null;
900     try {
901         myID = this.id();
902         otherID = tc.id();
903         // At this point the id operation is valid for both TypeCodes.
904

905         // Return true if the results of id for both TypeCodes are non-empty strings
906
// and both strings are equal.
907
// If both ids are non-empty but are not equal, then equivalent returns FALSE.
908
if (myID != null && otherID != null) {
909         return (myID.equals(otherID));
910         }
911     } catch (BadKind JavaDoc e) {
912         // id operation is not valid for either or both TypeCodes
913
}
914
915     // If either or both id is an empty string, or the TypeCode kind does not support
916
// the id operation, perform a structural comparison of the TypeCodes.
917

918     int myKind = myRealType.kind().value();
919     try {
920         if (myKind == TCKind._tk_struct ||
921         myKind == TCKind._tk_union ||
922         myKind == TCKind._tk_enum ||
923         myKind == TCKind._tk_except ||
924         myKind == TCKind._tk_value)
925         {
926         if (myRealType.member_count() != otherRealType.member_count())
927             return false;
928         }
929         if (myKind == TCKind._tk_union)
930         {
931         if (myRealType.default_index() != otherRealType.default_index())
932             return false;
933         }
934         if (myKind == TCKind._tk_string ||
935         myKind == TCKind._tk_wstring ||
936         myKind == TCKind._tk_sequence ||
937         myKind == TCKind._tk_array)
938         {
939         if (myRealType.length() != otherRealType.length())
940             return false;
941         }
942         if (myKind == TCKind._tk_fixed)
943         {
944         if (myRealType.fixed_digits() != otherRealType.fixed_digits() ||
945             myRealType.fixed_scale() != otherRealType.fixed_scale())
946             return false;
947         }
948         if (myKind == TCKind._tk_union)
949         {
950         for (int i=0; i<myRealType.member_count(); i++) {
951             if (myRealType.member_label(i) != otherRealType.member_label(i))
952             return false;
953         }
954         if ( ! myRealType.discriminator_type().equivalent(
955             otherRealType.discriminator_type()))
956             return false;
957         }
958         if (myKind == TCKind._tk_alias ||
959         myKind == TCKind._tk_value_box ||
960         myKind == TCKind._tk_sequence ||
961         myKind == TCKind._tk_array)
962         {
963         if ( ! myRealType.content_type().equivalent(otherRealType.content_type()))
964             return false;
965         }
966         if (myKind == TCKind._tk_struct ||
967         myKind == TCKind._tk_union ||
968         myKind == TCKind._tk_except ||
969         myKind == TCKind._tk_value)
970         {
971         for (int i=0; i<myRealType.member_count(); i++) {
972             if ( ! myRealType.member_type(i).equivalent(
973             otherRealType.member_type(i)))
974             return false;
975         }
976         }
977     } catch (BadKind JavaDoc e) {
978         // impossible if we checked correctly above
979
throw wrapper.badkindCannotOccur() ;
980     } catch (org.omg.CORBA.TypeCodePackage.Bounds JavaDoc e) {
981         // impossible if we checked correctly above
982
throw wrapper.boundsCannotOccur() ;
983     }
984
985     // Structural comparison succeeded!
986
return true;
987     }
988
989     public TypeCode JavaDoc get_compact_typecode() {
990     // _REVISIT_ It isn't clear whether this method should operate on this or a copy.
991
// For now just return this unmodified because the name and member_name fields
992
// aren't used for comparison anyways.
993
return this;
994     }
995
996     public TCKind JavaDoc kind()
997     {
998     if (_kind == tk_indirect)
999         return indirectType().kind();
1000    return TCKind.from_int(_kind);
1001    }
1002      
1003    public boolean is_recursive()
1004    {
1005    // Recursive is the only form of indirect type codes right now.
1006
// Indirection can also be used for repeated type codes.
1007
return (_kind == tk_indirect);
1008    }
1009      
1010    public String JavaDoc id()
1011    throws BadKind JavaDoc
1012    {
1013    switch (_kind) {
1014    case tk_indirect:
1015        //return indirectType().id(); // same as _id
1016
case TCKind._tk_except:
1017    case TCKind._tk_objref:
1018    case TCKind._tk_struct:
1019    case TCKind._tk_union:
1020    case TCKind._tk_enum:
1021    case TCKind._tk_alias:
1022    case TCKind._tk_value:
1023    case TCKind._tk_value_box:
1024    case TCKind._tk_native:
1025    case TCKind._tk_abstract_interface:
1026        // exception and objref typecodes must have a repository id.
1027
// structs, unions, enums, and aliases may or may not.
1028
return _id;
1029    default:
1030        // all other typecodes throw the BadKind exception.
1031
throw new BadKind JavaDoc();
1032    }
1033    }
1034
1035    public String JavaDoc name()
1036    throws BadKind JavaDoc
1037    {
1038    switch (_kind) {
1039    case tk_indirect:
1040        return indirectType().name();
1041    case TCKind._tk_except:
1042    case TCKind._tk_objref:
1043    case TCKind._tk_struct:
1044    case TCKind._tk_union:
1045    case TCKind._tk_enum:
1046    case TCKind._tk_alias:
1047    case TCKind._tk_value:
1048    case TCKind._tk_value_box:
1049    case TCKind._tk_native:
1050    case TCKind._tk_abstract_interface:
1051        return _name;
1052    default:
1053        throw new BadKind JavaDoc();
1054    }
1055    }
1056
1057    public int member_count()
1058    throws BadKind JavaDoc
1059    {
1060    switch (_kind) {
1061    case tk_indirect:
1062        return indirectType().member_count();
1063    case TCKind._tk_except:
1064    case TCKind._tk_struct:
1065    case TCKind._tk_union:
1066    case TCKind._tk_enum:
1067    case TCKind._tk_value:
1068        return _memberCount;
1069    default:
1070        throw new BadKind JavaDoc();
1071    }
1072    }
1073
1074    public String JavaDoc member_name(int index)
1075    throws BadKind JavaDoc, org.omg.CORBA.TypeCodePackage.Bounds JavaDoc
1076    {
1077    switch (_kind) {
1078    case tk_indirect:
1079        return indirectType().member_name(index);
1080    case TCKind._tk_except:
1081    case TCKind._tk_struct:
1082    case TCKind._tk_union:
1083    case TCKind._tk_enum:
1084    case TCKind._tk_value:
1085        try {
1086        return _memberNames[index];
1087        } catch (ArrayIndexOutOfBoundsException JavaDoc e) {
1088        throw new org.omg.CORBA.TypeCodePackage.Bounds JavaDoc();
1089        }
1090    default:
1091        throw new BadKind JavaDoc();
1092    }
1093    }
1094
1095    public TypeCode JavaDoc member_type(int index)
1096    throws BadKind JavaDoc, org.omg.CORBA.TypeCodePackage.Bounds JavaDoc
1097    {
1098    switch (_kind) {
1099    case tk_indirect:
1100        return indirectType().member_type(index);
1101    case TCKind._tk_except:
1102    case TCKind._tk_struct:
1103    case TCKind._tk_union:
1104    case TCKind._tk_value:
1105        try {
1106        return _memberTypes[index];
1107        } catch (ArrayIndexOutOfBoundsException JavaDoc e) {
1108        throw new org.omg.CORBA.TypeCodePackage.Bounds JavaDoc();
1109        }
1110    default:
1111        throw new BadKind JavaDoc();
1112    }
1113    }
1114      
1115    public Any JavaDoc member_label(int index)
1116    throws BadKind JavaDoc, org.omg.CORBA.TypeCodePackage.Bounds JavaDoc
1117    {
1118    switch (_kind) {
1119    case tk_indirect:
1120        return indirectType().member_label(index);
1121    case TCKind._tk_union:
1122        try {
1123        // _REVISIT_ Why create a new Any for this?
1124
return new AnyImpl(_orb, _unionLabels[index]);
1125        } catch (ArrayIndexOutOfBoundsException JavaDoc e) {
1126        throw new org.omg.CORBA.TypeCodePackage.Bounds JavaDoc();
1127        }
1128    default:
1129        throw new BadKind JavaDoc();
1130    }
1131    }
1132
1133    public TypeCode JavaDoc discriminator_type()
1134    throws BadKind JavaDoc
1135    {
1136    switch (_kind) {
1137    case tk_indirect:
1138        return indirectType().discriminator_type();
1139    case TCKind._tk_union:
1140        return _discriminator;
1141    default:
1142        throw new BadKind JavaDoc();
1143    }
1144    }
1145
1146    public int default_index()
1147    throws BadKind JavaDoc
1148    {
1149    switch (_kind) {
1150    case tk_indirect:
1151        return indirectType().default_index();
1152    case TCKind._tk_union:
1153        return _defaultIndex;
1154    default:
1155        throw new BadKind JavaDoc();
1156    }
1157    }
1158
1159    public int length()
1160    throws BadKind JavaDoc
1161    {
1162    switch (_kind) {
1163    case tk_indirect:
1164        return indirectType().length();
1165    case TCKind._tk_string:
1166    case TCKind._tk_wstring:
1167    case TCKind._tk_sequence:
1168    case TCKind._tk_array:
1169        return _length;
1170    default:
1171        throw new BadKind JavaDoc();
1172    }
1173    }
1174      
1175    public TypeCode JavaDoc content_type()
1176    throws BadKind JavaDoc
1177    {
1178    switch (_kind) {
1179    case tk_indirect:
1180        return indirectType().content_type();
1181    case TCKind._tk_sequence:
1182        return lazy_content_type();
1183    case TCKind._tk_array:
1184    case TCKind._tk_alias:
1185    case TCKind._tk_value_box:
1186        return _contentType;
1187    default:
1188        throw new BadKind JavaDoc();
1189    }
1190    }
1191
1192    public short fixed_digits() throws BadKind JavaDoc {
1193    switch (_kind) {
1194    case TCKind._tk_fixed:
1195        return _digits;
1196    default:
1197        throw new BadKind JavaDoc();
1198    }
1199    }
1200
1201    public short fixed_scale() throws BadKind JavaDoc {
1202    switch (_kind) {
1203    case TCKind._tk_fixed:
1204        return _scale;
1205    default:
1206        throw new BadKind JavaDoc();
1207    }
1208    }
1209
1210    public short member_visibility(int index) throws BadKind JavaDoc,
1211    org.omg.CORBA.TypeCodePackage.Bounds JavaDoc {
1212    switch (_kind) {
1213    case tk_indirect:
1214        return indirectType().member_visibility(index);
1215    case TCKind._tk_value:
1216        try {
1217        return _memberAccess[index];
1218        } catch (ArrayIndexOutOfBoundsException JavaDoc e) {
1219        throw new org.omg.CORBA.TypeCodePackage.Bounds JavaDoc();
1220        }
1221    default:
1222        throw new BadKind JavaDoc();
1223    }
1224    }
1225
1226    public short type_modifier() throws BadKind JavaDoc {
1227    switch (_kind) {
1228    case tk_indirect:
1229        return indirectType().type_modifier();
1230    case TCKind._tk_value:
1231        return _type_modifier;
1232    default:
1233        throw new BadKind JavaDoc();
1234    }
1235    }
1236
1237    public TypeCode JavaDoc concrete_base_type() throws BadKind JavaDoc {
1238    switch (_kind) {
1239    case tk_indirect:
1240        return indirectType().concrete_base_type();
1241    case TCKind._tk_value:
1242        return _concrete_base;
1243    default:
1244        throw new BadKind JavaDoc();
1245    }
1246    }
1247
1248    public void read_value(InputStream JavaDoc is) {
1249    if (is instanceof TypeCodeReader) {
1250        // hardly possible unless caller knows our "private" stream classes.
1251
if (read_value_kind((TypeCodeReader)is))
1252        read_value_body(is);
1253    } else if (is instanceof CDRInputStream) {
1254        WrapperInputStream wrapper = new WrapperInputStream((CDRInputStream)is);
1255        //if (debug) System.out.println("Created WrapperInputStream " + wrapper +
1256
// " with no parent");
1257
if (read_value_kind((TypeCodeReader)wrapper))
1258        read_value_body(wrapper);
1259    } else {
1260        read_value_kind(is);
1261        read_value_body(is);
1262    }
1263    }
1264
1265    private void read_value_recursive(TypeCodeInputStream is) {
1266    // don't wrap a CDRInputStream reading "inner" TypeCodes.
1267
if (is instanceof TypeCodeReader) {
1268        if (read_value_kind((TypeCodeReader)is))
1269        read_value_body(is);
1270    } else {
1271        read_value_kind((InputStream JavaDoc)is);
1272        read_value_body(is);
1273    }
1274    }
1275
1276    boolean read_value_kind(TypeCodeReader tcis)
1277    {
1278    _kind = tcis.read_long();
1279
1280    // Bug fix 5034649: allow for padding that precedes the typecode kind.
1281
int myPosition = tcis.getTopLevelPosition()-4;
1282    
1283    // check validity of kind
1284
if ((_kind < 0 || _kind > typeTable.length) && _kind != tk_indirect) {
1285        throw wrapper.cannotMarshalBadTckind() ;
1286    }
1287
1288    // Don't do any work if this is native
1289
if (_kind == TCKind._tk_native)
1290        throw wrapper.cannotMarshalNative() ;
1291
1292    // We have to remember the stream and position for EVERY type code
1293
// in case some recursive or indirect type code references it.
1294
TypeCodeReader topStream = tcis.getTopLevelStream();
1295
1296    if (_kind == tk_indirect) {
1297        int streamOffset = tcis.read_long();
1298        if (streamOffset > -4)
1299        throw wrapper.invalidIndirection( new Integer JavaDoc(streamOffset) ) ;
1300
1301        // The encoding used for indirection is the same as that used for recursive ,
1302
// TypeCodes i.e., a 0xffffffff indirection marker followed by a long offset
1303
// (in units of octets) from the beginning of the long offset.
1304
int topPos = tcis.getTopLevelPosition();
1305        // substract 4 to get back to the beginning of the long offset.
1306
int indirectTypePosition = topPos - 4 + streamOffset;
1307
1308        // Now we have to find the referenced type
1309
// by its indirectTypePosition within topStream.
1310
//if (debug) System.out.println(
1311
// "TypeCodeImpl looking up indirection at position topPos " +
1312
//topPos + " - 4 + offset " + streamOffset + " = " + indirectTypePosition);
1313
TypeCodeImpl type = topStream.getTypeCodeAtPosition(indirectTypePosition);
1314        if (type == null)
1315        throw wrapper.indirectionNotFound( new Integer JavaDoc(indirectTypePosition) ) ;
1316        setIndirectType(type);
1317        return false;
1318    }
1319
1320    topStream.addTypeCodeAtPosition(this, myPosition);
1321    return true;
1322    }
1323
1324    void read_value_kind(InputStream JavaDoc is) {
1325    // unmarshal the kind
1326
_kind = is.read_long();
1327
1328    // check validity of kind
1329
if ((_kind < 0 || _kind > typeTable.length) && _kind != tk_indirect) {
1330        throw wrapper.cannotMarshalBadTckind() ;
1331    }
1332    // Don't do any work if this is native
1333
if (_kind == TCKind._tk_native)
1334        throw wrapper.cannotMarshalNative() ;
1335
1336    if (_kind == tk_indirect) {
1337        throw wrapper.recursiveTypecodeError() ;
1338    }
1339    }
1340
1341    void read_value_body(InputStream JavaDoc is) {
1342    // start unmarshaling the rest of the typecode, based on the
1343
// encoding (empty, simple or complex).
1344

1345    switch (typeTable[_kind]) {
1346    case EMPTY:
1347        // nothing to unmarshal
1348
break;
1349
1350    case SIMPLE:
1351        switch (_kind) {
1352        case TCKind._tk_string:
1353        case TCKind._tk_wstring:
1354        _length = is.read_long();
1355        break;
1356        case TCKind._tk_fixed:
1357        _digits = is.read_ushort();
1358        _scale = is.read_short();
1359        break;
1360        default:
1361        throw wrapper.invalidSimpleTypecode() ;
1362        }
1363        break;
1364
1365    case COMPLEX:
1366        {
1367        TypeCodeInputStream _encap = TypeCodeInputStream.readEncapsulation(is,
1368            is.orb());
1369
1370        switch(_kind) {
1371
1372        case TCKind._tk_objref:
1373        case TCKind._tk_abstract_interface:
1374            {
1375            // get the repository id
1376
setId(_encap.read_string());
1377            // get the name
1378
_name = _encap.read_string();
1379            }
1380            break;
1381
1382        case TCKind._tk_union:
1383            {
1384            // get the repository id
1385
setId(_encap.read_string());
1386
1387            // get the name
1388
_name = _encap.read_string();
1389
1390            // discriminant typecode
1391
_discriminator = new TypeCodeImpl((ORB)is.orb());
1392            _discriminator.read_value_recursive(_encap);
1393
1394            // default index
1395
_defaultIndex = _encap.read_long();
1396
1397            // get the number of members
1398
_memberCount = _encap.read_long();
1399
1400            // create arrays for the label values, names and types of members
1401
_unionLabels = new AnyImpl[_memberCount];
1402            _memberNames = new String JavaDoc[_memberCount];
1403            _memberTypes = new TypeCodeImpl[_memberCount];
1404
1405            // read off label values, names and types
1406
for (int i=0; i < _memberCount; i++) {
1407                _unionLabels[i] = new AnyImpl((ORB)is.orb());
1408                if (i == _defaultIndex)
1409                // for the default case, read off the zero octet
1410
_unionLabels[i].insert_octet(_encap.read_octet());
1411                else {
1412                switch (realType(_discriminator).kind().value()) {
1413                case TCKind._tk_short:
1414                    _unionLabels[i].insert_short(_encap.read_short());
1415                    break;
1416                case TCKind._tk_long:
1417                    _unionLabels[i].insert_long(_encap.read_long());
1418                    break;
1419                case TCKind._tk_ushort:
1420                    _unionLabels[i].insert_ushort(_encap.read_short());
1421                    break;
1422                case TCKind._tk_ulong:
1423                    _unionLabels[i].insert_ulong(_encap.read_long());
1424                    break;
1425                case TCKind._tk_float:
1426                    _unionLabels[i].insert_float(_encap.read_float());
1427                    break;
1428                case TCKind._tk_double:
1429                    _unionLabels[i].insert_double(_encap.read_double());
1430                    break;
1431                case TCKind._tk_boolean:
1432                    _unionLabels[i].insert_boolean(_encap.read_boolean());
1433                    break;
1434                case TCKind._tk_char:
1435                    _unionLabels[i].insert_char(_encap.read_char());
1436                    break;
1437                case TCKind._tk_enum:
1438                    _unionLabels[i].type(_discriminator);
1439                    _unionLabels[i].insert_long(_encap.read_long());
1440                    break;
1441                case TCKind._tk_longlong:
1442                    _unionLabels[i].insert_longlong(_encap.read_longlong());
1443                    break;
1444                case TCKind._tk_ulonglong:
1445                    _unionLabels[i].insert_ulonglong(_encap.read_longlong());
1446                    break;
1447                    // _REVISIT_ figure out long double mapping
1448
// case TCKind.tk_longdouble:
1449
// _unionLabels[i].insert_longdouble(_encap.getDouble());
1450
// break;
1451
case TCKind._tk_wchar:
1452                    _unionLabels[i].insert_wchar(_encap.read_wchar());
1453                    break;
1454                default:
1455                    throw wrapper.invalidComplexTypecode() ;
1456                }
1457                }
1458                _memberNames[i] = _encap.read_string();
1459                _memberTypes[i] = new TypeCodeImpl((ORB)is.orb());
1460                _memberTypes[i].read_value_recursive(_encap);
1461                _memberTypes[i].setParent(this);
1462            }
1463            }
1464            break;
1465
1466        case TCKind._tk_enum:
1467            {
1468            // get the repository id
1469
setId(_encap.read_string());
1470
1471            // get the name
1472
_name = _encap.read_string();
1473
1474            // get the number of members
1475
_memberCount = _encap.read_long();
1476
1477            // create arrays for the identifier names
1478
_memberNames = new String JavaDoc[_memberCount];
1479
1480            // read off identifier names
1481
for (int i=0; i < _memberCount; i++)
1482                _memberNames[i] = _encap.read_string();
1483            }
1484            break;
1485
1486        case TCKind._tk_sequence:
1487            {
1488            // get the type of the sequence
1489
_contentType = new TypeCodeImpl((ORB)is.orb());
1490            _contentType.read_value_recursive(_encap);
1491        
1492            // get the bound on the length of the sequence
1493
_length = _encap.read_long();
1494            }
1495            break;
1496
1497        case TCKind._tk_array:
1498            {
1499            // get the type of the array
1500
_contentType = new TypeCodeImpl((ORB)is.orb());
1501            _contentType.read_value_recursive(_encap);
1502
1503            // get the length of the array
1504
_length = _encap.read_long();
1505            }
1506            break;
1507
1508        case TCKind._tk_alias:
1509        case TCKind._tk_value_box:
1510            {
1511            // get the repository id
1512
setId(_encap.read_string());
1513
1514            // get the name
1515
_name = _encap.read_string();
1516
1517            // get the type aliased
1518
_contentType = new TypeCodeImpl((ORB)is.orb());
1519            _contentType.read_value_recursive(_encap);
1520            }
1521            break;
1522
1523        case TCKind._tk_except:
1524        case TCKind._tk_struct:
1525            {
1526            // get the repository id
1527
setId(_encap.read_string());
1528
1529            // get the name
1530
_name = _encap.read_string();
1531
1532            // get the number of members
1533
_memberCount = _encap.read_long();
1534
1535            // create arrays for the names and types of members
1536
_memberNames = new String JavaDoc[_memberCount];
1537            _memberTypes = new TypeCodeImpl[_memberCount];
1538
1539            // read off member names and types
1540
for (int i=0; i < _memberCount; i++) {
1541                _memberNames[i] = _encap.read_string();
1542                _memberTypes[i] = new TypeCodeImpl((ORB)is.orb());
1543                //if (debug) System.out.println("TypeCode " + _name +
1544
// " reading member " + _memberNames[i]);
1545
_memberTypes[i].read_value_recursive(_encap);
1546                _memberTypes[i].setParent(this);
1547            }
1548            }
1549            break;
1550
1551        case TCKind._tk_value:
1552            {
1553            // get the repository id
1554
setId(_encap.read_string());
1555
1556            // get the name
1557
_name = _encap.read_string();
1558
1559            // get the type modifier
1560
_type_modifier = _encap.read_short();
1561
1562            // get the type aliased
1563
_concrete_base = new TypeCodeImpl((ORB)is.orb());
1564            _concrete_base.read_value_recursive(_encap);
1565            if (_concrete_base.kind().value() == TCKind._tk_null) {
1566                _concrete_base = null;
1567            }
1568
1569            // get the number of members
1570
_memberCount = _encap.read_long();
1571
1572            // create arrays for the names, types and visibility of members
1573
_memberNames = new String JavaDoc[_memberCount];
1574            _memberTypes = new TypeCodeImpl[_memberCount];
1575            _memberAccess = new short[_memberCount];
1576
1577            // read off value member visibilities
1578
for (int i=0; i < _memberCount; i++) {
1579                _memberNames[i] = _encap.read_string();
1580                _memberTypes[i] = new TypeCodeImpl((ORB)is.orb());
1581                //if (debug) System.out.println("TypeCode " + _name +
1582
// " reading member " + _memberNames[i]);
1583
_memberTypes[i].read_value_recursive(_encap);
1584                _memberTypes[i].setParent(this);
1585                _memberAccess[i] = _encap.read_short();
1586            }
1587            }
1588            break;
1589
1590        default:
1591            throw wrapper.invalidTypecodeKindMarshal() ;
1592        }
1593        break;
1594        }
1595    }
1596    }
1597
1598    public void write_value(OutputStream JavaDoc os) {
1599    // Wrap OutputStream into TypeCodeOutputStream.
1600
// This test shouldn't be necessary according to the Java language spec.
1601
if (os instanceof TypeCodeOutputStream) {
1602        this.write_value((TypeCodeOutputStream)os);
1603    } else {
1604        TypeCodeOutputStream wrapperOutStream = null;
1605
1606        if (outBuffer == null) {
1607        wrapperOutStream = TypeCodeOutputStream.wrapOutputStream(os);
1608        this.write_value(wrapperOutStream);
1609        if (cachingEnabled) {
1610            // Cache the buffer for repeated writes
1611
outBuffer = wrapperOutStream.getTypeCodeBuffer();
1612            //if (outBuffer != null)
1613
//System.out.println("Caching outBuffer with length = " +
1614
//outBuffer.length + " for id = " + _id);
1615
}
1616        } else {
1617        //System.out.println("Using cached outBuffer: length = " + outBuffer.length +
1618
//", id = " + _id);
1619
}
1620        // Write the first 4 bytes first to trigger alignment.
1621
// We know that it is the kind.
1622
if (cachingEnabled && outBuffer != null) {
1623        os.write_long(_kind);
1624        os.write_octet_array(outBuffer, 0, outBuffer.length);
1625        } else {
1626        //System.out.println("Buffer is empty for " + _id);
1627
wrapperOutStream.writeRawBuffer(os, _kind);
1628        }
1629    }
1630    }
1631
1632    public void write_value(TypeCodeOutputStream tcos) {
1633
1634    // Don't do any work if this is native
1635
if (_kind == TCKind._tk_native)
1636        throw wrapper.cannotMarshalNative() ;
1637
1638    TypeCodeOutputStream topStream = tcos.getTopLevelStream();
1639    //if (debug) tcos.printBuffer();
1640

1641    if (_kind == tk_indirect) {
1642        //if (debug) System.out.println("Writing indirection " + _name + "to " + _id);
1643
// The encoding used for indirection is the same as that used for recursive ,
1644
// TypeCodes i.e., a 0xffffffff indirection marker followed by a long offset
1645
// (in units of octets) from the beginning of the long offset.
1646
int pos = topStream.getPositionForID(_id);
1647        int topPos = tcos.getTopLevelPosition();
1648        //if (debug) System.out.println("TypeCodeImpl " + tcos +
1649
// " writing indirection " + _id +
1650
//" to position " + pos + " at position " + topPos);
1651
tcos.writeIndirection(tk_indirect, pos);
1652        // All that gets written is _kind and offset.
1653
return;
1654    }
1655
1656    // The original approach changed for 5034649
1657
// topStream.addIDAtPosition(_id, tcos.getTopLevelPosition());
1658

1659    // marshal the kind
1660
tcos.write_long(_kind);
1661    
1662    //if (debug) System.out.println("Writing " + _name + " with id " + _id);
1663
// We have to remember the stream and position for EVERY type code
1664
// in case some recursive or indirect type code references it.
1665
//
1666
// Bug fix 5034649:
1667
// Do this AFTER the write of the _kind in case the alignment
1668
// for the long changes the position.
1669
topStream.addIDAtPosition(_id, tcos.getTopLevelPosition()-4);
1670
1671    switch (typeTable[_kind]) {
1672    case EMPTY:
1673        // nothing more to marshal
1674
break;
1675      
1676    case SIMPLE:
1677        switch (_kind) {
1678        case TCKind._tk_string:
1679        case TCKind._tk_wstring:
1680        // marshal the bound on string length
1681
tcos.write_long(_length);
1682        break;
1683        case TCKind._tk_fixed:
1684        tcos.write_ushort(_digits);
1685        tcos.write_short(_scale);
1686        break;
1687        default:
1688        // unknown typecode kind
1689
throw wrapper.invalidSimpleTypecode() ;
1690        }
1691        break;
1692      
1693    case COMPLEX:
1694        {
1695        // create an encapsulation
1696
TypeCodeOutputStream _encap = tcos.createEncapsulation(tcos.orb());
1697
1698        switch(_kind) {
1699          
1700        case TCKind._tk_objref:
1701        case TCKind._tk_abstract_interface:
1702            {
1703            // put the repository id
1704
_encap.write_string(_id);
1705        
1706            // put the name
1707
_encap.write_string(_name);
1708            }
1709            break;
1710        
1711        case TCKind._tk_union:
1712            {
1713            // put the repository id
1714
_encap.write_string(_id);
1715
1716            // put the name
1717
_encap.write_string(_name);
1718
1719            // discriminant typecode
1720
_discriminator.write_value(_encap);
1721
1722            // default index
1723
_encap.write_long(_defaultIndex);
1724
1725            // put the number of members
1726
_encap.write_long(_memberCount);
1727
1728            // marshal label values, names and types
1729
for (int i=0; i < _memberCount; i++) {
1730
1731                // for the default case, marshal the zero octet
1732
if (i == _defaultIndex)
1733                _encap.write_octet(_unionLabels[i].extract_octet());
1734
1735                else {
1736                switch (realType(_discriminator).kind().value()) {
1737                case TCKind._tk_short:
1738                    _encap.write_short(_unionLabels[i].extract_short());
1739                    break;
1740                case TCKind._tk_long:
1741                    _encap.write_long(_unionLabels[i].extract_long());
1742                    break;
1743                case TCKind._tk_ushort:
1744                    _encap.write_short(_unionLabels[i].extract_ushort());
1745                    break;
1746                case TCKind._tk_ulong:
1747                    _encap.write_long(_unionLabels[i].extract_ulong());
1748                    break;
1749                case TCKind._tk_float:
1750                    _encap.write_float(_unionLabels[i].extract_float());
1751                    break;
1752                case TCKind._tk_double:
1753                    _encap.write_double(_unionLabels[i].extract_double());
1754                    break;
1755                case TCKind._tk_boolean:
1756                    _encap.write_boolean(_unionLabels[i].extract_boolean());
1757                    break;
1758                case TCKind._tk_char:
1759                    _encap.write_char(_unionLabels[i].extract_char());
1760                    break;
1761                case TCKind._tk_enum:
1762                    _encap.write_long(_unionLabels[i].extract_long());
1763                    break;
1764                case TCKind._tk_longlong:
1765                    _encap.write_longlong(_unionLabels[i].extract_longlong());
1766                    break;
1767                case TCKind._tk_ulonglong:
1768                    _encap.write_longlong(_unionLabels[i].extract_ulonglong());
1769                    break;
1770                    // _REVISIT_ figure out long double mapping
1771
// case TCKind.tk_longdouble:
1772
// _encap.putDouble(_unionLabels[i].extract_longdouble());
1773
// break;
1774
case TCKind._tk_wchar:
1775                    _encap.write_wchar(_unionLabels[i].extract_wchar());
1776                    break;
1777                default:
1778                    throw wrapper.invalidComplexTypecode() ;
1779                }
1780                }
1781                _encap.write_string(_memberNames[i]);
1782                _memberTypes[i].write_value(_encap);
1783            }
1784            }
1785            break;
1786
1787        case TCKind._tk_enum:
1788            {
1789            // put the repository id
1790
_encap.write_string(_id);
1791
1792            // put the name
1793
_encap.write_string(_name);
1794
1795            // put the number of members
1796
_encap.write_long(_memberCount);
1797
1798            // marshal identifier names
1799
for (int i=0; i < _memberCount; i++)
1800                _encap.write_string(_memberNames[i]);
1801            }
1802            break;
1803
1804        case TCKind._tk_sequence:
1805            {
1806            // put the type of the sequence
1807
lazy_content_type().write_value(_encap);
1808        
1809            // put the bound on the length of the sequence
1810
_encap.write_long(_length);
1811            }
1812            break;
1813
1814        case TCKind._tk_array:
1815            {
1816            // put the type of the array
1817
_contentType.write_value(_encap);
1818        
1819            // put the length of the array
1820
_encap.write_long(_length);
1821            }
1822            break;
1823
1824        case TCKind._tk_alias:
1825        case TCKind._tk_value_box:
1826            {
1827            // put the repository id
1828
_encap.write_string(_id);
1829
1830            // put the name
1831
_encap.write_string(_name);
1832
1833            // put the type aliased
1834
_contentType.write_value(_encap);
1835            }
1836            break;
1837
1838        case TCKind._tk_struct:
1839        case TCKind._tk_except:
1840            {
1841            // put the repository id
1842
_encap.write_string(_id);
1843
1844            // put the name
1845
_encap.write_string(_name);
1846
1847            // put the number of members
1848
_encap.write_long(_memberCount);
1849
1850            // marshal member names and types
1851
for (int i=0; i < _memberCount; i++) {
1852                _encap.write_string(_memberNames[i]);
1853                //if (debug) System.out.println("TypeCode " + _name +
1854
// " writing member " + _memberNames[i]);
1855
_memberTypes[i].write_value(_encap);
1856            }
1857            }
1858            break;
1859        
1860        case TCKind._tk_value:
1861            {
1862            // put the repository id
1863
_encap.write_string(_id);
1864
1865            // put the name
1866
_encap.write_string(_name);
1867
1868            // put the type modifier
1869
_encap.write_short(_type_modifier);
1870
1871            // put the type aliased
1872
if (_concrete_base == null) {
1873                _orb.get_primitive_tc(TCKind._tk_null).write_value(_encap);
1874            } else {
1875                _concrete_base.write_value(_encap);
1876            }
1877
1878            // put the number of members
1879
_encap.write_long(_memberCount);
1880
1881            // marshal member names and types
1882
for (int i=0; i < _memberCount; i++) {
1883                _encap.write_string(_memberNames[i]);
1884                //if (debug) System.out.println("TypeCode " + _name +
1885
// " writing member " + _memberNames[i]);
1886
_memberTypes[i].write_value(_encap);
1887                _encap.write_short(_memberAccess[i]);
1888            }
1889            }
1890            break;
1891          
1892        default:
1893            throw wrapper.invalidTypecodeKindMarshal() ;
1894        }
1895
1896        // marshal the encapsulation
1897
_encap.writeOctetSequenceTo(tcos);
1898        break;
1899        }
1900    }
1901    }
1902
1903    /**
1904     * This is not a copy of the TypeCodeImpl objects, but instead it
1905     * copies the value this type code is representing.
1906     * See AnyImpl read_value and write_value for usage.
1907     * The state of this TypeCodeImpl instance isn't changed, only used
1908     * by the Any to do the correct copy.
1909     */

1910    protected void copy(org.omg.CORBA.portable.InputStream JavaDoc src,
1911    org.omg.CORBA.portable.OutputStream JavaDoc dst)
1912    {
1913    switch (_kind) {
1914
1915    case TCKind._tk_null:
1916    case TCKind._tk_void:
1917    case TCKind._tk_native:
1918    case TCKind._tk_abstract_interface:
1919        break;
1920
1921    case TCKind._tk_short:
1922    case TCKind._tk_ushort:
1923        dst.write_short(src.read_short());
1924        break;
1925
1926    case TCKind._tk_long:
1927    case TCKind._tk_ulong:
1928        dst.write_long(src.read_long());
1929        break;
1930
1931    case TCKind._tk_float:
1932        dst.write_float(src.read_float());
1933        break;
1934
1935    case TCKind._tk_double:
1936        dst.write_double(src.read_double());
1937        break;
1938
1939    case TCKind._tk_longlong:
1940    case TCKind._tk_ulonglong:
1941        dst.write_longlong(src.read_longlong());
1942        break;
1943
1944    case TCKind._tk_longdouble:
1945        throw wrapper.tkLongDoubleNotSupported() ;
1946
1947    case TCKind._tk_boolean:
1948        dst.write_boolean(src.read_boolean());
1949        break;
1950      
1951    case TCKind._tk_char:
1952        dst.write_char(src.read_char());
1953        break;
1954
1955    case TCKind._tk_wchar:
1956        dst.write_wchar(src.read_wchar());
1957        break;
1958      
1959    case TCKind._tk_octet:
1960        dst.write_octet(src.read_octet());
1961        break;
1962
1963    case TCKind._tk_string:
1964        {
1965        String JavaDoc s;
1966        s = src.read_string();
1967        // make sure length bound in typecode is not violated
1968
if ((_length != 0) && (s.length() > _length))
1969            throw wrapper.badStringBounds( new Integer JavaDoc(s.length()),
1970            new Integer JavaDoc(_length) ) ;
1971        dst.write_string(s);
1972        }
1973        break;
1974
1975    case TCKind._tk_wstring:
1976        {
1977        String JavaDoc s;
1978        s = src.read_wstring();
1979        // make sure length bound in typecode is not violated
1980
if ((_length != 0) && (s.length() > _length))
1981            throw wrapper.badStringBounds( new Integer JavaDoc(s.length()),
1982            new Integer JavaDoc(_length) ) ;
1983        dst.write_wstring(s);
1984        }
1985        break;
1986
1987    case TCKind._tk_fixed:
1988        {
1989        dst.write_ushort(src.read_ushort());
1990        dst.write_short(src.read_short());
1991        }
1992        break;
1993
1994    case TCKind._tk_any:
1995        {
1996        //Any tmp = new AnyImpl(_orb);
1997
Any JavaDoc tmp = ((CDRInputStream)src).orb().create_any();
1998        TypeCodeImpl t = new TypeCodeImpl((ORB)dst.orb());
1999        t.read_value((org.omg.CORBA_2_3.portable.InputStream JavaDoc)src);
2000        t.write_value((org.omg.CORBA_2_3.portable.OutputStream JavaDoc)dst);
2001        tmp.read_value(src, t);
2002        tmp.write_value(dst);
2003        break;
2004        }
2005    
2006    case TCKind._tk_TypeCode:
2007        {
2008        dst.write_TypeCode(src.read_TypeCode());
2009        break;
2010        }
2011    
2012    case TCKind._tk_Principal:
2013        {
2014        dst.write_Principal(src.read_Principal());
2015        break;
2016        }
2017
2018    case TCKind._tk_objref:
2019        {
2020        dst.write_Object(src.read_Object());
2021        break;
2022        }
2023
2024    case TCKind._tk_except:
2025        // Copy repositoryId
2026
dst.write_string(src.read_string());
2027
2028        // Fall into ...
2029
// _REVISIT_ what about the inherited members of this values concrete base type?
2030
case TCKind._tk_value:
2031    case TCKind._tk_struct:
2032        {
2033        // copy each element, using the corresponding member type
2034
for (int i=0; i < _memberTypes.length; i++) {
2035            _memberTypes[i].copy(src, dst);
2036        }
2037        break;
2038        }
2039    case TCKind._tk_union:
2040    /* _REVISIT_ More generic code?
2041        {
2042        Any discriminator = new AnyImpl(_orb);
2043        discriminator.read_value(src, _discriminator);
2044        discriminator.write_value(dst);
2045        int labelIndex = currentUnionMemberIndex(discriminator);
2046        if (labelIndex == -1) {
2047            // check if label has not been found
2048            if (_defaultIndex == -1)
2049            // throw exception if default was not expected
2050            throw new MARSHAL();
2051            else
2052            // must be of the default branch type
2053            _memberTypes[_defaultIndex].copy(src, dst);
2054        } else {
2055            _memberTypes[labelIndex].copy(src, dst);
2056        }
2057        }
2058    */

2059        {
2060        Any JavaDoc tagValue = new AnyImpl( (ORB)src.orb());
2061
2062        switch (realType(_discriminator).kind().value()) {
2063        case TCKind._tk_short:
2064            {
2065            short value = src.read_short();
2066            tagValue.insert_short(value);
2067            dst.write_short(value);
2068            break;
2069            }
2070        case TCKind._tk_long:
2071            {
2072            int value = src.read_long();
2073            tagValue.insert_long(value);
2074            dst.write_long(value);
2075            break;
2076            }
2077        case TCKind._tk_ushort:
2078            {
2079            short value = src.read_short();
2080            tagValue.insert_ushort(value);
2081            dst.write_short(value);
2082            break;
2083            }
2084        case TCKind._tk_ulong:
2085            {
2086            int value = src.read_long();
2087            tagValue.insert_ulong(value);
2088            dst.write_long(value);
2089            break;
2090            }
2091        case TCKind._tk_float:
2092            {
2093            float value = src.read_float();
2094            tagValue.insert_float(value);
2095            dst.write_float(value);
2096            break;
2097            }
2098        case TCKind._tk_double:
2099            {
2100            double value = src.read_double();
2101            tagValue.insert_double(value);
2102            dst.write_double(value);
2103            break;
2104            }
2105        case TCKind._tk_boolean:
2106            {
2107            boolean value = src.read_boolean();
2108            tagValue.insert_boolean(value);
2109            dst.write_boolean(value);
2110            break;
2111            }
2112        case TCKind._tk_char:
2113            {
2114            char value = src.read_char();
2115            tagValue.insert_char(value);
2116            dst.write_char(value);
2117            break;
2118            }
2119        case TCKind._tk_enum:
2120            {
2121            int value = src.read_long();
2122            tagValue.type(_discriminator);
2123            tagValue.insert_long(value);
2124            dst.write_long(value);
2125            break;
2126            }
2127        case TCKind._tk_longlong:
2128            {
2129            long value = src.read_longlong();
2130            tagValue.insert_longlong(value);
2131            dst.write_longlong(value);
2132            break;
2133            }
2134        case TCKind._tk_ulonglong:
2135            {
2136            long value = src.read_longlong();
2137            tagValue.insert_ulonglong(value);
2138            dst.write_longlong(value);
2139            break;
2140            }
2141            // _REVISIT_ figure out long double mapping
2142
// case TCKind.tk_longdouble:
2143
// {
2144
// double value = src.read_double();
2145
// tagValue.insert_longdouble(value);
2146
// dst.putDouble(value);
2147
// break;
2148
//}
2149
case TCKind._tk_wchar:
2150            {
2151            char value = src.read_wchar();
2152            tagValue.insert_wchar(value);
2153            dst.write_wchar(value);
2154            break;
2155            }
2156        default:
2157            throw wrapper.illegalUnionDiscriminatorType() ;
2158        }
2159
2160        // using the value of the tag, find out the type of the value
2161
// following.
2162

2163        int labelIndex;
2164        for (labelIndex = 0; labelIndex < _unionLabels.length; labelIndex++) {
2165            // use equality over anys
2166
if (tagValue.equal(_unionLabels[labelIndex])) {
2167            _memberTypes[labelIndex].copy(src, dst);
2168            break;
2169            }
2170        }
2171
2172        if (labelIndex == _unionLabels.length) {
2173            // check if label has not been found
2174
if (_defaultIndex == -1)
2175            // throw exception if default was not expected
2176
throw wrapper.unexpectedUnionDefault() ;
2177            else
2178            // must be of the default branch type
2179
_memberTypes[_defaultIndex].copy(src, dst);
2180        }
2181        break;
2182        }
2183
2184    case TCKind._tk_enum:
2185        dst.write_long(src.read_long());
2186        break;
2187      
2188    case TCKind._tk_sequence:
2189        // get the length of the sequence
2190
int seqLength = src.read_long();
2191
2192        // check for sequence bound violated
2193
if ((_length != 0) && (seqLength > _length))
2194        throw wrapper.badSequenceBounds( new Integer JavaDoc(seqLength),
2195            new Integer JavaDoc(_length) ) ;
2196
2197        // write the length of the sequence
2198
dst.write_long(seqLength);
2199
2200        // copy each element of the seq using content type
2201
lazy_content_type(); // make sure it's resolved
2202
for (int i=0; i < seqLength; i++)
2203        _contentType.copy(src, dst);
2204        break;
2205
2206    case TCKind._tk_array:
2207        // copy each element of the array using content type
2208
for (int i=0; i < _length; i++)
2209        _contentType.copy(src, dst);
2210        break;
2211
2212    case TCKind._tk_alias:
2213    case TCKind._tk_value_box:
2214        // follow the alias
2215
_contentType.copy(src, dst);
2216        break;
2217
2218    case tk_indirect:
2219        // need to follow offset, get unmarshal typecode from that
2220
// offset, and use that to do the copy
2221
// Don't need to read type code before using it to do the copy.
2222
// It should be fully usable.
2223
indirectType().copy(src, dst);
2224        break;
2225
2226    default:
2227        throw wrapper.invalidTypecodeKindMarshal() ;
2228    }
2229    }
2230
2231
2232    static protected short digits(java.math.BigDecimal JavaDoc value) {
2233        if (value == null)
2234            return 0;
2235        short length = (short)value.unscaledValue().toString().length();
2236        if (value.signum() == -1)
2237            length--;
2238        return length;
2239    }
2240
2241    static protected short scale(java.math.BigDecimal JavaDoc value) {
2242        if (value == null)
2243            return 0;
2244        return (short)value.scale();
2245    }
2246
2247    // Utility methods
2248

2249    // Only for union type. Returns the index of the union member
2250
// corresponding to the discriminator. If not found returns the
2251
// default index or -1 if there is no default index.
2252
int currentUnionMemberIndex(Any JavaDoc discriminatorValue) throws BadKind JavaDoc {
2253        if (_kind != TCKind._tk_union)
2254            throw new BadKind JavaDoc();
2255
2256        try {
2257            for (int i=0; i<member_count(); i++) {
2258                if (member_label(i).equal(discriminatorValue)) {
2259                    return i;
2260                }
2261            }
2262            if (_defaultIndex != -1) {
2263                return _defaultIndex;
2264            }
2265        } catch (BadKind JavaDoc bad) {
2266        } catch (org.omg.CORBA.TypeCodePackage.Bounds JavaDoc bounds) {
2267        }
2268        return -1;
2269    }
2270
2271    public String JavaDoc description() {
2272        return "TypeCodeImpl with kind " + _kind + " and id " + _id;
2273    }
2274
2275    public String JavaDoc toString() {
2276        ByteArrayOutputStream JavaDoc byteOut = new ByteArrayOutputStream JavaDoc(1024);
2277        PrintStream JavaDoc printOut = new PrintStream JavaDoc(byteOut, true);
2278        printStream(printOut);
2279        return super.toString() + " =\n" + byteOut.toString();
2280    }
2281
2282    public void printStream(PrintStream JavaDoc s) {
2283        printStream(s, 0);
2284    }
2285
2286    private void printStream(PrintStream JavaDoc s, int level) {
2287        if (_kind == tk_indirect) {
2288            s.print("indirect " + _id);
2289            return;
2290        }
2291
2292        switch (_kind) {
2293            case TCKind._tk_null:
2294            case TCKind._tk_void:
2295            case TCKind._tk_short:
2296            case TCKind._tk_long:
2297            case TCKind._tk_ushort:
2298            case TCKind._tk_ulong:
2299            case TCKind._tk_float:
2300            case TCKind._tk_double:
2301            case TCKind._tk_boolean:
2302            case TCKind._tk_char:
2303            case TCKind._tk_octet:
2304            case TCKind._tk_any:
2305            case TCKind._tk_TypeCode:
2306            case TCKind._tk_Principal:
2307            case TCKind._tk_objref:
2308            case TCKind._tk_longlong:
2309            case TCKind._tk_ulonglong:
2310            case TCKind._tk_longdouble:
2311            case TCKind._tk_wchar:
2312            case TCKind._tk_native:
2313                s.print(kindNames[_kind] + " " + _name);
2314            break;
2315
2316            case TCKind._tk_struct:
2317            case TCKind._tk_except:
2318            case TCKind._tk_value:
2319                s.println(kindNames[_kind] + " " + _name + " = {");
2320                for(int i=0; i<_memberCount; i++) {
2321                    // memberName might differ from the name of the member.
2322
s.print(indent(level + 1));
2323                    if (_memberTypes[i] != null)
2324                        _memberTypes[i].printStream(s, level + 1);
2325                    else
2326                        s.print("<unknown type>");
2327                    s.println(" " + _memberNames[i] + ";");
2328                }
2329                s.print(indent(level) + "}");
2330            break;
2331
2332            case TCKind._tk_union:
2333                s.print("union " + _name + "...");
2334            break;
2335
2336            case TCKind._tk_enum:
2337                s.print("enum " + _name + "...");
2338            break;
2339
2340            case TCKind._tk_string:
2341                if (_length == 0)
2342                    s.print("unbounded string " + _name);
2343                else
2344                    s.print("bounded string(" + _length + ") " + _name);
2345            break;
2346
2347            case TCKind._tk_sequence:
2348            case TCKind._tk_array:
2349                s.println(kindNames[_kind] + "[" + _length + "] " + _name + " = {");
2350                s.print(indent(level + 1));
2351                if (lazy_content_type() != null) {
2352                    lazy_content_type().printStream(s, level + 1);
2353                }
2354                s.println(indent(level) + "}");
2355            break;
2356
2357            case TCKind._tk_alias:
2358                s.print("alias " + _name + " = " +
2359            (_contentType != null ? _contentType._name : "<unresolved>"));
2360            break;
2361
2362            case TCKind._tk_wstring:
2363                s.print("wstring[" + _length + "] " + _name);
2364            break;
2365
2366            case TCKind._tk_fixed:
2367                s.print("fixed(" + _digits + ", " + _scale + ") " + _name);
2368            break;
2369
2370            case TCKind._tk_value_box:
2371                s.print("valueBox " + _name + "...");
2372            break;
2373
2374            case TCKind._tk_abstract_interface:
2375                s.print("abstractInterface " + _name + "...");
2376            break;
2377
2378            default:
2379                s.print("<unknown type>");
2380            break;
2381        }
2382    }
2383
2384    private String JavaDoc indent(int level) {
2385        String JavaDoc indent = "";
2386        for(int i=0; i<level; i++) {
2387            indent += " ";
2388        }
2389        return indent;
2390    }
2391
2392    protected void setCaching(boolean enableCaching) {
2393        cachingEnabled = enableCaching;
2394        if (enableCaching == false)
2395            outBuffer = null;
2396    }
2397}
2398
Popular Tags