KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > coach > reactor > ReactorImplPrinter


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2005 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): Mathieu Vadet.
23 Contributor(s): Sylvain Leblanc, Philippe Merle.
24
25 ====================================================================
26 $Id: ReactorImplPrinter.java,v 1.3 2005/06/17 15:47:23 merle Exp $
27 ====================================================================*/

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

41
42 public class ReactorImplPrinter
43        extends JavaPrinterBase
44 {
45     // ==================================================================
46
//
47
// Internal state.
48
//
49
// ==================================================================
50
IDLTranslator idlTranslator;
51 ParameterList p;
52
53     // ==================================================================
54
//
55
// Constructor.
56
//
57
// ==================================================================
58

59     /**
60      ** The default constructor.
61      **/

62     public
63     ReactorImplPrinter(Generator gen,
64                         java.lang.String JavaDoc indent)
65     throws fr.lifl.cim.jidlscript.lang.JISError
66     {
67         super(gen, '$', '@', indent);
68
69         // set the "self" alias in root scope on this object.
70
super.setAlias("self", this);
71
72         // load the template file.
73
// super.loadFile("java_skeleton.template");
74
super.loadFile("reactor_component.template");
75         super.loadFile("reactor_home.template");
76         super.loadFile("reactor_event.template");
77         super.loadFile("reactor_core.template");
78         super.loadFile("reactor_usercode.template");
79         super.loadFile("reactor_script.template");
80
81         idlTranslator = new IDLTranslator();
82     }
83
84     // ==================================================================
85
//
86
// Internal methods.
87
//
88
// ==================================================================
89

90     // ==================================================================
91
//
92
// Public methods inherited from Printer.
93
//
94
// ==================================================================
95

96     /**
97      **
98      **/

99     public java.lang.String JavaDoc
100     modifyCurrentLine(java.lang.String JavaDoc str)
101     {
102         if (str.length()==0)
103         // Modified by Philippe Merle
104
// for dealing with empty line in template files.
105
return "\\n";
106
107         if (str.charAt(0)=='{')
108             return "{\\n$self.inc()$";
109
110         if (str.charAt(0)=='}')
111             return "$self.dec()$}\\n";
112
113         if ((str.charAt(0)!=getCallChar()) || (str.charAt(str.length()-1)!=getCallChar()))
114             return str+"\\n";
115
116         return str;
117     }
118
119     // ==================================================================
120
//
121
// Public methods (common).
122
//
123
// ==================================================================
124

125     /**
126      **
127      **/

128     public java.lang.String JavaDoc
129     which()
130     {
131         return "ir3_rimpl";
132     }
133
134     /**
135      **
136      **/

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

231     public java.lang.String JavaDoc
232     extractSuperName(org.objectweb.ccm.IDL3.Declaration obj,
233                      org.objectweb.ccm.IDL3.Declaration mapobj)
234     {
235         java.lang.String JavaDoc res = mapobj.getName();
236         int idx = res.indexOf(obj.getName());
237         if (idx==0)
238             return res;
239
240         return res.substring(0, idx-1);
241     }
242
243     /**
244      **
245      **/

246     public java.lang.String JavaDoc
247     packageName(org.objectweb.ccm.IDL3.Declaration decl)
248     {
249         java.lang.String JavaDoc pack_name = getTranslator().getPackage(decl);
250         if (!pack_name.equals(""))
251             return pack_name;
252
253         delete(8);
254         skip(3);
255         return "";
256     }
257
258     // ==================================================================
259
//
260
// Public methods (component related).
261
//
262
// ==================================================================
263

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

321     public java.lang.String JavaDoc
322     obtainExecutorWrapper(org.objectweb.ccm.IDL3.Scope scope)
323     {
324         org.objectweb.ccm.IDL3.Declaration[] objs = null;
325         objs = scope.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_provides +
326                                         org.objectweb.ccm.IDL3.DeclarationKind._dk_consumes);
327
328         java.lang.String JavaDoc[] aliases = { "name" , "impl" };
329         for (int i=0;i<objs.length;i++)
330         {
331             java.lang.String JavaDoc impl = "";
332             if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_provides)
333                 impl = "_monolithic_executor.get_"+objs[i].getName()+"()";
334             else
335                 impl = objs[i].getName()+"_wrapper_";
336
337             java.lang.Object JavaDoc[] objs2 = { objs[i].getName(), impl };
338             super.map("COMPONENT_MONOLITHIC_EXECUTOR_WRAPPER", aliases, objs2);
339         }
340
341         return "";
342     }
343
344     /**
345      ** Added by Philippe Merle.
346      **/

347     public java.lang.String JavaDoc
348     monolithicEventWrapperClasses(org.objectweb.ccm.IDL3.Scope scope)
349     {
350         org.objectweb.ccm.IDL3.Declaration[] objs =
351             scope.getContents(false,
352                 org.objectweb.ccm.IDL3.DeclarationKind._dk_consumes);
353
354         java.lang.String JavaDoc res = "";
355         for (int i=0; i<objs.length; i++)
356         {
357             org.objectweb.ccm.IDL3.InterfaceDecl itf =
358                 ((org.objectweb.ccm.IDL3.EventDecl)getType(objs[i])).
359                                                    getLocalConsumerMapping();
360
361             org.objectweb.ccm.IDL3.Declaration[] ops =
362                 itf.getContents(false,
363                     org.objectweb.ccm.IDL3.DeclarationKind._dk_operation);
364
365             for (int j=0; j<ops.length; j++)
366                 visitContainedWithMapping(objs[i], ops[j],
367                      "_EVENT_CONSUMER_MONOLITHIC_WRAPPER");
368         }
369
370         return "";
371     }
372
373     /**
374      **
375      **/

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

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

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

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

