KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > idl > javamapping > JavaMappingGeneratingVisitor


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

20
21 package org.jacorb.idl.javamapping;
22
23 import org.jacorb.idl.*;
24
25 import java.io.*;
26 import java.util.Enumeration JavaDoc;
27
28 /*
29  * The compiler backend for the IDL/Java mapping
30  *
31  * @author Copyright (c) 1999-2004, Gerald Brose
32  * @version $Id: JavaMappingGeneratingVisitor.java,v 1.5 2004/10/18 11:07:31 simon.mcqueen Exp $
33  *
34  */

35
36 public class JavaMappingGeneratingVisitor
37     implements IDLTreeVisitor
38 {
39     /**
40      * used by the IDL compiler
41      */

42
43     public JavaMappingGeneratingVisitor()
44     {
45     }
46
47     /**
48      * entry point for the code generation, called from
49      * the parser.
50      *
51      */

52
53     public void visitSpec( Spec spec )
54     {
55
56         Enumeration JavaDoc e = spec.definitions.elements();
57         while( e.hasMoreElements() )
58         {
59             IdlSymbol s = (IdlSymbol)e.nextElement();
60             s.accept( this );
61         }
62                 
63         // PrintStream ps = new PrintStream( System.out );
64
}
65
66     public void visitDefinitions( Definitions defs )
67     {
68         Enumeration JavaDoc e = defs.getElements();
69         while( e.hasMoreElements() )
70         {
71             IdlSymbol s = (IdlSymbol)e.nextElement();
72             s.accept( this );
73         }
74     }
75
76     public void visitDefinition( Definition def )
77     {
78         def.get_declaration().accept( this );
79     }
80
81     public void visitDeclaration( Declaration declaration )
82     {
83         // should not be needed, but to make sure we see something
84
// if we ever get here...
85
System.out.println("Unimplemented behavior: visitDeclaration");
86     }
87
88     public void visitModule( Module module )
89     {
90         module.getDefinitions().accept( this );
91     }
92
93     public void visitInterface( Interface interfce )
94     {
95         // forward declared interface, code will be generated
96
// when the defininition is encountered later
97
if( interfce.body == null )
98             return;
99
100         // list super interfaces
101
String JavaDoc[] superInts = interfce.get_ids();
102
103         for( int i = 1; i < superInts.length; i++ )
104         {
105             // skip index 0, which contains the current interface id
106

107         }
108
109         if( interfce.body != null )
110             interfce.body.accept( this );
111
112     }
113
114     public void visitInterfaceBody( InterfaceBody body )
115     {
116          Operation[] ops = body.getMethods();
117
118
119          for( int i = 0; i < ops.length; i++ )
120          {
121              ops[ i ].accept( this );
122          }
123
124
125     }
126
127     public void visitMethod( Method m )
128     {
129  
130         if( m.isGetter() )
131         {
132             ;
133         }
134         else
135         {
136             ;
137         }
138     }
139
140     public void visitOpDecl( OpDecl op )
141     {
142         // op.opAttribute == OpDecl.ONEWAY ? "true" : "false") );
143

144
145         // descend....
146
for( Enumeration JavaDoc e = op.paramDecls.elements(); e.hasMoreElements(); )
147         {
148             ParamDecl param = (ParamDecl)e.nextElement();
149             param.accept( this );
150         }
151
152     }
153
154     public void visitParamDecl( ParamDecl param )
155     {
156
157         String JavaDoc direction = "in";
158
159         if( param.paramAttribute == ParamDecl.MODE_OUT )
160             direction = "out";
161         else if( param.paramAttribute == ParamDecl.MODE_INOUT )
162             direction = "inout";
163
164
165     }
166
167
168     public void visitTypeDeclaration( TypeDeclaration typeDecl )
169     {
170     }
171
172     public void visitConstrTypeSpec( ConstrTypeSpec typeDecl )
173     {
174         //
175
}
176
177     public void visitStruct( StructType struct )
178     {
179         int length = -1;
180         boolean isSeq = false;
181         boolean isArray = false;
182
183         MemberList members = struct.memberlist;
184         if( members != null )
185         {
186  
187             for( Enumeration JavaDoc e = members.elements(); e.hasMoreElements(); )
188             {
189                 Member m = (Member)e.nextElement();
190                 String JavaDoc memberType = typeSpecDesignator( m.type_spec );
191         
192  
193                 if( m.type_spec instanceof VectorType )
194                 {
195                     memberType =
196                         typeSpecDesignator( ((VectorType)m.type_spec).elementTypeSpec() );
197                     length = ((VectorType)m.type_spec).length();
198                     
199                     if( m.type_spec instanceof SequenceType )
200                     {
201                         isSeq = true;
202                     }
203                     else if( m.type_spec instanceof ArrayTypeSpec )
204                     {
205                         isArray = true;
206                     }
207                     else
208                     {
209                         throw new RuntimeException JavaDoc("Internal Error: encountered vector that is neither array nor sequence!");
210                     }
211                 }
212             }
213         }
214     }
215
216     /**
217      *
218      */

219
220     public void visitEnum( EnumType enumType )
221     {
222
223         for( Enumeration JavaDoc e = enumType.enumlist.elements(); e.hasMoreElements(); )
224         {
225             //
226
}
227
228     }
229
230     public void visitUnion( UnionType union )
231     {
232
233     }
234
235     public void visitSequence( SequenceType seq )
236     {
237         // nothing here, all work done in visitAlias()
238
}
239
240     public void visitNative( NativeType _native )
241     {
242
243     }
244
245     public void visitTypeDef( TypeDef typedef )
246     {
247         // nothing here, all work done in visitAlias()
248
}
249
250
251     public void visitAlias( AliasTypeSpec alias )
252     {
253         boolean isSeq = false;
254         boolean isArray = false;
255         int length = -1;
256         String JavaDoc aliasedType = typeSpecDesignator( alias.originalType() );
257
258
259
260         if( alias.originalType() instanceof VectorType )
261         {
262             aliasedType =
263                 typeSpecDesignator( ((VectorType)alias.originalType()).elementTypeSpec());
264             length = ((VectorType)alias.originalType()).length();
265
266             if( alias.originalType() instanceof SequenceType )
267             {
268                 isSeq = true;
269             }
270             else if( alias.originalType() instanceof ArrayTypeSpec )
271             {
272                 isArray = true;
273             }
274             else
275             {
276                 throw new RuntimeException JavaDoc("Internal Error: encountered vector that is neither array nor sequence!");
277             }
278         }
279
280     }
281
282     public void visitValue( Value value )
283     {
284
285     }
286
287     /**
288      * Type ids
289      * @return a string describing a type
290      */

291
292     private String JavaDoc typeSpecDesignator( TypeSpec ts )
293     {
294         if( ts == null )
295             new RuntimeException JavaDoc().printStackTrace();
296
297         if( ! ts.basic() )
298         {
299             if( ts.typeSpec() instanceof AnyType )
300             {
301                 return "any";
302             }
303             else
304                 return ts.id();
305         }
306         else
307         {
308             
309 System.out.println("typeSpecDesignator for " + ts.typeSpec().getClass().getName());
310
311             if( ts.typeSpec() instanceof ObjectTypeSpec )
312             {
313                 return ts.id();
314             }
315             else if( ts.typeSpec() instanceof ConstrTypeSpec )
316             {
317                 return ((ConstrTypeSpec)ts.typeSpec()).id();
318             }
319             else if( ts.typeSpec() instanceof ScopedName )
320             {
321                 return typeSpecDesignator ( ((ScopedName)ts.typeSpec()).resolvedTypeSpec() );
322             }
323             else if( ts.typeSpec() instanceof StringType )
324             {
325                 return "string";
326             }
327  
328             else
329             {
330                 // debug:
331
// System.out.println("typeSpecDesignator for " +
332
// ts.typeSpec().getClass().getName());
333
return ts.toString();
334             }
335         }
336     }
337 }
338
Popular Tags