KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > IDL3 > TypeRefImpl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm-team@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): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.ccm.IDL3;
28
29 /**
30  * This class contains the reference to the IR3 IDLType object.
31  *
32  * @author <a=href="Philippe.Merle@lifl.fr">Philippe Merle</a>
33  * <a=href="Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
34  *
35  * @version 0.3
36  */

37
38 public class TypeRefImpl
39        implements TypeRef
40 {
41     // ==================================================================
42
//
43
// Internal state.
44
//
45
// ==================================================================
46

47     /**
48      ** Reference to the CORBA 3.0 IDLType.
49      **/

50     private org.omg.CORBA.IDLType JavaDoc type_;
51  
52     /**
53      **
54      **/

55     private int kind_;
56
57     /**
58      **
59      **/

60     private int length_;
61     private int scale_;
62     private TypeRef content_;
63
64     /**
65      **
66      **/

67     private Declaration[] dependencies_;
68
69     // ==================================================================
70
//
71
// Constructor.
72
//
73
// ==================================================================
74

75     /**
76      ** The constructor.
77      **
78      ** @param type The IDLType that should be referenced.
79      **/

80     protected
81     TypeRefImpl(org.omg.CORBA.IDLType JavaDoc type,
82                 int kind)
83     {
84         // Init internal state.
85
type_ = type;
86         kind_ = kind;
87         length_ = 0;
88         scale_ = 0;
89         content_ = null;
90         dependencies_ = null;
91     }
92
93     // ==================================================================
94
//
95
// Internal methods.
96
//
97
// ==================================================================
98

99
100     // ==================================================================
101
//
102
// Methods for the TypeRef interface.
103
//
104
// ==================================================================
105

106     /**
107      ** Obtain its IDLType reference.
108      **
109      ** @return The IDLType associated with the type reference.
110      **/

111     public org.omg.CORBA.IDLType JavaDoc
112     getIDLType()
113     {
114         return type_;
115     }
116
117     /**
118      **
119      **/

120     public void
121     addRef()
122     {
123         // nothing to do
124
}
125
126     /**
127      **
128      **/

129     public void
130     removeRef()
131     {
132         // nothing to do
133
}
134
135     /**
136      **
137      **/

138     public int
139     getTypeKind()
140     {
141         return kind_;
142     }
143
144     /**
145      ** Obtain the type external dependencies.
146      **
147      ** @return The list of dependencies as an array of Declaration.
148      **/

149     public Declaration[]
150     getDependencies()
151     {
152         if (dependencies_!=null)
153             return dependencies_;
154
155         if ((kind_!=TypeKind._tk_sequence) &&
156             (kind_!=TypeKind._tk_array))
157             dependencies_ = new Declaration[0];
158         else if (content_.isDeclaration())
159         {
160             Declaration[] depend = content_.getDependencies();
161             Declaration[] depend2 = new Declaration[1+depend.length];
162             for (int i=0;i<depend.length;i++)
163                 depend2[i] = depend[i];
164
165             depend2[depend.length] = (Declaration)content_;
166             dependencies_ = depend2;
167         }
168         else
169             dependencies_ = content_.getDependencies();
170
171         return dependencies_;
172     }
173
174     /**
175      **
176      **/

177     public boolean
178     isDeclaration()
179     {
180         return false;
181     }
182
183     // ==================================================================
184
//
185
// Public methods.
186
//
187
// ==================================================================
188

189     /**
190      **
191      **/

192     public void
193     setLength(int length)
194     {
195         length_ = length;
196     }
197
198     /**
199      **
200      **/

201     public void
202     setDigits(int digits)
203     {
204         length_ = digits;
205     }
206
207     /**
208      **
209      **/

210     public void
211     setScale(int scale)
212     {
213         scale_ = scale;
214     }
215
216     /**
217      **
218      **/

219     public void
220     setContentType(TypeRef content)
221     {
222         content_ = content;
223     }
224
225     /**
226      **
227      **/

228     public int
229     getLength()
230     {
231         if ((kind_==TypeKind._tk_string) ||
232             (kind_==TypeKind._tk_sequence) ||
233             (kind_==TypeKind._tk_array) ||
234             (kind_==TypeKind._tk_wstring))
235             return length_;
236         else
237             throw new Error JavaDoc("Bad TypeKind !");
238     }
239
240     /**
241      **
242      **/

243     public int
244     getDigits()
245     {
246         if (kind_==TypeKind._tk_fixed)
247             return length_;
248         else
249             throw new Error JavaDoc("Bad TypeKind !");
250     }
251
252     /**
253      **
254      **/

255     public int
256     getScale()
257     {
258         if (kind_==TypeKind._tk_fixed)
259             return scale_;
260         else
261             throw new Error JavaDoc("Bad TypeKind !");
262     }
263
264     /**
265      **
266      **/

267     public TypeRef
268     getContentType()
269     {
270         if ((kind_==TypeKind._tk_sequence) ||
271             (kind_==TypeKind._tk_array))
272             return content_;
273         else
274             throw new Error JavaDoc("Bad TypeKind !");
275     }
276
277     /**
278      **
279      **/

280     public String JavaDoc
281     getId()
282     {
283         if (kind_==TypeKind._tk_objref)
284             return "IDL:omg.org/CORBA/Object:1.0";
285
286         throw new Error JavaDoc("Bad TypeKind !");
287     }
288 }
289
Popular Tags