KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > ir3 > ProvidesDef_impl


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

26
27 package org.objectweb.openccm.ir3;
28
29 /**
30  * Implementation of the CORBA::ComponentIR::ProvidesDef interface.
31  *
32  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
33  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
34  *
35  * @version 0.5
36  */

37
38 public class ProvidesDef_impl
39      extends FeatureContained
40   implements org.omg.CORBA.ComponentIR.ProvidesDefOperations
41 {
42     // ==================================================================
43
//
44
// Internal state.
45
//
46
// ==================================================================
47

48     /** The provided interface. */
49     protected InterfaceDef_ref interface_type_;
50
51     /** Reference to the created local facet interface. */
52     protected org.omg.CORBA.ExtLocalInterfaceDef ccm_facet_executor_itf_;
53
54     // ==================================================================
55
//
56
// Constructor.
57
//
58
// ==================================================================
59

60     /** The default constructor. */
61     public
62     ProvidesDef_impl(IFR ifr,
63                      Container_impl container)
64     {
65         // Calls the FeatureContained contructor.
66
super(ifr, container);
67
68     // Sets the tie servant object.
69
setServant(new org.omg.CORBA.ComponentIR.ProvidesDefPOATie(this));
70
71         // Inits internal state.
72
interface_type_ = new InterfaceDef_ref(this);
73         ccm_facet_executor_itf_ = null;
74     }
75
76     // ==================================================================
77
//
78
// Public methods.
79
//
80
// ==================================================================
81

82     /**
83      * Obtain its CORBA::ComponentIR::ProvidesDef object reference.
84      */

85     public org.omg.CORBA.ComponentIR.ProvidesDef
86     asProvidesDef()
87     {
88         return org.omg.CORBA.ComponentIR.ProvidesDefHelper.narrow(asObject());
89     }
90
91     /**
92      * Obtain the CORBA::ComponentIR::ProvidesDescription of the declaration.
93      */

94     public org.omg.CORBA.ComponentIR.ProvidesDescription
95     describe_provides()
96     {
97         // create the CORBA::ProvidesDescription.
98
org.omg.CORBA.ComponentIR.ProvidesDescription description =
99             new org.omg.CORBA.ComponentIR.ProvidesDescription();
100         description.name = name();
101         description.id = id();
102         description.defined_in = getContainerID();
103         description.version = version();
104         description.interface_type = interface_type().id();
105
106         return description;
107     }
108
109     // ==================================================================
110
//
111
// For Contained_impl class.
112
//
113
// ==================================================================
114

115     /**
116      * To set the value field of the CORBA::Contained::Description struct.
117      */

118     public void
119     setDescriptionValue(org.omg.CORBA.Any JavaDoc any)
120     {
121         // insert it into the any.
122
org.omg.CORBA.ComponentIR.ProvidesDescriptionHelper.insert(any, describe_provides());
123     }
124
125     // ==================================================================
126
//
127
// Internal methods for managing dependencies.
128
//
129
// ==================================================================
130

131     /**
132      * Cuts dependencies to other objects.
133      */

134     protected void
135     cutDependencies()
136     {
137         // Destroys the equivalent local facet interface.
138
if(ccm_facet_executor_itf_ != null)
139         {
140 /**
141  * This code was commented in order to avoid error messages
142  * when trying to destroy the interface always referenced
143  * by other interfaces.
144  *
145  * try
146  * {
147  * ccm_facet_executor_itf_.destroy();
148  * }
149  * catch(org.omg.CORBA.OBJECT_NOT_EXIST exc)
150  * {
151  * // Thrown because this interface was previously destroyed.
152  * }
153  * catch(org.omg.CORBA.BAD_INV_ORDER exc)
154  * {
155  * // Thrown because this interface could not be destroyed
156  * // currently as there are still dependencies on it.
157  * }
158  */

159             ccm_facet_executor_itf_ = null;
160         }
161
162         // Cuts the dependency to the provided interface type.
163
interface_type_.cutDependency();
164         interface_type_ = null;
165
166         // Calls the Contained_impl::cutDependencies operation.
167
super.cutDependencies();
168     }
169
170     // ==================================================================
171
//
172
// For CORBA::IRObject interface.
173
//
174
// ==================================================================
175

176     /**
177      * IDL:omg.org/CORBA/IRObject/def_kind:1.0
178      */

179     public org.omg.CORBA.DefinitionKind JavaDoc
180     def_kind()
181     {
182         return org.omg.CORBA.DefinitionKind.dk_Provides;
183     }
184
185     // ==================================================================
186
//
187
// For CORBA::ComponentIR::ProvidesDef interface.
188
//
189
// ==================================================================
190

191     /**
192      * IDL:omg.org/CORBA/ComponentIR/ProvidesDef/interface_type:1.0
193      */

194     public org.omg.CORBA.InterfaceDef JavaDoc
195     interface_type()
196     {
197         // delegate to the InterfaceDef reference.
198
return interface_type_.asInterfaceDef();
199     }
200
201     // Warning: interface_type is a readonly attribute!
202
//
203
// Here, this allows us to implement the CORBA::Component::create_provides()
204
// operation in the same way that other create_* operations.
205
//
206
/**
207      * IDL:omg.org/CORBA/ComponentIR/ProvidesDef/interface_type:1.0
208      */

209     public void
210     interface_type(org.omg.CORBA.InterfaceDef JavaDoc val)
211     {
212         // try to cast val to a local InterfaceDef object
213
// and delegate to the InterfaceDef reference.
214
interface_type_.setDependency(castToLocal(val));
215     }
216
217     // ==================================================================
218
//
219
// For IDL2 mapping.
220
//
221
// ==================================================================
222

223     /**
224      * TODO
225      */

226     protected void
227     whenCreated()
228     {
229         // do nothing if mappings are not enabled.
230
if (!getIFR().getRepository().enable_mappings_)
231             return ;
232
233         // else create the mapping according to the CCM spec
234

235         //
236
// IDL2 mapping
237
//
238
// compute the container base repository id
239
String JavaDoc cont_base_id = getBaseContainerID();
240
241         // provides mappping :
242
//
243
// <interface_type> provide_<name>();
244
//
245
String JavaDoc name = "provide_" + name();
246         String JavaDoc version = version();
247         String JavaDoc id = cont_base_id + name + ':' + version;
248         InterfaceDef_impl container = (InterfaceDef_impl)container_;
249         container_.mapping_started_ = true;
250         container.create_operation(id, name, version,
251                                    interface_type_.asIDLType(),
252                                    org.omg.CORBA.OperationMode.OP_NORMAL,
253                                    new org.omg.CORBA.ParameterDescription JavaDoc[0],
254                                    new org.omg.CORBA.ExceptionDef JavaDoc[0],
255                                    new java.lang.String JavaDoc[0]);
256         container_.mapping_started_ = false;
257
258         //
259
// CIDL mapping
260
//
261
// check if the CCM_<interface_name> already exists.
262
cont_base_id = interface_type_.getImpl().getBaseContainerID();
263         version = interface_type_.getImpl().version();
264
265         name = "CCM_"+interface_type_.getImpl().name();
266         id = cont_base_id + name + ':' + version;
267         org.omg.CORBA.Contained JavaDoc contained = getIFR().getRepository().lookup_mapped_id(id);
268         org.omg.CORBA.ExtLocalInterfaceDef facet_executor = null;
269         if (contained==null)
270         {
271             //
272
// local interface CCM_<interface_name> : <interface_name> {};
273
//
274
org.omg.CORBA.InterfaceDef JavaDoc[] bases = new org.omg.CORBA.InterfaceDef JavaDoc[1];
275             bases[0] = interface_type();
276             interface_type_.getImpl().container_.mapping_started_ = true;
277             facet_executor = interface_type_.getImpl().container_.create_ext_local_interface(id, name, version, bases);
278         ccm_facet_executor_itf_ = facet_executor;
279             interface_type_.getImpl().container_.mapping_started_ = false;
280         }
281         else
282         {
283             facet_executor = org.omg.CORBA.ExtLocalInterfaceDefHelper.narrow(contained);
284         }
285
286         // local interface CCM_<component_name> : ...
287
// {
288
// CCM_<interface_name> get_<name>();
289
// };
290
//
291
cont_base_id = container_.getBaseContainerID();
292         version = container_.version();
293
294         String JavaDoc litf_id = cont_base_id + "CCM_" + container_.name() + ':' + version;
295         org.omg.CORBA.ExtLocalInterfaceDef litf = org.omg.CORBA.ExtLocalInterfaceDefHelper.narrow(
296              getIFR().getRepository().lookup_mapped_id(litf_id));
297
298         cont_base_id = computeBaseID(litf_id);
299         version = litf.version();
300         name = "get_" + name();
301         id = cont_base_id + name + ':' + version;
302
303         litf.create_operation(id, name, version,
304                               facet_executor,
305                               org.omg.CORBA.OperationMode.OP_NORMAL,
306                               new org.omg.CORBA.ParameterDescription JavaDoc[0],
307                               new org.omg.CORBA.ExceptionDef JavaDoc[0],
308                               new java.lang.String JavaDoc[0]);
309     }
310 }
311
Popular Tags