KickJava   Java API By Example, From Geeks To Geeks.

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


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 AbstractStorageTypeDecl. */
30 import org.objectweb.openccm.ast.api.AbstractStorageTypeDecl;
31
32 /** To use AST StorageTypeStateMemberDecl. */
33 import org.objectweb.openccm.ast.api.StorageTypeStateMemberDecl;
34
35 /** To use AST AbstractStorageTypeList. */
36 import org.objectweb.openccm.ast.api.AbstractStorageTypeList;
37
38 /** To report ASTError exceptions. */
39 import org.objectweb.openccm.ast.api.ASTError;
40
41 /**
42  * StorageTypeBaseImpl is a wrapper class for
43  * PSDL storagetype declarations.
44  *
45  *
46  * Inherits from:
47  *
48  * - ForwardScopeImpl as storagetypes are also IDL forward scopes.
49  *
50  * - StorageTypeBase as OMG IDL for PSDL storagetype declarations.
51  *
52  *
53  * Provides:
54  *
55  * - The list of inherited abstract storagetypes,
56  * i.e. the getAbstractStorageTypeList 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 abstract public class StorageTypeBaseImpl
66               extends ForwardScopePsdlImpl
67            implements org.objectweb.openccm.ast.api.StorageTypeBase
68 {
69     // ==================================================================
70
//
71
// Internal state.
72
//
73
// ==================================================================
74

75     /** The list of inherited abstract storagetypes. */
76     protected AbstractStorageTypeListImpl abstract_storagetypes_;
77
78     // ==================================================================
79
//
80
// Constructor.
81
//
82
// ==================================================================
83

84     /**
85      * The constructor with the parent scope.
86      *
87      * @param parent The parent scope of the declaration.
88      */

89     protected
90     StorageTypeBaseImpl(Repository rep,
91                         ScopeImpl parent)
92     {
93         // Call the ForwardScopePsdlImpl constructor.
94
super(rep, parent);
95
96         // Init internal state.
97
abstract_storagetypes_ = new AbstractStorageTypeListImpl();
98         content_loaded_ = true;
99     }
100
101     // ==================================================================
102
//
103
// Internal methods.
104
//
105
// ==================================================================
106

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

114     protected boolean
115     isValidState(String JavaDoc state)
116     {
117         DeclarationImpl decl = null;
118
119         // Find in the current storageType
120
decl = (DeclarationImpl)findInScope(state);
121         if(decl == null)
122         {
123             // Find in the implemented abstract storage types
124
boolean found = false;
125             int size = abstract_storagetypes_.getSize();
126             if (size > 0)
127             {
128                 int i = 0;
129                 while( (i<size) && !found )
130                 {
131                     found = ((AbstractStorageTypeDeclImpl)abstract_storagetypes_.get(i)).isValidState(state);
132                     i++;
133                 }
134             }
135             if(!found) return false;
136         }
137         return true;
138     }
139
140     // ==================================================================
141
//
142
// Methods for DeclarationImpl
143
//
144
// ==================================================================
145

146     // ==================================================================
147
//
148
// Methods for ScopeImpl
149
//
150
// ==================================================================
151

152     // ==================================================================
153
//
154
// Methods for ForwardScopeImpl
155
//
156
// ==================================================================
157

158     // ==================================================================
159
//
160
// Methods for ForwardScopePsdlImpl
161
//
162
// ==================================================================
163

164     // ==================================================================
165
//
166
// Public methods.
167
//
168
// ==================================================================
169

170     // ==================================================================
171
//
172
// Methods for OMG IDL org.objectweb.openccm.ast.api.WithDependencies
173
//
174
// ==================================================================
175

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

182     /**
183      * Create the declaration.
184      */

185     public void
186     create()
187     {
188         // Call the ForwardScopeImpl "create" method.
189
super.create();
190
191         // Check if an abstract storagetype is not specify more that once
192
int index = abstract_storagetypes_.checkSameItem();
193         if( index != -1 )
194         {
195             throw new ASTError(getName() + " implements twice " + ((AbstractStorageTypeDecl)abstract_storagetypes_.get(index)).getName() );
196         }
197     }
198
199     // ==================================================================
200
//
201
// Methods for OMG IDL org.objectweb.openccm.ast.api.Scope
202
//
203
// ==================================================================
204

205     // ==================================================================
206
//
207
// Methods for OMG IDL org.objectweb.openccm.ast.api.ForwardScope
208
//
209
// ==================================================================
210

211     // ==================================================================
212
//
213
// Methods for OMG IDL org.objectweb.openccm.ast.api.StorageTypeBase
214
//
215
// ==================================================================
216

217     /**
218      * Obtain the list of inherited abstract storagetypes.
219      *
220      * @return The list of inherited abstract storagetypes.
221      */

222     public AbstractStorageTypeList
223     getAbstractStorageTypeList()
224     {
225         return abstract_storagetypes_;
226     }
227
228     /**
229      * Obtain the list of all inherited abstract storagetypes.
230      *
231      * @return The list of all inherited abstract storagetypes.
232      */

233     public AbstractStorageTypeList
234     getAllImplementedAbstractStorageTypes()
235     {
236         AbstractStorageTypeDecl[] directly_impl = null;
237         AbstractStorageTypeListImpl implemented = new AbstractStorageTypeListImpl();
238
239         directly_impl = getAbstractStorageTypeList().getAbstractStorageTypes();
240         for(int i=0; i<directly_impl.length; i++)
241         {
242             AbstractStorageTypeDecl ast = (AbstractStorageTypeDecl)directly_impl[i];
243             implemented.add(ast);
244
245             AbstractStorageTypeDecl[] tmp =
246                 ast.getAllImplementedAbstractStorageTypes().getAbstractStorageTypes();
247             for (int j=0; j<tmp.length; j++)
248             {
249                 if (!implemented.contains(tmp[j]))
250                     implemented.add(tmp[j]);
251             }
252         }
253         return implemented;
254     }
255
256     /**
257      * Get a state member contained in a storage type with its name.
258      *
259      * @param name - The name of the state member to get.
260      *
261      * @return The state member declaration if found, else null.
262      */

263     public StorageTypeStateMemberDecl
264     getState(String JavaDoc name)
265     {
266         StorageTypeStateMemberDecl decl = null;
267
268         // Find in the current storageType
269
decl = (StorageTypeStateMemberDecl)findInScope(name);
270         if(decl == null)
271         {
272             // Find in the implemented abstract storage types
273
int size = abstract_storagetypes_.getSize();
274             if (size > 0)
275             {
276                 int i = 0;
277                 while( (i<size) && (decl == null) )
278                 {
279                     decl = ((AbstractStorageTypeDecl)abstract_storagetypes_.get(i)).getState(name);
280                     i++;
281                 }
282             }
283         }
284         return decl;
285     }
286 }
287
Popular Tags