KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > corba > generator > cif_idl > lib > ExecutorMapping


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_idl.lib;
28
29 // Package dependencies.
30
import org.objectweb.openccm.ast.api.ExecutorDecl;
31 import org.objectweb.openccm.ast.api.ComponentDecl;
32 import org.objectweb.openccm.ast.api.InterfacePortDecl;
33 import org.objectweb.openccm.ast.api.SegmentDecl;
34 import org.objectweb.openccm.ast.api.EventPortDecl;
35 import org.objectweb.openccm.ast.api.InterfaceList;
36 import org.objectweb.openccm.ast.api.NativeDecl;
37 import org.objectweb.openccm.ast.api.OperationDecl;
38 import org.objectweb.openccm.ast.api.InterfaceDecl;
39 import org.objectweb.openccm.ast.api.ModuleDecl;
40 import org.objectweb.openccm.ast.api.Declaration;
41 import org.objectweb.openccm.ast.api.CategoryKind;
42 import org.objectweb.openccm.ast.utils.api.CompositionInfo;
43 import org.objectweb.openccm.ast.utils.api.ExecutorInfo;
44 import org.objectweb.corba.generator.cif_idl.api.SegmentMapping;
45 import java.util.Set JavaDoc;
46
47
48 /**
49  * This class generates CIF IDL for an OMG CIDL Component Executor.
50  *
51  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
52  *
53  * @version 0.1
54  */

