KickJava   Java API By Example, From Geeks To Geeks.

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


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 TypeRef. */
30 import org.objectweb.openccm.ast.api.TypeRef;
31
32 /** Used to access AST DeclarationKind. */
33 import org.objectweb.openccm.ast.api.DeclarationKind;
34
35 /** Used to access AST Declaration. */
36 import org.objectweb.openccm.ast.api.Declaration;
37
38 /** To access AST StructMember. */
39 import org.objectweb.openccm.ast.api.StructMember;
40
41 /** To access AST StructMemberList. */
42 import org.objectweb.openccm.ast.api.StructMemberList;
43
44 /** To use CORBA::ExceptionDef. */
45 import org.omg.CORBA.ExceptionDef JavaDoc;
46 import org.omg.CORBA.ExceptionDefHelper;
47
48 /**
49  * ExceptionDeclImpl is a wrapper class for IDL exception declarations.
50  *
51  * Inherits from:
52  * - ScopeImpl as exceptions are also IDL scopes.
53  * - WithDeclarators to access exception members.
54  *
55  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
56  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
57  *
58  * @version 0.3
59  */

60
61 public class ExceptionDeclImpl
62        extends ScopeImpl
63        implements org.objectweb.openccm.ast.api.ExceptionDecl
64 {
65     // ==================================================================
66
//
67
// Internal state.
68
//
69
// ==================================================================
70

71     /** Reference to the CORBA 3.0 ExceptionDef. */
72     private ExceptionDef JavaDoc exception_def_;
73
74     /** List of members. */
75     private StructMemberListImpl members_;
76
77     // ==================================================================
78
//
79
// Constructor.
80
//
81
// ==================================================================
82

83     /**
84      * The constructor with the parent scope.
85      *
86      * @param rep The repository of the declaration.
87      * @param parent The parent scope of the exception declaration.
88      */

89     public
90     ExceptionDeclImpl(Repository rep,
91                       ScopeImpl parent)
92     {
93         // Call the ScopeImpl constructor.
94
super(rep, parent);
95
96         // Init internal state.
97
exception_def_ = null;
98         members_ = new StructMemberListImpl();
99     }
100
101     // ==================================================================
102
//
103
// Internal methods.
104
//
105
// ==================================================================
106

107     /**
108      * Create the exception declaration.
109      */

110     protected void
111     doCreation()
112     {
113         exception_def_ = the_parent_.getContainer().
114                          create_exception(getId(), getName(), getVersion(),
115                                           members_.getStructMemberSeq());
116         super.create();
117     }
118
119     // ==================================================================
120
//
121
// Internal methods for DeclarationImpl.
122
//
123
// ==================================================================
124

125     /**
126      * Loads infos of the CORBA 3.0 ExceptionDef.
127      *
128      * @param contained The ExceptionDef to load.
129      */

130     protected void
131     load(org.omg.CORBA.Contained JavaDoc contained)
132     {
133         exception_def_ = ExceptionDefHelper.narrow(contained);
134         org.omg.CORBA.StructMember JavaDoc[] members = exception_def_.members();
135
136         // for inlined struct, union or enum declarations
137
super.load(contained);
138
139         for (int i=0; i<members.length; i++)
140         {
141             members_.addMember(members[i].name,
142                                getRepository().
143                                    getAsTypeRef((members[i].type_def)));
144         }
145     }
146
147     /**
148      * Loads infos of the CORBA 3.0 ExceptionDef.
149      *
150      * @param contained The ExceptionDef to load.
151      */

152     protected void
153     loadAsMapping(org.omg.CORBA.Contained JavaDoc contained)
154     {
155         exception_def_ = ExceptionDefHelper.narrow(contained);
156         org.omg.CORBA.StructMember JavaDoc[] members = exception_def_.members();
157
158         // for inlined struct, union or enum declarations
159
super.loadAsMapping(contained);
160
161         for (int i=0; i<members.length; i++)
162             members_.addMember(members[i].name,
163                                getRepository().
164                                  getAsMappedTypeRef((members[i].type_def)));
165     }
166
167     /**
168      * Obtain its CORBA 3.0 Contained reference.
169      *
170      * @return The Contained object associated with the exception
171      * declaration.
172      */

173     protected org.omg.CORBA.Contained JavaDoc
174     getContained()
175     {
176         if(exception_def_ == null)
177            doCreation();
178
179        return exception_def_;
180     }
181
182     // ==================================================================
183
//
184
// Internal methods for ScopeImpl.
185
//
186
// ==================================================================
187

188     /**
189      * Obtain its CORBA 3.0 Container reference.
190      *
191      * @return The Container object associated with the exception
192      * declaration.
193      */

194     protected org.omg.CORBA.Container JavaDoc
195     getContainer()
196     {
197         if(exception_def_ == null)
198            doCreation();
199
200         return exception_def_;
201     }
202
203     // ==================================================================
204
//
205
// Public methods.
206
//
207
// ==================================================================
208

209     /**
210      * Obtain its ExceptionDef reference.
211      *
212      * @return The ExceptionDef associated with the exception declaration.
213      */

214     public ExceptionDef JavaDoc
215     getExceptionDef()
216     {
217         return exception_def_;
218     }
219
220     /**
221      * Obtain its associated CORBA::ExceptionDescription.
222      *
223      * @return Its associated CORBA::ExceptionDescription.
224      */

225     public org.omg.CORBA.ExceptionDescription JavaDoc
226     getExceptionDescription()
227     {
228         return new org.omg.CORBA.ExceptionDescription JavaDoc(getName(),
229                                                       getId(),
230                                                       the_parent_.getId(),
231                                                       getVersion(),
232                                                       getExceptionDef().type());
233     }
234
235     // ==================================================================
236
//
237
// Methods for OMG IDL org.objectweb.openccm.ast.api.WithDependencies
238
//
239
// ==================================================================
240

241     /**
242      * Obtain the declaration external dependencies.
243      *
244      * Note: for scopes, contained objects are not considered
245      * as dependencies.
246      *
247      * @return The list of dependencies as an array of Declaration.
248      */

249     public Declaration[]
250     getDependencies()
251     {
252         if (dependencies_!=null)
253             return dependencies_;
254
255         // members
256
java.util.List JavaDoc exc_depend = new java.util.ArrayList JavaDoc();
257         Declaration[] depend = null;
258
259         StructMember[] members = members_.getStructMembers();
260         for (int i=0; i<members.length; i++)
261         {
262             TypeRef member_type = members[i].getType();
263             if (member_type.isDeclaration())
264             {
265                 if ((!containsDecl((Declaration)member_type)) &&
266                     (exc_depend.indexOf(member_type)==-1))
267                     exc_depend.add(member_type);
268             }
269
270             depend = member_type.getDependencies();
271             for (int j=0; j<depend.length; j++)
272             {
273                 if ((exc_depend.indexOf(depend[j])==-1) &&
274                     (!containsDecl(depend[j])))
275                     exc_depend.add(depend[j]);
276             }
277         }
278         dependencies_ = (Declaration[])exc_depend.toArray(new Declaration[0]);
279         return dependencies_;
280     }
281
282     // ==================================================================
283
//
284
// Methods for OMG IDL org.objectweb.openccm.ast.api.Declaration
285
//
286
// ==================================================================
287

288     /**
289      * Obtain its DeclarationKind.
290      *
291      * @return The DeclarationKind of the object.
292      */

293     public long
294     getDeclKind()
295     {
296         return DeclarationKind.dk_exception;
297     }
298
299     /**
300      * Close the exception scope.
301      */

302     public void
303     create()
304     {
305         if(exception_def_ == null)
306            doCreation();
307         else
308           exception_def_.members(members_.getStructMemberSeq());
309     }
310
311     // ==================================================================
312
//
313
// Methods for OMG IDL org.objectweb.openccm.ast.api.Scope
314
//
315
// ==================================================================
316

317     // ==================================================================
318
//
319
// Methods for OMG IDL org.objectweb.openccm.ast.api.WithDeclarators
320
//
321
// ==================================================================
322

323     /**
324      * Find the declarator associated to an index.
325      *
326      * @param index The index.
327      *
328      * @return The declarator associated to the index.
329      */

330     public String JavaDoc
331     declaratorAt(int index)
332     {
333         return members_.nameAt(index);
334     }
335
336     // ==================================================================
337
//
338
// Methods for OMG IDL org.objectweb.openccm.ast.api.ExceptionDecl
339
//
340
// ==================================================================
341

342     /**
343      * Obtain the exception member list.
344      *
345      * @return The members of the exception declaration.
346      */

347     public StructMemberList
348     getMemberList()
349     {
350         return members_;
351     }
352 }
353
Popular Tags