src/share/jaxws_classes/com/sun/xml/internal/ws/api/wsdl/parser/WSDLParserExtension.java

changeset 0
373ffda63c9a
child 637
9c07ef4934dd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/api/wsdl/parser/WSDLParserExtension.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,282 @@
     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.api.wsdl.parser;
    1.30 +
    1.31 +import com.sun.xml.internal.ws.api.WSService;
    1.32 +import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLBoundFault;
    1.33 +import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLBoundOperation;
    1.34 +import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLBoundPortType;
    1.35 +import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLFault;
    1.36 +import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLInput;
    1.37 +import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLMessage;
    1.38 +import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLOperation;
    1.39 +import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLOutput;
    1.40 +import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLPort;
    1.41 +import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLPortType;
    1.42 +import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLService;
    1.43 +import com.sun.xml.internal.ws.api.pipe.Tube;
    1.44 +import com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser;
    1.45 +
    1.46 +import javax.xml.stream.XMLStreamConstants;
    1.47 +import javax.xml.stream.XMLStreamReader;
    1.48 +import javax.xml.ws.WebServiceException;
    1.49 +
    1.50 +/**
    1.51 + * Extends the WSDL parsing process.
    1.52 + *
    1.53 + * <p>
    1.54 + * This interface is implemented by components that build on top of the JAX-WS RI,
    1.55 + * to participate in the WSDL parsing process that happens in the runtime.
    1.56 + * This allows such components to retrieve information from WSDL extension elements,
    1.57 + * and use that later to, for example, configure {@link Tube}s.
    1.58 + *
    1.59 + *
    1.60 + *
    1.61 + * <h2>How it works?</h2>
    1.62 + * <p>
    1.63 + * Each method on this interface denotes one extension point in WSDL
    1.64 + * (the place where foreign elements/attributes can be added.) A {@link RuntimeWSDLParser}
    1.65 + * starts parsing WSDL with a fixed set of {@link WSDLParserExtension}s, and
    1.66 + * as it finds extension elements/attributes, it calls appropriate callback methods
    1.67 + * to provide a chance for {@link WSDLParserExtension} to parse such
    1.68 + * an extension element.
    1.69 + *
    1.70 + * <p>
    1.71 + * There are two kinds of callbacks.
    1.72 + *
    1.73 + * <h3>Attribute callbacks</h3>
    1.74 + * <p>
    1.75 + * One is for attributes, which ends with the name {@code Attributes}.
    1.76 + * This callback is invoked with {@link XMLStreamReader} that points
    1.77 + * to the start tag of the WSDL element.
    1.78 + *
    1.79 + * <p>
    1.80 + * The callback method can read interesting attributes on it.
    1.81 + * The method must return without advancing the parser to the next token.
    1.82 + *
    1.83 + * <h3>Element callbacks</h3>
    1.84 + * <p>
    1.85 + * The other callback is for extension elements, which ends with the name
    1.86 + * {@code Elements}.
    1.87 + * When a callback is invoked, {@link XMLStreamReader} points to the
    1.88 + * start tag of the extension element. The callback method can do
    1.89 + * one of the following:
    1.90 + *
    1.91 + * <ol>
    1.92 + *  <li>Return {@code false} without moving {@link XMLStreamReader},
    1.93 + *      to indicate that the extension element isn't recognized.
    1.94 + *      This allows the next {@link WSDLParserExtension} to see this
    1.95 + *      extension element.
    1.96 + *  <li>Parse the whole subtree rooted at the element,
    1.97 + *      move the cursor to the {@link XMLStreamConstants#END_ELEMENT} state,
    1.98 + *      and return {@code true}, indicating that the extension
    1.99 + *      element is consumed.
   1.100 + *      No other {@link WSDLParserExtension}s are notified of this extension.
   1.101 + * </ol>
   1.102 + *
   1.103 + * <h3>Parsing in callback</h3>
   1.104 + * <p>
   1.105 + * For each callback, the corresponding WSDL model object is passed in,
   1.106 + * so that {@link WSDLParserExtension} can relate what it's parsing
   1.107 + * to the {@link WSDLModel}. Most likely, extensions can parse
   1.108 + * their data into an {@link WSDLExtension}-derived classes, then
   1.109 + * use {@link WSDLExtensible} interface to hook them into {@link WSDLModel}.
   1.110 + *
   1.111 + * <p>
   1.112 + * Note that since the {@link WSDLModel} itself
   1.113 + * is being built, {@link WSDLParserExtension} may not invoke any of
   1.114 + * the query methods on the WSDL model. Those references are passed just so that
   1.115 + * {@link WSDLParserExtension} can hold on to those references, or put
   1.116 + * {@link WSDLExtensible} objects into the model, not to query it.
   1.117 + *
   1.118 + * <p>
   1.119 + * If {@link WSDLParserExtension} needs to query {@link WSDLModel},
   1.120 + * defer that processing until {@link #finished(WSDLParserExtensionContext)}, when it's
   1.121 + * safe to use {@link WSDLModel} can be used safely.
   1.122 + *
   1.123 + * <p>
   1.124 + * Also note that {@link WSDLParserExtension}s are called in no particular order.
   1.125 + * This interface is not designed for having multiple {@link WSDLParserExtension}s
   1.126 + * parse the same extension element.
   1.127 + *
   1.128 + *
   1.129 + * <h2>Error Handling</h2>
   1.130 + * <p>
   1.131 + * For usability, {@link WSDLParserExtension}s are expected to check possible
   1.132 + * errors in the extension elements that it parses. When an error is found,
   1.133 + * it may throw a {@link WebServiceException} to abort the parsing of the WSDL.
   1.134 + * This exception will be propagated to the user, so it should have
   1.135 + * detailed error messages pointing at the problem.
   1.136 + *
   1.137 + * <h2>Discovery</h2>
   1.138 + * <p>
   1.139 + * The JAX-WS RI locates the implementation of {@link WSDLParserExtension}s
   1.140 + * by using the standard service look up mechanism, in particular looking for
   1.141 + * <tt>META-INF/services/com.sun.xml.internal.ws.api.wsdl.parser.WSDLParserExtension</tt>
   1.142 + *
   1.143 + *
   1.144 + * <h2>TODO</h2>
   1.145 + * <p>
   1.146 + * As it's designed today, extensions cannot access to any of the environmental
   1.147 + * information before the parsing begins (such as what {@link WSService} this
   1.148 + * WSDL is being parsed for, etc.) We might need to reconsider this aspect.
   1.149 + * The JAX-WS team waits for feedback on this topic.
   1.150 + *
   1.151 + * @author Kohsuke Kawaguchi
   1.152 + */
   1.153 +public abstract class WSDLParserExtension {
   1.154 +
   1.155 +    public void start(WSDLParserExtensionContext context){
   1.156 +        // noop
   1.157 +    }
   1.158 +
   1.159 +    public void serviceAttributes(EditableWSDLService service, XMLStreamReader reader) {
   1.160 +        // noop
   1.161 +    }
   1.162 +
   1.163 +    public boolean serviceElements(EditableWSDLService service, XMLStreamReader reader) {
   1.164 +        return false;
   1.165 +    }
   1.166 +
   1.167 +    public void portAttributes(EditableWSDLPort port, XMLStreamReader reader) {
   1.168 +        // noop
   1.169 +    }
   1.170 +
   1.171 +    public boolean portElements(EditableWSDLPort port, XMLStreamReader reader) {
   1.172 +        return false;
   1.173 +    }
   1.174 +
   1.175 +    public boolean portTypeOperationInput(EditableWSDLOperation op, XMLStreamReader reader) {
   1.176 +        return false;
   1.177 +    }
   1.178 +
   1.179 +    public boolean portTypeOperationOutput(EditableWSDLOperation op, XMLStreamReader reader) {
   1.180 +        return false;
   1.181 +    }
   1.182 +
   1.183 +    public boolean portTypeOperationFault(EditableWSDLOperation op, XMLStreamReader reader) {
   1.184 +        return false;
   1.185 +    }
   1.186 +
   1.187 +    public boolean definitionsElements(XMLStreamReader reader) {
   1.188 +        return false;
   1.189 +    }
   1.190 +
   1.191 +    public boolean bindingElements(EditableWSDLBoundPortType binding, XMLStreamReader reader) {
   1.192 +        return false;
   1.193 +    }
   1.194 +
   1.195 +    public void bindingAttributes(EditableWSDLBoundPortType binding, XMLStreamReader reader) {
   1.196 +    }
   1.197 +
   1.198 +    public boolean portTypeElements(EditableWSDLPortType portType, XMLStreamReader reader) {
   1.199 +        return false;
   1.200 +    }
   1.201 +
   1.202 +    public void portTypeAttributes(EditableWSDLPortType portType, XMLStreamReader reader) {
   1.203 +    }
   1.204 +
   1.205 +    public boolean portTypeOperationElements(EditableWSDLOperation operation, XMLStreamReader reader) {
   1.206 +        return false;
   1.207 +    }
   1.208 +
   1.209 +    public void portTypeOperationAttributes(EditableWSDLOperation operation, XMLStreamReader reader) {
   1.210 +    }
   1.211 +
   1.212 +    public boolean bindingOperationElements(EditableWSDLBoundOperation operation, XMLStreamReader reader) {
   1.213 +        return false;
   1.214 +    }
   1.215 +
   1.216 +    public void bindingOperationAttributes(EditableWSDLBoundOperation operation, XMLStreamReader reader) {
   1.217 +    }
   1.218 +
   1.219 +    public boolean messageElements(EditableWSDLMessage msg, XMLStreamReader reader) {
   1.220 +        return false;
   1.221 +    }
   1.222 +
   1.223 +    public void messageAttributes(EditableWSDLMessage msg, XMLStreamReader reader) {
   1.224 +    }
   1.225 +
   1.226 +    public boolean portTypeOperationInputElements(EditableWSDLInput input, XMLStreamReader reader) {
   1.227 +        return false;
   1.228 +    }
   1.229 +
   1.230 +    public void portTypeOperationInputAttributes(EditableWSDLInput input, XMLStreamReader reader) {
   1.231 +    }
   1.232 +
   1.233 +    public boolean portTypeOperationOutputElements(EditableWSDLOutput output, XMLStreamReader reader) {
   1.234 +        return false;
   1.235 +    }
   1.236 +
   1.237 +    public void portTypeOperationOutputAttributes(EditableWSDLOutput output, XMLStreamReader reader) {
   1.238 +    }
   1.239 +
   1.240 +    public boolean portTypeOperationFaultElements(EditableWSDLFault fault, XMLStreamReader reader) {
   1.241 +        return false;
   1.242 +    }
   1.243 +
   1.244 +    public void portTypeOperationFaultAttributes(EditableWSDLFault fault, XMLStreamReader reader) {
   1.245 +    }
   1.246 +
   1.247 +    public boolean bindingOperationInputElements(EditableWSDLBoundOperation operation, XMLStreamReader reader) {
   1.248 +        return false;
   1.249 +    }
   1.250 +
   1.251 +    public void bindingOperationInputAttributes(EditableWSDLBoundOperation operation, XMLStreamReader reader) {
   1.252 +    }
   1.253 +
   1.254 +    public boolean bindingOperationOutputElements(EditableWSDLBoundOperation operation, XMLStreamReader reader) {
   1.255 +        return false;
   1.256 +    }
   1.257 +
   1.258 +    public void bindingOperationOutputAttributes(EditableWSDLBoundOperation operation, XMLStreamReader reader) {
   1.259 +    }
   1.260 +
   1.261 +    public boolean bindingOperationFaultElements(EditableWSDLBoundFault fault, XMLStreamReader reader) {
   1.262 +        return false;
   1.263 +    }
   1.264 +
   1.265 +    public void bindingOperationFaultAttributes(EditableWSDLBoundFault fault, XMLStreamReader reader) {
   1.266 +    }
   1.267 +
   1.268 +    // TODO: complete the rest of the callback
   1.269 +
   1.270 +    /**
   1.271 +     * Called when the parsing of a set of WSDL documents are all done.
   1.272 +     * <p>
   1.273 +     * This is the opportunity to do any post-processing of the parsing
   1.274 +     * you've done.
   1.275 +     *
   1.276 +     * @param context  {@link WSDLParserExtensionContext} gives fully parsed {@link WSDLModel}.
   1.277 +     */
   1.278 +    public void finished(WSDLParserExtensionContext context) {
   1.279 +        // noop
   1.280 +    }
   1.281 +
   1.282 +    public void postFinished(WSDLParserExtensionContext context) {
   1.283 +        // noop
   1.284 +    }
   1.285 +}

mercurial