KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

51     private org.omg.CORBA.OperationDef JavaDoc operation_def_;
52
53     /**
54      ** The operation mode.
55      **/

56     protected int mode_;
57
58     /**
59      ** The result type.
60      **/

61     protected TypeRef result_;
62
63     /**
64      ** List of parameters.
65      **/

66     protected ParameterListImpl parameters_;
67
68     /**
69      ** The operation exceptions.
70      **/

71     protected ExceptionListImpl exceptions_;
72
73     /**
74      ** List of contexts.
75      **/

76     private org.objectweb.ccm.util.Vector contexts_;
77
78     // ==================================================================
79
//
80
// Constructor.
81
//
82
// ==================================================================
83

84     /**
85      ** The constructor with the parent scope.
86      **
87      ** @param parent The parent scope of the operation declaration.
88      **/

89     protected
90     OperationDeclImpl(Repository rep, ScopeImpl parent)
91     {
92         // Call the DeclarationImpl constructor.
93
super(rep, parent);
94
95         // Init internal state.
96
operation_def_ = null;
97         mode_ = OperationDecl.OP_NORMAL;
98         result_ = null;
99         parameters_ = new ParameterListImpl();
100         exceptions_ = new ExceptionListImpl();
101         contexts_ = new org.objectweb.ccm.util.Vector();
102         the_declaration_kind_ = DeclarationKind._dk_operation;
103     }
104
105     // ==================================================================
106
//
107
// Internal methods.
108
//
109
// ==================================================================
110

111     /**
112      ** Add a parameter.
113      **
114      ** @param name The name of the parameter.
115      ** @param type The TypeRef of the parameter.
116      ** @param mode The mode of the parameter.
117      **/

118     protected void
119     addParam(String JavaDoc name,
120              TypeRef type,
121              org.omg.CORBA.ParameterMode JavaDoc mode)
122     {
123         parameters_.addParam(name, type, mode.value());
124     }
125
126     /**
127      ** Loads infos of the CORBA 3.0 OperationDef.
128      **
129      ** @param operation_def The OperationDef to load.
130      **/

131     protected void
132     load(org.omg.CORBA.Contained JavaDoc contained)
133     {
134         operation_def_ = org.omg.CORBA.OperationDefHelper.narrow(contained);
135         mode_ = operation_def_.mode().value();
136         setResultType(getRepository().getAsTypeRef(operation_def_.result_def()));
137         org.omg.CORBA.ParameterDescription JavaDoc[] params = operation_def_.params();
138         for (int i=0;i<params.length;i++)
139         {
140             addParam(params[i].name,
141                      getRepository().getAsTypeRef(params[i].type_def),
142                      params[i].mode);
143         }
144         org.omg.CORBA.ExceptionDef JavaDoc[] exc = operation_def_.exceptions();
145         for (int i=0;i<exc.length;i++)
146         {
147             exceptions_.add((ExceptionRef)getRepository().lookupId(exc[i].id()));
148         }
149         String JavaDoc[] contexts = operation_def_.contexts();
150         for (int i=0;i<contexts.length;i++)
151             addContext(contexts[i]);
152
153         super.load(contained);
154     }
155
156     /**
157      ** Loads infos of the CORBA 3.0 OperationDef.
158      **
159      ** @param operation_def The OperationDef to load.
160      **/

161     protected void
162     loadAsMapping(org.omg.CORBA.Contained JavaDoc contained)
163     {
164         operation_def_ = org.omg.CORBA.OperationDefHelper.narrow(contained);
165         mode_ = operation_def_.mode().value();
166         setResultType(getRepository().getAsMappedTypeRef(operation_def_.result_def()));
167         org.omg.CORBA.ParameterDescription JavaDoc[] params = operation_def_.params();
168         for (int i=0;i<params.length;i++)
169         {
170             addParam(params[i].name,
171                      getRepository().getAsMappedTypeRef(params[i].type_def),
172                      params[i].mode);
173         }
174         org.omg.CORBA.ExceptionDef JavaDoc[] exc = operation_def_.exceptions();
175         for (int i=0;i<exc.length;i++)
176         {
177             exceptions_.add((ExceptionRef)getRepository().lookupMappedId(exc[i].id()));
178         }
179         String JavaDoc[] contexts = operation_def_.contexts();
180         for (int i=0;i<contexts.length;i++)
181             addContext(contexts[i]);
182
183         super.loadAsMapping(contained);
184     }
185
186     // ==================================================================
187
//
188
// Methods for the Declaration interface.
189
//
190
// ==================================================================
191

192     /**
193      ** Create the operation declaration into the IFR.
194      **/

195     public void
196     create()
197     {
198         String JavaDoc[] contexts = new String JavaDoc[contexts_.size()];
199         for(int i=0; i<contexts.length; i++)
200             contexts[i] = (String JavaDoc)(contexts_.get(i));
201
202         operation_def_ = the_parent_.createOperation(this,
203                                                      result_.getIDLType(),
204                                                      org.omg.CORBA.OperationMode.from_int(mode_),
205                                                      parameters_.getParameterDescs(),
206                                                      exceptions_.getExceptionDefs(),
207                                                      contexts);
208     }
209
210     /**
211      ** Obtain the declaration external dependencies.
212      ** Note: for scopes, contained objects are not considered
213      ** as dependencies.
214      **
215      ** @return The list of dependencies as an array of Declaration.
216      **/

