1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
/*
 * %W% %E%
 *
 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

/*
 * Licensed Materials - Property of IBM
 * RMI-IIOP v1.0
 * Copyright IBM Corp. 1998 1999  All Rights Reserved
 *
 * US Government Users Restricted Rights - Use, duplication or
 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 */

package sun.rmi.rmic.iiop;

import java.util.Vector;
import java.util.Hashtable;
import java.util.Enumeration;
import java.io.IOException;
import sun.tools.java.ClassDefinition;
import sun.tools.java.ClassDeclaration;
import sun.tools.java.Identifier;
import sun.tools.java.ClassNotFound;
import sun.tools.java.CompilerError;
import sun.rmi.rmic.IndentingWriter;
import java.util.HashSet;
import com.sun.corba.se.impl.util.RepositoryId;
import sun.rmi.rmic.Names;

/**
 * Type is an abstract base class for a family of types which provide
 * conformance checking and name mapping as defined in the "Java to IDL
 * Mapping" OMG specification.  The family is composed of the following
 * fixed set of types:
 * <pre>
 *
 *                                              +- RemoteType <-- AbstractType
 *                                              | 
 *                           +- InterfaceType <-+- SpecialInterfaceType                   
 *         +- PrimitiveType  |                  | 
 *         |                 |                  +- NCInterfaceType
 *  Type <-+- CompoundType <-|                  
 *         |                 |                  +- ValueType
 *         +- ArrayType      |                  |       
 *                           +- ClassType <-----+- ImplementationType 
 *                                              |
 *                                              +- SpecialClassType
 *                                              |
 *                                              +- NCClassType
 *                                              
 * </pre>
 * PrimitiveType represents a primitive or a void type.
 * <p>
 * CompoundType is an abstract base representing any non-special class
 * or interface type.
 * <p>
 * InterfaceType is an abstract base representing any non-special
 * interface type.
 * <p>
 * RemoteType represents any non-special interface which inherits
 * from java.rmi.Remote.
 * <p>
 * AbstractType represents any non-special interface which does not 
 * inherit from java.rmi.Remote, for which all methods throw RemoteException.
 * <p>
 * SpecialInterfaceType represents any one of the following types:
 * <pre>
 *    java.rmi.Remote
 *    java.io.Serializable
 *    java.io.Externalizable
 * </pre>
 * all of which are treated as special cases.
 * <p>
 * NCInterfaceType represents any non-special, non-conforming interface.
 * <p>
 * ClassType is an abstract base representing any non-special class
 * type.
 * <p>
 * ValueType represents any non-special class which does inherit from
 * java.io.Serializable and does not inherit from java.rmi.Remote.
 * <p>
 * ImplementationType represents any non-special class which implements
 * one or more interfaces which inherit from java.rmi.Remote.
 * <p>
 * SpecialClassType represents any one of the following types:
 * <pre>
 *    java.lang.Object
 *    java.lang.String
 *    org.omg.CORBA.Object
 * </pre>
 * all of which are treated as special cases. For all but CORBA.Object,
 * the type must match exactly. For CORBA.Object, the type must either be
 * CORBA.Object or inherit from it.
 * <p>
 * NCClassType represents any non-special, non-conforming class.
 * <p>
 * ArrayType is a wrapper for any of the other types. The getElementType()
 * method can be used to get the array element type.  The getArrayDimension()
 * method can be used to get the array dimension.
 * <p>
 * <i><strong>NOTE:</strong> None of these types is multi-thread-safe</i>
 * @version 1.0, 2/25/98
 * @author  Bryan Atsatt
 */
public abstract class Type implements sun.rmi.rmic.iiop.Constants, ContextElement, Cloneable {

    private int typeCode;
    private int fullTypeCode;
    private Identifier id;

    private String name;
    private String packageName;
    private String qualifiedName;
    
    private String idlName;
    private String[] idlModuleNames;
    private String qualifiedIDLName;
    
    private String repositoryID;
    private Class ourClass;
    
