KickJava   Java API By Example, From Geeks To Geeks.

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


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.
23 Contributor(s): Christophe Demarey.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.ast.lib;
28
29 /** To use AST AbstractStorageHomeList. */
30 import org.objectweb.openccm.ast.api.AbstractStorageHomeList;
31
32 import org.objectweb.openccm.ast.api.StorageHomeFactoryDecl;
33
34 import org.objectweb.openccm.ast.api.StorageHomeKeyDecl;
35
36 /** To use AST AbstractStorageHomeDecl. */
37 import org.objectweb.openccm.ast.api.AbstractStorageHomeDecl;
38
39 /** To report ASTError exceptions. */
40 import org.objectweb.openccm.ast.api.ASTError;
41
42 /** To access AST DeclarationKind. */
43 import org.objectweb.openccm.ast.api.DeclarationKind;
44
45 /** To access AST Declaration. */
46 import org.objectweb.openccm.ast.api.Declaration;
47
48 /**
49  * StorageHomeBaseImpl is a wrapper class for
50  * PSDL storagehome declarations.
51  *
52  *
53  * Inherits from:
54  *
55  * - ForwardScopePsdlImpl as storagehomes are also PSDL forward scopes.
56  *
57  * - StorageHomeBase as OMG IDL for PSDL storagehome declarations.
58  *
59  *
60  * Provides:
61  *
62  * - The list of inherited abstract storagehomes,
63  * i.e. the getAbstractStorageHomeList operation.
64  *
65  * - The factory for StorageHomeKeyDecl,
66  * i.e. the startStorageHomeKey operation.
67  *
68  * - The factory for StorageHomeFactoryDecl,
69  * i.e. the startStorageHomeFactory operation.
70  *
71  *
72  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
73  * <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
74  *
75  * @version 0.1
76  */

