src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/WSDLParser.java

changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
equal deleted inserted replaced
366:8c0b6bccfe47 368:0989ad8c0860
1 /* 1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this 7 * published by the Free Software Foundation. Oracle designates this
56 import com.sun.tools.internal.ws.wsdl.document.schema.SchemaKinds; 56 import com.sun.tools.internal.ws.wsdl.document.schema.SchemaKinds;
57 import com.sun.tools.internal.ws.wsdl.framework.Entity; 57 import com.sun.tools.internal.ws.wsdl.framework.Entity;
58 import com.sun.tools.internal.ws.wsdl.framework.ParserListener; 58 import com.sun.tools.internal.ws.wsdl.framework.ParserListener;
59 import com.sun.tools.internal.ws.wsdl.framework.TWSDLParserContextImpl; 59 import com.sun.tools.internal.ws.wsdl.framework.TWSDLParserContextImpl;
60 import com.sun.xml.internal.ws.util.ServiceFinder; 60 import com.sun.xml.internal.ws.util.ServiceFinder;
61
62 import org.w3c.dom.Attr; 61 import org.w3c.dom.Attr;
63 import org.w3c.dom.Document; 62 import org.w3c.dom.Document;
64 import org.w3c.dom.Element; 63 import org.w3c.dom.Element;
65 import org.w3c.dom.Node;
66 import org.w3c.dom.NodeList; 64 import org.w3c.dom.NodeList;
67 import org.xml.sax.InputSource; 65 import org.xml.sax.InputSource;
68 import org.xml.sax.Locator; 66 import org.xml.sax.Locator;
69 import org.xml.sax.SAXException; 67 import org.xml.sax.SAXException;
70 68
71 import java.io.IOException; 69 import java.io.IOException;
72 import java.util.ArrayList; 70 import java.util.ArrayList;
73 import java.util.HashMap; 71 import java.util.HashMap;
74 import java.util.Iterator; 72 import java.util.Iterator;
75 import java.util.Map; 73 import java.util.Map;
74 import org.w3c.dom.Node;
76 75
77 /** 76 /**
78 * A parser for WSDL documents. This parser is used only at the tool time. 77 * A parser for WSDL documents. This parser is used only at the tool time.
79 * Extensions should extend TWSDLExtensionHandler, so that it will be called during 78 * Extensions should extend TWSDLExtensionHandler, so that it will be called during
80 * parsing wsdl to handle wsdl extenisbility elements. Generally these extensions 79 * parsing wsdl to handle wsdl extenisbility elements. Generally these extensions
99 this.options = options; 98 this.options = options;
100 this.errReceiver = errReceiver; 99 this.errReceiver = errReceiver;
101 if (forest == null) { 100 if (forest == null) {
102 forest = new MetadataFinder(new WSDLInternalizationLogic(), options, errReceiver); 101 forest = new MetadataFinder(new WSDLInternalizationLogic(), options, errReceiver);
103 forest.parseWSDL(); 102 forest.parseWSDL();
104 if (forest.isMexMetadata) 103 if (forest.isMexMetadata) {
105 errReceiver.reset(); 104 errReceiver.reset();
105 }
106 } 106 }
107 this.forest = forest; 107 this.forest = forest;
108 // register handlers for default extensions 108 // register handlers for default extensions
109 register(new SOAPExtensionHandler(extensionHandlers)); 109 register(new SOAPExtensionHandler(extensionHandlers));
110 register(new HTTPExtensionHandler(extensionHandlers)); 110 register(new HTTPExtensionHandler(extensionHandlers));
111 register(new MIMEExtensionHandler(extensionHandlers)); 111 register(new MIMEExtensionHandler(extensionHandlers));
112 register(new JAXWSBindingExtensionHandler(extensionHandlers)); 112 register(new JAXWSBindingExtensionHandler(extensionHandlers));
113 register(new SOAP12ExtensionHandler(extensionHandlers)); 113 register(new SOAP12ExtensionHandler(extensionHandlers));
114 register(new MemberSubmissionAddressingExtensionHandler(extensionHandlers, errReceiver)); 114
115 // MemberSubmission Addressing not supported by WsImport anymore see JAX_WS-1040 for details
116 //register(new MemberSubmissionAddressingExtensionHandler(extensionHandlers, errReceiver, options.isExtensionMode()));
117
115 register(new W3CAddressingExtensionHandler(extensionHandlers, errReceiver)); 118 register(new W3CAddressingExtensionHandler(extensionHandlers, errReceiver));
116 register(new W3CAddressingMetadataExtensionHandler(extensionHandlers, errReceiver)); 119 register(new W3CAddressingMetadataExtensionHandler(extensionHandlers, errReceiver));
117 register(new Policy12ExtensionHandler()); 120 register(new Policy12ExtensionHandler());
118 register(new Policy15ExtensionHandler()); 121 register(new Policy15ExtensionHandler());
119 for (TWSDLExtensionHandler te : ServiceFinder.find(TWSDLExtensionHandler.class)) { 122 for (TWSDLExtensionHandler te : ServiceFinder.find(TWSDLExtensionHandler.class)) {
142 for (InputSource value : options.getWSDLBindings()) { 145 for (InputSource value : options.getWSDLBindings()) {
143 errReceiver.pollAbort(); 146 errReceiver.pollAbort();
144 Document root = forest.parse(value, false); 147 Document root = forest.parse(value, false);
145 if(root==null) continue; // error must have been reported 148 if(root==null) continue; // error must have been reported
146 Element binding = root.getDocumentElement(); 149 Element binding = root.getDocumentElement();
147 if (!fixNull(binding.getNamespaceURI()).equals(JAXWSBindingsConstants.NS_JAXWS_BINDINGS) 150 if (!Internalizer.fixNull(binding.getNamespaceURI()).equals(JAXWSBindingsConstants.NS_JAXWS_BINDINGS)
148 || !binding.getLocalName().equals("bindings")){ 151 || !binding.getLocalName().equals("bindings")){
149 errReceiver.error(forest.locatorTable.getStartLocation(binding), WsdlMessages.PARSER_NOT_A_BINDING_FILE( 152 errReceiver.error(forest.locatorTable.getStartLocation(binding), WsdlMessages.PARSER_NOT_A_BINDING_FILE(
150 binding.getNamespaceURI(), 153 binding.getNamespaceURI(),
151 binding.getLocalName())); 154 binding.getLocalName()));
152 continue; 155 continue;
160 163
161 } 164 }
162 return buildWSDLDocument(); 165 return buildWSDLDocument();
163 } 166 }
164 167
165 private String fixNull(String s) {
166 if(s==null) return "";
167 else return s;
168 }
169
170 public MetadataFinder getDOMForest() { 168 public MetadataFinder getDOMForest() {
171 return forest; 169 return forest;
172 } 170 }
173 171
174 private WSDLDocument buildWSDLDocument(){ 172 private WSDLDocument buildWSDLDocument(){
201 context.pushWSDLLocation(); 199 context.pushWSDLLocation();
202 context.setWSDLLocation(context.getDocument().getSystemId()); 200 context.setWSDLLocation(context.getDocument().getSystemId());
203 201
204 new Internalizer(forest, options, errReceiver).transform(); 202 new Internalizer(forest, options, errReceiver).transform();
205 203
206 //print the wsdl
207 // try{
208 // forest.dump(System.out);
209 // }catch(IOException e){
210 // e.printStackTrace();
211 // }
212
213 Definitions definitions = parseDefinitionsNoImport(context, root); 204 Definitions definitions = parseDefinitionsNoImport(context, root);
214 if(definitions == null){ 205 if(definitions == null){
215 Locator locator = forest.locatorTable.getStartLocation(root.getDocumentElement()); 206 Locator locator = forest.locatorTable.getStartLocation(root.getDocumentElement());
216 errReceiver.error(locator, WsdlMessages.PARSING_NOT_AWSDL(locator.getSystemId())); 207 errReceiver.error(locator, WsdlMessages.PARSING_NOT_AWSDL(locator.getSystemId()));
217 208
219 processImports(context); 210 processImports(context);
220 context.popWSDLLocation(); 211 context.popWSDLLocation();
221 return definitions; 212 return definitions;
222 } 213 }
223 214
224 private void processMexDocs(TWSDLParserContextImpl context){
225 for(String location : forest.listSystemIDs()){
226 if (!context.getDocument().isImportedDocument(location)){
227 Document doc = forest.get(location);
228 if(doc == null)
229 continue;
230 Definitions importedDefinitions = parseDefinitionsNoImport(context, doc);
231 if(importedDefinitions == null)
232 continue;
233 context.getDocument().addImportedEntity(importedDefinitions);
234 context.getDocument().addImportedDocument(location);
235 }
236 }
237 }
238 private void processImports(TWSDLParserContextImpl context) { 215 private void processImports(TWSDLParserContextImpl context) {
239 for(String location : forest.getExternalReferences()){ 216 for(String location : forest.getExternalReferences()){
240 if (!context.getDocument().isImportedDocument(location)){ 217 if (!context.getDocument().isImportedDocument(location)){
241 Document doc = forest.get(location); 218 Document doc = forest.get(location);
242 if(doc == null) 219 if(doc == null)
518 e3.getLocalName().equals(Constants.ATTR_NAME)) 495 e3.getLocalName().equals(Constants.ATTR_NAME))
519 continue; 496 continue;
520 497
521 // possible extensibility element -- must live outside the WSDL namespace 498 // possible extensibility element -- must live outside the WSDL namespace
522 checkNotWsdlAttribute(e3); 499 checkNotWsdlAttribute(e3);
523 if (!handleExtension(context, input, e3, e2)) { 500 handleExtension(context, input, e3, e2);
524 // ignore the extensiblity attribute
525 // TODO throw a WARNING
526 }
527 } 501 }
528 502
529 // verify that there is at most one child element and it is a documentation element 503 // verify that there is at most one child element and it is a documentation element
530 boolean gotDocumentation2 = false; 504 boolean gotDocumentation2 = false;
531 for (Iterator iter2 = XmlUtil.getAllChildren(e2); 505 for (Iterator iter2 = XmlUtil.getAllChildren(e2);
580 e3.getLocalName().equals(Constants.ATTR_NAME)) 554 e3.getLocalName().equals(Constants.ATTR_NAME))
581 continue; 555 continue;
582 556
583 // possible extensibility element -- must live outside the WSDL namespace 557 // possible extensibility element -- must live outside the WSDL namespace
584 checkNotWsdlAttribute(e3); 558 checkNotWsdlAttribute(e3);
585 if (!handleExtension(context, output, e3, e2)) { 559 handleExtension(context, output, e3, e2);
586 // ignore the extensiblity attribute
587 // TODO throw a WARNING
588 }
589 } 560 }
590 561
591 // verify that there is at most one child element and it is a documentation element 562 // verify that there is at most one child element and it is a documentation element
592 boolean gotDocumentation2 = false; 563 boolean gotDocumentation2 = false;
593 for (Iterator iter2 = XmlUtil.getAllChildren(e2); 564 for (Iterator iter2 = XmlUtil.getAllChildren(e2);
633 e3.getLocalName().equals(Constants.ATTR_NAME)) 604 e3.getLocalName().equals(Constants.ATTR_NAME))
634 continue; 605 continue;
635 606
636 // possible extensibility element -- must live outside the WSDL namespace 607 // possible extensibility element -- must live outside the WSDL namespace
637 checkNotWsdlAttribute(e3); 608 checkNotWsdlAttribute(e3);
638 if (!handleExtension(context, fault, e3, e2)) { 609 handleExtension(context, fault, e3, e2);
639 // ignore the extensiblity attribute
640 // TODO throw a WARNING
641 }
642 } 610 }
643 611
644 // verify that there is at most one child element and it is a documentation element 612 // verify that there is at most one child element and it is a documentation element
645 boolean gotDocumentation2 = false; 613 boolean gotDocumentation2 = false;
646 for (Iterator iter2 = XmlUtil.getAllChildren(e2); 614 for (Iterator iter2 = XmlUtil.getAllChildren(e2);
778 Constants.TAG_OPERATION, 746 Constants.TAG_OPERATION,
779 name)); 747 name));
780 } 748 }
781 749
782 /* Here we check for the use scenario */ 750 /* Here we check for the use scenario */
783 Iterator itere2 = XmlUtil.getAllChildren(e2);
784 context.push(); 751 context.push();
785 context.registerNamespaces(e2); 752 context.registerNamespaces(e2);
786 BindingInput input = new BindingInput(forest.locatorTable.getStartLocation(e2)); 753 BindingInput input = new BindingInput(forest.locatorTable.getStartLocation(e2));
787 String nameAttr = 754 String nameAttr =
788 XmlUtil.getAttributeOrNull(e2, Constants.ATTR_NAME); 755 XmlUtil.getAttributeOrNull(e2, Constants.ATTR_NAME);
982 if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) { 949 if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) {
983 if (gotDocumentation) { 950 if (gotDocumentation) {
984 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName())); 951 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName()));
985 } 952 }
986 gotDocumentation = true; 953 gotDocumentation = true;
987 if(service.getDocumentation() == null) 954 if (service.getDocumentation() == null) {
988 service.setDocumentation(getDocumentationFor(e2)); 955 service.setDocumentation(getDocumentationFor(e2));
956 }
989 } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_PORT)) { 957 } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_PORT)) {
990 Port port = parsePort(context, definitions, e2); 958 Port port = parsePort(context, definitions, e2);
991 service.add(port); 959 service.add(port);
992 } else { 960 } else {
993 // possible extensibility element -- must live outside the WSDL namespace 961 // possible extensibility element -- must live outside the WSDL namespace
1020 988
1021 boolean gotDocumentation = false; 989 boolean gotDocumentation = false;
1022 990
1023 for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) { 991 for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
1024 Element e2 = Util.nextElement(iter); 992 Element e2 = Util.nextElement(iter);
1025 if (e2 == null) 993 if (e2 == null) {
1026 break; 994 break;
995 }
1027 996
1028 if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) { 997 if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) {
1029 if (gotDocumentation) { 998 if (gotDocumentation) {
1030 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName())); 999 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName()));
1031 } 1000 }
1032 gotDocumentation = true; 1001 gotDocumentation = true;
1033 if(port.getDocumentation() == null) 1002 if (port.getDocumentation() == null) {
1034 port.setDocumentation(getDocumentationFor(e2)); 1003 port.setDocumentation(getDocumentationFor(e2));
1004 }
1035 } else { 1005 } else {
1036 // possible extensibility element -- must live outside the WSDL namespace 1006 // possible extensibility element -- must live outside the WSDL namespace
1037 checkNotWsdlElement(e2); 1007 checkNotWsdlElement(e2);
1038 if (!handleExtension(context, port, e2)) { 1008 if (!handleExtension(context, port, e2)) {
1039 checkNotWsdlRequired(e2); 1009 checkNotWsdlRequired(e2);
1047 } 1017 }
1048 1018
1049 private void validateSchemaImports(Element typesElement){ 1019 private void validateSchemaImports(Element typesElement){
1050 for (Iterator iter = XmlUtil.getAllChildren(typesElement); iter.hasNext();) { 1020 for (Iterator iter = XmlUtil.getAllChildren(typesElement); iter.hasNext();) {
1051 Element e = Util.nextElement(iter); 1021 Element e = Util.nextElement(iter);
1052 if (e == null) 1022 if (e == null) {
1053 break; 1023 break;
1024 }
1054 if (XmlUtil.matchesTagNS(e, SchemaConstants.QNAME_IMPORT)) { 1025 if (XmlUtil.matchesTagNS(e, SchemaConstants.QNAME_IMPORT)) {
1055 errReceiver.warning(forest.locatorTable.getStartLocation(e), WsdlMessages.WARNING_WSI_R_2003()); 1026 errReceiver.warning(forest.locatorTable.getStartLocation(e), WsdlMessages.WARNING_WSI_R_2003());
1056 }else{ 1027 }else{
1057 checkNotWsdlElement(e); 1028 checkNotWsdlElement(e);
1058 // if (XmlUtil.matchesTagNS(e, SchemaConstants.QNAME_SCHEMA)) { 1029 // if (XmlUtil.matchesTagNS(e, SchemaConstants.QNAME_SCHEMA)) {
1070 Element e) { 1041 Element e) {
1071 TWSDLExtensionHandler h = 1042 TWSDLExtensionHandler h =
1072 (TWSDLExtensionHandler) extensionHandlers.get(e.getNamespaceURI()); 1043 (TWSDLExtensionHandler) extensionHandlers.get(e.getNamespaceURI());
1073 if (h == null) { 1044 if (h == null) {
1074 context.fireIgnoringExtension(e, (Entity) entity); 1045 context.fireIgnoringExtension(e, (Entity) entity);
1046 errReceiver.warning(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_UNKNOWN_EXTENSIBILITY_ELEMENT_OR_ATTRIBUTE(e.getLocalName(), e.getNamespaceURI()));
1075 return false; 1047 return false;
1076 } else { 1048 } else {
1077 return h.doHandleExtension(context, entity, e); 1049 return h.doHandleExtension(context, entity, e);
1078 } 1050 }
1079 } 1051 }
1085 Element e) { 1057 Element e) {
1086 TWSDLExtensionHandler h = 1058 TWSDLExtensionHandler h =
1087 (TWSDLExtensionHandler) extensionHandlers.get(n.getNamespaceURI()); 1059 (TWSDLExtensionHandler) extensionHandlers.get(n.getNamespaceURI());
1088 if (h == null) { 1060 if (h == null) {
1089 context.fireIgnoringExtension(e, (Entity) entity); 1061 context.fireIgnoringExtension(e, (Entity) entity);
1062 errReceiver.warning(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_UNKNOWN_EXTENSIBILITY_ELEMENT_OR_ATTRIBUTE(n.getLocalName(), n.getNamespaceURI()));
1090 return false; 1063 return false;
1091 } else { 1064 } else {
1092 return h.doHandleExtension(context, entity, e); 1065 return h.doHandleExtension(context, entity, e);
1093 } 1066 }
1094 } 1067 }
1095 1068
1096 private void checkNotWsdlElement(Element e) { 1069 private void checkNotWsdlElement(Element e) {
1097 // possible extensibility element -- must live outside the WSDL namespace 1070 // possible extensibility element -- must live outside the WSDL namespace
1098 if (e.getNamespaceURI() != null && e.getNamespaceURI().equals(Constants.NS_WSDL)) 1071 if (e.getNamespaceURI() != null && e.getNamespaceURI().equals(Constants.NS_WSDL)) {
1099 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_INVALID_WSDL_ELEMENT(e.getTagName())); 1072 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_INVALID_WSDL_ELEMENT(e.getTagName()));
1073 }
1100 } 1074 }
1101 1075
1102 private void checkNotWsdlAttribute(Attr a) { 1076 private void checkNotWsdlAttribute(Attr a) {
1103 // possible extensibility element -- must live outside the WSDL namespace 1077 // possible extensibility element -- must live outside the WSDL namespace
1104 if (a.getNamespaceURI().equals(Constants.NS_WSDL)) 1078 if (Constants.NS_WSDL.equals(a.getNamespaceURI())) {
1105 errReceiver.error(forest.locatorTable.getStartLocation(a.getOwnerElement()), WsdlMessages.PARSING_INVALID_WSDL_ELEMENT(a.getLocalName())); 1079 errReceiver.error(forest.locatorTable.getStartLocation(a.getOwnerElement()), WsdlMessages.PARSING_INVALID_WSDL_ELEMENT(a.getLocalName()));
1080 }
1106 } 1081 }
1107 1082
1108 private void checkNotWsdlRequired(Element e) { 1083 private void checkNotWsdlRequired(Element e) {
1109 // check the wsdl:required attribute, fail if set to "true" 1084 // check the wsdl:required attribute, fail if set to "true"
1110 String required = 1085 String required =

mercurial