    private int status = STATUS_PENDING;
    
    protected BatchEnvironment env; // Easy access for subclasses.
    protected ContextStack stack;   // Easy access for subclasses.
    
    protected boolean destroyed = false;

    //_____________________________________________________________________
    // Public Interfaces
    //_____________________________________________________________________
    
    /**
     * Return the unqualified name for this type (e.g. com.acme.Dynamite would
     * return "Dynamite").
     */
    public String getName() {
        return name;
    }
    
    /**
     * Return the package of this type (e.g. com.acme.Dynamite would
     * return "com.acme"). Will return null if default package or
     * if this type is a primitive.
     */
    public String getPackageName() {
    return packageName;
    }
    
    /**
     * Return the fully qualified name of this type  (e.g. com.acme.Dynamite
     * would return "com.acme.Dynamite")
     */
    public String getQualifiedName() {
    return qualifiedName;
    }
    
    /**
     * Return signature for this type  (e.g. com.acme.Dynamite
     * would return "com.acme.Dynamite", byte = "B")
     */
    public abstract String getSignature();
    
    /**
     * IDL_Naming
     * Return the unqualified IDL name of this type (e.g. com.acme.Dynamite would
     * return "Dynamite").
     */
    public String getIDLName() {
    return idlName;
    }
    
    /**
     * IDL_Naming
     * Return the IDL module name for this type (e.g. com.acme.Dynamite would return
     * a three element array of {"com","acme"). May be a zero length array if
     * there is no module name.
     */
    public String[] getIDLModuleNames() {
    return idlModuleNames;
    }

    /**
     * IDL_Naming
     * Return the fully qualified IDL name for this type (e.g. com.acme.Dynamite would
     * return "com::acme::Dynamite").
     * @param global If true, prepends "::".
     */
    public String getQualifiedIDLName(boolean global) {
    if (global && getIDLModuleNames().length > 0) {
        return IDL_NAME_SEPARATOR + qualifiedIDLName;
    } else {
        return qualifiedIDLName;
    }
    }
  
    /**
     * Return the identifier for this type. May be qualified.
     */
    public Identifier getIdentifier() {
    return id;
    }
  
    /**
     * Return the repository ID for this type.
     */
    public String getRepositoryID() {
    return repositoryID;
    }
    
    /**
     * Return the repository ID for this "boxed" type.
     */
    public String getBoxedRepositoryID() {
        return RepositoryId.createForJavaType(ourClass);
    }
    
    /**
     * Return the Class for this type.
     */
    public Class getClassInstance() {
    if (ourClass == null) {
        initClass();
    }
    return ourClass;
    }
 
    /**
     * Return the status of this type.
     */
    public int getStatus() {
    return status;
    }
      
    /**
     * Set the status of this type.
     */
    public void setStatus(int status) {
    this.status = status;
    }
      
    /**
     * Return the compiler environment for this type.
     */
    public BatchEnvironment getEnv() {
    return env;
    }
    
    /**
     * Get type code, without modifiers. Type codes are defined in sun.rmi.rmic.iiop.Constants.
     */
    public int getTypeCode() {
    return typeCode;
    }
    
    /**
     * Get type code, with modifiers. Type codes are defined in sun.rmi.rmic.iiop.Constants.
     */
    public int getFullTypeCode() {
    return fullTypeCode;
    }
    
    /**
     * Get type code modifiers. Type codes are defined in sun.rmi.rmic.iiop.Constants.
     */
    public int getTypeCodeModifiers() {
    return fullTypeCode & TM_MASK;
    }

    /**
     * Check for a certain type. Type codes are defined in sun.rmi.rmic.iiop.Constants.
     * Returns true if all of the bits in typeCodeMask are present in the full type code
     * of this object.
     */
    public boolean isType(int typeCodeMask) {
    return (fullTypeCode & typeCodeMask) == typeCodeMask;
    }
    
