KickJava   Java API By Example, From Geeks To Geeks.

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


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 DeclarationKind. */
30 import org.objectweb.openccm.ast.api.DeclarationKind;
31
32 /** To access AST Declaration. */
33 import org.objectweb.openccm.ast.api.Declaration;
34
35 /** To access AST ExceptionDecl. */
36 import org.objectweb.openccm.ast.api.ExceptionDecl;
37
38 /** To access AST ExceptionList. */
39 import org.objectweb.openccm.ast.api.ExceptionList;
40
41 /** To use CORBA::ExtAttributeDef. */
42 import org.omg.CORBA.ExtAttributeDef;
43 import org.omg.CORBA.ExtAttributeDefHelper;
44
45 /** To use CORBA::AttributeMode. */
46 import org.omg.CORBA.AttributeMode JavaDoc;
47
48 /** To use CORBA::ExceptionDef. */
49 import org.omg.CORBA.ExceptionDef JavaDoc;
50
51 /**
52  * AttributeDeclImpl is a wrapper class for IDL attribute declarations.
53  *
54  * Inherits from:
55  * - DeclarationWithTypeRefImpl as attributes are IDL declarations
56  * and have an associated type.
57  *
58  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
59  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
60  *
61  * @version 0.3
62  */

63
64 public class AttributeDeclImpl
65        extends DeclarationWithTypeRefImpl
66        implements org.objectweb.openccm.ast.api.AttributeDecl
67 {
68     // ==================================================================
69
//
70
// Internal state.
71
//
72
// ==================================================================
73

74     /** Reference to the CORBA 3.0 AttributeDef. */
75     private ExtAttributeDef ext_attribute_def_;
76
77     /** The attribute mode. */
78     private AttributeMode JavaDoc mode_;
79
80     /** The attribute get exceptions. */
81     private ExceptionListImpl get_exceptions_;
82
83     /** The attribute put exceptions. */
84     private ExceptionListImpl set_exceptions_;
85
86     // ==================================================================
87
//
88
// Constructor.
89
//
90
// ==================================================================
91

92     /**
93      * The constructor with the parent scope.
94      *
95      * @param rep The repository of the declaration.
96      * @param parent The parent scope of the declaration.
97      */

98     protected
99     AttributeDeclImpl(Repository rep,
100                       ScopeImpl parent)
101     {
102         // Call the DeclarationWithTypeRefImpl constructor.
103
super(rep, parent);
104
105         // Init internal state.
106
ext_attribute_def_ = null;
107         mode_ = AttributeMode.ATTR_NORMAL;
108         get_exceptions_ = new ExceptionListImpl();
109         set_exceptions_ = new ExceptionListImpl();
110     }
111
112     // ==================================================================
113
//
114
// Internal methods.
115
//
116
// ==================================================================
117

118     /**
119      * Add exception declarations as dependencies.
120      *
121      * @param attr_depend The dependencies list.
122      * @param excs The exception declarations to add.
123      */

124     protected void
125     addDependencies(java.util.List JavaDoc attr_depend,
126                     ExceptionDecl[] excs)
127     {
128         Declaration[] depend = null;
129         for (int i=0;i<excs.length;i++)
130         {
131             attr_depend.add(excs[i]);
132             depend = excs[i].getDependencies();
133             for (int j=0;j<depend.length;j++)
134             {
135                 if (attr_depend.indexOf(depend[j])==-1)
136                     attr_depend.add(depend[j]);
137             }
138         }
139     }
140
141     // ==================================================================
142
//
143
// Internal methods for DeclarationImpl.
144
//
145
// ==================================================================
146

147     /**
148      * Loads infos of the CORBA 3.0 ModuleDef.
149      *
150      * @param contained The ModuleDef to load.
151      */

152     protected void
153     load(org.omg.CORBA.Contained JavaDoc contained)
154     {
155         ext_attribute_def_ = ExtAttributeDefHelper.narrow(contained);
156         mode_ = ext_attribute_def_.mode();
157         setType(getRepository().getAsTypeRef(ext_attribute_def_.type_def()));
158
159         ExceptionDef JavaDoc[] exc = ext_attribute_def_.get_exceptions();
160         for (int i=0; i<exc.length; i++)
161             get_exceptions_.add((ExceptionDecl)getRepository().
162                                 lookupId(exc[i].id()));
163
164         exc = ext_attribute_def_.set_exceptions();
165         for (int i=0; i<exc.length; i++)
166             set_exceptions_.add((ExceptionDecl)getRepository().
167                                 lookupId(exc[i].id()));
168
169         super.load(contained);
170     }
171
172     /**
173      * Loads infos of the CORBA 3.0 ModuleDef.
174      *
175      * @param contained The ModuleDef to load.
176      */

177     protected void
178     loadAsMapping(org.omg.CORBA.Contained JavaDoc contained)
179     {
180         ext_attribute_def_ = ExtAttributeDefHelper.narrow(contained);
181         mode_ = ext_attribute_def_.mode();
182         setType(getRepository().
183                 getAsMappedTypeRef(ext_attribute_def_.type_def()));
184
185         ExceptionDef JavaDoc[] exc = ext_attribute_def_.get_exceptions();
186         for (int i=0; i<exc.length; i++)
187             get_exceptions_.add((ExceptionDecl)getRepository().
188                                 lookupMappedId(exc[i].id()));
189
190         exc = ext_attribute_def_.set_exceptions();
191         for (int i=0; i<exc.length; i++)
192             set_exceptions_.add((ExceptionDecl)getRepository().
193                                 lookupMappedId(exc[i].id()));
194
195         super.loadAsMapping(contained);
196     }
197
198     /**
199      * Obtain its CORBA 3.0 Contained reference.
200      *
201      * @return The Contained object associated with the
202      * attribute declaration.
203      */

204     protected org.omg.CORBA.Contained JavaDoc
205     getContained()
206     {
207        return ext_attribute_def_;
208     }
209
210     // ==================================================================
211
//
212
// Public methods.
213
//
214
// ==================================================================
215

216     // ==================================================================
217
//
218
// Methods for OMG IDL org.objectweb.openccm.ast.api.WithDependencies
219
//
220
// ==================================================================
221

222     /**
223      * Obtain the declaration external dependencies.
224      *
225      * Note: for scopes, contained objects are not considered
226      * as dependencies.
227      *
228      * @return The list of dependencies as an array of Declaration.
229      */

230     public Declaration[]
231     getDependencies()
232     {
233         if (dependencies_!=null)
234             return dependencies_;
235
236         java.util.List JavaDoc attr_depend = new java.util.ArrayList JavaDoc();
237         Declaration[] depend = null;
238
239         // attribute type
240
if (getType().isDeclaration())
241             attr_depend.add(getType());
242
243         depend = getType().getDependencies();
244         for (int i=0; i<depend.length; i++)
245             attr_depend.add(depend[i]);
246
247         // exceptions
248
if (isReadonly())
249             addDependencies(attr_depend, getExceptions());
250         else
251         {
252             addDependencies(attr_depend, getGetExceptions());
253             addDependencies(attr_depend, getSetExceptions());
254         }
255
256         dependencies_ = (Declaration[])attr_depend.toArray(new Declaration[0]);
257         return dependencies_;
258     }
259
260     // ==================================================================
261
//
262
// Methods for OMG IDL org.objectweb.openccm.ast.api.Declaration
263
//
264
// ==================================================================
265

266     /**
267      * Obtain its DeclarationKind.
268      *
269      * @return The DeclarationKind of the object.
270      */

271     public long
272     getDeclKind()
273     {
274         return DeclarationKind.dk_attribute;
275     }
276
277     /**
278      * Create the attribute declaration into the IFR.
279      */

280     public void
281     create()
282     {
283         ext_attribute_def_ = the_parent_.createExtAttribute(this,
284                                  getIDLType(), mode_,
285                                  get_exceptions_.getExceptionDefSeq(),
286                                  set_exceptions_.getExceptionDefSeq());
287         super.create();
288     }
289
290     // ==================================================================
291
//
292
// Methods for OMG IDL org.objectweb.openccm.ast.api.AttributeDecl
293
//
294
// ==================================================================
295

296     /**
297      * Set the associated mode as normal.
298      */

299     public void
300     setNormal()
301     {
302         mode_ = AttributeMode.ATTR_NORMAL;
303     }
304
305     /**
306      * Is a normal attribute?
307      *
308      * @return True if normal, else false.
309      */

310     public boolean
311     isNormal()
312     {
313         return mode_ == AttributeMode.ATTR_NORMAL;
314     }
315
316     /**
317      * Set the associated mode as readonly.
318      */

319     public void
320     setReadonly()
321     {
322         mode_ = AttributeMode.ATTR_READONLY;
323     }
324
325     /**
326      * Is a readonly attribute?
327      *
328      * @return True if readonly, else false.
329      */

330     public boolean
331     isReadonly()
332     {
333         return mode_ == AttributeMode.ATTR_READONLY;
334     }
335
336     /**
337      * Obtain the get exceptions list.
338      *
339      * @return The getraises ExceptionList of the attribute declaration
340      * or null if no exceptions were declared.
341      */

342     public ExceptionList
343     getGetExceptionList()
344     {
345         return get_exceptions_;
346     }
347
348     /**
349      * Obtain the all get exception declarations.
350      *
351      * @return The getraises ExceptionList of the attribute declaration
352      * or null if no exceptions were declared.
353      */

354     public ExceptionDecl[]
355     getGetExceptions()
356     {
357         if (isNormal())
358             return get_exceptions_.getExceptions();
359         return new ExceptionDecl[0];
360     }
361
362     /**
363      * Obtain the put exceptions list.
364      *
365      * @return The setraises (or raises for readonly attributes)
366      * ExceptionList of the attribute declaration
367      * or null if no exceptions were declared.
368      */

369     public ExceptionList
370     getSetExceptionList()
371     {
372         return set_exceptions_;
373     }
374
375     /**
376      * Obtain the all put exception declarations.
377      *
378      * @return The setRaises (or raises for readonly attributes)
379      * ExceptionList of the attribute declaration or
380      * null if no exceptions were declared.
381      */

382     public ExceptionDecl[]
383     getSetExceptions()
384     {
385         if (isNormal())
386             return set_exceptions_.getExceptions();
387         return new ExceptionDecl[0];
388     }
389
390     /**
391      * Obtain all exception declarations for a read only attribute.
392      *
393      * @return The getraises ExceptionList of the attribute declaration
394      * or null if no exceptions were declared or if the attribute.
395      * is not read only.
396      */

397     public ExceptionList
398     getExceptionList()
399     {
400         if (isReadonly())
401             return get_exceptions_;
402         else
403             return new ExceptionListImpl();
404     }
405
406     /**
407      * Obtain all exception declarations for a read only attribute.
408      *
409      * @return The getraises ExceptionList of the attribute declaration
410      * or null if no exceptions were declared or if the attribute.
411      * is not read only.
412      */

413     public ExceptionDecl[]
414     getExceptions()
415     {
416         if (isReadonly())
417             return get_exceptions_.getExceptions();
418         else
419             return new ExceptionDecl[0];
420     }
421 }
422
Popular Tags