1 26 27 package org.objectweb.ccm.visitorIDL3.java; 28 29 import org.objectweb.ccm.visitorIDL3.common.*; 30 31 38 39 public class JavaTranslator 40 { 41 47 50 protected org.objectweb.ccm.util.Table abs_names_; 51 52 55 protected org.objectweb.ccm.util.Table keywords_; 56 57 58 64 67 public 68 JavaTranslator() 69 { 70 abs_names_ = new org.objectweb.ccm.util.Table(); 71 keywords_ = new org.objectweb.ccm.util.Table(); 72 keywords_.put("public", new Object ()); 73 keywords_.put("protected", new Object ()); 74 keywords_.put("private", new Object ()); 75 keywords_.put("class", new Object ()); 76 keywords_.put("interface", new Object ()); 77 keywords_.put("abstract", new Object ()); 78 keywords_.put("boolean", new Object ()); 79 keywords_.put("break", new Object ()); 80 keywords_.put("byte", new Object ()); 81 keywords_.put("case", new Object ()); 82 keywords_.put("catch", new Object ()); 83 keywords_.put("char", new Object ()); 84 keywords_.put("const", new Object ()); 85 keywords_.put("continue", new Object ()); 86 keywords_.put("default", new Object ()); 87 keywords_.put("do", new Object ()); 88 keywords_.put("double", new Object ()); 89 keywords_.put("else", new Object ()); 90 keywords_.put("extends", new Object ()); 91 keywords_.put("final", new Object ()); 92 keywords_.put("finally", new Object ()); 93 keywords_.put("float", new Object ()); 94 keywords_.put("for", new Object ()); 95 keywords_.put("goto", new Object ()); 96 keywords_.put("if", new Object ()); 97 keywords_.put("implements", new Object ()); 98 keywords_.put("import", new Object ()); 99 keywords_.put("instanceof", new Object ()); 100 keywords_.put("int", new Object ()); 101 keywords_.put("long", new Object ()); 102 keywords_.put("native", new Object ()); 103 keywords_.put("new", new Object ()); 104 keywords_.put("package", new Object ()); 105 keywords_.put("return", new Object ()); 106 keywords_.put("short", new Object ()); 107 keywords_.put("static", new Object ()); 108 keywords_.put("super", new Object ()); 109 keywords_.put("switch", new Object ()); 110 keywords_.put("synchronized", new Object ()); 111 keywords_.put("this", new Object ()); 112 keywords_.put("throw", new Object ()); 113 keywords_.put("throws", new Object ()); 114 keywords_.put("transient", new Object ()); 115 keywords_.put("try", new Object ()); 116 keywords_.put("void", new Object ()); 117 keywords_.put("volatile", new Object ()); 118 keywords_.put("while", new Object ()); 119 keywords_.put("true", new Object ()); 120 keywords_.put("false", new Object ()); 121 keywords_.put("null", new Object ()); 122 keywords_.put("clone", new Object ()); 123 keywords_.put("equals", new Object ()); 124 keywords_.put("finalize", new Object ()); 125 keywords_.put("getClass", new Object ()); 126 keywords_.put("hashCode", new Object ()); 127 keywords_.put("notify", new Object ()); 128 keywords_.put("notifyAll", new Object ()); 129 keywords_.put("toString", new Object ()); 130 keywords_.put("wait", new Object ()); 131 } 132 133 139 145 148 public java.lang.String 149 toJava(org.objectweb.ccm.IDL3.TypeRef typeref) 150 { 151 switch(typeref.getTypeKind()) 152 { 153 case org.objectweb.ccm.IDL3.TypeKind._tk_null : 154 return "null"; 155 case org.objectweb.ccm.IDL3.TypeKind._tk_void : 156 return "void"; 157 case org.objectweb.ccm.IDL3.TypeKind._tk_short : 158 return "short"; 159 case org.objectweb.ccm.IDL3.TypeKind._tk_ushort : 160 return "short"; 161 case org.objectweb.ccm.IDL3.TypeKind._tk_long : 162 return "int"; 163 case org.objectweb.ccm.IDL3.TypeKind._tk_ulong : 164 return "int"; 165 case org.objectweb.ccm.IDL3.TypeKind._tk_longlong : 166 return "long"; 167 case org.objectweb.ccm.IDL3.TypeKind._tk_ulonglong : 168 return "long"; 169 case org.objectweb.ccm.IDL3.TypeKind._tk_float : 170 return "float"; 171 case org.objectweb.ccm.IDL3.TypeKind._tk_double : 172 return "double"; 173 case org.objectweb.ccm.IDL3.TypeKind._tk_longdouble : 174 return "double"; 175 case org.objectweb.ccm.IDL3.TypeKind._tk_boolean : 176 return "boolean"; 177 case org.objectweb.ccm.IDL3.TypeKind._tk_char : 178 return "char"; 179 case org.objectweb.ccm.IDL3.TypeKind._tk_wchar : 180 return "char"; 181 case org.objectweb.ccm.IDL3.TypeKind._tk_octet : 182 return "byte"; 183 case org.objectweb.ccm.IDL3.TypeKind._tk_any : 184 return "org.omg.CORBA.Any"; 185 case org.objectweb.ccm.IDL3.TypeKind._tk_Principal : 186 return "org.omg.CORBA.Principal"; 187 case org.objectweb.ccm.IDL3.TypeKind._tk_TypeCode : 188 return "org.omg.CORBA.TypeCode"; 189 case org.objectweb.ccm.IDL3.TypeKind._tk_objref : 190 return "org.omg.CORBA.Object"; 191 case org.objectweb.ccm.IDL3.TypeKind._tk_string : 192 return "java.lang.String"; 193 case org.objectweb.ccm.IDL3.TypeKind._tk_wstring : 194 return "java.lang.String"; 195 case org.objectweb.ccm.IDL3.TypeKind._tk_fixed : 196 return "java.Math.BigDecimal"; 197 198 case org.objectweb.ccm.IDL3.TypeKind._tk_struct : 199 case org.objectweb.ccm.IDL3.TypeKind._tk_union : 200 case org.objectweb.ccm.IDL3.TypeKind._tk_enum : 201 case org.objectweb.ccm.IDL3.TypeKind._tk_exception : 202 case org.objectweb.ccm.IDL3.TypeKind._tk_value_box : 203 case org.objectweb.ccm.IDL3.TypeKind._tk_value : 204 case org.objectweb.ccm.IDL3.TypeKind._tk_native : 205 case org.objectweb.ccm.IDL3.TypeKind._tk_abstract_interface : 206 case org.objectweb.ccm.IDL3.TypeKind._tk_local_interface : 207 case org.objectweb.ccm.IDL3.TypeKind._tk_interface : 208 case org.objectweb.ccm.IDL3.TypeKind._tk_component : 209 case org.objectweb.ccm.IDL3.TypeKind._tk_home : 210 case org.objectweb.ccm.IDL3.TypeKind._tk_event : 211 org.objectweb.ccm.IDL3.Declaration decl = (org.objectweb.ccm.IDL3.Declaration)typeref; 212 return getAbsoluteName(decl); 213 214 case org.objectweb.ccm.IDL3.TypeKind._tk_alias : 215 org.objectweb.ccm.IDL3.AliasDecl alias = (org.objectweb.ccm.IDL3.AliasDecl)typeref; 216 return toJava(alias.getType()); 217 218 case org.objectweb.ccm.IDL3.TypeKind._tk_sequence : 219 case org.objectweb.ccm.IDL3.TypeKind._tk_array : 220 org.objectweb.ccm.IDL3.TypeRefImpl impl= (org.objectweb.ccm.IDL3.TypeRefImpl)typeref; 221 java.lang.String str = toJava(impl.getContentType()); 222 return str+"[]"; 223 default : 224 return ""; 225 } 226 } 227 228 231 public java.lang.String 232 toJava(org.objectweb.ccm.IDL3.TypeRef type, 233 int mode) 234 { 235 if (mode==org.objectweb.ccm.IDL3.OperationDecl.PARAM_IN) 236 return toJava(type); 237 238 switch(type.getTypeKind()) 239 { 240 case org.objectweb.ccm.IDL3.TypeKind._tk_null : 241 case org.objectweb.ccm.IDL3.TypeKind._tk_void : 242 throw new Error ("IDL null and void types could not be used for out or inout parameters!!!"); 243 244 case org.objectweb.ccm.IDL3.TypeKind._tk_short : 245 return "org.omg.CORBA.ShortHolder"; 246 247 case org.objectweb.ccm.IDL3.TypeKind._tk_ushort : 248 return "org.omg.CORBA.ShortHolder"; 249 250 case org.objectweb.ccm.IDL3.TypeKind._tk_long : 251 return "org.omg.CORBA.IntHolder"; 252 253 case org.objectweb.ccm.IDL3.TypeKind._tk_ulong : 254 return "org.omg.CORBA.IntHolder"; 255 256 case org.objectweb.ccm.IDL3.TypeKind._tk_longlong : 257 return "org.omg.CORBA.LongHolder"; 258 259 case org.objectweb.ccm.IDL3.TypeKind._tk_ulonglong : 260 return "org.omg.CORBA.LongHolder"; 261 262 case org.objectweb.ccm.IDL3.TypeKind._tk_float : 263 return "org.omg.CORBA.FloatHolder"; 264 265 case org.objectweb.ccm.IDL3.TypeKind._tk_double : 266 return "org.omg.CORBA.DoubleHolder"; 267 268 case org.objectweb.ccm.IDL3.TypeKind._tk_longdouble : 269 throw new Error ("Java mapping for IDL longdouble is unspecified!!!"); 270 271 case org.objectweb.ccm.IDL3.TypeKind._tk_boolean : 272 return "org.omg.CORBA.BooleanHolder"; 273 274 case org.objectweb.ccm.IDL3.TypeKind._tk_char : 275 return "org.omg.CORBA.CharHolder"; 276 277 case org.objectweb.ccm.IDL3.TypeKind._tk_wchar : 278 return "org.omg.CORBA.CharHolder"; 279 280 case org.objectweb.ccm.IDL3.TypeKind._tk_octet : 281 return "org.omg.CORBA.ByteHolder"; 282 283 case org.objectweb.ccm.IDL3.TypeKind._tk_any : 284 return "org.omg.CORBA.AnyHolder"; 285 286 case org.objectweb.ccm.IDL3.TypeKind._tk_Principal : 287 return "org.omg.CORBA.PrincipalHolder"; 288 289 case org.objectweb.ccm.IDL3.TypeKind._tk_TypeCode : 290 return "org.omg.CORBA.TypeCodeHolder"; 291 292 case org.objectweb.ccm.IDL3.TypeKind._tk_objref : 293 return "org.omg.CORBA.ObjectHolder"; 294 295 case org.objectweb.ccm.IDL3.TypeKind._tk_string : 296 return "org.omg.CORBA.StringHolder"; 297 298 case org.objectweb.ccm.IDL3.TypeKind._tk_wstring : 299 return "org.omg.CORBA.StringHolder"; 300 301 case org.objectweb.ccm.IDL3.TypeKind._tk_fixed : 302 return "org.omg.CORBA.FixedHolder"; 303 304 case org.objectweb.ccm.IDL3.TypeKind._tk_alias : 305 { 306 org.objectweb.ccm.IDL3.TypeRef ct = 307 ((org.objectweb.ccm.IDL3.AliasDecl)type).getType(); 308 if ((ct.getTypeKind()==org.objectweb.ccm.IDL3.TypeKind._tk_array) || 309 (ct.getTypeKind()==org.objectweb.ccm.IDL3.TypeKind._tk_sequence)) 310 return getAbsoluteName((org.objectweb.ccm.IDL3.AliasDecl)type) + "Holder"; 311 else 312 return toJava(ct, mode); 313 } 314 315 case org.objectweb.ccm.IDL3.TypeKind._tk_sequence : 316 case org.objectweb.ccm.IDL3.TypeKind._tk_array : 317 throw new Error ("Not implemented!!!"); 318 319 case org.objectweb.ccm.IDL3.TypeKind._tk_struct : 320 case org.objectweb.ccm.IDL3.TypeKind._tk_union : 321 case org.objectweb.ccm.IDL3.TypeKind._tk_enum : 322 case org.objectweb.ccm.IDL3.TypeKind._tk_exception : 323 case org.objectweb.ccm.IDL3.TypeKind._tk_value_box : 324 case org.objectweb.ccm.IDL3.TypeKind._tk_value : 325 case org.objectweb.ccm.IDL3.TypeKind._tk_native : 326 case org.objectweb.ccm.IDL3.TypeKind._tk_abstract_interface : 327 case org.objectweb.ccm.IDL3.TypeKind._tk_local_interface : 328 case org.objectweb.ccm.IDL3.TypeKind._tk_interface : 329 case org.objectweb.ccm.IDL3.TypeKind._tk_component : 330 case org.objectweb.ccm.IDL3.TypeKind._tk_home : 331 case org.objectweb.ccm.IDL3.TypeKind._tk_event : 332 return getAbsoluteName((org.objectweb.ccm.IDL3.Declaration)type) + "Holder"; 333 334 default : 335 throw new Error ("Other cases are not supported!!!"); 336 } 337 } 338 339 342 public java.lang.String 343 checkKeywords(java.lang.String id) 344 { 345 346 if (keywords_.containsKey(id)) 347 return "_"+id; 348 349 return id; 350 } 351 352 355 public java.lang.String 356 getAbsoluteName(org.objectweb.ccm.IDL3.Declaration decl) 357 { 358 if (decl==null) 359 return ""; 360 361 java.lang.String res = null; 363 res = (java.lang.String )abs_names_.get(decl.getId()); 364 if (res!=null) 365 return res; 366 367 res = ""; 369 java.lang.String prefix = decl.getPrefix(); 370 int idx, idx2; 371 if (!prefix.equals("")) 372 { 373 idx = prefix.indexOf('.'); 374 idx2 = 0; 375 while (idx!=-1) 376 { 377 res = prefix.substring(idx2, idx+1) + res; 378 idx2 = idx+1; 379 idx = prefix.indexOf('.', idx2); 380 } 381 res = prefix.substring(idx2) + '.' + res; 382 } 383 384 java.lang.String abs_name = decl.getAbsoluteName(); 386 idx = abs_name.indexOf(':', 2); 387 idx2 = 2; 388 while (idx!=-1) 389 { 390 res = res + abs_name.substring(idx2, idx) + '.'; 391 idx2 = idx+2; 392 idx = abs_name.indexOf(':', idx2); 393 } 394 res = res + abs_name.substring(idx2); 395 396 org.objectweb.ccm.IDL3.Scope parent = decl.getParent(); 398 int parent_kind = parent.getDeclKind(); 399 int decl_kind = decl.getDeclKind(); 400 if (decl_kind==org.objectweb.ccm.IDL3.DeclarationKind._dk_constant) 401 { 402 if ((parent_kind!=org.objectweb.ccm.IDL3.DeclarationKind._dk_interface) && 403 (parent_kind!=org.objectweb.ccm.IDL3.DeclarationKind._dk_abstract_interface) && 404 (parent_kind!=org.objectweb.ccm.IDL3.DeclarationKind._dk_local_interface)) 405 res = res + ".value"; 406 } 407 else if ((decl_kind==org.objectweb.ccm.IDL3.DeclarationKind._dk_exception) || 408 (decl_kind==org.objectweb.ccm.IDL3.DeclarationKind._dk_alias) || 409 (decl_kind==org.objectweb.ccm.IDL3.DeclarationKind._dk_struct) || 410 (decl_kind==org.objectweb.ccm.IDL3.DeclarationKind._dk_union) || 411 (decl_kind==org.objectweb.ccm.IDL3.DeclarationKind._dk_enum) || 412 (decl_kind==org.objectweb.ccm.IDL3.DeclarationKind._dk_native)) 413 { 414 if ((parent_kind==org.objectweb.ccm.IDL3.DeclarationKind._dk_interface) || 415 (parent_kind==org.objectweb.ccm.IDL3.DeclarationKind._dk_abstract_interface) || 416 (parent_kind==org.objectweb.ccm.IDL3.DeclarationKind._dk_local_interface) || 417 (parent_kind==org.objectweb.ccm.IDL3.DeclarationKind._dk_home) || 418 (parent_kind==org.objectweb.ccm.IDL3.DeclarationKind._dk_value) || 419 (parent_kind==org.objectweb.ccm.IDL3.DeclarationKind._dk_event) || 420 (parent_kind==org.objectweb.ccm.IDL3.DeclarationKind._dk_component)) 421 { 422 idx = res.lastIndexOf('.'); 423 res = res.substring(0, idx) + "Package" + res.substring(idx); 424 } 425 } 426 427 abs_names_.put(decl.getId(), res); 429 return res; 430 } 431 432 435 public java.lang.String 436 getPackage(org.objectweb.ccm.IDL3.Declaration decl) 437 { 438 java.lang.String abs_name = getAbsoluteName(decl); 439 int idx = abs_name.lastIndexOf('.'); 440 if (idx==-1) 441 return ""; 442 443 return abs_name.substring(0, idx); 444 } 445 446 449 public java.lang.String 450 getAsDirectory(org.objectweb.ccm.IDL3.Declaration decl) 451 { 452 java.lang.String abs_name = getAbsoluteName(decl); 453 int idx = abs_name.indexOf('.'); 454 if (idx==-1) 455 return "./"; 456 457 java.lang.String dir = ""; 458 int idx2 = 0; 459 while (idx!=-1) 460 { 461 dir = dir + abs_name.substring(idx2, idx) + '/'; 462 idx2 = idx+1; 463 idx = abs_name.indexOf('.', idx2); 464 } 465 466 return dir; 467 } 468 } 469 | Popular Tags |