1 55 package org.jboss.axis.wsdl.gen; 56 57 import org.jboss.axis.utils.Messages; 58 import org.jboss.axis.wsdl.symbolTable.BindingEntry; 59 import org.jboss.axis.wsdl.symbolTable.CollectionElement; 60 import org.jboss.axis.wsdl.symbolTable.MessageEntry; 61 import org.jboss.axis.wsdl.symbolTable.PortTypeEntry; 62 import org.jboss.axis.wsdl.symbolTable.ServiceEntry; 63 import org.jboss.axis.wsdl.symbolTable.SymTabEntry; 64 import org.jboss.axis.wsdl.symbolTable.SymbolTable; 65 import org.jboss.axis.wsdl.symbolTable.Type; 66 import org.jboss.axis.wsdl.symbolTable.TypeEntry; 67 import org.w3c.dom.Document ; 68 import org.xml.sax.SAXException ; 69 70 import javax.wsdl.Binding; 71 import javax.wsdl.Definition; 72 import javax.wsdl.WSDLException; 73 import javax.xml.parsers.ParserConfigurationException ; 74 import java.io.IOException ; 75 import java.util.Iterator ; 76 import java.util.Vector ; 77 78 81 public class Parser 82 { 83 84 protected boolean debug = false; 85 protected boolean imports = true; 86 protected boolean verbose = false; 87 protected boolean nowrap = false; 88 89 protected String username = null; 91 protected String password = null; 92 93 private long timeoutms = 45000; 96 private GeneratorFactory genFactory = null; 97 private SymbolTable symbolTable = null; 98 99 public boolean isDebug() 100 { 101 return debug; 102 } 104 public void setDebug(boolean debug) 105 { 106 this.debug = debug; 107 } 109 public boolean isImports() 110 { 111 return imports; 112 } 114 public void setImports(boolean imports) 115 { 116 this.imports = imports; 117 } 119 public boolean isVerbose() 120 { 121 return verbose; 122 } 124 public void setVerbose(boolean verbose) 125 { 126 this.verbose = verbose; 127 } 129 public boolean isNowrap() 130 { 131 return nowrap; 132 } 133 134 public void setNowrap(boolean nowrap) 135 { 136 this.nowrap = nowrap; 137 } 138 139 142 public long getTimeout() 143 { 144 return timeoutms; 145 } 146 147 150 public void setTimeout(long timeout) 151 { 152 this.timeoutms = timeout; 153 } 154 155 public String getUsername() 156 { 157 return username; 158 } 160 public void setUsername(String username) 161 { 162 this.username = username; 163 } 165 public String getPassword() 166 { 167 return password; 168 } 170 public void setPassword(String password) 171 { 172 this.password = password; 173 } 175 public GeneratorFactory getFactory() 176 { 177 return genFactory; 178 } 180 public void setFactory(GeneratorFactory factory) 181 { 182 this.genFactory = factory; 183 } 185 189 public SymbolTable getSymbolTable() 190 { 191 return symbolTable; 192 } 194 198 public Definition getCurrentDefinition() 199 { 200 return symbolTable == null ? null : symbolTable.getDefinition(); 201 } 203 207 public String getWSDLURI() 208 { 209 return symbolTable == null ? null : symbolTable.getWSDLURI(); 210 } 212 218 public void run(String wsdlURI) throws Exception 219 { 220 if (getFactory() == null) 221 { 222 setFactory(new NoopFactory()); 223 } 224 symbolTable = new SymbolTable(genFactory.getBaseTypeMapping(), 225 imports, 226 verbose, 227 nowrap); 228 229 WSDLRunnable runnable = new WSDLRunnable(symbolTable, wsdlURI); 231 Thread wsdlThread = new Thread (runnable); 232 wsdlThread.start(); 233 234 try 235 { 236 if (timeoutms > 0) 237 wsdlThread.join(timeoutms); 238 else 239 wsdlThread.join(); 240 } 241 catch (InterruptedException e) 242 { 243 } 244 245 if (wsdlThread.isAlive()) 246 { 247 wsdlThread.interrupt(); 248 throw new IOException (Messages.getMessage("timedOut")); 249 } 250 251 if (runnable.getFailure() != null) 252 { 253 throw runnable.getFailure(); 254 } 255 } 257 private class WSDLRunnable implements Runnable 258 { 259 private SymbolTable symbolTable; 260 private String wsdlURI; 261 private Exception failure = null; 262 263 public WSDLRunnable(SymbolTable symbolTable, String wsdlURI) 264 { 265 this.symbolTable = symbolTable; 266 this.wsdlURI = wsdlURI; 267 } 269 public void run() 270 { 271 try 272 { 273 symbolTable.populate(wsdlURI, username, password); 274 generate(symbolTable); 275 } 276 catch (Exception e) 277 { 278 failure = e; 279 } 280 } 282 public Exception getFailure() 283 { 284 return failure; 285 } } 288 294 public void run(String context, Document doc) 295 throws IOException , SAXException , WSDLException, 296 ParserConfigurationException 297 { 298 if (getFactory() == null) 299 { 300 setFactory(new NoopFactory()); 301 } 302 symbolTable = new SymbolTable(genFactory.getBaseTypeMapping(), 303 imports, 304 verbose, 305 nowrap); 306 symbolTable.populate(context, doc); 307 generate(symbolTable); 308 } 310 protected void sanityCheck(SymbolTable symbolTable) 311 { 312 } 314 315 private void generate(SymbolTable symbolTable) throws IOException 316 { 317 sanityCheck(symbolTable); 318 Definition def = symbolTable.getDefinition(); 319 genFactory.generatorPass(def, symbolTable); 320 if (isDebug()) 321 { 322 symbolTable.dump(System.out); 323 } 324 325 generateTypes(symbolTable); 327 328 Iterator it = symbolTable.getHashMap().values().iterator(); 329 while (it.hasNext()) 330 { 331 Vector v = (Vector )it.next(); 332 for (int i = 0; i < v.size(); ++i) 333 { 334 SymTabEntry entry = (SymTabEntry)v.elementAt(i); 335 Generator gen = null; 336 if (entry instanceof MessageEntry) 337 { 338 gen = genFactory.getGenerator(((MessageEntry)entry).getMessage(), symbolTable); 339 } 340 else if (entry instanceof PortTypeEntry) 341 { 342 PortTypeEntry pEntry = (PortTypeEntry)entry; 343 if (pEntry.getPortType().isUndefined()) 347 { 348 continue; 349 } 350 gen = genFactory.getGenerator(pEntry.getPortType(), symbolTable); 351 } 352 else if (entry instanceof BindingEntry) 353 { 354 BindingEntry bEntry = (BindingEntry)entry; 355 Binding binding = bEntry.getBinding(); 356 357 if (binding.isUndefined() || !bEntry.isReferenced()) 361 { 362 continue; 363 } 364 gen = genFactory.getGenerator(binding, symbolTable); 365 } 366 else if (entry instanceof ServiceEntry) 367 { 368 gen = genFactory.getGenerator(((ServiceEntry)entry).getService(), symbolTable); 369 } 370 if (gen != null) 371 { 372 gen.generate(); 373 } 374 } 375 } 376 377 Generator gen = genFactory.getGenerator(def, symbolTable); 380 gen.generate(); 381 } 383 387 private void generateTypes(SymbolTable symbolTable) throws IOException 388 { 389 Vector types = symbolTable.getTypes(); 390 for (int i = 0; i < types.size(); ++i) 391 { 392 TypeEntry type = (TypeEntry)types.elementAt(i); 393 394 402 boolean isType = (type instanceof Type || 404 type instanceof CollectionElement); 405 if (type.getNode() != null && 406 type.isReferenced() && 407 isType && 408 type.getBaseType() == null) 409 { 410 Generator gen = genFactory.getGenerator(type, symbolTable); 411 gen.generate(); 412 } 413 } 414 } 416 } | Popular Tags |