594     /**
595      **
596      **/

597     public java.lang.String JavaDoc
598     homeHelper(org.objectweb.ccm.IDL3.TypeRef type)
599     {
600         java.lang.String JavaDoc res = getTranslator().toJava(type);
601         // for primary keys
602
if (type.getTypeKind()!=org.objectweb.ccm.IDL3.TypeKind._tk_interface)
603             res = res + "Factory";
604
605         return res;
606     }
607
608     /**
609      **
610      **/

611     public java.lang.String JavaDoc
612     hasPK(org.objectweb.ccm.IDL3.HomeDecl home)
613     {
614         if (home.getPrimaryKey()==null)
615             return "false";
616
617         return "true";
618     }
619
620     /**
621      **
622      **/

623     public java.lang.String JavaDoc
624     baseHome(org.objectweb.ccm.IDL3.HomeDecl home)
625     {
626         if (home.getPrimaryKey()==null)
627             return "CCMHomeImpl";
628
629         return "CCMHomeWithPKImpl";
630     }
631
632     /**
633      **
634      **/

635     public java.lang.String JavaDoc
636     implementedHomeExecutor(org.objectweb.ccm.IDL3.HomeDecl home)
637     {
638         if (home.getPrimaryKey()==null)
639             return "HomeExecutor";
640
641         return "HomeExecutorWithPK";
642     }
643
644     /**
645      **
646      **/

647     public java.lang.String JavaDoc
648     homeExecutorOps(org.objectweb.ccm.IDL3.HomeDecl home)
649     {
650         java.lang.String JavaDoc id = "HOME_EXECUTOR_OPS";
651         java.lang.String JavaDoc key_abs_name = "";
652         if (home.getPrimaryKey()!=null)
653         {
654             id = id + "_WITH_PK";
655             key_abs_name = getTranslator().getAbsoluteName(home.getPrimaryKey());
656         }
657
658         java.lang.String JavaDoc[] aliases = { "key_abs_name" };
659         java.lang.Object JavaDoc[] objs = { key_abs_name };
660         super.map(id, aliases, objs);
661
662
663         return "";
664     }
665  
666     /**
667      **
668      **/

669     public java.lang.String JavaDoc
670     primaryKeyOperations(org.objectweb.ccm.IDL3.HomeDecl home)
671     {
672         org.objectweb.ccm.IDL3.InterfaceDecl itf = null;
673         org.objectweb.ccm.IDL3.Declaration[] ops = null;
674
675         itf = home.getClientImplicitMapping();
676         ops = itf.getContents(true, org.objectweb.ccm.IDL3.DeclarationKind._dk_operation);
677
678         java.lang.String JavaDoc id = "";
679         java.lang.String JavaDoc[] aliases = { "obj" };
680         for (int i=0;i<ops.length;i++)
681         {
682             id = "HOME_OPERATION_SUPER";
683             if (getType(ops[i]).getTypeKind()==org.objectweb.ccm.IDL3.TypeKind._tk_void)
684                 id = id + "_VOID";
685
686             java.lang.Object JavaDoc[] objs = { ops[i] };
687             super.map(id, aliases, objs);
688         }
689
690         return "";
691     }
692
693     /**
694      **
695      **/

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

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

777     public java.lang.String JavaDoc
778     portUids(org.objectweb.ccm.IDL3.Scope scope)
779     {
780         org.objectweb.ccm.IDL3.Declaration[] objs = null;
781         java.lang.String JavaDoc res = "";
782         objs = scope.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_provides +
783                                         org.objectweb.ccm.IDL3.DeclarationKind._dk_consumes +
784                                         org.objectweb.ccm.IDL3.DeclarationKind._dk_emits +
785                                         org.objectweb.ccm.IDL3.DeclarationKind._dk_publishes +
786                                         org.objectweb.ccm.IDL3.DeclarationKind._dk_uses);
787
788         for (int i=0;i<objs.length;i++)
789             res = res+"\""+objs[i].getId()+"\", ";
790
791         if (!res.equals(""))
792             res = res.substring(0, res.length()-2);
793
794         return res;
795     }
796
797     /**
798      **
799      **/

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

840     public java.lang.String JavaDoc
841     executorWrappers(org.objectweb.ccm.IDL3.ComponentDecl comp)
842     {
843         org.objectweb.ccm.IDL3.Declaration[] objs = null;
844         objs = comp.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_consumes);
845
846         java.lang.String JavaDoc[] aliases = { "obj", "pack_name", "port_id" };
847         for (int i=0;i<objs.length;i++)
848         {
849             org.objectweb.ccm.IDL3.ConsumesDecl cons = (org.objectweb.ccm.IDL3.ConsumesDecl)objs[i];
850             org.objectweb.ccm.IDL3.EventDecl event = (org.objectweb.ccm.IDL3.EventDecl)cons.getType();
851
852             java.lang.Object JavaDoc[] objs2 = { event, javaPackage(event),
853                                          cons.getId() };
854             super.map("COMPONENT_EVENT_WRAPPER", aliases, objs2);
855         }
856
857         return "";
858     }
859
860     // ==================================================================
861
//
862
// Public methods (event related).
863
//
864
// ==================================================================
865

866     /**
867      **
868      **/

