KickJava   Java API By Example, From Geeks To Geeks.

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


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 /** Used to access AST AnyValue. */
30 import org.objectweb.openccm.ast.api.AnyValue;
31
32 /** Used to access AST DeclarationKind. */
33 import org.objectweb.openccm.ast.api.DeclarationKind;
34
35 /** Used to access AST Declaration. */
36 import org.objectweb.openccm.ast.api.Declaration;
37
38 /** To use CORBA::ConstantDef. */
39 import org.omg.CORBA.ConstantDef JavaDoc;
40 import org.omg.CORBA.ConstantDefHelper;
41
42 /**
43  * ConstantDeclImpl is a wrapper class for IDL constant declarations.
44  *
45  * Inherits from:
46  * - DeclarationWithTypeRefImpl as constants are IDL declarations
47  * and have an associated type,
48  * - WithAnyValue as constants have an associated any value.
49  *
50  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
51  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
52  *
53  * @version 0.3
54  */

55
56 public class ConstantDeclImpl
57        extends DeclarationWithTypeRefImpl
58        implements org.objectweb.openccm.ast.api.ConstantDecl
59 {
60     // ==================================================================
61
//
62
// Internal state.
63
//
64
// ==================================================================
65

66     /** Reference to the CORBA 3.0 ConstantDef. */
67     private ConstantDef JavaDoc constant_def_;
68
69     /** Reference to the AnyValue constant. */
70     private AnyValueImpl any_;
71
72     // ==================================================================
73
//
74
// Constructor.
75
//
76
// ==================================================================
77

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

84     protected
85     ConstantDeclImpl(Repository rep,
86                      ScopeImpl parent)
87     {
88         // Call the DeclarationWithTypeRefImpl constructor.
89
super(rep, parent);
90
91         // Init internal state.
92
constant_def_ = null;
93         any_ = new AnyValueImpl();
94     }
95
96     // ==================================================================
97
//
98
// Internal methods.
99
//
100
// ==================================================================
101

102     // ==================================================================
103
//
104
// Internal methods for DeclarationImpl.
105
//
106
// ==================================================================
107

108     /**
109      * Loads infos of the CORBA 3.0 ConstantDef.
110      *
111      * @param contained The ConstantDef to load.
112      */

113     protected void
114     load(org.omg.CORBA.Contained JavaDoc contained)
115     {
116         constant_def_ = ConstantDefHelper.narrow(contained);
117         setType(getRepository().getAsTypeRef(constant_def_.type_def()));
118         any_ = new AnyValueImpl();
119         any_.loadAny(constant_def_.value());
120
121         super.load(contained);
122     }
123
124     /**
125      * Loads infos of the CORBA 3.0 ConstantDef.
126      *
127      * @param contained The ConstantDef to load.
128      */

129     protected void
130     loadAsMapping(org.omg.CORBA.Contained JavaDoc contained)
131     {
132         constant_def_ = ConstantDefHelper.narrow(contained);
133         setType(getRepository().getAsMappedTypeRef(constant_def_.type_def()));
134         any_ = new AnyValueImpl();
135         any_.loadAny(constant_def_.value());
136
137         super.loadAsMapping(contained);
138     }
139
140     /**
141      * Obtain its CORBA 3.0 Contained reference.
142      *
143      * @return The Contained object associated with the constant declaration.
144      */

145     protected org.omg.CORBA.Contained JavaDoc
146     getContained()
147     {
148         return constant_def_;
149     }
150
151     // ==================================================================
152
//
153
// Public methods.
154
//
155
// ==================================================================
156

157     // ==================================================================
158
//
159
// Methods for OMG IDL org.objectweb.openccm.ast.api.WithDependencies
160
//
161
// ==================================================================
162

163     /**
164      * Obtain the declaration external dependencies.
165      *
166      * Note: for scopes, contained objects are not considered
167      * as dependencies.
168      *
169      * @return The list of dependencies as an array of Declaration.
170      */

171     public Declaration[]
172     getDependencies()
173     {
174         if (dependencies_!=null)
175             return dependencies_;
176
177         java.util.List JavaDoc constant_depend = new java.util.ArrayList JavaDoc();
178
179         // constant type
180
if (getType().isDeclaration())
181             constant_depend.add(getType());
182
183         Declaration[] depend = getType().getDependencies();
184         for (int i=0;i<depend.length;i++)
185             constant_depend.add(depend[i]);
186
187         dependencies_ = (Declaration[])constant_depend.toArray(
188                                                      new Declaration[0]);
189         return dependencies_;
190     }
191
192     // ==================================================================
193
//
194
// Methods for OMG IDL org.objectweb.openccm.ast.api.Declaration
195
//
196
// ==================================================================
197

198     /**
199      * Obtain its DeclarationKind.
200      *
201      * @return The DeclarationKind of the object.
202      */

203     public long
204     getDeclKind()
205     {
206         return DeclarationKind.dk_constant;
207     }
208
209     /**
210      * Create the constant declaration into the IFR.
211      */

212     public void
213     create()
214     {
215         constant_def_ = the_parent_.getContainer().
216                         create_constant(getId(), getName(), getVersion(),
217                                         getIDLType(),
218                                         any_.computeAny(getIDLType().type()));
219
220         super.create();
221     }
222
223     // ==================================================================
224
//
225
// Methods for OMG IDL org.objectweb.openccm.ast.api.WithAnyValue
226
//
227
// ==================================================================
228

229     /**
230      * Set the associated AnyValue.
231      *
232      * @param value The AnyValue to set.
233      */

234     public void
235     setAnyValue(AnyValue value)
236     {
237       any_ = (AnyValueImpl)value;
238     }
239
240     /**
241      * Obtain the associated AnyValue.
242      *
243      * @return The associated AnyValue.
244      */

245     public AnyValue
246     getAnyValue()
247     {
248       return any_;
249     }
250
251     // ==================================================================
252
//
253
// Methods for OMG IDL org.objectweb.openccm.ast.api.ConstantDecl
254
//
255
// ==================================================================
256

257 }
258
Popular Tags