1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/model/wsdl/AbstractExtensibleImpl.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,140 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.ws.model.wsdl; 1.30 + 1.31 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLExtensible; 1.32 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLExtension; 1.33 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLObject; 1.34 +import com.sun.xml.internal.ws.resources.UtilMessages; 1.35 +import com.sun.istack.internal.NotNull; 1.36 + 1.37 +import javax.xml.stream.XMLStreamReader; 1.38 +import javax.xml.namespace.QName; 1.39 +import javax.xml.ws.WebServiceException; 1.40 +import java.util.ArrayList; 1.41 +import java.util.HashSet; 1.42 +import java.util.List; 1.43 +import java.util.Set; 1.44 + 1.45 +import org.xml.sax.Locator; 1.46 + 1.47 +/** 1.48 + * All the WSDL 1.1 elements that are extensible should subclass from this abstract implementation of 1.49 + * {@link WSDLExtensible} interface. 1.50 + * 1.51 + * @author Vivek Pandey 1.52 + * @author Kohsuke Kawaguchi 1.53 + */ 1.54 +abstract class AbstractExtensibleImpl extends AbstractObjectImpl implements WSDLExtensible { 1.55 + protected final Set<WSDLExtension> extensions = new HashSet<WSDLExtension>(); 1.56 + // this captures any wsdl extensions that are not understood by WSDLExtensionParsers 1.57 + // and have wsdl:required=true 1.58 + protected List<UnknownWSDLExtension> notUnderstoodExtensions = 1.59 + new ArrayList<UnknownWSDLExtension>(); 1.60 + 1.61 + protected AbstractExtensibleImpl(XMLStreamReader xsr) { 1.62 + super(xsr); 1.63 + } 1.64 + 1.65 + protected AbstractExtensibleImpl(String systemId, int lineNumber) { 1.66 + super(systemId, lineNumber); 1.67 + } 1.68 + 1.69 + public final Iterable<WSDLExtension> getExtensions() { 1.70 + return extensions; 1.71 + } 1.72 + 1.73 + public final <T extends WSDLExtension> Iterable<T> getExtensions(Class<T> type) { 1.74 + // TODO: this is a rather stupid implementation 1.75 + List<T> r = new ArrayList<T>(extensions.size()); 1.76 + for (WSDLExtension e : extensions) { 1.77 + if(type.isInstance(e)) 1.78 + r.add(type.cast(e)); 1.79 + } 1.80 + return r; 1.81 + } 1.82 + 1.83 + public <T extends WSDLExtension> T getExtension(Class<T> type) { 1.84 + for (WSDLExtension e : extensions) { 1.85 + if(type.isInstance(e)) 1.86 + return type.cast(e); 1.87 + } 1.88 + return null; 1.89 + } 1.90 + 1.91 + public void addExtension(WSDLExtension ex) { 1.92 + if(ex==null) 1.93 + // I don't trust plugins. So let's always check it, instead of making this an assertion 1.94 + throw new IllegalArgumentException(); 1.95 + extensions.add(ex); 1.96 + } 1.97 + 1.98 + public List<? extends UnknownWSDLExtension> getNotUnderstoodExtensions() { 1.99 + return notUnderstoodExtensions; 1.100 + } 1.101 + 1.102 + /** 1.103 + * This can be used if a WSDL extension element that has wsdl:required=true 1.104 + * is not understood 1.105 + * @param extnEl 1.106 + * @param locator 1.107 + */ 1.108 + public void addNotUnderstoodExtension(QName extnEl, Locator locator) { 1.109 + notUnderstoodExtensions.add(new UnknownWSDLExtension(extnEl, locator)); 1.110 + } 1.111 + 1.112 + protected static class UnknownWSDLExtension implements WSDLExtension, WSDLObject { 1.113 + private final QName extnEl; 1.114 + private final Locator locator; 1.115 + public UnknownWSDLExtension(QName extnEl, Locator locator) { 1.116 + this.extnEl = extnEl; 1.117 + this.locator = locator; 1.118 + } 1.119 + public QName getName() { 1.120 + return extnEl; 1.121 + } 1.122 + @NotNull public Locator getLocation() { 1.123 + return locator; 1.124 + } 1.125 + public String toString(){ 1.126 + return extnEl + " "+ UtilMessages.UTIL_LOCATION( locator.getLineNumber(), locator.getSystemId()); 1.127 + } 1.128 + } 1.129 + 1.130 + /** 1.131 + * This method should be called after freezing the WSDLModel 1.132 + * @return true if all wsdl required extensions on Port and Binding are understood 1.133 + */ 1.134 + public boolean areRequiredExtensionsUnderstood() { 1.135 + if (notUnderstoodExtensions.size() != 0) { 1.136 + StringBuilder buf = new StringBuilder("Unknown WSDL extensibility elements:"); 1.137 + for (UnknownWSDLExtension extn : notUnderstoodExtensions) 1.138 + buf.append('\n').append(extn.toString()); 1.139 + throw new WebServiceException(buf.toString()); 1.140 + } 1.141 + return true; 1.142 + } 1.143 +}