    /**
     * Like isType(), but returns true if <em>any</em> of the bits in typeCodeMask are
     * present in the full type code of this object.
     */
    public boolean typeMatches(int typeCodeMask) {
    return (fullTypeCode & typeCodeMask) > 0;
    }


    /**
     * Return the fullTypeCode. If an array, returns the
     * type code from the element type.
     */
    public int getRootTypeCode() {
        if (isArray()) {
            return getElementType().getFullTypeCode();
        } else {
            return fullTypeCode;
        }
    }
    
    /**
     * Return true if this type is-a InterfaceType.
     */
    public boolean isInterface() {
    return (fullTypeCode & TM_INTERFACE) == TM_INTERFACE;
    }

    /**
     * Return true if this type is-a ClassType.
     */
    public boolean isClass() {
    return (fullTypeCode & TM_CLASS) == TM_CLASS;
    }

    /**
     * Return true if this type is-a inner class or interface.
     */
    public boolean isInner() {
    return (fullTypeCode & TM_INNER) == TM_INNER;
    }


    /**
     * Return true if this type is-a SpecialInterfaceType.
     */
    public boolean isSpecialInterface() {
    return (fullTypeCode & TM_SPECIAL_INTERFACE) == TM_SPECIAL_INTERFACE;
    }

    /**
     * Return true if this type is-a SpecialClassType.
     */
    public boolean isSpecialClass() {
    return (fullTypeCode & TM_SPECIAL_CLASS) == TM_SPECIAL_CLASS;
    }
    
    /**
     * Return true if this type is-a CompoundType.
     */
    public boolean isCompound() {
    return (fullTypeCode & TM_COMPOUND) == TM_COMPOUND;
    }
    
    /**
     * Return true if this type is-a PrimitiveType.
     */
    public boolean isPrimitive() {
    return (fullTypeCode & TM_PRIMITIVE) == TM_PRIMITIVE;
    }
    
    /**
     * Return true if this type is-a ArrayType.
     */
    public boolean isArray() {
    return (fullTypeCode & TYPE_ARRAY) == TYPE_ARRAY;
    }
    
    /**
     * Return true if this type is a conforming type.
     */
    public boolean isConforming() {
    return (fullTypeCode & TM_NON_CONFORMING) == TM_NON_CONFORMING;
    }

    /**
     * Return a string representation of this type.
     */
    public String toString () {     
    return getQualifiedName();
    }

    /**
     * Get element type. Returns null if not an array.
     */
    public Type getElementType () {
    return null;
    }
    
    /**
     * Get array dimension. Returns zero if not an array.
     */
    public int getArrayDimension () {
    return 0;
    }
    
    /**
     * Get brackets string. Returns "" if not an array.
     */
    public String getArrayBrackets () {
    return "";
    }
    
    /**
     * Equality check based on the string representation.
     */
    public boolean equals(Object obj) {
        
        String us = toString();
        String them = ((Type)obj).toString();
        return us.equals(them);
    }

    /**
     * Collect all the matching types referenced directly or indirectly
     * by this type, including itself.
     * @param typeCodeFilter The typeCode to use as a filter.
     */
    public Type[] collectMatching (int typeCodeFilter) {
        return collectMatching(typeCodeFilter,new HashSet(env.allTypes.size()));
    }

    /**
     * Collect all the matching types referenced directly or indirectly
     * by this type, including itself.
     * @param typeCodeFilter The typeCode to use as a filter.
     * @param alreadyChecked Contains types which have previously been checked
     * and will be ignored. Updated during collection.
     */
    public Type[] collectMatching (int typeCodeFilter, HashSet alreadyChecked) {
    Vector matching = new Vector();
    
    // Fill up the list...
        
    addTypes(typeCodeFilter,alreadyChecked,matching);
        
    // Copy vector contents to array and return it...
        
        Type[] result = new Type[matching.size()];
        matching.copyInto(result);
        
        return result;
    }

    /**
     * Return a string describing this type.
     */
    public abstract String getTypeDescription ();
    
