KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > visitorIDL3 > java > JavaImplPrinter


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm-team@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): Mathieu Vadet.
23 Contributor(s): .
24
25 ====================================================================*/

26
27 package org.objectweb.ccm.visitorIDL3.java;
28
29 import org.objectweb.ccm.visitorIDL3.common.*;
30
31 /**
32  * .
33  *
34  * @author <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
35  *
36  * @version 0.3
37  */

38
39 public class JavaImplPrinter
40        extends JavaPrinterBase
41 {
42     // ==================================================================
43
//
44
// Internal state.
45
//
46
// ==================================================================
47

48     // ==================================================================
49
//
50
// Constructor.
51
//
52
// ==================================================================
53

54     /**
55      ** The default constructor.
56      **/

57     public
58     JavaImplPrinter(Generator gen,
59                     java.lang.String JavaDoc indent)
60     throws fr.lifl.cim.jidlscript.lang.JISError
61     {
62         super(gen, '$', '#', indent);
63
64         // set the "self" alias in root scope on this object.
65
super.setAlias("self", this);
66
67         // load the template file.
68
super.loadFile("java_impl_common.template");
69     }
70
71     // ==================================================================
72
//
73
// Internal methods.
74
//
75
// ==================================================================
76

77     // ==================================================================
78
//
79
// Public methods inherited from Printer.
80
//
81
// ==================================================================
82

83     /**
84      **
85      **/

86     public java.lang.String JavaDoc
87     modifyCurrentLine(java.lang.String JavaDoc str)
88     {
89         if (str.length()==0)
90             return "";
91
92         if (str.charAt(0)=='{')
93             return "{\\n$self.inc()$";
94
95         if (str.charAt(0)=='}')
96             return "$self.dec()$}\\n";
97
98         if ((str.charAt(0)!=getCallChar()) || (str.charAt(str.length()-1)!=getCallChar()))
99             return str+"\\n";
100
101         return str;
102     }
103
104     // ==================================================================
105
//
106
// Public methods (common).
107
//
108
// ==================================================================
109

110     /**
111      **
112      **/

113     public java.lang.String JavaDoc
114     which()
115     {
116         return "ir3_jimpl";
117     }
118
119     /**
120      **
121      **/

122     public java.lang.String JavaDoc
123     visitModule(org.objectweb.ccm.IDL3.ModuleDecl module)
124     {
125         java.lang.String JavaDoc[] aliases = { "obj" };
126         org.objectweb.ccm.IDL3.Declaration[] components = null;
127         components = module.getContents(true, org.objectweb.ccm.IDL3.DeclarationKind._dk_component);
128         for (int i=0;i<components.length;i++)
129         {
130             java.lang.Object JavaDoc[] objs = { components[i] };
131             super.map("COMPONENT_MONOLITHIC", aliases, objs);
132         }
133
134         org.objectweb.ccm.IDL3.Declaration[] homes = null;
135         homes = module.getContents(true, org.objectweb.ccm.IDL3.DeclarationKind._dk_home);
136         for (int i=0;i<homes.length;i++)
137         {
138             java.lang.Object JavaDoc[] objs = { homes[i] };
139             super.map("HOME_IMPL", aliases, objs);
140         }
141
142         org.objectweb.ccm.IDL3.Declaration[] values = null;
143         org.objectweb.ccm.IDL3.ValueDecl value = null;
144         values = module.getContents(true, org.objectweb.ccm.IDL3.DeclarationKind._dk_event+
145                                           org.objectweb.ccm.IDL3.DeclarationKind._dk_value);
146         for (int i=0;i<values.length;i++)
147         {
148             value = (org.objectweb.ccm.IDL3.ValueDecl)values[i];
149             if (value.isAbstract())
150                 continue ;
151
152             java.lang.Object JavaDoc[] objs = { values[i] };
153             super.map("VALUE_IMPL", aliases, objs);
154             super.map("VALUE_FACTORY_IMPL", aliases, objs);
155         }
156
157         org.objectweb.ccm.IDL3.Declaration[] modules = null;
158         modules = module.getContents(true, org.objectweb.ccm.IDL3.DeclarationKind._dk_module);
159         for (int i=0;i<modules.length;i++)
160             visitModule((org.objectweb.ccm.IDL3.ModuleDecl)modules[i]);
161
162         return "";
163     }
164
165     /**
166      **
167      **/

168     public java.lang.String JavaDoc
169     packageName(org.objectweb.ccm.IDL3.Declaration decl)
170     {
171         java.lang.String JavaDoc pack_name = getTranslator().getPackage(decl);
172         if (!pack_name.equals(""))
173             return pack_name;
174
175         delete(8);
176         skip(3);
177         return "";
178     }
179
180     // ==================================================================
181
//
182
// Public methods (component related).
183
//
184
// ==================================================================
185

186     /**
187      * Generates interfaces to implements for ComponentMonolithicImpl.
188      * These interfaces are related to provided facets.
189      *
190      * @param comp The component declaration to use.
191      *
192      * @return The string of provides related interfaces to implements.
193      * This string is formatted to be used with ComponentMonolithicImpl
194      * class declaration.
195      */

196     public java.lang.String JavaDoc
197     providesLocalInterfaces(org.objectweb.ccm.IDL3.ComponentDecl comp)
198     {
199         String JavaDoc itfs = "";
200         org.objectweb.ccm.IDL3.Declaration[] objs = null;
201         objs = comp.getContents(false,org.objectweb.ccm.IDL3.
202                                DeclarationKind._dk_provides);
203         for (int i = 0 ; i<objs.length ; i++)
204         {
205             org.objectweb.ccm.IDL3.ProvidesDecl provides =
206                 (org.objectweb.ccm.IDL3.ProvidesDecl) objs[i];
207             org.objectweb.ccm.IDL3.InterfaceDecl type =
208                 provides.getLocalMapping();
209             itfs += " \n" +
210                 " " +
211                 getTranslator().getAbsoluteName(type) + ", ";
212         }
213         return itfs;
214     }
215
216     /**
217      * Call mapping actions for component business operations and attributes.
218      * These operations and attributes can come from Monolithic executor
219      * (base monolithic executor, provides and consumes related operations),
220      * supported interfaces, and component attributes. </br>
221      * Implementation of provides related operations is checked only
222      * with the operation name (starting with "get_"). This could
223      * result in some trouble in some rare cases (e.g. an operation
224      * caming from a supported interface and which name starts with "get_").
225      *
226      * @param comp The component to map.
227      * @return An empty string (required by generation framework).
228      */

229     public java.lang.String JavaDoc
230     businessOperations(org.objectweb.ccm.IDL3.ComponentDecl comp)
231     {
232         org.objectweb.ccm.IDL3.Declaration[] objs = null;
233         org.objectweb.ccm.IDL3.InterfaceDecl itf = comp.getLocalMonolithicMapping();
234         objs = itf.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_operation+
235                                       org.objectweb.ccm.IDL3.DeclarationKind._dk_attribute);
236
237         for (int i=0;i<objs.length;i++)
238         {
239             if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_attribute)
240             {
241                 org.objectweb.ccm.IDL3.AttributeDecl attr = (org.objectweb.ccm.IDL3.AttributeDecl)objs[i];
242                 if (attr.isReadonly())
243                     visitContained(attr, "_IMPL_READONLY");
244                 else
245                     visitContained(attr, "_IMPL");
246             }
247             else
248             {
249                 org.objectweb.ccm.IDL3.OperationDecl op = (org.objectweb.ccm.IDL3.OperationDecl)objs[i];
250                 if (op.getParent().getAbsoluteName().startsWith("::Components"))
251                     continue ;
252                 else if (op.getType().getTypeKind()==org.objectweb.ccm.IDL3.TypeKind._tk_void)
253                     visitContained(op, "_IMPL_VOID");
254                 else if (op.getName().startsWith("get_"))
255                     // obtaining facet operation
256
visitContained(op, "_IMPL_FACET");
257                 else
258                     visitContained(op, "_IMPL");
259             }
260         }
261
262         return "";
263     }
264
265     /**
266      * Generates all component provided facets operations to implement.
267      *
268      * @param comp The component to use.
269      *
270      * @return An empty string (required by generation framework).
271      */

