src/share/jaxws_classes/com/sun/xml/internal/ws/model/wsdl/WSDLBoundOperationImpl.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

ohair@286 1 /*
ohair@286 2 * Copyright (c) 1997, 2010, 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.model.wsdl;
ohair@286 27
ohair@286 28 import com.sun.istack.internal.Nullable;
ohair@286 29 import com.sun.istack.internal.NotNull;
ohair@286 30 import com.sun.xml.internal.ws.api.model.ParameterBinding;
ohair@286 31 import com.sun.xml.internal.ws.api.model.wsdl.*;
ohair@286 32
ohair@286 33 import javax.jws.WebParam.Mode;
ohair@286 34 import javax.jws.soap.SOAPBinding.Style;
ohair@286 35 import javax.xml.namespace.QName;
ohair@286 36 import javax.xml.stream.XMLStreamReader;
ohair@286 37 import java.util.*;
ohair@286 38
ohair@286 39 /**
ohair@286 40 * Implementation of {@link WSDLBoundOperation}
ohair@286 41 *
ohair@286 42 * @author Vivek Pandey
ohair@286 43 */
ohair@286 44 public final class WSDLBoundOperationImpl extends AbstractExtensibleImpl implements WSDLBoundOperation {
ohair@286 45 private final QName name;
ohair@286 46
ohair@286 47 // map of wsdl:part to the binding
ohair@286 48 private final Map<String, ParameterBinding> inputParts;
ohair@286 49 private final Map<String, ParameterBinding> outputParts;
ohair@286 50 private final Map<String, ParameterBinding> faultParts;
ohair@286 51 private final Map<String, String> inputMimeTypes;
ohair@286 52 private final Map<String, String> outputMimeTypes;
ohair@286 53 private final Map<String, String> faultMimeTypes;
ohair@286 54
ohair@286 55 private boolean explicitInputSOAPBodyParts = false;
ohair@286 56 private boolean explicitOutputSOAPBodyParts = false;
ohair@286 57 private boolean explicitFaultSOAPBodyParts = false;
ohair@286 58
ohair@286 59 private Boolean emptyInputBody;
ohair@286 60 private Boolean emptyOutputBody;
ohair@286 61 private Boolean emptyFaultBody;
ohair@286 62
ohair@286 63 private final Map<String, WSDLPartImpl> inParts;
ohair@286 64 private final Map<String, WSDLPartImpl> outParts;
ohair@286 65 private final Map<String, WSDLPartImpl> fltParts;
ohair@286 66 private final List<WSDLBoundFaultImpl> wsdlBoundFaults;
ohair@286 67 private WSDLOperationImpl operation;
ohair@286 68 private String soapAction;
ohair@286 69 private ANONYMOUS anonymous;
ohair@286 70
ohair@286 71 private final WSDLBoundPortTypeImpl owner;
ohair@286 72
ohair@286 73 /**
ohair@286 74 *
ohair@286 75 * @param name wsdl:operation name qualified value
ohair@286 76 */
ohair@286 77 public WSDLBoundOperationImpl(XMLStreamReader xsr, WSDLBoundPortTypeImpl owner, QName name) {
ohair@286 78 super(xsr);
ohair@286 79 this.name = name;
ohair@286 80 inputParts = new HashMap<String, ParameterBinding>();
ohair@286 81 outputParts = new HashMap<String, ParameterBinding>();
ohair@286 82 faultParts = new HashMap<String, ParameterBinding>();
ohair@286 83 inputMimeTypes = new HashMap<String, String>();
ohair@286 84 outputMimeTypes = new HashMap<String, String>();
ohair@286 85 faultMimeTypes = new HashMap<String, String>();
ohair@286 86 inParts = new HashMap<String, WSDLPartImpl>();
ohair@286 87 outParts = new HashMap<String, WSDLPartImpl>();
ohair@286 88 fltParts = new HashMap<String, WSDLPartImpl>();
ohair@286 89 wsdlBoundFaults = new ArrayList<WSDLBoundFaultImpl>();
ohair@286 90 this.owner = owner;
ohair@286 91 }
ohair@286 92
ohair@286 93 public QName getName(){
ohair@286 94 return name;
ohair@286 95 }
ohair@286 96
ohair@286 97 public String getSOAPAction() {
ohair@286 98 return soapAction;
ohair@286 99 }
ohair@286 100
ohair@286 101 public void setSoapAction(String soapAction) {
ohair@286 102 this.soapAction = soapAction!=null?soapAction:"";
ohair@286 103 }
ohair@286 104
ohair@286 105 public WSDLPartImpl getPart(String partName, Mode mode) {
ohair@286 106 if(mode==Mode.IN){
ohair@286 107 return inParts.get(partName);
ohair@286 108 }else if(mode==Mode.OUT){
ohair@286 109 return outParts.get(partName);
ohair@286 110 }
ohair@286 111 return null;
ohair@286 112 }
ohair@286 113
ohair@286 114 public void addPart(WSDLPartImpl part, Mode mode){
ohair@286 115 if(mode==Mode.IN)
ohair@286 116 inParts.put(part.getName(), part);
ohair@286 117 else if(mode==Mode.OUT)
ohair@286 118 outParts.put(part.getName(), part);
ohair@286 119 }
ohair@286 120
ohair@286 121 /**
ohair@286 122 * Map of wsdl:input part name and the binding as {@link ParameterBinding}
ohair@286 123 *
ohair@286 124 * @return empty Map if there is no parts
ohair@286 125 */
ohair@286 126 public Map<String, ParameterBinding> getInputParts() {
ohair@286 127 return inputParts;
ohair@286 128 }
ohair@286 129
ohair@286 130 /**
ohair@286 131 * Map of wsdl:output part name and the binding as {@link ParameterBinding}
ohair@286 132 *
ohair@286 133 * @return empty Map if there is no parts
ohair@286 134 */
ohair@286 135 public Map<String, ParameterBinding> getOutputParts() {
ohair@286 136 return outputParts;
ohair@286 137 }
ohair@286 138
ohair@286 139 /**
ohair@286 140 * Map of wsdl:fault part name and the binding as {@link ParameterBinding}
ohair@286 141 *
ohair@286 142 * @return empty Map if there is no parts
ohair@286 143 */
ohair@286 144 public Map<String, ParameterBinding> getFaultParts() {
ohair@286 145 return faultParts;
ohair@286 146 }
ohair@286 147
ohair@286 148 // TODO: what's the difference between this and inputParts/outputParts?
ohair@286 149 public Map<String,WSDLPart> getInParts() {
ohair@286 150 return Collections.<String,WSDLPart>unmodifiableMap(inParts);
ohair@286 151 }
ohair@286 152
ohair@286 153 public Map<String,WSDLPart> getOutParts() {
ohair@286 154 return Collections.<String,WSDLPart>unmodifiableMap(outParts);
ohair@286 155 }
ohair@286 156
ohair@286 157 @NotNull
ohair@286 158 public List<WSDLBoundFaultImpl> getFaults() {
ohair@286 159 return wsdlBoundFaults;
ohair@286 160 }
ohair@286 161
ohair@286 162 public void addFault(@NotNull WSDLBoundFaultImpl fault){
ohair@286 163 wsdlBoundFaults.add(fault);
ohair@286 164 }
ohair@286 165
ohair@286 166
ohair@286 167 /**
ohair@286 168 * Map of mime:content@part and the mime type from mime:content@type for wsdl:output
ohair@286 169 *
ohair@286 170 * @return empty Map if there is no parts
ohair@286 171 */
ohair@286 172 public Map<String, String> getInputMimeTypes() {
ohair@286 173 return inputMimeTypes;
ohair@286 174 }
ohair@286 175
ohair@286 176 /**
ohair@286 177 * Map of mime:content@part and the mime type from mime:content@type for wsdl:output
ohair@286 178 *
ohair@286 179 * @return empty Map if there is no parts
ohair@286 180 */
ohair@286 181 public Map<String, String> getOutputMimeTypes() {
ohair@286 182 return outputMimeTypes;
ohair@286 183 }
ohair@286 184
ohair@286 185 /**
ohair@286 186 * Map of mime:content@part and the mime type from mime:content@type for wsdl:fault
ohair@286 187 *
ohair@286 188 * @return empty Map if there is no parts
ohair@286 189 */
ohair@286 190 public Map<String, String> getFaultMimeTypes() {
ohair@286 191 return faultMimeTypes;
ohair@286 192 }
ohair@286 193
ohair@286 194 /**
ohair@286 195 * Gets {@link ParameterBinding} for a given wsdl part in wsdl:input
ohair@286 196 *
ohair@286 197 * @param part Name of wsdl:part, must be non-null
ohair@286 198 * @return null if the part is not found.
ohair@286 199 */
ohair@286 200 public ParameterBinding getInputBinding(String part){
ohair@286 201 if(emptyInputBody == null){
ohair@286 202 if(inputParts.get(" ") != null)
ohair@286 203 emptyInputBody = true;
ohair@286 204 else
ohair@286 205 emptyInputBody = false;
ohair@286 206 }
ohair@286 207 ParameterBinding block = inputParts.get(part);
ohair@286 208 if(block == null){
ohair@286 209 if(explicitInputSOAPBodyParts || emptyInputBody)
ohair@286 210 return ParameterBinding.UNBOUND;
ohair@286 211 return ParameterBinding.BODY;
ohair@286 212 }
ohair@286 213
ohair@286 214 return block;
ohair@286 215 }
ohair@286 216
ohair@286 217 /**
ohair@286 218 * Gets {@link ParameterBinding} for a given wsdl part in wsdl:output
ohair@286 219 *
ohair@286 220 * @param part Name of wsdl:part, must be non-null
ohair@286 221 * @return null if the part is not found.
ohair@286 222 */
ohair@286 223 public ParameterBinding getOutputBinding(String part){
ohair@286 224 if(emptyOutputBody == null){
ohair@286 225 if(outputParts.get(" ") != null)
ohair@286 226 emptyOutputBody = true;
ohair@286 227 else
ohair@286 228 emptyOutputBody = false;
ohair@286 229 }
ohair@286 230 ParameterBinding block = outputParts.get(part);
ohair@286 231 if(block == null){
ohair@286 232 if(explicitOutputSOAPBodyParts || emptyOutputBody)
ohair@286 233 return ParameterBinding.UNBOUND;
ohair@286 234 return ParameterBinding.BODY;
ohair@286 235 }
ohair@286 236
ohair@286 237 return block;
ohair@286 238 }
ohair@286 239
ohair@286 240 /**
ohair@286 241 * Gets {@link ParameterBinding} for a given wsdl part in wsdl:fault
ohair@286 242 *
ohair@286 243 * @param part Name of wsdl:part, must be non-null
ohair@286 244 * @return null if the part is not found.
ohair@286 245 */
ohair@286 246 public ParameterBinding getFaultBinding(String part){
ohair@286 247 if(emptyFaultBody == null){
ohair@286 248 if(faultParts.get(" ") != null)
ohair@286 249 emptyFaultBody = true;
ohair@286 250 else
ohair@286 251 emptyFaultBody = false;
ohair@286 252 }
ohair@286 253 ParameterBinding block = faultParts.get(part);
ohair@286 254 if(block == null){
ohair@286 255 if(explicitFaultSOAPBodyParts || emptyFaultBody)
ohair@286 256 return ParameterBinding.UNBOUND;
ohair@286 257 return ParameterBinding.BODY;
ohair@286 258 }
ohair@286 259
ohair@286 260 return block;
ohair@286 261 }
ohair@286 262
ohair@286 263 /**
ohair@286 264 * Gets the MIME type for a given wsdl part in wsdl:input
ohair@286 265 *
ohair@286 266 * @param part Name of wsdl:part, must be non-null
ohair@286 267 * @return null if the part is not found.
ohair@286 268 */
ohair@286 269 public String getMimeTypeForInputPart(String part){
ohair@286 270 return inputMimeTypes.get(part);
ohair@286 271 }
ohair@286 272
ohair@286 273 /**
ohair@286 274 * Gets the MIME type for a given wsdl part in wsdl:output
ohair@286 275 *
ohair@286 276 * @param part Name of wsdl:part, must be non-null
ohair@286 277 * @return null if the part is not found.
ohair@286 278 */
ohair@286 279 public String getMimeTypeForOutputPart(String part){
ohair@286 280 return outputMimeTypes.get(part);
ohair@286 281 }
ohair@286 282
ohair@286 283 /**
ohair@286 284 * Gets the MIME type for a given wsdl part in wsdl:fault
ohair@286 285 *
ohair@286 286 * @param part Name of wsdl:part, must be non-null
ohair@286 287 * @return null if the part is not found.
ohair@286 288 */
ohair@286 289 public String getMimeTypeForFaultPart(String part){
ohair@286 290 return faultMimeTypes.get(part);
ohair@286 291 }
ohair@286 292
ohair@286 293 public WSDLOperationImpl getOperation() {
ohair@286 294 return operation;
ohair@286 295 }
ohair@286 296
ohair@286 297
ohair@286 298 public WSDLBoundPortType getBoundPortType() {
ohair@286 299 return owner;
ohair@286 300 }
ohair@286 301
ohair@286 302 public void setInputExplicitBodyParts(boolean b) {
ohair@286 303 explicitInputSOAPBodyParts = b;
ohair@286 304 }
ohair@286 305
ohair@286 306 public void setOutputExplicitBodyParts(boolean b) {
ohair@286 307 explicitOutputSOAPBodyParts = b;
ohair@286 308 }
ohair@286 309
ohair@286 310 public void setFaultExplicitBodyParts(boolean b) {
ohair@286 311 explicitFaultSOAPBodyParts = b;
ohair@286 312 }
ohair@286 313
ohair@286 314 private Style style = Style.DOCUMENT;
ohair@286 315 public void setStyle(Style style){
ohair@286 316 this.style = style;
ohair@286 317 }
ohair@286 318
ohair@286 319 public @Nullable QName getReqPayloadName() {
ohair@286 320 if (emptyRequestPayload)
ohair@286 321 return null;
ohair@286 322
ohair@286 323 if (requestPayloadName != null)
ohair@286 324 return requestPayloadName;
ohair@286 325
ohair@286 326 if(style.equals(Style.RPC)){
ohair@286 327 String ns = getRequestNamespace() != null ? getRequestNamespace() : name.getNamespaceURI();
ohair@286 328 requestPayloadName = new QName(ns, name.getLocalPart());
ohair@286 329 return requestPayloadName;
ohair@286 330 }else{
ohair@286 331 QName inMsgName = operation.getInput().getMessage().getName();
ohair@286 332 WSDLMessageImpl message = messages.get(inMsgName);
ohair@286 333 for(WSDLPartImpl part:message.parts()){
ohair@286 334 ParameterBinding binding = getInputBinding(part.getName());
ohair@286 335 if(binding.isBody()){
ohair@286 336 requestPayloadName = part.getDescriptor().name();
ohair@286 337 return requestPayloadName;
ohair@286 338 }
ohair@286 339 }
ohair@286 340
ohair@286 341 //Its empty payload
ohair@286 342 emptyRequestPayload = true;
ohair@286 343 }
ohair@286 344 //empty body
ohair@286 345 return null;
ohair@286 346 }
ohair@286 347
ohair@286 348 public @Nullable QName getResPayloadName() {
ohair@286 349 if (emptyResponsePayload)
ohair@286 350 return null;
ohair@286 351
ohair@286 352 if (responsePayloadName != null)
ohair@286 353 return responsePayloadName;
ohair@286 354
ohair@286 355 if(style.equals(Style.RPC)){
ohair@286 356 String ns = getResponseNamespace() != null ? getResponseNamespace() : name.getNamespaceURI();
ohair@286 357 responsePayloadName = new QName(ns, name.getLocalPart()+"Response");
ohair@286 358 return responsePayloadName;
ohair@286 359 }else{
ohair@286 360 QName outMsgName = operation.getOutput().getMessage().getName();
ohair@286 361 WSDLMessageImpl message = messages.get(outMsgName);
ohair@286 362 for(WSDLPartImpl part:message.parts()){
ohair@286 363 ParameterBinding binding = getOutputBinding(part.getName());
ohair@286 364 if(binding.isBody()){
ohair@286 365 responsePayloadName = part.getDescriptor().name();
ohair@286 366 return responsePayloadName;
ohair@286 367 }
ohair@286 368 }
ohair@286 369
ohair@286 370 //Its empty payload
ohair@286 371 emptyResponsePayload = true;
ohair@286 372 }
ohair@286 373 //empty body
ohair@286 374 return null;
ohair@286 375 }
ohair@286 376
ohair@286 377
ohair@286 378 private String reqNamespace;
ohair@286 379 private String respNamespace;
ohair@286 380
ohair@286 381 /**
ohair@286 382 * For rpclit gives namespace value on soapbinding:body@namespace
ohair@286 383 *
ohair@286 384 * @return non-null for rpclit and null for doclit
ohair@286 385 * @see com.sun.xml.internal.ws.model.RuntimeModeler#processRpcMethod(com.sun.xml.internal.ws.model.JavaMethodImpl, String, javax.jws.WebMethod, String, java.lang.reflect.Method, javax.jws.WebService)
ohair@286 386 */
ohair@286 387 public String getRequestNamespace(){
ohair@286 388 return (reqNamespace != null)?reqNamespace:name.getNamespaceURI();
ohair@286 389 }
ohair@286 390
ohair@286 391 public void setRequestNamespace(String ns){
ohair@286 392 reqNamespace = ns;
ohair@286 393 }
ohair@286 394
ohair@286 395
ohair@286 396 /**
ohair@286 397 * For rpclit gives namespace value on soapbinding:body@namespace
ohair@286 398 *
ohair@286 399 * @return non-null for rpclit and null for doclit
ohair@286 400 * * @see com.sun.xml.internal.ws.modeler.RuntimeModeler#processRpcMethod(com.sun.xml.internal.ws.model.JavaMethod, String, javax.jws.WebMethod, String, java.lang.reflect.Method, javax.jws.WebService)
ohair@286 401 */
ohair@286 402 public String getResponseNamespace(){
ohair@286 403 return (respNamespace!=null)?respNamespace:name.getNamespaceURI();
ohair@286 404 }
ohair@286 405
ohair@286 406 public void setResponseNamespace(String ns){
ohair@286 407 respNamespace = ns;
ohair@286 408 }
ohair@286 409
ohair@286 410 WSDLBoundPortTypeImpl getOwner(){
ohair@286 411 return owner;
ohair@286 412 }
ohair@286 413
ohair@286 414 private QName requestPayloadName;
ohair@286 415 private QName responsePayloadName;
ohair@286 416 private boolean emptyRequestPayload;
ohair@286 417 private boolean emptyResponsePayload;
ohair@286 418 private Map<QName, WSDLMessageImpl> messages;
ohair@286 419
ohair@286 420 void freeze(WSDLModelImpl parent) {
ohair@286 421 messages = parent.getMessages();
ohair@286 422 operation = owner.getPortType().get(name.getLocalPart());
ohair@286 423 for(WSDLBoundFaultImpl bf : wsdlBoundFaults){
ohair@286 424 bf.freeze(this);
ohair@286 425 }
ohair@286 426 }
ohair@286 427
ohair@286 428 public void setAnonymous(ANONYMOUS anonymous) {
ohair@286 429 this.anonymous = anonymous;
ohair@286 430 }
ohair@286 431
ohair@286 432 /**
ohair@286 433 * @inheritDoc
ohair@286 434 */
ohair@286 435 public ANONYMOUS getAnonymous() {
ohair@286 436 return anonymous;
ohair@286 437 }
ohair@286 438 }

mercurial