KickJava   Java API By Example, From Geeks To Geeks.

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


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 /** To access AST TypeRef. */
30 import org.objectweb.openccm.ast.api.TypeRef;
31
32 /** To access AST DeclarationKind. */
33 import org.objectweb.openccm.ast.api.DeclarationKind;
34
35 /** To access AST Declaration. */
36 import org.objectweb.openccm.ast.api.Declaration;
37
38 /** To access AST ExceptionDecl. */
39 import org.objectweb.openccm.ast.api.ExceptionDecl;
40
41 /** Used to access AST StringList. */
42 import org.objectweb.openccm.ast.api.StringList;
43
44 /** To access AST Parameter. */
45 import org.objectweb.openccm.ast.api.Parameter;
46
47 /** To use CORBA::OperationDef. */
48 import org.omg.CORBA.OperationDef JavaDoc;
49 import org.omg.CORBA.OperationDefHelper;
50
51 /** To use CORBA::OperationMode. */
52 import org.omg.CORBA.OperationMode JavaDoc;
53
54 /** To use CORBA::ExceptionDef. */
55 import org.omg.CORBA.ExceptionDef JavaDoc;
56
57 /** To use CORBA::ParameterDescription. */
58 import org.omg.CORBA.ParameterDescription JavaDoc;
59
60 /**
61  * OperationDeclImpl is a wrapper class for IDL operation declarations.
62  *
63  *
64  * Inherits from:
65  *
66  * - OperationBaseImpl.
67  *
68  * - OperationDecl: OMG IDL for operation declarations.
69  *
70  *
71  * Provides:
72  *
73  * - the 'Oneway' or 'Normal' mode,
74  * i.e. the setOneway, isOneway, setNormal, and isNormal operations.
75  *
76  * - the list of contexts,
77  * i.e. the getContextList operation.
78  *
79  *
80  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
81  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
82  *
83  * @version 0.3
84  */

