KickJava   Java API By Example, From Geeks To Geeks.

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

51     /** The exceptions when getting the attribute. */
52     protected ExceptionDef_ref[] get_exceptions_;
53
54     /** The exceptions when setting the attribute. */
55     protected ExceptionDef_ref[] set_exceptions_;
56
57     // ==================================================================
58
//
59
// Constructor.
60
//
61
// ==================================================================
62

63     /**
64      * TODO.
65      */

66     public
67     ExtAttributeDef_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 ExtAttributeDefPOATie(this));
75
76         // Inits internal state.
77
get_exceptions_ = null;
78         set_exceptions_ = null;
79     }
80
81     // ==================================================================
82
//
83
// Public methods.
84
//
85
// ==================================================================
86

87     /**
88      * Obtain its CORBA::ExtAttributeDef object reference.
89      */

90     public ExtAttributeDef
91     asExtAttributeDef()
92     {
93         return ExtAttributeDefHelper.narrow(asObject());
94     }
95
96     /**
97      * Obtain its CORBA::ExtAttributeDescription.
98      */

99     public ExtAttributeDescription
100     getExtAttributeDescription()
101     {
102         // create the CORBA::ExtAttributeDescription.
103
ExtAttributeDescription description = new ExtAttributeDescription();
104
105         // set its fields.
106
description.name = name();
107         description.id = id();
108         description.defined_in = getContainerID();
109         description.version = version();
110         description.type = type();
111         description.mode = mode();
112         description.get_exceptions =
113             ExceptionDef_impl.compute_ExcDescriptionSeq(get_exceptions_);
114         description.set_exceptions =
115             ExceptionDef_impl.compute_ExcDescriptionSeq(set_exceptions_);
116
117         return description;
118     }
119
120     // ==================================================================
121
//
122
// For Contained_impl class.
123
//
124
// ==================================================================
125

126     /**
127      * To set the value field of the CORBA::Contained::Description struct.
128      */

129     public void
130     setDescriptionValue(Any any)
131     {
132         // insert its CORBA::ExtAttributeDescription into the any.
133
ExtAttributeDescriptionHelper.insert(any, getExtAttributeDescription());
134     }
135
136     // ==================================================================
137
//
138
// Internal methods for managing dependencies.
139
//
140
// ==================================================================
141

142     /**
143      * Cuts dependencies to other objects.
144      */

145     protected void
146     cutDependencies()
147     {
148         // Cuts the dependency.
149
type_def_.cutDependency();
150
151         mode_ = null;
152
153         // Cuts the previous dependency to get exceptions.
154
ExceptionDef_ref.cutDependencies(get_exceptions_);
155         get_exceptions_ = null;
156
157         // Cuts the previous dependency to put exceptions.
158
ExceptionDef_ref.cutDependencies(set_exceptions_);
159         set_exceptions_ = null;
160
161         // Calls the Contained_impl::cutDependencies operation.
162
super.cutDependencies();
163     }
164
165     // ==================================================================
166
//
167
// For CORBA::IRObject interface.
168
//
169
// ==================================================================
170

171     // ==================================================================
172
//
173
// For CORBA::ExtAttributeDef interface.
174
//
175
// ==================================================================
176

177     /**
178      * IDL:omg.org/CORBA/ExtAttributeDef/get_exceptions:1.0
179      */

180     public ExceptionDef[]
181     get_exceptions()
182     {
183         ExceptionDef[] result = new ExceptionDef[get_exceptions_.length];
184
185         for(int i=0; i<get_exceptions_.length; i++)
186              result[i] = get_exceptions_[i].asExceptionDef();
187
188         return result;
189     }
190
191     /**
192      * IDL:omg.org/CORBA/ExtAttributeDef/get_exceptions:1.0
193      */

194     public void
195     get_exceptions(ExceptionDef[] val)
196     {
197         ExceptionDef_impl[] exceptions = new ExceptionDef_impl[val.length];
198         for (int i=0; i<val.length; i++)
199             exceptions[i] = castToLocal(val[i]);
200
201         // TODO: check unicity
202

203         ExceptionDef_ref[] refs = new ExceptionDef_ref[val.length];
204         for (int i=0; i<val.length; i++)
205             refs[i] = new ExceptionDef_ref( this, exceptions[i] );
206
207         // cut the previous dependency to get exceptions.
208
ExceptionDef_ref.cutDependencies(get_exceptions_);
209
210         get_exceptions_ = refs;
211     }
212
213     /**
214      * IDL:omg.org/CORBA/ExtAttributeDef/set_exceptions:1.0
215      */

