| 1 16 package org.apache.axis.wsdl.symbolTable; 17 18 import org.apache.axis.Constants; 19 import org.apache.axis.constants.Style; 20 import org.apache.axis.constants.Use; 21 import org.apache.axis.utils.Messages; 22 import org.apache.axis.utils.URLHashSet; 23 import org.apache.axis.utils.XMLUtils; 24 import org.w3c.dom.Document ; 25 import org.w3c.dom.NamedNodeMap ; 26 import org.w3c.dom.Node ; 27 import org.w3c.dom.NodeList ; 28 import org.xml.sax.SAXException ; 29 30 import javax.wsdl.Binding; 31 import javax.wsdl.BindingFault; 32 import javax.wsdl.BindingInput; 33 import javax.wsdl.BindingOperation; 34 import javax.wsdl.BindingOutput; 35 import javax.wsdl.Definition; 36 import javax.wsdl.Fault; 37 import javax.wsdl.Import; 38 import javax.wsdl.Input; 39 import javax.wsdl.Message; 40 import javax.wsdl.Operation; 41 import javax.wsdl.Output; 42 import javax.wsdl.Part; 43 import javax.wsdl.Port; 44 import javax.wsdl.PortType; 45 import javax.wsdl.Service; 46 import javax.wsdl.WSDLException; 47 import javax.wsdl.extensions.ExtensibilityElement; 48 import javax.wsdl.extensions.UnknownExtensibilityElement; 49 import javax.wsdl.extensions.http.HTTPBinding; 50 import javax.wsdl.extensions.mime.MIMEContent; 51 import javax.wsdl.extensions.mime.MIMEMultipartRelated; 52 import javax.wsdl.extensions.mime.MIMEPart; 53 import javax.wsdl.extensions.soap.SOAPBinding; 54 import javax.wsdl.extensions.soap.SOAPBody; 55 import javax.wsdl.extensions.soap.SOAPFault; 56 import javax.wsdl.extensions.soap.SOAPHeader; 57 import javax.wsdl.extensions.soap.SOAPHeaderFault; 58 import javax.wsdl.factory.WSDLFactory; 59 import javax.wsdl.xml.WSDLReader; 60 import javax.xml.namespace.QName ; 61 import javax.xml.parsers.ParserConfigurationException ; 62 import javax.xml.rpc.holders.BooleanHolder ; 63 import javax.xml.rpc.holders.IntHolder ; 64 import javax.xml.rpc.holders.QNameHolder ; 65 import java.io.File ; 66 import java.io.IOException ; 67 import java.net.MalformedURLException ; 68 import java.net.URL ; 69 import java.util.ArrayList ; 70 import java.util.Collection ; 71 import java.util.Collections ; 72 import java.util.HashMap ; 73 import java.util.HashSet ; 74 import java.util.Iterator ; 75 import java.util.List ; 76 import java.util.Map ; 77 import java.util.Set ; 78 import java.util.Vector ; 79 80 91 public class SymbolTable { 92 93 protected HashMap derivedTypes = new HashMap (); 95 96 98 99 private boolean addImports; 100 101 110 111 private HashMap symbolTable = new HashMap (); 112 113 115 116 private final Map elementTypeEntries = new HashMap (); 117 118 120 121 private final Map elementIndex = 122 Collections.unmodifiableMap(elementTypeEntries); 123 124 126 127 private final Map typeTypeEntries = new HashMap (); 128 129 131 132 private final Map typeIndex = Collections.unmodifiableMap(typeTypeEntries); 133 134 139 protected final Map node2ExtensionBase = 140 new HashMap (); 142 143 private boolean verbose; 144 145 146 protected boolean quiet; 147 148 149 private BaseTypeMapping btm = null; 150 151 153 154 private boolean nowrap; 155 156 158 159 private boolean wrapped = false; 160 161 162 public static final String ANON_TOKEN = ">"; 163 164 165 private Definition def = null; 166 167 168 private String wsdlURI = null; 169 170 174 private boolean wrapArrays; 175 176 Set arrayTypeQNames = new HashSet(); 177 178 179 private final Map elementFormDefaults = new HashMap (); 180 188 public SymbolTable(BaseTypeMapping btm, boolean addImports, 189 boolean verbose, boolean nowrap) { 190 191 this.btm = btm; 192 this.addImports = addImports; 193 this.verbose = verbose; 194 this.nowrap = nowrap; 195 } 197 202 public boolean isQuiet() { 203 return quiet; 204 } 205 206 211 public void setQuiet(boolean quiet) { 212 this.quiet = quiet; 213 } 214 215 220 public HashMap getHashMap() { 221 return symbolTable; 222 } 224 231 public Vector getSymbols(QName qname) { 232 return (Vector ) symbolTable.get(qname); 233 } 235 242 public SymTabEntry get(QName qname, Class cls) { 243 244 Vector v = (Vector ) symbolTable.get(qname); 245 246 if (v == null) { 247 return null; 248 } else { 249 for (int i = 0; i < v.size(); ++i) { 250 SymTabEntry entry = (SymTabEntry) v.elementAt(i); 251 252 if (cls.isInstance(entry)) { 253 return entry; 254 } 255 } 256 257 return null; 258 } 259 } 261 268 public TypeEntry getTypeEntry(QName qname, boolean wantElementType) { 269 270 if (wantElementType) { 271 return getElement(qname); 272 } else { 273 return getType(qname); 274 } 275 } 277 284 public Type getType(QName qname) { 285 return (Type) typeTypeEntries.get(qname); 286 } 288 295 public Element getElement(QName qname) { 296 return (Element) elementTypeEntries.get(qname); 297 } 299 305 public MessageEntry getMessageEntry(QName qname) { 306 return (MessageEntry) get(qname, MessageEntry.class); 307 } 309 315 public PortTypeEntry getPortTypeEntry(QName qname) { 316 return (PortTypeEntry) get(qname, PortTypeEntry.class); 317 } 319 325 public BindingEntry getBindingEntry(QName qname) { 326 return (BindingEntry) get(qname, BindingEntry.class); 327 } 329 335 public ServiceEntry getServiceEntry(QName qname) { 336 return (ServiceEntry) get(qname, ServiceEntry.class); 337 } 339 346 public Vector getTypes() { 347 348 Vector v = new Vector (); 349 350 v.addAll(elementTypeEntries.values()); 351 v.addAll(typeTypeEntries.values()); 352 353 return v; 354 } 356 362 public Map getElementIndex() { 363 return elementIndex; 364 } 365 366 372 public Map getTypeIndex() { 373 return typeIndex; 374 } 375 376 381 public int getTypeEntryCount() { 382 return elementTypeEntries.size() + typeTypeEntries.size(); 383 } 384 385 391 public Definition getDefinition() { 392 return def; 393 } 395 401 public String getWSDLURI() { 402 return wsdlURI; 403 } 405 410 public boolean isWrapped() { 411 return wrapped; 412 } 413 414 419 public void setWrapped(boolean wrapped) { 420 this.wrapped = wrapped; 421 } 422 423 428 public void dump(java.io.PrintStream out) { 429 430 out.println(); 431 out.println(Messages.getMessage("symbolTable00")); 432 out.println("-----------------------"); 433 434 Iterator it = symbolTable.values().iterator(); 435 436 while (it.hasNext()) { 437 Vector v = (Vector ) it.next(); 438 439 for (int i = 0; i < v.size(); ++i) { 440 out.println(v.elementAt(i).getClass().getName()); 441 out.println(v.elementAt(i)); 442 } 443 } 444 445 out.println("-----------------------"); 446 } 448 457 public void populate(String uri) 458 throws IOException , WSDLException, SAXException , 459 ParserConfigurationException { 460 populate(uri, null, null); 461 } 463 474 public void populate(String uri, String username, String password) 475 throws IOException , WSDLException, SAXException , 476 ParserConfigurationException { 477 478 if (verbose) { 479 System.out.println(Messages.getMessage("parsing00", uri)); 480 } 481 482 Document doc = XMLUtils.newDocument(uri, username, password); 483 484 this.wsdlURI = uri; 485 486 try { 487 File f = new File (uri); 488 489 if (f.exists()) { 490 uri = f.toURL().toString(); 491 } 492 } catch (Exception e) { 493 } 494 495 populate(uri, doc); 496 } 498 508 public void populate(String context, Document doc) 509 throws IOException , SAXException , WSDLException, 510 ParserConfigurationException { 511 512 WSDLReader reader = WSDLFactory.newInstance().newWSDLReader(); 513 514 reader.setFeature("javax.wsdl.verbose", verbose); 515 516 this.def = reader.readWSDL(context, doc); 517 518 add(context, def, doc); 519 } 521 535 protected void add(String context, Definition def, Document doc) 536 throws IOException , SAXException , WSDLException, 537 ParserConfigurationException { 538 539 URL contextURL = (context == null) 540 ? null 541 : getURL(null, context); 542 543 populate(contextURL, def, doc, null); 544 processTypes(); 545 checkForUndefined(); 546 populateParameters(); 547 setReferences(def, doc); } 550 557 private void checkForUndefined(Definition def, String filename) 558 throws IOException { 559 560 if (def != null) { 561 562 Iterator ib = def.getBindings().values().iterator(); 564 565 while (ib.hasNext()) { 566 Binding binding = (Binding) ib.next(); 567 568 if (binding.isUndefined()) { 569 if (filename == null) { 570 throw new IOException ( 571 Messages.getMessage( 572 "emitFailtUndefinedBinding01", 573 binding.getQName().getLocalPart())); 574 } else { 575 throw new IOException ( 576 Messages.getMessage( 577 "emitFailtUndefinedBinding02", 578 binding.getQName().getLocalPart(), filename)); 579 } 580 } 581 } 582 583 Iterator ip = def.getPortTypes().values().iterator(); 585 586 while (ip.hasNext()) { 587 PortType portType = (PortType) ip.next(); 588 589 if (portType.isUndefined()) { 590 if (filename == null) { 591 throw new IOException ( 592 Messages.getMessage( 593 "emitFailtUndefinedPort01", 594 portType.getQName().getLocalPart())); 595 } else { 596 throw new IOException ( 597 Messages.getMessage( 598 "emitFailtUndefinedPort02", 599 portType.getQName().getLocalPart(), filename)); 600 } 601 } 602 } 603 604 621 } 622 } 623 624 629 private void checkForUndefined() throws IOException { 630 631 Iterator it = symbolTable.values().iterator(); 632 633 while (it.hasNext()) { 634 Vector v = (Vector ) it.next(); 635 636 for (int i = 0; i < v.size(); ++i) { 637 SymTabEntry entry = (SymTabEntry) v.get(i); 638 639 if (entry instanceof UndefinedType) { 641 QName qn = entry.getQName(); 642 643 if ((qn.getLocalPart().equals( 646 "dateTime") && !qn.getNamespaceURI().equals( 647 Constants.URI_2001_SCHEMA_XSD)) || (qn.getLocalPart().equals( 648 "timeInstant") && qn.getNamespaceURI().equals( 649 Constants.URI_2001_SCHEMA_XSD))) { 650 throw new IOException ( 651 Messages.getMessage( 652 "wrongNamespace00", qn.getLocalPart(), 653 qn.getNamespaceURI())); 654 } 655 656 if (SchemaUtils.isSimpleSchemaType(qn)) { 659 throw new IOException ( 660 Messages.getMessage( 661 "unsupportedSchemaType00", qn.getLocalPart())); 662 } 663 664 throw new IOException ( 666 Messages.getMessage( 667 "undefined00", qn.toString())); 668 } else if (entry instanceof UndefinedElement) { 670 throw new IOException ( 671 Messages.getMessage( 672 "undefinedElem00", entry.getQName().toString())); 673 } 674 } 675 } 676 } 678 685 private URLHashSet importedFiles = new URLHashSet(); 686 687 699 private void populate( 700 URL context, Definition def, Document doc, String filename) 701 throws IOException , ParserConfigurationException , SAXException , 702 WSDLException { 703 704 if (doc != null) { 705 populateTypes(context, doc); 706 707 if (addImports) { 708 709 lookForImports(context, doc); 711 } 712 } 713 714 if (def != null) { 715 checkForUndefined(def, filename); 716 717 if (addImports) { 718 719 Map imports = def.getImports(); 721 Object [] importKeys = imports.keySet().toArray(); 722 723 for (int i = 0; i < importKeys.length; ++i) { 724 Vector v = (Vector ) imports.get(importKeys[i]); 725 726 for (int j = 0; j < v.size(); ++j) { 727 Import imp = (Import) v.get(j); 728 729 if (!importedFiles.contains(imp.getLocationURI())) { 730 importedFiles.add(imp.getLocationURI()); 731 732 URL url = getURL(context, imp.getLocationURI()); 733 734 populate(url, imp.getDefinition(), 735 XMLUtils.newDocument(url.toString()), 736 url.toString()); 737 } 738 } 739 } 740 } 741 742 populateMessages(def); 743 populatePortTypes(def); 744 populateBindings(def); 745 populateServices(def); 746 } 747 } 749 758 private static URL getURL(URL contextURL, String spec) throws IOException { 759 760 String path = spec.replace('\\', '/'); 764 765 URL url = null; 767 768 try { 769 770 url = new URL (contextURL, path); 772 773 if ((contextURL != null) && url.getProtocol().equals("file") 776 && contextURL.getProtocol().equals("file")) { 777 url = getFileURL(contextURL, path); 778 } 779 } catch (MalformedURLException me) { 780 781 url = getFileURL(contextURL, path); 783 } 784 785 return url; 789 } 791 799 private static URL getFileURL(URL contextURL, String path) 800 throws IOException { 801 802 if (contextURL != null) { 803 804 String contextFileName = contextURL.getFile(); 807 URL parent = null; 808 File parentFile = new File (contextFileName).getParentFile(); 809 if ( parentFile != null ) { 810 parent = parentFile.toURL(); 811 } 812 if (parent != null) { 813 return new URL (parent, path); 814 } 815 } 816 817 return new URL ("file", "", path); 818 } |