KickJava   Java API By Example, From Geeks To Geeks.

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


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): Sylvain Leblanc.
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 JavaSkeletonPrinter
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     JavaSkeletonPrinter(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_skeleton.template");
69
super.loadFile("java_skeleton_component.template");
70         super.loadFile("java_skeleton_home.template");
71         super.loadFile("java_skeleton_event.template");
72         super.loadFile("java_skeleton_common.template");
73     }
74
75     // ==================================================================
76
//
77
// Internal methods.
78
//
79
// ==================================================================
80

81     // ==================================================================
82
//
83
// Public methods inherited from Printer.
84
//
85
// ==================================================================
86

87     /**
88      **
89      **/

90     public java.lang.String JavaDoc
91     modifyCurrentLine(java.lang.String JavaDoc str)
92     {
93         if (str.length()==0)
94         // Modified by Philippe Merle
95
// for dealing with empty line in template files.
96
return "\\n";
97
98         if (str.charAt(0)=='{')
99             return "{\\n$self.inc()$";
100
101         if (str.charAt(0)=='}')
102             return "$self.dec()$}\\n";
103
104         if ((str.charAt(0)!=getCallChar()) || (str.charAt(str.length()-1)!=getCallChar()))
105             return str+"\\n";
106
107         return str;
108     }
109
110     // ==================================================================
111
//
112
// Public methods (common).
113
//
114
// ==================================================================
115

116     /**
117      **
118      **/

119     public java.lang.String JavaDoc
120     which()
121     {
122         return "ir3_java";
123     }
124
125     /**
126      **
127      **/

