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

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 408
b0610cd08440
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

ohair@286 1 /*
alanb@368 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 package com.sun.xml.internal.ws.api.wsdl.parser;
ohair@286 27
ohair@286 28 import com.sun.xml.internal.ws.api.WSService;
ohair@286 29 import com.sun.xml.internal.ws.api.model.wsdl.*;
ohair@286 30 import com.sun.xml.internal.ws.api.pipe.Tube;
ohair@286 31 import com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser;
ohair@286 32
ohair@286 33 import javax.xml.stream.XMLStreamConstants;
ohair@286 34 import javax.xml.stream.XMLStreamReader;
ohair@286 35 import javax.xml.ws.WebServiceException;
ohair@286 36
ohair@286 37 /**
ohair@286 38 * Extends the WSDL parsing process.
ohair@286 39 *
ohair@286 40 * <p>
ohair@286 41 * This interface is implemented by components that build on top of the JAX-WS RI,
ohair@286 42 * to participate in the WSDL parsing process that happens in the runtime.
ohair@286 43 * This allows such components to retrieve information from WSDL extension elements,
ohair@286 44 * and use that later to, for example, configure {@link Tube}s.
ohair@286 45 *
ohair@286 46 *
ohair@286 47 *
ohair@286 48 * <h2>How it works?</h2>
ohair@286 49 * <p>
ohair@286 50 * Each method on this interface denotes one extension point in WSDL
ohair@286 51 * (the place where foreign elements/attributes can be added.) A {@link RuntimeWSDLParser}
ohair@286 52 * starts parsing WSDL with a fixed set of {@link WSDLParserExtension}s, and
ohair@286 53 * as it finds extension elements/attributes, it calls appropriate callback methods
ohair@286 54 * to provide a chance for {@link WSDLParserExtension} to parse such
ohair@286 55 * an extension element.
ohair@286 56 *
ohair@286 57 * <p>
ohair@286 58 * There are two kinds of callbacks.
ohair@286 59 *
ohair@286 60 * <h3>Attribute callbacks</h3>
ohair@286 61 * <p>
ohair@286 62 * One is for attributes, which ends with the name {@code Attributes}.
ohair@286 63 * This callback is invoked with {@link XMLStreamReader} that points
ohair@286 64 * to the start tag of the WSDL element.
ohair@286 65 *
ohair@286 66 * <p>
ohair@286 67 * The callback method can read interesting attributes on it.
ohair@286 68 * The method must return without advancing the parser to the next token.
ohair@286 69 *
ohair@286 70 * <h3>Element callbacks</h3>
ohair@286 71 * <p>
ohair@286 72 * The other callback is for extension elements, which ends with the name
ohair@286 73 * {@code Elements}.
ohair@286 74 * When a callback is invoked, {@link XMLStreamReader} points to the
ohair@286 75 * start tag of the extension element. The callback method can do
ohair@286 76 * one of the following:
ohair@286 77 *
ohair@286 78 * <ol>
ohair@286 79 * <li>Return {@code false} without moving {@link XMLStreamReader},
ohair@286 80 * to indicate that the extension element isn't recognized.
ohair@286 81 * This allows the next {@link WSDLParserExtension} to see this
ohair@286 82 * extension element.
ohair@286 83 * <li>Parse the whole subtree rooted at the element,
ohair@286 84 * move the cursor to the {@link XMLStreamConstants#END_ELEMENT} state,
ohair@286 85 * and return {@code true}, indicating that the extension
ohair@286 86 * element is consumed.
ohair@286 87 * No other {@link WSDLParserExtension}s are notified of this extension.
ohair@286 88 * </ol>
ohair@286 89 *
ohair@286 90 * <h3>Parsing in callback</h3>
ohair@286 91 * <p>
ohair@286 92 * For each callback, the corresponding WSDL model object is passed in,
ohair@286 93 * so that {@link WSDLParserExtension} can relate what it's parsing
ohair@286 94 * to the {@link WSDLModel}. Most likely, extensions can parse
ohair@286 95 * their data into an {@link WSDLExtension}-derived classes, then
ohair@286 96 * use {@link WSDLExtensible} interface to hook them into {@link WSDLModel}.
ohair@286 97 *
ohair@286 98 * <p>
ohair@286 99 * Note that since the {@link WSDLModel} itself
ohair@286 100 * is being built, {@link WSDLParserExtension} may not invoke any of
ohair@286 101 * the query methods on the WSDL model. Those references are passed just so that
ohair@286 102 * {@link WSDLParserExtension} can hold on to those references, or put
ohair@286 103 * {@link WSDLExtensible} objects into the model, not to query it.
ohair@286 104 *
ohair@286 105 * <p>
ohair@286 106 * If {@link WSDLParserExtension} needs to query {@link WSDLModel},
ohair@286 107 * defer that processing until {@link #finished(WSDLParserExtensionContext)}, when it's
ohair@286 108 * safe to use {@link WSDLModel} can be used safely.
ohair@286 109 *
ohair@286 110 * <p>
ohair@286 111 * Also note that {@link WSDLParserExtension}s are called in no particular order.
ohair@286 112 * This interface is not designed for having multiple {@link WSDLParserExtension}s
ohair@286 113 * parse the same extension element.
ohair@286 114 *
ohair@286 115 *
ohair@286 116 * <h2>Error Handling</h2>
ohair@286 117 * <p>
ohair@286 118 * For usability, {@link WSDLParserExtension}s are expected to check possible
ohair@286 119 * errors in the extension elements that it parses. When an error is found,
ohair@286 120 * it may throw a {@link WebServiceException} to abort the parsing of the WSDL.
ohair@286 121 * This exception will be propagated to the user, so it should have
ohair@286 122 * detailed error messages pointing at the problem.
ohair@286 123 *
ohair@286 124 * <h2>Discovery</h2>
ohair@286 125 * <p>
ohair@286 126 * The JAX-WS RI locates the implementation of {@link WSDLParserExtension}s
ohair@286 127 * by using the standard service look up mechanism, in particular looking for
ohair@286 128 * <tt>META-INF/services/com.sun.xml.internal.ws.api.wsdl.parser.WSDLParserExtension</tt>
ohair@286 129 *
ohair@286 130 *
ohair@286 131 * <h2>TODO</h2>
ohair@286 132 * <p>
ohair@286 133 * As it's designed today, extensions cannot access to any of the environmental
ohair@286 134 * information before the parsing begins (such as what {@link WSService} this
ohair@286 135 * WSDL is being parsed for, etc.) We might need to reconsider this aspect.
ohair@286 136 * The JAX-WS team waits for feedback on this topic.
ohair@286 137 *
ohair@286 138 * @author Kohsuke Kawaguchi
ohair@286 139 */
ohair@286 140 public abstract class WSDLParserExtension {
ohair@286 141 public void start(WSDLParserExtensionContext context){
ohair@286 142 // noop
ohair@286 143 }
ohair@286 144 public void serviceAttributes(WSDLService service, XMLStreamReader reader) {
ohair@286 145 // noop
ohair@286 146 }
ohair@286 147
ohair@286 148 public boolean serviceElements(WSDLService service, XMLStreamReader reader) {
ohair@286 149 return false;
ohair@286 150 }
ohair@286 151
ohair@286 152 public void portAttributes(WSDLPort port, XMLStreamReader reader) {
ohair@286 153 // noop
ohair@286 154 }
ohair@286 155
ohair@286 156 public boolean portElements(WSDLPort port, XMLStreamReader reader) {
ohair@286 157 return false;
ohair@286 158 }
ohair@286 159
ohair@286 160 public boolean portTypeOperationInput(WSDLOperation op, XMLStreamReader reader) {
ohair@286 161 return false;
ohair@286 162 }
ohair@286 163
ohair@286 164 public boolean portTypeOperationOutput(WSDLOperation op, XMLStreamReader reader) {
ohair@286 165 return false;
ohair@286 166 }
ohair@286 167
ohair@286 168 public boolean portTypeOperationFault(WSDLOperation op, XMLStreamReader reader) {
ohair@286 169 return false;
ohair@286 170 }
ohair@286 171
ohair@286 172 public boolean definitionsElements(XMLStreamReader reader) {
ohair@286 173 return false;
ohair@286 174 }
ohair@286 175
ohair@286 176 public boolean bindingElements(WSDLBoundPortType binding, XMLStreamReader reader) {
ohair@286 177 return false;
ohair@286 178 }
ohair@286 179
ohair@286 180 public void bindingAttributes(WSDLBoundPortType binding, XMLStreamReader reader) {
ohair@286 181 }
ohair@286 182
ohair@286 183 public boolean portTypeElements(WSDLPortType portType, XMLStreamReader reader) {
ohair@286 184 return false;
ohair@286 185 }
ohair@286 186
ohair@286 187 public void portTypeAttributes(WSDLPortType portType, XMLStreamReader reader) {
ohair@286 188 }
ohair@286 189
ohair@286 190 public boolean portTypeOperationElements(WSDLOperation operation, XMLStreamReader reader) {
ohair@286 191 return false;
ohair@286 192 }
ohair@286 193
ohair@286 194 public void portTypeOperationAttributes(WSDLOperation operation, XMLStreamReader reader) {
ohair@286 195 }
ohair@286 196
ohair@286 197 public boolean bindingOperationElements(WSDLBoundOperation operation, XMLStreamReader reader) {
ohair@286 198 return false;
ohair@286 199 }
ohair@286 200
ohair@286 201 public void bindingOperationAttributes(WSDLBoundOperation operation, XMLStreamReader reader) {
ohair@286 202 }
ohair@286 203
ohair@286 204 public boolean messageElements(WSDLMessage msg, XMLStreamReader reader) {
ohair@286 205 return false;
ohair@286 206 }
ohair@286 207
ohair@286 208 public void messageAttributes(WSDLMessage msg, XMLStreamReader reader) {
ohair@286 209 }
ohair@286 210
ohair@286 211 public boolean portTypeOperationInputElements(WSDLInput input, XMLStreamReader reader) {
ohair@286 212 return false;
ohair@286 213 }
ohair@286 214
ohair@286 215 public void portTypeOperationInputAttributes(WSDLInput input, XMLStreamReader reader) {
ohair@286 216 }
ohair@286 217
ohair@286 218 public boolean portTypeOperationOutputElements(WSDLOutput output, XMLStreamReader reader) {
ohair@286 219 return false;
ohair@286 220 }
ohair@286 221
ohair@286 222 public void portTypeOperationOutputAttributes(WSDLOutput output, XMLStreamReader reader) {
ohair@286 223 }
ohair@286 224
ohair@286 225 public boolean portTypeOperationFaultElements(WSDLFault fault, XMLStreamReader reader) {
ohair@286 226 return false;
ohair@286 227 }
ohair@286 228
ohair@286 229 public void portTypeOperationFaultAttributes(WSDLFault fault, XMLStreamReader reader) {
ohair@286 230 }
ohair@286 231
ohair@286 232 public boolean bindingOperationInputElements(WSDLBoundOperation operation, XMLStreamReader reader) {
ohair@286 233 return false;
ohair@286 234 }
ohair@286 235
ohair@286 236 public void bindingOperationInputAttributes(WSDLBoundOperation operation, XMLStreamReader reader) {
ohair@286 237 }
ohair@286 238
ohair@286 239 public boolean bindingOperationOutputElements(WSDLBoundOperation operation, XMLStreamReader reader) {
ohair@286 240 return false;
ohair@286 241 }
ohair@286 242
ohair@286 243 public void bindingOperationOutputAttributes(WSDLBoundOperation operation, XMLStreamReader reader) {
ohair@286 244 }
ohair@286 245
ohair@286 246 public boolean bindingOperationFaultElements(WSDLBoundFault fault, XMLStreamReader reader) {
ohair@286 247 return false;
ohair@286 248 }
ohair@286 249
ohair@286 250 public void bindingOperationFaultAttributes(WSDLBoundFault fault, XMLStreamReader reader) {
ohair@286 251 }
ohair@286 252
ohair@286 253 // TODO: complete the rest of the callback
ohair@286 254
ohair@286 255 /**
ohair@286 256 * Called when the parsing of a set of WSDL documents are all done.
ohair@286 257 * <p>
ohair@286 258 * This is the opportunity to do any post-processing of the parsing
ohair@286 259 * you've done.
ohair@286 260 *
ohair@286 261 * @param context {@link WSDLParserExtensionContext} gives fully parsed {@link WSDLModel}.
ohair@286 262 */
ohair@286 263 public void finished(WSDLParserExtensionContext context) {
ohair@286 264 // noop
ohair@286 265 }
ohair@286 266
ohair@286 267 public void postFinished(WSDLParserExtensionContext context) {
ohair@286 268 // noop
ohair@286 269 }
ohair@286 270 }

mercurial