216     public ExceptionDef[]
217     set_exceptions()
218     {
219         ExceptionDef[] result = new ExceptionDef[set_exceptions_.length];
220
221         for(int i=0; i<set_exceptions_.length; i++)
222              result[i] = set_exceptions_[i].asExceptionDef();
223
224         return result;
225     }
226
227     /**
228      * IDL:omg.org/CORBA/ExtAttributeDef/set_exceptions:1.0
229      */

230     public void
231     set_exceptions(ExceptionDef[] val)
232     {
233         ExceptionDef_impl[] exceptions = new ExceptionDef_impl[val.length];
234         for (int i=0; i<val.length; i++)
235             exceptions[i] = castToLocal(val[i]);
236
237         // TODO: check unicity
238

239         ExceptionDef_ref[] refs = new ExceptionDef_ref[val.length];
240         for (int i=0; i<val.length; i++)
241             refs[i] = new ExceptionDef_ref( this, exceptions[i] );
242
243         // cut the previous dependency to put exceptions.
244
ExceptionDef_ref.cutDependencies(set_exceptions_);
245
246         set_exceptions_ = refs;
247     }
248
249     /**
250      * IDL:omg.org/CORBA/ExtAttributeDef/describe:1.0
251      */

252     public org.omg.CORBA.ExtAttributeDescription
253     describe_attribute()
254     {
255         return getExtAttributeDescription();
256     }
257
258     // ==================================================================
259
//
260
// For IDL2 mapping.
261
//
262
// ==================================================================
263

264     /**
265      * TODO
266      */

267     protected void
268     whenCreated()
269     {
270         // do nothing if mappings are not enabled.
271
if (!getIFR().getRepository().enable_mappings_)
272             return ;
273
274         // check the container kind
275
if ((container_.def_kind().value()!=org.omg.CORBA.DefinitionKind._dk_Home) &&
276             (container_.def_kind().value()!=org.omg.CORBA.DefinitionKind._dk_Component))
277             return ;
278
279         // else create the mapping according to the CCM spec
280

281         // for homes
282
if (container_.def_kind().value()==org.omg.CORBA.DefinitionKind._dk_Home)
283         {
284             //
285
// copy the attribute in the home explicit interface
286
//
287
ExtInterfaceDef_impl explicit = (ExtInterfaceDef_impl)((HomeDef_impl)container_).base_interfaces_[0].getImpl();
288             String JavaDoc explicit_base_id = explicit.getBaseContainerID();
289             String JavaDoc id = explicit_base_id + name() + ":" + version();
290
291             container_.mapping_started_ = true;
292             explicit.create_ext_attribute(id, name(), version(), type_def(), mode(),
293                                           get_exceptions(), set_exceptions());
294             container_.mapping_started_ = false;
295
296         //
297
// CIDL mapping
298
//
299
//
300
// copy the attribute in the home explicit executor local interface
301
//
302
String JavaDoc cont_base_id = container_.getBaseContainerID();
303             String JavaDoc explicit_exe_id = cont_base_id + "CCM_" + container_.name() + "Explicit:" + container_.version();
304             org.omg.CORBA.ExtLocalInterfaceDef explicit_exe = org.omg.CORBA.ExtLocalInterfaceDefHelper.narrow(
305                 getIFR().getRepository().lookup_mapped_id(explicit_exe_id));
306
307             id = cont_base_id + "CCM_" + container_.name() + "Explicit/" + name() + ":" + version();
308             explicit_exe.create_ext_attribute(id, name(), version(), type_def(), mode(),
309                                               get_exceptions(), set_exceptions());
310
311         }
312         // for components
313
else if (container_.def_kind().value()==org.omg.CORBA.DefinitionKind._dk_Component)
314         {
315             //
316
// copy the attribute in the component main local interface executor
317
//
318
String JavaDoc cont_base_id = container_.getBaseContainerID();
319             // for main executor
320
String JavaDoc litf_id = cont_base_id + "CCM_" + container_.name() + "_Executor:" + container_.version();
321             org.omg.CORBA.ExtLocalInterfaceDef litf = org.omg.CORBA.ExtLocalInterfaceDefHelper.narrow(
322                  getIFR().getRepository().lookup_mapped_id(litf_id));
323
324             String JavaDoc id = cont_base_id + "CCM_" + container_.name() + "_Executor/" + name() + ":" + version();
325             litf.create_ext_attribute(id,
326                                       name(),
327                                       version(),
328                                       type_def(),
329                                       mode(),
330                                       get_exceptions(),
331                                       set_exceptions());
332         }
333     }
334 }
335
Popular Tags