KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > IDL3 > UsesDeclImpl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm-team@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): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.ccm.IDL3;
28
29 /**
30  * This class manages IDL uses port declarations.
31  *
32  * @author <a=href="Philippe.Merle@lifl.fr">Philippe Merle</a>
33  * <a=href="Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
34  *
35  * @version 0.3
36  */

37
38 public class UsesDeclImpl
39        extends DeclarationImpl
40        implements UsesDecl
41 {
42     // ==================================================================
43
//
44
// Internal state.
45
//
46
// ==================================================================
47

48     /**
49      ** Reference to the CORBA 3.0 UsesDef.
50      **/

51     private org.omg.CORBA.ComponentIR.UsesDef uses_def_;
52
53     /**
54      ** The port interface type.
55      **/

56     private InterfaceDeclImpl interface_;
57
58     /**
59      ** Is multiple.
60      **/

61     private boolean is_multiple_;
62
63     /**
64      **
65      **/

66     private OperationDeclImpl[] client_mapping_;
67
68     /**
69      **
70      **/

71     private OperationDeclImpl[] local_context_mapping_;
72
73     // ==================================================================
74
//
75
// Constructor.
76
//
77
// ==================================================================
78

79     /**
80      ** The constructor with the parent scope.
81      **
82      ** @param parent The parent scope of the uses declaration.
83      **/

84     protected
85     UsesDeclImpl(Repository rep, ScopeImpl parent)
86     {
87         // Call the DeclarationImpl constructor.
88
super(rep, parent);
89
90         // Init internal state.
91
uses_def_ = null;
92         client_mapping_ = null;
93         local_context_mapping_ = null;
94         interface_ = null;
95         is_multiple_ = false;
96         the_declaration_kind_ = DeclarationKind._dk_uses;
97     }
98
99     // ==================================================================
100
//
101
// Internal methods.
102
//
103
// ==================================================================
104

105     /**
106      ** Loads infos of the CORBA 3.0 UsesDef.
107      **
108      ** @param uses_def The UsesDef to load.
109      **/

110     protected void
111     load(org.omg.CORBA.Contained JavaDoc contained)
112     {
113         uses_def_ = org.omg.CORBA.ComponentIR.UsesDefHelper.narrow(contained);
114         setInterface((InterfaceRef)getRepository().lookupId(uses_def_.interface_type().id()));
115         is_multiple_ = uses_def_.is_multiple();
116         super.load(contained);
117     }
118
119     // ==================================================================
120
//
121
// Methods for the Declaration interface.
122
//
123
// ==================================================================
124

125     /**
126      ** Create the uses declaration into the IFR.
127      **/

128     public void
129     create()
130     {
131         uses_def_ = the_parent_.getComponentDef().create_uses(getId(), getName(),
132                                                               getVersion(),
133                                                               interface_.getInterfaceDef(),
134                                                               is_multiple_);
135
136         super.create();
137     }
138
139     /**
140      ** Obtain the declaration external dependencies.
141      ** Note: for scopes, contained objects are not considered
142      ** as dependencies.
143      **
144      ** @return The list of dependencies as an array of Declaration.
145      **/

146     public Declaration[]
147     getDependencies()
148     {
149         if (dependencies_!=null)
150             return dependencies_;
151
152         org.objectweb.ccm.util.Vector uses_depend = new org.objectweb.ccm.util.Vector();
153
154         // content
155
if (getType().isDeclaration())
156             uses_depend.add(getType());
157
158         Declaration[] depend = getType().getDependencies();
159         for (int i=0;i<depend.length;i++)
160             uses_depend.add(depend[i]);
161
162
163         dependencies_ = (Declaration[])uses_depend.toArray(new Declaration[0]);
164         return dependencies_;
165     }
166
167     // ==================================================================
168
//
169
// Methods for the ProvidesDecl interface.
170
//
171
// ==================================================================
172

173     /**
174      ** Set as multiple.
175      **/

176     public void
177     setMultiple()
178     {
179         is_multiple_ = true;
180     }
181
182     /**
183      ** Set the type.
184      **
185      ** @param itf The provided interface reference for the uses declaration.
186      **/

187     public void
188     setInterface(InterfaceRef itf)
189     {
190         if(itf != null)
191         {
192             interface_ = (InterfaceDeclImpl)itf;
193             interface_.addRef();
194         }
195     }
196
197     /**
198      **
199      **/

200     public TypeRef
201     getType()
202     {
203         return interface_;
204     }
205
206     /**
207      **
208      **/

209     public boolean
210     isMultiple()
211     {
212         return is_multiple_;
213     }
214
215     /**
216      **
217      **/

218     public OperationDecl[]
219     getClientMapping()
220     {
221         if (client_mapping_!=null)
222             return client_mapping_;
223
224         // retrieve the client mapping interface.
225
InterfaceDecl client = ((ComponentDecl)the_parent_).getClientMapping();
226         client.getContents(true, DeclarationKind._dk_null);
227
228         client_mapping_ = new OperationDeclImpl[3];
229         client_mapping_[0] = (OperationDeclImpl)client.find("connect_"+getName());
230         client_mapping_[1] = (OperationDeclImpl)client.find("disconnect_"+getName());
231
232         if (is_multiple_)
233             client_mapping_[2] = (OperationDeclImpl)client.find("get_connections_"+getName());
234         else
235             client_mapping_[2] = (OperationDeclImpl)client.find("get_connection_"+getName());
236
237         return client_mapping_;
238     }
239
240     /**
241      **
242      **/

243     public OperationDecl[]
244     getLocalContextMapping()
245     {
246         if (local_context_mapping_!=null)
247             return local_context_mapping_;
248
249         // retrieve the context mapping local interface.
250
InterfaceDecl context = ((ComponentDecl)the_parent_).getLocalContextMapping();
251         context.getContents(true, DeclarationKind._dk_null);
252
253         local_context_mapping_ = new OperationDeclImpl[1];
254         if (is_multiple_)
255             local_context_mapping_[0] = (OperationDeclImpl)context.find("get_connections_"+getName());
256         else
257             local_context_mapping_[0] = (OperationDeclImpl)context.find("get_connection_"+getName());
258
259         return local_context_mapping_;
260     }
261
262     // ==================================================================
263
//
264
// Methods for the inherited DeclarationImpl class.
265
//
266
// ==================================================================
267

268     /**
269      **
270      **/

271     public void
272     destroy()
273     {
274         if (interface_!=null)
275             interface_.removeRef();
276
277         super.destroy();
278     }
279
280     /**
281      ** Obtain its CORBA 3.0 Contained reference.
282      **
283      ** @return The Contained object associated with the uses declaration.
284      **/

285     protected org.omg.CORBA.Contained JavaDoc
286     getContained()
287     {
288        return uses_def_;
289     }
290 }
291
Popular Tags