128     public java.lang.String JavaDoc
129     visitModule(org.objectweb.ccm.IDL3.ModuleDecl module)
130     {
131         org.objectweb.ccm.util.Vector ports = new org.objectweb.ccm.util.Vector();
132
133         org.objectweb.ccm.IDL3.Declaration[] components = null;
134         components = module.getContents(true, org.objectweb.ccm.IDL3.DeclarationKind._dk_component);
135         for (int i=0;i<components.length;i++)
136         {
137             org.objectweb.ccm.IDL3.ComponentDecl comp = null;
138             org.objectweb.ccm.IDL3.Declaration[] comp_ports = null;
139
140             comp = (org.objectweb.ccm.IDL3.ComponentDecl)components[i];
141             visitContained(comp, "_SKELETON");
142             visitContained(comp.getClientMapping(), "_SKELETON_INTERCEPTOR");
143             visitContained(comp.getClientMapping(), "_STUB_INTERCEPTOR");
144             visitContained(comp, "_MONOLITHIC_WRAPPER");
145             comp_ports = comp.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_provides +
146                                           org.objectweb.ccm.IDL3.DeclarationKind._dk_uses +
147                                           org.objectweb.ccm.IDL3.DeclarationKind._dk_consumes +
148                                           org.objectweb.ccm.IDL3.DeclarationKind._dk_publishes +
149                                           org.objectweb.ccm.IDL3.DeclarationKind._dk_emits);
150
151             for (int j=0;j<comp_ports.length;j++)
152             {
153                 org.objectweb.ccm.IDL3.TypeRef port_type = getType(comp_ports[j]);
154                 if (!ports.contains(port_type))
155                     ports.add(port_type);
156             }
157         }
158
159         org.objectweb.ccm.IDL3.Declaration[] ports_arr = null;
160         ports_arr = (org.objectweb.ccm.IDL3.Declaration[])ports.toArray(new org.objectweb.ccm.IDL3.Declaration[0]);
161         for (int i=0;i<ports_arr.length;i++)
162         {
163             if (ports_arr[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_interface)
164             {
165                 visitContained(ports_arr[i], "_SKELETON_INTERCEPTOR");
166                 visitContained(ports_arr[i], "_STUB_INTERCEPTOR");
167             }
168             else if (ports_arr[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_event)
169             {
170                 org.objectweb.ccm.IDL3.EventDecl event = null;
171                 event = (org.objectweb.ccm.IDL3.EventDecl)ports_arr[i];
172                 visitContained(event.getClientMapping(),"_SKELETON_INTERCEPTOR");
173                 visitContained(event.getClientMapping(),"_STUB_INTERCEPTOR");
174            }
175         }
176
177         org.objectweb.ccm.IDL3.Declaration[] homes = null;
178         homes = module.getContents(true, org.objectweb.ccm.IDL3.DeclarationKind._dk_home);
179         for (int i=0;i<homes.length;i++)
180         {
181             visitContained(homes[i], "_SKELETON");
182             visitContained(((org.objectweb.ccm.IDL3.HomeDecl)homes[i]).getClientMapping(),
183                            "_SKELETON_INTERCEPTOR");
184             visitContained(((org.objectweb.ccm.IDL3.HomeDecl)homes[i]).getClientMapping(),
185                            "_STUB_INTERCEPTOR");
186         }
187
188         org.objectweb.ccm.IDL3.Declaration[] events = null;
189         events = module.getContents(true, org.objectweb.ccm.IDL3.DeclarationKind._dk_event);
190         for (int i=0;i<events.length;i++)
191         {
192             visitContained(events[i], "");
193             visitContained(events[i], "_CONSUMER_WRAPPER");
194         }
195
196         org.objectweb.ccm.IDL3.Declaration[] values = null;
197         values = module.getContents(true, org.objectweb.ccm.IDL3.DeclarationKind._dk_value);
198         for (int i=0;i<values.length;i++)
199         {
200             //
201
// TODO : incomplete : should recursively check inherited values also
202
//
203
org.objectweb.ccm.IDL3.ValueDecl val = (org.objectweb.ccm.IDL3.ValueDecl)values[i];
204             if (val.isPrimaryKey())
205                 visitContained(values[i], "_PK");
206             else
207                 visitContained(values[i], "");
208         }
209
210         org.objectweb.ccm.IDL3.Declaration[] modules = null;
211         modules = module.getContents(true, org.objectweb.ccm.IDL3.DeclarationKind._dk_module);
212         for (int i=0;i<modules.length;i++)
213             visitContained(modules[i], "");
214
215         return "";
216     }
217
218     /**
219      **
220      **/

221     public java.lang.String JavaDoc
222     extractSuperName(org.objectweb.ccm.IDL3.Declaration obj,
223                      org.objectweb.ccm.IDL3.Declaration mapobj)
224     {
225         java.lang.String JavaDoc res = mapobj.getName();
226         int idx = res.lastIndexOf(obj.getName());
227         if (idx==0)
228             return res;
229
230         return res.substring(0, idx-1);
231     }
232
233     /**
234      **
235      **/

236     public java.lang.String JavaDoc
237     packageName(org.objectweb.ccm.IDL3.Declaration decl)
238     {
239         java.lang.String JavaDoc pack_name = getTranslator().getPackage(decl);
240         if (!pack_name.equals(""))
241             return pack_name;
242
243         delete(8);
244         skip(3);
245         return "";
246     }
247
248     // ==================================================================
249
//
250
// Public methods (component related).
251
//
252
// ==================================================================
253

254     // Added by Philippe Merle
255
//
256
public java.lang.String JavaDoc
257     javaPackage(org.objectweb.ccm.IDL3.Declaration type)
258     {
259         java.lang.String JavaDoc packageName = getTranslator().getPackage(type);
260
261         if (packageName.length() != 0)
262             packageName = packageName + '.';
263
264         return packageName;
265     }
266
267     // Added by Philippe Merle
268
//
269
public java.lang.String JavaDoc
270     javaType(org.objectweb.ccm.IDL3.Declaration type,
271              java.lang.String JavaDoc prefix,
272              java.lang.String JavaDoc postfix)
273     {
274         return javaPackage(type) + prefix + type.getName() + postfix;
275     }
276
277     // Added by Philippe Merle
278
//
279
public java.lang.String JavaDoc
280     javaCCMConsumer(org.objectweb.ccm.IDL3.Declaration type)
281     {
282         return javaType(type, "CCM_", "Consumer");
283     }
284
285     // Added by Philippe Merle.
286
public java.lang.String JavaDoc
287     executorWrapperAttributes(org.objectweb.ccm.IDL3.Scope scope)
288     {
289         org.objectweb.ccm.IDL3.Declaration[] objs =
290             scope.getContents(false,
291                 org.objectweb.ccm.IDL3.DeclarationKind._dk_consumes);
292
293         java.lang.String JavaDoc res = "";
294         for (int i=0; i<objs.length; i++)
295         {
296             java.lang.String JavaDoc name = objs[i].getName();
297
298             res = res +
299                 "/** Wrapper for port " + name + ". */\n " +
300                 "protected " + name + "_ConsumerWrapper " +
301                 name + "_wrapper_ =\n new " +
302                 name + "_ConsumerWrapper();\n\n";
303         }
304
305         return res;
306     }
307
308     /**
309      **
310      **/

311     public java.lang.String JavaDoc
312     obtainExecutorWrapper(org.objectweb.ccm.IDL3.Scope scope)
313     {
314         org.objectweb.ccm.IDL3.Declaration[] objs = null;
315         objs = scope.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_provides +
316                                         org.objectweb.ccm.IDL3.DeclarationKind._dk_consumes);
317
318         java.lang.String JavaDoc[] aliases = { "name" , "impl" };
319         for (int i=0;i<objs.length;i++)
320         {
321             java.lang.String JavaDoc impl = "";
322             if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_provides)
323                 impl = "_monolithic_executor.get_"+objs[i].getName()+"()";
324             else
325                 impl = objs[i].getName()+"_wrapper_";
326
327             java.lang.Object JavaDoc[] objs2 = { objs[i].getName(), impl };
328             super.map("COMPONENT_MONOLITHIC_EXECUTOR_WRAPPER", aliases, objs2);
329         }
330
331         return "";
332     }
333
334     /**
335      ** Added by Philippe Merle.
336      **/

