KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > corba > TypeCodeUtils


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): Sylvain Leblanc.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.corba;
28
29 // Package dependencies
30
import org.omg.CORBA.TCKind JavaDoc;
31
32 /**
33  * This class provides CORBA::TypeCode util functions.
34  *
35  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
36  * @author <a HREF="mailto:Sylvain.Leblanc@lifl.fr">Sylvain Leblanc</a>
37  *
38  * @version 0.4
39  */

40 public abstract class TypeCodeUtils
41 {
42     // ==================================================================
43
//
44
// Internal state.
45
//
46
// ==================================================================
47

48     /**
49      ** The singleton CORBA::TypeCode for the OMG IDL void type.
50      **/

51     static private org.omg.CORBA.TypeCode JavaDoc tc_void_ = null;
52
53     // ==================================================================
54
//
55
// Constructor.
56
//
57
// ==================================================================
58

59     /**
60      ** The default constructor.
61      **/

62     private
63     TypeCodeUtils()
64     {
65     }
66
67     // ==================================================================
68
//
69
// Internal methods.
70
//
71
// ==================================================================
72

73     // ==================================================================
74
//
75
// Public methods.
76
//
77
// ==================================================================
78

79     /**
80      * Obtain the CORBA::TypeCode for the OMG IDL void type.
81      *
82      * @return The CORBA::TypeCode for the OMG IDL void type.
83      */

84     public static org.omg.CORBA.TypeCode JavaDoc
85     getTC_void()
86     {
87         if(tc_void_ == null)
88         {
89             tc_void_ = TheORB.getORB().get_primitive_tc(
90                                                         org.omg.CORBA.TCKind.tk_void);
91         }
92         return tc_void_;
93     }
94
95     /**
96      ** Obtain the orignal CORBA::TypeCode.
97      **
98      ** @param tc The aliased CORBA::TypeCode.
99      **
100      ** @return The unaliased CORBA::TypeCode.
101      **/

102     public static org.omg.CORBA.TypeCode JavaDoc
103     getOrigType(org.omg.CORBA.TypeCode JavaDoc tc)
104     {
105         try
106         {
107             while(tc.kind() == org.omg.CORBA.TCKind.tk_alias)
108             {
109                 tc = tc.content_type();
110             }
111             return tc;
112         }
113         catch(org.omg.CORBA.TypeCodePackage.BadKind JavaDoc exc)
114         {
115             // Wrap the CORBA::TypeCode::BadKind exception.
116
throw new UserExceptionWrapper(exc);
117         }
118
119     }
120
121     /**
122      * Returns a String representation of a TypeCode. This string
123      * representation is based on OMG IDL syntax.
124      *
125      * @param tc The type code.
126      *
127      * @return A string representation of the given
128      * <code>org.omg.CORBA.TypeCode</code>.
129      */

130     public static String JavaDoc
131     toStringValue(org.omg.CORBA.TypeCode JavaDoc tc)
132     {
133         TCKind JavaDoc tk = tc.kind();
134
135         try {
136             if (tk == TCKind.tk_null)
137                 return "null";
138             else if (tk == TCKind.tk_void)
139                 return "void";
140             else if (tk == TCKind.tk_short)
141                 return "short";
142             else if (tk == TCKind.tk_ushort)
143                 return "unsigned short";
144             else if (tk == TCKind.tk_long)
145                 return "long";
146             else if (tk == TCKind.tk_ulong)
147                 return "unsigned long";
148             else if (tk == TCKind.tk_longlong)
149                 return "long long";
150             else if (tk == TCKind.tk_ulonglong)
151                 return "unsigned long long";
152             else if (tk == TCKind.tk_float)
153                 return "float";
154             else if (tk == TCKind.tk_double)
155                 return "double";
156             else if (tk == TCKind.tk_longdouble)
157                 return "long double";
158             else if (tk == TCKind.tk_boolean)
159                 return "boolean";
160             else if (tk == TCKind.tk_char)
161                 return "char";
162             else if (tk == TCKind.tk_wchar)
163                 return "wchar";
164             else if (tk == TCKind.tk_octet)
165                 return "octet";
166             else if (tk == TCKind.tk_any)
167                 return "any";
168             else if (tk == TCKind.tk_Principal)
169                 return "::CORBA::Principal";
170             else if (tk == TCKind.tk_TypeCode)
171                 return "::CORBA::TypeCode";
172             else if (tk == TCKind.tk_objref)
173                 return "Object";
174             
175             // tk_local_interface not managed
176
// cf. ORBacus 4.1
177
else if ( (tk == TCKind.tk_struct) ||
178                       (tk == TCKind.tk_union) ||
179                       (tk == TCKind.tk_enum) ||
180                       (tk == TCKind.tk_except) ||
181                       (tk == TCKind.tk_alias) ||
182                       (tk == TCKind.tk_value_box) ||
183                       (tk == TCKind.tk_value) ||
184                       (tk == TCKind.tk_native) ||
185                       (tk == TCKind.tk_abstract_interface) )
186             {
187                 return tc.name();
188             }
189             else if (tk == TCKind.tk_string)
190             {
191                 int l = tc.length();
192                 if (l==0)
193                     return "string";
194                 return "string<"+l+">";
195             }
196             else if (tk == TCKind.tk_wstring)
197             {
198                 int l = tc.length();
199                 if (l==0)
200                     return "wstring";
201                 return "wstring<"+l+">";
202             }
203             else if (tk == TCKind.tk_sequence)
204             {
205                 int l = tc.length();
206                 String JavaDoc str = toStringValue(tc.content_type());
207                 if (l==0)
208                     return "sequence<"+str+">";
209                 return "sequence<"+str+","+l+">";
210             }
211             else if (tk == TCKind.tk_array)
212             {
213                 String JavaDoc str = toStringValue(tc.content_type());
214                 return str;
215             }
216             else if (tk == TCKind.tk_fixed)
217             {
218                 return "fixed<"+tc.fixed_digits()+","+tc.fixed_scale()+">";
219             }
220             else
221                 return "";
222         } catch (org.omg.CORBA.TypeCodePackage.BadKind JavaDoc ex) {
223             // cannot happened because "well used"
224
return "";
225         }
226     }
227 }
228
Popular Tags