1 16 package org.apache.axis.wsdl.symbolTable; 17 18 import org.apache.axis.Constants; 19 import org.apache.axis.AxisProperties; 20 import org.apache.axis.utils.JavaUtils; 21 import org.w3c.dom.DOMException ; 22 import org.w3c.dom.Element ; 23 import org.w3c.dom.Node ; 24 import org.w3c.dom.NodeList ; 25 26 import javax.xml.namespace.QName ; 27 import javax.xml.rpc.holders.BooleanHolder ; 28 import javax.xml.rpc.holders.IntHolder ; 29 import javax.xml.rpc.holders.BooleanHolder ; 30 import javax.xml.rpc.holders.QNameHolder ; 31 import java.util.Arrays ; 32 import java.util.HashSet ; 33 import java.util.Set ; 34 import java.util.StringTokenizer ; 35 import java.util.Vector ; 36 37 42 public class SchemaUtils { 43 44 45 static final QName VALUE_QNAME = Utils.findQName("", "_value"); 46 47 51 public static boolean isMixed(Node node) { 52 if (isXSDNode(node, "complexType")) { 54 String mixed = ((Element)node).getAttribute("mixed"); 55 if (mixed != null && mixed.length() > 0) { 56 return ("true".equalsIgnoreCase(mixed) || 57 "1".equals(mixed)); 58 } 59 NodeList children = node.getChildNodes(); 62 63 for (int j = 0; j < children.getLength(); j++) { 64 Node kid = children.item(j); 65 if (isXSDNode(kid, "complexContent")) { 66 mixed = ((Element)kid).getAttribute("mixed"); 67 return ("true".equalsIgnoreCase(mixed) || 68 "1".equals(mixed)); 69 } 70 } 71 } 72 return false; 73 } 74 75 public static Node getUnionNode(Node node) { 76 if (isXSDNode(node, "simpleType")) { 78 NodeList children = node.getChildNodes(); 80 for (int j = 0; j < children.getLength(); j++) { 81 Node kid = children.item(j); 82 if (isXSDNode(kid, "union")) { 83 return kid; 84 } 85 } 86 } 87 return null; 88 } 89 90 public static Node getListNode(Node node) { 91 if (isXSDNode(node, "simpleType")) { 93 NodeList children = node.getChildNodes(); 95 for (int j = 0; j < children.getLength(); j++) { 96 Node kid = children.item(j); 97 if (isXSDNode(kid, "list")) { 98 return kid; 99 } 100 } 101 } 102 return null; 103 } 104 105 public static boolean isSimpleTypeWithUnion(Node node) { 106 return (getUnionNode(node) != null); 107 } 108 109 119 public static boolean isWrappedType(Node node) { 120 121 if (node == null) { 122 return false; 123 } 124 125 if (isXSDNode(node, "element")) { 127 NodeList children = node.getChildNodes(); 128 boolean hasComplexType = false; 129 for (int j = 0; j < children.getLength(); j++) { 130 Node kid = children.item(j); 131 if (isXSDNode(kid, "complexType")) { 132 node = kid; 133 hasComplexType = true; 134 break; 135 } 136 } 137 if (!hasComplexType) { 138 return false; 139 } 140 } 141 142 if (isXSDNode(node, "complexType")) { 144 148 NodeList children = node.getChildNodes(); 149 150 for (int j = 0; j < children.getLength(); j++) { 151 Node kid = children.item(j); 152 153 if (isXSDNode(kid, "complexContent")) { 154 return false; 155 } else if (isXSDNode(kid, "simpleContent")) { 156 return false; 157 } 158 } 159 160 children = node.getChildNodes(); 165 int len = children.getLength(); 166 for (int j = 0; j < len; j++) { 167 Node kid = children.item(j); 168 String localName = kid.getLocalName(); 169 if (localName != null && 170 Constants.isSchemaXSD(kid.getNamespaceURI())) { 171 if (localName.equals("sequence")) { 172 Node sequenceNode = kid; 173 NodeList sequenceChildren = sequenceNode.getChildNodes(); 174 int sequenceLen = sequenceChildren.getLength(); 175 for (int k = 0; k < sequenceLen; k++) { 176 Node sequenceKid = sequenceChildren.item(k); 177 String sequenceLocalName = sequenceKid.getLocalName(); 178 if (sequenceLocalName != null && 179 Constants.isSchemaXSD(sequenceKid.getNamespaceURI())) { 180 if (sequenceLocalName.equals("choice")) { 182 Node choiceNode = sequenceKid; 183 NodeList choiceChildren = choiceNode.getChildNodes(); 184 int choiceLen = choiceChildren.getLength(); 185 for (int l = 0; l < choiceLen; l++) { 186 Node choiceKid = choiceChildren.item(l); 187 String choiceLocalName = choiceKid.getLocalName(); 188 if (choiceLocalName != null && 189 Constants.isSchemaXSD(choiceKid.getNamespaceURI())) { 190 if (!choiceLocalName.equals("element")) { 191 return false; 192 } 193 } 194 } 195 } 196 else 197 if (!sequenceLocalName.equals("element")) { 198 return false; 199 } 200 } 201 } 202 return true; 203 } else { 204 return false; 205 } 206 } 207 } 208 } 209 return true; 211 } 212 213 230 public static Vector getContainedElementDeclarations(Node node, 231 SymbolTable symbolTable) { 232 233 if (node == null) { 234 return null; 235 } 236 237 if (isXSDNode(node, "element")) { 239 NodeList children = node.getChildNodes(); 240 241 for (int j = 0; j < children.getLength(); j++) { 242 Node kid = children.item(j); 243 244 if (isXSDNode(kid, "complexType")) { 245 node = kid; 246 247 break; 248 } 249 } 250 } 251 252 if (isXSDNode(node, "complexType")) { 254 255 NodeList children = node.getChildNodes(); 258 Node complexContent = null; 259 Node simpleContent = null; 260 Node extension = null; 261 262 for (int j = 0; j < children.getLength(); j++) { 263 Node kid = children.item(j); 264 265 if (isXSDNode(kid, "complexContent")) { 266 complexContent = kid; 267 268 break; } else if (isXSDNode(kid, "simpleContent")) { 270 simpleContent = kid; 271 } 272 } 273 274 if (complexContent != null) { 275 children = complexContent.getChildNodes(); 276 277 for (int j = 0; 278 (j < children.getLength()) && (extension == null); 279 j++) { 280 Node kid = children.item(j); 281 282 if (isXSDNode(kid, "extension") 283 || isXSDNode(kid, "restriction")) { 284 extension = kid; 285 } 286 } 287 } 288 289 if (simpleContent != null) { 290 children = simpleContent.getChildNodes(); 291 292 int len = children.getLength(); 293 for (int j = 0; 294 (j < len) && (extension == null); 295 j++) { 296 Node kid = children.item(j); 297 String localName = kid.getLocalName(); 298 299 if ((localName != null) 300 && (localName.equals("extension") || localName.equals("restriction")) 301 && Constants.isSchemaXSD(kid.getNamespaceURI())) { 302 303 QName extendsOrRestrictsType = 305 Utils.getTypeQName(children.item(j), 306 new BooleanHolder (), false); 307 308 Vector v = new Vector (); 311 ElementDecl elem = new ElementDecl(symbolTable.getTypeEntry(extendsOrRestrictsType, false), VALUE_QNAME); 312 v.add(elem); 313 314 return v; 315 } 316 } 317 } 318 319 if (extension != null) { 320 node = extension; } 322 323 children = node.getChildNodes(); 326 327 Vector v = new Vector (); 328 int len = children.getLength(); 329 for (int j = 0; j < len; j++) { 330 Node kid = children.item(j); 331 String localName = kid.getLocalName(); 332 if (localName != null && 333 Constants.isSchemaXSD(kid.getNamespaceURI())) { 334 if (localName.equals("sequence")) { 335 v.addAll(processSequenceNode(kid, symbolTable)); 336 } else if (localName.equals("all")) { 337 v.addAll(processAllNode(kid, symbolTable)); 338 } else if (localName.equals("choice")) { 339 v.addAll(processChoiceNode(kid, symbolTable)); 340 } else if (localName.equals("group")) { 341 v.addAll(processGroupNode(kid, symbolTable)); 342 } 343 } 344 } 345 346 return v; 347 } else if (isXSDNode(node, "group")) { 348 373 return null; 374 } else { 375 376 QName [] simpleQName = getContainedSimpleTypes(node); 378 379 if (simpleQName != null) { 380 Vector v = null; 381 382 for (int i = 0; i < simpleQName.length; i++) { 383 384 Type simpleType = symbolTable.getType(simpleQName[i]); 385 386 if (simpleType != null) { 387 if (v == null) { 388 v = new Vector (); 389 } 390 391 QName qname = null; 392 if (simpleQName.length > 1) { 393 qname = new QName ("", simpleQName[i].getLocalPart() + "Value"); 394 } else { 395 qname = new QName ("", "value"); 396 } 397 398 v.add(new ElementDecl(simpleType, qname)); 399 } 400 } 401 402 return v; 403 } 404 } 405 406 return null; 407 } 408 409 417 private static Vector processChoiceNode(Node choiceNode, 418 SymbolTable symbolTable) { 419 420 Vector v = new Vector (); 421 NodeList children = choiceNode.getChildNodes(); 422 int len = children.getLength(); 423 for (int j = 0; j < len; j++) { 424 Node kid = children.item(j); 425 String localName = kid.getLocalName(); 426 if (localName != null && 427 Constants.isSchemaXSD(kid.getNamespaceURI())) { 428 if (localName.equals("choice")) { 429 v.addAll(processChoiceNode(kid, symbolTable)); 430 } else if (localName.equals("sequence")) { 431 v.addAll(processSequenceNode(kid, symbolTable)); 432 } else if (localName.equals("group")) { 433 v.addAll(processGroupNode(kid, symbolTable)); 434 } else if (localName.equals("element")) { 435 ElementDecl elem = processChildElementNode(kid, 436 symbolTable); 437 438 if (elem != null) { 439 elem.setMinOccursIs0(true); 442 443 v.add(elem); 444 } 445 } else if (localName.equals("any")) { 446 Type type = symbolTable.getType(Constants.XSD_ANY); 450 ElementDecl elem = new ElementDecl(type, 451 Utils.findQName("", 452 "any")); 453 454 elem.setAnyElement(true); 455 v.add(elem); 456 } 457 } 458 } 459 460 return v; 461 } 462 463 469 private static Node getChildByName(Node parentNode, String name) throws DOMException { 470 if (parentNode == null) return null; 471 NodeList children = parentNode.getChildNodes(); 472 if (children != null) { 473 for (int i = 0; i < children.getLength(); i++) { 474 Node child = children.item(i); 475 if (child != null) { 476 if (child.getNodeName() != null && name.equals(child.getNodeName())) { 477 return child; 478 } 479 } 480 } 481 } 482 return null; 483 } 484 485 492 public static String getTextByPath(Node root, String path) throws DOMException { 493 StringTokenizer st = new StringTokenizer (path, "/"); 494 Node node = root; 495 while (st.hasMoreTokens()) { 496 String elementName = st.nextToken(); 497 Node child = getChildByName(node, elementName); 498 if (child == null) 499 throw new DOMException (DOMException.NOT_FOUND_ERR, "could not find " + elementName); 500 node = child; 501 } 502 503 String text = ""; 505 NodeList children = node.getChildNodes(); 506 if (children != null) { 507 for (int i = 0; i < children.getLength(); i++) { 508 Node child = children.item(i); 509 if (child != null) { 510 if (child.getNodeName() != null 511 && (child.getNodeName().equals("#text") 512 || child.getNodeName().equals("#cdata-section"))) { 513 text += child.getNodeValue(); 514 } 515 } 516 } 517 } 518 return text; 519 } 520 521 528 public static String getAnnotationDocumentation(Node typeNode) { 529 Node annotationNode = typeNode.getFirstChild(); 530 while (annotationNode != null) { 531 if (isXSDNode(annotationNode, "annotation")) { 532 break; 533 } 534 annotationNode = annotationNode.getNextSibling(); 535 } 536 Node documentationNode; 537 if (annotationNode != null) { 538 documentationNode = annotationNode.getFirstChild(); 539 while (documentationNode != null) { 540 if (isXSDNode(documentationNode, "documentation")) { 541 break; 542 } 543 documentationNode = documentationNode.getNextSibling(); 544 } 545 } else { 546 documentationNode = null; 547 } 548 549 String text = ""; 551 if (documentationNode != null) { 552 NodeList children = documentationNode.getChildNodes(); 553 if (children != null) { 554 for (int i = 0; i < children.getLength(); i++) { 555 Node child = children.item(i); 556 if (child != null) { 557 if (child.getNodeName() != null 558 && (child.getNodeName().equals("#text") 559 || child.getNodeName().equals("#cdata-section"))) { 560 text += child.getNodeValue(); 561 } 562 } 563 } 564 } 565 } 566 return text; 567 } 568 569 577 private static Vector processSequenceNode(Node sequenceNode, 578 SymbolTable symbolTable) { 579 580 Vector v = new Vector (); 581 NodeList children = sequenceNode.getChildNodes(); 582 int len = children.getLength(); 583 for (int j = 0; j < len; j++) { 584 Node kid = children.item(j); 585 String localName = kid.getLocalName(); 586 587 if (localName != null && 588 Constants.isSchemaXSD(kid.getNamespaceURI())) { 589 if (localName.equals("choice")) { 590 v.addAll(processChoiceNode(kid, symbolTable)); 591 } else if (localName.equals("sequence")) { 592 v.addAll(processSequenceNode(kid, symbolTable)); 593 } else if (localName.equals("group")) { 594 v.addAll(processGroupNode(kid, symbolTable)); 595 } else if (localName.equals("any")) { 596 Type type = symbolTable.getType(Constants.XSD_ANY); 600 ElementDecl elem = new ElementDecl(type, 601 Utils.findQName("", 602 "any")); 603 604 elem.setAnyElement(true); 605 v.add(elem); 606 } else if (localName.equals("element")) { 607 ElementDecl elem = processChildElementNode(kid, 608 symbolTable); 609 610 if (elem != null) { 611 v.add(elem); 612 } 613 } 614 } 615 } 616 617 return v; 618 } 619 620 629 private static Vector processGroupNode(Node groupNode, 630 SymbolTable symbolTable) { 631 632 Vector v = new Vector (); 633 if (groupNode.getAttributes().getNamedItem("ref") == null) { 634 NodeList children = groupNode.getChildNodes(); 635 int len = children.getLength(); 636 for (int j = 0; j < len; j++) { 637 Node kid = children.item(j); 638 String localName = kid.getLocalName(); 639 if (localName != null && 640 Constants.isSchemaXSD(kid.getNamespaceURI())) { 641 if (localName.equals("choice")) { 642 v.addAll(processChoiceNode(kid, symbolTable)); 643 } else if (localName.equals("sequence")) { 644 v.addAll(processSequenceNode(kid, symbolTable)); 645 } else if (localName.equals("all")) { 646 v.addAll(processAllNode(kid, symbolTable)); 647 } 648 } 649 } 650 } else { 651 QName nodeName = Utils.getNodeNameQName(groupNode); 652 QName nodeType = Utils.getTypeQName(groupNode, new BooleanHolder (), false); 653 Type type = (Type) symbolTable.getTypeEntry(nodeType, false); 657 658 if (type != null && type.getNode() != null) { 659 Node node = type.getNode(); 661 NodeList children = node.getChildNodes(); 662 for (int j = 0; j < children.getLength(); j++) { 663 QName subNodeKind = Utils.getNodeQName(children.item(j)); 664 if ((subNodeKind != null) 665 && Constants.isSchemaXSD( 666 subNodeKind.getNamespaceURI())) { 667 if (subNodeKind.getLocalPart().equals("sequence")) { 668 v.addAll(processSequenceNode(children.item(j), 669 symbolTable)); 670 } else if (subNodeKind.getLocalPart().equals("all")) { 671 v.addAll(processAllNode(children.item(j), symbolTable)); 672 } else if (subNodeKind.getLocalPart().equals("choice")) { 673 v.addAll(processChoiceNode(children.item(j), 674 symbolTable)); 675 } 676 } 677 } 678 } 679 } 680 return v; 681 } 682 683 684 692 private static Vector processAllNode(Node allNode, 693 SymbolTable symbolTable) { 694 695 Vector v = new Vector (); 696 NodeList children = allNode.getChildNodes(); 697 698 for (int j = 0; j < children.getLength(); j++) { 699 Node kid = children.item(j); 700 701 if (isXSDNode(kid, "element")) { 702 ElementDecl elem = processChildElementNode(kid, symbolTable); 703 704 if (elem != null) { 705 v.add(elem); 706 } 707 } 708 } 709 710 return v; 711 } 712 713 724 private static ElementDecl processChildElementNode(Node elementNode, 725 SymbolTable symbolTable) { 726 727 QName nodeName = Utils.getNodeNameQName(elementNode); 729 BooleanHolder forElement = new BooleanHolder (); 730 String comments = null; 731 comments = getAnnotationDocumentation(elementNode); 732 733 QName nodeType = Utils.getTypeQName(elementNode, forElement, false); 736 TypeEntry type = symbolTable.getTypeEntry(nodeType, 737 forElement.value); 738 739 if (!forElement.value) { 744 745 String form = Utils.getAttribute(elementNode, "form"); 748 749 if ((form != null) && form.equals("unqualified")) { 750 751 nodeName = Utils.findQName("", nodeName.getLocalPart()); 753 } else if (form == null) { 754 755 String def = Utils.getScopedAttribute(elementNode, 757 "elementFormDefault"); 758 759 if ((def == null) || def.equals("unqualified")) { 760 761 nodeName = Utils.findQName("", nodeName.getLocalPart()); 763 } 764 } 765 } 766 767 if (type != null) { 768 ElementDecl elem = new ElementDecl(type, nodeName); 769 elem.setDocumentation(comments); 770 String minOccurs = Utils.getAttribute(elementNode, 771 "minOccurs"); 772 773 if ((minOccurs != null) && minOccurs.equals("0")) { 774 elem.setMinOccursIs0(true); 775 } 776 777 String maxOccurs = Utils.getAttribute(elementNode, "maxOccurs"); 778 if (maxOccurs != null) { 779 if (maxOccurs.equals("unbounded")) { 780 elem.setMaxOccursIsUnbounded(true); 781 } 782 else if(maxOccurs.equals("1")) { 783 elem.setMaxOccursIsExactlyOne(true); 784 } 785 } 786 else { 787 elem.setMaxOccursIsExactlyOne(true); 788 } 789 elem.setNillable( 790 JavaUtils.isTrueExplicitly( 791 Utils.getAttribute(elementNode, "nillable"))); 792 793 String useValue = Utils.getAttribute(elementNode, "use"); 794 795 if (useValue != null) { 796 elem.setOptional(useValue.equalsIgnoreCase("optional")); 797 } 798 799 return elem; 800 } 801 802 return null; 803 } 804 805 812 public static QName getElementAnonQName(Node node) { 813 814 if (isXSDNode(node, "element")) { 815 NodeList children = node.getChildNodes(); 816 817 for (int j = 0; j < children.getLength(); j++) { 818 Node kid = children.item(j); 819 820 if (isXSDNode(kid, "complexType") 821 || isXSDNode(kid, "simpleType")) { 822 return Utils.getNodeNameQName(kid); 823 } 824 } 825 } 826 827 return null; 828 } 829 830 837 public static QName getAttributeAnonQName(Node node) { 838 839 if (isXSDNode(node, "attribute")) { 840 NodeList children = node.getChildNodes(); 841 842 for (int j = 0; j < children.getLength(); j++) { 843 Node kid = children.item(j); 844 845 if (isXSDNode(kid, "complexType") 846 || isXSDNode(kid, "simpleType")) { 847 return Utils.getNodeNameQName(kid); 848 } 849 } 850 } 851 852 return null; 853 } 854 855 861 public static boolean isSimpleTypeOrSimpleContent(Node node) { 862 863 if (node == null) { 864 return false; 865 } 866 867 if (isXSDNode(node, "element")) { 869 NodeList children = node.getChildNodes(); 870 871 for (int j = 0; j < children.getLength(); j++) { 872 Node kid = children.item(j); 873 874 if (isXSDNode(kid, "complexType")) { 875 node = kid; 876 877 break; 878 } else if (isXSDNode(kid, "simpleType")) { 879 return true; 880 } 881 } 882 } 883 884 if (isXSDNode(node, "simpleType")) { 886 return true; 887 } 888 889 if (isXSDNode(node, "complexType")) { 890 891 NodeList children = node.getChildNodes(); 894 Node complexContent = null; 895 Node simpleContent = null; 896 897 for (int j = 0; j < children.getLength(); j++) { 898 Node kid = children.item(j); 899 900 if (isXSDNode(kid, "complexContent")) { 901 complexContent = kid; 902 903 break; 904 } else if (isXSDNode(kid, "simpleContent")) { 905 simpleContent = kid; 906 } 907 } 908 909 if (complexContent != null) { 910 return false; 911 } 912 913 if (simpleContent != null) { 914 return true; 915 } 916 } 917 918 return false; 919 } 920 921 933 private static boolean isXSDNode(Node node, String schemaLocalName) { 934 if (node == null) { 935 return false; 936 } 937 String localName = node.getLocalName(); 938 if (localName == null) { 939 return false; 940 } 941 return (localName.equals(schemaLocalName) && 942 Constants.isSchemaXSD(node.getNamespaceURI())); 943 } 944 945 953 public static TypeEntry getComplexElementRestrictionBase(Node node, 954 SymbolTable symbolTable) { 955 956 if (node == null) { 957 return null; 958 } 959 960 if (isXSDNode(node, "element")) { 962 NodeList children = node.getChildNodes(); 963 Node complexNode = null; 964 965 for (int j = 0; 966 (j < children.getLength()) && (complexNode == null); j++) { 967 if (isXSDNode(children.item(j), "complexType")) { 968 complexNode = children.item(j); 969 node = complexNode; 970 } 971 } 972 } 973 974 if (isXSDNode(node, "complexType")) { 976 977 NodeList children = node.getChildNodes(); 980 Node content = null; 981 Node restriction = null; 982 983 for (int j = 0; (j < children.getLength()) && (content == null); 984 j++) { 985 Node kid = children.item(j); 986 987 if (isXSDNode(kid, "complexContent")) { 988 content = kid; 989 } 990 } 991 992 if (content != null) { 993 children = content.getChildNodes(); 994 995 for (int j = 0; 996 (j < children.getLength()) && (restriction == null); 997 j++) { 998 Node kid = children.item(j); 999 1000 if (isXSDNode(kid, "restriction")) { 1001 restriction = kid; 1002 } 1003 } 1004 } 1005 1006 if (restriction == null) { 1007 return null; 1008 } else { 1009 1010 QName restrictionType = Utils.getTypeQName(restriction, 1012 new BooleanHolder (), 1013 false); 1014 1015 if (restrictionType == null) { 1016 return null; 1017 } else { 1018 1019 return symbolTable.getType(restrictionType); 1021 } 1022 } 1023 } else { 1024 return null; 1025 } 1026 } 1027 1028 1036 public static TypeEntry getComplexElementExtensionBase(Node node, 1037 SymbolTable symbolTable) { 1038 1039 if (node == null) { 1040 return null; 1041 } 1042 1043 TypeEntry cached = (TypeEntry) symbolTable.node2ExtensionBase.get(node); 1044 1045 if (cached != null) { 1046 return cached; } 1048 1049 if (isXSDNode(node, "element")) { 1051 NodeList children = node.getChildNodes(); 1052 Node complexNode = null; 1053 1054 for (int j = 0; 1055 (j < children.getLength()) && (complexNode == null); j++) { 1056 if (isXSDNode(children.item(j), "complexType")) { 1057 complexNode = children.item(j); 1058 node = complexNode; 1059 } 1060 } 1061 } 1062 1063 if (isXSDNode(node, "complexType")) { 1065 1066 NodeList children = node.getChildNodes(); 1069 Node content = null; 1070 Node extension = null; 1071 1072 for (int j = 0; (j < children.getLength()) && (content == null); 1073 j++) { 1074 Node kid = children.item(j); 1075 1076 if (isXSDNode(kid, "complexContent") 1077 || isXSDNode(kid, "simpleContent")) { 1078 content = kid; 1079 } 1080 } 1081 1082 if (content != null) { 1083 children = content.getChildNodes(); 1084 1085 for (int j = 0; 1086 (j < children.getLength()) && (extension == null); 1087 j++) { 1088 Node kid = children.item(j); 1089 1090 if (isXSDNode(kid, "extension")) { 1091 extension = kid; 1092 } 1093 } 1094 } 1095 1096 if (extension == null) { 1097 cached = null; 1098 } else { 1099 1100 QName extendsType = Utils.getTypeQName(extension, 1102 new BooleanHolder (), 1103 false); 1104 1105 if (extendsType == null) { 1106 cached = null; 1107 } else { 1108 1109 cached = symbolTable.getType(extendsType); 1111 } 1112 } 1113 } 1114 1115 symbolTable.node2ExtensionBase.put(node, cached); 1116 1117 return cached; 1118 } 1119 1120 1127 public static QName getSimpleTypeBase(Node node) { 1128 1129 QName [] qname = getContainedSimpleTypes(node); 1130 1131 if ((qname != null) && (qname.length > 0)) { 1132 return qname[0]; 1133 } 1134 1135 return null; 1136 } 1137 1138 1144 public static QName [] getContainedSimpleTypes(Node node) { 1145 1146 QName [] baseQNames = null; 1147 1148 if (node == null) { 1149 return null; 1150 } 1151 1152 if (isXSDNode(node, "element")) { 1154 NodeList children = node.getChildNodes(); 1155 1156 for (int j = 0; j < children.getLength(); j++) { 1157 if (isXSDNode(children.item(j), "simpleType")) { 1158 node = children.item(j); 1159 1160 break; 1161 } 1162 } 1163 } 1164 1165 if (isXSDNode(node, "simpleType")) { 1167 1168 NodeList children = node.getChildNodes(); 1171 Node restrictionNode = null; 1172 Node unionNode = null; 1173 1174 for (int j = 0; 1175 (j < children.getLength()) && (restrictionNode == null); 1176 j++) { 1177 if (isXSDNode(children.item(j), "restriction")) { 1178 restrictionNode = children.item(j); 1179 } else if (isXSDNode(children.item(j), "union")) { 1180 unionNode = children.item(j); 1181 } 1182 } 1183 1184 if (restrictionNode != null) { 1187 baseQNames = new QName [1]; 1188 baseQNames[0] = Utils.getTypeQName(restrictionNode, 1189 new BooleanHolder (), false); 1190 } 1191 1192 if (unionNode != null) { 1193 baseQNames = Utils.getMemberTypeQNames(unionNode); 1194 } 1195 1196 if ((baseQNames != null) && (restrictionNode != null) 1198 && (unionNode != null)) { 1199 NodeList enums = restrictionNode.getChildNodes(); 1200 1201 for (int i = 0; i < enums.getLength(); i++) { 1202 if (isXSDNode(enums.item(i), "enumeration")) { 1203 1204 return null; 1207 } 1208 } 1209 } 1210 } 1211 1212 return baseQNames; 1213 } 1214 1215 1222 public static Node getRestrictionOrExtensionNode(Node node) { 1223 1224 Node re = null; 1225 1226 if (node == null) { 1227 return re; 1228 } 1229 1230 if (isXSDNode(node, "element")) { 1232 NodeList children = node.getChildNodes(); 1233 1234 for (int j = 0; j < children.getLength(); j++) { 1235 Node n = children.item(j); 1236 1237 if (isXSDNode(n, "simpleType") || isXSDNode(n, "complexType") 1238 || isXSDNode(n, "simpleContent")) { 1239 node = n; 1240 1241 break; 1242 } 1243 } 1244 } 1245 1246 if (isXSDNode(node, "simpleType") || isXSDNode(node, "complexType")) { 1248 1249 NodeList children = node.getChildNodes(); 1251 Node complexContent = null; 1252 1253 if (node.getLocalName().equals("complexType")) { 1254 for (int j = 0; 1255 (j < children.getLength()) && (complexContent == null); 1256 j++) { 1257 Node kid = children.item(j); 1258 1259 if (isXSDNode(kid, "complexContent") 1260 || isXSDNode(kid, "simpleContent")) { 1261 complexContent = kid; 1262 } 1263 } 1264 1265 node = complexContent; 1266 } 1267 1268 if (node != null) { 1270 children = node.getChildNodes(); 1271 1272 for (int j = 0; (j < children.getLength()) && (re == null); 1273 j++) { 1274 Node kid = children.item(j); 1275 1276 if (isXSDNode(kid, "extension") 1277 || isXSDNode(kid, "restriction")) { 1278 re = kid; 1279 } 1280 } 1281 } 1282 } 1283 1284 return re; 1285 } 1286 1287 1297 public static QName getArrayComponentQName(Node node, 1298 IntHolder dims, 1299 BooleanHolder underlTypeNillable, 1300 QNameHolder itemQName, 1301 SymbolTable symbolTable) { 1302 1303 dims.value = 1; underlTypeNillable.value = false; 1306 QName qName = getCollectionComponentQName(node, itemQName); 1307 1308 if (qName == null) { 1309 qName = getArrayComponentQName_JAXRPC(node, dims, underlTypeNillable, symbolTable); 1310 } 1311 1312 return qName; 1313 } 1314 1315 1335 public static QName getCollectionComponentQName(Node node, 1336 QNameHolder itemQName) { 1337 boolean storeComponentQName = false; 1345 1346 if (node == null) { 1347 return null; 1348 } 1349 1350 if (itemQName != null && isXSDNode(node, "complexType")) { 1351 Node sequence = SchemaUtils.getChildByName(node, "sequence"); 1356 if (sequence == null) { 1357 return null; 1358 } 1359 NodeList children = sequence.getChildNodes(); 1360 Node element = null; 1361 for (int i = 0; i < children.getLength(); i++) { 1362 if (children.item(i).getNodeType() == Node.ELEMENT_NODE) { 1363 if (element == null) { 1364 element = children.item(i); 1365 } else { 1366 return null; 1367 } 1368 } 1369 } 1370 if (element == null) { 1371 return null; 1372 } 1373 1374 node = element; 1377 storeComponentQName = true; 1378 } 1379 1380 if (isXSDNode(node, "element")) { 1382 1383 BooleanHolder forElement = new BooleanHolder (); 1386 QName componentTypeQName = Utils.getTypeQName(node, 1387 forElement, 1388 true); 1389 1390 if (componentTypeQName != null) { 1391 QName fullQName = Utils.getTypeQName(node, forElement, false); 1392 1393 if (!componentTypeQName.equals(fullQName)) { 1394 if (storeComponentQName) { 1395 String name = Utils.getAttribute(node, "name"); 1396 if (name != null) { 1397 String def = Utils.getScopedAttribute(node, 1399 "elementFormDefault"); 1400 String namespace = ""; 1401 if ((def != null) && def.equals("qualified")) { 1402 namespace = Utils.getScopedAttribute(node, "targetNamespace"); 1403 } 1404 itemQName.value = new QName (namespace, name); 1405 } 1406 } 1407 return componentTypeQName; 1408 } 1409 } 1410 } 1411 1412 return null; 1413 } 1414 1415 1443 private static QName getArrayComponentQName_JAXRPC(Node node, 1444 IntHolder dims, 1445 BooleanHolder underlTypeNillable, 1446 SymbolTable symbolTable) 1447 { 1448 1449 dims.value = 0; underlTypeNillable.value = false; 1451 if (node == null) { 1452 return null; 1453 } 1454 1455 if (isXSDNode(node, "element")) { 1457 NodeList children = node.getChildNodes(); 1458 1459 for (int j = 0; j < children.getLength(); j++) { 1460 Node kid = children.item(j); 1461 1462 if (isXSDNode(kid, "complexType")) { 1463 node = kid; 1464 1465 break; 1466 } 1467 } 1468 } 1469 1470 if (isXSDNode(node, "complexType")) { 1472 1473 NodeList children = node.getChildNodes(); 1476 Node complexContentNode = null; 1477 1478 for (int j = 0; j < children.getLength(); j++) { 1479 Node kid = children.item(j); 1480 1481 if (isXSDNode(kid, "complexContent") 1482 || isXSDNode(kid, "simpleContent")) { 1483 complexContentNode = kid; 1484 1485 break; 1486 } 1487 } 1488 1489 Node restrictionNode = null; 1492 1493 if (complexContentNode != null) { 1494 children = complexContentNode.getChildNodes(); 1495 1496 for (int j = 0; j < children.getLength(); j++) { 1497 Node kid = children.item(j); 1498 1499 if (isXSDNode(kid, "restriction")) { 1500 restrictionNode = kid; 1501 1502 break; 1503 } 1504 } 1505 } 1506 1507 QName baseType = null; 1509 1510 if (restrictionNode != null) { 1511 baseType = Utils.getTypeQName(restrictionNode, 1512 new BooleanHolder (), false); 1513 1514 if (baseType != null) { 1515 if (!baseType.getLocalPart().equals("Array") || 1516 !Constants.isSOAP_ENC(baseType.getNamespaceURI())) { 1517 if (!symbolTable.arrayTypeQNames.contains(baseType)) { 1518 baseType = null; } 1520 } 1521 } 1522 } 1523 1524 Node groupNode = null; 1527 Node attributeNode = null; 1528 1529 if (baseType != null) { 1530 children = restrictionNode.getChildNodes(); 1531 1532 for (int j = 0; (j < children.getLength()) 1533 && (groupNode == null) 1534 && (attributeNode == null); j++) { 1535 Node kid = children.item(j); 1536 1537 if (isXSDNode(kid, "sequence") || isXSDNode(kid, "all")) { 1538 groupNode = kid; 1539 1540 if (groupNode.getChildNodes().getLength() == 0) { 1541 1542 groupNode = null; 1552 } 1553 } 1554 1555 if (isXSDNode(kid, "attribute")) { 1556 1557 BooleanHolder isRef = new BooleanHolder (); 1560 QName refQName = Utils.getTypeQName(kid, isRef, 1561 false); 1562 1563 if ((refQName != null) && isRef.value 1564 && refQName.getLocalPart().equals("arrayType") 1565 && Constants.isSOAP_ENC( 1566 refQName.getNamespaceURI())) { 1567 attributeNode = kid; 1568 } 1569 } 1570 } 1571 } 1572 1573 if (attributeNode != null) { 1575 String wsdlArrayTypeValue = null; 1576 Vector attrs = 1577 Utils.getAttributesWithLocalName(attributeNode, 1578 "arrayType"); 1579 1580 for (int i = 0; 1581 (i < attrs.size()) && (wsdlArrayTypeValue == null); 1582 i++) { 1583 Node attrNode = (Node ) attrs.elementAt(i); 1584 String attrName = attrNode.getNodeName(); 1585 QName attrQName = 1586 Utils.getQNameFromPrefixedName(attributeNode, attrName); 1587 1588 if (Constants.isWSDL(attrQName.getNamespaceURI())) { 1589 wsdlArrayTypeValue = attrNode.getNodeValue(); 1590 } 1591 } 1592 1593 if (wsdlArrayTypeValue != null) { 1598 int i = wsdlArrayTypeValue.indexOf('['); 1599 1600 if (i > 0) { 1601 String prefixedName = wsdlArrayTypeValue.substring(0, 1602 i); 1603 String mangledString = wsdlArrayTypeValue.replace(',', 1604 '['); 1605 1606 dims.value = 0; 1607 1608 int index = mangledString.indexOf('['); 1609 1610 while (index > 0) { 1611 dims.value++; 1612 1613 index = mangledString.indexOf('[', index + 1); 1614 } 1615 1616 return Utils.getQNameFromPrefixedName(restrictionNode, 1617 prefixedName); 1618 } 1619 } 1620 } else if (groupNode != null) { 1621 1622 NodeList elements = groupNode.getChildNodes(); 1624 Node elementNode = null; 1625 1626 for (int i = 0; 1627 (i < elements.getLength()) && (elementNode == null); 1628 i++) { 1629 Node kid = elements.item(i); 1630 1631 if (isXSDNode(kid, "element")) { 1632 elementNode = elements.item(i); 1633 1634 break; 1635 } 1636 } 1637 1638 if (elementNode != null) { 1641 1642 String underlTypeNillableValue = Utils.getAttribute(elementNode, 1643 "nillable"); 1644 1645 if (underlTypeNillableValue != null 1646 && underlTypeNillableValue.equals("true")) { 1647 1648 underlTypeNillable.value = true; 1649 } 1650 1651 String maxOccursValue = Utils.getAttribute(elementNode, 1652 "maxOccurs"); 1653 1654 if ((maxOccursValue != null) 1655 && maxOccursValue.equalsIgnoreCase("unbounded")) { 1656 1657 dims.value = 1; 1659 1660 return Utils.getTypeQName(elementNode, 1661 new BooleanHolder (), true); 1662 } 1663 } 1664 } 1665 } 1666 1667 return null; 1668 } 1669 1670 1678 private static void addAttributeToVector(Vector v, Node child, 1679 SymbolTable symbolTable) { 1680 1681 QName attributeName = Utils.getNodeNameQName(child); 1685 BooleanHolder forElement = new BooleanHolder (); 1686 QName attributeType = Utils.getTypeQName(child, forElement, 1687 false); 1688 1689 if (!forElement.value) { 1694 1695 String form = Utils.getAttribute(child, "form"); 1699 1700 if ((form != null) && form.equals("unqualified")) { 1701 1702 attributeName = Utils.findQName("", 1704 attributeName.getLocalPart()); 1705 } else if (form == null) { 1706 1707 String def = Utils.getScopedAttribute(child, 1709 "attributeFormDefault"); 1710 1711 if ((def == null) || def.equals("unqualified")) { 1712 1713 attributeName = 1715 Utils.findQName("", attributeName.getLocalPart()); 1716 } 1717 } 1718 } else { 1719 attributeName = attributeType; 1720 } 1721 1722 TypeEntry type = symbolTable.getTypeEntry(attributeType, 1724 forElement.value); 1725 1726 if (type instanceof org.apache.axis.wsdl.symbolTable.Element) { 1729 type = ((org.apache.axis.wsdl.symbolTable.Element) type).getRefType(); 1730 } 1731 1732 if ((type != null) && (attributeName != null)) { 1735 ContainedAttribute attr = 1736 new ContainedAttribute(type, attributeName); 1737 1738 String useValue = Utils.getAttribute(child, "use"); 1739 1740 if (useValue != null) { 1741 attr.setOptional(useValue.equalsIgnoreCase("optional")); 1742 } 1743 1744 v.add(attr); 1745 } 1746 } 1747 1748 1757 private static void addAttributeToVector(Vector v, SymbolTable symbolTable, 1758 QName type, QName name) { 1759 1760 TypeEntry typeEnt = symbolTable.getTypeEntry(type, false); 1761 1762 if (typeEnt != null) { 1764 v.add(new ContainedAttribute(typeEnt, name)); 1765 } 1766 } 1767 1768 1776 private static void addAttributeGroupToVector(Vector v, Node attrGrpnode, 1777 SymbolTable symbolTable) { 1778 1779 QName attributeGroupType = Utils.getTypeQName(attrGrpnode, 1781 new BooleanHolder (), false); 1782 TypeEntry type = 1783 symbolTable.getTypeEntry(attributeGroupType, false); 1784 1785 if (type != null) { 1786 if (type.getNode() != null) { 1787 1788 NodeList children = type.getNode().getChildNodes(); 1790 1791 for (int j = 0; j < children.getLength(); j++) { 1792 Node kid = children.item(j); 1793 1794 if (isXSDNode(kid, "attribute")) { 1795 addAttributeToVector(v, kid, symbolTable); 1796 } else if (isXSDNode(kid, "attributeGroup")) { 1797 addAttributeGroupToVector(v, kid, symbolTable); 1798 } 1799 } 1800 } else if (type.isBaseType()) { 1801 1802 if (type.getQName().equals(Constants.SOAP_COMMON_ATTRS11)) { 1805 1806 addAttributeToVector(v, symbolTable, Constants.XSD_ID, 1808 new QName (Constants.URI_SOAP11_ENC, 1809 "id")); 1810 addAttributeToVector(v, symbolTable, Constants.XSD_ANYURI, 1811 new QName (Constants.URI_SOAP11_ENC, 1812 "href")); 1813 } else if (type.getQName().equals( 1814 Constants.SOAP_COMMON_ATTRS12)) { 1815 1816 addAttributeToVector(v, symbolTable, Constants.XSD_ID, 1818 new QName (Constants.URI_SOAP12_ENC, 1819 "id")); 1820 } else if (type.getQName().equals( 1821 Constants.SOAP_ARRAY_ATTRS11)) { 1822 1823 addAttributeToVector(v, symbolTable, Constants.XSD_STRING, 1825 new QName (Constants.URI_SOAP12_ENC, 1826 "arrayType")); 1827 addAttributeToVector(v, symbolTable, Constants.XSD_STRING, 1828 new QName (Constants.URI_SOAP12_ENC, 1829 "offset")); 1830 } else if (type.getQName().equals( 1831 Constants.SOAP_ARRAY_ATTRS12)) { 1832 1833 addAttributeToVector(v, symbolTable, Constants.XSD_STRING, 1841 new QName (Constants.URI_SOAP12_ENC, 1842 "arraySize")); 1843 addAttributeToVector(v, symbolTable, Constants.XSD_QNAME, 1844 new QName (Constants.URI_SOAP12_ENC, 1845 "itemType")); 1846 } 1847 } 1848 } 1849 } 1850 1851 1871 public static Vector getContainedAttributeTypes(Node node, 1872 SymbolTable symbolTable) { 1873 1874 Vector v = null; 1876 if (node == null) { 1877 return null; 1878 } 1879 1880 if (isXSDNode(node, "element")) { 1883 NodeList children = node.getChildNodes(); 1884 int len = children.getLength(); 1885 for (int j = 0; j < len; j++) { 1886 Node kid = children.item(j); 1887 1888 if (isXSDNode(kid, "complexType")) { 1889 node = kid; 1890 1891 break; 1892 } 1893 } 1894 } 1895 1896 if (isXSDNode(node, "complexType")) { 1898 1899 NodeList children = node.getChildNodes(); 1902 Node content = null; 1903 int len = children.getLength(); 1904 for (int j = 0; j < len; j++) { 1905 Node kid = children.item(j); 1906 1907 if (isXSDNode(kid, "complexContent") 1908 || isXSDNode(kid, "simpleContent")) { 1909 content = kid; 1910 1911 break; 1912 } 1913 } 1914 1915 if (content != null) { 1917 children = content.getChildNodes(); 1918 len = children.getLength(); 1919 for (int j = 0; j < len; j++) { 1920 Node kid = children.item(j); 1921 1922 if (isXSDNode(kid, "extension") 1923 || isXSDNode(kid, "restriction")) { 1924 node = kid; 1925 1926 break; 1927 } 1928 } 1929 } 1930 1931 children = node.getChildNodes(); 1933 len = children.getLength(); 1934 for (int i = 0; i < len; i++) { 1935 Node child = children.item(i); 1936 1937 if (isXSDNode(child, "attributeGroup")) { 1938 if (v == null) { 1939 v = new Vector (); 1940 } 1941 addAttributeGroupToVector(v, child, symbolTable); 1942 } else if (isXSDNode(child, "anyAttribute")) { 1943 if (v == null) { 1945 v = new Vector (); 1946 } 1947 } else if (isXSDNode(child, "attribute")) { 1948 if (v == null) { 1950 v = new Vector (); 1951 } 1952 addAttributeToVector(v, child, symbolTable); 1953 } 1954 } 1955 } 1956 1957 return v; 1958 } 1959 1960 1962 1963 private static String schemaTypes[] = { 1964 "string", "normalizedString", "token", "byte", "unsignedByte", 1965 "base64Binary", "hexBinary", "integer", "positiveInteger", 1966 "negativeInteger", "nonNegativeInteger", "nonPositiveInteger", "int", 1967 "unsignedInt", "long", "unsignedLong", "short", "unsignedShort", 1968 "decimal", "float", "double", "boolean", "time", "dateTime", "duration", 1969 "date", "gMonth", "gYear", "gYearMonth", "gDay", "gMonthDay", "Name", 1970 "QName", "NCName", "anyURI", "language", "ID", "IDREF", "IDREFS", 1971 "ENTITY", "ENTITIES", "NOTATION", "NMTOKEN", "NMTOKENS", 1972 "anySimpleType" 1973 }; 1974 1975 1976 private static final Set schemaTypeSet = 1977 new HashSet (Arrays.asList(schemaTypes)); 1978 1979 1985 private static boolean isSimpleSchemaType(String s) { 1986 1987 if (s == null) { 1988 return false; 1989 } 1990 1991 return schemaTypeSet.contains(s); 1992 } 1993 1994 2000 public static boolean isSimpleSchemaType(QName qname) { 2001 2002 if ((qname == null) || !Constants.isSchemaXSD(qname.getNamespaceURI())) { 2003 return false; 2004 } 2005 2006 return isSimpleSchemaType(qname.getLocalPart()); 2007 } 2008 2009 2018 public static TypeEntry getBaseType(TypeEntry type, SymbolTable symbolTable) { 2019 Node node = type.getNode(); 2020 TypeEntry base = getComplexElementExtensionBase( 2021 node, symbolTable); 2022 if (base == null) { 2023 base = getComplexElementRestrictionBase(node, symbolTable); 2024 } 2025 2026 if (base == null) { 2027 QName baseQName = getSimpleTypeBase(node); 2028 if (baseQName != null) { 2029 base = symbolTable.getType(baseQName); 2030 } 2031 } 2032 return base; 2033 } 2034 2035 2041 public static boolean isListWithItemType(Node node) { 2042 2043 return getListItemType(node) != null; 2044 } 2045 2046 2051 public static QName getListItemType(Node node) { 2052 2053 if (node == null) { 2054 return null; 2055 } 2056 2057 if (isXSDNode(node, "element")) { 2059 NodeList children = node.getChildNodes(); 2060 for (int j = 0; j < children.getLength(); j++) { 2061 if (isXSDNode(children.item(j), "simpleType")) { 2062 node = children.item(j); 2063 break; 2064 } 2065 } 2066 } 2067 if (isXSDNode(node, "simpleType")) { 2069 NodeList children = node.getChildNodes(); 2070 for (int j = 0; j < children.getLength(); j++) { 2071 if (isXSDNode(children.item(j), "list")) { 2072 Node listNode = children.item(j); 2073 org.w3c.dom.Element listElement = 2074 (org.w3c.dom.Element ) listNode; 2075 String type = listElement.getAttribute("itemType"); 2076 if (type.equals("")) { 2077 Node localType = null; 2078 children = listNode.getChildNodes(); 2079 for (j = 0; j < children.getLength() && localType == null; j++) { 2080 if (isXSDNode(children.item(j), "simpleType")) { 2081 localType = children.item(j); 2082 } 2083 } 2084 if (localType != null) { 2085 return getSimpleTypeBase(localType); 2086 } 2087 return null; 2088 } 2089 return Utils.getQNameFromPrefixedName(node, type); 2095 } 2096 } 2097 } 2098 return null; 2099 } 2100} 2101 | Popular Tags |