src/share/jaxws_classes/com/sun/xml/internal/ws/model/wsdl/AbstractExtensibleImpl.java

Tue, 06 Mar 2012 16:09:35 -0800

author
ohair
date
Tue, 06 Mar 2012 16:09:35 -0800
changeset 286
f50545b5e2f1
child 368
0989ad8c0860
permissions
-rw-r--r--

7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom

     1 /*
     2  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.xml.internal.ws.model.wsdl;
    28 import com.sun.xml.internal.ws.api.model.wsdl.WSDLExtensible;
    29 import com.sun.xml.internal.ws.api.model.wsdl.WSDLExtension;
    30 import com.sun.xml.internal.ws.api.model.wsdl.WSDLObject;
    31 import com.sun.xml.internal.ws.resources.UtilMessages;
    32 import com.sun.xml.internal.ws.wsdl.parser.WSDLConstants;
    33 import com.sun.istack.internal.NotNull;
    35 import javax.xml.stream.XMLStreamReader;
    36 import javax.xml.stream.Location;
    37 import javax.xml.namespace.QName;
    38 import javax.xml.ws.WebServiceException;
    39 import java.util.ArrayList;
    40 import java.util.HashSet;
    41 import java.util.List;
    42 import java.util.Set;
    44 import org.xml.sax.Locator;
    45 import org.xml.sax.helpers.LocatorImpl;
    47 /**
    48  * All the WSDL 1.1 elements that are extensible should subclass from this abstract implementation of
    49  * {@link WSDLExtensible} interface.
    50  *
    51  * @author Vivek Pandey
    52  * @author Kohsuke Kawaguchi
    53  */
    54 abstract class AbstractExtensibleImpl extends AbstractObjectImpl implements WSDLExtensible {
    55     protected final Set<WSDLExtension> extensions = new HashSet<WSDLExtension>();
    56     // this captures any wsdl extensions that are not understood by WSDLExtensionParsers
    57     // and have wsdl:required=true
    58     protected List<UnknownWSDLExtension> notUnderstoodExtensions =
    59             new ArrayList<UnknownWSDLExtension>();
    61     protected AbstractExtensibleImpl(XMLStreamReader xsr) {
    62         super(xsr);
    63     }
    65     protected AbstractExtensibleImpl(String systemId, int lineNumber) {
    66         super(systemId, lineNumber);
    67     }
    69     public final Iterable<WSDLExtension> getExtensions() {
    70         return extensions;
    71     }
    73     public final <T extends WSDLExtension> Iterable<T> getExtensions(Class<T> type) {
    74         // TODO: this is a rather stupid implementation
    75         List<T> r = new ArrayList<T>(extensions.size());
    76         for (WSDLExtension e : extensions) {
    77             if(type.isInstance(e))
    78                 r.add(type.cast(e));
    79         }
    80         return r;
    81     }
    83     public <T extends WSDLExtension> T getExtension(Class<T> type) {
    84         for (WSDLExtension e : extensions) {
    85             if(type.isInstance(e))
    86                 return type.cast(e);
    87         }
    88         return null;
    89     }
    91     public void addExtension(WSDLExtension ex) {
    92         if(ex==null)
    93             // I don't trust plugins. So let's always check it, instead of making this an assertion
    94             throw new IllegalArgumentException();
    95         extensions.add(ex);
    96     }
    98     /**
    99      * This can be used if a WSDL extension element that has wsdl:required=true
   100      * is not understood
   101      * @param extnEl
   102      * @param locator
   103      */
   104     public void addNotUnderstoodExtension(QName extnEl, Locator locator) {
   105         notUnderstoodExtensions.add(new UnknownWSDLExtension(extnEl, locator));
   106     }
   108     protected static class UnknownWSDLExtension implements WSDLExtension, WSDLObject {
   109         private final QName extnEl;
   110         private final Locator locator;
   111         public UnknownWSDLExtension(QName extnEl, Locator locator) {
   112             this.extnEl = extnEl;
   113             this.locator = locator;
   114         }
   115         public QName getName() {
   116             return extnEl;
   117         }
   118         @NotNull public Locator getLocation() {
   119             return locator;
   120         }
   121         public String toString(){
   122            return extnEl + " "+ UtilMessages.UTIL_LOCATION( locator.getLineNumber(), locator.getSystemId());
   123        }
   124     }
   126     /**
   127      * This method should be called after freezing the WSDLModel
   128      * @return true if all wsdl required extensions on Port and Binding are understood
   129      */
   130     public boolean areRequiredExtensionsUnderstood() {
   131         if (notUnderstoodExtensions.size() != 0) {
   132             StringBuilder buf = new StringBuilder("Unknown WSDL extensibility elements:");
   133             for (UnknownWSDLExtension extn : notUnderstoodExtensions)
   134                 buf.append('\n').append(extn.toString());
   135             throw new WebServiceException(buf.toString());
   136         }
   137         return true;
   138     }
   139 }

mercurial