55
56 public class ExecutorMapping
57   implements org.objectweb.corba.generator.cif_idl.api.ExecutorMapping
58 {
59     // ==================================================================
60
//
61
// Internal state.
62
//
63
// ==================================================================
64

65     /** The component executor to map. */
66     private ExecutorDecl exec_;
67
68     // ==================================================================
69
//
70
// Constructors.
71
//
72
// ==================================================================
73

74     /**
75      * The default constructor.
76      *
77      * @param exec - The executor to map.
78      */

79     public ExecutorMapping(ExecutorDecl exec)
80     {
81         // Init internal states
82
exec_ = exec;
83     }
84
85     // ==================================================================
86
//
87
// Internal methods.
88
//
89
// ==================================================================
90

91     /**
92      * Add Component port interface mapping to the Interface List.
93      *
94      * @param composition - An abstract view of the binding composition.
95      * @param list - The list to add port mapping in.
96      */

97     protected void
98     addInterfacePortMapping(CompositionInfo composition,
99                             InterfaceList list)
100     {
101         ExecutorInfo exec_info = null;
102         Declaration[] implemented_facets = null;
103         Set JavaDoc itf_set = null;
104
105         itf_set = new java.util.HashSet JavaDoc();
106         exec_info = new org.objectweb.openccm.ast.utils.lib.ExecutorInfo(exec_);
107         implemented_facets = exec_info.getMainSegmentFacets();
108
109         // Add port mapping interface to the set
110
for (int i=0; i<implemented_facets.length; i++)
111         {
112             try {
113                 InterfacePortDecl itf_port = null;
114
115                 itf_port = (InterfacePortDecl) implemented_facets[i];
116                 itf_set.add( itf_port.getLocalMapping() );
117             }catch(ClassCastException JavaDoc e){
118                 EventPortDecl event_port = null;
119
120                 event_port = (EventPortDecl) implemented_facets[i];
121                 itf_set.add( event_port.getEvent().getLocalConsumerMapping() );
122             }
123         }
124
125         // Add all interfaces to the list
126
java.util.Iterator JavaDoc it = itf_set.iterator();
127         while ( it.hasNext() )
128         {
129             list.add((InterfaceDecl) it.next());
130         }
131     }
132
133     /**
134      * Create Executor CIF interface mapping.
135      *
136      * @param composition - An abstract view of the binding composition.
137      * @param module - The module to declare CIF mapping in.
138      * @param seg_base_mapping - The Segment base CIF interface mapping.
139      *
140      * @return The executor mapping.
141      */

142     protected InterfaceDecl
143     create_executor_mapping(CompositionInfo composition,
144                             ModuleDecl module,
145                             InterfaceDecl seg_base_mapping)
146     {
147         InterfaceDecl mapping = null,
148                       tmp = null;
149         InterfaceList list = null;
150         CategoryKind kind = null;
151
152
153         mapping = module.declareLocalInterface( "CIF_" + exec_.getName() );
154
155         // Feed inherited interface list
156
list = mapping.getInheritedInterfaceList();
157
158         // Add the CIF_SegmentBase interface
159
list.add(seg_base_mapping);
160
161         // Add the ExecutorLocator interface
162
tmp = (InterfaceDecl) exec_.getAST().lookup("::Components::ExecutorLocator");
163         list.add(tmp);
164
165         // Add the <kind>Component interface
166
kind = exec_.getCompositionKind();
167         if ( (kind == CategoryKind.ck_entity)
168              || (kind == CategoryKind.ck_process) )
169         {
170             tmp = (InterfaceDecl) exec_.getAST().lookup("::Components::EntityComponent");
171         }
172         else
173         {
174             tmp = (InterfaceDecl) exec_.getAST().lookup("::Components::SessionComponent");
175         }
176         list.add(tmp);
177
178         // Add the CCM_<component_name>_Executor interface (segmented strategy)
179
tmp = composition.getComponent().getLocalMainMapping();
180         list.add(tmp);
181
182         // Add facets and sinks directly implemented by the component executor
183
addInterfacePortMapping(composition, list);
184
185         // Create the mapping
186
mapping.create();
187
188         return mapping;
189     }
190
191     /**
192      * Add Executor CIF interface mapping contents.
193      *
194      * @param composition - An abstract view of the binding composition.
195      * @param mapping - The Executor CIF interface mapping.
196      * @param ast - The Executor Abstract Storage Type.
197      */

198     protected void
199     add_executor_mapping_contents(InterfaceDecl mapping,
200                                   NativeDecl ast)
201     {
202         if (ast != null)
203         {
204             OperationDecl op = null;
205
206            // create the get_state operation
207
op = mapping.startOperation("get_state");
208             op.setType(ast);
209             op.create();
210         }
211
212     }
213
214     /**
215      * Create Segment Base CIF interface mapping.
216      *
217      * @param composition - An abstract view of the binding composition.
218      *
219      * @return The segment base mapping.
220      */

221     protected InterfaceDecl
222     create_seg_base_mapping(ModuleDecl module)
223     {
224         InterfaceDecl seg_base_mapping = null;
225
226         seg_base_mapping = module.declareLocalInterface("CIF_SegmentBase");
227         seg_base_mapping.create();
228
229         return seg_base_mapping;
230     }
231
232     /**
233      * Add Segment Base CIF interface mapping contents.
234      *
235      * @param seg_base_mapping - The Segment Base CIF interface mapping.
236      * @param exec_mapping - The Executor CIF interface mapping.
237      * @param composition - An abstract view of the binding composition.
238      */

239     protected void
240     add_seg_base_mapping_contents(InterfaceDecl seg_base_mapping,
241                                   InterfaceDecl exec_mapping,
242                                   CompositionInfo composition)
243     {
244         OperationDecl op = null;
245
246         op = seg_base_mapping.startOperation("get_context");
247         // Retrieve CCM_<component_name>_Context interface
248
op.setType(composition.getComponent().getLocalContextMapping());
249         op.create();
250
251         op = seg_base_mapping.startOperation("get_main_segment");
252         op.setType(exec_mapping);
253         op.create();
254     }
255
256     // ==================================================================
257
//
258
// Public methods for org.objectweb.openccm.generator.cif_idl.api.ExecutorMapping
259
//
260
// ==================================================================
261

262     /**
263      * Declare CIF interfaces into Interface Repository.
264      *
265      * @param composition - An abstract view of the binding composition.
266      * @param module - The module to declare CIF mapping in.
267      * @param ast - The Executor Abstract Storage Type.
268      */

269     public void
270     declareCIF( CompositionInfo composition,
271                 ModuleDecl module,
272                 NativeDecl ast)
273     {
274         ComponentDecl comp = null;
275         SegmentDecl[] segments = null;
276         InterfaceDecl seg_base_mapping = null,
277                       exec_mapping = null;
278         SegmentMapping seg_mapping = null;
279
280         // Get the managed component
281
comp = composition.getComponent();
282
283         /** Create the segment base CIF interface **/
284         seg_base_mapping = create_seg_base_mapping(module);
285
286         /** Create the executor CIF interface **/
287         exec_mapping = create_executor_mapping(composition,
288                                                module,
289                                                seg_base_mapping);
290         add_executor_mapping_contents(exec_mapping, ast);
291
292         /** Finish creation of the segment base interface **/
293         add_seg_base_mapping_contents(seg_base_mapping,
294                                       exec_mapping,
295                                       composition);
296
297         /** Call mapping for segments **/
298         segments = composition.getSegments();
299         for (int i=0; i<segments.length; i++)
300         {
301             seg_mapping = new org.objectweb.corba.generator.cif_idl.lib.SegmentMapping(segments[i]);
302             seg_mapping.declareCIF( module,
303                                     seg_base_mapping,
304                                     comp );
305         }
306     }
307
308     // ==================================================================
309
//
310
// Public methods.
311
//
312
// ==================================================================
313

314 }
315
Popular Tags