KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > IDL3 > AttributeDeclImpl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm-team@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): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.ccm.IDL3;
28
29 /**
30  * This class manages the Attribute declarationn.
31  *
32  * @author <a=href="Philippe.Merle@lifl.fr">Philippe Merle</a>
33  * <a=href="Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
34  *
35  * @version 0.3
36  */

37
38 public class AttributeDeclImpl
39        extends DeclarationImpl
40        implements AttributeDecl
41 {
42     // ==================================================================
43
//
44
// Internal state.
45
//
46
// ==================================================================
47

48     /**
49      ** Reference to the CORBA 3.0 AttributeDef.
50      **/

51     private org.omg.CORBA.ExtAttributeDef ext_attribute_def_;
52
53     /**
54      ** The attribute mode.
55      **/

56     private int mode_;
57
58     /**
59      ** The attribute type.
60      **/

61     private TypeRef type_;
62
63     /**
64      ** The attribute get exceptions.
65      **/

66     private ExceptionListImpl get_exceptions_;
67
68     /**
69      ** The attribute put exceptions.
70      **/

71     private ExceptionListImpl set_exceptions_;
72
73     // ==================================================================
74
//
75
// Constructor.
76
//
77
// ==================================================================
78

79     /**
80      ** The constructor with the parent scope.
81      **
82      ** @param parent The parent scope of the declaration.
83      **/

84     protected
85     AttributeDeclImpl(Repository rep, ScopeImpl parent)
86     {
87         // Call the DeclarationImpl constructor.
88
super(rep, parent);
89
90         // Init internal state.
91
ext_attribute_def_ = null;
92         mode_ = AttributeDecl.ATTR_NORMAL;
93         type_ = null;
94         get_exceptions_ = new ExceptionListImpl();
95         set_exceptions_ = new ExceptionListImpl();
96         the_declaration_kind_ = DeclarationKind._dk_attribute;
97     }
98
99     // ==================================================================
100
//
101
// Internal methods.
102
//
103
// ==================================================================
104

105     /**
106      ** Loads infos of the CORBA 3.0 ModuleDef.
107      **
108      ** @param moduleDef The ModuleDef to load.
109      **/

110     protected void
111     load(org.omg.CORBA.Contained JavaDoc contained)
112     {
113         ext_attribute_def_ = org.omg.CORBA.ExtAttributeDefHelper.narrow(contained);
114         mode_ = ext_attribute_def_.mode().value();
115         setType(getRepository().getAsTypeRef(ext_attribute_def_.type_def()));
116
117         org.omg.CORBA.ExceptionDef JavaDoc[] exc = ext_attribute_def_.get_exceptions();
118         for (int i=0;i<exc.length;i++)
119             get_exceptions_.add((ExceptionRef)getRepository().lookupId(exc[i].id()));
120
121         exc = ext_attribute_def_.set_exceptions();
122         for (int i=0;i<exc.length;i++)
123             set_exceptions_.add((ExceptionRef)getRepository().lookupId(exc[i].id()));
124
125         super.load(contained);
126     }
127
128     /**
129      ** Loads infos of the CORBA 3.0 ModuleDef.
130      **
131      ** @param moduleDef The ModuleDef to load.
132      **/

133     protected void
134     loadAsMapping(org.omg.CORBA.Contained JavaDoc contained)
135     {
136         ext_attribute_def_ = org.omg.CORBA.ExtAttributeDefHelper.narrow(contained);
137         mode_ = ext_attribute_def_.mode().value();
138         setType(getRepository().getAsMappedTypeRef(ext_attribute_def_.type_def()));
139
140         org.omg.CORBA.ExceptionDef JavaDoc[] exc = ext_attribute_def_.get_exceptions();
141         for (int i=0;i<exc.length;i++)
142             get_exceptions_.add((ExceptionRef)getRepository().lookupMappedId(exc[i].id()));
143
144         exc = ext_attribute_def_.set_exceptions();
145         for (int i=0;i<exc.length;i++)
146             set_exceptions_.add((ExceptionRef)getRepository().lookupMappedId(exc[i].id()));
147
148         super.loadAsMapping(contained);
149     }
150
151     // ==================================================================
152
//
153
// Public methods for the Declaration interface.
154
//
155
// ==================================================================
156

157     /**
158      ** Create the attribute declaration into the IFR.
159      **/

160     public void
161     create()
162     {
163         ext_attribute_def_ = the_parent_.createExtAttribute(this, type_.getIDLType(),
164                                                             org.omg.CORBA.AttributeMode.from_int(mode_),
165                                                             get_exceptions_.getExceptionDefs(),
166                                                             set_exceptions_.getExceptionDefs());
167
168         super.create();
169     }
170
171     /**
172      ** Obtain the declaration external dependencies.
173      ** Note: for scopes, contained objects are not considered
174      ** as dependencies.
175      **
176      ** @return The list of dependencies as an array of Declaration.
177      **/

178     public Declaration[]
179     getDependencies()
180     {
181         if (dependencies_!=null)
182             return dependencies_;
183
184         org.objectweb.ccm.util.Vector attr_depend = new org.objectweb.ccm.util.Vector();
185         Declaration[] depend = null;
186
187         // attribute type
188
if (getType().isDeclaration())
189             attr_depend.add(getType());
190
191         depend = getType().getDependencies();
192         for (int i=0;i<depend.length;i++)
193             attr_depend.add(depend[i]);
194
195         // exceptions
196
if (isReadonly())
197             addDependencies(attr_depend, getExceptions());
198         else
199         {
200             addDependencies(attr_depend, getGetExceptions());
201             addDependencies(attr_depend, getSetExceptions());
202         }
203
204         dependencies_ = (Declaration[])attr_depend.toArray(new Declaration[0]);
205         return dependencies_;
206     }
207
208     /**
209      **
210      **/

211     protected void
212     addDependencies(org.objectweb.ccm.util.Vector attr_depend,
213                     ExceptionDecl[] excs)
214     {
215         Declaration[] depend = null;
216         for (int i=0;i<excs.length;i++)
217         {
218             attr_depend.add(excs[i]);
219             depend = excs[i].getDependencies();
220             for (int j=0;j<depend.length;j++)
221             {
222                 if (attr_depend.indexOf(depend[j])==-1)
223                     attr_depend.add(depend[j]);
224             }
225         }
226     }
227
228
229     // ==================================================================
230
//
231
// Public methods for the AttributeDecl interface.
232
//
233
// ==================================================================
234

235     /**
236      ** Set mode as normal.
237      **/

238     public void
239     setNormal()
240     {
241         mode_ = AttributeDecl.ATTR_NORMAL;
242     }
243
244     /**
245      ** Set mode as readonly.
246      **/

247     public void
248     setReadonly()
249     {
250         mode_ = AttributeDecl.ATTR_READONLY;
251     }
252
253     /**
254      ** Set the attribute type.
255      **
256      ** @param type The TypeRef of the attribute declaration.
257      **/

258     public void
259     setType(TypeRef type)
260     {
261         if(type != null)
262         {
263             type_ = type;
264             type_.addRef();
265         }
266     }
267
268     /**
269      ** Obtain the get exceptions list.
270      **
271      ** @return The getRaises ExceptionList of the attribute declaration
272      ** or null if no exceptions were declared.
273      **/

274     public ExceptionList
275     getGetExceptionList()
276     {
277         return get_exceptions_;
278     }
279
280     /**
281      ** Obtain the put exceptions list.
282      **
283      ** @return The setRaises (or raises for readonly attributes)
284      ** ExceptionList of the attribute declaration
285      ** or null if no exceptions were declared.
286      **/

287     public ExceptionList
288     getSetExceptionList()
289     {
290         return set_exceptions_;
291     }
292
293     /**
294      ** Obtain the get exceptions list.
295      **
296      ** @return The getRaises ExceptionList of the attribute declaration
297      ** or null if no exceptions were declared.
298      **/

299     public ExceptionDecl[]
300     getGetExceptions()
301     {
302         if (mode_==AttributeDecl.ATTR_NORMAL)
303             return get_exceptions_.getExceptions();
304         return new ExceptionDecl[0];
305     }
306
307     /**
308      ** Obtain the put exceptions list.
309      **
310      ** @return The setRaises (or raises for readonly attributes)
311      ** ExceptionList of the attribute declaration
312      ** or null if no exceptions were declared.
313      **/

314     public ExceptionDecl[]
315     getSetExceptions()
316     {
317         if (mode_==AttributeDecl.ATTR_NORMAL)
318             return set_exceptions_.getExceptions();
319         return new ExceptionDecl[0];
320     }
321
322     /**
323      **
324      **/

325     public ExceptionDecl[]
326     getExceptions()
327     {
328         if (mode_==AttributeDecl.ATTR_READONLY)
329             return get_exceptions_.getExceptions();
330         return new ExceptionDecl[0];
331     }
332
333     /**
334      **
335      **/

336     public boolean
337     isReadonly()
338     {
339         return mode_==AttributeDecl.ATTR_READONLY;
340     }
341
342     /**
343      **
344      **/

345     public TypeRef
346     getType()
347     {
348         return type_;
349     }
350
351     // ==================================================================
352
//
353
// Methods for the inherited DeclarationImpl class.
354
//
355
// ==================================================================
356

357     /**
358      **
359      **/

360     public void
361     destroy()
362     {
363         if (type_!=null)
364             type_.removeRef();
365
366         get_exceptions_.destroy();
367         set_exceptions_.destroy();
368         super.destroy();
369     }
370
371     /**
372      ** Obtain its CORBA 3.0 Contained reference.
373      **
374      ** @return The Contained object associated with the
375      ** attribute declaration.
376      **/

377     protected org.omg.CORBA.Contained JavaDoc
378     getContained()
379     {
380        return ext_attribute_def_;
381     }
382 }
383
Popular Tags