aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.xml.internal.ws.wsdl.parser; aoqi@0: aoqi@0: import com.sun.xml.internal.ws.api.addressing.AddressingVersion; aoqi@0: import com.sun.xml.internal.ws.api.model.wsdl.WSDLFeaturedObject; aoqi@0: import static com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation.ANONYMOUS; aoqi@0: import com.sun.xml.internal.ws.api.model.wsdl.editable.*; aoqi@0: import com.sun.xml.internal.ws.api.wsdl.parser.WSDLParserExtension; aoqi@0: import com.sun.xml.internal.ws.api.wsdl.parser.WSDLParserExtensionContext; aoqi@0: import com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil; aoqi@0: aoqi@0: import javax.xml.namespace.QName; aoqi@0: import javax.xml.stream.XMLStreamException; aoqi@0: import javax.xml.stream.XMLStreamReader; aoqi@0: import javax.xml.ws.WebServiceException; aoqi@0: import javax.xml.ws.soap.AddressingFeature; aoqi@0: aoqi@0: /** aoqi@0: * W3C WS-Addressing Runtime WSDL parser extension aoqi@0: * aoqi@0: * @author Arun Gupta aoqi@0: */ aoqi@0: public class W3CAddressingWSDLParserExtension extends WSDLParserExtension { aoqi@0: @Override aoqi@0: public boolean bindingElements(EditableWSDLBoundPortType binding, XMLStreamReader reader) { aoqi@0: return addressibleElement(reader, binding); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public boolean portElements(EditableWSDLPort port, XMLStreamReader reader) { aoqi@0: return addressibleElement(reader, port); aoqi@0: } aoqi@0: aoqi@0: private boolean addressibleElement(XMLStreamReader reader, WSDLFeaturedObject binding) { aoqi@0: QName ua = reader.getName(); aoqi@0: if (ua.equals(AddressingVersion.W3C.wsdlExtensionTag)) { aoqi@0: String required = reader.getAttributeValue(WSDLConstants.NS_WSDL, "required"); aoqi@0: binding.addFeature(new AddressingFeature(true, Boolean.parseBoolean(required))); aoqi@0: XMLStreamReaderUtil.skipElement(reader); aoqi@0: return true; // UsingAddressing is consumed aoqi@0: } aoqi@0: aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public boolean bindingOperationElements(EditableWSDLBoundOperation operation, XMLStreamReader reader) { aoqi@0: EditableWSDLBoundOperation edit = (EditableWSDLBoundOperation) operation; aoqi@0: aoqi@0: QName anon = reader.getName(); aoqi@0: if (anon.equals(AddressingVersion.W3C.wsdlAnonymousTag)) { aoqi@0: try { aoqi@0: String value = reader.getElementText(); aoqi@0: if (value == null || value.trim().equals("")) { aoqi@0: throw new WebServiceException("Null values not permitted in wsaw:Anonymous."); aoqi@0: // TODO: throw exception only if wsdl:required=true aoqi@0: // TODO: is this the right exception ? aoqi@0: } else if (value.equals("optional")) { aoqi@0: edit.setAnonymous(ANONYMOUS.optional); aoqi@0: } else if (value.equals("required")) { aoqi@0: edit.setAnonymous(ANONYMOUS.required); aoqi@0: } else if (value.equals("prohibited")) { aoqi@0: edit.setAnonymous(ANONYMOUS.prohibited); aoqi@0: } else { aoqi@0: throw new WebServiceException("wsaw:Anonymous value \"" + value + "\" not understood."); aoqi@0: // TODO: throw exception only if wsdl:required=true aoqi@0: // TODO: is this the right exception ? aoqi@0: } aoqi@0: } catch (XMLStreamException e) { aoqi@0: throw new WebServiceException(e); // TODO: is this the correct behavior ? aoqi@0: } aoqi@0: aoqi@0: return true; // consumed the element aoqi@0: } aoqi@0: aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: public void portTypeOperationInputAttributes(EditableWSDLInput input, XMLStreamReader reader) { aoqi@0: String action = ParserUtil.getAttribute(reader, getWsdlActionTag()); aoqi@0: if (action != null) { aoqi@0: input.setAction(action); aoqi@0: input.setDefaultAction(false); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: public void portTypeOperationOutputAttributes(EditableWSDLOutput output, XMLStreamReader reader) { aoqi@0: String action = ParserUtil.getAttribute(reader, getWsdlActionTag()); aoqi@0: if (action != null) { aoqi@0: output.setAction(action); aoqi@0: output.setDefaultAction(false); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: public void portTypeOperationFaultAttributes(EditableWSDLFault fault, XMLStreamReader reader) { aoqi@0: String action = ParserUtil.getAttribute(reader, getWsdlActionTag()); aoqi@0: if (action != null) { aoqi@0: fault.setAction(action); aoqi@0: fault.setDefaultAction(false); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Process wsdl:portType operation after the entire WSDL model has been populated. aoqi@0: * The task list includes:
aoqi@0: *