KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > corba > generator > cif > lib > ValueTypeImplMapping


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.corba.generator.cif.lib;
28
29 // Package dependencies.
30
import org.objectweb.openccm.generator.java.ast.api.*;
31 import org.objectweb.openccm.generator.java.ast.lib.*;
32
33 /**
34  * This class generates CIF implementation templates files for a value type.
35  *
36  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
37  *
38  * @version 0.1
39  */

40
41 public class ValueTypeImplMapping
42   implements org.objectweb.corba.generator.cif.api.ValueTypeImplMapping
43 {
44     // ==================================================================
45
//
46
// Internal state.
47
//
48
// ==================================================================
49

50     /** Utility class to convert types in Java*/
51     static public org.objectweb.openccm.generator.translator.idl2java.api.IDL_JavaTranslator translator_;
52
53     /** The Value Type to map. */
54     private org.objectweb.openccm.ast.api.ValueDecl value_decl_;
55
56     // ==================================================================
57
//
58
// Constructors.
59
//
60
// ==================================================================
61

62     /**
63      * The default constructor.
64      *
65      * @param value_decl - The value type declaration to map.
66      **/

67     public ValueTypeImplMapping(org.objectweb.openccm.ast.api.ValueDecl value_decl)
68     {
69         // Inits internal state
70
value_decl_ = value_decl;
71     }
72
73     // ==================================================================
74
//
75
// Internal methods.
76
//
77
// ==================================================================
78

79     /**
80      * Inits the static field.
81      **/

82     static
83     {
84         translator_ = new org.objectweb.openccm.generator.translator.idl2java.lib.IDL_JavaTranslator();
85     }
86
87     /**
88      * Inits value type members.
89      *
90      * @param ct - The constructor to complete.
91      **/

92     private void
93     init_value_members(ConstructorObject ct)
94     {
95         org.objectweb.openccm.ast.api.Declaration[] decls = null;
96
97         decls = value_decl_.getContents(false, org.objectweb.openccm.ast.api.DeclarationKind.dk_value_member);
98         ct.getImpl().setMacro("VALUE_TYPE_IMPL_CT");
99         ct.getImpl().addContextValue("members", decls);
100         ct.getImpl().addContextValue("translator", translator_);
101     }
102
103     /**
104      * Map value type local operations.
105      *
106      * @param clazz - Add operation mapping to the Value Type class.
107      **/

108     private void
109     local_operations(ClassObject clazz)
110     {
111         org.objectweb.openccm.ast.api.Declaration[] decls = null;
112         MethodObject method = null;
113
114         decls = value_decl_.getContents(false, org.objectweb.openccm.ast.api.DeclarationKind.dk_operation+
115                                                org.objectweb.openccm.ast.api.DeclarationKind.dk_attribute);
116         for (int i=0; i<decls.length; i++)
117         {
118             if (decls[i].getDeclKind() == org.objectweb.openccm.ast.api.DeclarationKind.dk_attribute)
119             {
120                 method = translator_.map_attribute_accessor( (org.objectweb.openccm.ast.api.AttributeDecl)decls[i] );
121                 method.getImpl().setMacro("BUSINESS_OP");
122                 method.getImpl().addContextValue("translator", translator_);
123                 method.getImpl().addContextValue("obj", decls[i]);
124                 clazz.addMethod(method);
125
126                 method = translator_.map_attribute_mutator( (org.objectweb.openccm.ast.api.AttributeDecl)decls[i] );
127                 if (method != null)
128                 {
129                     method.getImpl().setMacro("TODO");
130                     clazz.addMethod(method);
131                 }
132             }
133             else
134             {
135                 method = translator_.map_operation( (org.objectweb.openccm.ast.api.OperationDecl)decls[i] );
136                 method.getImpl().setMacro("BUSINESS_OP");
137                 method.getImpl().addContextValue("translator", translator_);
138                 method.getImpl().addContextValue("obj", decls[i]);
139                 clazz.addMethod(method);
140             }
141         }
142     }
143
144     /**
145      * Get the name of the base factory.
146      *
147      * @return The base factory name.
148      **/

149     private String JavaDoc
150     baseFactory()
151     {
152         org.objectweb.openccm.ast.api.Initializer[] inits = null;
153
154         inits = value_decl_.getInitializerList().getInitializers();
155
156         if (inits.length == 0)
157             return "org.omg.CORBA.portable.ValueFactory";
158         else
159             return translator_.checkKeywords(value_decl_.getName())+"ValueFactory";
160     }
161
162     /**
163      * Map value type factory default operations.
164      *
165      * @param clazz - Add methods to the Value Type class.
166      * @param value_name - The value type name managed by the factory.
167      **/

168     private void
169     map_factory_default_op(ClassObject clazz,
170                            String JavaDoc value_name )
171     {
172         MethodObject method = null;
173         ParameterObject param = null;
174
175         // Map "read_value" operation
176
method = new MethodObjectImpl();
177         method.addComment("Method for the org.omg.CORBA.portable.ValueFactory interface.");
178         method.addComment(" ");
179         method.addComment("To read " + value_name + " on a CORBA stream.");
180         method.setName("read_value");
181         method.setReturnType("java.io.Serializable");
182         method.getImpl().setMacro("VT_FACTORY_READ_VALUE");
183         method.getImpl().addContextValue("value_name", value_name);
184
185         param = new ParameterObjectImpl();
186         param.setName("in");
187         param.setType("org.omg.CORBA_2_3.portable.InputStream");
188         method.addParameter(param);
189         clazz.addMethod(method);
190
191         // Map "register" method
192
method = new MethodObjectImpl();
193         method.addComment("Register the valuetype factory to the ORB.");
194         method.setName("register");
195         method.setStatic(true);
196         method.setReturnType("void");
197         method.getImpl().setMacro("VT_FACTORY_REGISTER");
198         method.getImpl().addContextValue("value_name", value_name);
199         clazz.addMethod(method);
200     }
201
202     /**
203      * Map value type factory initializers.
204      *
205      * @param clazz - Add methods to the Value Type class.
206      **/

207     private void
208     map_factory_initializers(ClassObject clazz)
209     {
210         org.objectweb.openccm.ast.api.Initializer[] inits = null;
211
212         inits = value_decl_.getInitializerList().getInitializers();
213
214         for (int i=0; i<inits.length; i++)
215         {
216             MethodObject method = null;
217
218             // Map "read_value" operation
219
method = new MethodObjectImpl();
220             method.addComment("Implementation of the " +
221                               translator_.checkKeywords(inits[i].getName()) +
222                               " initializer");
223             method.addComment("in "+value_decl_.getAbsoluteName()+" valuetype.");
224             method.setName( translator_.checkKeywords(inits[i].getName()) );
225             method.setReturnType(value_decl_.getName());
226             method.getImpl().setMacro("VT_FACTORY_INITIALIZER");
227             method.getImpl().addContextValue("factory_impl_name", value_decl_.getName()+"Impl");
228
229             translator_.map_parameters( method,
230                                         inits[i].getParameterList() );
231             translator_.map_exceptions( method,
232                                         inits[i].getExceptionList() );
233             clazz.addMethod(method);
234         }
235     }
236
237     // ==================================================================
238
//
239
// Public methods for org.objectweb.openccm.generator.cif.api.ValueTypeImplMapping.
240
//
241
// ==================================================================
242

243     /**
244      * Generate Value Type template class.
245      *
246      * @param repository - The java repository.
247      **/

248     public void
249     toJavaValueTemplate(Repository repository)
250     {
251         ClassObject clazz = null;
252         ConstructorObject ct = null;
253
254         clazz = new ClassObjectImpl(value_decl_.getName()+"Impl");
255         clazz.addComment(" Implementation skeleton class for the "
256                          + value_decl_.getId()
257                          + " declaration.");
258         clazz.addComment("");
259         clazz.addComment(" @author OpenCCM CIF_Jimpl Compiler.");
260         clazz.setModifier(ModifierKindImpl.mk_public);
261         clazz.setPackage( translator_.getPackage(value_decl_) );
262         clazz.addInheritedObject(value_decl_.getName());
263
264         // Add the default constructor
265
ct = new ConstructorObjectImpl();
266         clazz.addConstructor(ct);
267
268         init_value_members(ct);
269         local_operations(clazz);
270
271         // Add object to the java repository
272
repository.addObject(clazz);
273     }
274
275     /**
276      * Generate Value Type Factory template class.
277      *
278      * @param repository - The java repository.
279      **/

280     public void
281     toJavaValueFactoryTemplate(Repository repository)
282     {
283         ClassObject clazz = null;
284         ConstructorObject ct = null;
285         MethodObject method = null;
286
287         clazz = new ClassObjectImpl(value_decl_.getName()+"FactoryImpl");
288         clazz.addComment(" Implementation skeleton class for the "
289                          + value_decl_.getId()
290                          + " declaration factory.");
291         clazz.addComment("");
292         clazz.addComment(" @author OpenCCM CIF_Jimpl Compiler.");
293         clazz.setModifier(ModifierKindImpl.mk_public);
294         clazz.setPackage( translator_.getPackage(value_decl_) );
295         clazz.addImplementedObject(baseFactory());
296
297         // Add the default constructor
298
ct = new ConstructorObjectImpl();
299         clazz.addConstructor(ct);
300
301         map_factory_default_op(clazz, value_decl_.getName());
302         map_factory_initializers(clazz);
303
304         // Add object to the java repository
305
repository.addObject(clazz);
306     }
307
308     // ==================================================================
309
//
310
// Public methods.
311
//
312
// ==================================================================
313

314 }
315
Popular Tags