1 26 27 package org.objectweb.ccm.visitorIDL3.java; 28 29 import org.objectweb.ccm.visitorIDL3.common.*; 30 31 39 40 public class JavaPrinterBase 41 extends Printer 42 { 43 49 52 protected JavaTranslator translator_; 53 54 60 63 public 64 JavaPrinterBase(Generator gen, 65 char call_char, 66 char comment_char, 67 java.lang.String indent) 68 throws fr.lifl.cim.jidlscript.lang.JISError 69 { 70 super(gen, call_char, comment_char, indent); 71 72 translator_ = new JavaTranslator(); 74 } 75 76 82 88 91 public java.lang.String 92 open(org.objectweb.ccm.IDL3.Declaration obj, 93 java.lang.String ext) 94 { 95 super.setDirectory(getTranslator().getAsDirectory(obj)); 96 super.open(name(obj)+ext); 97 return ""; 98 } 99 100 103 public java.lang.String 104 close(org.objectweb.ccm.IDL3.Declaration obj, 105 java.lang.String str) 106 { 107 System.out.println("File \'"+getTranslator().getAsDirectory(obj)+name(obj)+str+"\' has been generated"); 108 super.close(); 109 return ""; 110 } 111 112 115 public java.lang.String 116 visitContained(org.objectweb.ccm.IDL3.Declaration contained, 117 java.lang.String extension) 118 { 119 java.lang.String id = 120 org.objectweb.ccm.IDL3.DeclarationKind.toString(contained.getDeclKind()).toUpperCase()+ 121 extension; 122 123 java.lang.String [] aliases = { "obj" }; 124 java.lang.Object [] objs = { contained }; 125 super.map(id, aliases, objs); 126 127 return ""; 128 } 129 130 133 public java.lang.String 134 visitContainedWithMapping(org.objectweb.ccm.IDL3.Declaration obj, 135 org.objectweb.ccm.IDL3.Declaration mapobj, 136 java.lang.String extension) 137 { 138 java.lang.String id = 139 org.objectweb.ccm.IDL3.DeclarationKind.toString(mapobj.getDeclKind()).toUpperCase()+ 140 extension; 141 142 java.lang.String [] aliases = { "obj" , "mapobj" }; 143 java.lang.Object [] objs = { obj, mapobj }; 144 super.map(id, aliases, objs); 145 146 return ""; 147 } 148 149 152 public java.lang.String 153 visit(org.objectweb.ccm.IDL3.Declaration obj) 154 { 155 if (obj.getDeclKind()==org.objectweb.ccm.IDL3.DeclarationKind._dk_module) 156 return visitContained(obj, ""); 157 158 java.lang.String msg = 159 "error in class org.objectweb.ccm.visitorIDL3.JavaPrinterBase\n"+ 160 " operation : visit\n"+ 161 " message : root visited object must be a module"; 162 System.err.println(msg); 163 return ""; 164 } 165 166 169 public java.lang.String 170 name(org.objectweb.ccm.IDL3.Declaration decl) 171 { 172 return getTranslator().checkKeywords(decl.getName()); 173 } 174 175 178 public java.lang.String 179 checkName(java.lang.String idl_name) 180 { 181 return getTranslator().checkKeywords(idl_name); 182 } 183 184 187 public java.lang.String 188 type(org.objectweb.ccm.IDL3.TypeRef type) 189 { 190 return getTranslator().toJava(type); 191 } 192 193 196 public java.lang.String 197 isVoid(org.objectweb.ccm.IDL3.TypeRef type) 198 { 199 if (type.getTypeKind()!=org.objectweb.ccm.IDL3.TypeKind._tk_void) 200 return "return "; 201 202 return ""; 203 } 204 205 208 public java.lang.String 209 params(org.objectweb.ccm.IDL3.OperationDecl op) 210 { 211 return params(op.getParameters(), op.getContexts()); 212 } 213 214 217 public java.lang.String 218 params(org.objectweb.ccm.IDL3.Initializer init) 219 { 220 return params(init.getParameters(), null); 221 } 222 223 226 public java.lang.String 227 params(org.objectweb.ccm.IDL3.ParameterList list, 228 java.lang.String [] ctxs) 229 { 230 java.lang.String [] names = list.getParamNames(); 231 org.objectweb.ccm.IDL3.TypeRef[] types = list.getParamTypes(); 232 int[] modes = list.getParamModes(); 233 java.lang.String res = ""; 234 235 for (int i=0;i<names.length;i++) 236 res = res + getTranslator().toJava(types[i], modes[i]) + " " + names[i] + ", "; 237 238 if ((ctxs!=null) && (ctxs.length!=0)) 239 res = res + "org.omg.CORBA.Context ctx, "; 240 if (!res.equals("")) 241 res = res.substring(0, res.length()-2); 242 243 return res; 244 } 245 246 249 public java.lang.String 250 paramNames(org.objectweb.ccm.IDL3.OperationDecl op) 251 { 252 return paramNames(op.getParameters(), op.getContexts()); 253 } 254 255 258 public java.lang.String 259 paramNames(org.objectweb.ccm.IDL3.Initializer init) 260 { 261 return paramNames(init.getParameters(), null); 262 } 263 264 267 public java.lang.String 268 paramNames(org.objectweb.ccm.IDL3.ParameterList list, 269 java.lang.String [] ctxs) 270 { 271 java.lang.String [] names = list.getParamNames(); 272 java.lang.String str = ""; 273 274 for (int i=0;i<names.length;i++) 275 str = str + names[i] + ", "; 276 277 if ((ctxs!=null) && (ctxs.length!=0)) 278 str = str + "ctx, "; 279 if (!str.equals("")) 280 str = str.substring(0, str.length()-2); 281 282 return str; 283 } 284 285 288 public java.lang.String 289 exceptions(org.objectweb.ccm.IDL3.ExceptionDecl[] excs) 290 { 291 java.lang.String res = ""; 292 for (int i=0;i<excs.length;i++) 293 res = res + getTranslator().getAbsoluteName(excs[i]) + ", "; 294 295 if (!res.equals("")) 296 return "throws " + res.substring(0, res.length()-2) + "\\n"; 297 298 return ""; 299 } 300 301 304 public java.lang.String 305 nullValue(org.objectweb.ccm.IDL3.TypeRef type) 306 { 307 switch(type.getTypeKind()) 308 { 309 case org.objectweb.ccm.IDL3.TypeKind._tk_null : 310 return "????"; 311 case org.objectweb.ccm.IDL3.TypeKind._tk_void : 312 return "????"; 313 case org.objectweb.ccm.IDL3.TypeKind._tk_short : 314 case org.objectweb.ccm.IDL3.TypeKind._tk_ushort : 315 return "0"; 316 case org.objectweb.ccm.IDL3.TypeKind._tk_long : 317 case org.objectweb.ccm.IDL3.TypeKind._tk_ulong : 318 return "0"; 319 case org.objectweb.ccm.IDL3.TypeKind._tk_longlong : 320 case org.objectweb.ccm.IDL3.TypeKind._tk_ulonglong : 321 return "0"; 322 case org.objectweb.ccm.IDL3.TypeKind._tk_char : 323 case org.objectweb.ccm.IDL3.TypeKind._tk_wchar : 324 return "\'\0\'"; 325 case org.objectweb.ccm.IDL3.TypeKind._tk_string : 326 case org.objectweb.ccm.IDL3.TypeKind._tk_wstring : 327 return "\"\""; 328 case org.objectweb.ccm.IDL3.TypeKind._tk_float : 329 return "0f"; 330 case org.objectweb.ccm.IDL3.TypeKind._tk_double : 331 return "0.0"; 332 case org.objectweb.ccm.IDL3.TypeKind._tk_boolean : 333 return "true"; 334 case org.objectweb.ccm.IDL3.TypeKind._tk_octet : 335 return "(byte)0"; 336 default : 338 return "null"; 339 } 340 } 341 342 345 public org.objectweb.ccm.IDL3.TypeRef 346 getType(org.objectweb.ccm.IDL3.Declaration obj) 347 { 348 switch(obj.getDeclKind()) 349 { 350 case org.objectweb.ccm.IDL3.DeclarationKind._dk_alias : 351 return ((org.objectweb.ccm.IDL3.AliasDecl)obj).getType(); 352 case org.objectweb.ccm.IDL3.DeclarationKind._dk_attribute : 353 return ((org.objectweb.ccm.IDL3.AttributeDecl)obj).getType(); 354 case org.objectweb.ccm.IDL3.DeclarationKind._dk_constant : 355 return ((org.objectweb.ccm.IDL3.ConstantDecl)obj).getType(); 356 case org.objectweb.ccm.IDL3.DeclarationKind._dk_emits : 357 return ((org.objectweb.ccm.IDL3.EmitsDecl)obj).getType(); 358 case org.objectweb.ccm.IDL3.DeclarationKind._dk_publishes : 359 return ((org.objectweb.ccm.IDL3.PublishesDecl)obj).getType(); 360 case org.objectweb.ccm.IDL3.DeclarationKind._dk_consumes : 361 return ((org.objectweb.ccm.IDL3.ConsumesDecl)obj).getType(); 362 case org.objectweb.ccm.IDL3.DeclarationKind._dk_operation : 363 return ((org.objectweb.ccm.IDL3.OperationDecl)obj).getType(); 364 case org.objectweb.ccm.IDL3.DeclarationKind._dk_provides : 365 return ((org.objectweb.ccm.IDL3.ProvidesDecl)obj).getType(); 366 case org.objectweb.ccm.IDL3.DeclarationKind._dk_union : 367 return ((org.objectweb.ccm.IDL3.UnionDecl)obj).getType(); 368 case org.objectweb.ccm.IDL3.DeclarationKind._dk_uses : 369 return ((org.objectweb.ccm.IDL3.UsesDecl)obj).getType(); 370 case org.objectweb.ccm.IDL3.DeclarationKind._dk_value_box : 371 return ((org.objectweb.ccm.IDL3.ValueBoxDecl)obj).getType(); 372 case org.objectweb.ccm.IDL3.DeclarationKind._dk_value_member : 373 return ((org.objectweb.ccm.IDL3.ValueMemberDecl)obj).getType(); 374 default : 375 return null; 376 } 377 } 378 379 382 public JavaTranslator 383 getTranslator() 384 { 385 return translator_; 386 } 387 } 388 | Popular Tags |