ohair@286: /* alanb@368: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. ohair@286: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ohair@286: * ohair@286: * This code is free software; you can redistribute it and/or modify it ohair@286: * under the terms of the GNU General Public License version 2 only, as ohair@286: * published by the Free Software Foundation. Oracle designates this ohair@286: * particular file as subject to the "Classpath" exception as provided ohair@286: * by Oracle in the LICENSE file that accompanied this code. ohair@286: * ohair@286: * This code is distributed in the hope that it will be useful, but WITHOUT ohair@286: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ohair@286: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ohair@286: * version 2 for more details (a copy is included in the LICENSE file that ohair@286: * accompanied this code). ohair@286: * ohair@286: * You should have received a copy of the GNU General Public License version ohair@286: * 2 along with this work; if not, write to the Free Software Foundation, ohair@286: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ohair@286: * ohair@286: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@286: * or visit www.oracle.com if you need additional information or have any ohair@286: * questions. ohair@286: */ ohair@286: ohair@286: package com.sun.tools.internal.ws.wsdl.parser; ohair@286: ohair@286: import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible; ohair@286: import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensionHandler; ohair@286: import com.sun.tools.internal.ws.resources.WsdlMessages; ohair@286: import com.sun.tools.internal.ws.util.xml.XmlUtil; ohair@286: import com.sun.tools.internal.ws.wscompile.ErrorReceiverFilter; ohair@286: import com.sun.tools.internal.ws.wscompile.WsimportOptions; ohair@286: import com.sun.tools.internal.ws.wsdl.document.Binding; ohair@286: import com.sun.tools.internal.ws.wsdl.document.BindingFault; ohair@286: import com.sun.tools.internal.ws.wsdl.document.BindingInput; ohair@286: import com.sun.tools.internal.ws.wsdl.document.BindingOperation; ohair@286: import com.sun.tools.internal.ws.wsdl.document.BindingOutput; ohair@286: import com.sun.tools.internal.ws.wsdl.document.Definitions; ohair@286: import com.sun.tools.internal.ws.wsdl.document.Documentation; ohair@286: import com.sun.tools.internal.ws.wsdl.document.Fault; ohair@286: import com.sun.tools.internal.ws.wsdl.document.Import; ohair@286: import com.sun.tools.internal.ws.wsdl.document.Input; ohair@286: import com.sun.tools.internal.ws.wsdl.document.Message; ohair@286: import com.sun.tools.internal.ws.wsdl.document.MessagePart; ohair@286: import com.sun.tools.internal.ws.wsdl.document.Operation; ohair@286: import com.sun.tools.internal.ws.wsdl.document.OperationStyle; ohair@286: import com.sun.tools.internal.ws.wsdl.document.Output; ohair@286: import com.sun.tools.internal.ws.wsdl.document.Port; ohair@286: import com.sun.tools.internal.ws.wsdl.document.PortType; ohair@286: import com.sun.tools.internal.ws.wsdl.document.Service; ohair@286: import com.sun.tools.internal.ws.wsdl.document.WSDLConstants; ohair@286: import com.sun.tools.internal.ws.wsdl.document.WSDLDocument; ohair@286: import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBindingsConstants; ohair@286: import com.sun.tools.internal.ws.wsdl.document.schema.SchemaConstants; ohair@286: import com.sun.tools.internal.ws.wsdl.document.schema.SchemaKinds; ohair@286: import com.sun.tools.internal.ws.wsdl.framework.Entity; ohair@286: import com.sun.tools.internal.ws.wsdl.framework.ParserListener; ohair@286: import com.sun.tools.internal.ws.wsdl.framework.TWSDLParserContextImpl; ohair@286: import com.sun.xml.internal.ws.util.ServiceFinder; ohair@286: import org.w3c.dom.Attr; ohair@286: import org.w3c.dom.Document; ohair@286: import org.w3c.dom.Element; ohair@286: import org.w3c.dom.NodeList; ohair@286: import org.xml.sax.InputSource; ohair@286: import org.xml.sax.Locator; ohair@286: import org.xml.sax.SAXException; ohair@286: ohair@286: import java.io.IOException; ohair@286: import java.util.ArrayList; ohair@286: import java.util.HashMap; ohair@286: import java.util.Iterator; ohair@286: import java.util.Map; alanb@368: import org.w3c.dom.Node; ohair@286: ohair@286: /** ohair@286: * A parser for WSDL documents. This parser is used only at the tool time. ohair@286: * Extensions should extend TWSDLExtensionHandler, so that it will be called during ohair@286: * parsing wsdl to handle wsdl extenisbility elements. Generally these extensions ohair@286: * will effect the artifacts generated during WSDL processing. ohair@286: * ohair@286: * @see com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser which will be used for WSDL parsing ohair@286: * at runtime. ohair@286: * ohair@286: * @author WS Development Team ohair@286: */ ohair@286: public class WSDLParser { ohair@286: private final ErrorReceiverFilter errReceiver; ohair@286: private WsimportOptions options; ohair@286: ohair@286: //wsdl extension handlers ohair@286: private final Map extensionHandlers; ohair@286: private MetadataFinder forest; ohair@286: private ArrayList listeners; ohair@286: ohair@286: public WSDLParser(WsimportOptions options, ErrorReceiverFilter errReceiver, MetadataFinder forest) { ohair@286: this.extensionHandlers = new HashMap(); ohair@286: this.options = options; ohair@286: this.errReceiver = errReceiver; ohair@286: if (forest == null) { ohair@286: forest = new MetadataFinder(new WSDLInternalizationLogic(), options, errReceiver); ohair@286: forest.parseWSDL(); alanb@368: if (forest.isMexMetadata) { ohair@286: errReceiver.reset(); ohair@286: } alanb@368: } ohair@286: this.forest = forest; ohair@286: // register handlers for default extensions ohair@286: register(new SOAPExtensionHandler(extensionHandlers)); ohair@286: register(new HTTPExtensionHandler(extensionHandlers)); ohair@286: register(new MIMEExtensionHandler(extensionHandlers)); ohair@286: register(new JAXWSBindingExtensionHandler(extensionHandlers)); ohair@286: register(new SOAP12ExtensionHandler(extensionHandlers)); alanb@368: alanb@368: // MemberSubmission Addressing not supported by WsImport anymore see JAX_WS-1040 for details alanb@368: //register(new MemberSubmissionAddressingExtensionHandler(extensionHandlers, errReceiver, options.isExtensionMode())); alanb@368: ohair@286: register(new W3CAddressingExtensionHandler(extensionHandlers, errReceiver)); ohair@286: register(new W3CAddressingMetadataExtensionHandler(extensionHandlers, errReceiver)); ohair@286: register(new Policy12ExtensionHandler()); ohair@286: register(new Policy15ExtensionHandler()); ohair@286: for (TWSDLExtensionHandler te : ServiceFinder.find(TWSDLExtensionHandler.class)) { ohair@286: register(te); ohair@286: } ohair@286: ohair@286: } ohair@286: ohair@286: //TODO RK remove this after tests are fixed. ohair@286: WSDLParser(WsimportOptions options, ErrorReceiverFilter errReceiver) { ohair@286: this(options,errReceiver,null); ohair@286: } ohair@286: private void register(TWSDLExtensionHandler h) { ohair@286: extensionHandlers.put(h.getNamespaceURI(), h); ohair@286: } ohair@286: ohair@286: public void addParserListener(ParserListener l) { ohair@286: if (listeners == null) { ohair@286: listeners = new ArrayList(); ohair@286: } ohair@286: listeners.add(l); ohair@286: } ohair@286: ohair@286: public WSDLDocument parse() throws SAXException, IOException { ohair@286: // parse external binding files ohair@286: for (InputSource value : options.getWSDLBindings()) { ohair@286: errReceiver.pollAbort(); ohair@286: Document root = forest.parse(value, false); ohair@286: if(root==null) continue; // error must have been reported ohair@286: Element binding = root.getDocumentElement(); alanb@368: if (!Internalizer.fixNull(binding.getNamespaceURI()).equals(JAXWSBindingsConstants.NS_JAXWS_BINDINGS) ohair@286: || !binding.getLocalName().equals("bindings")){ ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(binding), WsdlMessages.PARSER_NOT_A_BINDING_FILE( ohair@286: binding.getNamespaceURI(), ohair@286: binding.getLocalName())); ohair@286: continue; ohair@286: } ohair@286: ohair@286: NodeList nl = binding.getElementsByTagNameNS( ohair@286: "http://java.sun.com/xml/ns/javaee", "handler-chains"); ohair@286: for(int i = 0; i < nl.getLength(); i++){ ohair@286: options.addHandlerChainConfiguration((Element) nl.item(i)); ohair@286: } ohair@286: ohair@286: } ohair@286: return buildWSDLDocument(); ohair@286: } ohair@286: ohair@286: public MetadataFinder getDOMForest() { ohair@286: return forest; ohair@286: } ohair@286: ohair@286: private WSDLDocument buildWSDLDocument(){ ohair@286: /** ohair@286: * Currently we are working off first WSDL document ohair@286: * TODO: add support of creating WSDLDocument from fromjava.collection of WSDL documents ohair@286: */ ohair@286: ohair@286: String location = forest.getRootWSDL(); ohair@286: ohair@286: //It means that WSDL is not found, an error might have been reported, lets try to recover ohair@286: if(location == null) ohair@286: return null; ohair@286: ohair@286: Document root = forest.get(location); ohair@286: ohair@286: if(root == null) ohair@286: return null; ohair@286: ohair@286: WSDLDocument document = new WSDLDocument(forest, errReceiver); ohair@286: document.setSystemId(location); ohair@286: TWSDLParserContextImpl context = new TWSDLParserContextImpl(forest, document, listeners, errReceiver); ohair@286: ohair@286: Definitions definitions = parseDefinitions(context, root); ohair@286: document.setDefinitions(definitions); ohair@286: return document; ohair@286: } ohair@286: ohair@286: private Definitions parseDefinitions(TWSDLParserContextImpl context, Document root) { ohair@286: context.pushWSDLLocation(); ohair@286: context.setWSDLLocation(context.getDocument().getSystemId()); ohair@286: ohair@286: new Internalizer(forest, options, errReceiver).transform(); ohair@286: ohair@286: Definitions definitions = parseDefinitionsNoImport(context, root); ohair@286: if(definitions == null){ ohair@286: Locator locator = forest.locatorTable.getStartLocation(root.getDocumentElement()); ohair@286: errReceiver.error(locator, WsdlMessages.PARSING_NOT_AWSDL(locator.getSystemId())); ohair@286: ohair@286: } ohair@286: processImports(context); ohair@286: context.popWSDLLocation(); ohair@286: return definitions; ohair@286: } ohair@286: ohair@286: private void processImports(TWSDLParserContextImpl context) { ohair@286: for(String location : forest.getExternalReferences()){ ohair@286: if (!context.getDocument().isImportedDocument(location)){ ohair@286: Document doc = forest.get(location); ohair@286: if(doc == null) ohair@286: continue; ohair@286: Definitions importedDefinitions = parseDefinitionsNoImport(context, doc); ohair@286: if(importedDefinitions == null) ohair@286: continue; ohair@286: context.getDocument().addImportedEntity(importedDefinitions); ohair@286: context.getDocument().addImportedDocument(location); ohair@286: } ohair@286: } ohair@286: } ohair@286: ohair@286: private Definitions parseDefinitionsNoImport( ohair@286: TWSDLParserContextImpl context, ohair@286: Document doc) { ohair@286: Element e = doc.getDocumentElement(); ohair@286: //at this poinjt we expect a wsdl or schema document to be fully qualified ohair@286: if(e.getNamespaceURI() == null || (!e.getNamespaceURI().equals(WSDLConstants.NS_WSDL) || !e.getLocalName().equals("definitions"))){ ohair@286: return null; ohair@286: } ohair@286: context.push(); ohair@286: context.registerNamespaces(e); ohair@286: ohair@286: Definitions definitions = new Definitions(context.getDocument(), forest.locatorTable.getStartLocation(e)); ohair@286: String name = XmlUtil.getAttributeOrNull(e, Constants.ATTR_NAME); ohair@286: definitions.setName(name); ohair@286: ohair@286: String targetNamespaceURI = ohair@286: XmlUtil.getAttributeOrNull(e, Constants.ATTR_TARGET_NAMESPACE); ohair@286: ohair@286: definitions.setTargetNamespaceURI(targetNamespaceURI); ohair@286: ohair@286: boolean gotDocumentation = false; ohair@286: boolean gotTypes = false; ohair@286: ohair@286: for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) { ohair@286: Element e2 = Util.nextElement(iter); ohair@286: if (e2 == null) ohair@286: break; ohair@286: ohair@286: if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) { ohair@286: if (gotDocumentation) { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e2), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName())); ohair@286: return null; ohair@286: } ohair@286: gotDocumentation = true; ohair@286: if(definitions.getDocumentation() == null) ohair@286: definitions.setDocumentation(getDocumentationFor(e2)); ohair@286: } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_TYPES)) { ohair@286: if (gotTypes && !options.isExtensionMode()) { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e2), WsdlMessages.PARSING_ONLY_ONE_TYPES_ALLOWED(Constants.TAG_DEFINITIONS)); ohair@286: return null; ohair@286: } ohair@286: gotTypes = true; ohair@286: //add all the wsdl:type elements to latter make a list of all the schema elements ohair@286: // that will be needed to create jaxb model ohair@286: if(!options.isExtensionMode()) ohair@286: validateSchemaImports(e2); ohair@286: } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_MESSAGE)) { ohair@286: Message message = parseMessage(context, definitions, e2); ohair@286: definitions.add(message); ohair@286: } else if ( ohair@286: XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_PORT_TYPE)) { ohair@286: PortType portType = parsePortType(context, definitions, e2); ohair@286: definitions.add(portType); ohair@286: } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_BINDING)) { ohair@286: Binding binding = parseBinding(context, definitions, e2); ohair@286: definitions.add(binding); ohair@286: } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_SERVICE)) { ohair@286: Service service = parseService(context, definitions, e2); ohair@286: definitions.add(service); ohair@286: } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_IMPORT)) { ohair@286: definitions.add(parseImport(context, definitions, e2)); ohair@286: } else if (XmlUtil.matchesTagNS(e2, SchemaConstants.QNAME_IMPORT)) { ohair@286: errReceiver.warning(forest.locatorTable.getStartLocation(e2), WsdlMessages.WARNING_WSI_R_2003()); ohair@286: } else { ohair@286: // possible extensibility element -- must live outside the WSDL namespace ohair@286: checkNotWsdlElement(e2); ohair@286: if (!handleExtension(context, definitions, e2)) { ohair@286: checkNotWsdlRequired(e2); ohair@286: } ohair@286: } ohair@286: } ohair@286: ohair@286: context.pop(); ohair@286: context.fireDoneParsingEntity( ohair@286: WSDLConstants.QNAME_DEFINITIONS, ohair@286: definitions); ohair@286: return definitions; ohair@286: } ohair@286: ohair@286: private Message parseMessage( ohair@286: TWSDLParserContextImpl context, ohair@286: Definitions definitions, ohair@286: Element e) { ohair@286: context.push(); ohair@286: context.registerNamespaces(e); ohair@286: Message message = new Message(definitions, forest.locatorTable.getStartLocation(e), errReceiver); ohair@286: String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME); ohair@286: message.setName(name); ohair@286: ohair@286: boolean gotDocumentation = false; ohair@286: ohair@286: for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) { ohair@286: Element e2 = Util.nextElement(iter); ohair@286: if (e2 == null) ohair@286: break; ohair@286: ohair@286: if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) { ohair@286: if (gotDocumentation) { ohair@286: Util.fail( ohair@286: "parsing.onlyOneDocumentationAllowed", ohair@286: e.getLocalName()); ohair@286: } ohair@286: gotDocumentation = true; ohair@286: message.setDocumentation(getDocumentationFor(e2)); ohair@286: } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_PART)) { ohair@286: MessagePart part = parseMessagePart(context, e2); ohair@286: message.add(part); ohair@286: } else { ohair@286: //Ignore any extensibility elements, WS-I BP 1.1 Profiled WSDL 1.1 schema allows extension elements here. ohair@286: /*Util.fail( ohair@286: "parsing.invalidElement", ohair@286: e2.getTagName(), ohair@286: e2.getNamespaceURI()); ohair@286: */ ohair@286: } ohair@286: } ohair@286: ohair@286: context.pop(); ohair@286: context.fireDoneParsingEntity(WSDLConstants.QNAME_MESSAGE, message); ohair@286: return message; ohair@286: } ohair@286: ohair@286: private MessagePart parseMessagePart(TWSDLParserContextImpl context, Element e) { ohair@286: context.push(); ohair@286: context.registerNamespaces(e); ohair@286: MessagePart part = new MessagePart(forest.locatorTable.getStartLocation(e)); ohair@286: String partName = Util.getRequiredAttribute(e, Constants.ATTR_NAME); ohair@286: part.setName(partName); ohair@286: ohair@286: String elementAttr = ohair@286: XmlUtil.getAttributeOrNull(e, Constants.ATTR_ELEMENT); ohair@286: String typeAttr = XmlUtil.getAttributeOrNull(e, Constants.ATTR_TYPE); ohair@286: ohair@286: if (elementAttr != null) { ohair@286: if (typeAttr != null) { ohair@286: errReceiver.error(context.getLocation(e), WsdlMessages.PARSING_ONLY_ONE_OF_ELEMENT_OR_TYPE_REQUIRED(partName)); ohair@286: ohair@286: } ohair@286: ohair@286: part.setDescriptor(context.translateQualifiedName(context.getLocation(e), elementAttr)); ohair@286: part.setDescriptorKind(SchemaKinds.XSD_ELEMENT); ohair@286: } else if (typeAttr != null) { ohair@286: part.setDescriptor(context.translateQualifiedName(context.getLocation(e), typeAttr)); ohair@286: part.setDescriptorKind(SchemaKinds.XSD_TYPE); ohair@286: } else { ohair@286: // XXX-NOTE - this is wrong; for extensibility purposes, ohair@286: // any attribute can be specified on a element, so ohair@286: // we need to put an extensibility hook here ohair@286: errReceiver.warning(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ELEMENT_OR_TYPE_REQUIRED(partName)); ohair@286: } ohair@286: ohair@286: context.pop(); ohair@286: context.fireDoneParsingEntity(WSDLConstants.QNAME_PART, part); ohair@286: return part; ohair@286: } ohair@286: ohair@286: private PortType parsePortType( ohair@286: TWSDLParserContextImpl context, ohair@286: Definitions definitions, ohair@286: Element e) { ohair@286: context.push(); ohair@286: context.registerNamespaces(e); ohair@286: PortType portType = new PortType(definitions, forest.locatorTable.getStartLocation(e), errReceiver); ohair@286: String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME); ohair@286: portType.setName(name); ohair@286: ohair@286: boolean gotDocumentation = false; ohair@286: ohair@286: for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) { ohair@286: Element e2 = Util.nextElement(iter); ohair@286: if (e2 == null) ohair@286: break; ohair@286: ohair@286: if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) { ohair@286: if (gotDocumentation) { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName())); ohair@286: } ohair@286: gotDocumentation = true; ohair@286: if(portType.getDocumentation() == null) ohair@286: portType.setDocumentation(getDocumentationFor(e2)); ohair@286: } else if ( ohair@286: XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_OPERATION)) { ohair@286: Operation op = parsePortTypeOperation(context, e2); ohair@286: op.setParent(portType); ohair@286: portType.add(op); ohair@286: } else { ohair@286: // possible extensibility element -- must live outside the WSDL namespace ohair@286: checkNotWsdlElement(e2); ohair@286: if (!handleExtension(context, portType, e2)) { ohair@286: checkNotWsdlRequired(e2); ohair@286: } ohair@286: }/*else { ohair@286: Util.fail( ohair@286: "parsing.invalidElement", ohair@286: e2.getTagName(), ohair@286: e2.getNamespaceURI()); ohair@286: }*/ ohair@286: } ohair@286: ohair@286: context.pop(); ohair@286: context.fireDoneParsingEntity(WSDLConstants.QNAME_PORT_TYPE, portType); ohair@286: return portType; ohair@286: } ohair@286: ohair@286: private Operation parsePortTypeOperation( ohair@286: TWSDLParserContextImpl context, ohair@286: Element e) { ohair@286: context.push(); ohair@286: context.registerNamespaces(e); ohair@286: ohair@286: Operation operation = new Operation(forest.locatorTable.getStartLocation(e)); ohair@286: String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME); ohair@286: operation.setName(name); ohair@286: String parameterOrderAttr = ohair@286: XmlUtil.getAttributeOrNull(e, Constants.ATTR_PARAMETER_ORDER); ohair@286: operation.setParameterOrder(parameterOrderAttr); ohair@286: ohair@286: boolean gotDocumentation = false; ohair@286: ohair@286: boolean gotInput = false; ohair@286: boolean gotOutput = false; ohair@286: boolean gotFault = false; ohair@286: boolean inputBeforeOutput = false; ohair@286: ohair@286: for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) { ohair@286: Element e2 = Util.nextElement(iter); ohair@286: if (e2 == null) ohair@286: break; ohair@286: ohair@286: if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) { ohair@286: if (gotDocumentation) { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e2), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e2.getLocalName())); ohair@286: } ohair@286: gotDocumentation = true; ohair@286: if(operation.getDocumentation() == null) ohair@286: operation.setDocumentation(getDocumentationFor(e2)); ohair@286: } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_INPUT)) { ohair@286: if (gotInput) { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_TOO_MANY_ELEMENTS(Constants.TAG_INPUT, ohair@286: Constants.TAG_OPERATION, ohair@286: name)); ohair@286: } ohair@286: ohair@286: context.push(); ohair@286: context.registerNamespaces(e2); ohair@286: Input input = new Input(forest.locatorTable.getStartLocation(e2), errReceiver); ohair@286: input.setParent(operation); ohair@286: String messageAttr = ohair@286: Util.getRequiredAttribute(e2, Constants.ATTR_MESSAGE); ohair@286: input.setMessage(context.translateQualifiedName(context.getLocation(e2), messageAttr)); ohair@286: String nameAttr = ohair@286: XmlUtil.getAttributeOrNull(e2, Constants.ATTR_NAME); ohair@286: input.setName(nameAttr); ohair@286: operation.setInput(input); ohair@286: gotInput = true; ohair@286: if (gotOutput) { ohair@286: inputBeforeOutput = false; ohair@286: } ohair@286: ohair@286: // check for extensiblity attributes ohair@286: for (Iterator iter2 = XmlUtil.getAllAttributes(e2); ohair@286: iter2.hasNext(); ohair@286: ) { ohair@286: Attr e3 = (Attr)iter2.next(); ohair@286: if (e3.getLocalName().equals(Constants.ATTR_MESSAGE) || ohair@286: e3.getLocalName().equals(Constants.ATTR_NAME)) ohair@286: continue; ohair@286: ohair@286: // possible extensibility element -- must live outside the WSDL namespace ohair@286: checkNotWsdlAttribute(e3); alanb@368: handleExtension(context, input, e3, e2); ohair@286: } ohair@286: ohair@286: // verify that there is at most one child element and it is a documentation element ohair@286: boolean gotDocumentation2 = false; ohair@286: for (Iterator iter2 = XmlUtil.getAllChildren(e2); ohair@286: iter2.hasNext(); ohair@286: ) { ohair@286: Element e3 = Util.nextElement(iter2); ohair@286: if (e3 == null) ohair@286: break; ohair@286: ohair@286: if (XmlUtil ohair@286: .matchesTagNS(e3, WSDLConstants.QNAME_DOCUMENTATION)) { ohair@286: if (gotDocumentation2) { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName())); ohair@286: } ohair@286: gotDocumentation2 = true; ohair@286: input.setDocumentation(getDocumentationFor(e3)); ohair@286: } else { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e3), WsdlMessages.PARSING_INVALID_ELEMENT(e3.getTagName(), ohair@286: e3.getNamespaceURI())); ohair@286: } ohair@286: } ohair@286: context.pop(); ohair@286: } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_OUTPUT)) { ohair@286: if (gotOutput) { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_TOO_MANY_ELEMENTS(Constants.TAG_INPUT, ohair@286: Constants.TAG_OPERATION, ohair@286: name)); ohair@286: } ohair@286: ohair@286: context.push(); ohair@286: context.registerNamespaces(e2); ohair@286: Output output = new Output(forest.locatorTable.getStartLocation(e2), errReceiver); ohair@286: output.setParent(operation); ohair@286: String messageAttr = ohair@286: Util.getRequiredAttribute(e2, Constants.ATTR_MESSAGE); ohair@286: output.setMessage(context.translateQualifiedName(context.getLocation(e2), messageAttr)); ohair@286: String nameAttr = ohair@286: XmlUtil.getAttributeOrNull(e2, Constants.ATTR_NAME); ohair@286: output.setName(nameAttr); ohair@286: operation.setOutput(output); ohair@286: gotOutput = true; ohair@286: if (gotInput) { ohair@286: inputBeforeOutput = true; ohair@286: } ohair@286: ohair@286: // check for extensiblity attributes ohair@286: for (Iterator iter2 = XmlUtil.getAllAttributes(e2); ohair@286: iter2.hasNext(); ohair@286: ) { ohair@286: Attr e3 = (Attr)iter2.next(); ohair@286: if (e3.getLocalName().equals(Constants.ATTR_MESSAGE) || ohair@286: e3.getLocalName().equals(Constants.ATTR_NAME)) ohair@286: continue; ohair@286: ohair@286: // possible extensibility element -- must live outside the WSDL namespace ohair@286: checkNotWsdlAttribute(e3); alanb@368: handleExtension(context, output, e3, e2); ohair@286: } ohair@286: ohair@286: // verify that there is at most one child element and it is a documentation element ohair@286: boolean gotDocumentation2 = false; ohair@286: for (Iterator iter2 = XmlUtil.getAllChildren(e2); ohair@286: iter2.hasNext(); ohair@286: ) { ohair@286: Element e3 = Util.nextElement(iter2); ohair@286: if (e3 == null) ohair@286: break; ohair@286: ohair@286: if (XmlUtil ohair@286: .matchesTagNS(e3, WSDLConstants.QNAME_DOCUMENTATION)) { ohair@286: if (gotDocumentation2) { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName())); ohair@286: } ohair@286: gotDocumentation2 = true; ohair@286: output.setDocumentation(getDocumentationFor(e3)); ohair@286: } else { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e3), WsdlMessages.PARSING_INVALID_ELEMENT(e3.getTagName(), ohair@286: e3.getNamespaceURI())); ohair@286: } ohair@286: } ohair@286: context.pop(); ohair@286: } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_FAULT)) { ohair@286: context.push(); ohair@286: context.registerNamespaces(e2); ohair@286: Fault fault = new Fault(forest.locatorTable.getStartLocation(e2)); ohair@286: fault.setParent(operation); ohair@286: String messageAttr = ohair@286: Util.getRequiredAttribute(e2, Constants.ATTR_MESSAGE); ohair@286: fault.setMessage(context.translateQualifiedName(context.getLocation(e2), messageAttr)); ohair@286: String nameAttr = ohair@286: XmlUtil.getAttributeOrNull(e2, Constants.ATTR_NAME); ohair@286: fault.setName(nameAttr); ohair@286: operation.addFault(fault); ohair@286: gotFault = true; ohair@286: ohair@286: // check for extensiblity attributes ohair@286: for (Iterator iter2 = XmlUtil.getAllAttributes(e2); ohair@286: iter2.hasNext(); ohair@286: ) { ohair@286: Attr e3 = (Attr)iter2.next(); ohair@286: if (e3.getLocalName().equals(Constants.ATTR_MESSAGE) || ohair@286: e3.getLocalName().equals(Constants.ATTR_NAME)) ohair@286: continue; ohair@286: ohair@286: // possible extensibility element -- must live outside the WSDL namespace ohair@286: checkNotWsdlAttribute(e3); alanb@368: handleExtension(context, fault, e3, e2); ohair@286: } ohair@286: ohair@286: // verify that there is at most one child element and it is a documentation element ohair@286: boolean gotDocumentation2 = false; ohair@286: for (Iterator iter2 = XmlUtil.getAllChildren(e2); ohair@286: iter2.hasNext(); ohair@286: ) { ohair@286: Element e3 = Util.nextElement(iter2); ohair@286: if (e3 == null) ohair@286: break; ohair@286: ohair@286: if (XmlUtil ohair@286: .matchesTagNS(e3, WSDLConstants.QNAME_DOCUMENTATION)) { ohair@286: if (gotDocumentation2) { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName())); ohair@286: } ohair@286: gotDocumentation2 = true; ohair@286: if(fault.getDocumentation() == null) ohair@286: fault.setDocumentation(getDocumentationFor(e3)); ohair@286: } else { ohair@286: // possible extensibility element -- must live outside the WSDL namespace ohair@286: checkNotWsdlElement(e3); ohair@286: if (!handleExtension(context, fault, e3)) { ohair@286: checkNotWsdlRequired(e3); ohair@286: } ohair@286: }/*else { ohair@286: Util.fail( ohair@286: "parsing.invalidElement", ohair@286: e3.getTagName(), ohair@286: e3.getNamespaceURI()); ohair@286: }*/ ohair@286: } ohair@286: context.pop(); ohair@286: } else { ohair@286: // possible extensibility element -- must live outside the WSDL namespace ohair@286: checkNotWsdlElement(e2); ohair@286: if (!handleExtension(context, operation, e2)) { ohair@286: checkNotWsdlRequired(e2); ohair@286: } ohair@286: }/*else { ohair@286: Util.fail( ohair@286: "parsing.invalidElement", ohair@286: e2.getTagName(), ohair@286: e2.getNamespaceURI()); ohair@286: }*/ ohair@286: } ohair@286: ohair@286: if (gotInput && !gotOutput && !gotFault) { ohair@286: operation.setStyle(OperationStyle.ONE_WAY); ohair@286: } else if (gotInput && gotOutput && inputBeforeOutput) { ohair@286: operation.setStyle(OperationStyle.REQUEST_RESPONSE); ohair@286: } else if (gotInput && gotOutput && !inputBeforeOutput) { ohair@286: operation.setStyle(OperationStyle.SOLICIT_RESPONSE); ohair@286: } else if (gotOutput && !gotInput && !gotFault) { ohair@286: operation.setStyle(OperationStyle.NOTIFICATION); ohair@286: } else { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_INVALID_OPERATION_STYLE(name)); ohair@286: } ohair@286: ohair@286: context.pop(); ohair@286: context.fireDoneParsingEntity(WSDLConstants.QNAME_OPERATION, operation); ohair@286: return operation; ohair@286: } ohair@286: ohair@286: private Binding parseBinding( ohair@286: TWSDLParserContextImpl context, ohair@286: Definitions definitions, ohair@286: Element e) { ohair@286: context.push(); ohair@286: context.registerNamespaces(e); ohair@286: Binding binding = new Binding(definitions, forest.locatorTable.getStartLocation(e), errReceiver); ohair@286: String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME); ohair@286: binding.setName(name); ohair@286: String typeAttr = Util.getRequiredAttribute(e, Constants.ATTR_TYPE); ohair@286: binding.setPortType(context.translateQualifiedName(context.getLocation(e), typeAttr)); ohair@286: ohair@286: boolean gotDocumentation = false; ohair@286: ohair@286: for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) { ohair@286: Element e2 = Util.nextElement(iter); ohair@286: if (e2 == null) ohair@286: break; ohair@286: ohair@286: if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) { ohair@286: if (gotDocumentation) { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName())); ohair@286: } ohair@286: gotDocumentation = true; ohair@286: binding.setDocumentation(getDocumentationFor(e2)); ohair@286: } else if ( ohair@286: XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_OPERATION)) { ohair@286: BindingOperation op = parseBindingOperation(context, e2); ohair@286: binding.add(op); ohair@286: } else { ohair@286: // possible extensibility element -- must live outside the WSDL namespace ohair@286: checkNotWsdlElement(e2); ohair@286: if (!handleExtension(context, binding, e2)) { ohair@286: checkNotWsdlRequired(e2); ohair@286: } ohair@286: } ohair@286: } ohair@286: ohair@286: context.pop(); ohair@286: context.fireDoneParsingEntity(WSDLConstants.QNAME_BINDING, binding); ohair@286: return binding; ohair@286: } ohair@286: ohair@286: private BindingOperation parseBindingOperation( ohair@286: TWSDLParserContextImpl context, ohair@286: Element e) { ohair@286: context.push(); ohair@286: context.registerNamespaces(e); ohair@286: BindingOperation operation = new BindingOperation(forest.locatorTable.getStartLocation(e)); ohair@286: String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME); ohair@286: operation.setName(name); ohair@286: ohair@286: boolean gotDocumentation = false; ohair@286: ohair@286: boolean gotInput = false; ohair@286: boolean gotOutput = false; ohair@286: boolean gotFault = false; ohair@286: boolean inputBeforeOutput = false; ohair@286: ohair@286: for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) { ohair@286: Element e2 = Util.nextElement(iter); ohair@286: if (e2 == null) ohair@286: break; ohair@286: if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) { ohair@286: if (gotDocumentation) { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName())); ohair@286: } ohair@286: gotDocumentation = true; ohair@286: operation.setDocumentation(getDocumentationFor(e2)); ohair@286: } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_INPUT)) { ohair@286: if (gotInput) { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_TOO_MANY_ELEMENTS(Constants.TAG_INPUT, ohair@286: Constants.TAG_OPERATION, ohair@286: name)); ohair@286: } ohair@286: ohair@286: /* Here we check for the use scenario */ ohair@286: context.push(); ohair@286: context.registerNamespaces(e2); ohair@286: BindingInput input = new BindingInput(forest.locatorTable.getStartLocation(e2)); ohair@286: String nameAttr = ohair@286: XmlUtil.getAttributeOrNull(e2, Constants.ATTR_NAME); ohair@286: input.setName(nameAttr); ohair@286: operation.setInput(input); ohair@286: gotInput = true; ohair@286: if (gotOutput) { ohair@286: inputBeforeOutput = false; ohair@286: } ohair@286: ohair@286: // verify that there is at most one child element and it is a documentation element ohair@286: boolean gotDocumentation2 = false; ohair@286: for (Iterator iter2 = XmlUtil.getAllChildren(e2); ohair@286: iter2.hasNext(); ohair@286: ) { ohair@286: Element e3 = Util.nextElement(iter2); ohair@286: if (e3 == null) ohair@286: break; ohair@286: ohair@286: if (XmlUtil ohair@286: .matchesTagNS(e3, WSDLConstants.QNAME_DOCUMENTATION)) { ohair@286: if (gotDocumentation2) { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName())); ohair@286: } ohair@286: gotDocumentation2 = true; ohair@286: input.setDocumentation(getDocumentationFor(e3)); ohair@286: } else { ohair@286: // possible extensibility element -- must live outside the WSDL namespace ohair@286: checkNotWsdlElement(e3); ohair@286: if (!handleExtension(context, input, e3)) { ohair@286: checkNotWsdlRequired(e3); ohair@286: } ohair@286: } ohair@286: } ohair@286: context.pop(); ohair@286: } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_OUTPUT)) { ohair@286: if (gotOutput) { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_TOO_MANY_ELEMENTS(Constants.TAG_INPUT, ohair@286: Constants.TAG_OPERATION, ohair@286: name)); ohair@286: } ohair@286: ohair@286: context.push(); ohair@286: context.registerNamespaces(e2); ohair@286: BindingOutput output = new BindingOutput(forest.locatorTable.getStartLocation(e2)); ohair@286: String nameAttr = ohair@286: XmlUtil.getAttributeOrNull(e2, Constants.ATTR_NAME); ohair@286: output.setName(nameAttr); ohair@286: operation.setOutput(output); ohair@286: gotOutput = true; ohair@286: if (gotInput) { ohair@286: inputBeforeOutput = true; ohair@286: } ohair@286: ohair@286: // verify that there is at most one child element and it is a documentation element ohair@286: boolean gotDocumentation2 = false; ohair@286: for (Iterator iter2 = XmlUtil.getAllChildren(e2); ohair@286: iter2.hasNext(); ohair@286: ) { ohair@286: ohair@286: Element e3 = Util.nextElement(iter2); ohair@286: if (e3 == null) ohair@286: break; ohair@286: ohair@286: if (XmlUtil ohair@286: .matchesTagNS(e3, WSDLConstants.QNAME_DOCUMENTATION)) { ohair@286: if (gotDocumentation2) { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName())); ohair@286: } ohair@286: gotDocumentation2 = true; ohair@286: output.setDocumentation(getDocumentationFor(e3)); ohair@286: } else { ohair@286: // possible extensibility element -- must live outside the WSDL namespace ohair@286: checkNotWsdlElement(e3); ohair@286: if (!handleExtension(context, output, e3)) { ohair@286: checkNotWsdlRequired(e3); ohair@286: } ohair@286: } ohair@286: } ohair@286: context.pop(); ohair@286: } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_FAULT)) { ohair@286: context.push(); ohair@286: context.registerNamespaces(e2); ohair@286: BindingFault fault = new BindingFault(forest.locatorTable.getStartLocation(e2)); ohair@286: String nameAttr = ohair@286: Util.getRequiredAttribute(e2, Constants.ATTR_NAME); ohair@286: fault.setName(nameAttr); ohair@286: operation.addFault(fault); ohair@286: gotFault = true; ohair@286: ohair@286: // verify that there is at most one child element and it is a documentation element ohair@286: boolean gotDocumentation2 = false; ohair@286: for (Iterator iter2 = XmlUtil.getAllChildren(e2); ohair@286: iter2.hasNext(); ohair@286: ) { ohair@286: Element e3 = Util.nextElement(iter2); ohair@286: if (e3 == null) ohair@286: break; ohair@286: ohair@286: if (XmlUtil ohair@286: .matchesTagNS(e3, WSDLConstants.QNAME_DOCUMENTATION)) { ohair@286: if (gotDocumentation2) { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName())); ohair@286: } ohair@286: gotDocumentation2 = true; ohair@286: if(fault.getDocumentation() == null) ohair@286: fault.setDocumentation(getDocumentationFor(e3)); ohair@286: } else { ohair@286: // possible extensibility element -- must live outside the WSDL namespace ohair@286: checkNotWsdlElement(e3); ohair@286: if (!handleExtension(context, fault, e3)) { ohair@286: checkNotWsdlRequired(e3); ohair@286: } ohair@286: } ohair@286: } ohair@286: context.pop(); ohair@286: } else { ohair@286: // possible extensibility element -- must live outside the WSDL namespace ohair@286: checkNotWsdlElement(e2); ohair@286: if (!handleExtension(context, operation, e2)) { ohair@286: checkNotWsdlRequired(e2); ohair@286: } ohair@286: } ohair@286: } ohair@286: ohair@286: if (gotInput && !gotOutput && !gotFault) { ohair@286: operation.setStyle(OperationStyle.ONE_WAY); ohair@286: } else if (gotInput && gotOutput && inputBeforeOutput) { ohair@286: operation.setStyle(OperationStyle.REQUEST_RESPONSE); ohair@286: } else if (gotInput && gotOutput && !inputBeforeOutput) { ohair@286: operation.setStyle(OperationStyle.SOLICIT_RESPONSE); ohair@286: } else if (gotOutput && !gotInput && !gotFault) { ohair@286: operation.setStyle(OperationStyle.NOTIFICATION); ohair@286: } else { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_INVALID_OPERATION_STYLE(name)); ohair@286: } ohair@286: ohair@286: context.pop(); ohair@286: context.fireDoneParsingEntity(WSDLConstants.QNAME_OPERATION, operation); ohair@286: return operation; ohair@286: } ohair@286: ohair@286: private Import parseImport( ohair@286: TWSDLParserContextImpl context, ohair@286: Definitions definitions, ohair@286: Element e) { ohair@286: context.push(); ohair@286: context.registerNamespaces(e); ohair@286: Import anImport = new Import(forest.locatorTable.getStartLocation(e)); ohair@286: String namespace = ohair@286: Util.getRequiredAttribute(e, Constants.ATTR_NAMESPACE); ohair@286: anImport.setNamespace(namespace); ohair@286: String location = Util.getRequiredAttribute(e, Constants.ATTR_LOCATION); ohair@286: anImport.setLocation(location); ohair@286: ohair@286: // according to the schema in the WSDL 1.1 spec, an import can have a documentation element ohair@286: boolean gotDocumentation = false; ohair@286: ohair@286: for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) { ohair@286: Element e2 = Util.nextElement(iter); ohair@286: if (e2 == null) ohair@286: break; ohair@286: ohair@286: if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) { ohair@286: if (gotDocumentation) { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName())); ohair@286: } ohair@286: gotDocumentation = true; ohair@286: anImport.setDocumentation(getDocumentationFor(e2)); ohair@286: } else { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e2), WsdlMessages.PARSING_INVALID_ELEMENT(e2.getTagName(), ohair@286: e2.getNamespaceURI())); ohair@286: } ohair@286: } ohair@286: context.pop(); ohair@286: context.fireDoneParsingEntity(WSDLConstants.QNAME_IMPORT, anImport); ohair@286: return anImport; ohair@286: } ohair@286: ohair@286: private Service parseService( ohair@286: TWSDLParserContextImpl context, ohair@286: Definitions definitions, ohair@286: Element e) { ohair@286: context.push(); ohair@286: context.registerNamespaces(e); ohair@286: Service service = new Service(definitions, forest.locatorTable.getStartLocation(e), errReceiver); ohair@286: String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME); ohair@286: service.setName(name); ohair@286: ohair@286: boolean gotDocumentation = false; ohair@286: ohair@286: for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) { ohair@286: Element e2 = Util.nextElement(iter); ohair@286: if (e2 == null) ohair@286: break; ohair@286: ohair@286: if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) { ohair@286: if (gotDocumentation) { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName())); ohair@286: } ohair@286: gotDocumentation = true; alanb@368: if (service.getDocumentation() == null) { ohair@286: service.setDocumentation(getDocumentationFor(e2)); alanb@368: } ohair@286: } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_PORT)) { ohair@286: Port port = parsePort(context, definitions, e2); ohair@286: service.add(port); ohair@286: } else { ohair@286: // possible extensibility element -- must live outside the WSDL namespace ohair@286: checkNotWsdlElement(e2); ohair@286: if (!handleExtension(context, service, e2)) { ohair@286: checkNotWsdlRequired(e2); ohair@286: } ohair@286: } ohair@286: } ohair@286: ohair@286: context.pop(); ohair@286: context.fireDoneParsingEntity(WSDLConstants.QNAME_SERVICE, service); ohair@286: return service; ohair@286: } ohair@286: ohair@286: private Port parsePort( ohair@286: TWSDLParserContextImpl context, ohair@286: Definitions definitions, ohair@286: Element e) { ohair@286: context.push(); ohair@286: context.registerNamespaces(e); ohair@286: ohair@286: Port port = new Port(definitions, forest.locatorTable.getStartLocation(e), errReceiver); ohair@286: String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME); ohair@286: port.setName(name); ohair@286: ohair@286: String bindingAttr = ohair@286: Util.getRequiredAttribute(e, Constants.ATTR_BINDING); ohair@286: port.setBinding(context.translateQualifiedName(context.getLocation(e), bindingAttr)); ohair@286: ohair@286: boolean gotDocumentation = false; ohair@286: ohair@286: for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) { ohair@286: Element e2 = Util.nextElement(iter); alanb@368: if (e2 == null) { ohair@286: break; alanb@368: } ohair@286: ohair@286: if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) { ohair@286: if (gotDocumentation) { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName())); ohair@286: } ohair@286: gotDocumentation = true; alanb@368: if (port.getDocumentation() == null) { ohair@286: port.setDocumentation(getDocumentationFor(e2)); alanb@368: } ohair@286: } else { ohair@286: // possible extensibility element -- must live outside the WSDL namespace ohair@286: checkNotWsdlElement(e2); ohair@286: if (!handleExtension(context, port, e2)) { ohair@286: checkNotWsdlRequired(e2); ohair@286: } ohair@286: } ohair@286: } ohair@286: ohair@286: context.pop(); ohair@286: context.fireDoneParsingEntity(WSDLConstants.QNAME_PORT, port); ohair@286: return port; ohair@286: } ohair@286: ohair@286: private void validateSchemaImports(Element typesElement){ ohair@286: for (Iterator iter = XmlUtil.getAllChildren(typesElement); iter.hasNext();) { ohair@286: Element e = Util.nextElement(iter); alanb@368: if (e == null) { ohair@286: break; alanb@368: } ohair@286: if (XmlUtil.matchesTagNS(e, SchemaConstants.QNAME_IMPORT)) { ohair@286: errReceiver.warning(forest.locatorTable.getStartLocation(e), WsdlMessages.WARNING_WSI_R_2003()); ohair@286: }else{ ohair@286: checkNotWsdlElement(e); ohair@286: // if (XmlUtil.matchesTagNS(e, SchemaConstants.QNAME_SCHEMA)) { ohair@286: // forest.getInlinedSchemaElement().add(e); ohair@286: // } ohair@286: ohair@286: } ohair@286: } ohair@286: } ohair@286: ohair@286: ohair@286: private boolean handleExtension( ohair@286: TWSDLParserContextImpl context, ohair@286: TWSDLExtensible entity, ohair@286: Element e) { ohair@286: TWSDLExtensionHandler h = ohair@286: (TWSDLExtensionHandler) extensionHandlers.get(e.getNamespaceURI()); ohair@286: if (h == null) { ohair@286: context.fireIgnoringExtension(e, (Entity) entity); alanb@368: errReceiver.warning(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_UNKNOWN_EXTENSIBILITY_ELEMENT_OR_ATTRIBUTE(e.getLocalName(), e.getNamespaceURI())); ohair@286: return false; ohair@286: } else { ohair@286: return h.doHandleExtension(context, entity, e); ohair@286: } ohair@286: } ohair@286: ohair@286: private boolean handleExtension( ohair@286: TWSDLParserContextImpl context, ohair@286: TWSDLExtensible entity, ohair@286: Node n, ohair@286: Element e) { ohair@286: TWSDLExtensionHandler h = ohair@286: (TWSDLExtensionHandler) extensionHandlers.get(n.getNamespaceURI()); ohair@286: if (h == null) { ohair@286: context.fireIgnoringExtension(e, (Entity) entity); alanb@368: errReceiver.warning(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_UNKNOWN_EXTENSIBILITY_ELEMENT_OR_ATTRIBUTE(n.getLocalName(), n.getNamespaceURI())); ohair@286: return false; ohair@286: } else { ohair@286: return h.doHandleExtension(context, entity, e); ohair@286: } ohair@286: } ohair@286: ohair@286: private void checkNotWsdlElement(Element e) { ohair@286: // possible extensibility element -- must live outside the WSDL namespace alanb@368: if (e.getNamespaceURI() != null && e.getNamespaceURI().equals(Constants.NS_WSDL)) { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_INVALID_WSDL_ELEMENT(e.getTagName())); ohair@286: } alanb@368: } ohair@286: ohair@286: private void checkNotWsdlAttribute(Attr a) { ohair@286: // possible extensibility element -- must live outside the WSDL namespace alanb@368: if (Constants.NS_WSDL.equals(a.getNamespaceURI())) { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(a.getOwnerElement()), WsdlMessages.PARSING_INVALID_WSDL_ELEMENT(a.getLocalName())); ohair@286: } alanb@368: } ohair@286: ohair@286: private void checkNotWsdlRequired(Element e) { ohair@286: // check the wsdl:required attribute, fail if set to "true" ohair@286: String required = ohair@286: XmlUtil.getAttributeNSOrNull( ohair@286: e, ohair@286: Constants.ATTR_REQUIRED, ohair@286: Constants.NS_WSDL); ohair@286: if (required != null && required.equals(Constants.TRUE) && !options.isExtensionMode()) { ohair@286: errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_REQUIRED_EXTENSIBILITY_ELEMENT(e.getTagName(), ohair@286: e.getNamespaceURI())); ohair@286: } ohair@286: } ohair@286: ohair@286: private Documentation getDocumentationFor(Element e) { ohair@286: String s = XmlUtil.getTextForNode(e); ohair@286: if (s == null) { ohair@286: return null; ohair@286: } else { ohair@286: return new Documentation(s); ohair@286: } ohair@286: } ohair@286: }