KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > generator > translator > idl2java > lib > IDL_JavaTranslator


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA & USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Christophe Demarey.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.generator.translator.idl2java.lib;
28
29 // Package dependencies.
30
import org.objectweb.openccm.generator.java.ast.api.*;
31 import org.objectweb.openccm.generator.java.ast.lib.*;
32 import org.objectweb.openccm.ast.api.InterfaceDecl;
33 import org.objectweb.openccm.ast.api.OperationDecl;
34 import org.objectweb.openccm.ast.api.AttributeDecl;
35 import org.objectweb.openccm.ast.api.Declaration;
36 import org.objectweb.openccm.ast.api.DeclarationKind;
37 import org.objectweb.openccm.ast.api.ParameterList;
38 import org.objectweb.openccm.ast.api.ExceptionList;
39
40 /**
41  * This class translates some IDL declarations to their java mapping.
42  *
43  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
44  *
45  * @version 0.1
46  */

47
48 public class IDL_JavaTranslator
49      extends org.objectweb.openccm.generator.translator.idl2java.lib.CommonTranslator
50   implements org.objectweb.openccm.generator.translator.idl2java.api.IDL_JavaTranslator
51 {
52     // ==================================================================
53
//
54
// Internal state.
55
//
56
// ==================================================================
57

58     // ==================================================================
59
//
60
// Constructors.
61
//
62
// ==================================================================
63

64     /**
65      * The default constructor.
66      **/

67     public IDL_JavaTranslator()
68     {
69     }
70
71     // ==================================================================
72
//
73
// Internal methods.
74
//
75
// ==================================================================
76

77     // ==================================================================
78
//
79
// Public methods for org.objectweb.openccm.generator.translator.idl2java.api.IDL_JavaTranslator.
80
//
81
// ==================================================================
82

83     /**
84      * Map an IDL operation.
85      *
86      * @param op - The operation to map.
87      *
88      * @return The MethodObject binding to this operation.
89      **/

90     public MethodObject
91     map_operation(OperationDecl op)
92     {
93         MethodObject method = null;
94
95         method = new MethodObjectImpl();
96         method.addComment("Implementation of the " + op.getAbsoluteName() + " operation.");
97         method.setName( checkKeywords(op.getName()) );
98         method.setReturnType( toJava(op.getType()) );
99         map_parameters( method,
100                         op.getParameterList() );
101         map_exceptions( method,
102                         op.getExceptionList() );
103         return method;
104     }
105
106     /**
107      * Map an IDL attribute to an accessor operation.
108      *
109      * @param att - The attribute to map.
110      *
111      * @return The MethodObject binding to this operation.
112      **/

113     public MethodObject
114     map_attribute_accessor(AttributeDecl att)
115     {
116         MethodObject method = null;
117
118         method = new MethodObjectImpl();
119         method.addComment("Implementation of the " +
120                            att.getAbsoluteName() + " attribute as accessor operation.");
121         method.setName( checkKeywords(att.getName()) );
122         method.setReturnType( toJava(att.getType()) );
123         map_exceptions( method,
124                         att.getExceptionList() );
125         return method;
126     }
127
128     /**
129      * Map an IDL attribute to a mutator operation.
130      *
131      * @param att - The attribute to map.
132      *
133      * @return The MethodObject binding to this operation.
134      **/

135     public MethodObject
136     map_attribute_mutator(AttributeDecl att)
137     {
138         if (!att.isReadonly())
139         {
140             MethodObject method = null;
141             ParameterObject param = null;
142
143             method = new MethodObjectImpl();
144             method.addComment("Implementation of the " +
145                                att.getAbsoluteName() + " attribute as mutator operation.");
146             method.setName( checkKeywords(att.getName()) );
147             method.setReturnType("void");
148
149             param = new ParameterObjectImpl();
150             param.setName( checkKeywords(att.getName()) );
151             param.setType( toJava(att.getType()) );
152             method.addParameter(param);
153
154             map_exceptions( method,
155                             att.getExceptionList() );
156             return method;
157         }
158         return null;
159     }
160
161     /**
162      * Map a parameter list for a method.
163      *
164      * @param method - Add parameters mapping to this method.
165      * @param list - The parameter list to map.
166      **/

167     public void
168     map_parameters(MethodObject method,
169                    ParameterList list)
170     {
171         org.objectweb.openccm.ast.api.Parameter[] params = null;
172         ParameterObject param = null;
173
174         params = list.getParameters();
175         for (int i=0; i<params.length; i++)
176         {
177             param = new ParameterObjectImpl();
178             param.setName( checkKeywords(params[i].getName()) );
179             param.setType( toJava(params[i].getType(), params[i].getMode()) );
180             method.addParameter(param);
181         }
182     }
183
184     /**
185      * Map an exeception list for a method.
186      *
187      * @param method - Add exceptions mapping to this method.
188      * @param list - The exception list to map.
189      **/

190     public void
191     map_exceptions(MethodObject method,
192                    ExceptionList list)
193     {
194         org.objectweb.openccm.ast.api.ExceptionDecl[] excs = null;
195
196         excs = list.getExceptions();
197         for (int i=0; i<excs.length; i++)
198         {
199             method.addException( getAbsoluteName(excs[i]) );
200         }
201     }
202
203     /**
204      * Generate operations mapping for an interface.
205      *
206      * @param clazz - Add methods to the segment class.
207      **/

208     public void
209     mapInterfaceOps(ClassObject clazz,
210                     InterfaceDecl itf)
211     {
212         Declaration[] decls = null;
213         MethodObject method = null;
214
215         decls = itf.getContents(false, DeclarationKind.dk_operation);
216         for (int i=0; i<decls.length; i++)
217         {
218             method = map_operation( (OperationDecl)decls[i] );
219             method.getImpl().setMacro("BUSINESS_OP");
220             method.getImpl().addContextValue("translator", this);
221             method.getImpl().addContextValue("obj", (OperationDecl)decls[i]);
222             clazz.addMethod(method);
223         }
224     }
225
226     // ==================================================================
227
//
228
// Public methods.
229
//
230
// ==================================================================
231

232 }
233
Popular Tags