1 55 56 package org.jboss.axis.wsdl.symbolTable; 57 58 import org.jboss.axis.Constants; 59 import org.jboss.axis.enums.Style; 60 import org.jboss.axis.enums.Use; 61 import org.jboss.axis.utils.LinkedHashMap; 62 import org.jboss.axis.utils.Messages; 63 import org.jboss.axis.utils.URLHashSet; 64 import org.jboss.axis.utils.XMLUtils; 65 import org.jboss.logging.Logger; 66 import org.w3c.dom.Document ; 67 import org.w3c.dom.NamedNodeMap ; 68 import org.w3c.dom.Node ; 69 import org.w3c.dom.NodeList ; 70 import org.xml.sax.SAXException ; 71 72 import javax.wsdl.Binding; 73 import javax.wsdl.BindingFault; 74 import javax.wsdl.BindingInput; 75 import javax.wsdl.BindingOperation; 76 import javax.wsdl.BindingOutput; 77 import javax.wsdl.Definition; 78 import javax.wsdl.Fault; 79 import javax.wsdl.Import; 80 import javax.wsdl.Input; 81 import javax.wsdl.Message; 82 import javax.wsdl.Operation; 83 import javax.wsdl.Output; 84 import javax.wsdl.Part; 85 import javax.wsdl.Port; 86 import javax.wsdl.PortType; 87 import javax.wsdl.Service; 88 import javax.wsdl.WSDLException; 89 import javax.wsdl.extensions.UnknownExtensibilityElement; 90 import javax.wsdl.extensions.http.HTTPBinding; 91 import javax.wsdl.extensions.mime.MIMEContent; 92 import javax.wsdl.extensions.mime.MIMEMultipartRelated; 93 import javax.wsdl.extensions.mime.MIMEPart; 94 import javax.wsdl.extensions.soap.SOAPBinding; 95 import javax.wsdl.extensions.soap.SOAPBody; 96 import javax.wsdl.extensions.soap.SOAPFault; 97 import javax.wsdl.extensions.soap.SOAPHeader; 98 import javax.wsdl.extensions.soap.SOAPHeaderFault; 99 import javax.wsdl.factory.WSDLFactory; 100 import javax.wsdl.xml.WSDLReader; 101 import javax.xml.namespace.QName ; 102 import javax.xml.parsers.ParserConfigurationException ; 103 import javax.xml.rpc.holders.BooleanHolder ; 104 import javax.xml.rpc.holders.IntHolder ; 105 import java.io.File ; 106 import java.io.IOException ; 107 import java.net.MalformedURLException ; 108 import java.net.URL ; 109 import java.util.ArrayList ; 110 import java.util.Collection ; 111 import java.util.Collections ; 112 import java.util.HashMap ; 113 import java.util.HashSet ; 114 import java.util.Iterator ; 115 import java.util.List ; 116 import java.util.Map ; 117 import java.util.Vector ; 118 119 130 public class SymbolTable 131 { 132 private static final Logger log = Logger.getLogger(SymbolTable.class); 133 134 private boolean addImports; 136 137 146 private HashMap symbolTable = new HashMap(); 147 148 private final Map elementTypeEntries = new HashMap(); 150 private final Map elementIndex = Collections.unmodifiableMap(elementTypeEntries); 152 private final Map typeTypeEntries = new HashMap(); 154 private final Map typeIndex = Collections.unmodifiableMap(typeTypeEntries); 156 157 162 protected final Map node2ExtensionBase = new HashMap(); 164 private boolean verbose; 165 166 private BaseTypeMapping btm = null; 167 168 private boolean nowrap; 170 private boolean wrapped = false; 172 173 public static final String ANON_TOKEN = ">"; 174 175 private Definition def = null; 176 private String wsdlURI = null; 177 178 181 public SymbolTable(BaseTypeMapping btm, boolean addImports, 182 boolean verbose, boolean nowrap) 183 { 184 this.btm = btm; 185 this.addImports = addImports; 186 this.verbose = verbose; 187 this.nowrap = nowrap; 188 } 190 193 public HashMap getHashMap() 194 { 195 return symbolTable; 196 } 198 202 public Vector getSymbols(QName qname) 203 { 204 return (Vector )symbolTable.get(qname); 205 } 207 210 public SymTabEntry get(QName qname, Class cls) 211 { 212 Vector v = (Vector )symbolTable.get(qname); 213 if (v == null) 214 { 215 return null; 216 } 217 else 218 { 219 for (int i = 0; i < v.size(); ++i) 220 { 221 SymTabEntry entry = (SymTabEntry)v.elementAt(i); 222 if (cls.isInstance(entry)) 223 { 224 return entry; 225 } 226 } 227 return null; 228 } 229 } 231 232 238 public TypeEntry getTypeEntry(QName qname, boolean wantElementType) 239 { 240 if (wantElementType) 241 { 242 return getElement(qname); 243 } 244 else 245 return getType(qname); 246 } 248 252 public Type getType(QName qname) 253 { 254 return (Type)typeTypeEntries.get(qname); 255 } 257 261 public Element getElement(QName qname) 262 { 263 return (Element)elementTypeEntries.get(qname); 264 } 266 269 public MessageEntry getMessageEntry(QName qname) 270 { 271 return (MessageEntry)get(qname, MessageEntry.class); 272 } 274 277 public PortTypeEntry getPortTypeEntry(QName qname) 278 { 279 return (PortTypeEntry)get(qname, PortTypeEntry.class); 280 } 282 285 public BindingEntry getBindingEntry(QName qname) 286 { 287 return (BindingEntry)get(qname, BindingEntry.class); 288 } 290 293 public ServiceEntry getServiceEntry(QName qname) 294 { 295 return (ServiceEntry)get(qname, ServiceEntry.class); 296 } 298 304 public Vector getTypes() 305 { 306 Vector v = new Vector (); 307 v.addAll(elementTypeEntries.values()); 308 v.addAll(typeTypeEntries.values()); 309 return v; 310 } 312 318 public Map getElementIndex() 319 { 320 return elementIndex; 321 } 322 323 329 public Map getTypeIndex() 330 { 331 return typeIndex; 332 } 333 334 339 public int getTypeEntryCount() 340 { 341 return elementTypeEntries.size() + typeTypeEntries.size(); 342 } 343 344 348 public Definition getDefinition() 349 { 350 return def; 351 } 353 357 public String getWSDLURI() 358 { 359 return wsdlURI; 360 } 362 365 public boolean isWrapped() 366 { 367 return wrapped; 368 } 369 370 373 public void setWrapped(boolean wrapped) 374 { 375 this.wrapped = wrapped; 376 } 377 378 381 public void dump(java.io.PrintStream out) 382 { 383 out.println(); 384 out.println(Messages.getMessage("symbolTable00")); 385 out.println("-----------------------"); 386 Iterator it = symbolTable.values().iterator(); 387 while (it.hasNext()) 388 { 389 Vector v = (Vector )it.next(); 390 for (int i = 0; i < v.size(); ++i) 391 { 392 out.println(v.elementAt(i).getClass().getName()); 393 out.println(v.elementAt(i)); 394 } 395 } 396 out.println("-----------------------"); 397 } 399 400 405 406 public void populate(String uri) 407 throws IOException , WSDLException, 408 SAXException , ParserConfigurationException 409 { 410 populate(uri, null, null); 411 } 413 public void populate(String uri, String username, String password) 414 throws IOException , WSDLException, 415 SAXException , ParserConfigurationException 416 { 417 if (verbose) 418 System.out.println(Messages.getMessage("parsing00", uri)); 419 420 Document doc = XMLUtils.newDocument(uri, username, password); 421 this.wsdlURI = uri; 422 try 423 { 424 File f = new File (uri); 425 if (f.exists()) 426 { 427 uri = f.toURL().toString(); 428 } 429 } 430 catch (Exception e) 431 { 432 } 433 populate(uri, doc); 434 } 436 442 public void populate(String context, Document doc) 443 throws IOException , SAXException , WSDLException, 444 ParserConfigurationException 445 { 446 WSDLReader reader = WSDLFactory.newInstance().newWSDLReader(); 447 reader.setFeature("javax.wsdl.verbose", verbose); 448 this.def = reader.readWSDL(context, doc); 449 450 add(context, def, doc); 451 } 453 459 protected void add(String context, Definition def, Document doc) 460 throws IOException , SAXException , WSDLException, 461 ParserConfigurationException 462 { 463 URL contextURL = context == null ? null : getURL(null, context); 464 populate(contextURL, def, doc, null); 465 checkForUndefined(); 466 populateParameters(); 467 setReferences(def, doc); } 470 473 private void checkForUndefined(Definition def, String filename) throws IOException 474 { 475 if (def != null) 476 { 477 Iterator ib = def.getBindings().values().iterator(); 479 while (ib.hasNext()) 480 { 481 Binding binding = (Binding)ib.next(); 482 if (binding.isUndefined()) 483 { 484 if (filename == null) 485 { 486 throw new IOException (Messages.getMessage("emitFailtUndefinedBinding01", 487 binding.getQName().getLocalPart())); 488 } 489 else 490 { 491 throw new IOException (Messages.getMessage("emitFailtUndefinedBinding02", 492 binding.getQName().getLocalPart(), filename)); 493 } 494 } 495 } 496 497 Iterator ip = def.getPortTypes().values().iterator(); 499 while (ip.hasNext()) 500 { 501 PortType portType = (PortType)ip.next(); 502 if (portType.isUndefined()) 503 { 504 if (filename == null) 505 { 506 throw new IOException (Messages.getMessage("emitFailtUndefinedPort01", 507 portType.getQName().getLocalPart())); 508 } 509 else 510 { 511 throw new IOException (Messages.getMessage("emitFailtUndefinedPort02", 512 portType.getQName().getLocalPart(), filename)); 513 } 514 } 515 } 516 517 533 } 534 } 535 536 539 private void checkForUndefined() throws IOException 540 { 541 Iterator it = symbolTable.values().iterator(); 542 while (it.hasNext()) 543 { 544 Vector v = (Vector )it.next(); 545 for (int i = 0; i < v.size(); ++i) 546 { 547 SymTabEntry entry = (SymTabEntry)v.get(i); 548 549 if (entry instanceof UndefinedType) 551 { 552 QName qn = entry.getQName(); 553 554 if ((qn.getLocalPart().equals("dateTime") && 557 !qn.getNamespaceURI().equals(Constants.URI_2001_SCHEMA_XSD)) || 558 (qn.getLocalPart().equals("timeInstant") && 559 qn.getNamespaceURI().equals(Constants.URI_2001_SCHEMA_XSD))) 560 { 561 throw new IOException (Messages.getMessage("wrongNamespace00", 562 qn.getLocalPart(), 563 qn.getNamespaceURI())); 564 } 565 566 if (SchemaUtils.isSimpleSchemaType(entry.getQName())) 569 { 570 throw new IOException (Messages.getMessage("unsupportedSchemaType00", 571 qn.getLocalPart())); 572 } 573 574 throw new IOException (Messages.getMessage("undefined00", 576 entry.getQName().toString())); 577 } else if (entry instanceof UndefinedElement) 579 { 580 throw new IOException (Messages.getMessage("undefinedElem00", 581 entry.getQName().toString())); 582 } 583 } 584 } 585 } 587 594 private URLHashSet importedFiles = new URLHashSet(); 595 596 private void populate(URL context, Definition def, Document doc, 597 String filename) 598 throws IOException , ParserConfigurationException , 599 SAXException , WSDLException 600 { 601 if (doc != null) 602 { 603 populateTypes(context, doc); 604 605 if (addImports) 606 { 607 lookForImports(context, doc); 609 } 610 } 611 if (def != null) 612 { 613 checkForUndefined(def, filename); 614 if (addImports) 615 { 616 Map imports = def.getImports(); 618 Object [] importKeys = imports.keySet().toArray(); 619 for (int i = 0; i < importKeys.length; ++i) 620 { 621 Vector v = (Vector )imports.get(importKeys[i]); 622 for (int j = 0; j < v.size(); ++j) 623 { 624 Import imp = (Import)v.get(j); 625 if (!importedFiles.contains(imp.getLocationURI())) 626 { 627 importedFiles.add(imp.getLocationURI()); 628 URL url = getURL(context, imp.getLocationURI()); 629 populate(url, imp.getDefinition(), 630 XMLUtils.newDocument(url.toString()), 631 url.toString()); 632 } 633 } 634 } 635 } 636 populateMessages(def); 637 populatePortTypes(def); 638 populateBindings(def); 639 populateServices(def); 640 } 641 } 643 647 private static URL getURL(URL contextURL, String spec) throws IOException 648 { 649 String path = spec.replace('\\', '/'); 653 654 URL url = null; 656 try 657 { 658 url = new URL (contextURL, path); 660 661 if (contextURL != null && 664 url.getProtocol().equals("file") && 665 contextURL.getProtocol().equals("file")) 666 { 667 url = getFileURL(contextURL, path); 668 } 669 } 670 catch (MalformedURLException me) 671 { 672 url = getFileURL(contextURL, path); 674 } 675 676 return url; 680 } 682 private static URL getFileURL(URL contextURL, String path) 683 throws IOException 684 { 685 if (contextURL != null) 686 { 687 String contextFileName = contextURL.getFile(); 690 URL parent = new File (contextFileName).getParentFile().toURL(); 691 if (parent != null) 692 { 693 return new URL (parent, path); 694 } 695 } 696 return new URL ("file", "", path); 697 } 699 702 private void lookForImports(URL context, Node node) 703 throws IOException , ParserConfigurationException , 704 SAXException , WSDLException 705 { 706 NodeList children = node.getChildNodes(); 707 for (int i = 0; i < children.getLength(); i++) 708 { 709 Node child = children.item(i); 710 if ("import".equals(child.getLocalName())) 711 { 712 NamedNodeMap attributes = child.getAttributes(); 713 Node namespace = attributes.getNamedItem("namespace"); 714 if (namespace != null && 716 isKnownNamespace(namespace.getNodeValue())) 717 { 718 continue; 719 } 720 Node importFile = attributes.getNamedItem("schemaLocation"); 721 if (importFile != null) 722 { 723 URL url = getURL(context, 724 importFile.getNodeValue()); 725 if (!importedFiles.contains(url)) 726 { 727 importedFiles.add(url); 728 String filename = url.toString(); 729 populate(url, null, 730 XMLUtils.newDocument(filename), filename); 731 } 732 } 733 } 734 lookForImports(context, child); 735 } 736 } 738 744 public boolean isKnownNamespace(String namespace) 745 { 746 if (Constants.isSOAP_ENC(namespace)) 747 return true; 748 if (Constants.isSchemaXSD(namespace)) 749 return true; 750 if (Constants.isSchemaXSI(namespace)) 751 return true; 752 if (namespace.equals(Constants.NS_URI_XML)) 753 return true; 754 return false; 755 } 756 757 760 public void populateTypes(URL context, Document doc) 761 throws IOException , SAXException , WSDLException, 762 ParserConfigurationException 763 { 764 addTypes(context, doc, ABOVE_SCHEMA_LEVEL); 765 } 767 779 private static final int ABOVE_SCHEMA_LEVEL = -1; 780 private static final int SCHEMA_LEVEL = 0; 781 782 private void addTypes(URL context, Node node, int level) 783 throws IOException , ParserConfigurationException , 784 WSDLException, SAXException 785 { 786 if (node == null) 787 { 788 return; 789 } 790 QName nodeKind = Utils.getNodeQName(node); 792 793 if (nodeKind != null) 794 { 795 String localPart = nodeKind.getLocalPart(); 796 boolean isXSD = Constants.isSchemaXSD(nodeKind.getNamespaceURI()); 797 if ((isXSD && localPart.equals("complexType") || 798 localPart.equals("simpleType"))) 799 { 800 801 Node re = SchemaUtils.getRestrictionOrExtensionNode(node); 804 if (re != null && 805 Utils.getAttribute(re, "base") != null) 806 { 807 createTypeFromRef(re); 808 } 809 810 createTypeFromDef(node, false, false); 813 } 814 else if (isXSD && localPart.equals("element")) 815 { 816 createTypeFromRef(node); 818 819 Node re = SchemaUtils.getRestrictionOrExtensionNode(node); 822 if (re != null && 823 Utils.getAttribute(re, "base") != null) 824 { 825 createTypeFromRef(re); 826 } 827 828 createTypeFromDef(node, true, level > SCHEMA_LEVEL); 832 } 833 else if (isXSD && localPart.equals("attribute")) 834 { 835 BooleanHolder forElement = new BooleanHolder (); 837 QName refQName = Utils.getTypeQName(node, forElement, false); 838 839 if (refQName != null && !forElement.value) 840 { 841 createTypeFromRef(node); 842 843 if (refQName != null) 846 { 847 TypeEntry refType = getTypeEntry(refQName, false); 848 if (refType != null && 849 refType instanceof Undefined) 850 { 851 refType.setSimpleType(true); 854 } 855 else if (refType == null || 856 (!(refType instanceof BaseType) && 857 !refType.isSimpleType())) 858 { 859 throw new IOException (Messages.getMessage("AttrNotSimpleType01", 861 refQName.toString())); 862 } 863 } 864 } 865 } 866 else if (isXSD && localPart.equals("any")) 867 { 868 if (getType(Constants.XSD_ANY) == null) 870 { 871 Type type = new BaseType(Constants.XSD_ANY); 872 symbolTablePut(type); 873 } 874 } 875 else if (localPart.equals("part") && 876 Constants.isWSDL(nodeKind.getNamespaceURI())) 877 { 878 879 createTypeFromRef(node); 881 } 882 else if (isXSD && localPart.equals("include")) 883 { 884 String includeName = Utils.getAttribute(node, "schemaLocation"); 885 if (includeName != null) 886 { 887 URL url = getURL(context, includeName); 888 Document includeDoc = XMLUtils.newDocument(url.toString()); 889 org.w3c.dom.Element schemaEl = includeDoc.getDocumentElement(); 891 if (!schemaEl.hasAttribute("targetNamespace")) 892 { 893 org.w3c.dom.Element parentSchemaEl = (org.w3c.dom.Element )node.getParentNode(); 894 if (parentSchemaEl.hasAttribute("targetNamespace")) 895 { 896 String tns = parentSchemaEl.getAttribute("targetNamespace"); 900 schemaEl.setAttribute("targetNamespace", tns); 901 schemaEl.setAttribute("xmlns", tns); 902 } 903 } 904 populate(url, null, includeDoc, url.toString()); 905 } 906 } 907 } 908 909 if (level == ABOVE_SCHEMA_LEVEL) 910 { 911 if (nodeKind != null && nodeKind.getLocalPart().equals("schema")) 912 { 913 level = SCHEMA_LEVEL; 914 } 915 } 916 else 917 { 918 ++level; 919 } 920 921 NodeList children = node.getChildNodes(); 923 for (int i = 0; i < children.getLength(); i++) 924 { 925 addTypes(context, children.item(i), level); 926 } 927 } 929 933 private void createTypeFromDef(Node node, boolean isElement, 934 boolean belowSchemaLevel) throws IOException 935 { 936 QName qName = Utils.getNodeNameQName(node); 938 if (qName != null) 939 { 940 941 if (!isElement && btm.getBaseName(qName) != null) 944 { 945 return; 946 } 947 948 BooleanHolder forElement = new BooleanHolder (); 951 QName refQName = Utils.getTypeQName(node, forElement, false); 952 953 if (refQName != null) 954 { 955 if (qName.getLocalPart().length() == 0) 957 { 958 String name = Utils.getAttribute(node, "name"); 959 if (name == null) 960 { 961 name = "unknown"; 962 } 963 throw new IOException (Messages.getMessage("emptyref00", name)); 964 } 965 966 TypeEntry refType = getTypeEntry(refQName, forElement.value); 968 if (!belowSchemaLevel) 969 { 970 if (refType == null) 971 { 972 throw new IOException (Messages.getMessage("absentRef00", refQName.toString(), qName.toString())); 973 } 974 symbolTablePut(new DefinedElement(qName, refType, node, "")); 975 } 976 } 977 else 978 { 979 981 IntHolder numDims = new IntHolder (); 983 numDims.value = 0; 984 QName arrayEQName = SchemaUtils.getArrayComponentQName(node, numDims); 985 986 if (arrayEQName != null) 987 { 988 refQName = arrayEQName; 990 TypeEntry refType = getTypeEntry(refQName, false); 991 if (refType == null) 992 { 993 String baseName = btm.getBaseName(refQName); 995 if (baseName != null) 996 refType = new BaseType(refQName); 997 else 998 refType = new UndefinedType(refQName); 999 symbolTablePut(refType); 1000 } 1001 1002 String dims = ""; 1004 while (numDims.value > 0) 1005 { 1006 dims += "[]"; 1007 numDims.value--; 1008 } 1009 1010 TypeEntry defType = null; 1011 if (isElement) 1012 { 1013 if (!belowSchemaLevel) 1014 { 1015 defType = new DefinedElement(qName, refType, node, dims); 1016 } 1017 } 1018 else 1019 { 1020 defType = new DefinedType(qName, refType, node, dims); 1021 } 1022 if (defType != null) 1023 { 1024 symbolTablePut(defType); 1025 } 1026 } 1027 else 1028 { 1029 1030 String baseName = btm.getBaseName(qName); 1032 if (baseName != null) 1033 { 1034 symbolTablePut(new BaseType(qName)); 1035 } 1036 else 1037 { 1038 1039 TypeEntry te = null; 1043 if (!isElement) 1044 { 1045 te = new DefinedType(qName, node); 1046 1047 if (qName.getLocalPart().indexOf(ANON_TOKEN) >= 0) 1051 { 1052 Node parent = node.getParentNode(); 1053 QName parentQName = Utils.getNodeNameQName(parent); 1054 TypeEntry parentType = getElement(parentQName); 1055 if (parentType != null) 1056 { 1057 parentType.setRefType(te); 1058 } 1059 } 1060 1061 } 1062 else 1063 { 1064 if (!belowSchemaLevel) 1065 { 1066 te = new DefinedElement(qName, node); 1067 } 1068 } 1069 if (te != null) 1070 { 1071 if (SchemaUtils.isSimpleTypeOrSimpleContent(node)) 1072 { 1073 te.setSimpleType(true); 1074 } 1075 symbolTablePut(te); 1076 } 1077 } 1078 } 1079 } 1080 } 1081 } 1083 1087 private void createTypeFromRef(Node node) throws IOException 1088 { 1089 BooleanHolder forElement = new BooleanHolder (); 1091 QName qName = Utils.getTypeQName(node, forElement, false); 1092 if (qName != null) 1093 { 1094 if (qName.getLocalPart().length() == 0) 1096 { 1097 String name = Utils.getAttribute(node, "name"); 1098 if (name == null) 1099 { 1100 name = "unknown"; 1101 } 1102 throw new IOException (Messages.getMessage("emptyref00", name)); 1103 } 1104 1105 TypeEntry type = getTypeEntry(qName, forElement.value); 1107 1108 if (type == null) 1110 { 1111 if (qName.getLocalPart().indexOf("[") > 0) 1113 { 1114 QName containedQName = Utils.getTypeQName(node, forElement, true); 1115 TypeEntry containedTE = getTypeEntry(containedQName, forElement.value); 1116 if (!forElement.value) 1117 { 1118 if (containedTE == null) 1120 { 1121 String baseName = btm.getBaseName(containedQName); 1123 if (baseName != null) 1124 { 1125 containedTE = new BaseType(containedQName); 1126 } 1127 else 1128 { 1129 containedTE = new UndefinedType(containedQName); 1130 } 1131 symbolTablePut(containedTE); 1132 } 1133 symbolTablePut(new CollectionType(qName, containedTE, node, "[]")); 1134 } 1135 else 1136 { 1137 if (containedTE == null) 1139 { 1140 containedTE = new UndefinedElement(containedQName); 1141 symbolTablePut(containedTE); 1142 } 1143 symbolTablePut(new CollectionElement(qName, containedTE, node, "[]")); 1144 } 1145 } 1146 else 1147 { 1148 String baseName = btm.getBaseName(qName); 1150 if (baseName != null) 1151 symbolTablePut(new BaseType(qName)); 1152 else if (forElement.value == false) 1153 symbolTablePut(new UndefinedType(qName)); 1154 else 1155 symbolTablePut(new UndefinedElement(qName)); 1156 } 1157 } 1158 } 1159 } 1161 1164 private void populateMessages(Definition def) throws IOException 1165 { 1166 Iterator i = def.getMessages().values().iterator(); 1167 while (i.hasNext()) 1168 { 1169 Message message = (Message)i.next(); 1170 MessageEntry mEntry = new MessageEntry(message); 1171 symbolTablePut(mEntry); 1172 } 1173 } 1175 1193 protected void ensureOperationMessageValid(Message message) throws IOException 1194 { 1195 1196 if (message == null) 1200 { 1201 throw new IOException ("<input>,<output>, or <fault> in <operation ..> without attribute 'message' found. Attribute 'message' is required."); 1202 } 1203 1204 if (message.isUndefined()) 1208 { 1209 throw new IOException ("<input ..>, <output ..> or <fault ..> in <portType> with undefined message found. message name is '" 1210 + message.getQName().toString() 1211 + "'"); 1212 } 1213 } 1214 1215 1216 1228 protected void ensureOperationValid(Operation operation) throws IOException 1229 { 1230 1231 if (operation == null) 1232 { 1233 throw new IllegalArgumentException ("parameter 'operation' must not be null"); 1234 } 1235 1236 Input input = operation.getInput(); 1237 if (input != null) 1238 { 1239 ensureOperationMessageValid(input.getMessage()); 1240 } 1241 1242 Output output = operation.getOutput(); 1243 if (output != null) 1244 { 1245 ensureOperationMessageValid(output.getMessage()); 1246 } 1247 1248 Map faults = operation.getFaults(); 1249 if (faults != null) 1250 { 1251 Iterator it = faults.values().iterator(); 1252 while (it.hasNext()) 1253 { 1254 ensureOperationMessageValid(((Fault)it.next()).getMessage()); 1255 } 1256 } 1257 } 1258 1259 1270 1271 protected void ensureOperationsOfPortTypeValid(PortType portType) throws IOException 1272 { 1273 if (portType == null) 1274 throw new IllegalArgumentException ("parameter 'portType' must not be null"); 1275 1276 List operations = portType.getOperations(); 1277 1278 if (operations == null || operations.size() == 0) return; 1281 1282 Iterator it = operations.iterator(); 1285 while (it.hasNext()) 1286 { 1287 Operation operation = (Operation)it.next(); 1288 ensureOperationValid(operation); 1289 } 1290 } 1291 1292 1295 private void populatePortTypes(Definition def) throws IOException 1296 { 1297 Iterator i = def.getPortTypes().values().iterator(); 1298 while (i.hasNext()) 1299 { 1300 PortType portType = (PortType)i.next(); 1301 1302 1303 if (!portType.isUndefined()) 1307 { 1308 ensureOperationsOfPortTypeValid(portType); 1309 PortTypeEntry ptEntry = new PortTypeEntry(portType); 1310 symbolTablePut(ptEntry); 1311 } 1312 } 1313 } 1315 1316 1319 private void populateParameters() throws IOException 1320 { 1321 Iterator it = symbolTable.values().iterator(); 1322 while (it.hasNext()) 1323 { 1324 Vector v = (Vector )it.next(); 1325 for (int i = 0; i < v.size(); ++i) 1326 { 1327 if (v.get(i) instanceof BindingEntry) 1328 { 1329 BindingEntry bEntry = (BindingEntry)v.get(i); 1330 if (bEntry.getBindingType() != BindingEntry.TYPE_SOAP) 1332 continue; 1333 1334 Binding binding = bEntry.getBinding(); 1335 Collection bindOperations = bEntry.getOperations(); 1336 PortType portType = binding.getPortType(); 1337 1338 LinkedHashMap parameters = new LinkedHashMap(); 1339 Iterator operations = portType.getOperations().iterator(); 1340 1341 while (operations.hasNext()) 1343 { 1344 Operation operation = (Operation)operations.next(); 1345 1346 if (!bindOperations.contains(operation)) 1349 { 1350 throw new IOException (Messages.getMessage("emitFailNoMatchingBindOperation01", 1351 operation.getName(), 1352 portType.getQName().getLocalPart())); 1353 } 1354 1355 String namespace = portType.getQName().getNamespaceURI(); 1356 Parameters parms = getOperationParameters(operation, 1357 namespace, 1358 bEntry); 1359 parameters.put(operation, parms); 1360 } 1361 bEntry.setParameters(parameters); 1362 } 1363 } 1364 } 1365 } 1367 1373 public Parameters getOperationParameters(Operation operation, 1374 String namespace, 1375 BindingEntry bindingEntry) throws IOException 1376 { 1377 Parameters parameters = new Parameters(); 1378 1379 Vector inputs = new Vector (); 1381 Vector outputs = new Vector (); 1382 1383 List parameterOrder = operation.getParameterOrdering(); 1384 1385 if (parameterOrder != null && parameterOrder.isEmpty()) 1387 { 1388 parameterOrder = null; 1389 } 1390 1391 if (parameterOrder != null) 1393 { 1394 Input input = operation.getInput(); 1395 if (input != null) 1396 { 1397 Message inputMsg = input.getMessage(); 1398 Map allInputs = inputMsg.getParts(); 1399 Collection orderedInputs = inputMsg.getOrderedParts(parameterOrder); 1400 if (allInputs.size() != orderedInputs.size()) 1401 { 1402 throw new IOException (Messages.getMessage("emitFail00", operation.getName())); 1403 } 1404 } 1405 } 1406 1407 boolean literalInput = false; 1408 boolean literalOutput = false; 1409 if (bindingEntry != null) 1410 { 1411 literalInput = (bindingEntry.getInputBodyType(operation) == Use.LITERAL); 1412 literalOutput = (bindingEntry.getOutputBodyType(operation) == Use.LITERAL); 1413 } 1414 1415 Input input = operation.getInput(); 1417 if (input != null && input.getMessage() != null) 1418 { 1419 getParametersFromParts(inputs, 1420 input.getMessage().getOrderedParts(null), 1421 literalInput, 1422 operation.getName(), 1423 bindingEntry); 1424 } 1425 1426 Output output = operation.getOutput(); 1428 if (output != null && output.getMessage() != null) 1429 { 1430 getParametersFromParts(outputs, 1431 output.getMessage().getOrderedParts(null), 1432 literalOutput, 1433 operation.getName(), 1434 bindingEntry); 1435 } 1436 1437 if (parameterOrder != null) 1438 { 1439 for (int i = 0; i < parameterOrder.size(); ++i) 1442 { 1443 String name = (String )parameterOrder.get(i); 1444 1445 int index = getPartIndex(name, inputs); 1447 1448 int outdex = getPartIndex(name, outputs); 1450 1451 if (index >= 0) 1452 { 1453 addInishParm(inputs, outputs, index, outdex, parameters, true); 1455 } 1456 else if (outdex >= 0) 1457 { 1458 addOutParm(outputs, outdex, parameters, true); 1459 } 1460 else 1461 { 1462 System.err.println(Messages.getMessage("noPart00", name)); 1463 } 1464 } 1465 } 1466 1467 if (wrapped && inputs.size() == 1 && outputs.size() == 1 && 1473 ((Parameter)inputs.get(0)).getName().equals(((Parameter)outputs.get(0)).getName())) 1474 { 1475 addInishParm(inputs, null, 0, -1, parameters, false); 1477 } 1478 else 1479 { 1480 for (int i = 0; i < inputs.size(); i++) 1485 { 1486 Parameter p = (Parameter)inputs.get(i); 1487 int outdex = getPartIndex(p.getName(), outputs); 1488 addInishParm(inputs, outputs, i, outdex, parameters, false); 1489 } 1490 } 1491 1492 if (outputs.size() == 1) 1497 { 1498 parameters.returnParam = (Parameter)outputs.get(0); 1499 parameters.returnParam.setMode(Parameter.OUT); 1500 if (parameters.returnParam.getType() instanceof DefinedElement) 1501 { 1502 parameters.returnParam.setQName(parameters.returnParam.getType() 1503 .getQName()); 1504 } 1505 ++parameters.outputs; 1506 } 1507 else 1508 { 1509 for (int i = 0; i < outputs.size(); i++) 1510 { 1511 addOutParm(outputs, i, parameters, false); 1512 } 1513 } 1514 parameters.faults = operation.getFaults(); 1515 1516 Vector used = new Vector (parameters.list.size()); 1519 Iterator i = parameters.list.iterator(); 1520 while (i.hasNext()) 1521 { 1522 Parameter parameter = (Parameter)i.next(); 1523 int count = 2; 1524 while (used.contains(parameter.getName())) 1525 { 1526 parameter.setName(parameter.getName() + Integer.toString(count++)); 1528 } 1529 used.add(parameter.getName()); 1530 } 1531 1532 return parameters; 1533 } 1535 private boolean isInParameterList(Vector params, String partName) 1537 { 1538 for (int i = 0; i < params.size(); i++) 1539 { 1540 Parameter parameter = (Parameter)params.get(i); 1541 if (partName.equals(parameter.getName())) 1542 return true; 1543 } 1544 return false; 1545 } 1546 1547 1550 private int getPartIndex(String name, Vector v) 1551 { 1552 for (int i = 0; i < v.size(); i++) 1553 { 1554 if (name.equals(((Parameter)v.get(i)).getName())) 1555 { 1556 return i; 1557 } 1558 } 1559 return -1; 1560 } 1562 1565 private void addInishParm(Vector inputs, 1566 Vector outputs, 1567 int index, 1568 int outdex, 1569 Parameters parameters, 1570 boolean trimInput) 1571 { 1572 Parameter p = (Parameter)inputs.get(index); 1573 if (p.getType() instanceof DefinedElement) 1576 { 1577 DefinedElement de = (DefinedElement)p.getType(); 1578 p.setQName(de.getQName()); 1579 } 1580 if (p.getType() instanceof CollectionElement) 1584 { 1585 p.setQName(p.getType().getRefType().getQName()); 1586 } 1587 1588 if (trimInput) 1590 { 1591 inputs.remove(index); 1592 } 1593 1594 if (outdex >= 0) 1598 { 1599 Parameter outParam = (Parameter)outputs.get(outdex); 1600 if (p.getType().equals(outParam.getType())) 1601 { 1602 outputs.remove(outdex); 1603 p.setMode(Parameter.INOUT); 1604 ++parameters.inouts; 1605 } 1606 else 1607 { 1608 1619 ++parameters.inputs; 1626 } 1627 } 1628 else 1629 { 1630 ++parameters.inputs; 1631 } 1632 1633 parameters.list.add(p); 1634 } 1636 1639 private void addOutParm(Vector outputs, 1640 int outdex, 1641 Parameters parameters, 1642 boolean trim) 1643 { 1644 Parameter p = (Parameter)outputs.get(outdex); 1645 1646 if (p.getType() instanceof DefinedElement) 1649 { 1650 DefinedElement de = (DefinedElement)p.getType(); 1651 p.setQName(de.getQName()); 1652 } 1653 if (p.getType() instanceof CollectionElement) 1657 { 1658 p.setQName(p.getType().getRefType().getQName()); 1659 } 1660 1661 if (trim) 1662 { 1663 outputs.remove(outdex); 1664 } 1665 1666 p.setMode(Parameter.OUT); 1667 ++parameters.outputs; 1668 1669 parameters.list.add(p); 1670 } 1672 1676 public void getParametersFromParts(Vector v, 1677 Collection parts, 1678 boolean literal, 1679 String opName, 1680 BindingEntry bindingEntry) 1681 throws IOException 1682 { 1683 1684 1688 int numberOfElements = 0; 1695 boolean possiblyWrapped = false; 1696 Iterator i = parts.iterator(); 1697 while (i.hasNext()) 1698 { 1699 Part part = (Part)i.next(); 1700 if (part.getElementName() != null) 1701 { 1702 ++numberOfElements; 1703 if (part.getElementName().getLocalPart().equals(opName)) 1704 { 1705 possiblyWrapped = true; 1706 } 1707 } 1708 } 1709 1710 if (!nowrap && 1718 literal && 1719 numberOfElements == 1 && 1720 possiblyWrapped) 1721 { 1722 wrapped = true; 1723 } 1724 1725 i = parts.iterator(); 1726 while (i.hasNext()) 1727 { 1728 Parameter param = new Parameter(); 1729 Part part = (Part)i.next(); 1730 QName elementName = part.getElementName(); 1731 QName typeName = part.getTypeName(); 1732 String partName = part.getName(); 1733 1734 if (!literal || !wrapped || elementName == null) 1738 { 1739 1740 param.setName(partName); 1741 1742 if (typeName != null) 1744 { 1745 param.setType(getType(typeName)); 1746 } 1747 else if (elementName != null) 1748 { 1749 param.setType(getElement(elementName)); 1755 } 1756 else 1757 { 1758 throw new IOException (Messages.getMessage("noTypeOrElement00", 1760 new String []{partName, 1761 opName})); 1762 } 1763 setMIMEInfo(param, bindingEntry == null ? null : 1764 bindingEntry.getMIMEInfo(opName, partName)); 1765 if (bindingEntry != null && 1766 bindingEntry.isInHeaderPart(opName, partName)) 1767 { 1768 param.setInHeader(true); 1769 } 1770 if (bindingEntry != null && 1771 bindingEntry.isOutHeaderPart(opName, partName)) 1772 { 1773 param.setOutHeader(true); 1774 } 1775 1776 v.add(param); 1777 1778 continue; } 1780 1781 1783 Node node = null; 1786 if (typeName != null && bindingEntry.getMIMETypes().size() == 0) 1787 { 1788 String bindingName = 1795 bindingEntry == null ? "unknown" : bindingEntry.getBinding().getQName().toString(); 1796 throw new IOException (Messages.getMessage("literalTypePart00", 1797 new String []{partName, 1798 opName, 1799 bindingName})); 1800 } 1801 1802 node = getTypeEntry(elementName, true).getNode(); 1809 1810 BooleanHolder forElement = new BooleanHolder (); 1813 QName type = Utils.getTypeQName(node, forElement, false); 1814 if (type != null && !forElement.value) 1815 { 1816 node = getTypeEntry(type, false).getNode(); 1819 } 1820 1821 Vector vTypes = null; 1822 if (node == null) 1824 { 1825 if (bindingEntry.isInHeaderPart(opName, partName)) 1826 { 1827 wrapped = false; 1828 } 1829 else 1830 { 1831 1839 } 1840 } 1841 else 1842 { 1843 Vector vAttrs = SchemaUtils.getContainedAttributeTypes(node, this); 1845 if (vAttrs != null) 1846 { 1847 wrapped = false; 1849 } 1850 1851 vTypes = SchemaUtils.getContainedElementDeclarations(node, this); 1856 } 1857 if (vTypes != null && wrapped) 1860 { 1861 for (int j = 0; j < vTypes.size(); j++) 1863 { 1864 ElementDecl elem = (ElementDecl)vTypes.elementAt(j); 1865 Parameter p = new Parameter(); 1866 p.setQName(elem.getName()); 1867 p.setType(elem.getType()); 1868 setMIMEInfo(p, bindingEntry == null ? null : 1869 bindingEntry.getMIMEInfo(opName, partName)); 1870 if (bindingEntry.isInHeaderPart(opName, partName)) 1871 { 1872 p.setInHeader(true); 1873 } 1874 if (bindingEntry.isOutHeaderPart(opName, partName)) 1875 { 1876 p.setOutHeader(true); 1877 } 1878 v.add(p); 1879 } 1880 } 1881 else 1882 { 1883 param.setName(partName); 1887 1888 if (typeName != null) 1889 { 1890 param.setType(getType(typeName)); 1891 } 1892 else if (elementName != null) 1893 { 1894 param.setType(getElement(elementName)); 1895 } 1896 setMIMEInfo(param, bindingEntry == null ? null : 1897 bindingEntry.getMIMEInfo(opName, partName)); 1898 if (bindingEntry.isInHeaderPart(opName, partName)) 1899 { 1900 param.setInHeader(true); 1901 } 1902 if (bindingEntry.isOutHeaderPart(opName, partName)) 1903 { 1904 param.setOutHeader(true); 1905 } 1906 1907 v.add(param); 1908 } 1909 } 1911 } 1913 1918 private void setMIMEInfo(Parameter p, MimeInfo mimeInfo) 1919 { 1920 if (mimeInfo == null) 1923 { 1924 QName mimeQName = p.getType().getQName(); 1925 if (mimeQName.getNamespaceURI().equals(Constants.NS_URI_XMLSOAP)) 1926 { 1927 if (Constants.MIME_IMAGE.equals(mimeQName)) 1928 { 1929 mimeInfo = new MimeInfo("image/jpeg", ""); 1930 } 1931 else if (Constants.MIME_PLAINTEXT.equals(mimeQName)) 1932 { 1933 mimeInfo = new MimeInfo("text/plain", ""); 1934 } 1935 else if (Constants.MIME_MULTIPART.equals(mimeQName)) 1936 { 1937 mimeInfo = new MimeInfo("multipart/related", ""); 1938 } 1939 else if (Constants.MIME_SOURCE.equals(mimeQName)) 1940 { 1941 mimeInfo = new MimeInfo("text/xml", ""); 1942 } 1943 else if (Constants.MIME_OCTETSTREAM.equals(mimeQName)) 1944 { 1945 mimeInfo = new MimeInfo("application/octetstream", ""); 1946 } 1947 } 1948 } 1949 p.setMIMEInfo(mimeInfo); 1950 } 1952 1955 private void populateBindings(Definition def) throws IOException 1956 { 1957 Iterator i = def.getBindings().values().iterator(); 1958 while (i.hasNext()) 1959 { 1960 Binding binding = (Binding)i.next(); 1961 1962 BindingEntry bEntry = new BindingEntry(binding); 1963 symbolTablePut(bEntry); 1964 1965 Iterator extensibilityElementsIterator = binding.getExtensibilityElements().iterator(); 1966 while (extensibilityElementsIterator.hasNext()) 1967 { 1968 Object obj = extensibilityElementsIterator.next(); 1969 if (obj instanceof SOAPBinding) 1970 { 1971 bEntry.setBindingType(BindingEntry.TYPE_SOAP); 1972 SOAPBinding sb = (SOAPBinding)obj; 1973 String style = sb.getStyle(); 1974 if ("rpc".equalsIgnoreCase(style)) 1975 { 1976 bEntry.setBindingStyle(Style.RPC); 1977 } 1978 } 1979 else if (obj instanceof HTTPBinding) 1980 { 1981 HTTPBinding hb = (HTTPBinding)obj; 1982 if (hb.getVerb().equalsIgnoreCase("post")) 1983 { 1984 bEntry.setBindingType(BindingEntry.TYPE_HTTP_POST); 1985 } 1986 else 1987 { 1988 bEntry.setBindingType(BindingEntry.TYPE_HTTP_GET); 1989 } 1990 } 1991 else if (obj instanceof UnknownExtensibilityElement) 1992 { 1993 UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement)obj; 1995 QName name = unkElement.getElementType(); 1996 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) && 1997 name.getLocalPart().equals("binding")) 1998 { 1999 bEntry.setBindingType(BindingEntry.TYPE_SOAP); 2000 String style = unkElement.getElement().getAttribute("style"); 2001 if ("rpc".equalsIgnoreCase(style)) 2002 { 2003 bEntry.setBindingStyle(Style.RPC); 2004 } 2005 } 2006 } 2007 } 2008 2009 HashMap attributes = new HashMap(); 2015 List bindList = binding.getBindingOperations(); 2016 HashMap faultMap = new HashMap(); for (Iterator opIterator = bindList.iterator(); opIterator.hasNext();) 2018 { 2019 BindingOperation bindOp = (BindingOperation)opIterator.next(); 2020 Operation operation = bindOp.getOperation(); 2021 BindingInput bindingInput = bindOp.getBindingInput(); 2022 BindingOutput bindingOutput = bindOp.getBindingOutput(); 2023 String opName = bindOp.getName(); 2024 2025 String inputName = bindingInput == null ? null : 2027 bindingInput.getName(); 2028 String outputName = bindingOutput == null ? null : 2029 bindingOutput.getName(); 2030 if (binding.getPortType().getOperation(opName, inputName, outputName) == null) 2031 { 2032 throw new IOException (Messages.getMessage("unmatchedOp", 2033 new String []{opName, inputName, outputName})); 2034 } 2035 2036 ArrayList faults = new ArrayList (); 2037 2038 if (bindingInput != null) 2040 { 2041 if (bindingInput.getExtensibilityElements() != null) 2042 { 2043 Iterator inIter = bindingInput. 2044 getExtensibilityElements().iterator(); 2045 fillInBindingInfo(bEntry, operation, inIter, faults, 2046 true); 2047 } 2048 } 2049 2050 if (bindingOutput != null) 2052 { 2053 if (bindingOutput.getExtensibilityElements() != null) 2054 { 2055 Iterator outIter = bindingOutput. 2056 getExtensibilityElements().iterator(); 2057 fillInBindingInfo(bEntry, operation, outIter, faults, 2058 false); 2059 } 2060 } 2061 2062 faultsFromSOAPFault(binding, bindOp, operation, faults); 2064 2065 faultMap.put(bindOp, faults); 2067 2068 Use inputBodyType = bEntry.getInputBodyType(operation); 2069 Use outputBodyType = bEntry.getOutputBodyType(operation); 2070 2071 attributes.put(bindOp.getOperation(), 2074 new BindingEntry.OperationAttr(inputBodyType, outputBodyType, faultMap)); 2075 2076 if (inputBodyType == Use.LITERAL || 2079 outputBodyType == Use.LITERAL) 2080 { 2081 bEntry.setHasLiteral(true); 2082 } 2083 bEntry.setFaultBodyTypeMap(operation, faultMap); 2084 } 2086 bEntry.setFaults(faultMap); 2087 } 2088 } 2090 2093 private void fillInBindingInfo(BindingEntry bEntry, Operation operation, 2094 Iterator it, ArrayList faults, boolean input) throws IOException 2095 { 2096 for (; it.hasNext();) 2097 { 2098 Object obj = it.next(); 2099 if (obj instanceof SOAPBody) 2100 { 2101 setBodyType(((SOAPBody)obj).getUse(), bEntry, operation, 2102 input); 2103 } 2104 else if (obj instanceof SOAPHeader) 2105 { 2106 SOAPHeader header = (SOAPHeader)obj; 2107 setBodyType(header.getUse(), bEntry, operation, input); 2108 2109 bEntry.setHeaderPart(operation.getName(), header.getPart(), header, 2116 input ? BindingEntry.IN_HEADER : BindingEntry.OUT_HEADER); 2117 2118 Iterator headerFaults = header.getSOAPHeaderFaults().iterator(); 2120 while (headerFaults.hasNext()) 2121 { 2122 SOAPHeaderFault headerFault = 2123 (SOAPHeaderFault)headerFaults.next(); 2124 faults.add(new FaultInfo(headerFault, this)); 2125 } 2126 } 2127 else if (obj instanceof MIMEMultipartRelated) 2128 { 2129 bEntry.setBodyType(operation, 2130 addMIMETypes(bEntry, (MIMEMultipartRelated)obj, 2131 operation), input); 2132 } 2133 else if (obj instanceof UnknownExtensibilityElement) 2134 { 2135 UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement)obj; 2136 QName name = unkElement.getElementType(); 2137 if (name.getNamespaceURI().equals(Constants.URI_DIME_WSDL) && 2138 name.getLocalPart().equals("message")) 2139 { 2140 fillInDIMEInformation(unkElement, input, operation, bEntry); 2141 } 2142 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) && 2144 name.getLocalPart().equals("body")) 2145 { 2146 setBodyType(unkElement.getElement().getAttribute("use"), bEntry, operation, 2147 input); 2148 } 2149 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) && 2151 name.getLocalPart().equals("header")) 2152 { 2153 setBodyType(unkElement.getElement().getAttribute("use"), bEntry, operation, input); 2154 2155 String partName = unkElement.getElement().getAttribute("part"); 2162 bEntry.setHeaderPart(operation.getName(), partName, null, 2163 input ? BindingEntry.IN_HEADER : BindingEntry.OUT_HEADER); 2164 2165 NodeList headerFaults = unkElement.getElement().getChildNodes(); 2167 for (int i = 0; i < headerFaults.getLength(); i++) 2168 { 2169 String faultMessage = unkElement.getElement().getAttribute("message"); 2170 String faultPart = unkElement.getElement().getAttribute("part"); 2171 String faultUse = unkElement.getElement().getAttribute("use"); 2172 String faultNamespaceURI = unkElement.getElement().getAttribute("namespace"); 2173 QName faultMessageQName = null; 2174 int sep = faultMessage.indexOf(':'); 2175 if (sep == -1) 2176 { 2177 faultMessageQName = new QName (faultMessage); 2178 } 2179 else 2180 { 2181 faultMessageQName = new QName (faultMessage.substring(0, sep), faultMessage.substring(sep + 1)); 2182 } 2183 faults.add(new FaultInfo(faultMessageQName, faultPart, faultUse, faultNamespaceURI, this)); 2184 } 2185 } 2186 } 2187 } 2188 } 2190 2198 private void fillInDIMEInformation(UnknownExtensibilityElement unkElement, boolean input, Operation operation, BindingEntry bEntry) 2199 { 2200 String layout = unkElement.getElement().getAttribute("layout"); 2201 if (layout.equals(Constants.URI_DIME_CLOSED_LAYOUT)) 2203 { 2204 } 2205 else if (layout.equals(Constants.URI_DIME_OPEN_LAYOUT)) 2206 { 2207 } 2208 Map parts = null; 2209 if (input) 2210 { 2211 parts = operation.getInput().getMessage().getParts(); 2212 } 2213 else 2214 { 2215 parts = operation.getOutput().getMessage().getParts(); 2216 } 2217 if (parts != null) 2218 { 2219 Iterator iterator = parts.values().iterator(); 2220 while (iterator.hasNext()) 2221 { 2222 Part part = (Part)iterator.next(); 2223 if (part != null) 2224 { 2225 String dims = ""; 2226 org.w3c.dom.Element element = null; 2227 if (part.getTypeName() != null) 2228 { 2229 TypeEntry partType = getType(part.getTypeName()); 2230 if (partType.getDimensions().length() > 0) 2231 { 2232 dims = partType.getDimensions(); 2233 partType = partType.getRefType(); 2234 } 2235 element = (org.w3c.dom.Element )partType.getNode(); 2236 } 2237 else if (part.getElementName() != null) 2238 { 2239 TypeEntry partElement = getElement(part.getElementName()).getRefType(); 2240 element = (org.w3c.dom.Element )partElement.getNode(); 2241 QName name = getInnerCollectionComponentQName(element); 2242 if (name != null) 2243 { 2244 dims += "[]"; 2245 partElement = getType(name); 2246 element = (org.w3c.dom.Element )partElement.getNode(); 2247 } 2248 else 2249 { 2250 name = getInnerTypeQName(element); 2251 if (name != null) 2252 { 2253 partElement = getType(name); 2254 element = (org.w3c.dom.Element )partElement.getNode(); 2255 } 2256 } 2257 } 2258 if (element != null) 2259 { 2260 org.w3c.dom.Element e = (org.w3c.dom.Element )XMLUtils.findNode(element, new QName (Constants.URI_DIME_CONTENT, "mediaType")); 2261 if (e != null) 2262 { 2263 String value = e.getAttribute("value"); 2264 bEntry.setOperationDIME(operation.getName()); 2265 bEntry.setMIMEInfo(operation.getName(), part.getName(), value, dims); 2266 } 2267 } 2268 } 2269 } 2270 } 2271 } 2272 2273 2276 private void faultsFromSOAPFault(Binding binding, BindingOperation bindOp, 2277 Operation operation, ArrayList faults) throws IOException 2278 { 2279 Iterator faultMapIter = bindOp.getBindingFaults().values().iterator(); 2280 for (; faultMapIter.hasNext();) 2281 { 2282 BindingFault bFault = (BindingFault)faultMapIter.next(); 2283 2284 String faultName = bFault.getName(); 2286 2287 if (faultName == null || faultName.length() == 0) 2289 { 2290 throw new IOException (Messages.getMessage("unNamedFault00", 2291 bindOp.getName(), 2292 binding.getQName().toString())); 2293 } 2294 2295 boolean foundSOAPFault = false; 2296 String soapFaultUse = ""; 2297 String soapFaultNamespace = ""; 2298 2299 Iterator faultIter = bFault.getExtensibilityElements().iterator(); 2300 for (; faultIter.hasNext();) 2301 { 2302 Object obj = faultIter.next(); 2303 if (obj instanceof SOAPFault) 2304 { 2305 foundSOAPFault = true; 2306 soapFaultUse = ((SOAPFault)obj).getUse(); 2307 soapFaultNamespace = ((SOAPFault)obj).getNamespaceURI(); 2308 break; 2309 } 2310 else if (obj instanceof UnknownExtensibilityElement) 2311 { 2312 UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement)obj; 2314 QName name = unkElement.getElementType(); 2315 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) && 2316 name.getLocalPart().equals("fault")) 2317 { 2318 if (unkElement.getElement().getAttribute("use") != null) 2319 { 2320 soapFaultUse = unkElement.getElement().getAttribute("use"); 2321 } 2322 if (unkElement.getElement().getAttribute("namespace") != null) 2323 { 2324 soapFaultNamespace = unkElement.getElement().getAttribute("namespace"); 2325 } 2326 } 2327 } 2328 } 2329 2330 if (!foundSOAPFault) 2332 { 2333 throw new IOException (Messages.getMessage("missingSoapFault00", 2334 faultName, 2335 bindOp.getName(), 2336 binding.getQName().toString())); 2337 } 2338 2339 2343 Fault opFault = operation.getFault(bFault.getName()); 2346 if (opFault == null) 2347 { 2348 throw new IOException (Messages.getMessage("noPortTypeFault", 2349 new String []{bFault.getName(), 2350 bindOp.getName(), 2351 binding.getQName().toString()})); 2352 } 2353 faults.add(new FaultInfo(opFault, 2355 Use.getUse(soapFaultUse), 2356 soapFaultNamespace, 2357 this)); 2358 } 2359 } 2361 2364 private void setBodyType(String use, BindingEntry bEntry, 2365 Operation operation, boolean input) 2366 { 2367 if (use == null) 2368 { 2369 use = "literal"; } 2371 if (use.equalsIgnoreCase("literal")) 2372 { 2373 bEntry.setBodyType(operation, Use.LITERAL, 2374 input); 2375 } 2376 } 2378 2383 private Use addMIMETypes(BindingEntry bEntry, MIMEMultipartRelated mpr, 2384 Operation op) throws IOException 2385 { 2386 Use bodyType = Use.ENCODED; 2387 List parts = mpr.getMIMEParts(); 2388 Iterator i = parts.iterator(); 2389 while (i.hasNext()) 2390 { 2391 MIMEPart part = (MIMEPart)i.next(); 2392 List elems = part.getExtensibilityElements(); 2393 Iterator j = elems.iterator(); 2394 while (j.hasNext()) 2395 { 2396 Object obj = j.next(); 2397 if (obj instanceof MIMEContent) 2398 { 2399 MIMEContent content = (MIMEContent)obj; 2400 TypeEntry typeEntry = findPart(op, content.getPart()); 2401 String dims = typeEntry.getDimensions(); 2402 if (dims.length() <= 0 && typeEntry.getRefType() != null) 2403 { 2404 Node node = typeEntry.getRefType().getNode(); 2405 if (getInnerCollectionComponentQName(node) != null) 2406 dims += "[]"; 2407 } 2408 String type = content.getType(); 2409 if (type == null || type.length() == 0) 2410 type = "text/plain"; 2411 bEntry.setMIMEInfo(op.getName(), content.getPart(), type, dims); 2412 } 2413 else if (obj instanceof SOAPBody) 2414 { 2415 String use = ((SOAPBody)obj).getUse(); 2416 if (use == null) 2417 { 2418 use = "literal"; 2419 } 2420 if (use.equalsIgnoreCase("literal")) 2421 { 2422 bodyType = Use.LITERAL; 2423 } 2424 } 2425 else if (obj instanceof UnknownExtensibilityElement) 2426 { 2427 UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement)obj; 2429 QName name = unkElement.getElementType(); 2430 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) && 2431 name.getLocalPart().equals("body")) 2432 { 2433 String use = unkElement.getElement().getAttribute("use"); 2434 if (use == null) 2435 { 2436 use = "literal"; 2437 } 2438 if (use.equalsIgnoreCase("literal")) 2439 { 2440 bodyType = Use.LITERAL; 2441 } 2442 } 2443 } 2444 } 2445 } 2446 return bodyType; 2447 } 2449 private TypeEntry findPart(Operation operation, String partName) 2450 { 2451 Map parts = operation.getInput().getMessage().getParts(); 2452 Iterator iterator = parts.values().iterator(); 2453 TypeEntry part = findPart(iterator, partName); 2454 2455 if (part == null) 2456 { 2457 parts = operation.getOutput().getMessage().getParts(); 2458 iterator = parts.values().iterator(); 2459 part = findPart(iterator, partName); 2460 } 2461 return part; 2462 } 2463 2464 private TypeEntry findPart(Iterator iterator, String partName) 2465 { 2466 while (iterator.hasNext()) 2467 { 2468 Part part = (Part)iterator.next(); 2469 if (part != null) 2470 { 2471 String typeName = part.getName(); 2472 if (partName.equals(typeName)) 2473 { 2474 if (part.getTypeName() != null) 2475 { 2476 return getType(part.getTypeName()); 2477 } 2478 else if (part.getElementName() != null) 2479 { 2480 return getElement(part.getElementName()); 2481 } 2482 } 2483 } 2484 } 2485 return null; 2486 } 2487 2488 2491 private void populateServices(Definition def) throws IOException 2492 { 2493 Iterator i = def.getServices().values().iterator(); 2494 while (i.hasNext()) 2495 { 2496 Service service = (Service)i.next(); 2497 2498 if (service.getQName() == null || 2500 service.getQName().getLocalPart() == null || 2501 service.getQName().getLocalPart().equals("")) 2502 { 2503 throw new IOException (Messages.getMessage("BadServiceName00")); 2504 } 2505 2506 ServiceEntry sEntry = new ServiceEntry(service); 2507 symbolTablePut(sEntry); 2508 populatePorts(service.getPorts()); 2509 } 2510 } 2512 2513 2522 private void populatePorts(Map ports) throws IOException 2523 { 2524 if (ports == null) return; 2525 Iterator it = ports.values().iterator(); 2526 while (it.hasNext()) 2527 { 2528 2529 Port port = (Port)it.next(); 2530 String portName = port.getName(); 2531 Binding portBinding = port.getBinding(); 2532 2533 if (portName == null) 2537 { 2538 throw new IOException (Messages.getMessage("missingPortNameException")); 2540 } 2541 2542 if (portBinding == null) 2546 { 2547 throw new IOException (Messages.getMessage("missingBindingException")); 2549 } 2550 2551 if (existsPortWithName(new QName (portName))) 2567 { 2568 throw new IOException (Messages.getMessage("twoPortsWithSameName", portName)); 2570 } 2571 PortEntry portEntry = new PortEntry(port); 2572 symbolTablePut(portEntry); 2573 } 2574 } 2575 2576 2583 private void setReferences(Definition def, Document doc) 2584 { 2585 Map stuff = def.getServices(); 2586 if (stuff.isEmpty()) 2587 { 2588 stuff = def.getBindings(); 2589 if (stuff.isEmpty()) 2590 { 2591 stuff = def.getPortTypes(); 2592 if (stuff.isEmpty()) 2593 { 2594 stuff = def.getMessages(); 2595 if (stuff.isEmpty()) 2596 { 2597 for (Iterator i = elementTypeEntries.values().iterator(); 2598 i.hasNext();) 2599 { 2600 setTypeReferences((TypeEntry)i.next(), doc, false); 2601 } 2602 for (Iterator i = typeTypeEntries.values().iterator(); 2603 i.hasNext();) 2604 { 2605 setTypeReferences((TypeEntry)i.next(), doc, false); 2606 } 2607 } 2608 else 2609 { 2610 Iterator i = stuff.values().iterator(); 2611 while (i.hasNext()) 2612 { 2613 Message message = (Message)i.next(); 2614 MessageEntry mEntry = 2615 getMessageEntry(message.getQName()); 2616 setMessageReferences(mEntry, def, doc, false); 2617 } 2618 } 2619 } 2620 else 2621 { 2622 Iterator i = stuff.values().iterator(); 2623 while (i.hasNext()) 2624 { 2625 PortType portType = (PortType)i.next(); 2626 PortTypeEntry ptEntry = 2627 getPortTypeEntry(portType.getQName()); 2628 setPortTypeReferences(ptEntry, null, def, doc); 2629 } 2630 } 2631 } 2632 else 2633 { 2634 Iterator i = stuff.values().iterator(); 2635 while (i.hasNext()) 2636 { 2637 Binding binding = (Binding)i.next(); 2638 BindingEntry bEntry = getBindingEntry(binding.getQName()); 2639 setBindingReferences(bEntry, def, doc); 2640 } 2641 } 2642 } 2643 else 2644 { 2645 Iterator i = stuff.values().iterator(); 2646 while (i.hasNext()) 2647 { 2648 Service service = (Service)i.next(); 2649 ServiceEntry sEntry = getServiceEntry(service.getQName()); 2650 setServiceReferences(sEntry, def, doc); 2651 } 2652 } 2653 } 2655 2659 private void setTypeReferences(TypeEntry entry, Document doc, 2660 boolean literal) 2661 { 2662 2663 if ((entry.isReferenced() && !literal) || 2665 (entry.isOnlyLiteralReferenced() && literal)) 2666 { 2667 return; 2668 } 2669 2670 if (wrapped) 2671 { 2672 if (!entry.isReferenced() && literal) 2675 { 2676 entry.setOnlyLiteralReference(true); 2677 } 2678 else if (entry.isOnlyLiteralReferenced() && !literal) 2682 { 2683 entry.setOnlyLiteralReference(false); 2684 } 2685 } 2686 2687 2688 Node node = entry.getNode(); 2691 if (addImports || node == null || node.getOwnerDocument() == doc) 2692 { 2693 entry.setIsReferenced(true); 2694 if (entry instanceof DefinedElement) 2695 { 2696 BooleanHolder forElement = new BooleanHolder (); 2697 QName referentName = Utils.getTypeQName(node, forElement, false); 2698 if (referentName != null) 2699 { 2700 TypeEntry referent = getTypeEntry(referentName, forElement.value); 2701 if (referent != null) 2702 { 2703 setTypeReferences(referent, doc, literal); 2704 } 2705 } 2706 QName anonQName = SchemaUtils.getElementAnonQName(entry.getNode()); 2709 if (anonQName != null) 2710 { 2711 TypeEntry anonType = getType(anonQName); 2712 if (anonType != null) 2713 { 2714 setTypeReferences(anonType, doc, literal); 2715 return; 2716 } 2717 } 2718 } 2719 } 2720 2721 HashSet nestedTypes = Utils.getNestedTypes(entry, this, true); 2722 Iterator it = nestedTypes.iterator(); 2723 while (it.hasNext()) 2724 { 2725 TypeEntry nestedType = (TypeEntry)it.next(); 2726 if (!nestedType.isReferenced()) 2727 { 2728 if (nestedType != entry) 2730 setTypeReferences(nestedType, doc, false); 2731 } 2732 } 2733 } 2735 2739 private void setMessageReferences(MessageEntry entry, Definition def, Document doc, boolean literal) 2740 { 2741 Message message = entry.getMessage(); 2744 if (addImports) 2745 { 2746 entry.setIsReferenced(true); 2747 } 2748 else 2749 { 2750 Map messages = def.getMessages(); 2754 if (messages.containsValue(message)) 2755 { 2756 entry.setIsReferenced(true); 2757 } 2758 } 2759 2760 Iterator parts = message.getParts().values().iterator(); 2762 while (parts.hasNext()) 2763 { 2764 Part part = (Part)parts.next(); 2765 TypeEntry type = getType(part.getTypeName()); 2766 if (type != null) 2767 { 2768 setTypeReferences(type, doc, literal); 2769 } 2770 type = getElement(part.getElementName()); 2771 if (type != null) 2772 { 2773 setTypeReferences(type, doc, literal); 2774 TypeEntry refType = type.getRefType(); 2775 if (refType != null) 2776 { 2777 setTypeReferences(refType, doc, literal); 2778 } 2779 } 2780 } 2781 } 2783 2787 private void setPortTypeReferences(PortTypeEntry entry, BindingEntry bEntry, 2788 Definition def, Document doc) 2789 { 2790 PortType portType = entry.getPortType(); 2793 if (addImports) 2794 { 2795 entry.setIsReferenced(true); 2796 } 2797 else 2798 { 2799 Map portTypes = def.getPortTypes(); 2803 if (portTypes.containsValue(portType)) 2804 { 2805 entry.setIsReferenced(true); 2806 } 2807 } 2808 2809 Iterator operations = portType.getOperations().iterator(); 2811 2812 while (operations.hasNext()) 2814 { 2815 Operation operation = (Operation)operations.next(); 2816 2817 Input input = operation.getInput(); 2818 Output output = operation.getOutput(); 2819 2820 boolean literalInput = false; 2822 boolean literalOutput = false; 2823 if (bEntry != null) 2824 { 2825 literalInput = bEntry.getInputBodyType(operation) == 2826 Use.LITERAL; 2827 literalOutput = bEntry.getOutputBodyType(operation) == 2828 Use.LITERAL; 2829 } 2830 2831 if (input != null) 2833 { 2834 Message message = input.getMessage(); 2835 if (message != null) 2836 { 2837 MessageEntry mEntry = getMessageEntry(message.getQName()); 2838 if (mEntry != null) 2839 { 2840 setMessageReferences(mEntry, def, doc, literalInput); 2841 } 2842 } 2843 } 2844 2845 if (output != null) 2847 { 2848 Message message = output.getMessage(); 2849 if (message != null) 2850 { 2851 MessageEntry mEntry = getMessageEntry(message.getQName()); 2852 if (mEntry != null) 2853 { 2854 setMessageReferences(mEntry, def, doc, literalOutput); 2855 } 2856 } 2857 } 2858 2859 Iterator faults = 2861 operation.getFaults().values().iterator(); 2862 while (faults.hasNext()) 2863 { 2864 Message message = ((Fault)faults.next()).getMessage(); 2865 if (message != null) 2866 { 2867 MessageEntry mEntry = getMessageEntry(message.getQName()); 2868 if (mEntry != null) 2869 { 2870 setMessageReferences(mEntry, def, doc, false); 2871 } 2872 } 2873 } 2874 } 2875 } 2877 2881 private void setBindingReferences(BindingEntry entry, Definition def, Document doc) 2882 { 2883 2884 if (entry.getBindingType() == BindingEntry.TYPE_SOAP) 2885 { 2886 Binding binding = entry.getBinding(); 2889 if (addImports) 2890 { 2891 entry.setIsReferenced(true); 2892 } 2893 else 2894 { 2895 Map bindings = def.getBindings(); 2899 if (bindings.containsValue(binding)) 2900 { 2901 entry.setIsReferenced(true); 2902 } 2903 } 2904 2905 PortType portType = binding.getPortType(); 2907 PortTypeEntry ptEntry = getPortTypeEntry(portType.getQName()); 2908 if (ptEntry != null) 2909 { 2910 setPortTypeReferences(ptEntry, entry, def, doc); 2911 } 2912 } 2913 } 2915 2919 private void setServiceReferences(ServiceEntry entry, Definition def, Document doc) 2920 { 2921 Service service = entry.getService(); 2924 if (addImports) 2925 { 2926 entry.setIsReferenced(true); 2927 } 2928 else 2929 { 2930 Map services = def.getServices(); 2934 if (services.containsValue(service)) 2935 { 2936 entry.setIsReferenced(true); 2937 } 2938 } 2939 2940 Iterator ports = service.getPorts().values().iterator(); 2942 while (ports.hasNext()) 2943 { 2944 Port port = (Port)ports.next(); 2945 Binding binding = port.getBinding(); 2946 if (binding != null) 2947 { 2948 BindingEntry bEntry = getBindingEntry(binding.getQName()); 2949 if (bEntry != null) 2950 { 2951 setBindingReferences(bEntry, def, doc); 2952 } 2953 } 2954 } 2955 } 2957 2960 private void symbolTablePut(SymTabEntry entry) throws IOException 2961 { 2962 QName name = entry.getQName(); 2963 if (get(name, entry.getClass()) == null) 2964 { 2965 if (entry instanceof Type && 2967 get(name, UndefinedType.class) != null) 2968 { 2969 2970 2975 if (((TypeEntry)get(name, UndefinedType.class)).isSimpleType() && 2976 !((TypeEntry)entry).isSimpleType()) 2977 { 2978 throw new IOException (Messages.getMessage("AttrNotSimpleType01", 2981 name.toString())); 2982 2983 } 2984 Vector v = (Vector )symbolTable.get(name); 2985 for (int i = 0; i < v.size(); ++i) 2986 { 2987 Object oldEntry = v.elementAt(i); 2988 if (oldEntry instanceof UndefinedType) 2989 { 2990 2991 v.setElementAt(entry, i); 2993 2994 typeTypeEntries.put(name, entry); 2996 2997 ((UndefinedType)oldEntry).update((Type)entry); 2999 } 3000 } 3001 } 3002 else if (entry instanceof Element && 3003 get(name, UndefinedElement.class) != null) 3004 { 3005 Vector v = (Vector )symbolTable.get(name); 3010 for (int i = 0; i < v.size(); ++i) 3011 { 3012 Object oldEntry = v.elementAt(i); 3013 if (oldEntry instanceof UndefinedElement) 3014 { 3015 3016 v.setElementAt(entry, i); 3018 3019 elementTypeEntries.put(name, entry); 3021 3022 ((Undefined)oldEntry).update((Element)entry); 3024 } 3025 } 3026 } 3027 else 3028 { 3029 Vector v = (Vector )symbolTable.get(name); 3031 if (v == null) 3032 { 3033 v = new Vector (); 3034 symbolTable.put(name, v); 3035 } 3036 v.add(entry); 3037 if (entry instanceof Element) 3040 { 3041 elementTypeEntries.put(name, entry); 3042 } 3043 else if (entry instanceof Type) 3044 { 3045 typeTypeEntries.put(name, entry); 3046 } 3047 } 3048 } 3049 else 3050 { 3051 System.out.println(Messages.getMessage("alreadyExists00", "" + name)); 3052 } 3053 } 3055 3056 3065 protected boolean existsPortWithName(QName name) 3066 { 3067 Vector v = (Vector )symbolTable.get(name); 3068 if (v == null) return false; 3069 Iterator it = v.iterator(); 3070 while (it.hasNext()) 3071 { 3072 Object o = it.next(); 3073 if (o instanceof PortEntry) return true; 3074 } 3075 return false; 3076 } 3077 3078 3079 private static QName getInnerCollectionComponentQName(Node node) 3080 { 3081 if (node == null) 3082 { 3083 return null; 3084 } 3085 3086 QName name = SchemaUtils.getCollectionComponentQName(node); 3087 if (name != null) 3088 return name; 3089 3090 NodeList children = node.getChildNodes(); 3092 for (int i = 0; i < children.getLength(); i++) 3093 { 3094 name = getInnerCollectionComponentQName(children.item(i)); 3095 if (name != null) 3096 return name; 3097 } 3098 return null; 3099 } 3100 3101 private static QName getInnerTypeQName(Node node) 3102 { 3103 if (node == null) 3104 { 3105 return null; 3106 } 3107 3108 BooleanHolder forElement = new BooleanHolder (); 3109 QName name = Utils.getTypeQName(node, forElement, true); 3110 if (name != null) 3111 return name; 3112 3113 NodeList children = node.getChildNodes(); 3115 for (int i = 0; i < children.getLength(); i++) 3116 { 3117 name = getInnerTypeQName(children.item(i)); 3118 if (name != null) 3119 return name; 3120 } 3121 return null; 3122 } 3123 3124} | Popular Tags |