869     public java.lang.String JavaDoc
870     eventConsumerOpWrapper(org.objectweb.ccm.IDL3.EventDecl event)
871     {
872         org.objectweb.ccm.IDL3.InterfaceDecl itf = null;
873         org.objectweb.ccm.IDL3.Declaration[] ops = null;
874         itf = event.getClientMapping();
875         ops = itf.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_operation);
876
877         for (int i=0;i<ops.length;i++)
878         {
879             if (!ops[i].getName().equals("push_event"))
880                 visitContainedWithMapping(event, ops[i], "_EVENT_CONSUMER_WRAPPER");
881         }
882
883         return "";
884     }
885
886     // ==================================================================
887
//
888
// Public methods (interceptor related).
889
//
890
// ==================================================================
891

892     /**
893      **
894      **/

895     public java.lang.String JavaDoc
896     delegateOperations(org.objectweb.ccm.IDL3.Scope scope)
897     {
898         org.objectweb.ccm.IDL3.Declaration[] objs = null;
899         objs = scope.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_operation +
900                                         org.objectweb.ccm.IDL3.DeclarationKind._dk_attribute);
901
902         for (int i=0;i<objs.length;i++)
903         {
904             if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_attribute)
905             {
906                 org.objectweb.ccm.IDL3.AttributeDecl attr = (org.objectweb.ccm.IDL3.AttributeDecl)objs[i];
907                 if (attr.isReadonly())
908                     visitContained(attr, "_READONLY_DELEGATE");
909                 else
910                     visitContained(attr, "_DELEGATE");
911             }
912             else
913                 visitContained(objs[i], "_DELEGATE");
914         }
915
916         return "";
917     }
918
919     /**
920      **
921      **/

922     public java.lang.String JavaDoc
923     interceptorDelegateWrapper(org.objectweb.ccm.IDL3.Declaration obj,
924                                java.lang.String JavaDoc name)
925     {
926         if (obj.getDeclKind()!=org.objectweb.ccm.IDL3.DeclarationKind._dk_consumes)
927             return name;
928
929         return "new "+name(obj)+"EventWrapper("+name+")";
930     }
931
932     /**
933      **
934      **/

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

975     public java.lang.String JavaDoc
976     facetOperations(org.objectweb.ccm.IDL3.Scope scope)
977     {
978         org.objectweb.ccm.IDL3.Declaration[] objs = null;
979         objs = scope.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_operation +
980                     /*org.objectweb.ccm.IDL3.DeclarationKind._dk_provides +*/
981                                  org.objectweb.ccm.IDL3.DeclarationKind._dk_attribute);
982         for (int i=0;i<objs.length;i++)
983         {
984             if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_attribute)
985             {
986                 org.objectweb.ccm.IDL3.AttributeDecl attr = (org.objectweb.ccm.IDL3.AttributeDecl)objs[i];
987                 if (attr.isReadonly())
988                     visitContained(attr, "_READONLY_FACET");
989                 else
990                     visitContained(attr, "_FACET");
991             }
992             else if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_operation)
993                     // obtaining facet operation
994
visitContained(objs[i], "_FACET");
995                 else
996                     visitContained(objs[i], "_PROVIDES");
997         }
998 // if (op.getParent().getAbsoluteName().startsWith("::Components"))
999
// continue ;
1000
// else if (op.getType().getTypeKind()==org.objectweb.ccm.IDL3.TypeKind._tk_void)
1001
// visitContained(op, "_IMPL_VOID");
1002
// else if (op.getName().startsWith("get_"))
1003
// // obtaining facet operation
1004
// visitContained(op, "_IMPL_FACET");
1005
// else
1006
// visitContained(op, "_IMPL");
1007

1008        return "";
1009    }
1010// Reactor stuff
1011
public java.lang.String JavaDoc
1012    pound()
1013    {
1014        return "$";
1015    }
1016
1017    public java.lang.String JavaDoc
1018    getManagedComponentName(org.objectweb.ccm.IDL3.InterfaceDecl obj)
1019    {
1020       return name(((org.objectweb.ccm.IDL3.HomeDecl)obj).getManagedComponent());
1021    }
1022
1023    /**
1024     **
1025     **/

1026    public java.lang.String JavaDoc
1027    componentOperations(org.objectweb.ccm.IDL3.Scope scope)
1028    {
1029        org.objectweb.ccm.IDL3.Declaration[] objs = null;
1030        objs = scope.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_operation +
1031                    org.objectweb.ccm.IDL3.DeclarationKind._dk_attribute);
1032        for (int i=0;i<objs.length;i++)
1033        {
1034            if (objs[i].getParent().getAbsoluteName().startsWith("::Components"))
1035                    continue ;
1036            if (objs[i].getName().equals("create"))
1037                    continue ;
1038            if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_attribute)
1039            {
1040                org.objectweb.ccm.IDL3.AttributeDecl attr = (org.objectweb.ccm.IDL3.AttributeDecl)objs[i];
1041                if (attr.isReadonly())
1042                    visitContained(attr, "_READONLY_COMPONENT");
1043                else
1044                    visitContained(attr, "_COMPONENT");
1045            }
1046            else if (objs[i].getName().startsWith("provide_"))
1047                    // obtaining facet operation
1048
visitContained(objs[i], "_GET_FACET");
1049            else // obtaining facet operation
1050
visitContained(objs[i], "_COMPONENT");
1051        }
1052
1053        return "";
1054    }
1055
1056    public java.lang.String JavaDoc
1057    replace(java.lang.String JavaDoc source, java.lang.String JavaDoc from, java.lang.String JavaDoc to)
1058    {
1059        return source.replaceFirst(from, to);
1060    }
1061    
1062    /**
1063     **
1064     **/

