KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > ir3 > OperationDef_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 // Package dependencies
30
import org.omg.CORBA.*;
31
32 /**
33  * Implementation of the CORBA::OperationDef interface.
34  *
35  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
36  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
37  *
38  * @version 0.5
39  */

40
41 public class OperationDef_impl
42      extends FeatureContained
43   implements OperationDefOperations
44 {
45     // ==================================================================
46
//
47
// Internal state.
48
//
49
// ==================================================================
50

51     /** The result type of the operation. */
52     protected IDLType_ref result_def_;
53
54     /** The parameters of the operation. */
55     protected Parameters params_;
56
57     /** The mode of the operation. */
58     protected OperationMode mode_;
59
60     /** The contexts of the operation. */
61     protected String JavaDoc[] contexts_;
62
63     /** The exceptions of the operation. */
64     protected ExceptionDef_ref[] exceptions_;
65
66     // ==================================================================
67
//
68
// Constructors.
69
//
70
// ==================================================================
71

72     /** TODO. */
73     public
74     OperationDef_impl(IFR ifr,
75                       Container_impl container)
76     {
77         this(ifr, container, false);
78
79         // Sets the tie servant object.
80
setServant(new OperationDefPOATie(this));
81     }
82
83     /** TODO. */
84     public
85     OperationDef_impl(IFR ifr,
86                       Container_impl container,
87                       boolean dummy)
88     {
89         // Calls the FeatureContained contructor.
90
super(ifr, container);
91
92         // Creates the result_def reference.
93
result_def_ = new IDLType_ref(this,
94                               ifr.getRepository().getPrimDefVoid());
95
96         // Inits internal state.
97
params_ = new Parameters(this);
98         mode_ = OperationMode.OP_NORMAL;
99         contexts_ = null;
100         exceptions_ = null;
101     }
102
103     // ==================================================================
104
//
105
// Public methods.
106
//
107
// ==================================================================
108

109     /**
110      * Obtain its CORBA::OperationDef object reference.
111      */

112     public OperationDef
113     asOperationDef()
114     {
115         return OperationDefHelper.narrow(asObject());
116     }
117
118     /**
119      * Obtain its CORBA::OperationDescription.
120      */

121     public OperationDescription
122     getOperationDescription()
123     {
124         // create the CORBA::OperationDescription.
125
OperationDescription description = new OperationDescription();
126
127         // set its fields.
128
description.name = name();
129         description.id = id();
130         description.defined_in = getContainerID();
131         description.version = version();
132         description.result = result();
133         description.mode = mode();
134         description.contexts = contexts();
135         description.parameters = params();
136         description.exceptions =
137             ExceptionDef_impl.compute_ExcDescriptionSeq(exceptions_);
138
139         return description;
140     }
141
142     // ==================================================================
143
//
144
// For Contained_impl class.
145
//
146
// ==================================================================
147

148     /**
149      * To set the value field of the CORBA::Contained::Description struct.
150      */

151     public void
152     setDescriptionValue(Any any)
153     {
154         // insert its CORBA::OperationDescription into the any.
155
OperationDescriptionHelper.insert(any, getOperationDescription());
156     }
157
158     // ==================================================================
159
//
160
// Internal methods for managing dependencies.
161
//
162
// ==================================================================
163

164     /**
165      * Cuts dependencies to other objects.
166      */

167     protected void
168     cutDependencies()
169     {
170         // Cuts the dependency.
171
result_def_.cutDependency();
172
173         // Cuts dependencies to params types.
174
params_.cutDependencies();
175
176         mode_ = null;
177         contexts_ = null;
178
179         // Cuts the dependency to exceptions.
180
ExceptionDef_ref.cutDependencies(exceptions_);
181         exceptions_ = null;
182
183         // Calls the Container_impl::cutDependencies operation.
184
super.cutDependencies();
185     }
186
187     // ==================================================================
188
//
189
// For CORBA::IRObject interface.
190
//
191
// ==================================================================
192

193     /**
194      * IDL:omg.org/CORBA/IRObject/def_kind:1.0
195      */

196     public DefinitionKind
197     def_kind()
198     {
199         return DefinitionKind.dk_Operation;
200     }
201
202     // ==================================================================
203
//
204
// For CORBA::OperationDef interface.
205
//
206
// ==================================================================
207

208     /**
209      * IDL:omg.org/CORBA/OperationDef/result:1.0
210      */

211     public TypeCode
212     result()
213     {
214         // delegate to the IDLType reference.
215
return result_def_.recursiveType();
216     }
217
218     /**
219      * IDL:omg.org/CORBA/OperationDef/result_def:1.0
220      */

221     public IDLType
222     result_def()
223     {
224         // delegate to the IDLType reference.
225
return result_def_.asIDLType();
226     }
227
228     /**
229      * IDL:omg.org/CORBA/OperationDef/result_def:1.0
230      */

231     public void
232     result_def(IDLType val)
233     {
234         // try to cast val to a local object
235
// and delegate to the IDLType reference.
236
result_def_.setDependency( castToLocal(val) );
237     }
238
239     /**
240      * IDL:omg.org/CORBA/OperationDef/params:1.0
241      */

242     public ParameterDescription[]
243     params()
244     {
245         // delegate to the Parameters.
246
return params_.getParameterDescriptionSeq();
247     }
248
249     /**
250      * IDL:omg.org/CORBA/OperationDef/params:1.0
251      */

252     public void
253     params(ParameterDescription[] val)
254     {
255         // Check if an oneway operation that parameters are only PARAM_IN!
256
if(mode_ == OperationMode.OP_ONEWAY)
257             for(int i=0; i<val.length; i++)
258                 if(val[i].mode != ParameterMode.PARAM_IN)
259                     throw exceptionNeedOnlyInParams();
260
261         // delegate to the Parameters.
262
params_.setParameterDescriptionSeq(val);
263     }
264
265     /**
266      * IDL:omg.org/CORBA/OperationDef/mode:1.0
267      */

268     public OperationMode
269     mode()
270     {
271         return mode_;
272     }
273
274     /**
275      * IDL:omg.org/CORBA/OperationDef/mode:1.0
276      */

277     public void
278     mode(OperationMode val)
279     {
280         // Check if ONEWAY only PARAM_IN and no exceptions!
281
if(val == OperationMode.OP_ONEWAY)
282     {
283             params_.checkOnlyInModes();
284             if(exceptions_ != null && exceptions_.length != 0)
285                throw exceptionNoExceptionsForOnewayOperation();
286         }
287         mode_ = val;
288     }
289
290     /**
291      * IDL:omg.org/CORBA/OperationDef/contexts:1.0
292      */

293     public String JavaDoc[]
294     contexts()
295     {
296         return contexts_;
297     }
298
299     /**
300      * IDL:omg.org/CORBA/OperationDef/contexts:1.0
301      */

302     public void
303     contexts(String JavaDoc[] val)
304     {
305         // TODO: check unicity
306
contexts_ = val;
307     }
308
309     /**
310      * IDL:omg.org/CORBA/OperationDef/exceptions:1.0
311      */

312     public ExceptionDef[]
313     exceptions()
314     {
315         ExceptionDef[] result = new ExceptionDef[exceptions_.length];
316
317         for(int i=0; i<exceptions_.length; i++)
318              result[i] = exceptions_[i].asExceptionDef();
319
320         return result;
321     }
322
323     /**
324      * IDL:omg.org/CORBA/OperationDef/exceptions:1.0
325      */

326     public void
327     exceptions(ExceptionDef[] val)
328     {
329         // Check if ONEWAY then no exceptions!
330
if(mode_ == OperationMode.OP_ONEWAY)
331     {
332             if(val.length != 0)
333                throw exceptionNoExceptionsForOnewayOperation();
334         }
335
336         ExceptionDef_impl[] exceptions = new ExceptionDef_impl[val.length];
337         for (int i=0; i<val.length; i++)
338             exceptions[i] = castToLocal(val[i]);
339
340         // TODO: check unicity
341

342         ExceptionDef_ref[] refs = new ExceptionDef_ref[val.length];
343         for (int i=0; i<val.length; i++)
344             refs[i] = new ExceptionDef_ref( this, exceptions[i] );
345
346         // cut the previous dependency to exceptions.
347
ExceptionDef_ref.cutDependencies(exceptions_);
348
349         exceptions_ = refs;
350     }
351
352     // ==================================================================
353
//
354
// For IDL2 mapping.
355
//
356
// ==================================================================
357

358     /**
359      * TODO
360      */

361     protected void
362     whenCreated()
363     {
364         // do nothing if mappings are not enabled.
365
if (!getIFR().getRepository().enable_mappings_)
366             return ;
367
368         // check the container kind
369
if (container_.def_kind().value()!=org.omg.CORBA.DefinitionKind._dk_Home)
370             return ;
371
372         // else create the mapping according to the CCM spec
373

374         //
375
// IDL2 mapping
376
//
377
//
378
// copy the operation in the home explicit interface
379
//
380
InterfaceDef_impl explicit = ((HomeDef_impl)container_).base_interfaces_[0].getImpl();
381         String JavaDoc explicit_base_id = explicit.getBaseID();
382         String JavaDoc id = explicit_base_id + name() + ":" + version();
383
384         container_.mapping_started_ = true;
385         explicit.create_operation(id, name(), version(), result_def(), mode(),
386                                   params(), exceptions(), contexts());
387         container_.mapping_started_ = false;
388
389         //
390
// CIDL mapping
391
//
392
//
393
// copy the operation in the home explicit executor interface
394
//
395
String JavaDoc cont_base_id = container_.getBaseContainerID();
396
397         String JavaDoc explicit_exe_id = cont_base_id + "CCM_" + container_.name() + "Explicit:" + container_.version();
398         org.omg.CORBA.ExtLocalInterfaceDef explicit_exe = org.omg.CORBA.ExtLocalInterfaceDefHelper.narrow(
399              getIFR().getRepository().lookup_mapped_id(explicit_exe_id));
400
401         id = cont_base_id + "CCM_" + container_.name() + "Explicit/" + name() + ":" + container_.version();
402         explicit_exe.create_operation(id, name(), version(),
403                                       result_def(),
404                                       mode(),
405                                       params(),
406                                       exceptions(),
407                                       contexts());
408     }
409 }
410
Popular Tags