337     public java.lang.String JavaDoc
338     monolithicEventWrapperClasses(org.objectweb.ccm.IDL3.Scope scope)
339     {
340         org.objectweb.ccm.IDL3.Declaration[] objs =
341             scope.getContents(false,
342                 org.objectweb.ccm.IDL3.DeclarationKind._dk_consumes);
343
344         java.lang.String JavaDoc res = "";
345         for (int i=0; i<objs.length; i++)
346         {
347             org.objectweb.ccm.IDL3.InterfaceDecl itf =
348                 ((org.objectweb.ccm.IDL3.EventDecl)getType(objs[i])).
349                                                    getLocalConsumerMapping();
350
351             org.objectweb.ccm.IDL3.Declaration[] ops =
352                 itf.getContents(false,
353                     org.objectweb.ccm.IDL3.DeclarationKind._dk_operation);
354
355             for (int j=0; j<ops.length; j++)
356                 visitContainedWithMapping(objs[i], ops[j],
357                      "_EVENT_CONSUMER_MONOLITHIC_WRAPPER");
358         }
359
360         return "";
361     }
362
363     /**
364      **
365      **/

366     public java.lang.String JavaDoc
367     portDeclarations(org.objectweb.ccm.IDL3.Scope scope)
368     {
369         org.objectweb.ccm.IDL3.Declaration[] objs = null;
370         java.lang.String JavaDoc res = "";
371         objs = scope.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_provides +
372                                  org.objectweb.ccm.IDL3.DeclarationKind._dk_uses +
373                                  org.objectweb.ccm.IDL3.DeclarationKind._dk_consumes +
374                                  org.objectweb.ccm.IDL3.DeclarationKind._dk_publishes +
375                                  org.objectweb.ccm.IDL3.DeclarationKind._dk_emits);
376
377
378         for (int i=0;i<objs.length;i++)
379         {
380             java.lang.String JavaDoc port_info = "";
381             org.objectweb.ccm.IDL3.Declaration type = null;
382             type = (org.objectweb.ccm.IDL3.Declaration)getType(objs[i]);
383
384             if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_provides)
385                 port_info = "ProvidesInfo(\""+objs[i].getId()+"\", \""+objs[i].getName()+"\", \""+type.getId()+"\")";
386             else if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_consumes)
387             {
388                 org.objectweb.ccm.IDL3.EventDecl event = (org.objectweb.ccm.IDL3.EventDecl)type;
389                 org.objectweb.ccm.IDL3.InterfaceDecl itf = event.getClientMapping();
390                 port_info = "ConsumesInfo(\""+objs[i].getId()+"\", \""+objs[i].getName()+"\", \""+itf.getId()+"\")";
391             }
392             else if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_emits)
393             {
394                 org.objectweb.ccm.IDL3.EventDecl event = (org.objectweb.ccm.IDL3.EventDecl)type;
395                 org.objectweb.ccm.IDL3.InterfaceDecl itf = event.getClientMapping();
396                 port_info = "EmitsInfo(\""+objs[i].getId()+"\", \""+objs[i].getName()+"\", \""+itf.getId()+"\")";
397             }
398             else if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_publishes)
399             {
400                 org.objectweb.ccm.IDL3.EventDecl event = (org.objectweb.ccm.IDL3.EventDecl)type;
401                 org.objectweb.ccm.IDL3.InterfaceDecl itf = event.getClientMapping();
402                 port_info = "PublishesInfo(\""+objs[i].getId()+"\", \""+objs[i].getName()+"\", \""+itf.getId()+"\")";
403             }
404             else
405             {
406                 org.objectweb.ccm.IDL3.UsesDecl uses = (org.objectweb.ccm.IDL3.UsesDecl)objs[i];
407                 if (uses.isMultiple())
408                     port_info = "UsesInfo(\""+objs[i].getId()+"\", \""+objs[i].getName()+"\", \""+type.getId()+"\", "+
409                         java.lang.Integer.toString(java.lang.Integer.MAX_VALUE)+")";
410                 else
411                     port_info = "UsesInfo(\""+objs[i].getId()+"\", \""+objs[i].getName()+"\", \""+type.getId()+"\")";
412             }
413
414             res = res+"_declare_port(new org.objectweb.openccm.Components."+port_info+");\\n";
415         }
416
417         return res;
418     }
419
420     /**
421      **
422      **/

