KickJava   Java API By Example, From Geeks To Geeks.

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


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::ProvidesDef. */
45 import org.omg.CORBA.ComponentIR.ProvidesDef;
46 import org.omg.CORBA.ComponentIR.ProvidesDefHelper;
47
48 /**
49  * ProvidesDeclImpl is a wrapper class for IDL provides port declarations.
50  *
51  * - InterfacePortDeclImpl as they are ports for an interface,
52  *
53  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
54  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
55  *
56  * @version 0.3
57  */

58
59 public class ProvidesDeclImpl
60        extends InterfacePortDeclImpl
61        implements org.objectweb.openccm.ast.api.ProvidesDecl
62 {
63     // ==================================================================
64
//
65
// Internal state.
66
//
67
// ==================================================================
68

69     /** Reference to the CORBA 3.0 ProvidesDef. */
70     private ProvidesDef provides_def_;
71
72     // ==================================================================
73
//
74
// Constructor.
75
//
76
// ==================================================================
77

78     /**
79      * The constructor with the parent scope.
80      *
81      * @param rep The repository of the declaration.
82      * @param parent The parent scope of the provides declaration.
83      */

84     protected
85     ProvidesDeclImpl(Repository rep,
86                      ScopeImpl parent)
87     {
88         // Call the InterfacePortDeclImpl constructor.
89
super(rep, parent);
90
91         // Init internal state.
92
provides_def_ = null;
93     }
94
95     // ==================================================================
96
//
97
// Internal methods.
98
//
99
// ==================================================================
100

101     // ==================================================================
102
//
103
// Internal methods for DeclarationImpl.
104
//
105
// ==================================================================
106

107     /**
108      * Loads infos of the CORBA 3.0 ProvidesDef.
109      *
110      * @param contained The ProvidesDef to load.
111      */

112     protected void
113     load(org.omg.CORBA.Contained JavaDoc contained)
114     {
115         provides_def_ = ProvidesDefHelper.narrow(contained);
116         setInterface((InterfaceDecl)getRepository().
117                      lookupId(provides_def_.interface_type().id()));
118         super.load(contained);
119     }
120
121     /**
122      * Obtain its CORBA 3.0 Contained reference.
123      *
124      * @return The Contained object associated with the provides declaration.
125      */

126     protected org.omg.CORBA.Contained JavaDoc
127     getContained()
128     {
129        return provides_def_;
130     }
131
132     // ==================================================================
133
//
134
// Public methods.
135
//
136
// ==================================================================
137

138     // ==================================================================
139
//
140
// Methods for OMG IDL org.objectweb.openccm.ast.api.WithDependencies
141
//
142
// ==================================================================
143

144     /**
145      * Obtain the declaration external dependencies.
146      *
147      * Note: for scopes, contained objects are not considered
148      * as dependencies.
149      *
150      * @return The list of dependencies as an array of Declaration.
151      */

152     public Declaration[]
153     getDependencies()
154     {
155         if (dependencies_!=null)
156             return dependencies_;
157
158         java.util.List JavaDoc provides_depend = new java.util.ArrayList JavaDoc();
159
160         // content
161
// TODO: The next test is not needed
162
// as InterfaceDecl is a Declaration, isn't it?
163
if (getInterface().isDeclaration())
164             provides_depend.add(getInterface());
165
166         Declaration[] depend = getInterface().getDependencies();
167         for (int i=0;i<depend.length;i++)
168             provides_depend.add(depend[i]);
169
170         dependencies_ = (Declaration[])provides_depend.toArray(
171                                                      new Declaration[0]);
172         return dependencies_;
173     }
174
175     // ==================================================================
176
//
177
// Methods for OMG IDL org.objectweb.openccm.ast.api.Declaration
178
//
179
// ==================================================================
180

181     /**
182      * Obtain its DeclarationKind.
183      *
184      * @return The DeclarationKind of the object.
185      */

186     public long
187     getDeclKind()
188     {
189         return DeclarationKind.dk_provides;
190     }
191
192     /**
193      * Create the provides declaration into the IFR.
194      */

195     public void
196     create()
197     {
198         provides_def_ = the_parent_.getComponentDef().
199                         create_provides(getId(), getName(), getVersion(),
200                                         interface_.getExtInterfaceDef());
201         super.create();
202     }
203
204     // ==================================================================
205
//
206
// Methods for OMG IDL org.objectweb.openccm.ast.api.ClientOperationMapping
207
//
208
// ==================================================================
209

210     /**
211      * Obtain the client operation mapping.
212      *
213      * @return The client operation mapping.
214      */

215     public OperationDecl[]
216     getClientMapping()
217     {
218         if (client_mapping_!=null)
219             return client_mapping_;
220
221         // retrieve the client mapping interface.
222
InterfaceDecl client = ((ComponentDecl)the_parent_).getClientMapping();
223         client.getContents(true, DeclarationKind.dk_null);
224
225         client_mapping_ = new OperationDecl[1];
226         client_mapping_[0] = (OperationDecl)client.find("provide_"+getName());
227         return client_mapping_;
228     }
229
230     // ==================================================================
231
//
232
// Methods for OMG IDL org.objectweb.openccm.ast.api.InterfacePortDecl
233
//
234
// ==================================================================
235

236     // ==================================================================
237
//
238
// Methods for OMG IDL org.objectweb.openccm.ast.api.ProvidesDecl
239
//
240
// ==================================================================
241
}
242
Popular Tags