KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > coach > reactor > IDLTranslator


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2005 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): Mathieu Vadet.
23 Contributor(s): Philippe Merle.
24
25 ====================================================================
26 $Id: IDLTranslator.java,v 1.1 2005/06/17 15:47:23 merle Exp $
27 ====================================================================*/

28
29 package org.coach.reactor;
30
31 import org.objectweb.ccm.visitorIDL3.common.*;
32
33 /**
34  * .
35  *
36  * @author <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
37  *
38  * @version 0.3
39  */

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

49     // ==================================================================
50
//
51
// Constructor.
52
//
53
// ==================================================================
54

55     /**
56      ** The default constructor.
57      **/

58     public
59     IDLTranslator()
60     {
61     }
62
63     // ==================================================================
64
//
65
// Internal methods.
66
//
67
// ==================================================================
68

69     // ==================================================================
70
//
71
// Public methods.
72
//
73
// ==================================================================
74

75     /**
76      **
77      **/

78     public java.lang.String JavaDoc
79     toIDL(org.objectweb.ccm.IDL3.TypeRef typeref)
80     {
81         switch(typeref.getTypeKind())
82         {
83             case org.objectweb.ccm.IDL3.TypeKind._tk_null :
84                 return "null";
85             case org.objectweb.ccm.IDL3.TypeKind._tk_void :
86                 return "void";
87             case org.objectweb.ccm.IDL3.TypeKind._tk_short :
88                 return "short";
89             case org.objectweb.ccm.IDL3.TypeKind._tk_ushort :
90                 return "unsigned short";
91             case org.objectweb.ccm.IDL3.TypeKind._tk_long :
92                 return "long";
93             case org.objectweb.ccm.IDL3.TypeKind._tk_ulong :
94                 return "unsigned long";
95             case org.objectweb.ccm.IDL3.TypeKind._tk_longlong :
96                 return "long long";
97             case org.objectweb.ccm.IDL3.TypeKind._tk_ulonglong :
98                 return "unsigned long long";
99             case org.objectweb.ccm.IDL3.TypeKind._tk_float :
100                 return "float";
101             case org.objectweb.ccm.IDL3.TypeKind._tk_double :
102                 return "double";
103             case org.objectweb.ccm.IDL3.TypeKind._tk_longdouble :
104                 return "long double";
105             case org.objectweb.ccm.IDL3.TypeKind._tk_boolean :
106                 return "boolean";
107             case org.objectweb.ccm.IDL3.TypeKind._tk_char :
108                 return "char";
109             case org.objectweb.ccm.IDL3.TypeKind._tk_wchar :
110                 return "wchar";
111             case org.objectweb.ccm.IDL3.TypeKind._tk_octet :
112                 return "octet";
113             case org.objectweb.ccm.IDL3.TypeKind._tk_any :
114                 return "any";
115             case org.objectweb.ccm.IDL3.TypeKind._tk_Principal :
116                 return "::CORBA::Principal";
117             case org.objectweb.ccm.IDL3.TypeKind._tk_TypeCode :
118                 return "::CORBA::TypeCode";
119
120             case org.objectweb.ccm.IDL3.TypeKind._tk_objref :
121                 return "Object";
122
123             case org.objectweb.ccm.IDL3.TypeKind._tk_struct :
124             case org.objectweb.ccm.IDL3.TypeKind._tk_union :
125             case org.objectweb.ccm.IDL3.TypeKind._tk_enum :
126             case org.objectweb.ccm.IDL3.TypeKind._tk_exception :
127             case org.objectweb.ccm.IDL3.TypeKind._tk_alias :
128             case org.objectweb.ccm.IDL3.TypeKind._tk_value_box :
129             case org.objectweb.ccm.IDL3.TypeKind._tk_value :
130             case org.objectweb.ccm.IDL3.TypeKind._tk_native :
131             case org.objectweb.ccm.IDL3.TypeKind._tk_abstract_interface :
132             case org.objectweb.ccm.IDL3.TypeKind._tk_local_interface :
133             case org.objectweb.ccm.IDL3.TypeKind._tk_interface :
134             case org.objectweb.ccm.IDL3.TypeKind._tk_component :
135             case org.objectweb.ccm.IDL3.TypeKind._tk_event :
136             case org.objectweb.ccm.IDL3.TypeKind._tk_home :
137                 org.objectweb.ccm.IDL3.Declaration decl = null;
138                 decl = (org.objectweb.ccm.IDL3.Declaration)typeref;
139                 return decl.getAbsoluteName();
140
141             case org.objectweb.ccm.IDL3.TypeKind._tk_string :
142                 int l = ((org.objectweb.ccm.IDL3.TypeRefImpl)typeref).getLength();
143                 if (l==0)
144                     return "string";
145                 return "string<"+l+">";
146             case org.objectweb.ccm.IDL3.TypeKind._tk_wstring :
147                 l = ((org.objectweb.ccm.IDL3.TypeRefImpl)typeref).getLength();
148                 if (l==0)
149                     return "wstring";
150                 return "wstring<"+l+">";
151             case org.objectweb.ccm.IDL3.TypeKind._tk_sequence :
152                 org.objectweb.ccm.IDL3.TypeRefImpl impl= (org.objectweb.ccm.IDL3.TypeRefImpl)typeref;
153                 l = impl.getLength();
154                 java.lang.String JavaDoc str = toIDL(impl.getContentType());
155                 if (l==0)
156                     return "sequence<"+str+">";
157                 return "sequence<"+str+","+l+">";
158             case org.objectweb.ccm.IDL3.TypeKind._tk_array :
159                 impl = (org.objectweb.ccm.IDL3.TypeRefImpl)typeref;
160                 str = toIDL(impl.getContentType());
161                 return str;
162             case org.objectweb.ccm.IDL3.TypeKind._tk_fixed :
163                 impl= (org.objectweb.ccm.IDL3.TypeRefImpl)typeref;
164                 return "fixed<"+impl.getDigits()+","+impl.getScale()+">";
165             default :
166                 return "";
167         }
168     }
169
170     /**
171      **
172      **/