423     public java.lang.String JavaDoc
424     computeComponentOpName(org.objectweb.ccm.IDL3.Declaration obj,
425                            org.objectweb.ccm.IDL3.Declaration mapobj)
426     {
427         java.lang.String JavaDoc str = "";
428
429         if (obj.getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_provides)
430             str = "provide_facet";
431         else if (obj.getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_uses)
432         {
433             str = "_"+extractSuperName(obj, mapobj);
434             org.objectweb.ccm.IDL3.UsesDecl uses = (org.objectweb.ccm.IDL3.UsesDecl)obj;
435             if (!uses.isMultiple())
436                 str = str+"_simple_receptacle";
437         }
438         else if (obj.getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_consumes)
439             str = "_get_consumer";
440         else if (obj.getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_emits)
441             str = "_"+extractSuperName(obj, mapobj)+"_emitter";
442         else if (obj.getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_publishes)
443             str = "_"+extractSuperName(obj, mapobj);
444
445         return str;
446     }
447
448     /**
449      ** Note: receptacles operations are not generated here as they are
450      ** already generated for the remote interface implementation
451      ** (they have the same signature).
452      **/

453     public java.lang.String JavaDoc
454     contextOperations(org.objectweb.ccm.IDL3.Scope scope)
455     {
456         org.objectweb.ccm.IDL3.Declaration[] objs = null;
457         objs = scope.getContents(false,
458                                  org.objectweb.ccm.IDL3.DeclarationKind._dk_publishes +
459                                  org.objectweb.ccm.IDL3.DeclarationKind._dk_emits);
460
461         java.lang.String JavaDoc[] aliases = { "obj", "event_abs_name", "port_name", "event" };
462         for (int i=0;i<objs.length;i++)
463         {
464             org.objectweb.ccm.IDL3.OperationDecl[] ops = null;
465             java.lang.String JavaDoc id = "";
466
467             if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_publishes)
468             {
469                 ops = ((org.objectweb.ccm.IDL3.PublishesDecl)objs[i]).getLocalContextMapping();
470                 id = "COMPONENT_CONTEXT_PUBLISHES";
471             }
472             else
473             {
474                 ops = ((org.objectweb.ccm.IDL3.EmitsDecl)objs[i]).getLocalContextMapping();
475                 id = "COMPONENT_CONTEXT_EMITS";
476             }
477
478             for (int j=0;j<ops.length;j++)
479             {
480                 java.lang.Object JavaDoc[] objs2 = { ops[j],
481                                             getTranslator().getAbsoluteName(
482                                                 (org.objectweb.ccm.IDL3.Declaration)getType(objs[i])),
483                                             objs[i].getName(),
484                                             getType(objs[i]) };
485                 super.map(id, aliases, objs2);
486             }
487         }
488
489         return "";
490     }
491
492     /**
493      **
494      **/

