KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > ir3 > ArrayDef_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::ArrayDef 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 ArrayDef_impl
42      extends IRObject_impl
43   implements ArrayDefOperations
44 {
45     // ==================================================================
46
//
47
// Internal state.
48
//
49
// ==================================================================
50

51     /** The array length. */
52     protected int length_;
53
54     /** The array element type. */
55     protected IDLType_ref element_type_def_;
56
57     // ==================================================================
58
//
59
// Constructor.
60
//
61
// ==================================================================
62

63     /**
64      * TODO.
65      */

66     public
67     ArrayDef_impl(IFR ifr)
68     {
69         // Calls the IRObject_impl contructor.
70
super(ifr);
71
72         // Sets the TIE servant object.
73
setServant(new ArrayDefPOATie(this));
74
75         // Sets the length to zero.
76
length_ = 0;
77
78         // Sets the element_type_def to null.
79
element_type_def_ = new IDLType_ref(this);
80     }
81
82     // ==================================================================
83
//
84
// Internal methods inherited from IROject_impl.
85
//
86
// ==================================================================
87

88     /**
89      * Warning : this operation must be implemented by subclasses.
90      * It allows us to avoid some casts while creating ::CORBA::TypeCode
91      */

92     protected TypeCode
93     recursiveType(java.util.List JavaDoc idSeq)
94     {
95         TypeCode tc = null;
96         try
97         {
98             Contained_impl cont = (Contained_impl)element_type_def_.getBaseImpl();
99             int idx = idSeq.indexOf(cont.id());
100             if (idx!=-1)
101             {
102                 // check if the contained can be a recursive type
103
// only valuetypes can be recursive in an array
104
// also unwound alias to original type to do the check
105
int dk = cont.def_kind().value();
106                 if (dk==DefinitionKind._dk_Alias)
107                 {
108                     AliasDef_impl alias = (AliasDef_impl)cont;
109                     IDLType type = alias.original_type_def();
110                     dk = type.def_kind().value();
111                     AliasDef alias_def = null;
112                     while (dk==DefinitionKind._dk_Alias)
113                     {
114                         alias_def = AliasDefHelper.narrow(type);
115                         type = alias_def.original_type_def();
116                         dk = type.def_kind().value();
117                     }
118                 }
119
120                 if (dk!=DefinitionKind._dk_Value)
121                     throw exceptionIllegalRecursion("array", cont.id());
122
123                 tc = getIFR().getTCF().create_recursive_tc(cont.id());
124             }
125         }
126         catch (java.lang.ClassCastException JavaDoc ex)
127         {
128         }
129
130         if (tc==null)
131             tc = element_type_def_.recursiveType(idSeq);
132
133         // delegation to the TypeCodeFactory.
134
return getIFR().getTCF().create_array_tc(length(), tc);
135     }
136
137     // ==================================================================
138
//
139
// Internal methods.
140
//
141
// ==================================================================
142

143     /**
144      * Obtain its CORBA::ArrayDef object reference.
145      */

146     public ArrayDef
147     asArrayDef()
148     {
149         return ArrayDefHelper.narrow(asObject());
150     }
151
152     // ==================================================================
153
//
154
// Internal methods for managing dependencies.
155
//
156
// ==================================================================
157

158     /**
159      * Cuts dependencies to other objects.
160      */

161     protected void
162     cutDependencies()
163     {
164         // Cuts the dependency.
165
element_type_def_.cutDependency();
166
167         // Calls the IRObject_impl::cutDependencies method.
168
super.cutDependencies();
169     }
170
171     // ==================================================================
172
//
173
// For CORBA::IRObject interface.
174
//
175
// ==================================================================
176

177     /**
178      * IDL:omg.org/CORBA/IRObject/def_kind:1.0
179      */

180     public DefinitionKind
181     def_kind()
182     {
183         return DefinitionKind.dk_Array;
184     }
185
186     // ==================================================================
187
//
188
// For CORBA::IDLType interface.
189
//
190
// ==================================================================
191

192     /**
193      * IDL:omg.org/CORBA/IDLType/type:1.0
194      */

195     public TypeCode
196     type()
197     {
198         // check for recursion.
199
java.util.List JavaDoc idSeq = new java.util.ArrayList JavaDoc();
200         return recursiveType(idSeq);
201     }
202
203     // ==================================================================
204
//
205
// For CORBA::ArrayDef interface.
206
//
207
// ==================================================================
208

209     /**
210      * IDL:omg.org/CORBA/ArrayDef/length:1.0
211      */

212     public int
213     length()
214     {
215         return length_;
216     }
217
218     /**
219      * IDL:omg.org/CORBA/ArrayDef/length:1.0
220      */

221     public void
222     length(int val)
223     {
224         length_ = val;
225     }
226
227     /**
228      * IDL:omg.org/CORBA/ArrayDef/element_type:1.0
229      */

230     public TypeCode
231     element_type()
232     {
233         // delegate to the IDLType reference.
234
return element_type_def_.recursiveType();
235     }
236
237     /**
238      * IDL:omg.org/CORBA/ArrayDef/element_type_def:1.0
239      */

240     public IDLType
241     element_type_def()
242     {
243         // delegate to the IDLType reference.
244
return element_type_def_.asIDLType();
245     }
246
247     /**
248      * IDL:omg.org/CORBA/ArrayDef/element_type_def:1.0
249      */

250     public void
251     element_type_def(IDLType val)
252     {
253         // try to cast val to a local object
254
// and delegate to the IDLType reference.
255
element_type_def_.setDependency( castToLocal(val) );
256     }
257 }
258
Popular Tags