173     public java.lang.String JavaDoc
174     toIDLPostfix(org.objectweb.ccm.IDL3.TypeRef typeref)
175     {
176         switch(typeref.getTypeKind())
177         {
178             case org.objectweb.ccm.IDL3.TypeKind._tk_array :
179                 org.objectweb.ccm.IDL3.TypeRefImpl impl = null;
180                 impl = (org.objectweb.ccm.IDL3.TypeRefImpl)typeref;
181                 java.lang.String JavaDoc str = toIDLPostfix(impl.getContentType());
182                 int l = impl.getLength();
183                 return str+"["+l+"]";
184             default :
185                 return "";
186         }
187     }
188
189     /**
190      **
191      **/

192     public java.lang.String JavaDoc
193     toString(org.objectweb.ccm.IDL3.AnyValue anyvalue,
194              org.objectweb.ccm.IDL3.TypeRef typeref)
195     {
196         //
197
// TODO : add escaped sequencesto strings, eg '\n' => "\\n"
198
//
199
if (anyvalue.isInteger())
200             return java.lang.String.valueOf(anyvalue.getAsInteger());
201         else if (anyvalue.isString())
202             return "\""+anyvalue.getAsString()+"\"";
203         else if (anyvalue.isWString())
204             return "L\""+anyvalue.getAsWString()+"\"";
205         else if (anyvalue.isChar())
206             return "\'"+java.lang.String.valueOf(anyvalue.getAsChar())+"\'";
207         else if (anyvalue.isWChar())
208             return "L\'"+java.lang.String.valueOf(anyvalue.getAsWChar())+"\'";
209         else if (anyvalue.isFloating())
210             return java.lang.String.valueOf(anyvalue.getAsFloating());
211         else if (anyvalue.isFixed())
212             return anyvalue.getAsFixed();
213         else if (anyvalue.isBoolean())
214         {
215             if (anyvalue.getAsBoolean())
216                 return "TRUE";
217
218             return "FALSE";
219         }
220         else if (anyvalue.isEnum())
221         {
222             // build enum member absolute name
223
java.lang.String JavaDoc abs_name = ((org.objectweb.ccm.IDL3.EnumDecl)typeref).getParent().getAbsoluteName();
224             return abs_name + "::" + anyvalue.getAsEnum();
225         }
226         else
227             return "";
228     }
229 }
230
Popular Tags