    /**
     * Return the name of this type. For arrays, will include "[]" if useIDLNames == false.
     * @param useQualifiedNames If true, print qualified names; otherwise, print unqualified names.
     * @param useIDLNames If true, print IDL names; otherwise, print java names.
     * @param globalIDLNames If true and useIDLNames true, prepends "::".
     */
    public String getTypeName ( boolean useQualifiedNames,
                boolean useIDLNames,
                boolean globalIDLNames) {
    if (useIDLNames) {
        if (useQualifiedNames) {
        return getQualifiedIDLName(globalIDLNames);
        } else {
        return getIDLName();
        }
    } else {
        if (useQualifiedNames) {
        return getQualifiedName();
        } else {
        return getName();
        }
    }
    }

    /**
     * Print all types referenced directly or indirectly by this type which
     * match the filter.
     * @param writer The stream to print to.
     * @param typeCodeFilter The type codes to print.
     * @param useQualifiedNames If true, print qualified names; otherwise, print unqualified names.
     * @param useIDLNames If true, print IDL names; otherwise, print java names.
     * @param globalIDLNames If true and useIDLNames true, prepends "::".
     */
    public void print ( IndentingWriter writer,
            int typeCodeFilter,
            boolean useQualifiedNames,
            boolean useIDLNames,
            boolean globalIDLNames) throws IOException {
        
    Type[] theTypes = collectMatching(typeCodeFilter);
    print(writer,theTypes,useQualifiedNames,useIDLNames,globalIDLNames);
    }
    
    /**
     * Print an array of types.
     * @param writer The stream to print to.
     * @param theTypes The types to print.
     * @param useQualifiedNames If true, print qualified names; otherwise, print unqualified names.
     * @param useIDLNames If true, print IDL names; otherwise, print java names.
     * @param globalIDLNames If true and useIDLNames true, prepends "::".
     */
    public static void print (  IndentingWriter writer,
                Type[] theTypes,
                boolean useQualifiedNames,
                boolean useIDLNames,
                boolean globalIDLNames) throws IOException {
        
    for (int i = 0; i < theTypes.length; i++) {
        theTypes[i].println(writer,useQualifiedNames,useIDLNames,globalIDLNames);
    }
    }
    
    
    /**
     * Print this type.
     * @param writer The stream to print to.
     * @param useQualifiedNames If true, print qualified names; otherwise, print unqualified names.
     * @param useIDLNames If true, print IDL names; otherwise, print java names.
     * @param globalIDLNames If true and useIDLNames true, prepends "::".
     */
    public void print ( IndentingWriter writer,
            boolean useQualifiedNames,
            boolean useIDLNames,
            boolean globalIDLNames) throws IOException {
    printTypeName(writer,useQualifiedNames,useIDLNames,globalIDLNames);
    }
    
    /**
     * Print this type, followed by a newline.
     * @param writer The stream to print to.
     * @param useQualifiedNames If true, print qualified names; otherwise, print unqualified names.
     * @param useIDLNames If true, print IDL names; otherwise, print java names.
     * @param globalIDLNames If true and useIDLNames true, prepends "::".
     */
    public void println (   IndentingWriter writer,
                boolean useQualifiedNames,
                boolean useIDLNames,
                boolean globalIDLNames) throws IOException  {
        
    print(writer,useQualifiedNames,useIDLNames,globalIDLNames);
    writer.pln();
    }
    

    
    /**
     * Print the name of this type.
     * @param writer The stream to print to.
     * @param useQualifiedNames If true, print qualified names; otherwise, print unqualified names.
     * @param useIDLNames If true, print IDL names; otherwise, print java names.
     * @param globalIDLNames If true and useIDLNames true, prepends "::".
     */
    public void printTypeName ( IndentingWriter writer,
                boolean useQualifiedNames,
                boolean useIDLNames,
                boolean globalIDLNames) throws IOException {
                            
    writer.p(getTypeName(useQualifiedNames,useIDLNames,globalIDLNames));
    }

