KickJava   Java API By Example, From Geeks To Geeks.

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


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.ModuleDecl;
31 import org.objectweb.openccm.ast.api.InterfaceList;
32 import org.objectweb.openccm.ast.api.InterfaceDecl;
33 import org.objectweb.openccm.ast.api.InterfacePortDecl;
34 import org.objectweb.openccm.ast.api.EventPortDecl;
35 import org.objectweb.openccm.ast.api.ComponentDecl;
36 import org.objectweb.openccm.ast.api.SegmentDecl;
37 import org.objectweb.openccm.ast.api.NativeDecl;
38 import org.objectweb.openccm.ast.api.OperationDecl;
39
40 /**
41  * This class generates CIF IDL for an OMG CIDL Segment.
42  *
43  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
44  *
45  * @version 0.1
46  */

47
48 public class SegmentMapping
49   implements org.objectweb.corba.generator.cif_idl.api.SegmentMapping
50 {
51     // ==================================================================
52
//
53
// Internal state.
54
//
55
// ==================================================================
56

57     /** The segment to map. */
58     private SegmentDecl seg_;
59
60     // ==================================================================
61
//
62
// Constructors.
63
//
64
// ==================================================================
65

66     /**
67      * The default constructor.
68      */

69     public SegmentMapping(SegmentDecl seg)
70     {
71         // Init internal states
72
seg_ = seg;
73     }
74
75     // ==================================================================
76
//
77
// Internal methods.
78
//
79
// ==================================================================
80

81     /**
82      * Create Segment Base CIF interface mapping : CIF_<segment_name>.
83      *
84      * @param module - The module to declare CIF mapping in.
85      * @param seg_base_mapping - The Segment base CIF interface mapping.
86      * @param comp - The binding component.
87      *
88      * @return The segment CIF mapping.
89      */

90     protected InterfaceDecl
91     create_seg_mapping(ModuleDecl module,
92                        InterfaceDecl seg_base_mapping,
93                        ComponentDecl comp)
94     {
95         InterfaceDecl seg_mapping = null;
96         InterfaceList list = null;
97         String JavaDoc[] facets = null;
98         String JavaDoc[] sinks = null;
99
100         seg_mapping = module.declareLocalInterface( "CIF_" + seg_.getName() );
101         list = seg_mapping.getInheritedInterfaceList();
102
103         // Add the CIF_SegmentBase interface
104
list.add(seg_base_mapping);
105
106         // Add the CCM_<providing_object_name> interface
107
// for each facet implemented
108
facets = seg_.getFacetList().getStrings();
109         for (int i=0; i<facets.length; i++)
110         {
111             InterfacePortDecl itf_port = null;
112             ComponentDecl current = null;
113
114             current = comp;
115             while ((current != null) && (itf_port == null))
116             {
117                 itf_port = (InterfacePortDecl) current.lookup(facets[i]);
118                 // Search facet declaration in the base component
119
current = comp.getBaseComponent();
120             }
121             list.add( itf_port.getLocalMapping() );
122         }
123
124         // Add the CCM_<providing_object_name> interface
125
// For each sink implemented
126
sinks = seg_.getSinkList().getStrings();
127         for (int i=0; i<sinks.length; i++)
128         {
129             EventPortDecl event_port = null;
130             ComponentDecl current = null;
131
132             current = comp;
133             while ((current != null) && (event_port == null))
134             {
135                 event_port = (EventPortDecl) current.lookup(sinks[i]);
136                 // Search sink declaration in the base component
137
current = comp.getBaseComponent();
138             }
139             list.add( event_port.getEvent().getLocalConsumerMapping() );
140         }
141
142         // Create the mapping
143
seg_mapping.create();
144
145         return seg_mapping;
146     }
147
148     /**
149      * Add Segment Base CIF interface mapping contents.
150      *
151      * @param seg_mapping - The Segment CIF interface mapping.
152      */

153     protected void
154     add_seg_mapping_contents(InterfaceDecl seg_mapping)
155     {
156         /** Create operations for persistence if needed **/
157         if (seg_.getAbstractStorageHome() != null)
158         {
159             NativeDecl ast = null,
160                        ash = null;
161             OperationDecl op = null;
162
163             ash = seg_.getAbstractStorageHome().getMapping();
164             ast = seg_.getAbstractStorageHome().getAbstractStorageType().getMapping();
165
166             op = seg_mapping.startOperation("get_state");
167             op.setType(ast);
168             op.create();
169             // Create an operation to get home ?
170
}
171     }
172
173     // ==================================================================
174
//
175
// Public methods for org.objectweb.openccm.generator.cif_idl.api.SegmentMapping
176
//
177
// ==================================================================
178

179     /**
180      * Declare CIF interfaces into Interface Repository.
181      *
182      * @param module - The module to declare CIF mapping in.
183      * @param seg_base_mapping - The Segment CIF interface mapping.
184      * @param comp - The binding component.
185      */

186     public void
187     declareCIF(ModuleDecl module,
188                InterfaceDecl seg_base_mapping,
189                ComponentDecl comp)
190     {
191         InterfaceDecl seg_mapping = null;
192
193         seg_mapping = create_seg_mapping(module,
194                                          seg_base_mapping,
195                                          comp);
196         add_seg_mapping_contents(seg_mapping);
197     }
198
199     // ==================================================================
200
//
201
// Public methods.
202
//
203
// ==================================================================
204

205 }
206
Popular Tags