217     public Declaration[]
218     getDependencies()
219     {
220         if (dependencies_!=null)
221             return dependencies_;
222
223         org.objectweb.ccm.util.Vector op_depend = new org.objectweb.ccm.util.Vector();
224         Declaration[] depend = null;
225
226         // return type
227
if (getType().isDeclaration())
228             op_depend.add(getType());
229
230         depend = getType().getDependencies();
231         for (int i=0;i<depend.length;i++)
232             op_depend.add(depend[i]);
233
234         // exceptions
235
ExceptionDecl[] excs = getExceptions();
236         for (int i=0;i<excs.length;i++)
237         {
238             op_depend.add(excs[i]);
239             depend = excs[i].getDependencies();
240             for (int j=0;j<depend.length;j++)
241             {
242                 if (op_depend.indexOf(depend[j])==-1)
243                     op_depend.add(depend[j]);
244             }
245         }
246
247         // parameters type
248
TypeRef[] param_types = getParameters().getParamTypes();
249         for (int i=0;i<param_types.length;i++)
250         {
251             if (param_types[i].isDeclaration())
252                 op_depend.add(param_types[i]);
253
254             depend = param_types[i].getDependencies();
255             for (int j=0;j<depend.length;j++)
256             {
257                 if (op_depend.indexOf(depend[j])==-1)
258                     op_depend.add(depend[j]);
259             }
260         }
261
262         dependencies_ = (Declaration[])op_depend.toArray(new Declaration[0]);
263         return dependencies_;
264     }
265
266
267
268     // ==================================================================
269
//
270
// Methods for the WithInParameters interface.
271
//
272
// ==================================================================
273

274     /**
275      ** Add a in parameter.
276      **
277      ** @param name The name of the parameter.
278      ** @param type The TypeRef of the parameter.
279      **/

280     public void
281     addInParam(String JavaDoc name,
282                TypeRef type)
283     {
284         addParam(name, type, org.omg.CORBA.ParameterMode.PARAM_IN);
285     }
286
287     // ==================================================================
288
//
289
// Methods for the OperationDecl interface.
290
//
291
// ==================================================================
292

293     /**
294      ** Set mode as normal.
295      **/

296     public void
297     setNormal()
298     {
299         mode_ = OperationDecl.OP_NORMAL;
300     }
301
302     /**
303      ** Set mode as oneway.
304      **/

305     public void
306     setOneway()
307     {
308         mode_ = OperationDecl.OP_ONEWAY;
309     }
310
311     /**
312      ** Set the result type.
313      **
314      ** @param type The TypeRef of the returned object.
315      **/

316     public void
317     setResultType(TypeRef type)
318     {
319         if(type != null)
320         {
321             result_ = type;
322             result_.addRef();
323         }
324     }
325
326     /**
327      ** Add an out parameter.
328      **
329      ** @param name The name of the parameter.
330      ** @param type The TypeRef of the parameter.
331      **/

332     public void
333     addOutParam(String JavaDoc name,
334                 TypeRef type)
335     {
336         addParam(name, type, org.omg.CORBA.ParameterMode.PARAM_OUT);
337     }
338
339     /**
340      ** Add an inout parameter.
341      **
342      ** @param name The name of the parameter.
343      ** @param type The TypeRef of the parameter.
344      **/

345     public void
346     addInOutParam(String JavaDoc name,
347                   TypeRef type)
348     {
349         addParam(name, type, org.omg.CORBA.ParameterMode.PARAM_INOUT);
350     }
351
352     /**
353      ** Add a context.
354      **
355      ** @param name The name of the context.
356      **/

357     public void
358     addContext(String JavaDoc name)
359     {
360         contexts_.add(name);
361     }
362
363     /**
364      **
365      **/

366     public boolean
367     isOneway()
368     {
369         return mode_==OperationDecl.OP_ONEWAY;
370     }
371
372     /**
373      **
374      **/

375     public TypeRef
376     getType()
377     {
378         return result_;
379     }
380
381     /**
382      **
383      **/

384     public ExceptionList
385     getExceptionList()
386     {
387         return exceptions_;
388     }
389
390     /**
391      **
392      **/

393     public ExceptionDecl[]
394     getExceptions()
395     {
396         return exceptions_.getExceptions();
397     }
398
399     /**
400      **
401      **/

402     public ParameterList
403     getParameters()
404     {
405         return parameters_;
406     }
407
408     /**
409      **
410      **/

411     public String JavaDoc[]
412     getContexts()
413     {
414         String JavaDoc[] result = new String JavaDoc[contexts_.size()];
415         for (int i=0;i<result.length;i++)
416         {
417             result[i] = (String JavaDoc)contexts_.get(i);
418         }
419         return result;
420     }
421
422     // ==================================================================
423
//
424
// Methods for the inherited DeclarationImpl class.
425
//
426
// ==================================================================
427

428     /**
429      **
430      **/

431     public void
432     destroy()
433     {
434         if (result_!=null)
435             result_.removeRef();
436
437         exceptions_.destroy();
438         parameters_.destroy();
439         super.destroy();
440     }
441
442     /**
443      ** Obtain its CORBA 3.0 Contained reference.
444      **
445      ** @return The Contained object associated with the
446      ** operation declaration.
447      **/

448     protected org.omg.CORBA.Contained JavaDoc
449     getContained()
450     {
451        return operation_def_;
452     }
453 }
454
Popular Tags