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

Fri, 04 Oct 2013 16:21:34 +0100

author
mkos
date
Fri, 04 Oct 2013 16:21:34 +0100
changeset 408
b0610cd08440
parent 368
0989ad8c0860
child 637
9c07ef4934dd
permissions
-rw-r--r--

8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
Reviewed-by: chegar

ohair@286 1 /*
alanb@368 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 package com.sun.tools.internal.ws.wsdl.parser;
ohair@286 27
ohair@286 28 import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible;
ohair@286 29 import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensionHandler;
ohair@286 30 import com.sun.tools.internal.ws.resources.WsdlMessages;
ohair@286 31 import com.sun.tools.internal.ws.util.xml.XmlUtil;
ohair@286 32 import com.sun.tools.internal.ws.wscompile.ErrorReceiverFilter;
ohair@286 33 import com.sun.tools.internal.ws.wscompile.WsimportOptions;
ohair@286 34 import com.sun.tools.internal.ws.wsdl.document.Binding;
ohair@286 35 import com.sun.tools.internal.ws.wsdl.document.BindingFault;
ohair@286 36 import com.sun.tools.internal.ws.wsdl.document.BindingInput;
ohair@286 37 import com.sun.tools.internal.ws.wsdl.document.BindingOperation;
ohair@286 38 import com.sun.tools.internal.ws.wsdl.document.BindingOutput;
ohair@286 39 import com.sun.tools.internal.ws.wsdl.document.Definitions;
ohair@286 40 import com.sun.tools.internal.ws.wsdl.document.Documentation;
ohair@286 41 import com.sun.tools.internal.ws.wsdl.document.Fault;
ohair@286 42 import com.sun.tools.internal.ws.wsdl.document.Import;
ohair@286 43 import com.sun.tools.internal.ws.wsdl.document.Input;
ohair@286 44 import com.sun.tools.internal.ws.wsdl.document.Message;
ohair@286 45 import com.sun.tools.internal.ws.wsdl.document.MessagePart;
ohair@286 46 import com.sun.tools.internal.ws.wsdl.document.Operation;
ohair@286 47 import com.sun.tools.internal.ws.wsdl.document.OperationStyle;
ohair@286 48 import com.sun.tools.internal.ws.wsdl.document.Output;
ohair@286 49 import com.sun.tools.internal.ws.wsdl.document.Port;
ohair@286 50 import com.sun.tools.internal.ws.wsdl.document.PortType;
ohair@286 51 import com.sun.tools.internal.ws.wsdl.document.Service;
ohair@286 52 import com.sun.tools.internal.ws.wsdl.document.WSDLConstants;
ohair@286 53 import com.sun.tools.internal.ws.wsdl.document.WSDLDocument;
ohair@286 54 import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBindingsConstants;
ohair@286 55 import com.sun.tools.internal.ws.wsdl.document.schema.SchemaConstants;
ohair@286 56 import com.sun.tools.internal.ws.wsdl.document.schema.SchemaKinds;
ohair@286 57 import com.sun.tools.internal.ws.wsdl.framework.Entity;
ohair@286 58 import com.sun.tools.internal.ws.wsdl.framework.ParserListener;
ohair@286 59 import com.sun.tools.internal.ws.wsdl.framework.TWSDLParserContextImpl;
ohair@286 60 import com.sun.xml.internal.ws.util.ServiceFinder;
ohair@286 61 import org.w3c.dom.Attr;
ohair@286 62 import org.w3c.dom.Document;
ohair@286 63 import org.w3c.dom.Element;
ohair@286 64 import org.w3c.dom.NodeList;
ohair@286 65 import org.xml.sax.InputSource;
ohair@286 66 import org.xml.sax.Locator;
ohair@286 67 import org.xml.sax.SAXException;
ohair@286 68
ohair@286 69 import java.io.IOException;
ohair@286 70 import java.util.ArrayList;
ohair@286 71 import java.util.HashMap;
ohair@286 72 import java.util.Iterator;
ohair@286 73 import java.util.Map;
alanb@368 74 import org.w3c.dom.Node;
ohair@286 75
ohair@286 76 /**
ohair@286 77 * A parser for WSDL documents. This parser is used only at the tool time.
ohair@286 78 * Extensions should extend TWSDLExtensionHandler, so that it will be called during
ohair@286 79 * parsing wsdl to handle wsdl extenisbility elements. Generally these extensions
ohair@286 80 * will effect the artifacts generated during WSDL processing.
ohair@286 81 *
ohair@286 82 * @see com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser which will be used for WSDL parsing
ohair@286 83 * at runtime.
ohair@286 84 *
ohair@286 85 * @author WS Development Team
ohair@286 86 */
ohair@286 87 public class WSDLParser {
ohair@286 88 private final ErrorReceiverFilter errReceiver;
ohair@286 89 private WsimportOptions options;
ohair@286 90
ohair@286 91 //wsdl extension handlers
ohair@286 92 private final Map extensionHandlers;
ohair@286 93 private MetadataFinder forest;
ohair@286 94 private ArrayList<ParserListener> listeners;
ohair@286 95
ohair@286 96 public WSDLParser(WsimportOptions options, ErrorReceiverFilter errReceiver, MetadataFinder forest) {
ohair@286 97 this.extensionHandlers = new HashMap();
ohair@286 98 this.options = options;
ohair@286 99 this.errReceiver = errReceiver;
ohair@286 100 if (forest == null) {
ohair@286 101 forest = new MetadataFinder(new WSDLInternalizationLogic(), options, errReceiver);
ohair@286 102 forest.parseWSDL();
alanb@368 103 if (forest.isMexMetadata) {
ohair@286 104 errReceiver.reset();
ohair@286 105 }
alanb@368 106 }
ohair@286 107 this.forest = forest;
ohair@286 108 // register handlers for default extensions
ohair@286 109 register(new SOAPExtensionHandler(extensionHandlers));
ohair@286 110 register(new HTTPExtensionHandler(extensionHandlers));
ohair@286 111 register(new MIMEExtensionHandler(extensionHandlers));
ohair@286 112 register(new JAXWSBindingExtensionHandler(extensionHandlers));
ohair@286 113 register(new SOAP12ExtensionHandler(extensionHandlers));
alanb@368 114
alanb@368 115 // MemberSubmission Addressing not supported by WsImport anymore see JAX_WS-1040 for details
alanb@368 116 //register(new MemberSubmissionAddressingExtensionHandler(extensionHandlers, errReceiver, options.isExtensionMode()));
alanb@368 117
ohair@286 118 register(new W3CAddressingExtensionHandler(extensionHandlers, errReceiver));
ohair@286 119 register(new W3CAddressingMetadataExtensionHandler(extensionHandlers, errReceiver));
ohair@286 120 register(new Policy12ExtensionHandler());
ohair@286 121 register(new Policy15ExtensionHandler());
ohair@286 122 for (TWSDLExtensionHandler te : ServiceFinder.find(TWSDLExtensionHandler.class)) {
ohair@286 123 register(te);
ohair@286 124 }
ohair@286 125
ohair@286 126 }
ohair@286 127
ohair@286 128 //TODO RK remove this after tests are fixed.
ohair@286 129 WSDLParser(WsimportOptions options, ErrorReceiverFilter errReceiver) {
ohair@286 130 this(options,errReceiver,null);
ohair@286 131 }
ohair@286 132 private void register(TWSDLExtensionHandler h) {
ohair@286 133 extensionHandlers.put(h.getNamespaceURI(), h);
ohair@286 134 }
ohair@286 135
ohair@286 136 public void addParserListener(ParserListener l) {
ohair@286 137 if (listeners == null) {
ohair@286 138 listeners = new ArrayList<ParserListener>();
ohair@286 139 }
ohair@286 140 listeners.add(l);
ohair@286 141 }
ohair@286 142
ohair@286 143 public WSDLDocument parse() throws SAXException, IOException {
ohair@286 144 // parse external binding files
ohair@286 145 for (InputSource value : options.getWSDLBindings()) {
ohair@286 146 errReceiver.pollAbort();
ohair@286 147 Document root = forest.parse(value, false);
ohair@286 148 if(root==null) continue; // error must have been reported
ohair@286 149 Element binding = root.getDocumentElement();
alanb@368 150 if (!Internalizer.fixNull(binding.getNamespaceURI()).equals(JAXWSBindingsConstants.NS_JAXWS_BINDINGS)
ohair@286 151 || !binding.getLocalName().equals("bindings")){
ohair@286 152 errReceiver.error(forest.locatorTable.getStartLocation(binding), WsdlMessages.PARSER_NOT_A_BINDING_FILE(
ohair@286 153 binding.getNamespaceURI(),
ohair@286 154 binding.getLocalName()));
ohair@286 155 continue;
ohair@286 156 }
ohair@286 157
ohair@286 158 NodeList nl = binding.getElementsByTagNameNS(
ohair@286 159 "http://java.sun.com/xml/ns/javaee", "handler-chains");
ohair@286 160 for(int i = 0; i < nl.getLength(); i++){
ohair@286 161 options.addHandlerChainConfiguration((Element) nl.item(i));
ohair@286 162 }
ohair@286 163
ohair@286 164 }
ohair@286 165 return buildWSDLDocument();
ohair@286 166 }
ohair@286 167
ohair@286 168 public MetadataFinder getDOMForest() {
ohair@286 169 return forest;
ohair@286 170 }
ohair@286 171
ohair@286 172 private WSDLDocument buildWSDLDocument(){
ohair@286 173 /**
ohair@286 174 * Currently we are working off first WSDL document
ohair@286 175 * TODO: add support of creating WSDLDocument from fromjava.collection of WSDL documents
ohair@286 176 */
ohair@286 177
ohair@286 178 String location = forest.getRootWSDL();
ohair@286 179
ohair@286 180 //It means that WSDL is not found, an error might have been reported, lets try to recover
ohair@286 181 if(location == null)
ohair@286 182 return null;
ohair@286 183
ohair@286 184 Document root = forest.get(location);
ohair@286 185
ohair@286 186 if(root == null)
ohair@286 187 return null;
ohair@286 188
ohair@286 189 WSDLDocument document = new WSDLDocument(forest, errReceiver);
ohair@286 190 document.setSystemId(location);
ohair@286 191 TWSDLParserContextImpl context = new TWSDLParserContextImpl(forest, document, listeners, errReceiver);
ohair@286 192
ohair@286 193 Definitions definitions = parseDefinitions(context, root);
ohair@286 194 document.setDefinitions(definitions);
ohair@286 195 return document;
ohair@286 196 }
ohair@286 197
ohair@286 198 private Definitions parseDefinitions(TWSDLParserContextImpl context, Document root) {
ohair@286 199 context.pushWSDLLocation();
ohair@286 200 context.setWSDLLocation(context.getDocument().getSystemId());
ohair@286 201
ohair@286 202 new Internalizer(forest, options, errReceiver).transform();
ohair@286 203
ohair@286 204 Definitions definitions = parseDefinitionsNoImport(context, root);
ohair@286 205 if(definitions == null){
ohair@286 206 Locator locator = forest.locatorTable.getStartLocation(root.getDocumentElement());
ohair@286 207 errReceiver.error(locator, WsdlMessages.PARSING_NOT_AWSDL(locator.getSystemId()));
ohair@286 208
ohair@286 209 }
ohair@286 210 processImports(context);
ohair@286 211 context.popWSDLLocation();
ohair@286 212 return definitions;
ohair@286 213 }
ohair@286 214
ohair@286 215 private void processImports(TWSDLParserContextImpl context) {
ohair@286 216 for(String location : forest.getExternalReferences()){
ohair@286 217 if (!context.getDocument().isImportedDocument(location)){
ohair@286 218 Document doc = forest.get(location);
ohair@286 219 if(doc == null)
ohair@286 220 continue;
ohair@286 221 Definitions importedDefinitions = parseDefinitionsNoImport(context, doc);
ohair@286 222 if(importedDefinitions == null)
ohair@286 223 continue;
ohair@286 224 context.getDocument().addImportedEntity(importedDefinitions);
ohair@286 225 context.getDocument().addImportedDocument(location);
ohair@286 226 }
ohair@286 227 }
ohair@286 228 }
ohair@286 229
ohair@286 230 private Definitions parseDefinitionsNoImport(
ohair@286 231 TWSDLParserContextImpl context,
ohair@286 232 Document doc) {
ohair@286 233 Element e = doc.getDocumentElement();
ohair@286 234 //at this poinjt we expect a wsdl or schema document to be fully qualified
ohair@286 235 if(e.getNamespaceURI() == null || (!e.getNamespaceURI().equals(WSDLConstants.NS_WSDL) || !e.getLocalName().equals("definitions"))){
ohair@286 236 return null;
ohair@286 237 }
ohair@286 238 context.push();
ohair@286 239 context.registerNamespaces(e);
ohair@286 240
ohair@286 241 Definitions definitions = new Definitions(context.getDocument(), forest.locatorTable.getStartLocation(e));
ohair@286 242 String name = XmlUtil.getAttributeOrNull(e, Constants.ATTR_NAME);
ohair@286 243 definitions.setName(name);
ohair@286 244
ohair@286 245 String targetNamespaceURI =
ohair@286 246 XmlUtil.getAttributeOrNull(e, Constants.ATTR_TARGET_NAMESPACE);
ohair@286 247
ohair@286 248 definitions.setTargetNamespaceURI(targetNamespaceURI);
ohair@286 249
ohair@286 250 boolean gotDocumentation = false;
ohair@286 251 boolean gotTypes = false;
ohair@286 252
ohair@286 253 for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
ohair@286 254 Element e2 = Util.nextElement(iter);
ohair@286 255 if (e2 == null)
ohair@286 256 break;
ohair@286 257
ohair@286 258 if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) {
ohair@286 259 if (gotDocumentation) {
ohair@286 260 errReceiver.error(forest.locatorTable.getStartLocation(e2), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName()));
ohair@286 261 return null;
ohair@286 262 }
ohair@286 263 gotDocumentation = true;
ohair@286 264 if(definitions.getDocumentation() == null)
ohair@286 265 definitions.setDocumentation(getDocumentationFor(e2));
ohair@286 266 } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_TYPES)) {
ohair@286 267 if (gotTypes && !options.isExtensionMode()) {
ohair@286 268 errReceiver.error(forest.locatorTable.getStartLocation(e2), WsdlMessages.PARSING_ONLY_ONE_TYPES_ALLOWED(Constants.TAG_DEFINITIONS));
ohair@286 269 return null;
ohair@286 270 }
ohair@286 271 gotTypes = true;
ohair@286 272 //add all the wsdl:type elements to latter make a list of all the schema elements
ohair@286 273 // that will be needed to create jaxb model
ohair@286 274 if(!options.isExtensionMode())
ohair@286 275 validateSchemaImports(e2);
ohair@286 276 } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_MESSAGE)) {
ohair@286 277 Message message = parseMessage(context, definitions, e2);
ohair@286 278 definitions.add(message);
ohair@286 279 } else if (
ohair@286 280 XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_PORT_TYPE)) {
ohair@286 281 PortType portType = parsePortType(context, definitions, e2);
ohair@286 282 definitions.add(portType);
ohair@286 283 } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_BINDING)) {
ohair@286 284 Binding binding = parseBinding(context, definitions, e2);
ohair@286 285 definitions.add(binding);
ohair@286 286 } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_SERVICE)) {
ohair@286 287 Service service = parseService(context, definitions, e2);
ohair@286 288 definitions.add(service);
ohair@286 289 } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_IMPORT)) {
ohair@286 290 definitions.add(parseImport(context, definitions, e2));
ohair@286 291 } else if (XmlUtil.matchesTagNS(e2, SchemaConstants.QNAME_IMPORT)) {
ohair@286 292 errReceiver.warning(forest.locatorTable.getStartLocation(e2), WsdlMessages.WARNING_WSI_R_2003());
ohair@286 293 } else {
ohair@286 294 // possible extensibility element -- must live outside the WSDL namespace
ohair@286 295 checkNotWsdlElement(e2);
ohair@286 296 if (!handleExtension(context, definitions, e2)) {
ohair@286 297 checkNotWsdlRequired(e2);
ohair@286 298 }
ohair@286 299 }
ohair@286 300 }
ohair@286 301
ohair@286 302 context.pop();
ohair@286 303 context.fireDoneParsingEntity(
ohair@286 304 WSDLConstants.QNAME_DEFINITIONS,
ohair@286 305 definitions);
ohair@286 306 return definitions;
ohair@286 307 }
ohair@286 308
ohair@286 309 private Message parseMessage(
ohair@286 310 TWSDLParserContextImpl context,
ohair@286 311 Definitions definitions,
ohair@286 312 Element e) {
ohair@286 313 context.push();
ohair@286 314 context.registerNamespaces(e);
ohair@286 315 Message message = new Message(definitions, forest.locatorTable.getStartLocation(e), errReceiver);
ohair@286 316 String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME);
ohair@286 317 message.setName(name);
ohair@286 318
ohair@286 319 boolean gotDocumentation = false;
ohair@286 320
ohair@286 321 for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
ohair@286 322 Element e2 = Util.nextElement(iter);
ohair@286 323 if (e2 == null)
ohair@286 324 break;
ohair@286 325
ohair@286 326 if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) {
ohair@286 327 if (gotDocumentation) {
ohair@286 328 Util.fail(
ohair@286 329 "parsing.onlyOneDocumentationAllowed",
ohair@286 330 e.getLocalName());
ohair@286 331 }
ohair@286 332 gotDocumentation = true;
ohair@286 333 message.setDocumentation(getDocumentationFor(e2));
ohair@286 334 } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_PART)) {
ohair@286 335 MessagePart part = parseMessagePart(context, e2);
ohair@286 336 message.add(part);
ohair@286 337 } else {
ohair@286 338 //Ignore any extensibility elements, WS-I BP 1.1 Profiled WSDL 1.1 schema allows extension elements here.
ohair@286 339 /*Util.fail(
ohair@286 340 "parsing.invalidElement",
ohair@286 341 e2.getTagName(),
ohair@286 342 e2.getNamespaceURI());
ohair@286 343 */
ohair@286 344 }
ohair@286 345 }
ohair@286 346
ohair@286 347 context.pop();
ohair@286 348 context.fireDoneParsingEntity(WSDLConstants.QNAME_MESSAGE, message);
ohair@286 349 return message;
ohair@286 350 }
ohair@286 351
ohair@286 352 private MessagePart parseMessagePart(TWSDLParserContextImpl context, Element e) {
ohair@286 353 context.push();
ohair@286 354 context.registerNamespaces(e);
ohair@286 355 MessagePart part = new MessagePart(forest.locatorTable.getStartLocation(e));
ohair@286 356 String partName = Util.getRequiredAttribute(e, Constants.ATTR_NAME);
ohair@286 357 part.setName(partName);
ohair@286 358
ohair@286 359 String elementAttr =
ohair@286 360 XmlUtil.getAttributeOrNull(e, Constants.ATTR_ELEMENT);
ohair@286 361 String typeAttr = XmlUtil.getAttributeOrNull(e, Constants.ATTR_TYPE);
ohair@286 362
ohair@286 363 if (elementAttr != null) {
ohair@286 364 if (typeAttr != null) {
ohair@286 365 errReceiver.error(context.getLocation(e), WsdlMessages.PARSING_ONLY_ONE_OF_ELEMENT_OR_TYPE_REQUIRED(partName));
ohair@286 366
ohair@286 367 }
ohair@286 368
ohair@286 369 part.setDescriptor(context.translateQualifiedName(context.getLocation(e), elementAttr));
ohair@286 370 part.setDescriptorKind(SchemaKinds.XSD_ELEMENT);
ohair@286 371 } else if (typeAttr != null) {
ohair@286 372 part.setDescriptor(context.translateQualifiedName(context.getLocation(e), typeAttr));
ohair@286 373 part.setDescriptorKind(SchemaKinds.XSD_TYPE);
ohair@286 374 } else {
ohair@286 375 // XXX-NOTE - this is wrong; for extensibility purposes,
ohair@286 376 // any attribute can be specified on a <part> element, so
ohair@286 377 // we need to put an extensibility hook here
ohair@286 378 errReceiver.warning(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ELEMENT_OR_TYPE_REQUIRED(partName));
ohair@286 379 }
ohair@286 380
ohair@286 381 context.pop();
ohair@286 382 context.fireDoneParsingEntity(WSDLConstants.QNAME_PART, part);
ohair@286 383 return part;
ohair@286 384 }
ohair@286 385
ohair@286 386 private PortType parsePortType(
ohair@286 387 TWSDLParserContextImpl context,
ohair@286 388 Definitions definitions,
ohair@286 389 Element e) {
ohair@286 390 context.push();
ohair@286 391 context.registerNamespaces(e);
ohair@286 392 PortType portType = new PortType(definitions, forest.locatorTable.getStartLocation(e), errReceiver);
ohair@286 393 String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME);
ohair@286 394 portType.setName(name);
ohair@286 395
ohair@286 396 boolean gotDocumentation = false;
ohair@286 397
ohair@286 398 for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
ohair@286 399 Element e2 = Util.nextElement(iter);
ohair@286 400 if (e2 == null)
ohair@286 401 break;
ohair@286 402
ohair@286 403 if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) {
ohair@286 404 if (gotDocumentation) {
ohair@286 405 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName()));
ohair@286 406 }
ohair@286 407 gotDocumentation = true;
ohair@286 408 if(portType.getDocumentation() == null)
ohair@286 409 portType.setDocumentation(getDocumentationFor(e2));
ohair@286 410 } else if (
ohair@286 411 XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_OPERATION)) {
ohair@286 412 Operation op = parsePortTypeOperation(context, e2);
ohair@286 413 op.setParent(portType);
ohair@286 414 portType.add(op);
ohair@286 415 } else {
ohair@286 416 // possible extensibility element -- must live outside the WSDL namespace
ohair@286 417 checkNotWsdlElement(e2);
ohair@286 418 if (!handleExtension(context, portType, e2)) {
ohair@286 419 checkNotWsdlRequired(e2);
ohair@286 420 }
ohair@286 421 }/*else {
ohair@286 422 Util.fail(
ohair@286 423 "parsing.invalidElement",
ohair@286 424 e2.getTagName(),
ohair@286 425 e2.getNamespaceURI());
ohair@286 426 }*/
ohair@286 427 }
ohair@286 428
ohair@286 429 context.pop();
ohair@286 430 context.fireDoneParsingEntity(WSDLConstants.QNAME_PORT_TYPE, portType);
ohair@286 431 return portType;
ohair@286 432 }
ohair@286 433
ohair@286 434 private Operation parsePortTypeOperation(
ohair@286 435 TWSDLParserContextImpl context,
ohair@286 436 Element e) {
ohair@286 437 context.push();
ohair@286 438 context.registerNamespaces(e);
ohair@286 439
ohair@286 440 Operation operation = new Operation(forest.locatorTable.getStartLocation(e));
ohair@286 441 String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME);
ohair@286 442 operation.setName(name);
ohair@286 443 String parameterOrderAttr =
ohair@286 444 XmlUtil.getAttributeOrNull(e, Constants.ATTR_PARAMETER_ORDER);
ohair@286 445 operation.setParameterOrder(parameterOrderAttr);
ohair@286 446
ohair@286 447 boolean gotDocumentation = false;
ohair@286 448
ohair@286 449 boolean gotInput = false;
ohair@286 450 boolean gotOutput = false;
ohair@286 451 boolean gotFault = false;
ohair@286 452 boolean inputBeforeOutput = false;
ohair@286 453
ohair@286 454 for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
ohair@286 455 Element e2 = Util.nextElement(iter);
ohair@286 456 if (e2 == null)
ohair@286 457 break;
ohair@286 458
ohair@286 459 if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) {
ohair@286 460 if (gotDocumentation) {
ohair@286 461 errReceiver.error(forest.locatorTable.getStartLocation(e2), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e2.getLocalName()));
ohair@286 462 }
ohair@286 463 gotDocumentation = true;
ohair@286 464 if(operation.getDocumentation() == null)
ohair@286 465 operation.setDocumentation(getDocumentationFor(e2));
ohair@286 466 } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_INPUT)) {
ohair@286 467 if (gotInput) {
ohair@286 468 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_TOO_MANY_ELEMENTS(Constants.TAG_INPUT,
ohair@286 469 Constants.TAG_OPERATION,
ohair@286 470 name));
ohair@286 471 }
ohair@286 472
ohair@286 473 context.push();
ohair@286 474 context.registerNamespaces(e2);
ohair@286 475 Input input = new Input(forest.locatorTable.getStartLocation(e2), errReceiver);
ohair@286 476 input.setParent(operation);
ohair@286 477 String messageAttr =
ohair@286 478 Util.getRequiredAttribute(e2, Constants.ATTR_MESSAGE);
ohair@286 479 input.setMessage(context.translateQualifiedName(context.getLocation(e2), messageAttr));
ohair@286 480 String nameAttr =
ohair@286 481 XmlUtil.getAttributeOrNull(e2, Constants.ATTR_NAME);
ohair@286 482 input.setName(nameAttr);
ohair@286 483 operation.setInput(input);
ohair@286 484 gotInput = true;
ohair@286 485 if (gotOutput) {
ohair@286 486 inputBeforeOutput = false;
ohair@286 487 }
ohair@286 488
ohair@286 489 // check for extensiblity attributes
ohair@286 490 for (Iterator iter2 = XmlUtil.getAllAttributes(e2);
ohair@286 491 iter2.hasNext();
ohair@286 492 ) {
ohair@286 493 Attr e3 = (Attr)iter2.next();
ohair@286 494 if (e3.getLocalName().equals(Constants.ATTR_MESSAGE) ||
ohair@286 495 e3.getLocalName().equals(Constants.ATTR_NAME))
ohair@286 496 continue;
ohair@286 497
ohair@286 498 // possible extensibility element -- must live outside the WSDL namespace
ohair@286 499 checkNotWsdlAttribute(e3);
alanb@368 500 handleExtension(context, input, e3, e2);
ohair@286 501 }
ohair@286 502
ohair@286 503 // verify that there is at most one child element and it is a documentation element
ohair@286 504 boolean gotDocumentation2 = false;
ohair@286 505 for (Iterator iter2 = XmlUtil.getAllChildren(e2);
ohair@286 506 iter2.hasNext();
ohair@286 507 ) {
ohair@286 508 Element e3 = Util.nextElement(iter2);
ohair@286 509 if (e3 == null)
ohair@286 510 break;
ohair@286 511
ohair@286 512 if (XmlUtil
ohair@286 513 .matchesTagNS(e3, WSDLConstants.QNAME_DOCUMENTATION)) {
ohair@286 514 if (gotDocumentation2) {
ohair@286 515 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName()));
ohair@286 516 }
ohair@286 517 gotDocumentation2 = true;
ohair@286 518 input.setDocumentation(getDocumentationFor(e3));
ohair@286 519 } else {
ohair@286 520 errReceiver.error(forest.locatorTable.getStartLocation(e3), WsdlMessages.PARSING_INVALID_ELEMENT(e3.getTagName(),
ohair@286 521 e3.getNamespaceURI()));
ohair@286 522 }
ohair@286 523 }
ohair@286 524 context.pop();
ohair@286 525 } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_OUTPUT)) {
ohair@286 526 if (gotOutput) {
ohair@286 527 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_TOO_MANY_ELEMENTS(Constants.TAG_INPUT,
ohair@286 528 Constants.TAG_OPERATION,
ohair@286 529 name));
ohair@286 530 }
ohair@286 531
ohair@286 532 context.push();
ohair@286 533 context.registerNamespaces(e2);
ohair@286 534 Output output = new Output(forest.locatorTable.getStartLocation(e2), errReceiver);
ohair@286 535 output.setParent(operation);
ohair@286 536 String messageAttr =
ohair@286 537 Util.getRequiredAttribute(e2, Constants.ATTR_MESSAGE);
ohair@286 538 output.setMessage(context.translateQualifiedName(context.getLocation(e2), messageAttr));
ohair@286 539 String nameAttr =
ohair@286 540 XmlUtil.getAttributeOrNull(e2, Constants.ATTR_NAME);
ohair@286 541 output.setName(nameAttr);
ohair@286 542 operation.setOutput(output);
ohair@286 543 gotOutput = true;
ohair@286 544 if (gotInput) {
ohair@286 545 inputBeforeOutput = true;
ohair@286 546 }
ohair@286 547
ohair@286 548 // check for extensiblity attributes
ohair@286 549 for (Iterator iter2 = XmlUtil.getAllAttributes(e2);
ohair@286 550 iter2.hasNext();
ohair@286 551 ) {
ohair@286 552 Attr e3 = (Attr)iter2.next();
ohair@286 553 if (e3.getLocalName().equals(Constants.ATTR_MESSAGE) ||
ohair@286 554 e3.getLocalName().equals(Constants.ATTR_NAME))
ohair@286 555 continue;
ohair@286 556
ohair@286 557 // possible extensibility element -- must live outside the WSDL namespace
ohair@286 558 checkNotWsdlAttribute(e3);
alanb@368 559 handleExtension(context, output, e3, e2);
ohair@286 560 }
ohair@286 561
ohair@286 562 // verify that there is at most one child element and it is a documentation element
ohair@286 563 boolean gotDocumentation2 = false;
ohair@286 564 for (Iterator iter2 = XmlUtil.getAllChildren(e2);
ohair@286 565 iter2.hasNext();
ohair@286 566 ) {
ohair@286 567 Element e3 = Util.nextElement(iter2);
ohair@286 568 if (e3 == null)
ohair@286 569 break;
ohair@286 570
ohair@286 571 if (XmlUtil
ohair@286 572 .matchesTagNS(e3, WSDLConstants.QNAME_DOCUMENTATION)) {
ohair@286 573 if (gotDocumentation2) {
ohair@286 574 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName()));
ohair@286 575 }
ohair@286 576 gotDocumentation2 = true;
ohair@286 577 output.setDocumentation(getDocumentationFor(e3));
ohair@286 578 } else {
ohair@286 579 errReceiver.error(forest.locatorTable.getStartLocation(e3), WsdlMessages.PARSING_INVALID_ELEMENT(e3.getTagName(),
ohair@286 580 e3.getNamespaceURI()));
ohair@286 581 }
ohair@286 582 }
ohair@286 583 context.pop();
ohair@286 584 } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_FAULT)) {
ohair@286 585 context.push();
ohair@286 586 context.registerNamespaces(e2);
ohair@286 587 Fault fault = new Fault(forest.locatorTable.getStartLocation(e2));
ohair@286 588 fault.setParent(operation);
ohair@286 589 String messageAttr =
ohair@286 590 Util.getRequiredAttribute(e2, Constants.ATTR_MESSAGE);
ohair@286 591 fault.setMessage(context.translateQualifiedName(context.getLocation(e2), messageAttr));
ohair@286 592 String nameAttr =
ohair@286 593 XmlUtil.getAttributeOrNull(e2, Constants.ATTR_NAME);
ohair@286 594 fault.setName(nameAttr);
ohair@286 595 operation.addFault(fault);
ohair@286 596 gotFault = true;
ohair@286 597
ohair@286 598 // check for extensiblity attributes
ohair@286 599 for (Iterator iter2 = XmlUtil.getAllAttributes(e2);
ohair@286 600 iter2.hasNext();
ohair@286 601 ) {
ohair@286 602 Attr e3 = (Attr)iter2.next();
ohair@286 603 if (e3.getLocalName().equals(Constants.ATTR_MESSAGE) ||
ohair@286 604 e3.getLocalName().equals(Constants.ATTR_NAME))
ohair@286 605 continue;
ohair@286 606
ohair@286 607 // possible extensibility element -- must live outside the WSDL namespace
ohair@286 608 checkNotWsdlAttribute(e3);
alanb@368 609 handleExtension(context, fault, e3, e2);
ohair@286 610 }
ohair@286 611
ohair@286 612 // verify that there is at most one child element and it is a documentation element
ohair@286 613 boolean gotDocumentation2 = false;
ohair@286 614 for (Iterator iter2 = XmlUtil.getAllChildren(e2);
ohair@286 615 iter2.hasNext();
ohair@286 616 ) {
ohair@286 617 Element e3 = Util.nextElement(iter2);
ohair@286 618 if (e3 == null)
ohair@286 619 break;
ohair@286 620
ohair@286 621 if (XmlUtil
ohair@286 622 .matchesTagNS(e3, WSDLConstants.QNAME_DOCUMENTATION)) {
ohair@286 623 if (gotDocumentation2) {
ohair@286 624 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName()));
ohair@286 625 }
ohair@286 626 gotDocumentation2 = true;
ohair@286 627 if(fault.getDocumentation() == null)
ohair@286 628 fault.setDocumentation(getDocumentationFor(e3));
ohair@286 629 } else {
ohair@286 630 // possible extensibility element -- must live outside the WSDL namespace
ohair@286 631 checkNotWsdlElement(e3);
ohair@286 632 if (!handleExtension(context, fault, e3)) {
ohair@286 633 checkNotWsdlRequired(e3);
ohair@286 634 }
ohair@286 635 }/*else {
ohair@286 636 Util.fail(
ohair@286 637 "parsing.invalidElement",
ohair@286 638 e3.getTagName(),
ohair@286 639 e3.getNamespaceURI());
ohair@286 640 }*/
ohair@286 641 }
ohair@286 642 context.pop();
ohair@286 643 } else {
ohair@286 644 // possible extensibility element -- must live outside the WSDL namespace
ohair@286 645 checkNotWsdlElement(e2);
ohair@286 646 if (!handleExtension(context, operation, e2)) {
ohair@286 647 checkNotWsdlRequired(e2);
ohair@286 648 }
ohair@286 649 }/*else {
ohair@286 650 Util.fail(
ohair@286 651 "parsing.invalidElement",
ohair@286 652 e2.getTagName(),
ohair@286 653 e2.getNamespaceURI());
ohair@286 654 }*/
ohair@286 655 }
ohair@286 656
ohair@286 657 if (gotInput && !gotOutput && !gotFault) {
ohair@286 658 operation.setStyle(OperationStyle.ONE_WAY);
ohair@286 659 } else if (gotInput && gotOutput && inputBeforeOutput) {
ohair@286 660 operation.setStyle(OperationStyle.REQUEST_RESPONSE);
ohair@286 661 } else if (gotInput && gotOutput && !inputBeforeOutput) {
ohair@286 662 operation.setStyle(OperationStyle.SOLICIT_RESPONSE);
ohair@286 663 } else if (gotOutput && !gotInput && !gotFault) {
ohair@286 664 operation.setStyle(OperationStyle.NOTIFICATION);
ohair@286 665 } else {
ohair@286 666 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_INVALID_OPERATION_STYLE(name));
ohair@286 667 }
ohair@286 668
ohair@286 669 context.pop();
ohair@286 670 context.fireDoneParsingEntity(WSDLConstants.QNAME_OPERATION, operation);
ohair@286 671 return operation;
ohair@286 672 }
ohair@286 673
ohair@286 674 private Binding parseBinding(
ohair@286 675 TWSDLParserContextImpl context,
ohair@286 676 Definitions definitions,
ohair@286 677 Element e) {
ohair@286 678 context.push();
ohair@286 679 context.registerNamespaces(e);
ohair@286 680 Binding binding = new Binding(definitions, forest.locatorTable.getStartLocation(e), errReceiver);
ohair@286 681 String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME);
ohair@286 682 binding.setName(name);
ohair@286 683 String typeAttr = Util.getRequiredAttribute(e, Constants.ATTR_TYPE);
ohair@286 684 binding.setPortType(context.translateQualifiedName(context.getLocation(e), typeAttr));
ohair@286 685
ohair@286 686 boolean gotDocumentation = false;
ohair@286 687
ohair@286 688 for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
ohair@286 689 Element e2 = Util.nextElement(iter);
ohair@286 690 if (e2 == null)
ohair@286 691 break;
ohair@286 692
ohair@286 693 if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) {
ohair@286 694 if (gotDocumentation) {
ohair@286 695 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName()));
ohair@286 696 }
ohair@286 697 gotDocumentation = true;
ohair@286 698 binding.setDocumentation(getDocumentationFor(e2));
ohair@286 699 } else if (
ohair@286 700 XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_OPERATION)) {
ohair@286 701 BindingOperation op = parseBindingOperation(context, e2);
ohair@286 702 binding.add(op);
ohair@286 703 } else {
ohair@286 704 // possible extensibility element -- must live outside the WSDL namespace
ohair@286 705 checkNotWsdlElement(e2);
ohair@286 706 if (!handleExtension(context, binding, e2)) {
ohair@286 707 checkNotWsdlRequired(e2);
ohair@286 708 }
ohair@286 709 }
ohair@286 710 }
ohair@286 711
ohair@286 712 context.pop();
ohair@286 713 context.fireDoneParsingEntity(WSDLConstants.QNAME_BINDING, binding);
ohair@286 714 return binding;
ohair@286 715 }
ohair@286 716
ohair@286 717 private BindingOperation parseBindingOperation(
ohair@286 718 TWSDLParserContextImpl context,
ohair@286 719 Element e) {
ohair@286 720 context.push();
ohair@286 721 context.registerNamespaces(e);
ohair@286 722 BindingOperation operation = new BindingOperation(forest.locatorTable.getStartLocation(e));
ohair@286 723 String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME);
ohair@286 724 operation.setName(name);
ohair@286 725
ohair@286 726 boolean gotDocumentation = false;
ohair@286 727
ohair@286 728 boolean gotInput = false;
ohair@286 729 boolean gotOutput = false;
ohair@286 730 boolean gotFault = false;
ohair@286 731 boolean inputBeforeOutput = false;
ohair@286 732
ohair@286 733 for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
ohair@286 734 Element e2 = Util.nextElement(iter);
ohair@286 735 if (e2 == null)
ohair@286 736 break;
ohair@286 737 if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) {
ohair@286 738 if (gotDocumentation) {
ohair@286 739 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName()));
ohair@286 740 }
ohair@286 741 gotDocumentation = true;
ohair@286 742 operation.setDocumentation(getDocumentationFor(e2));
ohair@286 743 } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_INPUT)) {
ohair@286 744 if (gotInput) {
ohair@286 745 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_TOO_MANY_ELEMENTS(Constants.TAG_INPUT,
ohair@286 746 Constants.TAG_OPERATION,
ohair@286 747 name));
ohair@286 748 }
ohair@286 749
ohair@286 750 /* Here we check for the use scenario */
ohair@286 751 context.push();
ohair@286 752 context.registerNamespaces(e2);
ohair@286 753 BindingInput input = new BindingInput(forest.locatorTable.getStartLocation(e2));
ohair@286 754 String nameAttr =
ohair@286 755 XmlUtil.getAttributeOrNull(e2, Constants.ATTR_NAME);
ohair@286 756 input.setName(nameAttr);
ohair@286 757 operation.setInput(input);
ohair@286 758 gotInput = true;
ohair@286 759 if (gotOutput) {
ohair@286 760 inputBeforeOutput = false;
ohair@286 761 }
ohair@286 762
ohair@286 763 // verify that there is at most one child element and it is a documentation element
ohair@286 764 boolean gotDocumentation2 = false;
ohair@286 765 for (Iterator iter2 = XmlUtil.getAllChildren(e2);
ohair@286 766 iter2.hasNext();
ohair@286 767 ) {
ohair@286 768 Element e3 = Util.nextElement(iter2);
ohair@286 769 if (e3 == null)
ohair@286 770 break;
ohair@286 771
ohair@286 772 if (XmlUtil
ohair@286 773 .matchesTagNS(e3, WSDLConstants.QNAME_DOCUMENTATION)) {
ohair@286 774 if (gotDocumentation2) {
ohair@286 775 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName()));
ohair@286 776 }
ohair@286 777 gotDocumentation2 = true;
ohair@286 778 input.setDocumentation(getDocumentationFor(e3));
ohair@286 779 } else {
ohair@286 780 // possible extensibility element -- must live outside the WSDL namespace
ohair@286 781 checkNotWsdlElement(e3);
ohair@286 782 if (!handleExtension(context, input, e3)) {
ohair@286 783 checkNotWsdlRequired(e3);
ohair@286 784 }
ohair@286 785 }
ohair@286 786 }
ohair@286 787 context.pop();
ohair@286 788 } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_OUTPUT)) {
ohair@286 789 if (gotOutput) {
ohair@286 790 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_TOO_MANY_ELEMENTS(Constants.TAG_INPUT,
ohair@286 791 Constants.TAG_OPERATION,
ohair@286 792 name));
ohair@286 793 }
ohair@286 794
ohair@286 795 context.push();
ohair@286 796 context.registerNamespaces(e2);
ohair@286 797 BindingOutput output = new BindingOutput(forest.locatorTable.getStartLocation(e2));
ohair@286 798 String nameAttr =
ohair@286 799 XmlUtil.getAttributeOrNull(e2, Constants.ATTR_NAME);
ohair@286 800 output.setName(nameAttr);
ohair@286 801 operation.setOutput(output);
ohair@286 802 gotOutput = true;
ohair@286 803 if (gotInput) {
ohair@286 804 inputBeforeOutput = true;
ohair@286 805 }
ohair@286 806
ohair@286 807 // verify that there is at most one child element and it is a documentation element
ohair@286 808 boolean gotDocumentation2 = false;
ohair@286 809 for (Iterator iter2 = XmlUtil.getAllChildren(e2);
ohair@286 810 iter2.hasNext();
ohair@286 811 ) {
ohair@286 812
ohair@286 813 Element e3 = Util.nextElement(iter2);
ohair@286 814 if (e3 == null)
ohair@286 815 break;
ohair@286 816
ohair@286 817 if (XmlUtil
ohair@286 818 .matchesTagNS(e3, WSDLConstants.QNAME_DOCUMENTATION)) {
ohair@286 819 if (gotDocumentation2) {
ohair@286 820 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName()));
ohair@286 821 }
ohair@286 822 gotDocumentation2 = true;
ohair@286 823 output.setDocumentation(getDocumentationFor(e3));
ohair@286 824 } else {
ohair@286 825 // possible extensibility element -- must live outside the WSDL namespace
ohair@286 826 checkNotWsdlElement(e3);
ohair@286 827 if (!handleExtension(context, output, e3)) {
ohair@286 828 checkNotWsdlRequired(e3);
ohair@286 829 }
ohair@286 830 }
ohair@286 831 }
ohair@286 832 context.pop();
ohair@286 833 } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_FAULT)) {
ohair@286 834 context.push();
ohair@286 835 context.registerNamespaces(e2);
ohair@286 836 BindingFault fault = new BindingFault(forest.locatorTable.getStartLocation(e2));
ohair@286 837 String nameAttr =
ohair@286 838 Util.getRequiredAttribute(e2, Constants.ATTR_NAME);
ohair@286 839 fault.setName(nameAttr);
ohair@286 840 operation.addFault(fault);
ohair@286 841 gotFault = true;
ohair@286 842
ohair@286 843 // verify that there is at most one child element and it is a documentation element
ohair@286 844 boolean gotDocumentation2 = false;
ohair@286 845 for (Iterator iter2 = XmlUtil.getAllChildren(e2);
ohair@286 846 iter2.hasNext();
ohair@286 847 ) {
ohair@286 848 Element e3 = Util.nextElement(iter2);
ohair@286 849 if (e3 == null)
ohair@286 850 break;
ohair@286 851
ohair@286 852 if (XmlUtil
ohair@286 853 .matchesTagNS(e3, WSDLConstants.QNAME_DOCUMENTATION)) {
ohair@286 854 if (gotDocumentation2) {
ohair@286 855 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName()));
ohair@286 856 }
ohair@286 857 gotDocumentation2 = true;
ohair@286 858 if(fault.getDocumentation() == null)
ohair@286 859 fault.setDocumentation(getDocumentationFor(e3));
ohair@286 860 } else {
ohair@286 861 // possible extensibility element -- must live outside the WSDL namespace
ohair@286 862 checkNotWsdlElement(e3);
ohair@286 863 if (!handleExtension(context, fault, e3)) {
ohair@286 864 checkNotWsdlRequired(e3);
ohair@286 865 }
ohair@286 866 }
ohair@286 867 }
ohair@286 868 context.pop();
ohair@286 869 } else {
ohair@286 870 // possible extensibility element -- must live outside the WSDL namespace
ohair@286 871 checkNotWsdlElement(e2);
ohair@286 872 if (!handleExtension(context, operation, e2)) {
ohair@286 873 checkNotWsdlRequired(e2);
ohair@286 874 }
ohair@286 875 }
ohair@286 876 }
ohair@286 877
ohair@286 878 if (gotInput && !gotOutput && !gotFault) {
ohair@286 879 operation.setStyle(OperationStyle.ONE_WAY);
ohair@286 880 } else if (gotInput && gotOutput && inputBeforeOutput) {
ohair@286 881 operation.setStyle(OperationStyle.REQUEST_RESPONSE);
ohair@286 882 } else if (gotInput && gotOutput && !inputBeforeOutput) {
ohair@286 883 operation.setStyle(OperationStyle.SOLICIT_RESPONSE);
ohair@286 884 } else if (gotOutput && !gotInput && !gotFault) {
ohair@286 885 operation.setStyle(OperationStyle.NOTIFICATION);
ohair@286 886 } else {
ohair@286 887 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_INVALID_OPERATION_STYLE(name));
ohair@286 888 }
ohair@286 889
ohair@286 890 context.pop();
ohair@286 891 context.fireDoneParsingEntity(WSDLConstants.QNAME_OPERATION, operation);
ohair@286 892 return operation;
ohair@286 893 }
ohair@286 894
ohair@286 895 private Import parseImport(
ohair@286 896 TWSDLParserContextImpl context,
ohair@286 897 Definitions definitions,
ohair@286 898 Element e) {
ohair@286 899 context.push();
ohair@286 900 context.registerNamespaces(e);
ohair@286 901 Import anImport = new Import(forest.locatorTable.getStartLocation(e));
ohair@286 902 String namespace =
ohair@286 903 Util.getRequiredAttribute(e, Constants.ATTR_NAMESPACE);
ohair@286 904 anImport.setNamespace(namespace);
ohair@286 905 String location = Util.getRequiredAttribute(e, Constants.ATTR_LOCATION);
ohair@286 906 anImport.setLocation(location);
ohair@286 907
ohair@286 908 // according to the schema in the WSDL 1.1 spec, an import can have a documentation element
ohair@286 909 boolean gotDocumentation = false;
ohair@286 910
ohair@286 911 for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
ohair@286 912 Element e2 = Util.nextElement(iter);
ohair@286 913 if (e2 == null)
ohair@286 914 break;
ohair@286 915
ohair@286 916 if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) {
ohair@286 917 if (gotDocumentation) {
ohair@286 918 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName()));
ohair@286 919 }
ohair@286 920 gotDocumentation = true;
ohair@286 921 anImport.setDocumentation(getDocumentationFor(e2));
ohair@286 922 } else {
ohair@286 923 errReceiver.error(forest.locatorTable.getStartLocation(e2), WsdlMessages.PARSING_INVALID_ELEMENT(e2.getTagName(),
ohair@286 924 e2.getNamespaceURI()));
ohair@286 925 }
ohair@286 926 }
ohair@286 927 context.pop();
ohair@286 928 context.fireDoneParsingEntity(WSDLConstants.QNAME_IMPORT, anImport);
ohair@286 929 return anImport;
ohair@286 930 }
ohair@286 931
ohair@286 932 private Service parseService(
ohair@286 933 TWSDLParserContextImpl context,
ohair@286 934 Definitions definitions,
ohair@286 935 Element e) {
ohair@286 936 context.push();
ohair@286 937 context.registerNamespaces(e);
ohair@286 938 Service service = new Service(definitions, forest.locatorTable.getStartLocation(e), errReceiver);
ohair@286 939 String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME);
ohair@286 940 service.setName(name);
ohair@286 941
ohair@286 942 boolean gotDocumentation = false;
ohair@286 943
ohair@286 944 for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
ohair@286 945 Element e2 = Util.nextElement(iter);
ohair@286 946 if (e2 == null)
ohair@286 947 break;
ohair@286 948
ohair@286 949 if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) {
ohair@286 950 if (gotDocumentation) {
ohair@286 951 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName()));
ohair@286 952 }
ohair@286 953 gotDocumentation = true;
alanb@368 954 if (service.getDocumentation() == null) {
ohair@286 955 service.setDocumentation(getDocumentationFor(e2));
alanb@368 956 }
ohair@286 957 } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_PORT)) {
ohair@286 958 Port port = parsePort(context, definitions, e2);
ohair@286 959 service.add(port);
ohair@286 960 } else {
ohair@286 961 // possible extensibility element -- must live outside the WSDL namespace
ohair@286 962 checkNotWsdlElement(e2);
ohair@286 963 if (!handleExtension(context, service, e2)) {
ohair@286 964 checkNotWsdlRequired(e2);
ohair@286 965 }
ohair@286 966 }
ohair@286 967 }
ohair@286 968
ohair@286 969 context.pop();
ohair@286 970 context.fireDoneParsingEntity(WSDLConstants.QNAME_SERVICE, service);
ohair@286 971 return service;
ohair@286 972 }
ohair@286 973
ohair@286 974 private Port parsePort(
ohair@286 975 TWSDLParserContextImpl context,
ohair@286 976 Definitions definitions,
ohair@286 977 Element e) {
ohair@286 978 context.push();
ohair@286 979 context.registerNamespaces(e);
ohair@286 980
ohair@286 981 Port port = new Port(definitions, forest.locatorTable.getStartLocation(e), errReceiver);
ohair@286 982 String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME);
ohair@286 983 port.setName(name);
ohair@286 984
ohair@286 985 String bindingAttr =
ohair@286 986 Util.getRequiredAttribute(e, Constants.ATTR_BINDING);
ohair@286 987 port.setBinding(context.translateQualifiedName(context.getLocation(e), bindingAttr));
ohair@286 988
ohair@286 989 boolean gotDocumentation = false;
ohair@286 990
ohair@286 991 for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
ohair@286 992 Element e2 = Util.nextElement(iter);
alanb@368 993 if (e2 == null) {
ohair@286 994 break;
alanb@368 995 }
ohair@286 996
ohair@286 997 if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) {
ohair@286 998 if (gotDocumentation) {
ohair@286 999 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName()));
ohair@286 1000 }
ohair@286 1001 gotDocumentation = true;
alanb@368 1002 if (port.getDocumentation() == null) {
ohair@286 1003 port.setDocumentation(getDocumentationFor(e2));
alanb@368 1004 }
ohair@286 1005 } else {
ohair@286 1006 // possible extensibility element -- must live outside the WSDL namespace
ohair@286 1007 checkNotWsdlElement(e2);
ohair@286 1008 if (!handleExtension(context, port, e2)) {
ohair@286 1009 checkNotWsdlRequired(e2);
ohair@286 1010 }
ohair@286 1011 }
ohair@286 1012 }
ohair@286 1013
ohair@286 1014 context.pop();
ohair@286 1015 context.fireDoneParsingEntity(WSDLConstants.QNAME_PORT, port);
ohair@286 1016 return port;
ohair@286 1017 }
ohair@286 1018
ohair@286 1019 private void validateSchemaImports(Element typesElement){
ohair@286 1020 for (Iterator iter = XmlUtil.getAllChildren(typesElement); iter.hasNext();) {
ohair@286 1021 Element e = Util.nextElement(iter);
alanb@368 1022 if (e == null) {
ohair@286 1023 break;
alanb@368 1024 }
ohair@286 1025 if (XmlUtil.matchesTagNS(e, SchemaConstants.QNAME_IMPORT)) {
ohair@286 1026 errReceiver.warning(forest.locatorTable.getStartLocation(e), WsdlMessages.WARNING_WSI_R_2003());
ohair@286 1027 }else{
ohair@286 1028 checkNotWsdlElement(e);
ohair@286 1029 // if (XmlUtil.matchesTagNS(e, SchemaConstants.QNAME_SCHEMA)) {
ohair@286 1030 // forest.getInlinedSchemaElement().add(e);
ohair@286 1031 // }
ohair@286 1032
ohair@286 1033 }
ohair@286 1034 }
ohair@286 1035 }
ohair@286 1036
ohair@286 1037
ohair@286 1038 private boolean handleExtension(
ohair@286 1039 TWSDLParserContextImpl context,
ohair@286 1040 TWSDLExtensible entity,
ohair@286 1041 Element e) {
ohair@286 1042 TWSDLExtensionHandler h =
ohair@286 1043 (TWSDLExtensionHandler) extensionHandlers.get(e.getNamespaceURI());
ohair@286 1044 if (h == null) {
ohair@286 1045 context.fireIgnoringExtension(e, (Entity) entity);
alanb@368 1046 errReceiver.warning(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_UNKNOWN_EXTENSIBILITY_ELEMENT_OR_ATTRIBUTE(e.getLocalName(), e.getNamespaceURI()));
ohair@286 1047 return false;
ohair@286 1048 } else {
ohair@286 1049 return h.doHandleExtension(context, entity, e);
ohair@286 1050 }
ohair@286 1051 }
ohair@286 1052
ohair@286 1053 private boolean handleExtension(
ohair@286 1054 TWSDLParserContextImpl context,
ohair@286 1055 TWSDLExtensible entity,
ohair@286 1056 Node n,
ohair@286 1057 Element e) {
ohair@286 1058 TWSDLExtensionHandler h =
ohair@286 1059 (TWSDLExtensionHandler) extensionHandlers.get(n.getNamespaceURI());
ohair@286 1060 if (h == null) {
ohair@286 1061 context.fireIgnoringExtension(e, (Entity) entity);
alanb@368 1062 errReceiver.warning(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_UNKNOWN_EXTENSIBILITY_ELEMENT_OR_ATTRIBUTE(n.getLocalName(), n.getNamespaceURI()));
ohair@286 1063 return false;
ohair@286 1064 } else {
ohair@286 1065 return h.doHandleExtension(context, entity, e);
ohair@286 1066 }
ohair@286 1067 }
ohair@286 1068
ohair@286 1069 private void checkNotWsdlElement(Element e) {
ohair@286 1070 // possible extensibility element -- must live outside the WSDL namespace
alanb@368 1071 if (e.getNamespaceURI() != null && e.getNamespaceURI().equals(Constants.NS_WSDL)) {
ohair@286 1072 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_INVALID_WSDL_ELEMENT(e.getTagName()));
ohair@286 1073 }
alanb@368 1074 }
ohair@286 1075
ohair@286 1076 private void checkNotWsdlAttribute(Attr a) {
ohair@286 1077 // possible extensibility element -- must live outside the WSDL namespace
alanb@368 1078 if (Constants.NS_WSDL.equals(a.getNamespaceURI())) {
ohair@286 1079 errReceiver.error(forest.locatorTable.getStartLocation(a.getOwnerElement()), WsdlMessages.PARSING_INVALID_WSDL_ELEMENT(a.getLocalName()));
ohair@286 1080 }
alanb@368 1081 }
ohair@286 1082
ohair@286 1083 private void checkNotWsdlRequired(Element e) {
ohair@286 1084 // check the wsdl:required attribute, fail if set to "true"
ohair@286 1085 String required =
ohair@286 1086 XmlUtil.getAttributeNSOrNull(
ohair@286 1087 e,
ohair@286 1088 Constants.ATTR_REQUIRED,
ohair@286 1089 Constants.NS_WSDL);
ohair@286 1090 if (required != null && required.equals(Constants.TRUE) && !options.isExtensionMode()) {
ohair@286 1091 errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_REQUIRED_EXTENSIBILITY_ELEMENT(e.getTagName(),
ohair@286 1092 e.getNamespaceURI()));
ohair@286 1093 }
ohair@286 1094 }
ohair@286 1095
ohair@286 1096 private Documentation getDocumentationFor(Element e) {
ohair@286 1097 String s = XmlUtil.getTextForNode(e);
ohair@286 1098 if (s == null) {
ohair@286 1099 return null;
ohair@286 1100 } else {
ohair@286 1101 return new Documentation(s);
ohair@286 1102 }
ohair@286 1103 }
ohair@286 1104 }

mercurial