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 Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,139 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2010, 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.xml.internal.ws.wsdl.parser.WSDLConstants; 1.36 +import com.sun.istack.internal.NotNull; 1.37 + 1.38 +import javax.xml.stream.XMLStreamReader; 1.39 +import javax.xml.stream.Location; 1.40 +import javax.xml.namespace.QName; 1.41 +import javax.xml.ws.WebServiceException; 1.42 +import java.util.ArrayList; 1.43 +import java.util.HashSet; 1.44 +import java.util.List; 1.45 +import java.util.Set; 1.46 + 1.47 +import org.xml.sax.Locator; 1.48 +import org.xml.sax.helpers.LocatorImpl; 1.49 + 1.50 +/** 1.51 + * All the WSDL 1.1 elements that are extensible should subclass from this abstract implementation of 1.52 + * {@link WSDLExtensible} interface. 1.53 + * 1.54 + * @author Vivek Pandey 1.55 + * @author Kohsuke Kawaguchi 1.56 + */ 1.57 +abstract class AbstractExtensibleImpl extends AbstractObjectImpl implements WSDLExtensible { 1.58 + protected final Set<WSDLExtension> extensions = new HashSet<WSDLExtension>(); 1.59 + // this captures any wsdl extensions that are not understood by WSDLExtensionParsers 1.60 + // and have wsdl:required=true 1.61 + protected List<UnknownWSDLExtension> notUnderstoodExtensions = 1.62 + new ArrayList<UnknownWSDLExtension>(); 1.63 + 1.64 + protected AbstractExtensibleImpl(XMLStreamReader xsr) { 1.65 + super(xsr); 1.66 + } 1.67 + 1.68 + protected AbstractExtensibleImpl(String systemId, int lineNumber) { 1.69 + super(systemId, lineNumber); 1.70 + } 1.71 + 1.72 + public final Iterable<WSDLExtension> getExtensions() { 1.73 + return extensions; 1.74 + } 1.75 + 1.76 + public final <T extends WSDLExtension> Iterable<T> getExtensions(Class<T> type) { 1.77 + // TODO: this is a rather stupid implementation 1.78 + List<T> r = new ArrayList<T>(extensions.size()); 1.79 + for (WSDLExtension e : extensions) { 1.80 + if(type.isInstance(e)) 1.81 + r.add(type.cast(e)); 1.82 + } 1.83 + return r; 1.84 + } 1.85 + 1.86 + public <T extends WSDLExtension> T getExtension(Class<T> type) { 1.87 + for (WSDLExtension e : extensions) { 1.88 + if(type.isInstance(e)) 1.89 + return type.cast(e); 1.90 + } 1.91 + return null; 1.92 + } 1.93 + 1.94 + public void addExtension(WSDLExtension ex) { 1.95 + if(ex==null) 1.96 + // I don't trust plugins. So let's always check it, instead of making this an assertion 1.97 + throw new IllegalArgumentException(); 1.98 + extensions.add(ex); 1.99 + } 1.100 + 1.101 + /** 1.102 + * This can be used if a WSDL extension element that has wsdl:required=true 1.103 + * is not understood 1.104 + * @param extnEl 1.105 + * @param locator 1.106 + */ 1.107 + public void addNotUnderstoodExtension(QName extnEl, Locator locator) { 1.108 + notUnderstoodExtensions.add(new UnknownWSDLExtension(extnEl, locator)); 1.109 + } 1.110 + 1.111 + protected static class UnknownWSDLExtension implements WSDLExtension, WSDLObject { 1.112 + private final QName extnEl; 1.113 + private final Locator locator; 1.114 + public UnknownWSDLExtension(QName extnEl, Locator locator) { 1.115 + this.extnEl = extnEl; 1.116 + this.locator = locator; 1.117 + } 1.118 + public QName getName() { 1.119 + return extnEl; 1.120 + } 1.121 + @NotNull public Locator getLocation() { 1.122 + return locator; 1.123 + } 1.124 + public String toString(){ 1.125 + return extnEl + " "+ UtilMessages.UTIL_LOCATION( locator.getLineNumber(), locator.getSystemId()); 1.126 + } 1.127 + } 1.128 + 1.129 + /** 1.130 + * This method should be called after freezing the WSDLModel 1.131 + * @return true if all wsdl required extensions on Port and Binding are understood 1.132 + */ 1.133 + public boolean areRequiredExtensionsUnderstood() { 1.134 + if (notUnderstoodExtensions.size() != 0) { 1.135 + StringBuilder buf = new StringBuilder("Unknown WSDL extensibility elements:"); 1.136 + for (UnknownWSDLExtension extn : notUnderstoodExtensions) 1.137 + buf.append('\n').append(extn.toString()); 1.138 + throw new WebServiceException(buf.toString()); 1.139 + } 1.140 + return true; 1.141 + } 1.142 +}