272     public java.lang.String JavaDoc
273     facetsOperations(org.objectweb.ccm.IDL3.ComponentDecl comp)
274     {
275         
276         org.objectweb.ccm.IDL3.Declaration[] objs = null;
277         objs = comp.getContents(false,org.objectweb.ccm.IDL3.
278                                DeclarationKind._dk_provides);
279         for (int i = 0 ; i<objs.length ; i++)
280         {
281             org.objectweb.ccm.IDL3.ProvidesDecl provides =
282                 (org.objectweb.ccm.IDL3.ProvidesDecl)objs[i];
283             visitContained(provides, "_OPERATIONS");
284         }
285         return "";
286     }
287
288     /**
289      * Generates facet operations to implement.
290      *
291      * @param provides The component provides declaration.
292      *
293      * @return An empty string (required by generation framework).
294      */

295     public java.lang.String JavaDoc
296     facetOperations(org.objectweb.ccm.IDL3.ProvidesDecl provides)
297     {
298         org.objectweb.ccm.IDL3.InterfaceDecl itf = provides.getLocalMapping();
299         org.objectweb.ccm.IDL3.Declaration[] decls = null;
300         decls = itf.getContents(false,
301                                 org.objectweb.ccm.IDL3.DeclarationKind.
302                                 _dk_operation+
303                                 org.objectweb.ccm.IDL3.DeclarationKind.
304                                 _dk_attribute);
305         
306         
307         for (int i=0;i<decls.length;i++)
308         {
309             if (decls[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_attribute)
310             {
311                 org.objectweb.ccm.IDL3.AttributeDecl attr =
312                     (org.objectweb.ccm.IDL3.AttributeDecl)decls[i];
313                 if (attr.isReadonly())
314                     visitContained(attr, "_IMPL_READONLY");
315                 else
316                     visitContained(attr, "_IMPL");
317             }
318             else
319             {
320                 org.objectweb.ccm.IDL3.OperationDecl op =
321                     (org.objectweb.ccm.IDL3.OperationDecl)decls[i];
322                 if (op.getParent().getAbsoluteName().startsWith("::Components"))
323                             continue ;
324                 else if (op.getType().getTypeKind()==org.objectweb.ccm.IDL3.TypeKind._tk_void)
325                     visitContained(op, "_IMPL_VOID");
326                 else
327                     visitContained(op, "_IMPL");
328             }
329         }
330         return "";
331     }
332
333     /**
334      **
335      **/

336     public java.lang.String JavaDoc
337     businessOperations(org.objectweb.ccm.IDL3.HomeDecl home)
338     {
339         org.objectweb.ccm.IDL3.Declaration[] objs = null;
340         org.objectweb.ccm.IDL3.InterfaceDecl itf = home.getLocalMapping();
341         objs = itf.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_operation);
342
343         for (int i=0;i<objs.length;i++)
344         {
345             org.objectweb.ccm.IDL3.OperationDecl op = (org.objectweb.ccm.IDL3.OperationDecl)objs[i];
346             if (op.getParent().getAbsoluteName().startsWith("::Components"))
347                 continue ;
348             else if (op.getType().getTypeKind()==org.objectweb.ccm.IDL3.TypeKind._tk_void)
349                 visitContained(objs[i], "_IMPL_VOID");
350             else
351                 visitContained(objs[i], "_IMPL");
352         }
353
354         return "";
355     }
356
357     /**
358      **
359      **/

