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

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

mercurial