KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > ast > lib > UsesDeclImpl


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): Philippe Merle, Mathieu Vadet.
23 Contributor(s): Christophe Demarey.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.ast.lib;
28
29 /** Used to access AST DeclarationKind. */
30 import org.objectweb.openccm.ast.api.DeclarationKind;
31
32 /** Used to access AST Declaration. */
33 import org.objectweb.openccm.ast.api.Declaration;
34
35 /** Used to access AST InterfaceDecl. */
36 import org.objectweb.openccm.ast.api.InterfaceDecl;
37
38 /** Used to access AST OperationDecl. */
39 import org.objectweb.openccm.ast.api.OperationDecl;
40
41 /** Used to access AST ComponentDecl. */
42 import org.objectweb.openccm.ast.api.ComponentDecl;
43
44 /** To use CORBA::ComponentIR::UsesDef. */
45 import org.omg.CORBA.ComponentIR.UsesDef;
46 import org.omg.CORBA.ComponentIR.UsesDefHelper;
47
48 /**
49  * UsesDeclImpl is a wrapper class for IDL uses port declarations.
50  *
51  * Inherits from:
52  * - InterfacePortDeclImpl as they are ports for an interface,
53  * - LocalContextOperationMapping
54  * to obtain the local context operation mapping.
55  *
56  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
57  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
58  *
59  * @version 0.3
60  */