360     public java.lang.String JavaDoc
361     initMembers(org.objectweb.ccm.IDL3.ValueDecl value)
362     {
363         org.objectweb.ccm.IDL3.Declaration[] objs = null;
364         objs = value.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_value_member);
365         java.lang.String JavaDoc str = "";
366
367         for (int i=0;i<objs.length;i++)
368         {
369             org.objectweb.ccm.IDL3.ValueMemberDecl member = (org.objectweb.ccm.IDL3.ValueMemberDecl)objs[i];
370             //
371
// Keywords check added.
372
//
373
str = checkName(member.getName()) +
374                 " = " +
375                 nullValue(member.getType()) +
376                 ";\\n";
377             super.printImmediately(str);
378         }
379
380         return "";
381     }
382
383     /**
384      **
385      **/

386     public java.lang.String JavaDoc
387     localOperations(org.objectweb.ccm.IDL3.ValueDecl value)
388     {
389         org.objectweb.ccm.IDL3.Declaration[] objs = null;
390         objs = value.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_operation+
391                                  org.objectweb.ccm.IDL3.DeclarationKind._dk_attribute);
392         java.lang.String JavaDoc str = "";
393
394         for (int i=0;i<objs.length;i++)
395         {
396             if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_attribute)
397             {
398                 org.objectweb.ccm.IDL3.AttributeDecl attr = (org.objectweb.ccm.IDL3.AttributeDecl)objs[i];
399                 if (attr.isReadonly())
400                     visitContained(attr, "_IMPL_READONLY");
401                 else
402                     visitContained(attr, "_IMPL");
403             }
404             else
405             {
406                 org.objectweb.ccm.IDL3.OperationDecl op = (org.objectweb.ccm.IDL3.OperationDecl)objs[i];
407                 if (op.getType().getTypeKind()==org.objectweb.ccm.IDL3.TypeKind._tk_void)
408                     visitContained(objs[i], "_IMPL_VOID");
409                 else
410                     visitContained(objs[i], "_IMPL");
411             }
412         }
413
414
415         return "";
416     }
417
418     /**
419      **
420      **/

421     public java.lang.String JavaDoc
422     baseFactory(org.objectweb.ccm.IDL3.ValueDecl value)
423     {
424         org.objectweb.ccm.IDL3.Initializer[] inits = value.getInitializers();
425
426         if (inits.length==0)
427             return "org.omg.CORBA.portable.ValueFactory";
428
429         //
430
// Keywords check added.
431
//
432
return checkName(value.getName())+"ValueFactory";
433     }
434
435     /**
436      **
437      **/

438     public java.lang.String JavaDoc
439     factoriesImpl(org.objectweb.ccm.IDL3.ValueDecl value)
440     {
441         org.objectweb.ccm.IDL3.Initializer[] inits = value.getInitializers();
442         java.lang.String JavaDoc[] aliases = { "obj", "value" };
443
444         for (int i=0;i<inits.length;i++)
445         {
446             java.lang.Object JavaDoc[] objs = { inits[i], value };
447             super.map("INITIALIZER_IMPL", aliases, objs);
448         }
449
450         return "";
451     }
452 }
453
Popular Tags