85
86 public class OperationDeclImpl
87        extends OperationBaseImpl
88        implements org.objectweb.openccm.ast.api.OperationDecl
89 {
90     // ==================================================================
91
//
92
// Internal state.
93
//
94
// ==================================================================
95

96     /** Reference to the CORBA 3.0 OperationDef. */
97     private OperationDef JavaDoc operation_def_;
98
99     /**
100      ** The operation mode.
101      **/

102     protected OperationMode JavaDoc mode_;
103
104     /** List of contexts. */
105     private StringListImpl contexts_;
106
107     // ==================================================================
108
//
109
// Constructor.
110
//
111
// ==================================================================
112

113     /**
114      * The constructor with the parent scope.
115      *
116      * @param rep The repository of the declaration.
117      * @param parent The parent scope of the operation declaration.
118      */

119     protected
120     OperationDeclImpl(Repository rep,
121                       ScopeImpl parent)
122     {
123         // Call the OperationBaseImpl constructor.
124
super(rep, parent);
125
126         // Init internal state.
127
operation_def_ = null;
128         mode_ = OperationMode.OP_NORMAL;
129         contexts_ = new StringListImpl();
130     }
131
132     // ==================================================================
133
//
134
// Internal methods.
135
//
136
// ==================================================================
137

138     // ==================================================================
139
//
140
// Internal methods for DeclarationImpl.
141
//
142
// ==================================================================
143

144     /**
145      * Loads infos of the CORBA 3.0 OperationDef.
146      *
147      * @param contained The OperationDef to load.
148      */

149     protected void
150     load(org.omg.CORBA.Contained JavaDoc contained)
151     {
152         operation_def_ = OperationDefHelper.narrow(contained);
153         mode_ = operation_def_.mode();
154         setType(getRepository().
155                 getAsTypeRef(operation_def_.result_def()));
156         ParameterDescription JavaDoc[] params = operation_def_.params();
157         for (int i=0; i<params.length; i++)
158         {
159             parameters_.addParam(params[i].name,
160                      getRepository().getAsTypeRef(params[i].type_def),
161                      params[i].mode);
162         }
163         ExceptionDef JavaDoc[] exc = operation_def_.exceptions();
164         for (int i=0; i<exc.length; i++)
165         {
166             exceptions_.add((ExceptionDecl)getRepository().
167                             lookupId(exc[i].id()));
168         }
169         String JavaDoc[] contexts = operation_def_.contexts();
170         for (int i=0; i<contexts.length; i++)
171             contexts_.add(contexts[i]);
172
173         super.load(contained);
174     }
175
176     /**
177      * Loads infos of the CORBA 3.0 OperationDef.
178      *
179      * @param operation_def The OperationDef to load.
180      */

181     protected void
182     loadAsMapping(org.omg.CORBA.Contained JavaDoc contained)
183     {
184         operation_def_ = OperationDefHelper.narrow(contained);
185         mode_ = operation_def_.mode();
186         setType(getRepository().
187                 getAsMappedTypeRef(operation_def_.result_def()));
188
189         ParameterDescription JavaDoc[] params = operation_def_.params();
190         for (int i=0; i<params.length; i++)
191         {
192             parameters_.addParam(params[i].name,
193                      getRepository().getAsMappedTypeRef(params[i].type_def),
194                      params[i].mode);
195         }
196
197         ExceptionDef JavaDoc[] exc = operation_def_.exceptions();
198         for (int i=0; i<exc.length; i++)
199         {
200             exceptions_.add((ExceptionDecl)getRepository().
201                             lookupMappedId(exc[i].id()));
202         }
203
204         String JavaDoc[] contexts = operation_def_.contexts();
205         for (int i=0; i<contexts.length; i++)
206             contexts_.add(contexts[i]);
207
208         super.loadAsMapping(contained);
209     }
210
211     /**
212      * Obtain its CORBA 3.0 Contained reference.
213      *
214      * @return The Contained object associated with the
215      * operation declaration.
216      */

217     protected org.omg.CORBA.Contained JavaDoc
218     getContained()
219     {
220        return operation_def_;
221     }
222
223     // ==================================================================
224
//
225
// Public methods.
226
//
227
// ==================================================================
228

229     // ==================================================================
230
//
231
// Methods for OMG IDL org.objectweb.openccm.ast.api.WithDependencies
232
//
233
// ==================================================================
234

235     /**
236      * Obtain the declaration external dependencies.
237      *
238      * Note: for scopes, contained objects are not considered
239      * as dependencies.
240      *
241      * @return The list of dependencies as an array of Declaration.
242      */

243     public Declaration[]
244     getDependencies()
245     {
246         if (dependencies_!=null)
247             return dependencies_;
248
249         java.util.List JavaDoc op_depend = new java.util.ArrayList JavaDoc();
250         Declaration[] depend = null;
251
252         // return type
253
if (getType().isDeclaration())
254             op_depend.add(getType());
255
256         depend = getType().getDependencies();
257         for (int i=0; i<depend.length; i++)
258             op_depend.add(depend[i]);
259
260         // exceptions
261
ExceptionDecl[] excs = exceptions_.getExceptions();
262         for (int i=0; i<excs.length; i++)
263         {
264             op_depend.add(excs[i]);
265             depend = excs[i].getDependencies();
266             for (int j=0; j<depend.length; j++)
267             {
268                 if (op_depend.indexOf(depend[j])==-1)
269                     op_depend.add(depend[j]);
270             }
271         }
272
273         // parameters type
274
Parameter[] parameters = parameters_.getParameters();
275         for (int i=0;i<parameters.length;i++)
276         {
277             TypeRef param_type = parameters[i].getType();
278             if (param_type.isDeclaration())
279                 op_depend.add(param_type);
280
281             depend = param_type.getDependencies();
282             for (int j=0;j<depend.length;j++)
283             {
284                 if (op_depend.indexOf(depend[j])==-1)
285                     op_depend.add(depend[j]);
286             }
287         }
288
289         dependencies_ = (Declaration[])op_depend.toArray(new Declaration[0]);
290 /* System.err.println("dependances de l'operation : "+getAbsoluteName());
291             for(int i=0; i<dependencies_.length; i++)
292                 System.err.println(" |"+dependencies_[i].getAbsoluteName());
293 */
return dependencies_;
294     }
295
296     // ==================================================================
297
//
298
// Methods for OMG IDL org.objectweb.openccm.ast.api.Declaration
299
//
300
// ==================================================================
301

302     /**
303      * Obtain its DeclarationKind.
304      *
305      * @return The DeclarationKind of the object.
306      */

307     public long
308     getDeclKind()
309     {
310         return DeclarationKind.dk_operation;
311     }
312
313     /**
314      * Create the operation declaration into the IFR.
315      */

316     public void
317     create()
318     {
319         operation_def_ = the_parent_.
320                          createOperation(this,
321                                          getIDLType(),
322                                          mode_,
323                                  parameters_.getParameterDescriptionSeq(),
324                                  exceptions_.getExceptionDefSeq(),
325                                  contexts_.getStrings());
326     }
327
328     // ==================================================================
329
//
330
// Methods for OMG IDL org.objectweb.openccm.ast.api.OperationBase
331
//
332
// ==================================================================
333

334     // ==================================================================
335
//
336
// Methods for OMG IDL org.objectweb.openccm.ast.api.OperationDecl
337
//
338
// ==================================================================
339

340     /**
341      * Set the associated mode as oneway.
342      */

343     public void
344     setOneway()
345     {
346         mode_ = OperationMode.OP_ONEWAY;
347     }
348
349     /**
350      * Is it an oneway operation?
351      *
352      * @return True if oneway operation, or false otherwise.
353      */

354     public boolean
355     isOneway()
356     {
357         return mode_ == OperationMode.OP_ONEWAY;
358     }
359
360     /**
361      * Set the associated mode as normal.
362      */

363     public void
364     setNormal()
365     {
366         mode_ = OperationMode.OP_NORMAL;
367     }
368
369     /**
370      * Is it a normal operation?
371      *
372      * @return True if a normal operation, or false otherwise.
373      */

374     public boolean
375     isNormal()
376     {
377         return mode_ == OperationMode.OP_NORMAL;
378     }
379
380     /**
381      * Obtain the list of contexts.
382      *
383      * @return The list of contexts.
384      */

385     public StringList
386     getContextList()
387     {
388         return contexts_;
389     }
390 }
391
Popular Tags