    /**
     * Return context element name.
     */     
    public String getElementName() {
        return getQualifiedName();    
    }
    
    //_____________________________________________________________________
    // Subclass Interfaces
    //_____________________________________________________________________

    /**
     * Print the "opening" of the package or module of this type.
     * @param writer The stream to print to.
     * @param useIDLNames If true, print IDL names; otherwise, print java names.
     */     
    protected void printPackageOpen (   IndentingWriter writer,
                    boolean useIDLNames) throws IOException {
    
    if (useIDLNames) {
        String[] moduleNames = getIDLModuleNames();
        for (int i = 0; i < moduleNames.length; i++ ) {
        writer.plnI("module " + moduleNames[i] + " {");
        }
    } else {
        String packageName = getPackageName();
        if (packageName != null) {
        writer.pln("package " + packageName + ";");
        }
    }
    }
 
    /**
     * Get a type out of the table.
     */     
    protected static Type getType (sun.tools.java.Type key, ContextStack stack) {
    return getType(key.toString(),stack);   
    }
    
    /**
     * Get a type out of the table.
     */     
    protected static Type getType (String key, ContextStack stack) {
    Type result = (Type) stack.getEnv().allTypes.get(key);
        
    if (result != null) {
        stack.traceExistingType(result);    
    }
        
    return result;   
    }
    
    /**
     * Remove a type from the table.
     */     
    protected static void removeType (String key, ContextStack stack) {
    Type value = (Type) stack.getEnv().allTypes.remove(key);
    stack.getEnv().invalidTypes.put(value,key);
    }
    
    /**
     * Remove a type from the table.
     */     
    protected static void removeType (sun.tools.java.Type key, ContextStack stack) {
    String theKey = key.toString();
    Type old = (Type) stack.getEnv().allTypes.remove(theKey);
    putInvalidType(old,theKey,stack);
    }
    
    /**
     * Put a type into the table.
     */     
    protected static void putType (sun.tools.java.Type key, Type value, ContextStack stack) {
    stack.getEnv().allTypes.put(key.toString(),value);   
    }
    
    /**
     * Put a type into the table.
     */     
    protected static void putType (String key, Type value, ContextStack stack) {
    stack.getEnv().allTypes.put(key,value);   
    }
    
    /**
     * Put an invalid type into the.
     */     
    protected static void putInvalidType (Type key, String value, ContextStack stack) {
    stack.getEnv().invalidTypes.put(key,value);   
    }
 
    
    /**
     * Remove all invalid types...
     */     
    public void removeInvalidTypes () {
    if (env.invalidTypes.size() > 0) {
            env.invalidTypes.clear();
        }
    }
    
    /**
     * Walk all types and tell them to update invalid types...
     */     
    protected static void updateAllInvalidTypes (ContextStack stack) {
    BatchEnvironment env = stack.getEnv();
    if (env.invalidTypes.size() > 0) {

            // Walk all types and swap invalid...
        
            for (Enumeration e = env.allTypes.elements() ; e.hasMoreElements() ;) {
                Type it = (Type) e.nextElement();
                it.swapInvalidTypes();
            }       
            
            // Delete all invalidTypes...
            
            env.invalidTypes.clear();
        }
    }
 
    /**
     * Return count of previously parsed types.
     */     
    protected int countTypes () {
    return env.allTypes.size();
    }
    
    /**
     * Reset types removes all previously parsed types.
     */     
    void resetTypes () {
    env.reset();
    }
 
    /**
     * Release all resources.
     */     
    protected void destroy () {
    if (!destroyed) {
            id = null;
            name = null;
            packageName = null;
            qualifiedName = null;
            idlName = null;
            idlModuleNames = null;
            qualifiedIDLName = null;
            repositoryID = null;
            ourClass = null;
            env = null;
            stack = null;
            destroyed = true;
        }
    }

    /**
     * Convert all invalid types to valid ones.
     */     
    protected void swapInvalidTypes () {
    }
   
