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