495     public java.lang.String JavaDoc
496     connectionOperations(org.objectweb.ccm.IDL3.Scope scope)
497     {
498         org.objectweb.ccm.IDL3.Declaration[] objs = null;
499         objs = scope.getContents(false,
500                                  org.objectweb.ccm.IDL3.DeclarationKind._dk_provides +
501                                  org.objectweb.ccm.IDL3.DeclarationKind._dk_uses +
502                                  org.objectweb.ccm.IDL3.DeclarationKind._dk_consumes +
503                                  org.objectweb.ccm.IDL3.DeclarationKind._dk_publishes +
504                                  org.objectweb.ccm.IDL3.DeclarationKind._dk_emits);
505
506         for (int i=0;i<objs.length;i++)
507         {
508             org.objectweb.ccm.IDL3.OperationDecl[] ops = null;
509             java.lang.String JavaDoc id = "";
510
511             if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_provides)
512                 ops = ((org.objectweb.ccm.IDL3.ProvidesDecl)objs[i]).getClientMapping();
513             else if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_uses)
514                 ops = ((org.objectweb.ccm.IDL3.UsesDecl)objs[i]).getClientMapping();
515             else if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_consumes)
516                 ops = ((org.objectweb.ccm.IDL3.ConsumesDecl)objs[i]).getClientMapping();
517             else if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_publishes)
518                 ops = ((org.objectweb.ccm.IDL3.PublishesDecl)objs[i]).getClientMapping();
519             else
520                 ops = ((org.objectweb.ccm.IDL3.EmitsDecl)objs[i]).getClientMapping();
521
522             java.lang.String JavaDoc[] aliases = { "obj", "narrow", "super_op_name",
523                                            "port_name", "param_names",
524                                            "port_abs_name", "struct_abs_name" };
525             for (int j=0;j<ops.length;j++)
526             {
527                 id = "COMPONENT_CONNECTION";
528                 java.lang.String JavaDoc narrow = "";
529                 java.lang.String JavaDoc param_names = paramNames(ops[j]);
530                 java.lang.String JavaDoc port_abs_name = getTranslator().getAbsoluteName(objs[i]);
531                 java.lang.String JavaDoc struct_abs_name = "";
532                 if (!param_names.equals(""))
533                     param_names = ", "+param_names;
534                 if (ops[j].getType().getTypeKind()!=org.objectweb.ccm.IDL3.TypeKind._tk_void)
535                 {
536                     // only narrow the result if the returned type is not ::Components::Cookie
537
// or even if it's not an valuetype (more simple)
538
if (ops[j].getType().getTypeKind()!=org.objectweb.ccm.IDL3.TypeKind._tk_value)
539                     {
540                         id = id+"_DEFAULT";
541                         narrow = type(ops[j].getType())+"Helper.narrow";
542                     }
543                     else
544                         id = id+"_NO_NARROW";
545                 }
546                 else
547                     id = id+"_VOID";
548
549                 // if uses multiple, uses another template for the get_connections_XXX operation.
550
if ((objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_uses) &&
551                     (ops[j].getName().startsWith("get_connections_")))
552                 {
553                     id = "COMPONENT_CONNECTION_USES_MULTIPLE";
554                     org.objectweb.ccm.IDL3.AliasDecl alias = null;
555                     org.objectweb.ccm.IDL3.TypeRefImpl sequence = null;
556                     org.objectweb.ccm.IDL3.StructDecl struct = null;
557                     alias = (org.objectweb.ccm.IDL3.AliasDecl)ops[j].getType();
558                     sequence = (org.objectweb.ccm.IDL3.TypeRefImpl)alias.getType();
559                     struct = (org.objectweb.ccm.IDL3.StructDecl)sequence.getContentType();
560                     struct_abs_name = getTranslator().getAbsoluteName(struct);
561                     narrow = type(getType(objs[i]))+"Helper.narrow";
562                 }
563
564                 java.lang.Object JavaDoc[] objs2 = { ops[j], narrow,
565                                              computeComponentOpName(objs[i], ops[j]),
566                                              objs[i].getName(),
567                                              param_names,
568                                              port_abs_name,
569                                              struct_abs_name };
570                 super.map(id, aliases, objs2);
571             }
572         }
573
574         return "";
575     }
576
577
578     // ==================================================================
579
//
580
// Public methods (home related).
581
//
582
// ==================================================================
583

584     /**
585      **
586      **/

587     public java.lang.String JavaDoc
588     homeHelper(org.objectweb.ccm.IDL3.TypeRef type)
589     {
590         java.lang.String JavaDoc res = getTranslator().toJava(type);
591         // for primary keys
592
if (type.getTypeKind()!=org.objectweb.ccm.IDL3.TypeKind._tk_interface)
593             res = res + "Factory";
594
595         return res;
596     }
597
598     /**
599      **
600      **/

601     public java.lang.String JavaDoc
602     hasPK(org.objectweb.ccm.IDL3.HomeDecl home)
603     {
604         if (home.getPrimaryKey()==null)
605             return "false";
606
607         return "true";
608     }
609
610     /**
611      **
612      **/

613     public java.lang.String JavaDoc
614     baseHome(org.objectweb.ccm.IDL3.HomeDecl home)
615     {
616         if (home.getPrimaryKey()==null)
617             return "CCMHomeImpl";
618
619         return "CCMHomeWithPKImpl";
620     }
621
622     /**
623      **
624      **/

