KickJava   Java API By Example, From Geeks To Geeks.

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


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 access AST DeclarationKind. */
30 import org.objectweb.openccm.ast.api.DeclarationKind;
31
32 import org.objectweb.openccm.ast.api.StorageTypeDecl;
33 import org.objectweb.openccm.ast.api.StorageHomeDecl;
34 import org.objectweb.openccm.ast.api.AbstractStorageTypeDecl;
35 import org.objectweb.openccm.ast.api.AbstractStorageHomeDecl;
36
37 /** To access AST Declaration. */
38 import org.objectweb.openccm.ast.api.Declaration;
39
40 /** To report ASTError exceptions. */
41 import org.objectweb.openccm.ast.api.ASTError;
42
43 /**
44  * StorageHomeDeclImpl is a wrapper class for
45  * PSDL storagehome declarations.
46  *
47  *
48  * Inherits from:
49  *
50  * - StorageHomeBaseImpl as storagehomes are also IDL forward scopes.
51  *
52  *
53  * Provides:
54  *
55  * - The managed storagetype,
56  * i.e. the setStorageType and getStorageType operations.
57  *
58  * - The inherited base storagehome,
59  * i.e. the setBaseStorageHome and getBaseStorageHome operations.
60  *
61  * - The primary key ref property,
62  * i.e. the setPrimaryKeyName and getPrimaryKeyName operations.
63  *
64  * - The primary key name,
65  * i.e. the setPrimaryKeyRef and isPrimaryKeyRef operations.
66  *
67  *
68  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
69  * <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
70  *
71  * @version 0.1
72  */