77
78 abstract public class StorageHomeBaseImpl
79                 extends ForwardScopePsdlImpl
80                 implements org.objectweb.openccm.ast.api.StorageHomeBase
81 {
82     // ==================================================================
83
//
84
// Internal state.
85
//
86
// ==================================================================
87

88     /** The list of inherited abstract storagehomes. */
89     protected AbstractStorageHomeListImpl abstract_storagehomes_;
90
91     // ==================================================================
92
//
93
// Constructor.
94
//
95
// ==================================================================
96

97     /**
98      * The constructor with the parent scope.
99      *
100      * @param parent The parent scope of the declaration.
101      */

102     protected
103     StorageHomeBaseImpl(Repository rep,
104                         ScopeImpl parent)
105     {
106         // Call the ForwardScopeImpl constructor.
107
super(rep, parent);
108
109         // Init internal state.
110
abstract_storagehomes_ = new AbstractStorageHomeListImpl();
111         content_loaded_ = true;
112     }
113
114     // ==================================================================
115
//
116
// Internal methods.
117
//
118
// ==================================================================
119

120     // ==================================================================
121
//
122
// Methods for DeclarationImpl
123
//
124
// ==================================================================
125

126     /**
127      * Check if the declaration is valid.
128      */

129     public void
130     check(StorageTypeBaseImpl st)
131     {
132         Declaration[] decls = null;
133
134         // Retrieve keys defined in this storage home
135
decls = getKeys();
136         if(decls != null)
137         {
138             for (int i=0; i<decls.length; i++)
139             {
140                 // For each key, check the validity of key state members
141
((StorageHomeKeyDeclImpl)decls[i]).check(st);
142             }
143         }
144
145         // Retrieve factories defined in this storage home
146
decls = getFactories();
147         if(decls != null)
148         {
149             for (int i=0; i<decls.length; i++)
150             {
151                 // For each factory, check the validity of factory state members
152
((StorageHomeFactoryDeclImpl)decls[i]).check(st);
153             }
154         }
155     }
156
157     // ==================================================================
158
//
159
// Methods for ScopeImpl
160
//
161
// ==================================================================
162

163     // ==================================================================
164
//
165
// Methods for ForwardScopeImpl
166
//
167
// ==================================================================
168

169     // ==================================================================
170
//
171
// Methods for ForwardScopePsdlImpl
172
//
173
// ==================================================================
174

175     // ==================================================================
176
//
177
// Public methods.
178
//
179
// ==================================================================
180

181     /**
182      * Get keys defined in this storage home.
183      *
184      * @return a list of Keys.
185      */

186     public Declaration[]
187     getKeys()
188     {
189        return getContents(true, DeclarationKind.dk_storage_home_key);
190     }
191
192     /**
193      * Get factories defined in this storage home.
194      *
195      * @return a list of factories.
196      */

197     public Declaration[]
198     getFactories()
199     {
200        return getContents(true, DeclarationKind.dk_storage_home_factory);
201     }
202
203     // ==================================================================
204
//
205
// Methods for OMG IDL org.objectweb.openccm.ast.api.WithDependencies
206
//
207
// ==================================================================
208

209     // ==================================================================
210
//
211
// Methods for OMG IDL org.objectweb.openccm.ast.api.Declaration
212
//
213
// ==================================================================
214

215     /**
216      * Create the declaration.
217      */

218     public void
219     create()
220     {
221         // Call the ForwardScopeImpl "create" method.
222
super.create();
223
224         // Check if an abstract storagehome is not specify more that once
225
int index = abstract_storagehomes_.checkSameItem();
226         if( index != -1 )
227         {
228             throw new ASTError(getName() + " implements twice " + ((AbstractStorageHomeDecl)abstract_storagehomes_.get(index)).getName() );
229         }
230     }
231
232     // ==================================================================
233
//
234
// Methods for OMG IDL org.objectweb.openccm.ast.api.Scope
235
//
236
// ==================================================================
237

238     // ==================================================================
239
//
240
// Methods for OMG IDL org.objectweb.openccm.ast.api.ForwardScope
241
//
242
// ==================================================================
243

244     // ==================================================================
245
//
246
// Methods for OMG IDL org.objectweb.openccm.ast.api.StorageHomeBase
247
//
248
// ==================================================================
249

250     /**
251      * Obtain the list of inherited abstract storagehomes.
252      *
253      * @return The list of inherited abstract storagehomes.
254      */

255     public AbstractStorageHomeList
256     getAbstractStorageHomeList()
257     {
258         return abstract_storagehomes_;
259     }
260
261     /**
262      * Obtain the list of all inherited abstract storagehomes.
263      *
264      * @return The list of all inherited abstract storagehomes.
265      */

266     public AbstractStorageHomeList
267     getAllImplementedAbstractStorageHomes()
268     {
269         AbstractStorageHomeDecl[] directly_impl = null;
270         AbstractStorageHomeListImpl implemented = new AbstractStorageHomeListImpl();
271
272         directly_impl = getAbstractStorageHomeList().getAbstractStorageHomes();
273         for(int i=0; i<directly_impl.length; i++)
274         {
275             AbstractStorageHomeDecl ash = (AbstractStorageHomeDecl)directly_impl[i];
276             implemented.add(ash);
277
278             AbstractStorageHomeDecl[] tmp =
279                 ash.getAllImplementedAbstractStorageHomes().getAbstractStorageHomes();
280             for (int j=0; j<tmp.length; j++)
281             {
282                 if (!implemented.contains(tmp[j]))
283                     implemented.add(tmp[j]);
284             }
285         }
286         return implemented;
287     }
288
289     /**
290      * Start a storagehome key declaration.
291      *
292      * @param name The name of the storagehome key declaration.
293      *
294      * @return The created StorageHomeKeyDecl.
295      */

296     public StorageHomeKeyDecl
297     startStorageHomeKey(String JavaDoc name)
298     {
299         // Check if the name is already used
300
if ( findInScope(name) != null)
301         {
302             throw new ASTError(name + " is already defined." );
303         }
304
305         StorageHomeKeyDecl decl = new StorageHomeKeyDeclImpl(getRepository(), this);
306         decl.setName(name);
307         return decl;
308     }
309
310     /**
311      * Start a storagehome factory declaration.
312      *
313      * @param name The name of the storagehome factory declaration.
314      *
315      * @return The created StorageHomeFactoryDecl.
316      */

317     public StorageHomeFactoryDecl
318     startStorageHomeFactory(String JavaDoc name)
319     {
320         // Check if the name is already used
321
if ( findInScope(name) != null)
322         {
323             throw new ASTError(name + " is already defined." );
324         }
325
326         StorageHomeFactoryDecl decl = new StorageHomeFactoryDeclImpl(getRepository(), this);
327         decl.setName(name);
328         return decl;
329     }
330 }
331
Popular Tags