KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > ir3 > ConstantDef_impl


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): Mathieu Vadet, Christophe Demarey.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.ir3;
28
29 // Package dependencies
30
import org.omg.CORBA.*;
31
32 /**
33  * Implementation of the CORBA::ConstantDef interface.
34  *
35  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
36  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
37  *
38  * @version 0.5
39  */

40
41 public class ConstantDef_impl
42      extends Contained_impl
43   implements ConstantDefOperations
44 {
45     // ==================================================================
46
//
47
// Internal state.
48
//
49
// ==================================================================
50

51     /** The type of the constant. */
52     protected IDLType_ref type_def_;
53
54     /** The value of the constant. */
55     protected Any value_;
56
57     // ==================================================================
58
//
59
// Constructor.
60
//
61
// ==================================================================
62

63     /**
64      * TODO.
65      */

66     public
67     ConstantDef_impl(IFR ifr,
68                      Container_impl container)
69     {
70         // Calls the Contained_impl contructor.
71
super(ifr, container);
72
73     // Sets the tie servant object.
74
setServant(new ConstantDefPOATie(this));
75
76         // Creates the type_def reference.
77
type_def_ = new IDLType_ref(this);
78
79         // null value.
80
value_ = null;
81     }
82
83     // ==================================================================
84
//
85
// Public methods.
86
//
87
// ==================================================================
88

89     /**
90      * Obtain its CORBA::ConstantDef object reference.
91      */

92     public ConstantDef
93     asConstantDef()
94     {
95         return ConstantDefHelper.narrow(asObject());
96     }
97
98     // ==================================================================
99
//
100
// For Contained_impl class.
101
//
102
// ==================================================================
103

104     /**
105      * To set the value field of the CORBA::Contained::Description struct.
106      */

107     public void
108     setDescriptionValue(Any any)
109     {
110         // create the CORBA::ConstantDescription.
111
ConstantDescription description = new ConstantDescription();
112         description.name = name();
113         description.id = id();
114         description.defined_in = getContainerID();
115         description.version = version();
116         description.type = type();
117         description.value = value();
118
119         // insert it into the any.
120
ConstantDescriptionHelper.insert(any, description);
121     }
122
123     // ==================================================================
124
//
125
// Internal methods for managing dependencies.
126
//
127
// ==================================================================
128

129     /**
130      * Cuts dependencies to other objects.
131      */

132     protected void
133     cutDependencies()
134     {
135         // Cuts the dependency.
136
type_def_.cutDependency();
137
138         value_ = null;
139
140         // Calls the Container_impl::cutDependencies operation.
141
super.cutDependencies();
142     }
143
144     // ==================================================================
145
//
146
// For CORBA::IRObject interface.
147
//
148
// ==================================================================
149

150     /**
151      * IDL:omg.org/CORBA/IRObject/def_kind:1.0
152      */

153     public DefinitionKind
154     def_kind()
155     {
156         return DefinitionKind.dk_Constant;
157     }
158
159     // ==================================================================
160
//
161
// For CORBA::Container interface.
162
//
163
// ==================================================================
164

165     /**
166      * IDL:omg.org/CORBA/ConstantDef/type:1.0
167      */

168     public TypeCode
169     type()
170     {
171         // delegate to the IDLType reference.
172
return type_def_.recursiveType();
173     }
174
175     /**
176      * IDL:omg.org/CORBA/ConstantDef/type_def:1.0
177      */

178     public IDLType
179     type_def()
180     {
181         // delegate to the IDLType reference.
182
return type_def_.asIDLType();
183     }
184
185     /**
186      * IDL:omg.org/CORBA/ConstantDef/type_def:1.0
187      */

188     public void
189     type_def(IDLType val)
190     {
191         // try to cast val to a local object
192
// and delegate to the IDLType reference.
193
type_def_.setDependency( castToLocal(val) );
194     }
195
196     /**
197      * IDL:omg.org/CORBA/ConstantDef/value:1.0
198      */

199     public Any
200     value()
201     {
202         if (value_ == null)
203             throw exceptionBadInvOrder("IDL:omg.org/CORBA/ConstantDef/value:1.0");
204
205         return value_;
206     }
207
208     /**
209      * IDL:omg.org/CORBA/ConstantDef/value:1.0
210      */

211     public void
212     value(Any val)
213     {
214     // The following line does not work on OpenORB!!!
215
// if (!val.type().equal(type()))
216
if (!val.type().equivalent(type()))
217     //
218
throw exceptionBadParam("IDL:omg.org/CORBA/ConstantDef/value:1.0");
219
220         value_ = val;
221     }
222 }
223
Popular Tags