625     public java.lang.String JavaDoc
626     implementedHomeExecutor(org.objectweb.ccm.IDL3.HomeDecl home)
627     {
628         if (home.getPrimaryKey()==null)
629             return "HomeExecutor";
630
631         return "HomeExecutorWithPK";
632     }
633
634     /**
635      **
636      **/

637     public java.lang.String JavaDoc
638     homeExecutorOps(org.objectweb.ccm.IDL3.HomeDecl home)
639     {
640         java.lang.String JavaDoc id = "HOME_EXECUTOR_OPS";
641         java.lang.String JavaDoc key_abs_name = "";
642         if (home.getPrimaryKey()!=null)
643         {
644             id = id + "_WITH_PK";
645             key_abs_name = getTranslator().getAbsoluteName(home.getPrimaryKey());
646         }
647
648         java.lang.String JavaDoc[] aliases = { "key_abs_name" };
649         java.lang.Object JavaDoc[] objs = { key_abs_name };
650         super.map(id, aliases, objs);
651
652
653         return "";
654     }
655  
656     /**
657      **
658      **/

659     public java.lang.String JavaDoc
660     primaryKeyOperations(org.objectweb.ccm.IDL3.HomeDecl home)
661     {
662         org.objectweb.ccm.IDL3.InterfaceDecl itf = null;
663         org.objectweb.ccm.IDL3.Declaration[] ops = null;
664
665         itf = home.getClientImplicitMapping();
666         ops = itf.getContents(true, org.objectweb.ccm.IDL3.DeclarationKind._dk_operation);
667
668         java.lang.String JavaDoc id = "";
669         java.lang.String JavaDoc[] aliases = { "obj" };
670         for (int i=0;i<ops.length;i++)
671         {
672             id = "HOME_OPERATION_SUPER";
673             if (getType(ops[i]).getTypeKind()==org.objectweb.ccm.IDL3.TypeKind._tk_void)
674                 id = id + "_VOID";
675
676             java.lang.Object JavaDoc[] objs = { ops[i] };
677             super.map(id, aliases, objs);
678         }
679
680         return "";
681     }
682
683     /**
684      **
685      **/

686     public java.lang.String JavaDoc
687     factoryFinderOperations(org.objectweb.ccm.IDL3.HomeDecl home)
688     {
689         org.objectweb.ccm.IDL3.Declaration[] objs = null;
690
691         objs = home.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_factory +
692                                        org.objectweb.ccm.IDL3.DeclarationKind._dk_finder);
693
694         java.lang.String JavaDoc id = "";
695         org.objectweb.ccm.IDL3.Declaration[] ops = null;
696         org.objectweb.ccm.IDL3.FactoryDecl factory = null;
697         org.objectweb.ccm.IDL3.FinderDecl finder = null;
698         java.lang.String JavaDoc[] aliases = { "obj" };
699         for (int i=0;i<objs.length;i++)
700         {
701             id = "HOME";
702             if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_factory)
703             {
704                 factory = (org.objectweb.ccm.IDL3.FactoryDecl)objs[i];
705                 ops = factory.getClientMapping();
706                 id = id + "_FACTORY_SUPER";
707             }
708             else
709             {
710                 finder = (org.objectweb.ccm.IDL3.FinderDecl)objs[i];
711                 ops = finder.getClientMapping();
712                 id = id + "_FINDER_SUPER";
713             }
714
715             for (int j=0;j<ops.length;j++)
716             {
717                 java.lang.Object JavaDoc[] objs2 = { ops[j] };
718                 super.map(id, aliases, objs2);
719             }
720         }
721
722         return "";
723     }
724
725     /**
726      **
727      **/

728     public java.lang.String JavaDoc
729     portInterceptors(org.objectweb.ccm.IDL3.Scope scope)
730     {
731         org.objectweb.ccm.IDL3.Declaration[] objs = null;
732         objs = scope.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_provides +
733                                         org.objectweb.ccm.IDL3.DeclarationKind._dk_consumes +
734                                         org.objectweb.ccm.IDL3.DeclarationKind._dk_emits +
735                                         org.objectweb.ccm.IDL3.DeclarationKind._dk_publishes +
736                                         org.objectweb.ccm.IDL3.DeclarationKind._dk_uses);
737
738         java.lang.String JavaDoc res = "";
739         org.objectweb.ccm.IDL3.Declaration type = null;
740         java.lang.String JavaDoc ext = "";
741         for (int i=0;i<objs.length;i++)
742         {
743             if ((objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_emits) ||
744                 (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_publishes))
745                 ext = "ConsumerStub";
746             else if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_consumes)
747                 ext = "ConsumerSkeleton";
748             else if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_uses)
749                 ext = "Stub";
750             else
751                 ext = "Skeleton";
752
753             type = (org.objectweb.ccm.IDL3.Declaration)getType(objs[i]);
754             res = "if (uid.equals(\""+objs[i].getId()+
755                 "\"))\\n"+
756                 getIndentation()+"return new "+getTranslator().getAbsoluteName(type)+ext+"Interceptor();\\n";
757
758             super.printImmediately(res);
759         }
760
761         return "";
762     }
763
764     /**
765      **
766      **/