73
74 public class StorageHomeDeclImpl
75      extends StorageHomeBaseImpl
76   implements org.objectweb.openccm.ast.api.StorageHomeDecl
77 {
78     // ==================================================================
79
//
80
// Internal state.
81
//
82
// ==================================================================
83

84     /** The managed storagetype. */
85     protected StorageTypeDeclImpl managedStorageType_;
86
87     /** The inherited base storagehome. */
88     protected StorageHomeDeclImpl baseStorageHome_;
89
90     /** The primarykey name. */
91     protected String JavaDoc primaryKeyName_;
92
93     /** Is a primarykey ref. */
94     protected boolean isPrimaryKeyRef_;
95
96     // ==================================================================
97
//
98
// Constructor.
99
//
100
// ==================================================================
101

102     /**
103      * The constructor with the parent scope.
104      *
105      * @param parent The parent scope of the declaration.
106      */

107     protected
108     StorageHomeDeclImpl(Repository rep,
109                         ScopeImpl parent)
110     {
111         // Call the StorageHomeBaseImpl constructor.
112
super(rep, parent);
113
114         // Init internal state.
115
managedStorageType_ = null;
116         baseStorageHome_ = null;
117         primaryKeyName_ = null;
118         isPrimaryKeyRef_ = false;
119     }
120
121     // ==================================================================
122
//
123
// Internal methods.
124
//
125
// ==================================================================
126

127     // ==================================================================
128
//
129
// Methods for DeclarationImpl
130
//
131
// ==================================================================
132

133     /**
134      * Obtain its DeclarationKind.
135      *
136      * This method is implemented into DeclarationImpl subclasses.
137      *
138      * @return The DeclarationKind of the object.
139      */

140     public long
141     getDeclKind()
142     {
143         return DeclarationKind.dk_storage_home;
144     }
145
146
147     /**
148      * Create the declaration.
149      */

150     public void
151     create()
152     {
153         // Call the StorageHomeBaseImpl "create" method.
154
super.create();
155
156         // Check the primary key
157
if(primaryKeyName_ != null)
158         {
159             java.util.List JavaDoc keys = new java.util.ArrayList JavaDoc();
160
161             int size = 0;
162             size = abstract_storagehomes_.getSize();
163             for (int i=0; i<size; i++)
164             {
165                 AbstractStorageHomeDeclImpl ash = (AbstractStorageHomeDeclImpl)abstract_storagehomes_.get(i);
166                 Declaration decls[] = ash.getKeys();
167                 if(decls != null)
168                 {
169                     for(int j=0; j<decls.length; j++)
170                         keys.add( decls[j] );
171                 }
172             }
173
174             int i = 0;
175             boolean found = false;
176
177             size = keys.size();
178             while( (i<size) && !found)
179             {
180                 if( primaryKeyName_.compareTo(((Declaration)keys.get(i)).getName()) == 0 )
181                     found = true;
182                 i++;
183             }
184             if(!found)
185             {
186                 throw new ASTError(getName() +" : " + primaryKeyName_ + " is not a valid primary key.");
187             }
188         }
189
190         // Check the storage type managed
191
java.util.List JavaDoc ast_required = new java.util.ArrayList JavaDoc();
192         AbstractStorageHomeListImpl ash_list = null;
193         int size = 0;
194
195         // Retrieve abstract storage homes implemented
196
ash_list = (AbstractStorageHomeListImpl)getAbstractStorageHomeList();
197         size = ash_list.getSize();
198         for(int i=0; i<size; i++)
199         {
200             AbstractStorageHomeDeclImpl ash = (AbstractStorageHomeDeclImpl)ash_list.get(i);
201             AbstractStorageTypeDeclImpl ast = (AbstractStorageTypeDeclImpl)ash.getAbstractStorageType();
202             ast_required.add(ast);
203         }
204
205         // Retrieve abstract storage types implemented by the managed storage type
206
AbstractStorageTypeDecl[] ast_list = null;
207         java.util.ArrayList JavaDoc implemented_ast_found = new java.util.ArrayList JavaDoc();
208
209         ast_list = managedStorageType_.getAllImplementedAbstractStorageTypes().getAbstractStorageTypes();
210         for(int i=0; i<ast_list.length; i++)
211         {
212             implemented_ast_found.add(ast_list[i]);
213         }
214
215
216         if(!implemented_ast_found.containsAll(ast_required))
217              throw new ASTError(getName() + " has not a valid storage type.");
218
219     }
220
221     // ==================================================================
222
//
223
// Methods for ScopeImpl
224
//
225
// ==================================================================
226

227     // ==================================================================
228
//
229
// Methods for ForwardScopeImpl
230
//
231
// ==================================================================
232

233     // ==================================================================
234
//
235
// Methods for ForwardScopePsdlImpl
236
//
237
// ==================================================================
238

239     // ==================================================================
240
//
241
// Methods for StorageHomeBaseImpl
242
//
243
// ==================================================================
244

245     // ==================================================================
246
//
247
// Public methods.
248
//
249
// ==================================================================
250

251     // ==================================================================
252
//
253
// Methods for OMG IDL org.objectweb.openccm.ast.api.WithDependencies
254
//
255
// ==================================================================
256

257     // ==================================================================
258
//
259
// Methods for OMG IDL org.objectweb.openccm.ast.api.Declaration
260
//
261
// ==================================================================
262

263     /**
264      * Check if the declaration is valid.
265      */

266     public void
267     check()
268     {
269         // Call the StorageHomeBase "check" method
270
super.check(managedStorageType_);
271     }
272
273     // ==================================================================
274
//
275
// Methods for OMG IDL org.objectweb.openccm.ast.api.Scope
276
//
277
// ==================================================================
278

279     // ==================================================================
280
//
281
// Methods for OMG IDL org.objectweb.openccm.ast.api.ForwardScope
282
//
283
// ==================================================================
284

285     // ==================================================================
286
//
287
// Methods for OMG IDL org.objectweb.openccm.ast.api.StorageHomeBase
288
//
289
// ==================================================================
290

291     // ==================================================================
292
//
293
// Methods for OMG IDL org.objectweb.openccm.ast.api.StorageHomeDecl
294
//
295
// ==================================================================
296

297     /**
298      * Set the managed storagetype.
299      *
300      * @param st The managed storagetype.
301      */

302     public void
303     setStorageType(StorageTypeDecl st)
304     {
305         if(st != null)
306         {
307             managedStorageType_ = (StorageTypeDeclImpl)st;
308         }
309     }
310
311     /**
312      * Obtain the managed storagetype.
313      *
314      * @return The managed storagetype.
315      */

316     public StorageTypeDecl
317     getStorageType()
318     {
319         return managedStorageType_;
320     }
321
322     /**
323      * Set the inherited base storagehome.
324      *
325      * @param sh The inherited base storagehome.
326      */

327     public void
328     setBaseStorageHome(StorageHomeDecl sh)
329     {
330         if(sh != null)
331         {
332             baseStorageHome_ = (StorageHomeDeclImpl)sh;
333         }
334     }
335
336     /**
337      * Obtain the inherited base storagehome.
338      *
339      * @return The inherited base storagehome.
340      */

341     public StorageHomeDecl
342     getBaseStorageHome()
343     {
344         return baseStorageHome_;
345     }
346
347     /**
348      * Set the primary key name.
349      *
350      * @param name The primary key name.
351      */

352     public void
353     setPrimaryKeyName(String JavaDoc name)
354     {
355         primaryKeyName_ = name;
356     }
357
358     /**
359      * Obtain the primary key name.
360      *
361      * @return The primary key name.
362      */

363     public String JavaDoc
364     getPrimaryKeyName()
365     {
366         return primaryKeyName_;
367     }
368
369     /**
370      * Set as a primary key ref.
371      *
372      * @param b True if a primary key ref, or false otherwise.
373      */

374     public void
375     setPrimaryKeyRef(boolean b)
376     {
377         isPrimaryKeyRef_ = b;
378     }
379
380     /**
381      * Is it a primary key ref?
382      *
383      * @return True if a primary key ref, or false otherwise.
384      */

385     public boolean
386     isPrimaryKeyRef()
387     {
388         return isPrimaryKeyRef_;
389     }
390
391     /**
392      * Get directly implemented abstract storage homes.
393      *
394      * @return A list of abstract storage homes.
395      **/

396     public AbstractStorageHomeDecl[]
397     getDirectlyImplementedAbstractStorageHomes()
398     {
399         AbstractStorageHomeDecl[] sh_base_implemented = null,
400                                   ash_implemented = null,
401                                   result = null;
402
403         ash_implemented =
404             getAllImplementedAbstractStorageHomes().getAbstractStorageHomes();
405
406         if (getBaseStorageHome() == null)
407         {
408             return ash_implemented;
409         }
410
411         sh_base_implemented =
412             getBaseStorageHome().getAllImplementedAbstractStorageHomes().getAbstractStorageHomes();
413
414         // Construct a list of implemented abstract storage home by
415
// the storage home base
416
java.util.Set JavaDoc base_list = new java.util.HashSet JavaDoc();
417         for (int i=0; i<sh_base_implemented.length; i++)
418         {
419             base_list.add(sh_base_implemented[i]);
420         }
421
422         // Construct a list of implemented abstract storage home
423
java.util.Set JavaDoc own_list = new java.util.HashSet JavaDoc();
424         for (int i=0; i<ash_implemented.length; i++)
425         {
426             own_list.add(ash_implemented[i]);
427         }
428
429         // Diff = directly implemented abstract storage home
430
own_list.removeAll(base_list);
431         result = (AbstractStorageHomeDecl[])own_list.toArray(new AbstractStorageHomeDecl[0]);
432         return result;
433     }
434 }
435
Popular Tags