KickJava   Java API By Example, From Geeks To Geeks.

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


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

26
27 package org.objectweb.corba.generator.cif.lib;
28
29 // Package dependencies.
30
import org.objectweb.openccm.generator.java.ast.api.*;
31 import org.objectweb.openccm.generator.java.ast.lib.*;
32 import org.objectweb.openccm.ast.api.Declaration;
33 import org.objectweb.openccm.ast.api.DeclarationKind;
34 import org.objectweb.openccm.ast.api.InterfaceDecl;
35 import org.objectweb.openccm.ast.api.AttributeDecl;
36 import org.objectweb.openccm.ast.api.OperationDecl;
37 import org.objectweb.openccm.ast.api.ProvidesDecl;
38 import org.objectweb.openccm.ast.api.ConsumesDecl;
39 import org.objectweb.openccm.ast.utils.api.ExecutorInfo;
40
41
42 /**
43  * This class generates CIF implementation templates files for a component.
44  *
45  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
46  *
47  * @version 0.1
48  */

49
50 public class ComponentImplMapping
51   implements org.objectweb.corba.generator.cif.api.ComponentImplMapping
52 {
53     // ==================================================================
54
//
55
// Internal state.
56
//
57
// ==================================================================
58

59     /** Utility class to convert types in Java*/
60     static public org.objectweb.openccm.generator.translator.idl2java.api.IDL_JavaTranslator translator_;
61
62     /** The composition containing the component. */
63     private org.objectweb.openccm.ast.utils.api.CompositionInfo comp_;
64
65     // ==================================================================
66
//
67
// Constructors.
68
//
69
// ==================================================================
70

71     /**
72      * The default constructor.
73      *
74      * @param composition - The composition to manage.
75      **/

76     public ComponentImplMapping(org.objectweb.openccm.ast.api.CompositionDecl composition)
77     {
78         comp_ = new org.objectweb.openccm.ast.utils.lib.CompositionInfo(composition);
79     }
80
81     // ==================================================================
82
//
83
// Internal methods.
84
//
85
// ==================================================================
86

87     /**
88      * Inits the static field.
89      **/

90     static
91     {
92         translator_ = new org.objectweb.openccm.generator.translator.idl2java.lib.IDL_JavaTranslator();
93     }
94
95     /**
96      * Call mapping actions for component session operations.
97      * These operations come from ::Components::SessionComponent IDL interface.
98      *
99      * @param clazz - Add methods to the Component class.
100      */

101     private void
102     sessionComponentOperations(ClassObject clazz)
103     {
104         MethodObject method = null;
105         ParameterObject param = null;
106
107         // Add the configuration_complete method
108
method = new MethodObjectImpl();
109         method.addComment(" Complete the component configuration.");
110         method.addComment(" ");
111         method.addComment(" @exception org.omg.Components.InvalidConfiguration");
112         method.addComment(" Thrown if the configuration is invalid.");
113         method.setName("configuration_complete");
114         method.setReturnType("void");
115         method.addException("org.omg.Components.InvalidConfiguration");
116         method.getImpl().setMacro("COMP_CONFIGURATION_COMPLETE");
117         clazz.addMethod(method);
118
119         // Add the set_session_context method
120
method = new MethodObjectImpl();
121         method.addComment(" Sets the session component context.");
122         method.addComment(" ");
123         method.addComment(" @param context The session component context.");
124         method.addComment(" ");
125         method.addComment(" @throw org.omg.Components.CCMException For any problems.");
126         method.setName("set_session_context");
127         method.setReturnType("void");
128         param = new ParameterObjectImpl();
129         param.setName("context");
130         param.setType("org.omg.Components.SessionContext");
131         method.addParameter(param);
132         method.addException("org.omg.Components.CCMException");
133         method.getImpl().setMacro("COMP_SET_SESSION_CONTEXT");
134         clazz.addMethod(method);
135
136         // Add the ccm_activate method
137
method = new MethodObjectImpl();
138         method.addComment(" Container callback to signal that the component is activated.");
139         method.addComment(" ");
140         method.addComment(" @throw org.omg.Components.CCMException For any problems.");
141         method.setName("ccm_activate");
142         method.setReturnType("void");
143         method.addException("org.omg.Components.CCMException");
144         method.getImpl().setMacro("COMP_CCM_ACTIVATE");
145         clazz.addMethod(method);
146
147         // Add the ccm_passivate method
148
method = new MethodObjectImpl();
149         method.addComment(" Container callback to signal that the component is passivated.");
150         method.addComment(" ");
151         method.addComment(" @throw org.omg.Components.CCMException For any problems.");
152         method.setName("ccm_passivate");
153         method.setReturnType("void");
154         method.addException("org.omg.Components.CCMException");
155         method.getImpl().setMacro("COMP_CCM_PASSIVATE");
156         clazz.addMethod(method);
157
158         // Add the ccm_remove method
159
method = new MethodObjectImpl();
160         method.addComment(" Container callback to signal that the component is removed.");
161         method.addComment(" ");
162         method.addComment(" @throw org.omg.Components.CCMException For any problems.");
163         method.setName("ccm_remove");
164         method.setReturnType("void");
165         method.addException("org.omg.Components.CCMException");
166         method.getImpl().setMacro("COMP_CCM_REMOVE");
167         clazz.addMethod(method);
168     }
169
170     /**
171      * Call mapping actions for component business operations and attributes.
172      * These operations and attributes can come from Monolithic executor
173      * (base monolithic executor, provides and consumes related operations),
174      * supported interfaces, and component attributes. </br>
175      * Implementation of provides related operations is checked only
176      * with the operation name (starting with "get_"). This could
177      * result in some trouble in some rare cases (e.g. an operation
178      * caming from a supported interface and which name starts with "get_").
179      *
180      * @param clazz - Add methods to the Component class.
181      */

182     private void
183     businessOperations(ClassObject clazz)
184     {
185         Declaration[] decls = null;
186         InterfaceDecl itf = null;
187         AttributeDecl attr = null;
188         OperationDecl op = null;
189         MethodObject method = null;
190
191         itf = comp_.getComponent().getLocalMainMapping();
192         decls = itf.getContents(false, DeclarationKind.dk_operation+
193                                        DeclarationKind.dk_attribute);
194
195         for (int i=0; i<decls.length; i++)
196         {
197             // Map Attributes
198
if (decls[i].getDeclKind() == DeclarationKind.dk_attribute)
199             {
200                 attr = (AttributeDecl)decls[i];
201
202                 method = translator_.map_attribute_accessor( (org.objectweb.openccm.ast.api.AttributeDecl)decls[i] );
203                 method.getImpl().setMacro("BUSINESS_OP");
204                 method.getImpl().addContextValue("translator", translator_);
205                 method.getImpl().addContextValue("obj", decls[i]);
206                 clazz.addMethod(method);
207
208                 method = translator_.map_attribute_mutator( (org.objectweb.openccm.ast.api.AttributeDecl)decls[i] );
209                 if (method != null)
210                 {
211                     method.getImpl().setMacro("TODO");
212                     clazz.addMethod(method);
213                 }
214             }
215             else
216             // Map Operations
217
{
218                 op = (OperationDecl)decls[i];
219
220                 if ( (!op.getParent().getAbsoluteName().startsWith("::Components")) &&
221                      (!op.getName().equals("get_")) )
222                 {
223                     method = translator_.map_operation(op);
224                     method.getImpl().setMacro("BUSINESS_OP");
225                     method.getImpl().addContextValue("translator", translator_);
226                     method.getImpl().addContextValue("obj", op);
227                     clazz.addMethod(method);
228                 }
229             }
230         }
231     }
232
233     /**
234      * Generates all component provided facets operations to implement.
235      *
236      * @param clazz - Add methods to the Component class.
237      */

238     private void
239     facetsOperations(ClassObject clazz)
240     {
241
242         Declaration[] decls = null;
243         ProvidesDecl provide = null;
244         ConsumesDecl consume = null;
245         ExecutorInfo exec_info = null;
246
247         // Get "provides" and "consumes" declaration
248
exec_info = new org.objectweb.openccm.ast.utils.lib.ExecutorInfo(
249                             comp_.getComponentExecutor() );
250         decls = exec_info.getMainSegmentFacets();
251
252         for (int i = 0; i<decls.length; i++)
253         {
254             if(decls[i].getDeclKind() == DeclarationKind.dk_provides)
255             {
256                 provide = (ProvidesDecl)decls[i];
257                 translator_.mapInterfaceOps(clazz, provide.getLocalMapping());
258             }
259             else
260             {
261                 consume = (ConsumesDecl)decls[i];
262                 translator_.mapInterfaceOps(clazz, consume.getEvent().getLocalConsumerMapping());
263             }
264         }
265     }
266
267     // ==================================================================
268
//
269
// Public methods for org.objectweb.openccm.generator.cif.api.ComponentImplMapping.
270
//
271
// ==================================================================
272

273     /**
274      * Generate Component template class.
275      *
276      * @param repository - The java repository.
277      **/

278     public void
279     toJavaComponentTemplate(Repository repository)
280     {
281         ClassObject clazz = null;
282         ConstructorObject ct = null;
283
284         clazz = new ClassObjectImpl(comp_.getComponent().getName()+"Impl");
285         clazz.addComment(" This is the CIDL-based implementation of the");
286         clazz.addComment(" OMG IDL3 "
287                          + comp_.getComponent().getId()
288                          + " component type.");
289         clazz.addComment("");
290         clazz.addComment(" @author OpenCCM CIF_Jimpl Compiler.");
291         clazz.setModifier(ModifierKindImpl.mk_public);
292         clazz.setPackage( translator_.getPackage(comp_.getHomeExecutor()) );
293         clazz.addInheritedObject( translator_.getPackage(comp_.getHomeExecutor()) + "." +
294                                   comp_.getComponentExecutor().getName() );
295
296         // Add the default constructor
297
ct = new ConstructorObjectImpl();
298         clazz.addConstructor(ct);
299
300         // Add Component methods
301
businessOperations(clazz);
302         facetsOperations(clazz);
303         sessionComponentOperations(clazz);
304
305         // Add object to the java repository
306
repository.addObject(clazz);
307     }
308
309     // ==================================================================
310
//
311
// Public methods.
312
//
313
// ==================================================================
314

315 }
316
Popular Tags