767     public java.lang.String JavaDoc
768     portUids(org.objectweb.ccm.IDL3.Scope scope)
769     {
770         org.objectweb.ccm.IDL3.Declaration[] objs = null;
771         java.lang.String JavaDoc res = "";
772         objs = scope.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_provides +
773                                         org.objectweb.ccm.IDL3.DeclarationKind._dk_consumes +
774                                         org.objectweb.ccm.IDL3.DeclarationKind._dk_emits +
775                                         org.objectweb.ccm.IDL3.DeclarationKind._dk_publishes +
776                                         org.objectweb.ccm.IDL3.DeclarationKind._dk_uses);
777
778         for (int i=0;i<objs.length;i++)
779             res = res+"\""+objs[i].getId()+"\", ";
780
781         if (!res.equals(""))
782             res = res.substring(0, res.length()-2);
783
784         return res;
785     }
786
787     /**
788      **
789      **/

790     public java.lang.String JavaDoc
791     portTypeUid(org.objectweb.ccm.IDL3.Scope scope)
792     {
793         org.objectweb.ccm.IDL3.Declaration[] objs = null;
794         objs = scope.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_provides +
795                                         org.objectweb.ccm.IDL3.DeclarationKind._dk_consumes +
796                                         org.objectweb.ccm.IDL3.DeclarationKind._dk_emits +
797                                         org.objectweb.ccm.IDL3.DeclarationKind._dk_publishes +
798                                         org.objectweb.ccm.IDL3.DeclarationKind._dk_uses);
799
800         java.lang.String JavaDoc res = "";
801         org.objectweb.ccm.IDL3.Declaration type = null;
802         for (int i=0;i<objs.length;i++)
803         {
804             type = (org.objectweb.ccm.IDL3.Declaration)getType(objs[i]);
805
806             res = "if (port_uid.equals(\""+objs[i].getId()+
807                 "\"))\\n"+
808                 getIndentation()+"return \"";
809
810             java.lang.String JavaDoc type_id = type.getId();
811             if ((objs[i].getDeclKind()!=org.objectweb.ccm.IDL3.DeclarationKind._dk_provides) &&
812                 (objs[i].getDeclKind()!=org.objectweb.ccm.IDL3.DeclarationKind._dk_uses))
813             {
814                 org.objectweb.ccm.IDL3.EventDecl event = (org.objectweb.ccm.IDL3.EventDecl)type;
815                 org.objectweb.ccm.IDL3.InterfaceDecl itf = event.getClientMapping();
816                 type_id = itf.getId();
817             }
818
819             res = res+type_id+"\";\\n";
820
821             super.printImmediately(res);
822         }
823
824         return "";
825     }
826
827     /**
828      ** Note: only generated for events.
829      **/

830     public java.lang.String JavaDoc
831     executorWrappers(org.objectweb.ccm.IDL3.ComponentDecl comp)
832     {
833         org.objectweb.ccm.IDL3.Declaration[] objs = null;
834         objs = comp.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_consumes);
835
836         java.lang.String JavaDoc[] aliases = { "obj", "pack_name", "port_id" };
837         for (int i=0;i<objs.length;i++)
838         {
839             org.objectweb.ccm.IDL3.ConsumesDecl cons = (org.objectweb.ccm.IDL3.ConsumesDecl)objs[i];
840             org.objectweb.ccm.IDL3.EventDecl event = (org.objectweb.ccm.IDL3.EventDecl)cons.getType();
841
842             java.lang.Object JavaDoc[] objs2 = { event, javaPackage(event),
843                                          cons.getId() };
844             super.map("COMPONENT_EVENT_WRAPPER", aliases, objs2);
845         }
846
847         return "";
848     }
849
850     // ==================================================================
851
//
852
// Public methods (event related).
853
//
854
// ==================================================================
855

