KickJava   Java API By Example, From Geeks To Geeks.

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


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.StringList;
33
34 import org.objectweb.openccm.ast.api.StorageTypeDecl;
35 import org.objectweb.openccm.ast.api.AbstractStorageTypeDecl;
36
37 /** To report ASTError exceptions. */
38 import org.objectweb.openccm.ast.api.ASTError;
39
40 /**
41  * StorageTypeDeclImpl is a wrapper class for
42  * PSDL storagetype declarations.
43  *
44  *
45  * Inherits from:
46  *
47  * - StorageTypeBaseImpl as storagetypes are also IDL forward scopes.
48  *
49  *
50  * Provides:
51  *
52  * - The base inherited storagetype,
53  * i.e. the setBaseStorageType and getBaseStorageType operations.
54  *
55  * - The list of ref rep directives,
56  * i.e. the getRefRepDirectiveList operation.
57  *
58  *
59  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
60  * <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
61  *
62  * @version 0.1
63  */

64
65 public class StorageTypeDeclImpl
66      extends StorageTypeBaseImpl
67   implements org.objectweb.openccm.ast.api.StorageTypeDecl
68 {
69     // ==================================================================
70
//
71
// Internal state.
72
//
73
// ==================================================================
74

75     /** Base storage type. */
76     protected StorageTypeDeclImpl baseStorageType_;
77
78     /** Ref rep directive list. */
79     protected StringListImpl refRepDirectiveList_;
80
81     // ==================================================================
82
//
83
// Constructor.
84
//
85
// ==================================================================
86

87     /**
88      * The constructor with the parent scope.
89      *
90      * @param parent The parent scope of the declaration.
91      */

92     protected
93     StorageTypeDeclImpl(Repository rep,
94                         ScopeImpl parent)
95     {
96         // Call the StorageTypeBaseImpl constructor.
97
super(rep, parent);
98
99         // Init internal state.
100
baseStorageType_ = null;
101         refRepDirectiveList_ = new StringListImpl();
102     }
103
104     // ==================================================================
105
//
106
// Internal methods.
107
//
108
// ==================================================================
109

110     /**
111      * This method check if the string passed match with a declared state member.
112      *
113      * @param state The name of the state member to check.
114      *
115      * @return True if it's a valid state member.
116      */

117     protected boolean
118     isValidState(String JavaDoc state)
119     {
120         // Call the StorageTypeBase "isValidState" method
121
boolean found = super.isValidState(state);
122
123         if(baseStorageType_ == null)
124             return found;
125         if(!found)
126             // if not found, check in the base storage type
127
return baseStorageType_.isValidState(state);
128         else
129             return true;
130     }
131
132     // ==================================================================
133
//
134
// Methods for DeclarationImpl
135
//
136
// ==================================================================
137

138     /**
139      * Obtain its DeclarationKind.
140      *
141      * This method is implemented into DeclarationImpl subclasses.
142      *
143      * @return The DeclarationKind of the object.
144      */

145     public long
146     getDeclKind()
147     {
148         return DeclarationKind.dk_storage_type;
149     }
150
151     // ==================================================================
152
//
153
// Methods for ScopeImpl
154
//
155
// ==================================================================
156

157     // ==================================================================
158
//
159
// Methods for ForwardScopeImpl
160
//
161
// ==================================================================
162

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

169     // ==================================================================
170
//
171
// Public methods.
172
//
173
// ==================================================================
174

175     // ==================================================================
176
//
177
// Methods for OMG IDL org.objectweb.openccm.ast.api.WithDependencies
178
//
179
// ==================================================================
180

181     // ==================================================================
182
//
183
// Methods for OMG IDL org.objectweb.openccm.ast.api.Declaration
184
//
185
// ==================================================================
186

187     /**
188      * Create the declaration.
189      */

190     public void
191     create()
192     {
193         // Call the ForwardScopeImpl "create" method.
194
super.create();
195
196         // Check if a member is not specify more that once
197
int index = refRepDirectiveList_.checkSameItem();
198         if( index != -1 )
199         {
200             throw new ASTError( (String JavaDoc)refRepDirectiveList_.get(index) + " must be specified once and once only.");
201         }
202     }
203
204     /**
205      * Check if the declaration is valid.
206      */

207     public void
208     check()
209     {
210         /** Check if the reference representation is valid */
211         int size = refRepDirectiveList_.getSize();
212
213         // 1. baseStorageType_ must be null
214
if( (size>0) && (baseStorageType_ != null) )
215         {
216             throw new ASTError( getName() +
217                " has a based storage type. This is not consistent with a reference representation directive!" );
218         }
219
220         // 2. state members must be valid
221
for(int i=0; i<size; i++)
222         {
223             String JavaDoc state = (String JavaDoc)refRepDirectiveList_.get(i);
224             if( isValidState(state) == false)
225             {
226                 throw new ASTError(getName() + " => " + state + " is not a valid state member." );
227             }
228         }
229
230         /* A storagetype that directly implements an abstract storagetype
231            that declares a state member whose type is an abstract storagetype
232            or an array or a sequence of abstract storagetypes must provide
233            a store directive for this state member.
234         */

235         org.objectweb.openccm.ast.api.AbstractStorageTypeDecl[] ast_decls = null;
236
237         // get abstract storage types directly implemented
238
ast_decls = getDirectlyImplementedAbstractStorageTypes();
239         //getAbstractStorageTypeList().getAbstractStorageTypes();
240
for(int i=0; i<ast_decls.length; i++)
241         {
242             // System.err.println("+--> "+ast_decls[i].getName());
243
// get storage type state members
244
org.objectweb.openccm.ast.api.Declaration[] decls = null;
245             decls = ast_decls[i].getContents(true, org.objectweb.openccm.ast.api.DeclarationKind.dk_storage_type_state_member);
246             for(int j=0; j<decls.length; j++)
247             {
248                 org.objectweb.openccm.ast.api.StorageTypeStateMemberDecl
249                             member = (org.objectweb.openccm.ast.api.StorageTypeStateMemberDecl)decls[j];
250                 org.objectweb.openccm.ast.api.StorageTypeBase type = member.getType().getStorageTypeBase();
251                 if ( (type != null) && (!member.getType().isRef()) )
252                 {
253                     // State member is a storage type or an abstract storage type
254
String JavaDoc name = getAbsoluteName()+"::"+decls[j].getName()+"_store_directive";
255                     org.objectweb.openccm.ast.api.Declaration store_directive = lookup(name);
256                     if (store_directive == null)
257                         throw new ASTError(
258                             getAbsoluteName()+" : No store directive found for "+decls[j].getName());
259                 }
260             }
261         }
262
263     }
264
265     // ==================================================================
266
//
267
// Methods for OMG IDL org.objectweb.openccm.ast.api.Scope
268
//
269
// ==================================================================
270

271     // ==================================================================
272
//
273
// Methods for OMG IDL org.objectweb.openccm.ast.api.ForwardScope
274
//
275
// ==================================================================
276

277     // ==================================================================
278
//
279
// Methods for OMG IDL org.objectweb.openccm.ast.api.StorageTypeBase
280
//
281
// ==================================================================
282

283     // ==================================================================
284
//
285
// Methods for OMG IDL org.objectweb.openccm.ast.api.StorageTypeDecl
286
//
287
// ==================================================================
288

289     /**
290      * Set the base inherited storagetype.
291      *
292      * @param st The base inherited storagetype.
293      **/

294     public void
295     setBaseStorageType(StorageTypeDecl st)
296     {
297         if(st != null)
298         {
299             baseStorageType_ = (StorageTypeDeclImpl)st;
300         }
301     }
302
303     /**
304      * Obtain the base inherited storagetype.
305      *
306      * @return The base inherited storagetype.
307      **/

308     public StorageTypeDecl
309     getBaseStorageType()
310     {
311         return baseStorageType_;
312     }
313
314     /**
315      * Obtain the list of ref rep directives.
316      *
317      * @return all ref rep directives.
318      **/

319     public StringList
320     getRefRepDirectiveList()
321     {
322        return refRepDirectiveList_;
323     }
324
325     /**
326      * Get directly implemented abstract storage types.
327      *
328      * @return A list of abstract storage types.
329      **/

330     public AbstractStorageTypeDecl[]
331     getDirectlyImplementedAbstractStorageTypes()
332     {
333         AbstractStorageTypeDecl[] st_base_implemented = null,
334                                   ast_implemented = null,
335                                   result = null;
336
337         ast_implemented =
338             getAllImplementedAbstractStorageTypes().getAbstractStorageTypes();
339
340         if (getBaseStorageType() == null)
341         {
342             return ast_implemented;
343         }
344
345         st_base_implemented =
346             getBaseStorageType().getAllImplementedAbstractStorageTypes().getAbstractStorageTypes();
347
348         // Construct a list of implemented abstract storage type by
349
// the storage type base
350
java.util.Set JavaDoc base_list = new java.util.HashSet JavaDoc();
351         for (int i=0; i<st_base_implemented.length; i++)
352         {
353             base_list.add(st_base_implemented[i]);
354         }
355
356         // Construct a list of implemented abstract storage type
357
java.util.Set JavaDoc own_list = new java.util.HashSet JavaDoc();
358         for (int i=0; i<ast_implemented.length; i++)
359         {
360             own_list.add(ast_implemented[i]);
361         }
362
363         // Diff = directly implemented abstract storage type
364
own_list.removeAll(base_list);
365         result = (AbstractStorageTypeDecl[])own_list.toArray(new AbstractStorageTypeDecl[0]);
366         return result;
367     }
368 }
369
Popular Tags