ohair@286: /* mkos@408: * 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.xml.internal.ws.wsdl.parser; ohair@286: ohair@286: import com.sun.xml.internal.ws.api.wsdl.parser.WSDLParserExtension; ohair@286: import com.sun.xml.internal.ws.api.wsdl.parser.WSDLParserExtensionContext; mkos@408: import com.sun.xml.internal.ws.api.model.wsdl.editable.*; ohair@286: import com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil; ohair@286: ohair@286: import javax.xml.stream.XMLStreamReader; ohair@286: import javax.xml.stream.Location; ohair@286: ohair@286: import org.xml.sax.Locator; ohair@286: import org.xml.sax.helpers.LocatorImpl; ohair@286: ohair@286: /** ohair@286: * {@link WSDLParserExtension} that delegates to ohair@286: * multiple {@link WSDLParserExtension}s. ohair@286: * ohair@286: *

ohair@286: * This simplifies {@link RuntimeWSDLParser} since it now ohair@286: * only needs to work with one {@link WSDLParserExtension}. ohair@286: * ohair@286: *

ohair@286: * This class is guaranteed to return true from ohair@286: * all the extension callback methods. ohair@286: * ohair@286: * @author Kohsuke Kawaguchi ohair@286: */ ohair@286: final class WSDLParserExtensionFacade extends WSDLParserExtension { ohair@286: private final WSDLParserExtension[] extensions; ohair@286: ohair@286: WSDLParserExtensionFacade(WSDLParserExtension... extensions) { ohair@286: assert extensions!=null; ohair@286: this.extensions = extensions; ohair@286: } ohair@286: ohair@286: public void start(WSDLParserExtensionContext context) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: e.start(context); ohair@286: } ohair@286: } ohair@286: mkos@408: public boolean serviceElements(EditableWSDLService service, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: if(e.serviceElements(service,reader)) ohair@286: return true; ohair@286: } ohair@286: XMLStreamReaderUtil.skipElement(reader); ohair@286: return true; ohair@286: } ohair@286: mkos@408: public void serviceAttributes(EditableWSDLService service, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) ohair@286: e.serviceAttributes(service,reader); ohair@286: } ohair@286: mkos@408: public boolean portElements(EditableWSDLPort port, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: if(e.portElements(port,reader)) ohair@286: return true; ohair@286: } ohair@286: //extension is not understood by any WSDlParserExtension ohair@286: //Check if it must be understood. ohair@286: if(isRequiredExtension(reader)) { mkos@408: port.addNotUnderstoodExtension(reader.getName(),getLocator(reader)); ohair@286: } ohair@286: XMLStreamReaderUtil.skipElement(reader); ohair@286: return true; ohair@286: } ohair@286: mkos@408: public boolean portTypeOperationInput(EditableWSDLOperation op, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) ohair@286: e.portTypeOperationInput(op,reader); ohair@286: ohair@286: return false; ohair@286: } ohair@286: mkos@408: public boolean portTypeOperationOutput(EditableWSDLOperation op, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) ohair@286: e.portTypeOperationOutput(op,reader); ohair@286: ohair@286: return false; ohair@286: } ohair@286: mkos@408: public boolean portTypeOperationFault(EditableWSDLOperation op, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) ohair@286: e.portTypeOperationFault(op,reader); ohair@286: ohair@286: return false; ohair@286: } ohair@286: mkos@408: public void portAttributes(EditableWSDLPort port, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) ohair@286: e.portAttributes(port,reader); ohair@286: } ohair@286: ohair@286: public boolean definitionsElements(XMLStreamReader reader){ ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: if (e.definitionsElements(reader)) { ohair@286: return true; ohair@286: } ohair@286: } ohair@286: XMLStreamReaderUtil.skipElement(reader); ohair@286: return true; ohair@286: } ohair@286: mkos@408: public boolean bindingElements(EditableWSDLBoundPortType binding, XMLStreamReader reader){ ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: if (e.bindingElements(binding, reader)) { ohair@286: return true; ohair@286: } ohair@286: } ohair@286: //extension is not understood by any WSDlParserExtension ohair@286: //Check if it must be understood. ohair@286: if (isRequiredExtension(reader)) { mkos@408: binding.addNotUnderstoodExtension( ohair@286: reader.getName(), getLocator(reader)); ohair@286: } ohair@286: XMLStreamReaderUtil.skipElement(reader); ohair@286: return true; ohair@286: } ohair@286: mkos@408: public void bindingAttributes(EditableWSDLBoundPortType binding, XMLStreamReader reader){ ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: e.bindingAttributes(binding, reader); ohair@286: } ohair@286: } ohair@286: mkos@408: public boolean portTypeElements(EditableWSDLPortType portType, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: if (e.portTypeElements(portType, reader)) { ohair@286: return true; ohair@286: } ohair@286: } ohair@286: XMLStreamReaderUtil.skipElement(reader); ohair@286: return true; ohair@286: } ohair@286: mkos@408: public void portTypeAttributes(EditableWSDLPortType portType, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: e.portTypeAttributes(portType, reader); ohair@286: } ohair@286: } ohair@286: mkos@408: public boolean portTypeOperationElements(EditableWSDLOperation operation, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: if (e.portTypeOperationElements(operation, reader)) { ohair@286: return true; ohair@286: } ohair@286: } ohair@286: XMLStreamReaderUtil.skipElement(reader); ohair@286: return true; ohair@286: } ohair@286: mkos@408: public void portTypeOperationAttributes(EditableWSDLOperation operation, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: e.portTypeOperationAttributes(operation, reader); ohair@286: } ohair@286: } ohair@286: mkos@408: public boolean bindingOperationElements(EditableWSDLBoundOperation operation, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: if (e.bindingOperationElements(operation, reader)) { ohair@286: return true; ohair@286: } ohair@286: } ohair@286: XMLStreamReaderUtil.skipElement(reader); ohair@286: return true; ohair@286: } ohair@286: mkos@408: public void bindingOperationAttributes(EditableWSDLBoundOperation operation, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: e.bindingOperationAttributes(operation, reader); ohair@286: } ohair@286: } ohair@286: mkos@408: public boolean messageElements(EditableWSDLMessage msg, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: if (e.messageElements(msg, reader)) { ohair@286: return true; ohair@286: } ohair@286: } ohair@286: XMLStreamReaderUtil.skipElement(reader); ohair@286: return true; ohair@286: } ohair@286: mkos@408: public void messageAttributes(EditableWSDLMessage msg, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: e.messageAttributes(msg, reader); ohair@286: } ohair@286: } ohair@286: mkos@408: public boolean portTypeOperationInputElements(EditableWSDLInput input, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: if (e.portTypeOperationInputElements(input, reader)) { ohair@286: return true; ohair@286: } ohair@286: } ohair@286: XMLStreamReaderUtil.skipElement(reader); ohair@286: return true; ohair@286: } ohair@286: mkos@408: public void portTypeOperationInputAttributes(EditableWSDLInput input, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: e.portTypeOperationInputAttributes(input, reader); ohair@286: } ohair@286: } ohair@286: mkos@408: public boolean portTypeOperationOutputElements(EditableWSDLOutput output, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: if (e.portTypeOperationOutputElements(output, reader)) { ohair@286: return true; ohair@286: } ohair@286: } ohair@286: XMLStreamReaderUtil.skipElement(reader); ohair@286: return true; ohair@286: } ohair@286: mkos@408: public void portTypeOperationOutputAttributes(EditableWSDLOutput output, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: e.portTypeOperationOutputAttributes(output, reader); ohair@286: } ohair@286: } ohair@286: mkos@408: public boolean portTypeOperationFaultElements(EditableWSDLFault fault, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: if (e.portTypeOperationFaultElements(fault, reader)) { ohair@286: return true; ohair@286: } ohair@286: } ohair@286: XMLStreamReaderUtil.skipElement(reader); ohair@286: return true; ohair@286: } ohair@286: mkos@408: public void portTypeOperationFaultAttributes(EditableWSDLFault fault, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: e.portTypeOperationFaultAttributes(fault, reader); ohair@286: } ohair@286: } ohair@286: mkos@408: public boolean bindingOperationInputElements(EditableWSDLBoundOperation operation, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: if (e.bindingOperationInputElements(operation, reader)) { ohair@286: return true; ohair@286: } ohair@286: } ohair@286: XMLStreamReaderUtil.skipElement(reader); ohair@286: return true; ohair@286: } ohair@286: mkos@408: public void bindingOperationInputAttributes(EditableWSDLBoundOperation operation, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: e.bindingOperationInputAttributes(operation, reader); ohair@286: } ohair@286: } ohair@286: mkos@408: public boolean bindingOperationOutputElements(EditableWSDLBoundOperation operation, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: if (e.bindingOperationOutputElements(operation, reader)) { ohair@286: return true; ohair@286: } ohair@286: } ohair@286: XMLStreamReaderUtil.skipElement(reader); ohair@286: return true; ohair@286: } ohair@286: mkos@408: public void bindingOperationOutputAttributes(EditableWSDLBoundOperation operation, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: e.bindingOperationOutputAttributes(operation, reader); ohair@286: } ohair@286: } ohair@286: mkos@408: public boolean bindingOperationFaultElements(EditableWSDLBoundFault fault, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: if (e.bindingOperationFaultElements(fault, reader)) { ohair@286: return true; ohair@286: } ohair@286: } ohair@286: XMLStreamReaderUtil.skipElement(reader); ohair@286: return true; ohair@286: } ohair@286: mkos@408: public void bindingOperationFaultAttributes(EditableWSDLBoundFault fault, XMLStreamReader reader) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: e.bindingOperationFaultAttributes(fault, reader); ohair@286: } ohair@286: } ohair@286: ohair@286: public void finished(WSDLParserExtensionContext context) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: e.finished(context); ohair@286: } ohair@286: } ohair@286: ohair@286: public void postFinished(WSDLParserExtensionContext context) { ohair@286: for (WSDLParserExtension e : extensions) { ohair@286: e.postFinished(context); ohair@286: } ohair@286: } ohair@286: /** ohair@286: * ohair@286: * @param reader ohair@286: * @return If the element has wsdl:required attribute set to true ohair@286: */ ohair@286: ohair@286: private boolean isRequiredExtension(XMLStreamReader reader) { ohair@286: String required = reader.getAttributeValue(WSDLConstants.NS_WSDL, "required"); ohair@286: if(required != null) ohair@286: return Boolean.parseBoolean(required); ohair@286: return false; ohair@286: } ohair@286: ohair@286: private Locator getLocator(XMLStreamReader reader) { ohair@286: Location location = reader.getLocation(); ohair@286: LocatorImpl loc = new LocatorImpl(); ohair@286: loc.setSystemId(location.getSystemId()); ohair@286: loc.setLineNumber(location.getLineNumber()); ohair@286: return loc; ohair@286: } ohair@286: ohair@286: }