856     /**
857      **
858      **/

859     public java.lang.String JavaDoc
860     eventConsumerOpWrapper(org.objectweb.ccm.IDL3.EventDecl event)
861     {
862         org.objectweb.ccm.IDL3.InterfaceDecl itf = null;
863         org.objectweb.ccm.IDL3.Declaration[] ops = null;
864         itf = event.getClientMapping();
865         ops = itf.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_operation);
866
867         for (int i=0;i<ops.length;i++)
868         {
869             if (!ops[i].getName().equals("push_event"))
870                 visitContainedWithMapping(event, ops[i], "_EVENT_CONSUMER_WRAPPER");
871         }
872
873         return "";
874     }
875
876     // ==================================================================
877
//
878
// Public methods (interceptor related).
879
//
880
// ==================================================================
881

882     /**
883      **
884      **/

885     public java.lang.String JavaDoc
886     delegateOperations(org.objectweb.ccm.IDL3.Scope scope)
887     {
888         org.objectweb.ccm.IDL3.Declaration[] objs = null;
889         objs = scope.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_operation +
890                                         org.objectweb.ccm.IDL3.DeclarationKind._dk_attribute);
891
892         for (int i=0;i<objs.length;i++)
893         {
894             if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_attribute)
895             {
896                 org.objectweb.ccm.IDL3.AttributeDecl attr = (org.objectweb.ccm.IDL3.AttributeDecl)objs[i];
897                 if (attr.isReadonly())
898                     visitContained(attr, "_READONLY_DELEGATE");
899                 else
900                     visitContained(attr, "_DELEGATE");
901             }
902             else
903                 visitContained(objs[i], "_DELEGATE");
904         }
905
906         return "";
907     }
908
909     /**
910      **
911      **/

912     public java.lang.String JavaDoc
913     interceptorDelegateWrapper(org.objectweb.ccm.IDL3.Declaration obj,
914                                java.lang.String JavaDoc name)
915     {
916         if (obj.getDeclKind()!=org.objectweb.ccm.IDL3.DeclarationKind._dk_consumes)
917             return name;
918
919         return "new "+name(obj)+"EventWrapper("+name+")";
920     }
921
922     /**
923      **
924      **/

925     public java.lang.String JavaDoc
926     interceptorIState(org.objectweb.ccm.IDL3.Scope scope)
927     {
928         org.objectweb.ccm.IDL3.Declaration[] objs = null;
929         java.lang.String JavaDoc str = "";
930         objs = scope.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_operation +
931                                  org.objectweb.ccm.IDL3.DeclarationKind._dk_attribute);
932
933         for (int i=0;i<objs.length;i++)
934         {
935             if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_attribute)
936             {
937                 str = "private org.objectweb.openccm.Containers.CallCoordinator _cc_get_"+
938                     objs[i].getName()+" = null;\\n\\n";
939
940                 super.printImmediately(str);
941
942                 org.objectweb.ccm.IDL3.AttributeDecl attr = (org.objectweb.ccm.IDL3.AttributeDecl)objs[i];
943                 if (!attr.isReadonly())
944                 {
945                     str = "private org.objectweb.openccm.Containers.CallCoordinator _cc_set_"+
946                         objs[i].getName()+" = null;\\n\\n";
947                     super.printImmediately(str);
948                 }
949             }
950             else
951             {
952                 str = "private org.objectweb.openccm.Containers.CallCoordinator _cc_"+
953                     objs[i].getName()+" = null;\\n\\n";
954                 super.printImmediately(str);
955             }
956
957         }
958
959         return "";
960     }
961
962     /**
963      **
964      **/

965     public java.lang.String JavaDoc
966     interceptorOperations(org.objectweb.ccm.IDL3.Scope scope)
967     {
968         org.objectweb.ccm.IDL3.Declaration[] objs = null;
969         objs = scope.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_operation +
970                                  org.objectweb.ccm.IDL3.DeclarationKind._dk_attribute);
971         for (int i=0;i<objs.length;i++)
972         {
973             if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_attribute)
974             {
975                 org.objectweb.ccm.IDL3.AttributeDecl attr = (org.objectweb.ccm.IDL3.AttributeDecl)objs[i];
976                 if (attr.isReadonly())
977                     visitContained(attr, "_READONLY_INTERCEPTOR");
978                 else
979                     visitContained(attr, "_INTERCEPTOR");
980             }
981             else
982                 visitContained(objs[i], "_INTERCEPTOR");
983         }
984
985         return "";
986     }
987 }
988
Popular Tags