    /**
     * Convert an invalid type to a valid one.
     */     
    protected Type getValidType (Type invalidType) {
    if (invalidType.getStatus() == STATUS_VALID) {
        return invalidType;
    }
        
    String key = (String)env.invalidTypes.get(invalidType);
    Type result = null;
    if (key != null) {
        result = (Type) env.allTypes.get(key);
    }

        if (result == null) {
        throw new Error("Failed to find valid type to swap for " + invalidType + " mis-identified as " + invalidType.getTypeDescription());
        }
    //System.out.println("Swapped " + result + " from " + invalidType.getTypeDescription()
    //    + " to " + result.getTypeDescription());
    //ContextStack.dumpCallStack();
        return result;
    }
    
    /**
     * Print the "closing" of the package or module of this type.
     * @param writer The stream to print to.
     * @param useIDLNames If true, print IDL names; otherwise, print java names.
     */     
    protected void printPackageClose (  IndentingWriter writer,
                    boolean useIDLNames) throws IOException {
    if (useIDLNames) {
        String[] moduleNames = getIDLModuleNames();
        for (int i = 0; i < moduleNames.length; i++ ) {
        writer.pOln("};");
        }
    }
    }
   
    /**
     * Create a Type instance for the given type. Requires that
     * setName(Identifier) be called afterward.
     */
    protected Type(ContextStack stack, int fullTypeCode) {
    this.env = stack.getEnv();
    this.stack = stack;
    this.fullTypeCode = fullTypeCode;
    typeCode = fullTypeCode & TYPE_MASK;
    }
    
    /**
     * Set type codes. May only be called during initialization.
     */
    protected void setTypeCode(int fullTypeCode) {
    this.fullTypeCode = fullTypeCode;
    typeCode = fullTypeCode & TYPE_MASK;
    }
    
    /**
     * Set name and package. May only be called during initialization.
     */
    protected void setNames(Identifier id, String[] idlModuleNames, String idlName) {
        
    this.id = id;
    name = Names.mangleClass(id).getName().toString();
    packageName = null;
        
    if (id.isQualified()) {
        packageName = id.getQualifier().toString();
        qualifiedName = packageName + NAME_SEPARATOR + name;
    } else {
        qualifiedName = name;
    }       
        
    setIDLNames(idlModuleNames,idlName);
    }
 
 
    /**
     * Set IDL name. May only be called during initialization.
     */
    protected void setIDLNames(String[] idlModuleNames, String idlName) {
        this.idlName = idlName;
        
    if (idlModuleNames != null) {
        this.idlModuleNames = idlModuleNames;
    } else {
        this.idlModuleNames = new String[0];
    }
    qualifiedIDLName = IDLNames.getQualifiedName(idlModuleNames,idlName);
    }
   
    /**
     * Report a ClassNotFoundException thru the compiler environment.
     */
    protected static void classNotFound(ContextStack stack,
                                        ClassNotFound e) {
        classNotFound(false,stack,e);
    }
    
    /**
     * Report a ClassNotFoundException thru the compiler environment.
     */
    protected static void classNotFound(boolean quiet,
                                        ContextStack stack,
                                        ClassNotFound e) {
        if (!quiet) stack.getEnv().error(0, "rmic.class.not.found", e.name);
        stack.traceCallStack();
    }
    
    /**
     * Report a constraint failure thru the compiler environment.
     * @param constraintNum Used to generate a key of the form
     "rmic.iiop.constraint.N", which must identify a message
     in the "rmic.properties" file.
     * @param quiet True if should not cause failure or message.
     * @param stack The context stack.
     * @param arg0 An object to substitute for {0} in the message.
     * @param arg1 An object to substitute for {1} in the message.
     * @param arg2 An object to substitute for {2} in the message.
     * @return false.
     */
    protected static boolean failedConstraint(int constraintNum,
                          boolean quiet,
                          ContextStack stack,
                          Object arg0, Object arg1, Object arg2) {
        String message = "rmic.iiop.constraint." + constraintNum;

        if (!quiet) {
            stack.getEnv().error(0,message,
                 (arg0 != null ? arg0.toString() : null),
                 (arg1 != null ? arg1.toString() : null),
                 (arg2 != null ? arg2.toString() : null));
        } else {
            String error = stack.getEnv().errorString(message,arg0,arg1,arg2);
            stack.traceln(error);
        }
        
        return false;
    }