1065    public java.lang.String JavaDoc
1066    interceptorUserOperations(org.objectweb.ccm.IDL3.Scope scope)
1067    {
1068        org.objectweb.ccm.IDL3.Declaration[] objs = null;
1069        objs = scope.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_operation +
1070                                 org.objectweb.ccm.IDL3.DeclarationKind._dk_attribute);
1071        for (int i=0;i<objs.length;i++)
1072        {
1073            if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_attribute)
1074            {
1075                org.objectweb.ccm.IDL3.AttributeDecl attr = (org.objectweb.ccm.IDL3.AttributeDecl)objs[i];
1076                if (attr.isReadonly())
1077                    visitContained(attr, "_READONLY_USER_INTERCEPTOR");
1078                else
1079                    visitContained(attr, "_USER_INTERCEPTOR");
1080            }
1081            else
1082                visitContained(objs[i], "_USER_INTERCEPTOR");
1083        }
1084
1085        return "";
1086    }
1087
1088    /**
1089     **
1090     **/

1091    public java.lang.String JavaDoc
1092    interceptorTclOperations(org.objectweb.ccm.IDL3.Scope scope)
1093    {
1094        org.objectweb.ccm.IDL3.Declaration[] objs = null;
1095        objs = scope.getContents(false, org.objectweb.ccm.IDL3.DeclarationKind._dk_operation +
1096                                 org.objectweb.ccm.IDL3.DeclarationKind._dk_attribute);
1097        for (int i=0;i<objs.length;i++)
1098        {
1099            if (objs[i].getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_attribute)
1100            {
1101                org.objectweb.ccm.IDL3.AttributeDecl attr = (org.objectweb.ccm.IDL3.AttributeDecl)objs[i];
1102                if (attr.isReadonly())
1103                    visitContained(attr, "_READONLY_TCL");
1104                else
1105                    visitContained(attr, "_TCL");
1106            }
1107            else
1108                visitContained(objs[i], "_TCL");
1109        }
1110
1111        return "";
1112    }
1113  public java.lang.String JavaDoc
1114  toStringMode(int mode)
1115  {
1116      if (mode==org.objectweb.ccm.IDL3.OperationDecl.PARAM_IN)
1117          return "in";
1118      else if (mode==org.objectweb.ccm.IDL3.OperationDecl.PARAM_OUT)
1119          return "out";
1120      else
1121          return "inout";
1122  }
1123        
1124  public java.lang.String JavaDoc
1125  createParameterArray (org.objectweb.ccm.IDL3.OperationDecl op) {
1126
1127    ExceptionDecl[] raises = op.getExceptions();
1128    p = op.getParameters();
1129    int inCount = 0;
1130    int outCount = 0;
1131    int [] parameterModes = p.getParamModes();
1132    TypeRef [] ptRef =p.getParamTypes();
1133    String JavaDoc [] pnames = p.getParamNames();
1134    StringBuffer JavaDoc sb = new StringBuffer JavaDoc(" par = new Parameter[] {\n");
1135    String JavaDoc comma = " ";
1136    String JavaDoc id = null;
1137
1138
1139    for (int j = 0; j < ptRef.length; j++) {
1140      if (isPrimitive(ptRef[j]))
1141        id = toJava(ptRef[j]);
1142      else {
1143        try {
1144          id = ptRef[j].getIDLType().type().id(); //idlTranslator.toIDL(ptRef[j]);
1145
}catch (Exception JavaDoc e) {
1146          sb.append("EXCEPTION RAISED\n"+pnames[j]);// e.printStackTrace();
1147
}
1148      }
1149 
1150      sb.append(comma + "new Parameter(\"" + toStringMode(parameterModes[j]) + "\", \"" + id + "\", \"" + pnames[j] + "\")");
1151      comma = ",\n ";
1152    }
1153  
1154    if (op.getType().getTypeKind() != org.objectweb.ccm.IDL3.TypeKind._tk_void) {
1155 // id = idlTranslator.toIDL(op.getType());
1156
if (isPrimitive(op.getType()))
1157        id = toJava(op.getType());
1158      else {
1159        try {
1160          id = op.getType().getIDLType().type().id(); //idlTranslator.toIDL(ptRef[j]);
1161
}catch (Exception JavaDoc e) {
1162          sb.append("EXCEPTION RAISED in return value");// e.printStackTrace();
1163
}
1164      }
1165      
1166      sb.append(comma + "new Parameter(\"return\", \"" + id + "\", \"return\")");
1167    }
1168    sb.append("\n};\n");
1169    sb.append(" val = new org.omg.CORBA.Any[par.length];\n");
1170    sb.append(" for (int i = 0; i < val.length; i++) {\n");
1171    sb.append(" val[i] = m_orb.create_any();\n");
1172    sb.append(" }\n");
1173 
1174    for (int j = 0; j < parameterModes.length; j++) {
1175      sb.append(" ");
1176      if (parameterModes[j] == org.objectweb.ccm.IDL3.OperationDecl.PARAM_IN) {
1177        sb.append(getInsertExpression(ptRef[j], "val[" + j + "]", pnames[j]) + ";\n");
1178      }
1179      if (parameterModes[j] == org.objectweb.ccm.IDL3.OperationDecl.PARAM_INOUT) {
1180        sb.append(getInsertExpression(ptRef[j], "val[" + j + "]", pnames[j] + ".value") + ";\n");
1181      }
1182      if (parameterModes[j] == org.objectweb.ccm.IDL3.OperationDecl.PARAM_OUT) {
1183        sb.append("val[" + j + "] = IdlNode.create(" + getTypeCodeExpression(ptRef[j]) + ").toAny();\n");
1184      }
1185    }
1186    
1187    if (op.getType().getTypeKind()!=org.objectweb.ccm.IDL3.TypeKind._tk_void) {
1188      sb.append(" val[" + parameterModes.length + "] = IdlNode.create(" + getTypeCodeExpression(op.getType()) + ").toAny();\n");
1189    }
1190    
1191    if (raises.length > 0) {
1192      sb.append(" String[] exceptions = new String[] {\n");
1193      comma = "";
1194      for (int j = 0; j < raises.length; j++) {
1195        sb.append(comma + " \"" + raises[j].getName() + "\"");
1196        comma = ",\n";
1197      }
1198      sb.append("\n };\n");
1199      sb.append(" org.omg.CORBA.TypeCode[] exceptionTypes = new org.omg.CORBA.TypeCode[] {\n");
1200      comma = " ";
1201      for (int j = 0; j < raises.length; j++) {
1202        sb.append(comma + getHelperName(raises[j]) + ".type()");
1203        comma = ",\n ";
1204      }
1205      sb.append("\n };\n");
1206      sb.append(" IdlReply opr = new IdlReply(\"" + op.getParent().getId() + "\", \"" + op.getName() + "\", par, val, exceptions, exceptionTypes);\n");
1207    } else {
1208      sb.append(" IdlReply opr = new IdlReply(\"" + op.getParent().getId() + "\", \"" + op.getName() + "\", par, val);\n");
1209    }
1210     return sb.toString();
1211  }
1212
1213  public java.lang.String JavaDoc
1214  processReturnValue(org.objectweb.ccm.IDL3.OperationDecl op)
1215  {
1216    StringBuffer JavaDoc sb = new StringBuffer JavaDoc("");
1217    ExceptionDecl [] excepts = null;
1218    ExceptionList el = null;
1219    org.omg.CORBA.ExceptionDef JavaDoc [] ced = null;
1220    
1221    if (op == null) {
1222        return "oops";
1223    }
1224    
1225    excepts = op.getExceptions();
1226    el = op.getExceptionList();
1227    ced = el.getExceptionDefs();
1228    
1229    String JavaDoc comma = "";
1230    
1231    int [] parameterModes = null;
1232    TypeRef [] ptRef = null;
1233    String JavaDoc [] pnames = null;
1234
1235    if ( p != null) {
1236      parameterModes = p.getParamModes();
1237      ptRef =p.getParamTypes();
1238      pnames = p.getParamNames();
1239    }
1240    
1241    
1242    if (excepts.length > 0) {
1243      sb.append(" if (opr.isException()) {\n");
1244      sb.append(" String _ex_id = opr.getException().getId();\n");
1245 
1246      for (int j = 0; j < excepts.length; j++) {
1247        sb.append(" if (_ex_id.equals(\"" + excepts[j].getId() + "\")) {\n");
1248        sb.append(" throw " + getHelperName(excepts[j]) + ".extract(opr.getException().toAny());\n");
1249        sb.append(" }\n");
1250      }
1251      sb.append(" }\n");
1252    }
1253    
1254    sb.append(" opr.getValues(val);\n");
1255    sb.append("}\n");
1256    // extract of references fails for some reason
1257
// write holder values
1258
for (int j = 0; j < ptRef.length; j++) {
1259      if (parameterModes[j] != org.objectweb.ccm.IDL3.OperationDecl.PARAM_IN) {
1260        sb.append(pnames[j] + ".value = " + getExtractExpression(ptRef[j], "val[" + j + "]") + ";\n");
1261      }
1262    }
1263    if (op.getType().getTypeKind()!=org.objectweb.ccm.IDL3.TypeKind._tk_void) {
1264      sb.append(getTranslator().toJava(op.getType()) + " _result = " + getExtractExpression(op.getType(), "val[" + ptRef.length + "]") + ";\n");
1265      sb.append(" return _result;\n");
1266    }
1267
1268  return sb.toString();
1269  }
1270
1271  public String JavaDoc
1272  getExtractExpression(org.objectweb.ccm.IDL3.TypeRef type, String JavaDoc any) {
1273
1274        String JavaDoc expr = null;
1275        
1276        if (isPrimitive(type)) {
1277            expr = any + ".extract_"+ toJava(type)+"()";
1278        } else {
1279            expr = toJava(type)+"Helper.extract(" + any + ")";
1280        }
1281        
1282        return expr;
1283
1284// return any + ".extract_"+ toJava(type) + "()";
1285
}
1286
1287  public String JavaDoc
1288  getInsertExpression(org.objectweb.ccm.IDL3.TypeRef type, String JavaDoc any, String JavaDoc var) {
1289
1290        String JavaDoc expr = null;
1291        
1292        if (isPrimitive(type)) {
1293            expr = any + ".insert_"+ toJava(type)+"(" + var + ")";
1294        } else {
1295            expr = toJava(type)+"Helper.insert(" + any + ", " + var + ")";
1296        }
1297        
1298        return expr;
1299
1300  /* if (type instanceof ConstrTypeSpec || type instanceof TypeDeclarator || type instanceof InterfaceDecl || type instanceof ValueDecl || type instanceof FixedPointType || type instanceof SequenceType || type instanceof ArrayType) {
1301            expr = getTranslator().toJava(type) + "Helper.insert(" + any + ", " + var + ")";
1302        } else if (type instanceof ScopedName) {
1303            expr = getInsertExpression(((ScopedName)type).getType(), any, var);
1304*/

1305// return expr;
1306
}
1307    
1308    
1309    boolean
1310    isPrimitive(org.objectweb.ccm.IDL3.TypeRef typeref)
1311    {
1312        switch(typeref.getTypeKind())
1313        {
1314            case org.objectweb.ccm.IDL3.TypeKind._tk_short :
1315            case org.objectweb.ccm.IDL3.TypeKind._tk_ushort :
1316            case org.objectweb.ccm.IDL3.TypeKind._tk_long :
1317            case org.objectweb.ccm.IDL3.TypeKind._tk_ulong :
1318            case org.objectweb.ccm.IDL3.TypeKind._tk_longlong :
1319            case org.objectweb.ccm.IDL3.TypeKind._tk_ulonglong :
1320            case org.objectweb.ccm.IDL3.TypeKind._tk_float :
1321            case org.objectweb.ccm.IDL3.TypeKind._tk_double :
1322            case org.objectweb.ccm.IDL3.TypeKind._tk_longdouble :
1323            case org.objectweb.ccm.IDL3.TypeKind._tk_boolean :
1324            case org.objectweb.ccm.IDL3.TypeKind._tk_char :
1325            case org.objectweb.ccm.IDL3.TypeKind._tk_wchar :
1326            case org.objectweb.ccm.IDL3.TypeKind._tk_octet :
1327            case org.objectweb.ccm.IDL3.TypeKind._tk_any :
1328            case org.objectweb.ccm.IDL3.TypeKind._tk_objref :
1329            case org.objectweb.ccm.IDL3.TypeKind._tk_string :
1330            case org.objectweb.ccm.IDL3.TypeKind._tk_wstring :
1331                return true;
1332                default:
1333                return false;
1334        }
1335    }
1336    
1337    public java.lang.String JavaDoc
1338    toJava(org.objectweb.ccm.IDL3.TypeRef typeref)
1339    {
1340        switch(typeref.getTypeKind())
1341        {
1342            case org.objectweb.ccm.IDL3.TypeKind._tk_short :
1343                return "short";
1344            case org.objectweb.ccm.IDL3.TypeKind._tk_ushort :
1345                return "ushort";
1346            case org.objectweb.ccm.IDL3.TypeKind._tk_long :
1347                return "long";
1348            case org.objectweb.ccm.IDL3.TypeKind._tk_ulong :
1349                return "ulong";
1350            case org.objectweb.ccm.IDL3.TypeKind._tk_longlong :
1351                return "longlong";
1352            case org.objectweb.ccm.IDL3.TypeKind._tk_ulonglong :
1353                return "ulonglong";
1354            case org.objectweb.ccm.IDL3.TypeKind._tk_float :
1355                return "float";
1356            case org.objectweb.ccm.IDL3.TypeKind._tk_double :
1357                return "double";
1358            case org.objectweb.ccm.IDL3.TypeKind._tk_longdouble :
1359                return "doubledouble";
1360            case org.objectweb.ccm.IDL3.TypeKind._tk_boolean :
1361                return "boolean";
1362            case org.objectweb.ccm.IDL3.TypeKind._tk_char :
1363                return "char";
1364            case org.objectweb.ccm.IDL3.TypeKind._tk_wchar :
1365                return "wchar";
1366            case org.objectweb.ccm.IDL3.TypeKind._tk_octet :
1367                return "octet";
1368            case org.objectweb.ccm.IDL3.TypeKind._tk_any :
1369                return "any";
1370/*
1371            case org.objectweb.ccm.IDL3.TypeKind._tk_Principal :
1372                return "org.omg.CORBA.Principal";
1373            case org.objectweb.ccm.IDL3.TypeKind._tk_TypeCode :
1374                return "org.omg.CORBA.TypeCode";
1375*/

1376            case org.objectweb.ccm.IDL3.TypeKind._tk_objref :
1377                return "Object";
1378            case org.objectweb.ccm.IDL3.TypeKind._tk_string :
1379                return "string";
1380            case org.objectweb.ccm.IDL3.TypeKind._tk_wstring :
1381                return "wstring";
1382/*
1383            case org.objectweb.ccm.IDL3.TypeKind._tk_fixed :
1384                return "java.Math.BigDecimal";
1385*/

1386            case org.objectweb.ccm.IDL3.TypeKind._tk_struct :
1387            case org.objectweb.ccm.IDL3.TypeKind._tk_union :
1388            case org.objectweb.ccm.IDL3.TypeKind._tk_enum :
1389            case org.objectweb.ccm.IDL3.TypeKind._tk_exception :
1390            case org.objectweb.ccm.IDL3.TypeKind._tk_value_box :
1391            case org.objectweb.ccm.IDL3.TypeKind._tk_value :
1392            case org.objectweb.ccm.IDL3.TypeKind._tk_native :
1393            case org.objectweb.ccm.IDL3.TypeKind._tk_abstract_interface :
1394            case org.objectweb.ccm.IDL3.TypeKind._tk_local_interface :
1395            case org.objectweb.ccm.IDL3.TypeKind._tk_interface :
1396            case org.objectweb.ccm.IDL3.TypeKind._tk_component :
1397            case org.objectweb.ccm.IDL3.TypeKind._tk_home :
1398            case org.objectweb.ccm.IDL3.TypeKind._tk_event :
1399                org.objectweb.ccm.IDL3.Declaration decl = (org.objectweb.ccm.IDL3.Declaration)typeref;
1400                return getTranslator().getAbsoluteName(decl);
1401         
1402            case org.objectweb.ccm.IDL3.TypeKind._tk_alias :
1403                org.objectweb.ccm.IDL3.AliasDecl alias = (org.objectweb.ccm.IDL3.AliasDecl)typeref;
1404                return getTranslator().getAbsoluteName(alias);
1405
1406            case org.objectweb.ccm.IDL3.TypeKind._tk_sequence :
1407            case org.objectweb.ccm.IDL3.TypeKind._tk_array :
1408                org.objectweb.ccm.IDL3.TypeRefImpl impl= (org.objectweb.ccm.IDL3.TypeRefImpl)typeref;
1409                java.lang.String JavaDoc str = toJava(impl.getContentType());
1410                return str+"[:-)]";
1411            default :
1412                return "";
1413        }
1414    }
1415
1416   public String JavaDoc
1417   getTypeCodeExpression(org.objectweb.ccm.IDL3.TypeRef type) {
1418    
1419    String JavaDoc expr;
1420    if (isPrimitive(type))
1421          expr = "org.omg.CORBA.ORB.init().get_primitive_tc("+tkToString(type.getIDLType().type())+")";
1422        else
1423          expr = toJava(type) + "Helper.type()";
1424          
1425        return expr;
1426    
1427    /*
1428        if (type instanceof ConstrTypeSpec || type instanceof TypeDeclarator || type instanceof InterfaceDecl || type instanceof ValueDecl || type instanceof FixedPointType) {
1429            expr = getTranslator().toJava(type) + "Helper.type()";
1430        } else if (type instanceof ScopedName) {
1431            expr = getTypeCodeExpression(((ScopedName)type).getType());
1432        } else if (type instanceof LongLongType) {
1433            if (((LongLongType)type).isUnsigned()) {
1434                expr = "org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_ulonglong)";
1435            } else {
1436                expr = "org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_longlong)";
1437            }
1438        } else if (type instanceof LongType) {
1439            if (((LongType)type).isUnsigned()) {
1440                expr = "org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_ulong)";
1441            } else {
1442                expr = "org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_long)";
1443            }
1444        } else if (type instanceof ShortType) {
1445            if (((ShortType)type).isUnsigned()) {
1446                expr = "org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_ushort)";
1447            } else {
1448                expr = "org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_short)";
1449            }
1450            expr = "org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_objref)";
1451        } else if (type instanceof SequenceType) {
1452            expr = "org.omg.CORBA.ORB.init().create_sequence_tc(" + ((SequenceType)type).getSize() + ", " + getTypeCodeExpression(((SequenceType)type).getType()) + ")";
1453        } else if (type instanceof ArrayType) {
1454            expr = "org.omg.CORBA.ORB.init().create_array_tc(" + ((ArrayType)type).getSize() + ", " + getTypeCodeExpression(((ArrayType)type).getType()) + ")";
1455        } else {
1456            System.err.println("unexpected type: " + type.getClass().getName());
1457        }
1458*/

1459// return expr;
1460
}
1461    
1462  public java.lang.String JavaDoc
1463  tkToString(org.omg.CORBA.TypeCode JavaDoc tc) {
1464
1465    try {
1466      switch (tc.kind().value()) {
1467    case org.omg.CORBA.TCKind._tk_boolean: { return "org.omg.CORBA.TCKind.tk_boolean";}
1468    case org.omg.CORBA.TCKind._tk_octet: { return "org.omg.CORBA.TCKind.tk_octet";}
1469    case org.omg.CORBA.TCKind._tk_short: { return "org.omg.CORBA.TCKind.tk_short";}
1470    case org.omg.CORBA.TCKind._tk_ushort: { return "org.omg.CORBA.TCKind.tk_ushort";}
1471    case org.omg.CORBA.TCKind._tk_long: { return "org.omg.CORBA.TCKind.tk_long";}
1472    case org.omg.CORBA.TCKind._tk_ulong: { return "org.omg.CORBA.TCKind.tk_ulong";}
1473    case org.omg.CORBA.TCKind._tk_longlong: { return "org.omg.CORBA.TCKind.tk_longlong";}
1474    case org.omg.CORBA.TCKind._tk_ulonglong: { return "org.omg.CORBA.TCKind.tk_ulonglong";}
1475    case org.omg.CORBA.TCKind._tk_float: { return "org.omg.CORBA.TCKind.tk_float";}
1476    case org.omg.CORBA.TCKind._tk_double: { return "org.omg.CORBA.TCKind.tk_double";}
1477    case org.omg.CORBA.TCKind._tk_longdouble: { return "org.omg.CORBA.TCKind.tk_longdouble";}
1478    case org.omg.CORBA.TCKind._tk_char: { return "org.omg.CORBA.TCKind.tk_char";}
1479    case org.omg.CORBA.TCKind._tk_string: { return "org.omg.CORBA.TCKind.tk_string";}
1480    case org.omg.CORBA.TCKind._tk_wchar: { return "org.omg.CORBA.TCKind.tk_wchar";}
1481    case org.omg.CORBA.TCKind._tk_wstring: { return "org.omg.CORBA.TCKind.tk_wstring";}
1482    case org.omg.CORBA.TCKind._tk_objref: { return "org.omg.CORBA.TCKind.tk_objref";}
1483    case org.omg.CORBA.TCKind._tk_fixed: { return "org.omg.CORBA.TCKind.tk_fixed";}
1484    case org.omg.CORBA.TCKind._tk_any: { return "org.omg.CORBA.TCKind.tk_any";}
1485    case org.omg.CORBA.TCKind._tk_void: { return "org.omg.CORBA.TCKind.tk_void";}
1486        default: { return tc.id(); }
1487      }
1488    } catch (Exception JavaDoc e) {
1489     e.printStackTrace();
1490    }
1491    return null;
1492  }
1493  
1494  
1495  public String JavaDoc getHelperName(org.objectweb.ccm.IDL3.Declaration decl) {
1496    
1497    return getTranslator().getAbsoluteName(decl)+"Helper";
1498  }
1499
1500  public String JavaDoc getHelperName(org.objectweb.ccm.IDL3.TypeRef typeref) {
1501
1502        switch(typeref.getTypeKind())
1503        {
1504            case org.objectweb.ccm.IDL3.TypeKind._tk_short :
1505            case org.objectweb.ccm.IDL3.TypeKind._tk_ushort :
1506                return "org.omg.CORBA.ShortHelper";
1507            case org.objectweb.ccm.IDL3.TypeKind._tk_long :
1508            case org.objectweb.ccm.IDL3.TypeKind._tk_ulong :
1509                return "org.omg.CORBA.LongLongHelper";
1510            case org.objectweb.ccm.IDL3.TypeKind._tk_longlong :
1511            case org.objectweb.ccm.IDL3.TypeKind._tk_ulonglong :
1512                return "org.omg.CORBA.LongLongHelper";
1513            case org.objectweb.ccm.IDL3.TypeKind._tk_float :
1514                return "org.omg.CORBA.FloatHelper";
1515            case org.objectweb.ccm.IDL3.TypeKind._tk_double :
1516            case org.objectweb.ccm.IDL3.TypeKind._tk_longdouble :
1517                return "org.omg.CORBA.DoubleHelper";
1518            case org.objectweb.ccm.IDL3.TypeKind._tk_boolean :
1519                return "org.omg.CORBA.BooleanHelper";
1520            case org.objectweb.ccm.IDL3.TypeKind._tk_char :
1521                return "org.omg.CORBA.CharHelper";
1522            case org.objectweb.ccm.IDL3.TypeKind._tk_wchar :
1523                return "org.omg.CORBA.WcharHelper";
1524            case org.objectweb.ccm.IDL3.TypeKind._tk_octet :
1525                return "org.omg.CORBA.OctetHelper";
1526            case org.objectweb.ccm.IDL3.TypeKind._tk_any :
1527                return "any";
1528/*
1529            case org.objectweb.ccm.IDL3.TypeKind._tk_Principal :
1530                return "org.omg.CORBA.Principal";
1531            case org.objectweb.ccm.IDL3.TypeKind._tk_TypeCode :
1532                return "org.omg.CORBA.TypeCode";
1533*/

1534            case org.objectweb.ccm.IDL3.TypeKind._tk_objref :
1535                return "org.omg.CORBA.ObjectHelper";
1536            case org.objectweb.ccm.IDL3.TypeKind._tk_string :
1537                return "org.omg.CORBA.StringHelper";
1538            case org.objectweb.ccm.IDL3.TypeKind._tk_wstring :
1539                return "org.omg.CORBA.WideStringHelper";
1540/*
1541            case org.objectweb.ccm.IDL3.TypeKind._tk_fixed :
1542                return "java.Math.BigDecimal";
1543*/

1544            case org.objectweb.ccm.IDL3.TypeKind._tk_struct :
1545            case org.objectweb.ccm.IDL3.TypeKind._tk_union :
1546            case org.objectweb.ccm.IDL3.TypeKind._tk_enum :
1547            case org.objectweb.ccm.IDL3.TypeKind._tk_exception :
1548            case org.objectweb.ccm.IDL3.TypeKind._tk_value_box :
1549            case org.objectweb.ccm.IDL3.TypeKind._tk_value :
1550            case org.objectweb.ccm.IDL3.TypeKind._tk_native :
1551            case org.objectweb.ccm.IDL3.TypeKind._tk_abstract_interface :
1552            case org.objectweb.ccm.IDL3.TypeKind._tk_local_interface :
1553            case org.objectweb.ccm.IDL3.TypeKind._tk_interface :
1554            case org.objectweb.ccm.IDL3.TypeKind._tk_component :
1555            case org.objectweb.ccm.IDL3.TypeKind._tk_home :
1556            case org.objectweb.ccm.IDL3.TypeKind._tk_event :
1557                org.objectweb.ccm.IDL3.Declaration decl = (org.objectweb.ccm.IDL3.Declaration)typeref;
1558                return getTranslator().getAbsoluteName(decl)+"Helper";
1559
1560            case org.objectweb.ccm.IDL3.TypeKind._tk_sequence :
1561            case org.objectweb.ccm.IDL3.TypeKind._tk_array :
1562        return toJava(typeref)+"qHelper";
1563        
1564// decl = (org.objectweb.ccm.IDL3.Declaration)typeref;
1565
// exceptie return getTranslator().getAbsoluteName(decl)+"qHelper";
1566
// org.objectweb.ccm.IDL3.TypeRefImpl impl= (org.objectweb.ccm.IDL3.TypeRefImpl)typeref;
1567
// return getTranslator().getAbsoluteName(typeref)+"xHelper";
1568

1569            case org.objectweb.ccm.IDL3.TypeKind._tk_alias :
1570                org.objectweb.ccm.IDL3.AliasDecl alias = (org.objectweb.ccm.IDL3.AliasDecl)typeref;
1571                return getHelperName(alias.getType());
1572
1573/*
1574            case org.objectweb.ccm.IDL3.TypeKind._tk_sequence :
1575            case org.objectweb.ccm.IDL3.TypeKind._tk_array :
1576                org.objectweb.ccm.IDL3.TypeRefImpl impl= (org.objectweb.ccm.IDL3.TypeRefImpl)typeref;
1577                java.lang.String str = toJava(impl.getContentType());
1578                return str+"[]";
1579*/

1580        default:
1581            System.err.println("unknown type: " + idlTranslator.toIDL(typeref));
1582        }
1583        return "";
1584    }
1585    
1586}
1587
Popular Tags