KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > ir3 > AttributeDef_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::AttributeDef 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 AttributeDef_impl
42      extends FeatureContained
43   implements AttributeDefOperations
44 {
45     // ==================================================================
46
//
47
// Internal state.
48
//
49
// ==================================================================
50

51     /** The type of the attribute. */
52     protected IDLType_ref type_def_;
53
54     /** The mode of the attribute. */
55     protected AttributeMode mode_;
56
57     // ==================================================================
58
//
59
// Constructor.
60
//
61
// ==================================================================
62

63     /**
64      * TODO.
65      */

66     public
67     AttributeDef_impl(IFR ifr,
68                       Container_impl container)
69     {
70         // Calls the FeatureContained contructor.
71
super(ifr, container);
72
73         // Sets the tie servant object.
74
setServant(new AttributeDefPOATie(this));
75
76         // Creates the type_def reference.
77
type_def_ = new IDLType_ref(this);
78
79         // Inits internal state.
80
mode_ = AttributeMode.ATTR_NORMAL;
81     }
82
83     // ==================================================================
84
//
85
// Public methods.
86
//
87
// ==================================================================
88

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

92     public AttributeDef
93     asAttributeDef()
94     {
95         return AttributeDefHelper.narrow(asObject());
96     }
97
98     /**
99      * Obtain its CORBA::AttributeDescription.
100      */

101     public AttributeDescription
102     getAttributeDescription()
103     {
104         // create the CORBA::AttributeDescription.
105
AttributeDescription description = new AttributeDescription();
106
107         // set its fields.
108
description.name = name();
109         description.id = id();
110         description.defined_in = getContainerID();
111         description.version = version();
112         description.type = type();
113         description.mode = mode();
114
115         return description;
116     }
117
118     // ==================================================================
119
//
120
// For Contained_impl class.
121
//
122
// ==================================================================
123

124     /**
125      * To set the value field of the CORBA::Contained::Description struct.
126      */

127     public void
128     setDescriptionValue(Any any)
129     {
130         // insert its CORBA::AttributeDescription into the any.
131
AttributeDescriptionHelper.insert(any, getAttributeDescription());
132     }
133
134     // ==================================================================
135
//
136
// Internal methods for managing dependencies.
137
//
138
// ==================================================================
139

140     /**
141      * Cuts dependencies to other objects.
142      */

143     protected void
144     cutDependencies()
145     {
146         // Cuts the dependency.
147
type_def_.cutDependency();
148
149         mode_ = null;
150
151         // Calls the Container_impl::cutDependencies operation.
152
super.cutDependencies();
153     }
154
155     // ==================================================================
156
//
157
// For CORBA::IRObject interface.
158
//
159
// ==================================================================
160

161     /**
162      * IDL:omg.org/CORBA/IRObject/def_kind:1.0
163      */

164     public DefinitionKind
165     def_kind()
166     {
167         return DefinitionKind.dk_Attribute;
168     }
169
170     // ==================================================================
171
//
172
// For CORBA::AttributeDef interface.
173
//
174
// ==================================================================
175

176     /**
177      * IDL:omg.org/CORBA/AttributeDef/type:1.0
178      */

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

189     public IDLType
190     type_def()
191     {
192         // delegate to the IDLType reference.
193
return type_def_.asIDLType();
194     }
195
196     /**
197      * IDL:omg.org/CORBA/AttributeDef/type_def:1.0
198      */

199     public void
200     type_def(IDLType val)
201     {
202         // try to cast val to a local object
203
// and delegate to the IDLType reference.
204
type_def_.setDependency( castToLocal(val) );
205     }
206
207     /**
208      * IDL:omg.org/CORBA/AttributeDef/mode:1.0
209      */

210     public AttributeMode
211     mode()
212     {
213         return mode_;
214     }
215
216     /**
217      * IDL:omg.org/CORBA/AttributeDef/mode:1.0
218      */

219     public void
220     mode(AttributeMode val)
221     {
222         mode_ = val;
223     }
224
225     // ==================================================================
226
//
227
// For IDL2 mapping.
228
//
229
// ==================================================================
230

231     /**
232      * TODO
233      */

234     protected void
235     whenCreated()
236     {
237         // do nothing if mappings are not enabled.
238
if (!getIFR().getRepository().enable_mappings_)
239             return ;
240
241         // check the container kind
242
if ((container_.def_kind().value()!=org.omg.CORBA.DefinitionKind._dk_Home) &&
243             (container_.def_kind().value()!=org.omg.CORBA.DefinitionKind._dk_Component))
244             return ;
245
246         // else create the mapping according to the CCM spec
247

248         // for homes
249
if (container_.def_kind().value()==org.omg.CORBA.DefinitionKind._dk_Home)
250         {
251             //
252
// copy the attribute in the home explicit interface
253
//
254
ExtInterfaceDef_impl explicit = (ExtInterfaceDef_impl)((HomeDef_impl)container_).base_interfaces_[0].getImpl();
255             String JavaDoc explicit_base_id = explicit.getBaseID();
256             String JavaDoc id = explicit_base_id + name() + ":" + version();
257
258             container_.mapping_started_ = true;
259             explicit.create_ext_attribute(id, name(), version(), type_def(), mode(),
260                                           new org.omg.CORBA.ExceptionDef JavaDoc[0],
261                                           new org.omg.CORBA.ExceptionDef JavaDoc[0]);
262             container_.mapping_started_ = false;
263
264         //
265
// CIDL mapping
266
//
267
//
268
// copy the attribute in the home explicit executor interface
269
//
270
String JavaDoc cont_base_id = container_.getBaseContainerID();
271             String JavaDoc explicit_exe_id = cont_base_id + "CCM_" + container_.name() + "Explicit:" + container_.version();
272             org.omg.CORBA.ExtLocalInterfaceDef explicit_exe = org.omg.CORBA.ExtLocalInterfaceDefHelper.narrow(
273                 getIFR().getRepository().lookup_mapped_id(explicit_exe_id));
274
275             id = cont_base_id + "CCM_" + container_.name() + "Explicit/" + name() + ":" + version();
276             explicit_exe.create_ext_attribute(id, name(), version(), type_def(), mode(),
277                                               new org.omg.CORBA.ExceptionDef JavaDoc[0],
278                                               new org.omg.CORBA.ExceptionDef JavaDoc[0]);
279
280         }
281         // for components
282
else if (container_.def_kind().value()==org.omg.CORBA.DefinitionKind._dk_Component)
283         {
284             //
285
// copy the attribute in the component main local interface executor
286
//
287
String JavaDoc cont_base_id = container_.getBaseContainerID();
288             // for main executor
289
String JavaDoc litf_id = cont_base_id + "CCM_" + container_.name() + "_Executor:" + container_.version();
290             org.omg.CORBA.ExtLocalInterfaceDef litf = org.omg.CORBA.ExtLocalInterfaceDefHelper.narrow(
291                  getIFR().getRepository().lookup_mapped_id(litf_id));
292
293             String JavaDoc id = cont_base_id + "CCM_" + container_.name() + "_Executor/" + name() + ":" + version();
294             litf.create_ext_attribute(id,
295                                       name(),
296                                       version(),
297                                       type_def(),
298                                       mode(),
299                                       new org.omg.CORBA.ExceptionDef JavaDoc[0],
300                                       new org.omg.CORBA.ExceptionDef JavaDoc[0]);
301         }
302     }
303 }
304
Popular Tags