1 package org.jacorb.idl; 2 3 22 23 24 import java.io.File ; 25 import java.io.PrintWriter ; 26 import java.util.*; 27 28 36 37 public class ValueAbsDecl 38 extends Value 39 { 40 ValueBody body = null; 41 ValueInheritanceSpec inheritanceSpec; 42 43 public ValueAbsDecl(int num) 44 { 45 super(num); 46 pack_name = ""; 47 } 48 49 public void setPackage(String s) 50 { 51 s = parser.pack_replace(s); 52 if (pack_name.length() > 0) 53 pack_name = s + "." + pack_name; 54 else 55 pack_name = s; 56 57 if (body != null) body.setPackage(s); 60 if (inheritanceSpec != null) 61 inheritanceSpec.setPackage(s); 62 } 63 64 public void setInheritanceSpec(ValueInheritanceSpec spec) 65 { 66 inheritanceSpec = spec; 67 } 68 69 public ValueInheritanceSpec setInheritanceSpec() 70 { 71 return inheritanceSpec; 72 } 73 74 public TypeDeclaration declaration() 75 { 76 return this; 77 }; 78 79 public String typeName() 80 { 81 return full_name(); 82 } 83 84 85 public Object clone() 86 { 87 throw new RuntimeException ("Don't clone me, i am an interface!"); 88 } 89 90 91 public void setEnclosingSymbol(IdlSymbol s) 92 { 93 if (enclosing_symbol != null && enclosing_symbol != s) 94 { 95 logger.error("was " + enclosing_symbol.getClass().getName() + 96 " now: " + s.getClass().getName()); 97 throw new RuntimeException ("Compiler Error: trying to reassign container for " + name); 98 } 99 enclosing_symbol = s; 100 } 101 102 103 public boolean basic() 104 { 105 return true; 106 } 107 108 109 public String holderName() 110 { 111 return javaName() + "Holder"; 112 } 113 114 public String toString() 115 { 116 String n = typeName(); 117 if (!n.startsWith("org.omg")) 118 { 119 return omgPrefix() + n; 120 } 121 else 122 return n; 123 } 124 125 126 public void set_included(boolean i) 127 { 128 included = i; 129 } 130 131 132 public void parse() 133 { 134 boolean justAnotherOne = false; 135 136 escapeName(); 137 138 ConstrTypeSpec ctspec = new ConstrTypeSpec(new_num()); 139 try 140 { 141 ScopedName.definePseudoScope(full_name()); 142 ctspec.c_type_spec = this; 143 144 NameTable.define(full_name(), "type"); 145 TypeMap.typedef(full_name(), ctspec); 146 } 147 catch (IllegalRedefinition ill) 148 { 149 parser.fatal_error("Illegal Redefinition of " + 150 ill.oldDef + " in nested scope as " + ill.newDef, token); 151 } 152 catch (NameAlreadyDefined nad) 153 { 154 159 if (body != null) 160 { 161 justAnotherOne = true; 162 } 163 164 if (!full_name().equals("org.omg.CORBA.TypeCode") && body != null) 165 { 166 TypeMap.replaceForwardDeclaration(full_name(), ctspec); 167 } 168 } 169 170 if (body != null) 171 { 172 if (inheritanceSpec != null && inheritanceSpec.v.size() > 0) 173 { 174 if (logger.isDebugEnabled()) 175 logger.debug("Checking inheritanceSpec of " + full_name()); 176 for (Enumeration e = inheritanceSpec.v.elements(); e.hasMoreElements();) 177 { 178 ScopedName name = (ScopedName)e.nextElement(); 179 180 TypeSpec resolvedTSpec = name.resolvedTypeSpec(); 181 182 if (parser.strict_inheritance) 185 { 186 while (resolvedTSpec instanceof AliasTypeSpec ) 188 { 189 resolvedTSpec = 190 ((AliasTypeSpec)resolvedTSpec).originalType(); 191 } 192 193 if (! (resolvedTSpec instanceof ConstrTypeSpec)) 194 { 195 if (logger.isDebugEnabled()) 196 { 197 logger.debug("Illegal inheritance spec, not a constr. type but " + 198 resolvedTSpec.getClass() + ", name " + name ); 199 } 200 parser.fatal_error("Illegal inheritance spec (not a constr. type): " + 201 inheritanceSpec, token); 202 } 203 204 ConstrTypeSpec ts = (ConstrTypeSpec)resolvedTSpec; 205 if (!(ts.declaration() instanceof Interface) && 206 !(ts.declaration() instanceof ValueAbsDecl)) 207 { 208 parser.fatal_error("Illegal inheritance spec (not an intf. or abs. value type): " + 209 inheritanceSpec, token); 210 } 211 } 212 } 213 body.set_ancestors(inheritanceSpec); 214 } 215 body.parse(); 216 NameTable.parsed_interfaces.put(full_name(), ""); 217 } 218 else if (!justAnotherOne) 219 { 220 parser.set_pending(full_name()); 223 } 224 } 225 226 227 ValueBody getBody() 228 { 229 if (parser.get_pending(full_name()) != null) 230 { 231 parser.fatal_error(full_name() + " is forward declared and still pending!", token); 232 } 233 else if (body == null) 234 { 235 if (((ValueAbsDecl)((ConstrTypeSpec)TypeMap.map(full_name())).c_type_spec) != this) 236 body = ((ValueAbsDecl)((ConstrTypeSpec)TypeMap.map(full_name())).c_type_spec).getBody(); 237 if (body == null) 238 parser.fatal_error(full_name() + " still has an empty body!", token); 239 } 240 return body; 241 } 242 243 public String getTypeCodeExpression() 244 { 245 return this.getTypeCodeExpression(new HashSet()); 246 } 247 248 public String getTypeCodeExpression(Set knownTypes) 249 { 250 if (knownTypes.contains(this)) 251 { 252 return this.getRecursiveTypeCodeExpression(); 253 } 254 else 255 { 256 knownTypes.add(this); 257 258 return "org.omg.CORBA.ORB.init().create_value_tc(\"" + id() + 259 "\", \"" + name + 260 "\", org.omg.CORBA.VM_ABSTRACT.value " + 261 ", null, null)"; 262 } 263 } 264 265 266 public String printReadExpression(String streamname) 267 { 268 return "(" + javaName() + ")" 269 + "((org.omg.CORBA_2_3.portable.InputStream)" + streamname + ")" 270 + ".read_value (\"" + id() + "\")"; 271 } 272 273 public String printReadStatement(String var_name, String streamname) 274 { 275 return var_name + " = " + printReadExpression(streamname); 276 } 277 278 public String printWriteStatement(String var_name, String streamname) 279 { 280 return "((org.omg.CORBA_2_3.portable.OutputStream)" + streamname + ")" 281 + ".write_value (" + var_name + ");"; 282 } 283 284 285 private void printClassComment(String className, PrintWriter ps) 286 { 287 ps.println("/**"); 288 ps.println(" *\tGenerated from IDL definition of abstract value type " + 289 "\"" + className + "\""); 290 ps.println(" *\t@author JacORB IDL compiler "); 291 ps.println(" */\n"); 292 } 293 294 298 299 public void print(PrintWriter unused) 300 { 301 if (included && !generateIncluded()) 302 return; 303 304 if (body != null) { 307 try 308 { 309 311 String path = 312 parser.out_dir + fileSeparator + pack_name.replace('.', fileSeparator); 313 File dir = new File (path); 314 if (!dir.exists()) 315 { 316 if (!dir.mkdirs()) 317 { 318 org.jacorb.idl.parser.fatal_error("Unable to create " + path, null); 319 } 320 } 321 322 File f = new File (dir, name + ".java"); 323 324 if (GlobalInputStream.isMoreRecentThan(f)) 325 { 326 PrintWriter ps = new PrintWriter (new java.io.FileWriter (f)); 327 328 if (Environment.JAVA14 && pack_name.equals("")) 329 lexer.emit_warn 330 ("No package defined for " + name + " - illegal in JDK1.4", token); 331 if (!pack_name.equals("")) 332 ps.println("package " + pack_name + ";\n"); 333 334 printClassComment(name, ps); 335 336 339 if (inheritanceSpec != null && inheritanceSpec.v.size() > 0) 340 { 341 Enumeration e = inheritanceSpec.v.elements(); 342 for (; e.hasMoreElements();) 343 { 344 ScopedName sn = (ScopedName)e.nextElement(); 345 if (sn.resolvedName().indexOf('.') < 0) 346 { 347 ps.println("import " + sn + "Operations;"); 348 } 349 } 350 } 351 printImport(ps); 352 353 ps.println("public interface " + name); 354 ps.print("\textends org.omg.CORBA.portable.ValueBase "); 355 356 if (inheritanceSpec != null && inheritanceSpec.v.size() > 0) 357 { 358 for (Enumeration e = inheritanceSpec.v.elements(); e.hasMoreElements();) 359 { 360 ps.print(", " + (ScopedName)e.nextElement()); 361 } 362 } 363 364 ps.println("\n{"); 365 if (body != null) 366 { 367 body.printOperationSignatures(ps); 369 } 370 ps.println("}"); 371 ps.close(); 372 } 373 } 374 catch (java.io.IOException i) 375 { 376 throw new RuntimeException ("File IO error" + i); 377 } 378 } 379 } 380 381 public void accept(IDLTreeVisitor visitor) 382 { 383 visitor.visitValue(this); 384 } 385 } 386 | Popular Tags |