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 } 820 830 private void lookForImports(URL context, Node node) 831 throws IOException , ParserConfigurationException , SAXException , 832 WSDLException { 833 834 NodeList children = node.getChildNodes(); 835 836 for (int i = 0; i < children.getLength(); i++) { 837 Node child = children.item(i); 838 839 if ("import".equals(child.getLocalName())) { 840 NamedNodeMap attributes = child.getAttributes(); 841 Node namespace = attributes.getNamedItem("namespace"); 842 843 if ((namespace != null) 845 && isKnownNamespace(namespace.getNodeValue())) { 846 continue; 847 } 848 849 Node importFile = attributes.getNamedItem("schemaLocation"); 850 851 if (importFile != null) { 852 URL url = getURL(context, importFile.getNodeValue()); 853 854 if (!importedFiles.contains(url)) { 855 importedFiles.add(url); 856 857 String filename = url.toString(); 858 859 populate(url, null, XMLUtils.newDocument(filename), 860 filename); 861 } 862 } 863 } 864 865 lookForImports(context, child); 866 } 867 } 869 875 public boolean isKnownNamespace(String namespace) { 876 877 if (Constants.isSOAP_ENC(namespace)) { 878 return true; 879 } 880 881 if (Constants.isSchemaXSD(namespace)) { 882 return true; 883 } 884 885 if (Constants.isSchemaXSI(namespace)) { 886 return true; 887 } 888 889 if (namespace.equals(Constants.NS_URI_XML)) { 890 return true; 891 } 892 893 return false; 894 } 895 896 906 public void populateTypes(URL context, Document doc) 907 throws IOException , SAXException , WSDLException, 908 ParserConfigurationException { 909 addTypes(context, doc, ABOVE_SCHEMA_LEVEL); 910 } 912 924 private static final int ABOVE_SCHEMA_LEVEL = -1; 925 926 927 private static final int SCHEMA_LEVEL = 0; 928 929 940 private void addTypes(URL context, Node node, int level) 941 throws IOException , ParserConfigurationException , WSDLException, 942 SAXException { 943 944 if (node == null) { 945 return; 946 } 947 948 String localPart = node.getLocalName(); 950 951 if (localPart != null) { 952 boolean isXSD = 953 Constants.isSchemaXSD(node.getNamespaceURI()); 954 955 if (((isXSD && localPart.equals("complexType")) 956 || localPart.equals("simpleType"))) { 957 958 Node re = SchemaUtils.getRestrictionOrExtensionNode(node); 961 962 if ((re != null) && (Utils.getAttribute(re, "base") != null)) { 963 createTypeFromRef(re); 964 } 965 966 Node list = SchemaUtils.getListNode(node); 967 if (list != null && Utils.getAttribute(list,"itemType") != null) { 968 createTypeFromRef(list); 969 } 970 971 Node union = SchemaUtils.getUnionNode(node); 972 if (union != null) { 973 QName [] memberTypes = Utils.getMemberTypeQNames(union); 974 if (memberTypes != null) { 975 for (int i=0;i<memberTypes.length;i++) { 976 if (SchemaUtils.isSimpleSchemaType(memberTypes[i]) && 977 getType(memberTypes[i]) == null) { 978 symbolTablePut(new BaseType(memberTypes[i])); 979 } 980 } 981 } 982 } 983 984 createTypeFromDef(node, false, false); 987 } else if (isXSD && localPart.equals("element")) { 988 989 createTypeFromRef(node); 991 992 Node re = SchemaUtils.getRestrictionOrExtensionNode(node); 995 996 if ((re != null) && (Utils.getAttribute(re, "base") != null)) { 997 createTypeFromRef(re); 998 } 999 1000 createTypeFromDef(node, true, level > SCHEMA_LEVEL); 1004 } else if (isXSD && localPart.equals("attributeGroup")) { 1005 1006 createTypeFromRef(node); 1009 1010 createTypeFromDef(node, false, level > SCHEMA_LEVEL); 1012 } else if (isXSD && localPart.equals("group")) { 1013 createTypeFromRef(node); 1015 createTypeFromDef(node, false, level > SCHEMA_LEVEL); 1017 } else if (isXSD && localPart.equals("attribute")) { 1018 1019 BooleanHolder forElement = new BooleanHolder (); 1021 QName refQName = Utils.getTypeQName(node, forElement, 1022 false); 1023 1024 if ((refQName != null) && !forElement.value) { 1025 createTypeFromRef(node); 1026 1027 if (refQName != null) { 1030 TypeEntry refType = getTypeEntry(refQName, false); 1031 1032 if ((refType != null) 1033 && (refType instanceof Undefined)) { 1034 1035 refType.setSimpleType(true); 1038 } else if ((refType == null) 1039 || (!(refType instanceof BaseType) 1040 && !refType.isSimpleType())) { 1041 1042 throw new IOException ( 1044 Messages.getMessage( 1045 "AttrNotSimpleType01", 1046 refQName.toString())); 1047 } 1048 } 1049 } 1050 createTypeFromDef(node, true, level > SCHEMA_LEVEL); 1051 } else if (isXSD && localPart.equals("any")) { 1052 1053 if (getType(Constants.XSD_ANY) == null) { 1055 Type type = new BaseType(Constants.XSD_ANY); 1056 1057 symbolTablePut(type); 1058 } 1059 } else if (localPart.equals("part") 1060 && Constants.isWSDL(node.getNamespaceURI())) { 1061 1062 createTypeFromRef(node); 1064 } else if (isXSD && localPart.equals("include")) { 1065 String includeName = Utils.getAttribute(node, "schemaLocation"); 1066 1067 if (includeName != null) { 1068 URL url = getURL(context, includeName); 1069 Document includeDoc = XMLUtils.newDocument(url.toString()); 1070 1071 org.w3c.dom.Element schemaEl = 1073 includeDoc.getDocumentElement(); 1074 1075 if (!schemaEl.hasAttribute("targetNamespace")) { 1076 org.w3c.dom.Element parentSchemaEl = 1077 (org.w3c.dom.Element ) node.getParentNode(); 1078 1079 if (parentSchemaEl.hasAttribute("targetNamespace")) { 1080 1081 String tns = 1085 parentSchemaEl.getAttribute("targetNamespace"); 1086 1087 schemaEl.setAttribute("targetNamespace", tns); 1088 schemaEl.setAttribute("xmlns", tns); 1089 } 1090 } 1091 1092 populate(url, null, includeDoc, url.toString()); 1093 } 1094 } 1095 } 1096 1097 if (level == ABOVE_SCHEMA_LEVEL) { 1098 if ((localPart != null) 1099 && localPart.equals("schema")) { 1100 level = SCHEMA_LEVEL; 1101 String targetNamespace = ((org.w3c.dom.Element ) node).getAttribute("targetNamespace"); 1102 String elementFormDefault = ((org.w3c.dom.Element ) node).getAttribute("elementFormDefault"); 1103 if (targetNamespace != null && targetNamespace.length() > 0) { 1104 elementFormDefault = (elementFormDefault == null || elementFormDefault.length() == 0) ? 1105 "unqualified" : elementFormDefault; 1106 if(elementFormDefaults.get(targetNamespace)==null) { 1107 elementFormDefaults.put(targetNamespace, elementFormDefault); 1108 } 1109 } 1110 } 1111 } else { 1112 ++level; 1113 } 1114 1115 NodeList children = node.getChildNodes(); 1117 1118 for (int i = 0; i < children.getLength(); i++) { 1119 addTypes(context, children.item(i), level); 1120 } 1121 } 1123 1132 private void createTypeFromDef( 1133 Node node, boolean isElement, boolean belowSchemaLevel) 1134 throws IOException { 1135 1136 QName qName = Utils.getNodeNameQName(node); 1138 1139 if (qName != null) { 1140 1141 if (!isElement && (btm.getBaseName(qName) != null)) { 1144 return; 1145 } 1146 1147 BooleanHolder forElement = new BooleanHolder (); 1150 QName refQName = Utils.getTypeQName(node, forElement, 1151 false); 1152 1153 if (refQName != null) { 1154 1155 if (qName.getLocalPart().length() == 0) { 1157 String name = Utils.getAttribute(node, "name"); 1158 1159 if (name == null) { 1160 name = "unknown"; 1161 } 1162 1163 throw new IOException (Messages.getMessage("emptyref00", 1164 name)); 1165 } 1166 1167 TypeEntry refType = getTypeEntry(refQName, forElement.value); 1169 1170 if (!belowSchemaLevel) { 1171 if (refType == null) { 1172 throw new IOException ( 1173 Messages.getMessage( 1174 "absentRef00", refQName.toString(), 1175 qName.toString())); 1176 } 1177 1178 symbolTablePut(new DefinedElement(qName, refType, node, 1179 "")); 1180 } 1181 } else { 1182 1183 IntHolder numDims = new IntHolder (); 1186 BooleanHolder underlTypeNillable = new BooleanHolder (); 1187 1188 QNameHolder itemQName = wrapArrays ? null : new QNameHolder (); 1191 1192 numDims.value = 0; 1193 1194 QName arrayEQName = 1195 SchemaUtils.getArrayComponentQName(node, 1196 numDims, 1197 underlTypeNillable, 1198 itemQName, 1199 this); 1200 1201 if (arrayEQName != null) { 1202 1203 refQName = arrayEQName; 1205 1206 TypeEntry refType = getTypeEntry(refQName, false); 1207 1208 if (refType == null) { 1209 1211 String baseName = btm.getBaseName(refQName); 1213 1214 if (baseName != null) { 1215 refType = new BaseType(refQName); 1216 } else { 1217 refType = new UndefinedType(refQName); 1218 } 1219 1220 symbolTablePut(refType); 1221 } 1222 1223 String dims = ""; 1225 1226 while (numDims.value > 0) { 1227 dims += "[]"; 1228 1229 numDims.value--; 1230 } 1231 1232 TypeEntry defType = null; 1233 1234 if (isElement) { 1235 if (!belowSchemaLevel) { 1236 defType = 1237 new DefinedElement(qName, refType, node, dims); 1238 defType.setComponentType(arrayEQName); 1240 if (itemQName != null) 1241 defType.setItemQName(itemQName.value); 1242 } 1243 } else { 1244 defType = new DefinedType(qName, refType, node, dims); 1245 defType.setComponentType(arrayEQName); 1247 defType.setUnderlTypeNillable(underlTypeNillable.value); 1248 if (itemQName != null) 1249 defType.setItemQName(itemQName.value); 1250 } 1251 1252 if (defType != null) { 1253 symbolTablePut(defType); 1254 } 1255 } else { 1256 1257 String baseName = btm.getBaseName(qName); 1259 1260 if (baseName != null) { 1261 symbolTablePut(new BaseType(qName)); 1262 } else { 1263 1264 TypeEntry te = null; 1268 TypeEntry parentType = null; 1269 1270 if (!isElement) { 1271 te = new DefinedType(qName, node); 1272 1273 if (qName.getLocalPart().indexOf(ANON_TOKEN) >= 0) { 1277 Node parent = node.getParentNode(); 1278 QName parentQName = 1279 Utils.getNodeNameQName(parent); 1280 parentType = getElement(parentQName); 1281 } 1282 } else { 1283 if (!belowSchemaLevel) { 1284 te = new DefinedElement(qName, node); 1285 } 1286 } 1287 1288 if (te != null) { 1289 if (SchemaUtils.isSimpleTypeOrSimpleContent(node)) { 1290 te.setSimpleType(true); 1291 } 1292 te = (TypeEntry)symbolTablePut(te); 1293 1294 if (parentType != null) { 1295 parentType.setRefType(te); 1296 } 1297 } 1298 } 1299 } 1300 } 1301 } 1302 } 1304 1311 private void createTypeFromRef(Node node) throws IOException { 1312 1313 BooleanHolder forElement = new BooleanHolder (); 1315 QName qName = Utils.getTypeQName(node, forElement, false); 1316 1317 if (qName == null || (Constants.isSchemaXSD(qName.getNamespaceURI()) && 1318 qName.getLocalPart().equals("simpleRestrictionModel"))) { 1319 return; 1320 } 1321 1322 if (qName.getLocalPart().length() == 0) { 1324 String name = Utils.getAttribute(node, "name"); 1325 1326 if (name == null) { 1327 name = "unknown"; 1328 } 1329 1330 throw new IOException (Messages.getMessage("emptyref00", name)); 1331 } 1332 1333 TypeEntry type = getTypeEntry(qName, forElement.value); 1335 1336 if (type == null) { 1338 1339 if (qName.getLocalPart().indexOf("[") > 0) { 1341 QName containedQName = Utils.getTypeQName(node, 1342 forElement, true); 1343 TypeEntry containedTE = getTypeEntry(containedQName, 1344 forElement.value); 1345 1346 if (!forElement.value) { 1347 1348 if (containedTE == null) { 1350 1351 String baseName = btm.getBaseName(containedQName); 1353 1354 if (baseName != null) { 1355 containedTE = new BaseType(containedQName); 1356 } else { 1357 containedTE = new UndefinedType(containedQName); 1358 } 1359 1360 symbolTablePut(containedTE); 1361 } 1362 symbolTablePut(new CollectionType(qName, containedTE, 1363 node, "[]")); 1364 } else { 1365 1366 if (containedTE == null) { 1368 containedTE = new UndefinedElement(containedQName); 1369 1370 symbolTablePut(containedTE); 1371 } 1372 1373 symbolTablePut(new CollectionElement(qName, 1374 containedTE, node, 1375 "[]")); 1376 } 1377 } else { 1378 1379 String baseName = btm.getBaseName(qName); 1381 1382 if (baseName != null) { 1383 symbolTablePut(new BaseType(qName)); 1384 1385 } else if (qName.equals(Constants.SOAP_COMMON_ATTRS11)) { 1389 symbolTablePut(new BaseType(qName)); 1390 1391 if (getTypeEntry(Constants.XSD_ID, false) == null) { 1395 symbolTablePut(new BaseType(Constants.XSD_ID)); 1396 } 1397 1398 if (getTypeEntry(Constants.XSD_ANYURI, false) == null) { 1400 symbolTablePut(new BaseType(Constants.XSD_ANYURI)); 1401 } 1402 } else if (qName.equals(Constants.SOAP_COMMON_ATTRS12)) { 1403 symbolTablePut(new BaseType(qName)); 1404 1405 if (getTypeEntry(Constants.XSD_ID, false) == null) { 1409 symbolTablePut(new BaseType(Constants.XSD_ID)); 1410 } 1411 } else if (qName.equals(Constants.SOAP_ARRAY_ATTRS11)) { 1412 symbolTablePut(new BaseType(qName)); 1413 1414 if (getTypeEntry(Constants.XSD_STRING, false) == null) { 1418 symbolTablePut(new BaseType(Constants.XSD_STRING)); 1419 } 1420 1421 } else if (qName.equals(Constants.SOAP_ARRAY_ATTRS12)) { 1424 symbolTablePut(new BaseType(qName)); 1425 1426 if (getTypeEntry(Constants.XSD_STRING, false) == null) { 1432 symbolTablePut(new BaseType(Constants.XSD_STRING)); 1433 } 1434 1435 if (getTypeEntry(Constants.XSD_QNAME, false) == null) { 1437 symbolTablePut(new BaseType(Constants.XSD_QNAME)); 1438 } 1439 } else if (forElement.value == false) { 1440 symbolTablePut(new UndefinedType(qName)); 1441 } else { 1442 symbolTablePut(new UndefinedElement(qName)); 1443 } 1444 } 1445 } 1446 } 1448 1454 private void populateMessages(Definition def) throws IOException { 1455 1456 Iterator i = def.getMessages().values().iterator(); 1457 1458 while (i.hasNext()) { 1459 Message message = (Message) i.next(); 1460 MessageEntry mEntry = new MessageEntry(message); 1461 1462 symbolTablePut(mEntry); 1463 } 1464 } 1466 1484 protected void ensureOperationMessageValid(Message message) 1485 throws IOException { 1486 1487 if (message == null) { 1491 throw new IOException ( 1492 "<input>,<output>, or <fault> in <operation ..> without attribute 'message' found. Attribute 'message' is required."); 1493 } 1494 1495 if (message.isUndefined()) { 1499 throw new IOException ( 1500 "<input ..>, <output ..> or <fault ..> in <portType> with undefined message found. message name is '" 1501 + message.getQName().toString() + "'"); 1502 } 1503 } 1504 1505 1517 protected void ensureOperationValid(Operation operation) 1518 throws IOException { 1519 1520 if (operation == null) { 1521 throw new IllegalArgumentException ( 1522 "parameter 'operation' must not be null"); 1523 } 1524 1525 Input input = operation.getInput(); 1526 Message message; 1527 1528 if (input != null) { 1529 message = input.getMessage(); 1530 if (message == null) { 1531 throw new IOException ( 1532 "No 'message' attribute in <input> for operation '" + 1533 operation.getName() + "'"); 1534 } 1535 ensureOperationMessageValid(message); 1536 } 1537 1538 Output output = operation.getOutput(); 1539 1540 if (output != null) { 1541 message = output.getMessage(); 1542 if (message == null) { 1543 throw new IOException ( 1544 "No 'message' attribute in <output> for operation '" + 1545 operation.getName() + "'"); 1546 } 1547 ensureOperationMessageValid(output.getMessage()); 1548 } 1549 1550 Map faults = operation.getFaults(); 1551 1552 if (faults != null) { 1553 Iterator it = faults.values().iterator(); 1554 1555 while (it.hasNext()) { 1556 Fault fault = (Fault)it.next(); 1557 message = fault.getMessage(); 1558 if (message == null) { 1559 throw new IOException ( 1560 "No 'message' attribute in <fault> named '" + 1561 fault.getName() + "' for operation '" + 1562 operation.getName() + "'"); 1563 } 1564 ensureOperationMessageValid(message); 1565 } 1566 } 1567 } 1568 1569 1580 protected void ensureOperationsOfPortTypeValid(PortType portType) 1581 throws IOException { 1582 1583 if (portType == null) { 1584 throw new IllegalArgumentException ( 1585 "parameter 'portType' must not be null"); 1586 } 1587 1588 List operations = portType.getOperations(); 1589 1590 if ((operations == null) || (operations.size() == 0)) { 1593 return; 1594 } 1595 1596 Iterator it = operations.iterator(); 1599 1600 while (it.hasNext()) { 1601 Operation operation = (Operation) it.next(); 1602 1603 ensureOperationValid(operation); 1604 } 1605 } 1606 1607 1613 private void populatePortTypes(Definition def) throws IOException { 1614 1615 Iterator i = def.getPortTypes().values().iterator(); 1616 1617 while (i.hasNext()) { 1618 PortType portType = (PortType) i.next(); 1619 1620 if (!portType.isUndefined()) { 1624 ensureOperationsOfPortTypeValid(portType); 1625 1626 PortTypeEntry ptEntry = new PortTypeEntry(portType); 1627 1628 symbolTablePut(ptEntry); 1629 } 1630 } 1631 } 1633 1638 private void populateParameters() throws IOException { 1639 1640 Iterator it = symbolTable.values().iterator(); 1641 1642 while (it.hasNext()) { 1643 Vector v = (Vector ) it.next(); 1644 1645 for (int i = 0; i < v.size(); ++i) { 1646 if (v.get(i) instanceof BindingEntry) { 1647 BindingEntry bEntry = (BindingEntry) v.get(i); 1648 1649 if (bEntry.getBindingType() != BindingEntry.TYPE_SOAP) { 1651 continue; 1652 } 1653 1654 Binding binding = bEntry.getBinding(); 1655 Collection bindOperations = bEntry.getOperations(); 1656 PortType portType = binding.getPortType(); 1657 HashMap parameters = new HashMap (); 1658 Iterator operations = 1659 portType.getOperations().iterator(); 1660 1661 while (operations.hasNext()) { 1663 Operation operation = (Operation) operations.next(); 1664 1665 if (!bindOperations.contains(operation)) { 1668 throw new IOException ( 1669 Messages.getMessage( 1670 "emitFailNoMatchingBindOperation01", 1671 operation.getName(), 1672 portType.getQName().getLocalPart())); 1673 } 1674 1675 String namespace = 1676 portType.getQName().getNamespaceURI(); 1677 Parameters parms = getOperationParameters(operation, 1678 namespace, bEntry); 1679 parameters.put(operation, parms); 1680 } 1681 1682 bEntry.setParameters(parameters); 1683 } 1684 } 1685 } 1686 } 1688 1700 public Parameters getOperationParameters( 1701 Operation operation, String namespace, BindingEntry bindingEntry) 1702 throws IOException { 1703 1704 Parameters parameters = new Parameters(); 1705 1706 Vector inputs = new Vector (); 1708 Vector outputs = new Vector (); 1709 List parameterOrder = operation.getParameterOrdering(); 1710 1711 if ((parameterOrder != null) && parameterOrder.isEmpty()) { 1713 parameterOrder = null; 1714 } 1715 1716 Input input = operation.getInput(); 1717 Output output = operation.getOutput(); 1718 1719 parameters.mep = operation.getStyle(); 1720 1721 if (parameterOrder != null && !wrapped) { 1723 if (input != null) { 1724 Message inputMsg = input.getMessage(); 1725 Map allInputs = inputMsg.getParts(); 1726 Collection orderedInputs = 1727 inputMsg.getOrderedParts(parameterOrder); 1728 1729 if (allInputs.size() != orderedInputs.size()) { 1730 throw new IOException ( 1731 Messages.getMessage("emitFail00", operation.getName())); 1732 } 1733 } 1734 } 1735 1736 boolean literalInput = false; 1737 boolean literalOutput = false; 1738 1739 if (bindingEntry != null) { 1740 literalInput = (bindingEntry.getInputBodyType(operation) 1741 == Use.LITERAL); 1742 literalOutput = (bindingEntry.getOutputBodyType(operation) 1743 == Use.LITERAL); 1744 } 1745 1746 if ((input != null) && (input.getMessage() != null)) { 1748 getParametersFromParts(inputs, 1749 input.getMessage().getOrderedParts(null), 1750 literalInput, operation.getName(), 1751 bindingEntry); 1752 } 1753 1754 if ((output != null) && (output.getMessage() != null)) { 1756 getParametersFromParts(outputs, 1757 output.getMessage().getOrderedParts(null), 1758 literalOutput, operation.getName(), 1759 bindingEntry); 1760 } 1761 1762 if (parameterOrder != null && !wrapped) { 1763 1764 for (int i = 0; i < parameterOrder.size(); ++i) { 1767 String name = (String ) parameterOrder.get(i); 1768 1769 int index = getPartIndex(name, inputs); 1771 1772 int outdex = getPartIndex(name, outputs); 1774 1775 if (index >= 0) { 1776 1777 addInishParm(inputs, outputs, index, outdex, parameters, 1779 true); 1780 } else if (outdex >= 0) { 1781 addOutParm(outputs, outdex, parameters, true); 1782 } else { 1783 System.err.println(Messages.getMessage("noPart00", name)); 1784 } 1785 } 1786 } 1787 1788 if (wrapped && (inputs.size() == 1) && (outputs.size() == 1) 1794 && 1795 Utils.getLastLocalPart(((Parameter) inputs.get(0)).getName()).equals( 1796 Utils.getLastLocalPart(((Parameter) outputs.get(0)).getName())) 1797 ) { 1798 1799 addInishParm(inputs, null, 0, -1, parameters, false); 1801 } else { 1802 1803 for (int i = 0; i < inputs.size(); i++) { 1808 Parameter p = (Parameter) inputs.get(i); 1809 int outdex = getPartIndex(p.getName(), outputs); 1810 1811 addInishParm(inputs, outputs, i, outdex, parameters, false); 1812 } 1813 } 1814 1815 if (outputs.size() == 1) { 1820 parameters.returnParam = (Parameter) outputs.get(0); 1821 1822 parameters.returnParam.setMode(Parameter.OUT); 1823 1824 if (parameters.returnParam.getType() instanceof DefinedElement) { 1825 parameters.returnParam.setQName( 1826 parameters.returnParam.getType().getQName()); 1827 } 1828 1829 ++parameters.outputs; 1830 } else { 1831 for (int i = 0; i < outputs.size(); i++) { 1832 addOutParm(outputs, i, parameters, false); 1833 } 1834 } 1835 1836 parameters.faults = operation.getFaults(); 1837 1838 Vector used = new Vector (parameters.list.size()); 1841 Iterator i = parameters.list.iterator(); 1842 1843 while (i.hasNext()) { 1844 Parameter parameter = (Parameter) i.next(); 1845 int count = 2; 1846 1847 while (used.contains(parameter.getName())) { 1848 1849 parameter.setName(parameter.getName() 1851 + Integer.toString(count++)); 1852 } 1853 1854 used.add(parameter.getName()); 1855 } 1856 1857 return parameters; 1858 } 1860 1867 private int getPartIndex(String name, Vector v) { 1868 name = Utils.getLastLocalPart(name); 1869 for (int i = 0; i < v.size(); i++) { 1870 String paramName = ((Parameter) v.get(i)).getName(); 1871 paramName = Utils.getLastLocalPart(paramName); 1872 if (name.equals(paramName)) { 1873 return i; 1874 } 1875 } 1876 1877 return -1; 1878 } 1880 1890 private void addInishParm(Vector inputs, Vector outputs, int index, 1891 int outdex, Parameters parameters, 1892 boolean trimInput) { 1893 1894 Parameter p = (Parameter) inputs.get(index); 1895 1896 if (p.getType() instanceof DefinedElement) { 1899 DefinedElement de = (DefinedElement) p.getType(); 1900 1901 p.setQName(de.getQName()); 1902 } 1903 1904 if (p.getType() instanceof CollectionElement) { 1908 p.setQName(p.getType().getRefType().getQName()); 1909 } 1910 1911 if (trimInput) { 1913 inputs.remove(index); 1914 } 1915 1916 if (outdex >= 0) { 1920 Parameter outParam = (Parameter) outputs.get(outdex); 1921 1922 TypeEntry paramEntry = p.getType(); 1923 TypeEntry outParamEntry = outParam.getType(); 1924 if (paramEntry.equals(outParamEntry)) { 1927 outputs.remove(outdex); 1928 p.setMode(Parameter.INOUT); 1929 1930 ++parameters.inouts; 1931 } 1932 1959 else { 1960 1961 ++parameters.inputs; 1978 } 1979 } else { 1980 ++parameters.inputs; 1981 } 1982 1983 parameters.list.add(p); 1984 } 1986 1994 private void addOutParm(Vector outputs, int outdex, Parameters parameters, 1995 boolean trim) { 1996 1997 Parameter p = (Parameter) outputs.get(outdex); 1998 1999 if (p.getType() instanceof DefinedElement) { 2002 DefinedElement de = (DefinedElement) p.getType(); 2003 2004 p.setQName(de.getQName()); 2005 } 2006 2007 if (p.getType() instanceof CollectionElement) { 2011 p.setQName(p.getType().getRefType().getQName()); 2012 } 2013 2014 if (trim) { 2015 outputs.remove(outdex); 2016 } 2017 2018 p.setMode(Parameter.OUT); 2019 2020 ++parameters.outputs; 2021 2022 parameters.list.add(p); 2023 } 2025 2044 public void getParametersFromParts(Vector v, 2045 Collection parts, 2046 boolean literal, 2047 String opName, 2048 BindingEntry bindingEntry) 2049 throws IOException { 2050 2051 int numberOfElements = 0; 2058 boolean possiblyWrapped = false; 2059 Iterator i = parts.iterator(); 2060 2061 while (i.hasNext()) { 2062 Part part = (Part) i.next(); 2063 2064 if (part.getElementName() != null) { 2065 ++numberOfElements; 2066 2067 if (part.getElementName().getLocalPart().equals(opName)) { 2068 possiblyWrapped = true; 2069 } 2070 } 2071 } 2072 2073 2081 if (!nowrap && literal && (numberOfElements == 1) && possiblyWrapped) { 2082 wrapped = true; 2083 } 2084 2085 i = parts.iterator(); 2086 2087 while (i.hasNext()) { 2088 Parameter param = new Parameter(); 2089 Part part = (Part) i.next(); 2090 QName elementName = part.getElementName(); 2091 QName typeName = part.getTypeName(); 2092 String partName = part.getName(); 2093 2094 if (!literal || !wrapped || (elementName == null)) { 2098 param.setName(partName); 2099 2100 if (typeName != null) { 2102 param.setType(getType(typeName)); 2103 } else if (elementName != null) { 2104 2105 param.setType(getElement(elementName)); 2111 } else { 2112 2113 throw new IOException ( 2115 Messages.getMessage( 2116 "noTypeOrElement00", new String []{partName, 2117 opName})); 2118 } 2119 2120 fillParamInfo(param, bindingEntry, opName, partName); 2121 v.add(param); 2122 2123 continue; } 2125 2126 Node node = null; 2130 TypeEntry typeEntry = null; 2131 2132 if ((typeName != null) 2133 && (bindingEntry == null || bindingEntry.getMIMETypes().size() == 0)) { 2134 2135 String bindingName = (bindingEntry == null) 2142 ? "unknown" 2143 : bindingEntry.getBinding().getQName().toString(); 2144 2145 throw new IOException (Messages.getMessage("literalTypePart00", 2146 new String []{ 2147 partName, 2148 opName, 2149 bindingName})); 2150 } 2151 2152 typeEntry = getTypeEntry(elementName, true); 2159 node = typeEntry.getNode(); 2160 2161 BooleanHolder forElement = new BooleanHolder (); 2164 QName type = Utils.getTypeQName(node, forElement, 2165 false); 2166 if ((type != null) && !forElement.value) { 2167 2168 typeEntry = getTypeEntry(type, false); 2171 node = typeEntry.getNode(); 2172 } 2173 2174 Vector vTypes = null; 2175 2176 if (node == null) { 2178 wrapped = false; 2181 } else { 2182 2183 if (typeEntry.getContainedAttributes() != null) { 2185 wrapped = false; 2187 } 2188 2189 if (!SchemaUtils.isWrappedType(node)) { 2190 typeEntry.setOnlyLiteralReference(false); 2197 wrapped = false; 2198 } 2199 2200 vTypes = typeEntry.getContainedElements(); 2205 } 2206 2207 if ((vTypes != null) && wrapped) { 2210 2211 for (int j = 0; j < vTypes.size(); j++) { 2213 ElementDecl elem = (ElementDecl) vTypes.elementAt(j); 2214 Parameter p = new Parameter(); 2215 2216 p.setQName(elem.getQName()); 2217 String paramName = p.getName(); 2220 final int gt = paramName.lastIndexOf(ANON_TOKEN); 2221 if (gt != 1) { 2222 paramName = paramName.substring(gt+1); 2223 } 2224 p.setName(paramName); 2225 p.setType(elem.getType()); 2226 p.setOmittable(elem.getMinOccursIs0()); 2227 fillParamInfo(p, bindingEntry, opName, partName); 2228 v.add(p); 2229 } 2230 } else { 2231 2232 param.setName(partName); 2236 2237 if (typeName != null) { 2238 param.setType(getType(typeName)); 2239 } else if (elementName != null) { 2240 param.setType(getElement(elementName)); 2241 } 2242 2243 fillParamInfo(param, bindingEntry, opName, partName); 2244 v.add(param); 2245 } 2246 } } 2249 2257 private void fillParamInfo(Parameter param, BindingEntry bindingEntry, 2258 String opName, String partName) { 2259 2260 if (bindingEntry == null) 2262 return; 2263 2264 setMIMEInfo(param, bindingEntry.getMIMEInfo(opName, partName)); 2265 2266 boolean isHeader = false; 2267 2268 if (bindingEntry.isInHeaderPart(opName, partName)) { 2270 isHeader = true; 2271 param.setInHeader(true); 2272 } 2273 2274 if (bindingEntry.isOutHeaderPart(opName, partName)) { 2276 isHeader = true; 2277 param.setOutHeader(true); 2278 } 2279 2280 if (isHeader && (bindingEntry.getBinding() != null)) { 2283 List list = bindingEntry.getBinding().getBindingOperations(); 2284 2285 for (int i = 0; (list != null) && (i < list.size()); i++) { 2286 BindingOperation operation = (BindingOperation) list.get(i); 2287 2288 if (operation.getName().equals(opName)) { 2289 if (param.isInHeader()) { 2290 QName qName = getBindedParameterName( 2291 operation.getBindingInput().getExtensibilityElements(), 2292 param); 2293 2294 if(qName!= null) { 2295 param.setQName(qName); 2296 } 2297 } else if (param.isOutHeader()) { 2298 QName qName = getBindedParameterName( 2299 operation.getBindingOutput().getExtensibilityElements(), 2300 param); 2301 2302 if(qName!= null) { 2303 param.setQName(qName); 2304 } 2305 } 2306 } 2307 } 2308 } 2309 } 2310 2311 2318 private QName getBindedParameterName(List elements, Parameter p) { 2319 2320 QName paramName = null; 2330 String defaultNamespace = null; 2331 String parameterPartName = p.getName(); 2332 2333 for (Iterator k = elements.iterator(); k.hasNext();) { 2334 ExtensibilityElement element = (ExtensibilityElement) k.next(); 2335 2336 if (element instanceof SOAPBody) { 2337 SOAPBody bodyElement = (SOAPBody) element; 2338 List parts = bodyElement.getParts(); 2339 2340 if ((parts == null) || (parts.size() == 0)) { 2341 defaultNamespace = bodyElement.getNamespaceURI(); 2342 } else { 2343 boolean found = false; 2344 2345 for (Iterator l = parts.iterator(); l.hasNext();) { 2346 Object o = l.next(); 2347 2348 if(o instanceof String ) { 2349 if (parameterPartName.equals((String )o)) { 2350 paramName = 2351 new QName (bodyElement.getNamespaceURI(), 2352 parameterPartName); 2353 found = true; 2354 break; 2355 } 2356 } 2357 } 2358 2359 if (found) { 2360 break; 2361 } 2362 } 2363 } else if (element instanceof SOAPHeader) { 2364 SOAPHeader headerElement = (SOAPHeader) element; 2365 String part = headerElement.getPart(); 2366 2367 if (parameterPartName.equals(part)) { 2368 paramName = new QName (headerElement.getNamespaceURI(), 2369 parameterPartName); 2370 break; 2371 } 2372 } 2373 } 2374 2375 if ((paramName == null) && (!p.isInHeader()) && (!p.isOutHeader())) { 2376 if (defaultNamespace != null) { 2377 paramName = new QName (defaultNamespace, parameterPartName); 2378 } else { 2379 paramName = p.getQName(); 2380 } 2381 } 2382 2383 return paramName; 2384 } 2385 2386 2394 private void setMIMEInfo(Parameter p, MimeInfo mimeInfo) { 2395 2396 if (mimeInfo == null && p.getType() != null) { 2399 QName mimeQName = p.getType().getQName(); 2400 2401 if (mimeQName.getNamespaceURI().equals(Constants.NS_URI_XMLSOAP)) { 2402 if (Constants.MIME_IMAGE.equals(mimeQName)) { 2403 mimeInfo = new MimeInfo("image/jpeg", ""); 2404 } else if (Constants.MIME_PLAINTEXT.equals(mimeQName)) { 2405 mimeInfo = new MimeInfo("text/plain", ""); 2406 } else if (Constants.MIME_MULTIPART.equals(mimeQName)) { 2407 mimeInfo = new MimeInfo("multipart/related", ""); 2408 } else if (Constants.MIME_SOURCE.equals(mimeQName)) { 2409 mimeInfo = new MimeInfo("text/xml", ""); 2410 } else if (Constants.MIME_OCTETSTREAM.equals(mimeQName)) { 2411 mimeInfo = new MimeInfo("application/octet-stream", ""); 2412 } 2413 } 2414 } 2415 2416 p.setMIMEInfo(mimeInfo); 2417 } 2419 2425 private void populateBindings(Definition def) throws IOException { 2426 2427 Iterator i = def.getBindings().values().iterator(); 2428 2429 while (i.hasNext()) { 2430 Binding binding = (Binding) i.next(); 2431 BindingEntry bEntry = new BindingEntry(binding); 2432 2433 symbolTablePut(bEntry); 2434 2435 Iterator extensibilityElementsIterator = 2436 binding.getExtensibilityElements().iterator(); 2437 2438 while (extensibilityElementsIterator.hasNext()) { 2439 Object obj = extensibilityElementsIterator.next(); 2440 2441 if (obj instanceof SOAPBinding) { 2442 bEntry.setBindingType(BindingEntry.TYPE_SOAP); 2443 2444 SOAPBinding sb = (SOAPBinding) obj; 2445 String style = sb.getStyle(); 2446 2447 if ("rpc".equalsIgnoreCase(style)) { 2448 bEntry.setBindingStyle(Style.RPC); 2449 } 2450 } else if (obj instanceof HTTPBinding) { 2451 HTTPBinding hb = (HTTPBinding) obj; 2452 2453 if (hb.getVerb().equalsIgnoreCase("post")) { 2454 bEntry.setBindingType(BindingEntry.TYPE_HTTP_POST); 2455 } else { 2456 bEntry.setBindingType(BindingEntry.TYPE_HTTP_GET); 2457 } 2458 } else if (obj instanceof UnknownExtensibilityElement) { 2459 2460 UnknownExtensibilityElement unkElement = 2462 (UnknownExtensibilityElement) obj; 2463 QName name = 2464 unkElement.getElementType(); 2465 2466 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) 2467 && name.getLocalPart().equals("binding")) { 2468 bEntry.setBindingType(BindingEntry.TYPE_SOAP); 2469 2470 String style = 2471 unkElement.getElement().getAttribute("style"); 2472 2473 if ("rpc".equalsIgnoreCase(style)) { 2474 bEntry.setBindingStyle(Style.RPC); 2475 } 2476 } 2477 } 2478 } 2479 2480 HashMap attributes = new HashMap (); 2486 List bindList = binding.getBindingOperations(); 2487 HashMap faultMap = new HashMap (); 2489 for (Iterator opIterator = bindList.iterator(); 2490 opIterator.hasNext();) { 2491 BindingOperation bindOp = 2492 (BindingOperation) opIterator.next(); 2493 Operation operation = bindOp.getOperation(); 2494 BindingInput bindingInput = bindOp.getBindingInput(); 2495 BindingOutput bindingOutput = bindOp.getBindingOutput(); 2496 String opName = bindOp.getName(); 2497 2498 String inputName = (bindingInput == null) 2500 ? null 2501 : bindingInput.getName(); 2502 String outputName = (bindingOutput == null) 2503 ? null 2504 : bindingOutput.getName(); 2505 2506 if (binding.getPortType().getOperation( 2507 opName, inputName, outputName) == null) { 2508 throw new IOException (Messages.getMessage("unmatchedOp", 2509 new String []{ 2510 opName, 2511 inputName, 2512 outputName})); 2513 } 2514 2515 ArrayList faults = new ArrayList (); 2516 2517 if (bindingInput != null) { 2519 if (bindingInput.getExtensibilityElements() != null) { 2520 Iterator inIter = 2521 bindingInput.getExtensibilityElements().iterator(); 2522 2523 fillInBindingInfo(bEntry, operation, inIter, faults, 2524 true); 2525 } 2526 } 2527 2528 if (bindingOutput != null) { 2530 if (bindingOutput.getExtensibilityElements() != null) { 2531 Iterator outIter = 2532 bindingOutput.getExtensibilityElements().iterator(); 2533 2534 fillInBindingInfo(bEntry, operation, outIter, faults, 2535 false); 2536 } 2537 } 2538 2539 faultsFromSOAPFault(binding, bindOp, operation, faults); 2541 2542 faultMap.put(bindOp, faults); 2544 2545 Use inputBodyType = bEntry.getInputBodyType(operation); 2546 Use outputBodyType = bEntry.getOutputBodyType(operation); 2547 2548 attributes.put(bindOp.getOperation(), 2551 new BindingEntry.OperationAttr(inputBodyType, 2552 outputBodyType, faultMap)); 2553 2554 if ((inputBodyType == Use.LITERAL) 2557 || (outputBodyType == Use.LITERAL)) { 2558 bEntry.setHasLiteral(true); 2559 } 2560 2561 bEntry.setFaultBodyTypeMap(operation, faultMap); 2562 } 2564 bEntry.setFaults(faultMap); 2565 } 2566 } 2568 2578 private void fillInBindingInfo( 2579 BindingEntry bEntry, Operation operation, Iterator it, ArrayList faults, boolean input) 2580 throws IOException { 2581 2582 for (; it.hasNext();) { 2583 Object obj = it.next(); 2584 2585 if (obj instanceof SOAPBody) { 2586 setBodyType(((SOAPBody) obj).getUse(), bEntry, operation, 2587 input); 2588 } else if (obj instanceof SOAPHeader) { 2589 SOAPHeader header = (SOAPHeader) obj; 2590 2591 setBodyType(header.getUse(), bEntry, operation, input); 2592 2593 bEntry.setHeaderPart(operation.getName(), header.getPart(), 2600 input 2601 ? BindingEntry.IN_HEADER 2602 : BindingEntry.OUT_HEADER); 2603 2604 Iterator headerFaults = header.getSOAPHeaderFaults().iterator(); 2606 2607 while (headerFaults.hasNext()) { 2608 SOAPHeaderFault headerFault = 2609 (SOAPHeaderFault) headerFaults.next(); 2610 2611 faults.add(new FaultInfo(headerFault, this)); 2612 } 2613 } else if (obj instanceof MIMEMultipartRelated) { 2614 bEntry.setBodyType( 2615 operation, 2616 addMIMETypes( 2617 bEntry, (MIMEMultipartRelated) obj, operation), input); 2618 } else if (obj instanceof UnknownExtensibilityElement) { 2619 UnknownExtensibilityElement unkElement = 2620 (UnknownExtensibilityElement) obj; 2621 QName name = 2622 unkElement.getElementType(); 2623 2624 if (name.getNamespaceURI().equals(Constants.URI_DIME_WSDL) 2625 && name.getLocalPart().equals("message")) { 2626 fillInDIMEInformation(unkElement, input, operation, bEntry); 2627 } 2628 2629 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) 2631 && name.getLocalPart().equals("body")) { 2632 setBodyType(unkElement.getElement().getAttribute("use"), 2633 bEntry, operation, input); 2634 } 2635 2636 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) 2638 && name.getLocalPart().equals("header")) { 2639 setBodyType(unkElement.getElement().getAttribute("use"), 2640 bEntry, operation, input); 2641 2642 bEntry.setHeaderPart( 2649 operation.getName(), 2650 unkElement.getElement().getAttribute("part"), input 2651 ? BindingEntry.IN_HEADER 2652 : BindingEntry.OUT_HEADER); 2653 2654 NodeList headerFaults = 2656 unkElement.getElement().getChildNodes(); 2657 2658 for (int i = 0; i < headerFaults.getLength(); i++) { 2659 String faultMessage = 2660 unkElement.getElement().getAttribute("message"); 2661 String faultPart = 2662 unkElement.getElement().getAttribute("part"); 2663 String faultUse = 2664 unkElement.getElement().getAttribute("use"); 2665 String faultNamespaceURI = 2666 unkElement.getElement().getAttribute("namespace"); 2667 QName faultMessageQName = null; 2668 int sep = faultMessage.indexOf(':'); 2669 2670 if (sep == -1) { 2671 faultMessageQName = new QName (faultMessage); 2672 } else { 2673 faultMessageQName = 2674 new QName (faultMessage.substring(0, sep), 2675 faultMessage.substring(sep + 1)); 2676 } 2677 2678 faults.add(new FaultInfo(faultMessageQName, faultPart, 2679 faultUse, faultNamespaceURI, 2680 this)); 2681 } 2682 } 2683 } 2684 } 2685 } 2687 2695 private void fillInDIMEInformation(UnknownExtensibilityElement unkElement, 2696 boolean input, Operation operation, 2697 BindingEntry bEntry) { 2698 2699 String layout = unkElement.getElement().getAttribute("layout"); 2700 2701 if (layout.equals(Constants.URI_DIME_CLOSED_LAYOUT)) { 2703 } else if (layout.equals(Constants.URI_DIME_OPEN_LAYOUT)) { 2704 } 2705 2706 Map parts = null; 2707 2708 if (input) { 2709 parts = operation.getInput().getMessage().getParts(); 2710 } else { 2711 parts = operation.getOutput().getMessage().getParts(); 2712 } 2713 2714 if (parts != null) { 2715 Iterator iterator = parts.values().iterator(); 2716 2717 while (iterator.hasNext()) { 2718 Part part = (Part) iterator.next(); 2719 2720 if (part != null) { 2721 String dims = ""; 2722 org.w3c.dom.Element element = null; 2723 2724 if (part.getTypeName() != null) { 2725 TypeEntry partType = getType(part.getTypeName()); 2726 2727 if (partType.getDimensions().length() > 0) { 2728 dims = partType.getDimensions(); 2729 partType = partType.getRefType(); 2730 } 2731 2732 element = (org.w3c.dom.Element ) partType.getNode(); 2733 } else if (part.getElementName() != null) { 2734 TypeEntry partElement = 2735 getElement(part.getElementName()).getRefType(); 2736 2737 element = (org.w3c.dom.Element ) partElement.getNode(); 2738 2739 QName name = getInnerCollectionComponentQName(element); 2740 2741 if (name != null) { 2742 dims += "[]"; 2743 partElement = getType(name); 2744 element = 2745 (org.w3c.dom.Element ) partElement.getNode(); 2746 } else { 2747 name = getInnerTypeQName(element); 2748 2749 if (name != null) { 2750 partElement = getType(name); 2751 element = 2752 (org.w3c.dom.Element ) partElement.getNode(); 2753 } 2754 } 2755 } 2756 2757 if (element != null) { 2758 org.w3c.dom.Element e = 2759 (org.w3c.dom.Element ) XMLUtils.findNode( 2760 element, 2761 new QName ( 2762 Constants.URI_DIME_CONTENT, "mediaType")); 2763 2764 if (e != null) { 2765 String value = e.getAttribute("value"); 2766 2767 bEntry.setOperationDIME(operation.getName()); 2768 bEntry.setMIMEInfo(operation.getName(), 2769 part.getName(), value, dims); 2770 } 2771 } 2772 } 2773 } 2774 } 2775 } 2776 2777 2786 private void faultsFromSOAPFault( 2787 Binding binding, BindingOperation bindOp, Operation operation, ArrayList faults) 2788 throws IOException { 2789 2790 Iterator faultMapIter = bindOp.getBindingFaults().values().iterator(); 2791 2792 for (; faultMapIter.hasNext();) { 2793 BindingFault bFault = (BindingFault) faultMapIter.next(); 2794 2795 String faultName = bFault.getName(); 2797 2798 if ((faultName == null) || (faultName.length() == 0)) { 2800 throw new IOException ( 2801 Messages.getMessage( 2802 "unNamedFault00", bindOp.getName(), 2803 binding.getQName().toString())); 2804 } 2805 2806 boolean foundSOAPFault = false; 2807 String soapFaultUse = ""; 2808 String soapFaultNamespace = ""; 2809 Iterator faultIter = 2810 bFault.getExtensibilityElements().iterator(); 2811 2812 for (; faultIter.hasNext();) { 2813 Object obj = faultIter.next(); 2814 2815 if (obj instanceof SOAPFault) { 2816 foundSOAPFault = true; 2817 soapFaultUse = ((SOAPFault) obj).getUse(); 2818 soapFaultNamespace = ((SOAPFault) obj).getNamespaceURI(); 2819 2820 break; 2821 } else if (obj instanceof UnknownExtensibilityElement) { 2822 2823 UnknownExtensibilityElement unkElement = 2825 (UnknownExtensibilityElement) obj; 2826 QName name = 2827 unkElement.getElementType(); 2828 2829 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) 2830 && name.getLocalPart().equals("fault")) { 2831 if (unkElement.getElement().getAttribute("use") 2832 != null) { 2833 soapFaultUse = 2834 unkElement.getElement().getAttribute("use"); 2835 } 2836 2837 if (unkElement.getElement().getAttribute("namespace") 2838 != null) { 2839 soapFaultNamespace = 2840 unkElement.getElement().getAttribute( 2841 "namespace"); 2842 } 2843 } 2844 } 2845 } 2846 2847 if (!foundSOAPFault) { 2849 throw new IOException ( 2850 Messages.getMessage( 2851 "missingSoapFault00", faultName, bindOp.getName(), 2852 binding.getQName().toString())); 2853 } 2854 2855 Fault opFault = operation.getFault(bFault.getName()); 2861 2862 if (opFault == null) { 2863 throw new IOException (Messages.getMessage("noPortTypeFault", 2864 new String []{ 2865 bFault.getName(), 2866 bindOp.getName(), 2867 binding.getQName().toString()})); 2868 } 2869 2870 faults.add(new FaultInfo(opFault, Use.getUse(soapFaultUse), 2872 soapFaultNamespace, this)); 2873 } 2874 } 2876 2884 private void setBodyType(String use, 2885 BindingEntry bEntry, 2886 Operation operation, 2887 boolean input) 2888 { 2889 2890 if (use == null) { 2891 use = "literal"; 2897 } 2898 2899 if (use.equalsIgnoreCase("literal")) { 2900 bEntry.setBodyType(operation, Use.LITERAL, input); 2901 } 2902 } 2904 2915 private Use addMIMETypes( 2916 BindingEntry bEntry, MIMEMultipartRelated mpr, Operation op) 2917 throws IOException { 2918 2919 Use bodyType = Use.ENCODED; 2920 List parts = mpr.getMIMEParts(); 2921 Iterator i = parts.iterator(); 2922 2923 while (i.hasNext()) { 2924 MIMEPart part = (MIMEPart) i.next(); 2925 List elems = part.getExtensibilityElements(); 2926 Iterator j = elems.iterator(); 2927 2928 while (j.hasNext()) { 2929 Object obj = j.next(); 2930 2931 if (obj instanceof MIMEContent) { 2932 MIMEContent content = (MIMEContent) obj; 2933 TypeEntry typeEntry = findPart(op, content.getPart()); 2934 if (typeEntry == null) { 2935 throw new RuntimeException (Messages.getMessage("cannotFindPartForOperation00", content.getPart(), 2936 op.getName(), content.getType())); 2937 } 2938 String dims = typeEntry.getDimensions(); 2939 2940 if ((dims.length() <= 0) 2941 && (typeEntry.getRefType() != null)) { 2942 Node node = typeEntry.getRefType().getNode(); 2943 2944 if (getInnerCollectionComponentQName(node) != null) { 2945 dims += "[]"; 2946 } 2947 } 2948 2949 String type = content.getType(); 2950 2951 if ((type == null) || (type.length() == 0)) { 2952 type = "text/plain"; 2953 } 2954 2955 bEntry.setMIMEInfo(op.getName(), content.getPart(), type, 2956 dims); 2957 } else if (obj instanceof SOAPBody) { 2958 String use = ((SOAPBody) obj).getUse(); 2959 2960 if (use == null) { 2961 throw new IOException ( 2962 Messages.getMessage("noUse", op.getName())); 2963 } 2964 2965 if (use.equalsIgnoreCase("literal")) { 2966 bodyType = Use.LITERAL; 2967 } 2968 } else if (obj instanceof UnknownExtensibilityElement) { 2969 2970 UnknownExtensibilityElement unkElement = 2972 (UnknownExtensibilityElement) obj; 2973 QName name = 2974 unkElement.getElementType(); 2975 2976 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) 2977 && name.getLocalPart().equals("body")) { 2978 String use = 2979 unkElement.getElement().getAttribute("use"); 2980 2981 if (use == null) { 2982 throw new IOException ( 2983 Messages.getMessage("noUse", op.getName())); 2984 } 2985 2986 if (use.equalsIgnoreCase("literal")) { 2987 bodyType = Use.LITERAL; 2988 } 2989 } 2990 } 2991 } 2992 } 2993 2994 return bodyType; 2995 } 2997 3004 private TypeEntry findPart(Operation operation, String partName) { 3005 3006 Map parts = operation.getInput().getMessage().getParts(); 3007 Iterator iterator = parts.values().iterator(); 3008 TypeEntry part = findPart(iterator, partName); 3009 3010 if (part == null) { 3011 parts = operation.getOutput().getMessage().getParts(); 3012 iterator = parts.values().iterator(); 3013 part = findPart(iterator, partName); 3014 } 3015 3016 return part; 3017 } 3018 3019 3026 private TypeEntry findPart(Iterator iterator, String partName) { 3027 3028 while (iterator.hasNext()) { 3029 Part part = (Part) iterator.next(); 3030 3031 if (part != null) { 3032 String typeName = part.getName(); 3033 3034 if (partName.equals(typeName)) { 3035 if (part.getTypeName() != null) { 3036 return getType(part.getTypeName()); 3037 } else if (part.getElementName() != null) { 3038 return getElement(part.getElementName()); 3039 } 3040 } 3041 } 3042 } 3043 3044 return null; 3045 } 3046 3047 3053 private void populateServices(Definition def) throws IOException { 3054 3055 Iterator i = def.getServices().values().iterator(); 3056 3057 while (i.hasNext()) { 3058 Service service = (Service) i.next(); 3059 3060 if ((service.getQName() == null) 3062 || (service.getQName().getLocalPart() == null) 3063 || service.getQName().getLocalPart().equals("")) { 3064 throw new IOException (Messages.getMessage("BadServiceName00")); 3065 } 3066 3067 ServiceEntry sEntry = new ServiceEntry(service); 3068 3069 symbolTablePut(sEntry); 3070 populatePorts(service.getPorts()); 3071 } 3072 } 3074 3083 private void populatePorts(Map ports) throws IOException { 3084 3085 if (ports == null) { 3086 return; 3087 } 3088 3089 Iterator it = ports.values().iterator(); 3090 3091 while (it.hasNext()) { 3092 Port port = (Port) it.next(); 3093 String portName = port.getName(); 3094 Binding portBinding = port.getBinding(); 3095 3096 if (portName == null) { 3100 3101 throw new IOException ( 3103 Messages.getMessage("missingPortNameException")); 3104 } 3105 3106 if (portBinding == null) { 3110 3111 throw new IOException ( 3113 Messages.getMessage("missingBindingException")); 3114 } 3115 3116 if (existsPortWithName(new QName (portName))) { 3132 3133 throw new IOException ( 3135 Messages.getMessage("twoPortsWithSameName", portName)); 3136 } 3137 3138 PortEntry portEntry = new PortEntry(port); 3139 3140 symbolTablePut(portEntry); 3141 } 3142 } 3143 3144 3154 private void setReferences(Definition def, Document doc) { 3155 3156 Map stuff = def.getServices(); 3157 3158 if (stuff.isEmpty()) { 3159 stuff = def.getBindings(); 3160 3161 if (stuff.isEmpty()) { 3162 stuff = def.getPortTypes(); 3163 3164 if (stuff.isEmpty()) { 3165 stuff = def.getMessages(); 3166 3167 if (stuff.isEmpty()) { 3168 for (Iterator i = elementTypeEntries.values().iterator(); 3169 i.hasNext();) { 3170 setTypeReferences((TypeEntry) i.next(), doc, false); 3171 } 3172 3173 for (Iterator i = typeTypeEntries.values().iterator(); 3174 i.hasNext();) { 3175 setTypeReferences((TypeEntry) i.next(), doc, false); 3176 } 3177 } else { 3178 Iterator i = stuff.values().iterator(); 3179 3180 while (i.hasNext()) { 3181 Message message = (Message) i.next(); 3182 MessageEntry mEntry = 3183 getMessageEntry(message.getQName()); 3184 3185 setMessageReferences(mEntry, def, doc, false); 3186 } 3187 } 3188 } else { 3189 Iterator i = stuff.values().iterator(); 3190 3191 while (i.hasNext()) { 3192 PortType portType = (PortType) i.next(); 3193 PortTypeEntry ptEntry = 3194 getPortTypeEntry(portType.getQName()); 3195 3196 setPortTypeReferences(ptEntry, null, def, doc); 3197 } 3198 } 3199 } else { 3200 Iterator i = stuff.values().iterator(); 3201 3202 while (i.hasNext()) { 3203 Binding binding = (Binding) i.next(); 3204 BindingEntry bEntry = getBindingEntry(binding.getQName()); 3205 3206 setBindingReferences(bEntry, def, doc); 3207 } 3208 } 3209 } else { 3210 Iterator i = stuff.values().iterator(); 3211 3212 while (i.hasNext()) { 3213 Service service = (Service) i.next(); 3214 ServiceEntry sEntry = getServiceEntry(service.getQName()); 3215 3216 setServiceReferences(sEntry, def, doc); 3217 } 3218 } 3219 } 3221 3229 private void setTypeReferences(TypeEntry entry, Document doc, 3230 boolean literal) { 3231 3232 if ((entry.isReferenced() && !literal) 3234 || (entry.isOnlyLiteralReferenced() && literal)) { 3235 return; 3236 } 3237 3238 if (wrapped) { 3239 3240 if (!entry.isReferenced() && literal) { 3243 entry.setOnlyLiteralReference(true); 3244 } 3245 3246 else if (entry.isOnlyLiteralReferenced() && !literal) { 3250 entry.setOnlyLiteralReference(false); 3251 } 3252 } 3253 3254 Node node = entry.getNode(); 3257 3258 if (addImports || (node == null) || (node.getOwnerDocument() == doc)) { 3259 entry.setIsReferenced(true); 3260 3261 if (entry instanceof DefinedElement) { 3262 BooleanHolder forElement = new BooleanHolder (); 3263 QName referentName = Utils.getTypeQName(node, 3264 forElement, false); 3265 3266 if (referentName != null) { 3267 TypeEntry referent = getTypeEntry(referentName, 3268 forElement.value); 3269 3270 if (referent != null) { 3271 setTypeReferences(referent, doc, literal); 3272 } 3273 } 3274 3275 QName anonQName = 3278 SchemaUtils.getElementAnonQName(entry.getNode()); 3279 3280 if (anonQName != null) { 3281 TypeEntry anonType = getType(anonQName); 3282 3283 if (anonType != null) { 3284 setTypeReferences(anonType, doc, literal); 3285 3286 return; 3287 } 3288 } 3289 } 3290 } 3291 3292 HashSet nestedTypes = entry.getNestedTypes(this, true); 3293 Iterator it = nestedTypes.iterator(); 3294 3295 while (it.hasNext()) { 3296 TypeEntry nestedType = (TypeEntry) it.next(); 3297 TypeEntry refType = entry.getRefType(); 3298 3299 if (nestedType == null) { 3300 continue; 3301 } 3302 3303 if ((refType != null) 3309 && !refType.equals(nestedType) 3310 && nestedType.isOnlyLiteralReferenced()) { 3311 nestedType.setOnlyLiteralReference(false); 3312 } 3313 3314 if (!nestedType.isReferenced()) { 3315 3316 if (nestedType != entry) { 3318 setTypeReferences(nestedType, doc, false); 3319 } 3320 } 3321 } 3322 } 3324 3333 private void setMessageReferences(MessageEntry entry, Definition def, 3334 Document doc, boolean literal) { 3335 3336 Message message = entry.getMessage(); 3339 3340 if (addImports) { 3341 entry.setIsReferenced(true); 3342 } else { 3343 3344 Map messages = def.getMessages(); 3348 3349 if (messages.containsValue(message)) { 3350 entry.setIsReferenced(true); 3351 } 3352 } 3353 3354 Iterator parts = message.getParts().values().iterator(); 3356 3357 while (parts.hasNext()) { 3358 Part part = (Part) parts.next(); 3359 TypeEntry type = getType(part.getTypeName()); 3360 3361 if (type != null) { 3362 setTypeReferences(type, doc, literal); 3363 } 3364 3365 type = getElement(part.getElementName()); 3366 3367 if (type != null) { 3368 setTypeReferences(type, doc, literal); 3369 3370 TypeEntry refType = type.getRefType(); 3371 3372 if (refType != null) { 3373 setTypeReferences(refType, doc, literal); 3374 } 3375 } 3376 } 3377 } 3379 3388 private void setPortTypeReferences(PortTypeEntry entry, 3389 BindingEntry bEntry, Definition def, 3390 Document doc) { 3391 3392 PortType portType = entry.getPortType(); 3395 3396 if (addImports) { 3397 entry.setIsReferenced(true); 3398 } else { 3399 3400 Map portTypes = def.getPortTypes(); 3404 3405 if (portTypes.containsValue(portType)) { 3406 entry.setIsReferenced(true); 3407 } 3408 } 3409 3410 Iterator operations = portType.getOperations().iterator(); 3412 3413 while (operations.hasNext()) { 3415 Operation operation = (Operation) operations.next(); 3416 Input input = operation.getInput(); 3417 Output output = operation.getOutput(); 3418 3419 boolean literalInput = false; 3421 boolean literalOutput = false; 3422 3423 if (bEntry != null) { 3424 literalInput = bEntry.getInputBodyType(operation) 3425 == Use.LITERAL; 3426 literalOutput = bEntry.getOutputBodyType(operation) 3427 == Use.LITERAL; 3428 } 3429 3430 if (input != null) { 3432 Message message = input.getMessage(); 3433 3434 if (message != null) { 3435 MessageEntry mEntry = getMessageEntry(message.getQName()); 3436 3437 if (mEntry != null) { 3438 setMessageReferences(mEntry, def, doc, literalInput); 3439 } 3440 } 3441 } 3442 3443 if (output != null) { 3445 Message message = output.getMessage(); 3446 3447 if (message != null) { 3448 MessageEntry mEntry = getMessageEntry(message.getQName()); 3449 3450 if (mEntry != null) { 3451 setMessageReferences(mEntry, def, doc, literalOutput); 3452 } 3453 } 3454 } 3455 3456 Iterator faults = operation.getFaults().values().iterator(); 3458 3459 while (faults.hasNext()) { 3460 Message message = ((Fault) faults.next()).getMessage(); 3461 3462 if (message != null) { 3463 MessageEntry mEntry = getMessageEntry(message.getQName()); 3464 3465 if (mEntry != null) { 3466 setMessageReferences(mEntry, def, doc, false); 3467 } 3468 } 3469 } 3470 } 3471 } 3473 3481 private void setBindingReferences(BindingEntry entry, Definition def, 3482 Document doc) { 3483 3484 if (entry.getBindingType() == BindingEntry.TYPE_SOAP) { 3485 3486 Binding binding = entry.getBinding(); 3489 3490 if (addImports) { 3491 entry.setIsReferenced(true); 3492 } else { 3493 3494 Map bindings = def.getBindings(); 3498 3499 if (bindings.containsValue(binding)) { 3500 entry.setIsReferenced(true); 3501 } 3502 } 3503 3504 PortType portType = binding.getPortType(); 3506 PortTypeEntry ptEntry = getPortTypeEntry(portType.getQName()); 3507 3508 if (ptEntry != null) { 3509 setPortTypeReferences(ptEntry, entry, def, doc); 3510 } 3511 } 3512 } 3514 3522 private void setServiceReferences(ServiceEntry entry, Definition def, 3523 Document doc) { 3524 3525 Service service = entry.getService(); 3528 3529 if (addImports) { 3530 entry.setIsReferenced(true); 3531 } else { 3532 3533 Map services = def.getServices(); 3537 3538 if (services.containsValue(service)) { 3539 entry.setIsReferenced(true); 3540 } 3541 } 3542 3543 Iterator ports = service.getPorts().values().iterator(); 3545 3546 while (ports.hasNext()) { 3547 Port port = (Port) ports.next(); 3548 Binding binding = port.getBinding(); 3549 3550 if (binding != null) { 3551 BindingEntry bEntry = getBindingEntry(binding.getQName()); 3552 3553 if (bEntry != null) { 3554 setBindingReferences(bEntry, def, doc); 3555 } 3556 } 3557 } 3558 } 3560 3566 private SymTabEntry symbolTablePut(SymTabEntry entry) throws IOException { 3567 3568 QName name = entry.getQName(); 3569 3570 SymTabEntry e = get(name, entry.getClass()); 3571 3572 if (e == null) { 3573 e = entry; 3574 3575 if ((entry instanceof Type) 3577 && (get(name, UndefinedType.class) != null)) { 3578 3579 if (((TypeEntry) get(name, UndefinedType.class)).isSimpleType() 3584 && !((TypeEntry) entry).isSimpleType()) { 3585 3586 throw new IOException ( 3589 Messages.getMessage( 3590 "AttrNotSimpleType01", name.toString())); 3591 } 3592 3593 Vector v = (Vector ) symbolTable.get(name); 3594 3595 for (int i = 0; i < v.size(); ++i) { 3596 Object oldEntry = v.elementAt(i); 3597 3598 if (oldEntry instanceof UndefinedType) { 3599 3600 v.setElementAt(entry, i); 3602 3603 typeTypeEntries.put(name, entry); 3605 3606 ((UndefinedType) oldEntry).update((Type) entry); 3608 } 3609 } 3610 } else if ((entry instanceof Element) 3611 && (get(name, UndefinedElement.class) != null)) { 3612 3613 Vector v = (Vector ) symbolTable.get(name); 3618 3619 for (int i = 0; i < v.size(); ++i) { 3620 Object oldEntry = v.elementAt(i); 3621 3622 if (oldEntry instanceof UndefinedElement) { 3623 3624 v.setElementAt(entry, i); 3626 3627 elementTypeEntries.put(name, entry); 3629 3630 ((Undefined) oldEntry).update((Element) entry); 3632 } 3633 } 3634 } else { 3635 3636 Vector v = (Vector ) symbolTable.get(name); 3638 3639 if (v == null) { 3640 v = new Vector (); 3641 3642 symbolTable.put(name, v); 3643 } 3644 3645 v.add(entry); 3646 3647 if (entry instanceof Element) { 3650 elementTypeEntries.put(name, entry); 3651 } else if (entry instanceof Type) { 3652 typeTypeEntries.put(name, entry); 3653 } 3654 } 3655 } else { 3656 if (!quiet) { 3657 System.out.println(Messages.getMessage("alreadyExists00", 3658 "" + name)); 3659 } 3660 } 3661 3662 return e; 3663 } 3665 3674 protected boolean existsPortWithName(QName name) { 3675 3676 Vector v = (Vector ) symbolTable.get(name); 3677 3678 if (v == null) { 3679 return false; 3680 } 3681 3682 Iterator it = v.iterator(); 3683 3684 while (it.hasNext()) { 3685 Object o = it.next(); 3686 3687 if (o instanceof PortEntry) { 3688 return true; 3689 } 3690 } 3691 3692 return false; 3693 } 3694 3695 3701 private static QName getInnerCollectionComponentQName(Node node) { 3702 3703 if (node == null) { 3704 return null; 3705 } 3706 3707 QName name = SchemaUtils.getCollectionComponentQName(node, new QNameHolder ()); 3708 3709 if (name != null) { 3710 return name; 3711 } 3712 3713 NodeList children = node.getChildNodes(); 3715 3716 for (int i = 0; i < children.getLength(); i++) { 3717 name = getInnerCollectionComponentQName(children.item(i)); 3718 3719 if (name != null) { 3720 return name; 3721 } 3722 } 3723 3724 return null; 3725 } 3726 3727 3733 private static QName getInnerTypeQName(Node node) { 3734 3735 if (node == null) { 3736 return null; 3737 } 3738 3739 BooleanHolder forElement = new BooleanHolder (); 3740 QName name = Utils.getTypeQName(node, forElement, true); 3741 3742 if (name != null) { 3743 return name; 3744 } 3745 3746 NodeList children = node.getChildNodes(); 3748 3749 for (int i = 0; i < children.getLength(); i++) { 3750 name = getInnerTypeQName(children.item(i)); 3751 3752 if (name != null) { 3753 return name; 3754 } 3755 } 3756 3757 return null; 3758 } 3759 3760 protected void processTypes() { 3761 for (Iterator i = typeTypeEntries.values().iterator(); i.hasNext(); ) { 3762 Type type = (Type) i.next(); 3763 Node node = type.getNode(); 3764 3765 Vector attributes = 3767 SchemaUtils.getContainedAttributeTypes(node, this); 3768 3769 if (attributes != null) { 3770 type.setContainedAttributes(attributes); 3771 } 3772 3773 Vector elements = 3775 SchemaUtils.getContainedElementDeclarations(node, this); 3776 3777 if (elements != null) { 3778 type.setContainedElements(elements); 3779 } 3780 } 3781 } 3782 3783 public List getMessageEntries() { 3784 List messageEntries = new ArrayList (); 3785 Iterator iter = symbolTable.values().iterator(); 3786 while (iter.hasNext()) { 3787 Vector v = (Vector )iter.next(); 3788 for (int i = 0; i < v.size(); ++i) { 3789 SymTabEntry entry = (SymTabEntry)v.elementAt(i); 3790 if (entry instanceof MessageEntry) { 3791 messageEntries.add(entry); 3792 } 3793 } 3794 } 3795 3796 return messageEntries; 3797 } 3798 3799 public void setWrapArrays(boolean wrapArrays) { 3800 this.wrapArrays = wrapArrays; 3801 } 3802 3803 public Map getElementFormDefaults() { 3804 return elementFormDefaults; 3805 } 3806} 3807 | Popular Tags |