KickJava   Java API By Example, From Geeks To Geeks.

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


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 IDL constant declarations.
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 ConstantDeclImpl
39        extends AnyValueDeclImpl
40        implements ConstantDecl
41 {
42     // ==================================================================
43
//
44
// Internal state.
45
//
46
// ==================================================================
47

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

51     private org.omg.CORBA.ConstantDef JavaDoc constant_def_;
52
53     /**
54      ** The type of the constant.
55      **/

56     private TypeRef type_;
57
58     // ==================================================================
59
//
60
// Constructor.
61
//
62
// ==================================================================
63

64     /**
65      ** The constructor with the parent scope.
66      **
67      ** @param parent The parent scope of the declaration.
68      **/

69     protected
70     ConstantDeclImpl(Repository rep, ScopeImpl parent)
71     {
72         // Call the AnyValueDeclImpl constructor.
73
super(rep, parent);
74
75         // Init internal state.
76
constant_def_ = null;
77         type_ = null;
78         the_declaration_kind_ = DeclarationKind._dk_constant;
79     }
80
81     // ==================================================================
82
//
83
// Internal methods.
84
//
85
// ==================================================================
86

87     /**
88      ** Loads infos of the CORBA 3.0 ConstantDef.
89      **
90      ** @param constant_def The ConstantDef to load.
91      **/

92     protected void
93     load(org.omg.CORBA.Contained JavaDoc contained)
94     {
95         constant_def_ = org.omg.CORBA.ConstantDefHelper.narrow(contained);
96         setType(getRepository().getAsTypeRef(constant_def_.type_def()));
97         AnyValue any = new AnyValue();
98         any.loadAny(constant_def_.value());
99         setAnyValue(any);
100
101         super.load(contained);
102     }
103
104     /**
105      ** Loads infos of the CORBA 3.0 ConstantDef.
106      **
107      ** @param constant_def The ConstantDef to load.
108      **/

109     protected void
110     loadAsMapping(org.omg.CORBA.Contained JavaDoc contained)
111     {
112         constant_def_ = org.omg.CORBA.ConstantDefHelper.narrow(contained);
113         setType(getRepository().getAsMappedTypeRef(constant_def_.type_def()));
114         AnyValue any = new AnyValue();
115         any.loadAny(constant_def_.value());
116         setAnyValue(any);
117
118         super.loadAsMapping(contained);
119     }
120
121     // ==================================================================
122
//
123
// Methods for the Declaration interface.
124
//
125
// ==================================================================
126

127     /**
128      ** Create the constant declaration into the IFR.
129      **/

130     public void
131     create()
132     {
133         constant_def_ = the_parent_.getContainer().create_constant(getId(),
134                                                                    getName(),
135                                                                    getVersion(),
136                                                                    type_.getIDLType(),
137                                                                    getAnyValue().computeAny(type_.getIDLType().type()));
138
139         super.create();
140     }
141
142     /**
143      ** Obtain the declaration external dependencies.
144      ** Note: for scopes, contained objects are not considered
145      ** as dependencies.
146      **
147      ** @return The list of dependencies as an array of Declaration.
148      **/

149     public Declaration[]
150     getDependencies()
151     {
152         if (dependencies_!=null)
153             return dependencies_;
154
155         org.objectweb.ccm.util.Vector constant_depend = new org.objectweb.ccm.util.Vector();
156
157         // constant type
158
if (getType().isDeclaration())
159             constant_depend.add(getType());
160
161         Declaration[] depend = getType().getDependencies();
162         for (int i=0;i<depend.length;i++)
163             constant_depend.add(depend[i]);
164
165         dependencies_ = (Declaration[])constant_depend.toArray(new Declaration[0]);
166         return dependencies_;
167     }
168
169
170     // ==================================================================
171
//
172
// Methods for the ConstantDecl interface.
173
//
174
// ==================================================================
175

176     /**
177      ** Set the type.
178      **
179      ** @param type The TypeRef of the constant declaration type.
180      **/

181     public void
182     setType(TypeRef type)
183     {
184         if(type != null)
185         {
186             type_ = type;
187             type_.addRef();
188         }
189     }
190
191     /**
192      **
193      **/

194     public TypeRef
195     getType()
196     {
197         return type_;
198     }
199
200     // ==================================================================
201
//
202
// Methods for the inherited DeclarationImpl class.
203
//
204
// ==================================================================
205

206     /**
207      **
208      **/

209     public void
210     destroy()
211     {
212         if (type_!=null)
213             type_.removeRef();
214
215         super.destroy();
216     }
217
218     /**
219      ** Obtain its CORBA 3.0 Contained reference.
220      **
221      ** @return The Contained object associated with the constant declaration.
222      **/

223     protected org.omg.CORBA.Contained JavaDoc
224     getContained()
225     {
226         return constant_def_;
227     }
228 }
229
Popular Tags