KickJava   Java API By Example, From Geeks To Geeks.

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


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 exception 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 ExceptionDeclImpl
39        extends ScopeImpl
40        implements ExceptionRef, ExceptionDecl
41 {
42     // ==================================================================
43
//
44
// Internal state.
45
//
46
// ==================================================================
47

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

51     private org.omg.CORBA.ExceptionDef JavaDoc exception_def_;
52
53     /**
54      ** List of members.
55      **/

56     private StructMembersImpl members_;
57
58     // ==================================================================
59
//
60
// Constructor.
61
//
62
// ==================================================================
63

64     /**
65      ** The constructor with the parent scope.
66      **
67      ** @param parent The parent scope of the exception declaration.
68      **/

69     public
70     ExceptionDeclImpl(Repository rep, ScopeImpl parent)
71     {
72         // Call the ScopeImpl constructor.
73
super(rep, parent);
74
75         // Init internal state.
76
exception_def_ = null;
77         members_ = new StructMembersImpl();
78         the_declaration_kind_ = DeclarationKind._dk_exception;
79     }
80
81     // ==================================================================
82
//
83
// Internal methods.
84
//
85
// ==================================================================
86

87     /**
88      ** Create the exception declaration.
89      **/

90     protected void
91     doCreation()
92     {
93         exception_def_ = the_parent_.getContainer().create_exception(getId(), getName(), getVersion(),
94                                                                         members_.getMemberDefs());
95         super.create();
96     }
97
98     // ==================================================================
99
//
100
// Internal methods.
101
//
102
// ==================================================================
103

104     /**
105      ** Loads infos of the CORBA 3.0 ExceptionDef.
106      **
107      ** @param exceptionDef The ExceptionDef to load.
108      **/

109     protected void
110     load(org.omg.CORBA.Contained JavaDoc contained)
111     {
112         exception_def_ = org.omg.CORBA.ExceptionDefHelper.narrow(contained);
113         org.omg.CORBA.StructMember JavaDoc[] members = exception_def_.members();
114
115         // for inlined struct, union or enum declarations
116
super.load(contained);
117
118         for (int i=0;i<members.length;i++)
119         {
120             members_.addMember(members[i].name,
121                                getRepository().getAsTypeRef((members[i].type_def)));
122         }
123     }
124
125     /**
126      ** Loads infos of the CORBA 3.0 ExceptionDef.
127      **
128      ** @param exceptionDef The ExceptionDef to load.
129      **/

130     protected void
131     loadAsMapping(org.omg.CORBA.Contained JavaDoc contained)
132     {
133         exception_def_ = org.omg.CORBA.ExceptionDefHelper.narrow(contained);
134         org.omg.CORBA.StructMember JavaDoc[] members = exception_def_.members();
135
136         // for inlined struct, union or enum declarations
137
super.loadAsMapping(contained);
138
139         for (int i=0;i<members.length;i++)
140             members_.addMember(members[i].name,
141                                getRepository().getAsMappedTypeRef((members[i].type_def)));
142     }
143
144     // ==================================================================
145
//
146
// Methods for the Declaration interface.
147
//
148
// ==================================================================
149

150     /**
151      ** Return the index declarator.
152      **
153      ** @param index The index of the declarator that should be returned.
154      **
155      ** @return The name of the declarator at the specified index.
156      **/

157     public String JavaDoc
158     declaratorAt(int index)
159     {
160         return members_.nameAt(index);
161     }
162
163     /**
164      ** Obtain the declaration external dependencies.
165      ** Note: for scopes, contained objects are not considered
166      ** as dependencies.
167      **
168      ** @return The list of dependencies as an array of Declaration.
169      **/

170     public Declaration[]
171     getDependencies()
172     {
173         if (dependencies_!=null)
174             return dependencies_;
175
176         // members
177
org.objectweb.ccm.util.Vector exc_depend = new org.objectweb.ccm.util.Vector();
178         Declaration[] depend = null;
179         TypeRef[] member_types = getMembers().getMemberTypes();
180
181         for (int i=0;i<member_types.length;i++)
182         {
183             if (member_types[i].isDeclaration())
184             {
185                 if ((!containsDecl((Declaration)member_types[i])) &&
186                     (exc_depend.indexOf(member_types[i])==-1))
187                     exc_depend.add(member_types[i]);
188             }
189
190             depend = member_types[i].getDependencies();
191             for (int j=0;j<depend.length;j++)
192             {
193                 if ((exc_depend.indexOf(depend[j])==-1) &&
194                     (!containsDecl(depend[j])))
195                     exc_depend.add(depend[j]);
196             }
197         }
198
199         dependencies_ = (Declaration[])exc_depend.toArray(new Declaration[0]);
200         return dependencies_;
201     }
202
203     // ==================================================================
204
//
205
// Methods for the Scope interface.
206
//
207
// ==================================================================
208

209     /**
210      ** Close the exception scope.
211      **/

212     public void
213     create()
214     {
215         if(exception_def_ == null)
216            doCreation();
217         else
218           exception_def_.members(members_.getMemberDefs());
219     }
220
221     // ==================================================================
222
//
223
// Methods for the ExceptionRef interface.
224
//
225
// ==================================================================
226

227     /**
228      ** Obtain its ExceptionDef reference.
229      **
230      ** @return The ExceptionDef associated with the exception declaration.
231      **/

232     public org.omg.CORBA.ExceptionDef JavaDoc
233     getExceptionDef()
234     {
235         return exception_def_;
236     }
237
238     /**
239      **
240      **/

241     public int
242     getTypeKind()
243     {
244         return TypeKind._tk_exception;
245     }
246
247     // ==================================================================
248
//
249
// Methods for the ExceptionDecl interface.
250
//
251
// ==================================================================
252

253     /**
254      ** Obtain the member list.
255      **
256      ** @return The StructMembers of the exception declaration.
257      **/

258     public StructMembers
259     getMembers()
260     {
261         return members_;
262     }
263
264     // ==================================================================
265
//
266
// Methods for the inherited ScopeImpl class.
267
//
268
// ==================================================================
269

270     /**
271      ** Obtain its CORBA 3.0 Container reference.
272      **
273      ** @return The Container object associated with the exception
274      ** declaration.
275      **/

276     protected org.omg.CORBA.Container JavaDoc
277     getContainer()
278     {
279         if(exception_def_ == null)
280            doCreation();
281
282         return exception_def_;
283     }
284
285     // ==================================================================
286
//
287
// Methods for the inherited DeclarationImpl class.
288
//
289
// ==================================================================
290

291     /**
292      **
293      **/

294     public void
295     destroy()
296     {
297         members_.destroy();
298         super.destroy();
299     }
300
301     /**
302      ** Obtain its CORBA 3.0 Contained reference.
303      **
304      ** @return The Contained object associated with the exception
305      ** declaration.
306      **/

307     protected org.omg.CORBA.Contained JavaDoc
308     getContained()
309     {
310         if(exception_def_ == null)
311            doCreation();
312
313        return exception_def_;
314     }
315 }
316
Popular Tags