61
62 public class UsesDeclImpl
63        extends InterfacePortDeclImpl
64        implements org.objectweb.openccm.ast.api.UsesDecl
65 {
66     // ==================================================================
67
//
68
// Internal state.
69
//
70
// ==================================================================
71

72     /** Reference to the CORBA 3.0 UsesDef. */
73     private UsesDef uses_def_;
74
75     /** Is multiple. */
76     private boolean is_multiple_;
77
78     /** Local context operation mapping. */
79     private OperationDecl[] local_context_mapping_;
80
81     // ==================================================================
82
//
83
// Constructor.
84
//
85
// ==================================================================
86

87     /**
88      * The constructor with the parent scope.
89      *
90      * @param rep The repository of the declaration.
91      * @param parent The parent scope of the uses declaration.
92      */

93     protected
94     UsesDeclImpl(Repository rep,
95                  ScopeImpl parent)
96     {
97         // Call the InterfacePortDeclImpl constructor.
98
super(rep, parent);
99
100         // Init internal state.
101
uses_def_ = null;
102         is_multiple_ = false;
103         local_context_mapping_ = null;
104     }
105
106     // ==================================================================
107
//
108
// Internal methods.
109
//
110
// ==================================================================
111

112     // ==================================================================
113
//
114
// Internal methods for DeclarationImpl.
115
//
116
// ==================================================================
117

118     /**
119      * Loads infos of the CORBA 3.0 UsesDef.
120      *
121      * @param contained The UsesDef to load.
122      */

123     protected void
124     load(org.omg.CORBA.Contained JavaDoc contained)
125     {
126         uses_def_ = UsesDefHelper.narrow(contained);
127         setInterface((InterfaceDecl)getRepository().
128                      lookupId(uses_def_.interface_type().id()));
129         is_multiple_ = uses_def_.is_multiple();
130         super.load(contained);
131     }
132
133     /**
134      * Obtain its CORBA 3.0 Contained reference.
135      *
136      * @return The Contained object associated with the uses declaration.
137      */

138     protected org.omg.CORBA.Contained JavaDoc
139     getContained()
140     {
141        return uses_def_;
142     }
143
144     // ==================================================================
145
//
146
// Public methods.
147
//
148
// ==================================================================
149

150     // ==================================================================
151
//
152
// Methods for OMG IDL org.objectweb.openccm.ast.api.WithDependencies
153
//
154
// ==================================================================
155

156     /**
157      * Obtain the declaration external dependencies.
158      *
159      * Note: for scopes, contained objects are not considered
160      * as dependencies.
161      *
162      * @return The list of dependencies as an array of Declaration.
163      */

164     public Declaration[]
165     getDependencies()
166     {
167         if (dependencies_!=null)
168             return dependencies_;
169
170         java.util.List JavaDoc uses_depend = new java.util.ArrayList JavaDoc();
171
172         // content
173
// TODO: The next test is not needed
174
// as InterfaceDecl is a Declaration, isn't it?
175
if (getInterface().isDeclaration())
176             uses_depend.add(getInterface());
177
178         Declaration[] depend = getInterface().getDependencies();
179         for (int i=0; i<depend.length; i++)
180             uses_depend.add(depend[i]);
181
182         dependencies_ = (Declaration[])uses_depend.toArray(new Declaration[0]);
183         return dependencies_;
184     }
185
186     // ==================================================================
187
//
188
// Methods for OMG IDL org.objectweb.openccm.ast.api.Declaration
189
//
190
// ==================================================================
191

192     /**
193      * Obtain its DeclarationKind.
194      *
195      * @return The DeclarationKind of the object.
196      */

197     public long
198     getDeclKind()
199     {
200         return DeclarationKind.dk_uses;
201     }
202
203     /**
204      * Create the uses declaration into the IFR.
205      */

206     public void
207     create()
208     {
209         uses_def_ = the_parent_.getComponentDef().
210                     create_uses(getId(), getName(), getVersion(),
211                                 interface_.getInterfaceDef(),
212                                 is_multiple_);
213         super.create();
214     }
215
216     // ==================================================================
217
//
218
// Methods for OMG IDL org.objectweb.openccm.ast.api.ClientOperationMapping
219
//
220
// ==================================================================
221

222     /**
223      * Obtain the client operation mapping.
224      *
225      * @return The client operation mapping.
226      */

227     public OperationDecl[]
228     getClientMapping()
229     {
230         if (client_mapping_!=null)
231             return client_mapping_;
232
233         // retrieve the client mapping interface.
234
InterfaceDecl client = ((ComponentDecl)the_parent_).getClientMapping();
235         client.getContents(true, DeclarationKind.dk_null);
236
237         client_mapping_ = new OperationDecl[3];
238         client_mapping_[0] = (OperationDecl)client.find("connect_"+getName());
239         client_mapping_[1] = (OperationDecl)client.find("disconnect_"+getName());
240
241         if (is_multiple_)
242             client_mapping_[2] = (OperationDecl)
243                                  client.find("get_connections_"+getName());
244         else
245             client_mapping_[2] = (OperationDecl)
246                                  client.find("get_connection_"+getName());
247
248         return client_mapping_;
249     }
250
251     // ==================================================================
252
//
253
// Methods for OMG IDL org.objectweb.openccm.ast.api.InterfacePortDecl
254
//
255
// ==================================================================
256

257     // ==================================================================
258
//
259
// Methods for OMG IDL org.objectweb.openccm.ast.api.LocalContextOperationMapping
260
//
261
// ==================================================================
262

263     /**
264      * Obtain the local context operation mapping.
265      *
266      * @return The local context operation mapping.
267      */

268     public OperationDecl[]
269     getLocalContextMapping()
270     {
271         if (local_context_mapping_!=null)
272             return local_context_mapping_;
273
274         // retrieve the context mapping local interface.
275
InterfaceDecl context = ((ComponentDecl)the_parent_).
276                                 getLocalContextMapping();
277         context.getContents(true, DeclarationKind.dk_null);
278
279         local_context_mapping_ = new OperationDecl[1];
280         if (is_multiple_)
281             local_context_mapping_[0] = (OperationDecl)
282                              context.find("get_connections_"+getName());
283         else
284             local_context_mapping_[0] = (OperationDecl)
285                              context.find("get_connection_"+getName());
286
287         return local_context_mapping_;
288     }
289     // ==================================================================
290
//
291
// Methods for OMG IDL org.objectweb.openccm.ast.api.UsesDecl
292
//
293
// ==================================================================
294

295     /**
296      * Set as multiple.
297      */

298     public void
299     setMultiple()
300     {
301         is_multiple_ = true;
302     }
303
304     /**
305      * Is it multiple?
306      *
307      * @return True if it is multiple, else false.
308      */

309     public boolean
310     isMultiple()
311     {
312         return is_multiple_;
313     }
314 }
315
Popular Tags