KickJava   Java API By Example, From Geeks To Geeks.

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


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 Declaration. */
30 import org.objectweb.openccm.ast.api.Declaration;
31
32 /** To access AST DeclarationKind. */
33 import org.objectweb.openccm.ast.api.DeclarationKind;
34
35 /** To access AST FileScope. */
36 import org.objectweb.openccm.ast.api.FileScope;
37
38 /**
39  * FileScopeImpl is a wrapper class for included IDL files.
40  *
41  * Inherits from:
42  * - ScopeImpl as file scopes are IDL scopes.
43  *
44  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
45  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
46  *
47  * @version 0.3
48  */

49
50 public class FileScopeImpl
51        extends ScopeImpl
52        implements FileScope
53 {
54     // ==================================================================
55
//
56
// Internal state.
57
//
58
// ==================================================================
59

60     /** The associated file name. */
61     protected String JavaDoc file_name_;
62
63     /** To store included files names. */
64     protected java.util.List JavaDoc included_files_;
65
66     // ==================================================================
67
//
68
// Constructor.
69
//
70
// ==================================================================
71

72     /**
73      * The constructor with the parent scope and declaration tables.
74      *
75      * @param rep The repository of the declaration.
76      * @param parent The parent scope of the declaration.
77      * @param decls The list of contained declarations.
78      */

79     public
80     FileScopeImpl(Repository rep,
81                   ScopeImpl parent,
82                   java.util.List JavaDoc decls)
83     {
84         // Call the ScopeImpl constructor.
85
super(rep, parent);
86
87         // Init internal state.
88
file_name_ = null;
89         setName("");
90         contained_decls_ = decls;
91         included_files_ = new java.util.ArrayList JavaDoc();
92     }
93
94     // ==================================================================
95
//
96
// Internal methods.
97
//
98
// ==================================================================
99

100     // ==================================================================
101
//
102
// Internal methods for DeclarationImpl.
103
//
104
// ==================================================================
105

106     /**
107      * Obtain its CORBA 3.0 Contained reference.
108      *
109      * @return null because no Contained object is associated
110      * with the FileScope.
111      */

112     protected org.omg.CORBA.Contained JavaDoc
113     getContained()
114     {
115         return null;
116     }
117
118     // ==================================================================
119
//
120
// Internal methods for ScopeImpl.
121
//
122
// ==================================================================
123

124     /**
125      * Obtain its CORBA 3.0 Container reference.
126      *
127      * @return The Container object associated with the
128      * FileScope declaration.
129      */

130     protected org.omg.CORBA.Container JavaDoc
131     getContainer()
132     {
133         return the_parent_.getContainer();
134     }
135
136     /**
137      * Obtain its CORBA 3.0 Container reference.
138      *
139      * @return The Container object associated with the module declaration.
140      */

141     protected org.omg.CORBA.ComponentIR.Container
142     getComponentContainer()
143     {
144        return the_parent_.getComponentContainer();
145     }
146
147     // ==================================================================
148
//
149
// Public methods.
150
//
151
// ==================================================================
152

153     // ==================================================================
154
//
155
// Methods for OMG IDL org.objectweb.openccm.ast.api.Declaration
156
//
157
// ==================================================================
158

159     /**
160      * Obtain its DeclarationKind.
161      *
162      * This method is implemented into DeclarationImpl subclasses.
163      *
164      * @return The DeclarationKind of the object.
165      */

166     public long
167     getDeclKind()
168     {
169         return DeclarationKind.dk_null;
170     }
171
172     /**
173      * Obtain its absolute name.
174      *
175      * It is redefined to avoid to add the name of the FileScope.
176      *
177      * @return Its absolute name.
178      */

179     public java.lang.String JavaDoc
180     getAbsoluteName()
181     {
182         java.lang.String JavaDoc result = "";
183         if(the_parent_ != null)
184             result = the_parent_.getAbsoluteName();
185         return result;
186     }
187
188     /**
189      * Destroy all the contained declarations of the file scope in the IR3.
190      */

191     public void
192     destroy()
193     {
194 // Contributor: Philippe Merle
195
// Updated for Bug #554.
196

197         // Destroys all included files.
198
//
199
for (int i=0; i<included_files_.size(); i++)
200         {
201             FileScope fs = (FileScope)(included_files_.get(i));
202             fs.destroy();
203         }
204
205         // Destroys itself, i.e. call ScopeImpl.destroy
206
//
207
super.destroy();
208
209 /* Previous code.
210
211         // if this FileScope is the root FileScope then destroy it as a Scope.
212         if (getName().equals(""))
213             super.destroy();
214 */

215     }
216
217     // ==================================================================
218
//
219
// Methods for OMG IDL org.objectweb.openccm.ast.api.Scope
220
//
221
// ==================================================================
222

223     // ==================================================================
224
//
225
// Methods for OMG IDL org.objectweb.openccm.ast.api.FileScope
226
//
227
// ==================================================================
228

229     // ==================================================================
230
//
231
// Public methods for included files.
232
//
233
// ==================================================================
234

235     /**
236      * Set the associated file name.
237      *
238      * @param name - The associated file name.
239      */

240     public void
241     setFileName(String JavaDoc name)
242     {
243         file_name_ = name;
244     }
245
246     /**
247      * Obtain the associated name.
248      *
249      * @return The associated name.
250      */

251     public String JavaDoc
252     getFileName()
253     {
254         return file_name_;
255     }
256
257     /**
258      * Add an included file name to the current list.
259      *
260      * @param fs The parent FileScope.
261      */

262     public void
263     addIncluded(FileScope fs)
264     {
265         included_files_.add(fs);
266     }
267
268     /**
269      * Obtain the included file names in order.
270      *
271      * @return An array containing the included file names.
272      */

273     public String JavaDoc[]
274     getIncluded()
275     {
276         String JavaDoc[] filenames = new String JavaDoc[included_files_.size()];
277         for (int i=0;i<filenames.length;i++)
278             filenames[i] = ((Declaration)included_files_.get(i)).getName();
279
280         return filenames;
281     }
282 }
283
Popular Tags