1 16 package org.apache.axis.wsdl.gen; 17 18 import org.apache.axis.utils.Messages; 19 import org.apache.axis.wsdl.symbolTable.BindingEntry; 20 import org.apache.axis.wsdl.symbolTable.CollectionElement; 21 import org.apache.axis.wsdl.symbolTable.MessageEntry; 22 import org.apache.axis.wsdl.symbolTable.PortTypeEntry; 23 import org.apache.axis.wsdl.symbolTable.ServiceEntry; 24 import org.apache.axis.wsdl.symbolTable.SymTabEntry; 25 import org.apache.axis.wsdl.symbolTable.SymbolTable; 26 import org.apache.axis.wsdl.toJava.Utils; 27 import org.apache.axis.wsdl.symbolTable.Type; 28 import org.apache.axis.wsdl.symbolTable.TypeEntry; 29 import org.w3c.dom.Document ; 30 import org.xml.sax.SAXException ; 31 32 import javax.wsdl.Binding; 33 import javax.wsdl.Definition; 34 import javax.wsdl.WSDLException; 35 import javax.xml.parsers.ParserConfigurationException ; 36 import java.io.IOException ; 37 import java.util.Collection ; 38 import java.util.Iterator ; 39 import java.util.Map ; 40 import java.util.Vector ; 41 42 45 public class Parser { 46 47 48 protected boolean debug = false; 49 50 51 protected boolean quiet = false; 52 53 54 protected boolean imports = true; 55 56 57 protected boolean verbose = false; 58 59 60 protected boolean nowrap = false; 61 62 64 65 protected String username = null; 66 67 68 protected String password = null; 69 70 71 protected boolean wrapArrays = false; 72 73 75 76 private long timeoutms = 45000; 78 79 private GeneratorFactory genFactory = null; 80 81 82 private SymbolTable symbolTable = null; 83 84 89 public boolean isDebug() { 90 return debug; 91 } 93 98 public void setDebug(boolean debug) { 99 this.debug = debug; 100 } 102 107 public boolean isQuiet() { 108 return quiet; 109 } 110 111 116 public void setQuiet(boolean quiet) { 117 this.quiet = quiet; 118 } 119 120 125 public boolean isImports() { 126 return imports; 127 } 129 134 public void setImports(boolean imports) { 135 this.imports = imports; 136 } 138 143 public boolean isVerbose() { 144 return verbose; 145 } 147 152 public void setVerbose(boolean verbose) { 153 this.verbose = verbose; 154 } 156 161 public boolean isNowrap() { 162 return nowrap; 163 } 164 165 170 public void setNowrap(boolean nowrap) { 171 this.nowrap = nowrap; 172 } 173 174 179 public long getTimeout() { 180 return timeoutms; 181 } 182 183 188 public void setTimeout(long timeout) { 189 this.timeoutms = timeout; 190 } 191 192 197 public String getUsername() { 198 return username; 199 } 201 206 public void setUsername(String username) { 207 this.username = username; 208 } 210 215 public String getPassword() { 216 return password; 217 } 219 224 public void setPassword(String password) { 225 this.password = password; 226 } 228 233 public GeneratorFactory getFactory() { 234 return genFactory; 235 } 237 242 public void setFactory(GeneratorFactory factory) { 243 this.genFactory = factory; 244 } 246 252 public SymbolTable getSymbolTable() { 253 return symbolTable; 254 } 256 262 public Definition getCurrentDefinition() { 263 264 return (symbolTable == null) 265 ? null 266 : symbolTable.getDefinition(); 267 } 269 275 public String getWSDLURI() { 276 277 return (symbolTable == null) 278 ? null 279 : symbolTable.getWSDLURI(); 280 } 282 291 public void run(String wsdlURI) throws Exception { 292 293 if (getFactory() == null) { 294 setFactory(new NoopFactory()); 295 } 296 297 symbolTable = new SymbolTable(genFactory.getBaseTypeMapping(), imports, 298 verbose, nowrap); 299 symbolTable.setQuiet(quiet); 300 symbolTable.setWrapArrays(wrapArrays); 301 302 WSDLRunnable runnable = new WSDLRunnable(symbolTable, wsdlURI); 304 Thread wsdlThread = new Thread (runnable); 305 306 wsdlThread.start(); 307 308 try { 309 if (timeoutms > 0) { 310 wsdlThread.join(timeoutms); 311 } else { 312 wsdlThread.join(); 313 } 314 } catch (InterruptedException e) { 315 } 316 317 if (wsdlThread.isAlive()) { 318 wsdlThread.interrupt(); 319 320 throw new IOException (Messages.getMessage("timedOut")); 321 } 322 323 if (runnable.getFailure() != null) { 324 throw runnable.getFailure(); 325 } 326 } 328 333 private class WSDLRunnable implements Runnable { 334 335 336 private SymbolTable symbolTable; 337 338 339 private String wsdlURI; 340 341 342 private Exception failure = null; 343 344 350 public WSDLRunnable(SymbolTable symbolTable, String wsdlURI) { 351 this.symbolTable = symbolTable; 352 this.wsdlURI = wsdlURI; 353 } 355 358 public void run() { 359 360 try { 361 symbolTable.populate(wsdlURI, username, password); 362 generate(symbolTable); 363 } catch (Exception e) { 364 failure = e; 365 } 366 } 368 373 public Exception getFailure() { 374 return failure; 375 } } 378 388 public void run(String context, Document doc) 389 throws IOException , SAXException , WSDLException, 390 ParserConfigurationException { 391 392 if (getFactory() == null) { 393 setFactory(new NoopFactory()); 394 } 395 396 symbolTable = new SymbolTable(genFactory.getBaseTypeMapping(), imports, 397 verbose, nowrap); 398 399 symbolTable.populate(context, doc); 400 generate(symbolTable); 401 } 403 408 protected void sanityCheck(SymbolTable symbolTable) { 409 410 } 412 413 419 private void generate(SymbolTable symbolTable) throws IOException { 420 421 sanityCheck(symbolTable); 422 423 Definition def = symbolTable.getDefinition(); 424 425 genFactory.generatorPass(def, symbolTable); 426 427 if (isDebug()) { 428 symbolTable.dump(System.out); 429 } 430 431 generateTypes(symbolTable); 433 434 Iterator it = symbolTable.getHashMap().values().iterator(); 435 436 while (it.hasNext()) { 437 Vector v = (Vector ) it.next(); 438 439 for (int i = 0; i < v.size(); ++i) { 440 SymTabEntry entry = (SymTabEntry) v.elementAt(i); 441 Generator gen = null; 442 443 if (entry instanceof MessageEntry) { 444 gen = genFactory.getGenerator( 445 ((MessageEntry) entry).getMessage(), symbolTable); 446 } else if (entry instanceof PortTypeEntry) { 447 PortTypeEntry pEntry = (PortTypeEntry) entry; 448 449 if (pEntry.getPortType().isUndefined()) { 453 continue; 454 } 455 456 gen = genFactory.getGenerator(pEntry.getPortType(), 457 symbolTable); 458 } else if (entry instanceof BindingEntry) { 459 BindingEntry bEntry = (BindingEntry) entry; 460 Binding binding = bEntry.getBinding(); 461 462 if (binding.isUndefined() || !bEntry.isReferenced()) { 466 continue; 467 } 468 469 gen = genFactory.getGenerator(binding, symbolTable); 470 } else if (entry instanceof ServiceEntry) { 471 gen = genFactory.getGenerator( 472 ((ServiceEntry) entry).getService(), symbolTable); 473 } 474 475 if (gen != null) { 476 gen.generate(); 477 } 478 } 479 } 480 481 Generator gen = genFactory.getGenerator(def, symbolTable); 484 485 gen.generate(); 486 } 488 495 private void generateTypes(SymbolTable symbolTable) throws IOException { 496 497 Map elements = symbolTable.getElementIndex(); 498 Collection elementCollection = elements.values(); 499 for (Iterator i = elementCollection.iterator(); i.hasNext(); ) { 500 TypeEntry type = (TypeEntry) i.next(); 501 502 boolean isType = ((type instanceof Type) 511 || (type instanceof CollectionElement)); 512 513 if ((type.getNode() != null) 514 && !Utils.isXsNode(type.getNode(), "attributeGroup") 515 && !Utils.isXsNode(type.getNode(), "group") 516 && type.isReferenced() && isType 517 && (type.getBaseType() == null)) { 518 Generator gen = genFactory.getGenerator(type, symbolTable); 519 520 gen.generate(); 521 } 522 } 523 524 Map types = symbolTable.getTypeIndex(); 525 Collection typeCollection = types.values(); 526 for (Iterator i = typeCollection.iterator(); i.hasNext(); ) { 527 TypeEntry type = (TypeEntry) i.next(); 528 529 boolean isType = ((type instanceof Type) 538 || (type instanceof CollectionElement)); 539 540 if ((type.getNode() != null) 541 && !Utils.isXsNode(type.getNode(), "attributeGroup") 542 && !Utils.isXsNode(type.getNode(), "group") 543 && type.isReferenced() && isType 544 && (type.getBaseType() == null)) { 545 Generator gen = genFactory.getGenerator(type, symbolTable); 546 547 gen.generate(); 548 } 549 } 550 } } | Popular Tags |