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.model.wsdl; aoqi@0: aoqi@0: import com.sun.xml.internal.ws.api.model.wsdl.WSDLExtensible; aoqi@0: import com.sun.xml.internal.ws.api.model.wsdl.WSDLExtension; aoqi@0: import com.sun.xml.internal.ws.api.model.wsdl.WSDLObject; aoqi@0: import com.sun.xml.internal.ws.resources.UtilMessages; aoqi@0: import com.sun.istack.internal.NotNull; aoqi@0: aoqi@0: import javax.xml.stream.XMLStreamReader; aoqi@0: import javax.xml.namespace.QName; aoqi@0: import javax.xml.ws.WebServiceException; aoqi@0: import java.util.ArrayList; aoqi@0: import java.util.HashSet; aoqi@0: import java.util.List; aoqi@0: import java.util.Set; aoqi@0: aoqi@0: import org.xml.sax.Locator; aoqi@0: aoqi@0: /** aoqi@0: * All the WSDL 1.1 elements that are extensible should subclass from this abstract implementation of aoqi@0: * {@link WSDLExtensible} interface. aoqi@0: * aoqi@0: * @author Vivek Pandey aoqi@0: * @author Kohsuke Kawaguchi aoqi@0: */ aoqi@0: abstract class AbstractExtensibleImpl extends AbstractObjectImpl implements WSDLExtensible { aoqi@0: protected final Set extensions = new HashSet(); aoqi@0: // this captures any wsdl extensions that are not understood by WSDLExtensionParsers aoqi@0: // and have wsdl:required=true aoqi@0: protected List notUnderstoodExtensions = aoqi@0: new ArrayList(); aoqi@0: aoqi@0: protected AbstractExtensibleImpl(XMLStreamReader xsr) { aoqi@0: super(xsr); aoqi@0: } aoqi@0: aoqi@0: protected AbstractExtensibleImpl(String systemId, int lineNumber) { aoqi@0: super(systemId, lineNumber); aoqi@0: } aoqi@0: aoqi@0: public final Iterable getExtensions() { aoqi@0: return extensions; aoqi@0: } aoqi@0: aoqi@0: public final Iterable getExtensions(Class type) { aoqi@0: // TODO: this is a rather stupid implementation aoqi@0: List r = new ArrayList(extensions.size()); aoqi@0: for (WSDLExtension e : extensions) { aoqi@0: if(type.isInstance(e)) aoqi@0: r.add(type.cast(e)); aoqi@0: } aoqi@0: return r; aoqi@0: } aoqi@0: aoqi@0: public T getExtension(Class type) { aoqi@0: for (WSDLExtension e : extensions) { aoqi@0: if(type.isInstance(e)) aoqi@0: return type.cast(e); aoqi@0: } aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: public void addExtension(WSDLExtension ex) { aoqi@0: if(ex==null) aoqi@0: // I don't trust plugins. So let's always check it, instead of making this an assertion aoqi@0: throw new IllegalArgumentException(); aoqi@0: extensions.add(ex); aoqi@0: } aoqi@0: aoqi@0: public List getNotUnderstoodExtensions() { aoqi@0: return notUnderstoodExtensions; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * This can be used if a WSDL extension element that has wsdl:required=true aoqi@0: * is not understood aoqi@0: * @param extnEl aoqi@0: * @param locator aoqi@0: */ aoqi@0: public void addNotUnderstoodExtension(QName extnEl, Locator locator) { aoqi@0: notUnderstoodExtensions.add(new UnknownWSDLExtension(extnEl, locator)); aoqi@0: } aoqi@0: aoqi@0: protected static class UnknownWSDLExtension implements WSDLExtension, WSDLObject { aoqi@0: private final QName extnEl; aoqi@0: private final Locator locator; aoqi@0: public UnknownWSDLExtension(QName extnEl, Locator locator) { aoqi@0: this.extnEl = extnEl; aoqi@0: this.locator = locator; aoqi@0: } aoqi@0: public QName getName() { aoqi@0: return extnEl; aoqi@0: } aoqi@0: @NotNull public Locator getLocation() { aoqi@0: return locator; aoqi@0: } aoqi@0: public String toString(){ aoqi@0: return extnEl + " "+ UtilMessages.UTIL_LOCATION( locator.getLineNumber(), locator.getSystemId()); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * This method should be called after freezing the WSDLModel aoqi@0: * @return true if all wsdl required extensions on Port and Binding are understood aoqi@0: */ aoqi@0: public boolean areRequiredExtensionsUnderstood() { aoqi@0: if (notUnderstoodExtensions.size() != 0) { aoqi@0: StringBuilder buf = new StringBuilder("Unknown WSDL extensibility elements:"); aoqi@0: for (UnknownWSDLExtension extn : notUnderstoodExtensions) aoqi@0: buf.append('\n').append(extn.toString()); aoqi@0: throw new WebServiceException(buf.toString()); aoqi@0: } aoqi@0: return true; aoqi@0: } aoqi@0: }