    /**
     * Report a constraint failure thru the compiler environment.
     * @param constraintNum Used to generate a key of the form
     "rmic.iiop.constraint.N", which must identify a message
     in the "rmic.properties" file.
     * @param quiet True if should not cause failure or message.
     * @param stack The context stack.
     * @param arg0 An object to substitute for {0} in the message.
     * @param arg1 An object to substitute for {1} in the message.
     * @return false.
     */
    protected static boolean failedConstraint(int constraintNum,
                          boolean quiet,
                          ContextStack stack,
                          Object arg0, Object arg1) {
        return failedConstraint(constraintNum,quiet,stack,arg0,arg1,null);
    }


    /**
     * Report a constraint failure thru the compiler environment.
     * @param constraintNum Used to generate a key of the form
     "rmic.iiop.constraint.N", which must identify a message
     in the "rmic.properties" file.
     * @param quiet True if should not cause failure or message.
     * @param stack The context stack.
     * @param arg0 An object to substitute for {0} in the message.
     * @return false.
     */
    protected static boolean failedConstraint(int constraintNum,
                          boolean quiet,
                          ContextStack stack,
                          Object arg0) {
        return failedConstraint(constraintNum,quiet,stack,arg0,null,null);
    }

    /**
     * Report a constraint failure thru the compiler environment.
     * @param quiet True if should not cause failure or message.
     * @param stack The context stack.
     * @param constraintNum Used to generate a key of the form
     "rmic.iiop.constraint.N", which must identify a message
     in the "rmic.properties" file.
     * @return false.
     */
    protected static boolean failedConstraint(int constraintNum,
                          boolean quiet,
                          ContextStack stack) {
        return failedConstraint(constraintNum,quiet,stack,null,null,null);
    }

    /**
     * Cloning is supported by returning a shallow copy of this object.
     */
    protected Object clone() {
    try {
        return super.clone();
    } catch (CloneNotSupportedException e) {
        throw new Error("clone failed");
    }
    }

    /*
     * Add matching types to list. Return true if this type has not
     * been previously checked, false otherwise.
     */
    protected boolean addTypes (int typeCodeFilter,
                                HashSet checked,
                                Vector matching) {
    
    boolean result;

    // Have we already checked this type?
        
    if (checked.contains(this)) {
            
        // Yes, so return false.
            
        result = false;
            
    } else {

            // Nope, so add it...

            checked.add(this);
            
        // Do we match the filter?
 
        if (typeMatches(typeCodeFilter)) {

        // Yep. so add it and set result to true...
 
        matching.addElement(this);
        }
            
        // Return true.
            
        result = true;
    }
        
    return result;
    }

    /*
     * Load a Class instance. Return null if fail.
     */
    protected abstract Class loadClass();

    private boolean initClass() {
        if (ourClass == null) {
            ourClass = loadClass();
            if (ourClass == null) {
        failedConstraint(27,false,stack,getQualifiedName());
                return false;
            }
        }
        return true;
    }

    /*
     * Set the clz and repositoryID fields. Reports error
     * and returns false if fails, returns true if succeeds.
     */
    protected boolean setRepositoryID() {

        // First, load the class...
        
    if (!initClass()) {
        return false;
        }
        
    // Now make the repositoryID and return success...
        
    repositoryID = RepositoryId.createForAnyType(ourClass);
        return true;
    }   
    
    
    //_____________________________________________________________________
    // Internal Interfaces
    //_____________________________________________________________________

    private Type () {} // Disallowed.
}
			
			

Browsed Source: [clear]