KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.PrintWriter JavaDoc;
24 import java.util.*;
25
26 /**
27  * @author Gerald Brose
28  * @version $Id: RaisesExpr.java,v 1.15 2004/05/06 12:39:58 nicolas Exp $
29  */

30
31 class RaisesExpr
32         extends IdlSymbol
33 {
34
35     public Vector nameList;
36
37     public RaisesExpr( int num )
38     {
39         super( num );
40         nameList = new Vector();
41     }
42
43     public void setPackage( String JavaDoc s )
44     {
45         s = parser.pack_replace( s );
46         for( Enumeration e = nameList.elements();
47              e.hasMoreElements();
48              ( (ScopedName)e.nextElement() ).setPackage( s ) )
49             ;
50     }
51
52     public boolean empty()
53     {
54         return ( nameList.size() == 0 );
55     }
56
57     public String JavaDoc[] getExceptionNames()
58     {
59         String JavaDoc[] result = new String JavaDoc[ nameList.size() ];
60         Enumeration e = nameList.elements();
61         for( int i = 0; i < result.length; i++ )
62         {
63             result[ i ] = ( (ScopedName)e.nextElement() ).toString();
64         }
65         return result;
66     }
67
68     public String JavaDoc[] getExceptionIds()
69     {
70         String JavaDoc[] result = new String JavaDoc[ nameList.size() ];
71         Enumeration e = nameList.elements();
72         for( int i = 0; i < result.length; i++ )
73         {
74             result[ i ] = ( (ScopedName)e.nextElement() ).id();
75         }
76         return result;
77     }
78
79     public String JavaDoc[] getExceptionClassNames()
80     {
81         String JavaDoc[] result = new String JavaDoc[ nameList.size() ];
82         Enumeration e = nameList.elements();
83         for( int i = 0; i < result.length; i++ )
84         {
85             result[ i ] = ( (ScopedName)e.nextElement() ).toString();
86         }
87         return result;
88     }
89
90     public void parse()
91     {
92         Hashtable h = new Hashtable(); // for removing duplicate exception names
93
for( Enumeration e = nameList.elements(); e.hasMoreElements(); )
94         {
95             ScopedName name = null;
96             try
97             {
98                 name = (ScopedName)e.nextElement();
99                 TypeSpec ts = name.resolvedTypeSpec();
100                 if( ( (StructType)( (ConstrTypeSpec)ts ).declaration() ).isException() )
101                 {
102                     h.put( name.resolvedName(), name );
103                     continue; // ok
104
}
105                 // else: go to the exception
106
}
107             catch( Exception JavaDoc ex )
108             {
109                 // any type cast errors
110
}
111             parser.fatal_error( "Illegal type in raises clause: " +
112                     name.toString(), token );
113         }
114         // remove duplicate exceptions, i.e. ScopedNames that, when
115
// fully qualified, point to the same exception declaration
116
nameList = new Vector();
117         for( Enumeration e = h.keys(); e.hasMoreElements(); )
118         {
119             nameList.addElement( h.get( (String JavaDoc)e.nextElement() ) );
120         }
121         h.clear();
122         String JavaDoc[] classes = getExceptionClassNames();
123
124         IdlSymbol myInterface = enclosing_symbol;
125
126         for( int i = 0; i < classes.length; i++ )
127         {
128             myInterface.addImportedName( classes[ i ] );
129         }
130     }
131
132
133     public void print( PrintWriter JavaDoc ps )
134     {
135         Enumeration e = nameList.elements();
136         if( e.hasMoreElements() )
137         {
138             ps.print( " throws " + ( (ScopedName)e.nextElement() ) );
139         }
140         for( ; e.hasMoreElements(); )
141         {
142             ps.print( "," + ( (ScopedName)e.nextElement() ) );
143         }
144     }
145 }
146
Popular Tags