KickJava   Java API By Example, From Geeks To Geeks.

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


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 provides 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 ProvidesDeclImpl
39        extends DeclarationImpl
40        implements ProvidesDecl
41 {
42     // ==================================================================
43
//
44
// Internal state.
45
//
46
// ==================================================================
47

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

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

56     private InterfaceDeclImpl interface_;
57
58     /**
59      **
60      **/

61     private OperationDeclImpl[] client_mapping_;
62
63      /**
64      **
65      **/

66     private InterfaceDeclImpl local_mapping_;
67
68    // ==================================================================
69
//
70
// Constructor.
71
//
72
// ==================================================================
73

74     /**
75      ** The constructor with the parent scope.
76      **
77      ** @param parent The parent scope of the provides declaration.
78      **/

79     protected
80     ProvidesDeclImpl(Repository rep, ScopeImpl parent)
81     {
82         // Call the DeclarationImpl constructor.
83
super(rep, parent);
84
85         // Init internal state.
86
provides_def_ = null;
87         client_mapping_ = null;
88         local_mapping_ = null;
89         interface_ = null;
90         the_declaration_kind_ = DeclarationKind._dk_provides;
91     }
92
93     // ==================================================================
94
//
95
// Internal methods.
96
//
97
// ==================================================================
98

99     /**
100      ** Loads infos of the CORBA 3.0 ProvidesDef.
101      **
102      ** @param provides_def The ProvidesDef to load.
103      **/

104     protected void
105     load(org.omg.CORBA.Contained JavaDoc contained)
106     {
107         provides_def_ = org.omg.CORBA.ComponentIR.ProvidesDefHelper.narrow(contained);
108         setInterface((InterfaceRef)getRepository().lookupId(provides_def_.interface_type().id()));
109         super.load(contained);
110     }
111
112     // ==================================================================
113
//
114
// Methods for the Declaration interface.
115
//
116
// ==================================================================
117

118     /**
119      ** Create the provides declaration into the IFR.
120      **/

121     public void
122     create()
123     {
124         provides_def_ = the_parent_.getComponentDef().create_provides(getId(), getName(),
125                                                                       getVersion(),
126                                                                       interface_.getExtInterfaceDef());
127
128         super.create();
129     }
130
131     /**
132      ** Obtain the declaration external dependencies.
133      ** Note: for scopes, contained objects are not considered
134      ** as dependencies.
135      **
136      ** @return The list of dependencies as an array of Declaration.
137      **/

138     public Declaration[]
139     getDependencies()
140     {
141         if (dependencies_!=null)
142             return dependencies_;
143
144         org.objectweb.ccm.util.Vector provides_depend = new org.objectweb.ccm.util.Vector();
145
146         // content
147
if (getType().isDeclaration())
148             provides_depend.add(getType());
149
150         Declaration[] depend = getType().getDependencies();
151         for (int i=0;i<depend.length;i++)
152             provides_depend.add(depend[i]);
153
154
155         dependencies_ = (Declaration[])provides_depend.toArray(new Declaration[0]);
156         return dependencies_;
157     }
158
159     // ==================================================================
160
//
161
// Methods for the ProvidesDecl interface.
162
//
163
// ==================================================================
164

165     /**
166      ** Set the interface type.
167      **
168      ** @param itf The provided interface reference.
169      **/

170     public void
171     setInterface(InterfaceRef itf)
172     {
173         if(itf != null)
174         {
175             interface_ = (InterfaceDeclImpl)itf;
176             interface_.addRef();
177         }
178     }
179
180     /**
181      **
182      **/

183     public TypeRef
184     getType()
185     {
186         return interface_;
187     }
188
189     /**
190      **
191      **/

192     public OperationDecl[]
193     getClientMapping()
194     {
195         if (client_mapping_!=null)
196             return client_mapping_;
197
198         // retrieve the client mapping interface.
199
InterfaceDecl client = ((ComponentDecl)the_parent_).getClientMapping();
200         client.getContents(true, DeclarationKind._dk_null);
201
202         client_mapping_ = new OperationDeclImpl[1];
203         client_mapping_[0] = (OperationDeclImpl)client.find("provide_"+getName());
204
205         return client_mapping_;
206     }
207
208     /**
209      * Obtain the local mapping. (CCM_<name> interface)
210      *
211      * @return The local interface mapping.
212      */

213     public InterfaceDecl
214     getLocalMapping()
215     {
216         if (local_mapping_==null)
217         {
218             // load the local interface mapping for this provides facet.
219
InterfaceDecl itf = (InterfaceDecl)getType();
220             String JavaDoc parent_base_id = itf.getParent().getId();
221             int idx = parent_base_id.lastIndexOf(':');
222             parent_base_id = parent_base_id.substring(0, idx);
223             String JavaDoc id = parent_base_id + "/CCM_" + itf.getName() + ":" + getVersion();
224             local_mapping_ = (InterfaceDeclImpl)getRepository().loadMapping(itf.getParent(), id);
225         }
226         return local_mapping_;
227     }
228
229     // ==================================================================
230
//
231
// Methods for the inherited DeclarationImpl class.
232
//
233
// ==================================================================
234

235     /**
236      **
237      **/

238     public void
239     destroy()
240     {
241         if (interface_!=null)
242             interface_.removeRef();
243
244         super.destroy();
245     }
246
247     /**
248      ** Obtain its CORBA 3.0 Contained reference.
249      **
250      ** @return The Contained object associated with the provides declaration.
251      **/

252     protected org.omg.CORBA.Contained JavaDoc
253     getContained()
254     {
255        return provides_def_;
256     }
257 }
258
Popular Tags