KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > visitorIDL3 > xmi > XMITranslator


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): Mathieu Vadet
23                       Tran Huynh (tran.huynh@fr.thalesgroup.com)
24 Contributor(s): .
25
26 ====================================================================*/

27
28 package org.objectweb.ccm.visitorIDL3.xmi;
29
30 /**
31  * This class translates CORBA types into XMI.
32  */

33 public class XMITranslator {
34
35     /**
36      * Default constructor.
37      */

38     public XMITranslator() {
39     }
40
41     /**
42      * This method returns the XMI string for a given TypeRef object.
43      *
44      * @param typeref The TypeRef object.
45      *
46      * @return The XMI string.
47      */

48     public java.lang.String JavaDoc
49     toXMI(org.objectweb.ccm.IDL3.TypeRef typeref) {
50         switch (typeref.getTypeKind()) {
51             case org.objectweb.ccm.IDL3.TypeKind._tk_null :
52                 return "null";
53             case org.objectweb.ccm.IDL3.TypeKind._tk_void :
54                 return "void";
55             case org.objectweb.ccm.IDL3.TypeKind._tk_short :
56                 return "CORBAshort";
57             case org.objectweb.ccm.IDL3.TypeKind._tk_ushort :
58                 return "CORBAunsignedshort";
59             case org.objectweb.ccm.IDL3.TypeKind._tk_long :
60                 return "CORBAlong";
61             case org.objectweb.ccm.IDL3.TypeKind._tk_ulong :
62                 return "CORBAunsignedlong";
63             case org.objectweb.ccm.IDL3.TypeKind._tk_longlong :
64                 return "CORBAlonglong";
65             case org.objectweb.ccm.IDL3.TypeKind._tk_ulonglong :
66                 return "CORBAunsignedlonglong";
67             case org.objectweb.ccm.IDL3.TypeKind._tk_float :
68                 return "CORBAfloat";
69             case org.objectweb.ccm.IDL3.TypeKind._tk_double :
70                 return "CORBAdouble";
71             case org.objectweb.ccm.IDL3.TypeKind._tk_longdouble :
72                 return "CORBAlongdouble";
73             case org.objectweb.ccm.IDL3.TypeKind._tk_boolean :
74                 return "CORBAboolean";
75             case org.objectweb.ccm.IDL3.TypeKind._tk_char :
76                 return "CORBAchar";
77             case org.objectweb.ccm.IDL3.TypeKind._tk_wchar :
78                 return "CORBAwchar";
79             case org.objectweb.ccm.IDL3.TypeKind._tk_octet :
80                 return "CORBAoctet";
81             case org.objectweb.ccm.IDL3.TypeKind._tk_any :
82                 return "CORBAany";
83             case org.objectweb.ccm.IDL3.TypeKind._tk_Principal :
84                 return "CORBAPrincipal";
85             case org.objectweb.ccm.IDL3.TypeKind._tk_TypeCode :
86                 return "CORBATypeCode";
87             case org.objectweb.ccm.IDL3.TypeKind._tk_objref :
88                 return "CORBAObject";
89
90             case org.objectweb.ccm.IDL3.TypeKind._tk_alias :
91             case org.objectweb.ccm.IDL3.TypeKind._tk_struct :
92             case org.objectweb.ccm.IDL3.TypeKind._tk_union :
93             case org.objectweb.ccm.IDL3.TypeKind._tk_enum :
94             case org.objectweb.ccm.IDL3.TypeKind._tk_exception :
95             case org.objectweb.ccm.IDL3.TypeKind._tk_value_box :
96             case org.objectweb.ccm.IDL3.TypeKind._tk_value :
97             case org.objectweb.ccm.IDL3.TypeKind._tk_native :
98             case org.objectweb.ccm.IDL3.TypeKind._tk_abstract_interface :
99             case org.objectweb.ccm.IDL3.TypeKind._tk_local_interface :
100             case org.objectweb.ccm.IDL3.TypeKind._tk_interface :
101             case org.objectweb.ccm.IDL3.TypeKind._tk_component :
102             case org.objectweb.ccm.IDL3.TypeKind._tk_home :
103             case org.objectweb.ccm.IDL3.TypeKind._tk_event :
104                 org.objectweb.ccm.IDL3.Declaration decl = (org.objectweb.ccm.IDL3.Declaration) typeref;
105                 return getAbsoluteName(decl);
106
107             case org.objectweb.ccm.IDL3.TypeKind._tk_sequence :
108                 org.objectweb.ccm.IDL3.TypeRefImpl impl= (org.objectweb.ccm.IDL3.TypeRefImpl) typeref;
109                 java.lang.String JavaDoc str = toXMI(impl.getContentType());
110                 int length = impl.getLength();
111                 if (length == 0)
112                     return "CORBAsequence<" + str + ">";
113                 return "CORBAsequence<" + str + ", " + length + ">";
114
115             case org.objectweb.ccm.IDL3.TypeKind._tk_array :
116                 impl= (org.objectweb.ccm.IDL3.TypeRefImpl) typeref;
117                 str = toXMI(impl.getContentType());
118                 return "CORBAarray<" + str + ", " + impl.getLength() + ">";
119
120             case org.objectweb.ccm.IDL3.TypeKind._tk_string :
121                 impl= (org.objectweb.ccm.IDL3.TypeRefImpl) typeref;
122                 length = impl.getLength();
123                 if (length == 0)
124                     return "CORBAstring";
125                 return "CORBAstring<" + impl.getLength() + ">";
126             
127             case org.objectweb.ccm.IDL3.TypeKind._tk_wstring :
128                 impl= (org.objectweb.ccm.IDL3.TypeRefImpl) typeref;
129                 length = impl.getLength();
130                 if (length == 0)
131                     return "CORBAwstring";
132                 return "CORBAwstring<" + impl.getLength() + ">";
133     
134             case org.objectweb.ccm.IDL3.TypeKind._tk_fixed :
135                 impl= (org.objectweb.ccm.IDL3.TypeRefImpl) typeref;
136                 return "CORBAfixed<" + impl.getDigits() + ", " + impl.getScale() + ">";
137
138             default :
139                 return "";
140         }
141     }
142     
143     /**
144      * This method returns the XMI string for a given TypeRef object.
145      *
146      * @param typeref The TypeRef object.
147      */

148     public java.lang.String JavaDoc
149     toXMIString(org.objectweb.ccm.IDL3.TypeRef typeref) {
150         switch(typeref.getTypeKind()) {
151             case org.objectweb.ccm.IDL3.TypeKind._tk_null :
152                 return "null";
153             case org.objectweb.ccm.IDL3.TypeKind._tk_void :
154                 return "void";
155             case org.objectweb.ccm.IDL3.TypeKind._tk_short :
156                 return "CORBAshort";
157             case org.objectweb.ccm.IDL3.TypeKind._tk_ushort :
158                 return "CORBAunsignedshort";
159             case org.objectweb.ccm.IDL3.TypeKind._tk_long :
160                 return "CORBAlong";
161             case org.objectweb.ccm.IDL3.TypeKind._tk_ulong :
162                 return "CORBAunsignedlong";
163             case org.objectweb.ccm.IDL3.TypeKind._tk_longlong :
164                 return "CORBAlonglong";
165             case org.objectweb.ccm.IDL3.TypeKind._tk_ulonglong :
166                 return "CORBAunsignedlonglong";
167             case org.objectweb.ccm.IDL3.TypeKind._tk_float :
168                 return "CORBAfloat";
169             case org.objectweb.ccm.IDL3.TypeKind._tk_double :
170                 return "CORBAdouble";
171             case org.objectweb.ccm.IDL3.TypeKind._tk_longdouble :
172                 return "CORBAlongdouble";
173             case org.objectweb.ccm.IDL3.TypeKind._tk_boolean :
174                 return "CORBAboolean";
175             case org.objectweb.ccm.IDL3.TypeKind._tk_char :
176                 return "CORBAchar";
177             case org.objectweb.ccm.IDL3.TypeKind._tk_wchar :
178                 return "CORBAwchar";
179             case org.objectweb.ccm.IDL3.TypeKind._tk_octet :
180                 return "CORBAoctet";
181             case org.objectweb.ccm.IDL3.TypeKind._tk_any :
182                 return "CORBAany";
183             case org.objectweb.ccm.IDL3.TypeKind._tk_Principal :
184                 return "CORBAPrincipal";
185             case org.objectweb.ccm.IDL3.TypeKind._tk_TypeCode :
186                 return "CORBATypeCode";
187             case org.objectweb.ccm.IDL3.TypeKind._tk_objref :
188                 return "CORBAObject";
189             case org.objectweb.ccm.IDL3.TypeKind._tk_string :
190                 return "CORBAstring";
191             case org.objectweb.ccm.IDL3.TypeKind._tk_wstring :
192                 return "CORBAwstring";
193             case org.objectweb.ccm.IDL3.TypeKind._tk_fixed :
194                 return "CORBAFixed";
195             case org.objectweb.ccm.IDL3.TypeKind._tk_sequence :
196                 return "CORBASequence";
197             case org.objectweb.ccm.IDL3.TypeKind._tk_array :
198                 return "CORBAArray";
199
200             case org.objectweb.ccm.IDL3.TypeKind._tk_alias :
201             case org.objectweb.ccm.IDL3.TypeKind._tk_struct :
202             case org.objectweb.ccm.IDL3.TypeKind._tk_union :
203             case org.objectweb.ccm.IDL3.TypeKind._tk_enum :
204             case org.objectweb.ccm.IDL3.TypeKind._tk_exception :
205             case org.objectweb.ccm.IDL3.TypeKind._tk_value_box :
206             case org.objectweb.ccm.IDL3.TypeKind._tk_value :
207             case org.objectweb.ccm.IDL3.TypeKind._tk_native :
208             case org.objectweb.ccm.IDL3.TypeKind._tk_abstract_interface :
209             case org.objectweb.ccm.IDL3.TypeKind._tk_local_interface :
210             case org.objectweb.ccm.IDL3.TypeKind._tk_interface :
211             case org.objectweb.ccm.IDL3.TypeKind._tk_component :
212             case org.objectweb.ccm.IDL3.TypeKind._tk_home :
213             case org.objectweb.ccm.IDL3.TypeKind._tk_event :
214                 org.objectweb.ccm.IDL3.Declaration decl = (org.objectweb.ccm.IDL3.Declaration) typeref;
215                 return getAbsoluteName(decl);
216
217             default :
218                 return "";
219         }
220     }
221
222     /**
223      * This method returns the absolute name of an IDL declaration.
224      *
225      * @param decl The IDL declaration.
226      *
227      * @return The absolute name.
228      */

229     public java.lang.String JavaDoc
230     getAbsoluteName(org.objectweb.ccm.IDL3.Declaration decl) {
231         return decl.getAbsoluteName();
232     }
233
234     /**
235      * This method returns a string for an ANY value.
236      *
237      * @param anyvalue The ANY value.
238      * @param typeref The TypeRef object.
239      *
240      * @return The ANY value as a string.
241      */

242     public java.lang.String JavaDoc
243     toString(org.objectweb.ccm.IDL3.AnyValue anyvalue,
244              org.objectweb.ccm.IDL3.TypeRef typeref) {
245         // TODO : add escaped sequences to strings, eg '\n' => "\\n"
246
if (anyvalue.isInteger()) {
247             return java.lang.String.valueOf(anyvalue.getAsInteger());
248         } else if (anyvalue.isString()) {
249             return "\"" + anyvalue.getAsString() + "\"";
250         } else if (anyvalue.isWString()) {
251             return "L\"" + anyvalue.getAsWString() + "\"";
252         } else if (anyvalue.isChar()) {
253             return "\'" + java.lang.String.valueOf(anyvalue.getAsChar()) + "\'";
254         } else if (anyvalue.isWChar()) {
255             return "L\'" + java.lang.String.valueOf(anyvalue.getAsWChar()) + "\'";
256         } else if (anyvalue.isFloating()) {
257             return java.lang.String.valueOf(anyvalue.getAsFloating());
258         } else if (anyvalue.isFixed()) {
259             return anyvalue.getAsFixed();
260         } else if (anyvalue.isBoolean()) {
261             if (anyvalue.getAsBoolean()) {
262                 return "TRUE";
263             }
264             return "FALSE";
265         } else if (anyvalue.isEnum()) {
266             // Build enum member absolute name
267
java.lang.String JavaDoc abs_name = ((org.objectweb.ccm.IDL3.EnumDecl)
268                 typeref).getParent().getAbsoluteName();
269             return abs_name + "::" + anyvalue.getAsEnum();
270         } else {
271             return "";
272         }
273     }
274 }
275
Popular Tags