KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > idl > SwitchBody


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

22
23 import java.util.*;
24
25 class SwitchBody
26         extends IdlSymbol
27 {
28
29     /** holds case list */
30     Vector caseListVector = new Vector();
31
32     TypeSpec ts = null;
33     UnionType myUnion = null;
34
35     public SwitchBody( int num )
36     {
37         super( num );
38     }
39
40     public void setTypeSpec( TypeSpec s )
41     {
42         ts = s;
43         for( Enumeration e = caseListVector.elements(); e.hasMoreElements(); )
44         {
45             Case c = (Case)e.nextElement();
46             c.setPackage( pack_name );
47             c.setTypeSpec( s );
48         }
49     }
50
51     /**
52      * pass a reference to the containing union through
53      * to the case elements, which pass it on
54      */

55
56     public void setUnion( UnionType ut )
57     {
58         myUnion = ut;
59         for( Enumeration e = caseListVector.elements(); e.hasMoreElements(); )
60         {
61             Case c = (Case)e.nextElement();
62             c.setUnion( ut );
63         }
64     }
65
66     public void setEnclosingSymbol( IdlSymbol s )
67     {
68         if( enclosing_symbol != null && enclosing_symbol != s )
69             throw new RuntimeException JavaDoc( "Compiler Error: trying to reassign container for " + name );
70         enclosing_symbol = s;
71         for( Enumeration e = caseListVector.elements(); e.hasMoreElements(); )
72             ( (IdlSymbol)e.nextElement() ).setEnclosingSymbol( s );
73     }
74
75     public void setPackage( String JavaDoc s )
76     {
77         s = parser.pack_replace( s );
78         if( pack_name.length() > 0 )
79             pack_name = s + "." + pack_name;
80         else
81             pack_name = s;
82
83         if( ts != null )
84             ts.setPackage( s );
85     }
86
87     /**
88      * do the parsing
89      */

90
91     public void parse()
92     {
93         Hashtable usedLabelNames = new Hashtable();
94
95         for( Enumeration e = caseListVector.elements(); e.hasMoreElements(); )
96         {
97             Case theCase = (Case)e.nextElement();
98             theCase.parse();
99
100             // get all case labels and check for duplicates
101

102             IdlSymbol[] labels = theCase.getLabels();
103
104             for( int i = 0; i < labels.length; i++ )
105             {
106                 if( labels[ i ] != null ) // null means default
107
{
108                     IdlSymbol sym =
109                             (IdlSymbol)usedLabelNames.get( labels[ i ].toString() );
110
111                     if( sym != null )
112                     {
113                         parser.error( "Duplicate case label <" +
114                                 sym.toString() + ">", sym.get_token() );
115                     }
116
117                     usedLabelNames.put( labels[ i ].toString(), labels[ i ] );
118                 }
119             }
120         }
121         usedLabelNames.clear();
122
123         ts.parse();
124         myUnion.addImportedName( ts.typeName() );
125
126     }
127
128     public void print( java.io.PrintWriter JavaDoc ps )
129     {
130         for( Enumeration e = caseListVector.elements(); e.hasMoreElements(); )
131         {
132             Case c = (Case)e.nextElement();
133             c.print( ps );
134         }
135     }
136
137 }
138
139
140
141
142
143
144
Popular Tags