1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/model/wsdl/WSDLBoundOperationImpl.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,430 @@ 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.model.wsdl; 1.30 + 1.31 +import com.sun.istack.internal.Nullable; 1.32 +import com.sun.istack.internal.NotNull; 1.33 +import com.sun.xml.internal.ws.api.model.ParameterBinding; 1.34 +import com.sun.xml.internal.ws.api.model.wsdl.*; 1.35 +import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLBoundFault; 1.36 +import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLBoundOperation; 1.37 +import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLBoundPortType; 1.38 +import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLMessage; 1.39 +import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLModel; 1.40 +import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLOperation; 1.41 +import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLPart; 1.42 +import com.sun.xml.internal.ws.model.RuntimeModeler; 1.43 + 1.44 +import javax.jws.WebParam.Mode; 1.45 +import javax.jws.soap.SOAPBinding.Style; 1.46 +import javax.xml.namespace.QName; 1.47 +import javax.xml.stream.XMLStreamReader; 1.48 + 1.49 +import java.util.*; 1.50 + 1.51 +/** 1.52 + * Implementation of {@link WSDLBoundOperation} 1.53 + * 1.54 + * @author Vivek Pandey 1.55 + */ 1.56 +public final class WSDLBoundOperationImpl extends AbstractExtensibleImpl implements EditableWSDLBoundOperation { 1.57 + private final QName name; 1.58 + 1.59 + // map of wsdl:part to the binding 1.60 + private final Map<String, ParameterBinding> inputParts; 1.61 + private final Map<String, ParameterBinding> outputParts; 1.62 + private final Map<String, ParameterBinding> faultParts; 1.63 + private final Map<String, String> inputMimeTypes; 1.64 + private final Map<String, String> outputMimeTypes; 1.65 + private final Map<String, String> faultMimeTypes; 1.66 + 1.67 + private boolean explicitInputSOAPBodyParts = false; 1.68 + private boolean explicitOutputSOAPBodyParts = false; 1.69 + private boolean explicitFaultSOAPBodyParts = false; 1.70 + 1.71 + private Boolean emptyInputBody; 1.72 + private Boolean emptyOutputBody; 1.73 + private Boolean emptyFaultBody; 1.74 + 1.75 + private final Map<String, EditableWSDLPart> inParts; 1.76 + private final Map<String, EditableWSDLPart> outParts; 1.77 + private final List<EditableWSDLBoundFault> wsdlBoundFaults; 1.78 + private EditableWSDLOperation operation; 1.79 + private String soapAction; 1.80 + private ANONYMOUS anonymous; 1.81 + 1.82 + private final EditableWSDLBoundPortType owner; 1.83 + 1.84 + /** 1.85 + * 1.86 + * @param name wsdl:operation name qualified value 1.87 + */ 1.88 + public WSDLBoundOperationImpl(XMLStreamReader xsr, EditableWSDLBoundPortType owner, QName name) { 1.89 + super(xsr); 1.90 + this.name = name; 1.91 + inputParts = new HashMap<String, ParameterBinding>(); 1.92 + outputParts = new HashMap<String, ParameterBinding>(); 1.93 + faultParts = new HashMap<String, ParameterBinding>(); 1.94 + inputMimeTypes = new HashMap<String, String>(); 1.95 + outputMimeTypes = new HashMap<String, String>(); 1.96 + faultMimeTypes = new HashMap<String, String>(); 1.97 + inParts = new HashMap<String, EditableWSDLPart>(); 1.98 + outParts = new HashMap<String, EditableWSDLPart>(); 1.99 + wsdlBoundFaults = new ArrayList<EditableWSDLBoundFault>(); 1.100 + this.owner = owner; 1.101 + } 1.102 + 1.103 + @Override 1.104 + public QName getName(){ 1.105 + return name; 1.106 + } 1.107 + 1.108 + @Override 1.109 + public String getSOAPAction() { 1.110 + return soapAction; 1.111 + } 1.112 + 1.113 + public void setSoapAction(String soapAction) { 1.114 + this.soapAction = soapAction!=null?soapAction:""; 1.115 + } 1.116 + 1.117 + @Override 1.118 + public EditableWSDLPart getPart(String partName, Mode mode) { 1.119 + if(mode==Mode.IN){ 1.120 + return inParts.get(partName); 1.121 + }else if(mode==Mode.OUT){ 1.122 + return outParts.get(partName); 1.123 + } 1.124 + return null; 1.125 + } 1.126 + 1.127 + public void addPart(EditableWSDLPart part, Mode mode){ 1.128 + if(mode==Mode.IN) 1.129 + inParts.put(part.getName(), part); 1.130 + else if(mode==Mode.OUT) 1.131 + outParts.put(part.getName(), part); 1.132 + } 1.133 + 1.134 + /** 1.135 + * Map of wsdl:input part name and the binding as {@link ParameterBinding} 1.136 + * 1.137 + * @return empty Map if there is no parts 1.138 + */ 1.139 + public Map<String, ParameterBinding> getInputParts() { 1.140 + return inputParts; 1.141 + } 1.142 + 1.143 + /** 1.144 + * Map of wsdl:output part name and the binding as {@link ParameterBinding} 1.145 + * 1.146 + * @return empty Map if there is no parts 1.147 + */ 1.148 + public Map<String, ParameterBinding> getOutputParts() { 1.149 + return outputParts; 1.150 + } 1.151 + 1.152 + /** 1.153 + * Map of wsdl:fault part name and the binding as {@link ParameterBinding} 1.154 + * 1.155 + * @return empty Map if there is no parts 1.156 + */ 1.157 + public Map<String, ParameterBinding> getFaultParts() { 1.158 + return faultParts; 1.159 + } 1.160 + 1.161 + // TODO: what's the difference between this and inputParts/outputParts? 1.162 + @Override 1.163 + public Map<String, ? extends EditableWSDLPart> getInParts() { 1.164 + return Collections.<String, EditableWSDLPart>unmodifiableMap(inParts); 1.165 + } 1.166 + 1.167 + @Override 1.168 + public Map<String, ? extends EditableWSDLPart> getOutParts() { 1.169 + return Collections.<String, EditableWSDLPart>unmodifiableMap(outParts); 1.170 + } 1.171 + 1.172 + @NotNull 1.173 + @Override 1.174 + public List<? extends EditableWSDLBoundFault> getFaults() { 1.175 + return wsdlBoundFaults; 1.176 + } 1.177 + 1.178 + public void addFault(@NotNull EditableWSDLBoundFault fault){ 1.179 + wsdlBoundFaults.add(fault); 1.180 + } 1.181 + 1.182 + 1.183 + /** 1.184 + * Gets {@link ParameterBinding} for a given wsdl part in wsdl:input 1.185 + * 1.186 + * @param part Name of wsdl:part, must be non-null 1.187 + * @return null if the part is not found. 1.188 + */ 1.189 + public ParameterBinding getInputBinding(String part){ 1.190 + if(emptyInputBody == null){ 1.191 + if(inputParts.get(" ") != null) 1.192 + emptyInputBody = true; 1.193 + else 1.194 + emptyInputBody = false; 1.195 + } 1.196 + ParameterBinding block = inputParts.get(part); 1.197 + if(block == null){ 1.198 + if(explicitInputSOAPBodyParts || emptyInputBody) 1.199 + return ParameterBinding.UNBOUND; 1.200 + return ParameterBinding.BODY; 1.201 + } 1.202 + 1.203 + return block; 1.204 + } 1.205 + 1.206 + /** 1.207 + * Gets {@link ParameterBinding} for a given wsdl part in wsdl:output 1.208 + * 1.209 + * @param part Name of wsdl:part, must be non-null 1.210 + * @return null if the part is not found. 1.211 + */ 1.212 + public ParameterBinding getOutputBinding(String part){ 1.213 + if(emptyOutputBody == null){ 1.214 + if(outputParts.get(" ") != null) 1.215 + emptyOutputBody = true; 1.216 + else 1.217 + emptyOutputBody = false; 1.218 + } 1.219 + ParameterBinding block = outputParts.get(part); 1.220 + if(block == null){ 1.221 + if(explicitOutputSOAPBodyParts || emptyOutputBody) 1.222 + return ParameterBinding.UNBOUND; 1.223 + return ParameterBinding.BODY; 1.224 + } 1.225 + 1.226 + return block; 1.227 + } 1.228 + 1.229 + /** 1.230 + * Gets {@link ParameterBinding} for a given wsdl part in wsdl:fault 1.231 + * 1.232 + * @param part Name of wsdl:part, must be non-null 1.233 + * @return null if the part is not found. 1.234 + */ 1.235 + public ParameterBinding getFaultBinding(String part){ 1.236 + if(emptyFaultBody == null){ 1.237 + if(faultParts.get(" ") != null) 1.238 + emptyFaultBody = true; 1.239 + else 1.240 + emptyFaultBody = false; 1.241 + } 1.242 + ParameterBinding block = faultParts.get(part); 1.243 + if(block == null){ 1.244 + if(explicitFaultSOAPBodyParts || emptyFaultBody) 1.245 + return ParameterBinding.UNBOUND; 1.246 + return ParameterBinding.BODY; 1.247 + } 1.248 + 1.249 + return block; 1.250 + } 1.251 + 1.252 + /** 1.253 + * Gets the MIME type for a given wsdl part in wsdl:input 1.254 + * 1.255 + * @param part Name of wsdl:part, must be non-null 1.256 + * @return null if the part is not found. 1.257 + */ 1.258 + public String getMimeTypeForInputPart(String part){ 1.259 + return inputMimeTypes.get(part); 1.260 + } 1.261 + 1.262 + /** 1.263 + * Gets the MIME type for a given wsdl part in wsdl:output 1.264 + * 1.265 + * @param part Name of wsdl:part, must be non-null 1.266 + * @return null if the part is not found. 1.267 + */ 1.268 + public String getMimeTypeForOutputPart(String part){ 1.269 + return outputMimeTypes.get(part); 1.270 + } 1.271 + 1.272 + /** 1.273 + * Gets the MIME type for a given wsdl part in wsdl:fault 1.274 + * 1.275 + * @param part Name of wsdl:part, must be non-null 1.276 + * @return null if the part is not found. 1.277 + */ 1.278 + public String getMimeTypeForFaultPart(String part){ 1.279 + return faultMimeTypes.get(part); 1.280 + } 1.281 + 1.282 + @Override 1.283 + public EditableWSDLOperation getOperation() { 1.284 + return operation; 1.285 + } 1.286 + 1.287 + 1.288 + @Override 1.289 + public EditableWSDLBoundPortType getBoundPortType() { 1.290 + return owner; 1.291 + } 1.292 + 1.293 + public void setInputExplicitBodyParts(boolean b) { 1.294 + explicitInputSOAPBodyParts = b; 1.295 + } 1.296 + 1.297 + public void setOutputExplicitBodyParts(boolean b) { 1.298 + explicitOutputSOAPBodyParts = b; 1.299 + } 1.300 + 1.301 + public void setFaultExplicitBodyParts(boolean b) { 1.302 + explicitFaultSOAPBodyParts = b; 1.303 + } 1.304 + 1.305 + private Style style = Style.DOCUMENT; 1.306 + public void setStyle(Style style){ 1.307 + this.style = style; 1.308 + } 1.309 + 1.310 + @Override 1.311 + public @Nullable QName getRequestPayloadName() { 1.312 + if (emptyRequestPayload) 1.313 + return null; 1.314 + 1.315 + if (requestPayloadName != null) 1.316 + return requestPayloadName; 1.317 + 1.318 + if(style.equals(Style.RPC)){ 1.319 + String ns = getRequestNamespace() != null ? getRequestNamespace() : name.getNamespaceURI(); 1.320 + requestPayloadName = new QName(ns, name.getLocalPart()); 1.321 + return requestPayloadName; 1.322 + }else{ 1.323 + QName inMsgName = operation.getInput().getMessage().getName(); 1.324 + EditableWSDLMessage message = messages.get(inMsgName); 1.325 + for(EditableWSDLPart part:message.parts()){ 1.326 + ParameterBinding binding = getInputBinding(part.getName()); 1.327 + if(binding.isBody()){ 1.328 + requestPayloadName = part.getDescriptor().name(); 1.329 + return requestPayloadName; 1.330 + } 1.331 + } 1.332 + 1.333 + //Its empty payload 1.334 + emptyRequestPayload = true; 1.335 + } 1.336 + //empty body 1.337 + return null; 1.338 + } 1.339 + 1.340 + @Override 1.341 + public @Nullable QName getResponsePayloadName() { 1.342 + if (emptyResponsePayload) 1.343 + return null; 1.344 + 1.345 + if (responsePayloadName != null) 1.346 + return responsePayloadName; 1.347 + 1.348 + if(style.equals(Style.RPC)){ 1.349 + String ns = getResponseNamespace() != null ? getResponseNamespace() : name.getNamespaceURI(); 1.350 + responsePayloadName = new QName(ns, name.getLocalPart()+"Response"); 1.351 + return responsePayloadName; 1.352 + }else{ 1.353 + QName outMsgName = operation.getOutput().getMessage().getName(); 1.354 + EditableWSDLMessage message = messages.get(outMsgName); 1.355 + for(EditableWSDLPart part:message.parts()){ 1.356 + ParameterBinding binding = getOutputBinding(part.getName()); 1.357 + if(binding.isBody()){ 1.358 + responsePayloadName = part.getDescriptor().name(); 1.359 + return responsePayloadName; 1.360 + } 1.361 + } 1.362 + 1.363 + //Its empty payload 1.364 + emptyResponsePayload = true; 1.365 + } 1.366 + //empty body 1.367 + return null; 1.368 + } 1.369 + 1.370 + 1.371 + private String reqNamespace; 1.372 + private String respNamespace; 1.373 + 1.374 + /** 1.375 + * For rpclit gives namespace value on soapbinding:body@namespace 1.376 + * 1.377 + * @return non-null for rpclit and null for doclit 1.378 + * @see RuntimeModeler#processRpcMethod(JavaMethodImpl, String, String, Method) 1.379 + */ 1.380 + @Override 1.381 + public String getRequestNamespace(){ 1.382 + return (reqNamespace != null)?reqNamespace:name.getNamespaceURI(); 1.383 + } 1.384 + 1.385 + public void setRequestNamespace(String ns){ 1.386 + reqNamespace = ns; 1.387 + } 1.388 + 1.389 + /** 1.390 + * For rpclit gives namespace value on soapbinding:body@namespace 1.391 + * 1.392 + * @return non-null for rpclit and null for doclit 1.393 + * @see RuntimeModeler#processRpcMethod(JavaMethodImpl, String, String, Method) 1.394 + */ 1.395 + @Override 1.396 + public String getResponseNamespace(){ 1.397 + return (respNamespace!=null)?respNamespace:name.getNamespaceURI(); 1.398 + } 1.399 + 1.400 + public void setResponseNamespace(String ns){ 1.401 + respNamespace = ns; 1.402 + } 1.403 + 1.404 + EditableWSDLBoundPortType getOwner(){ 1.405 + return owner; 1.406 + } 1.407 + 1.408 + private QName requestPayloadName; 1.409 + private QName responsePayloadName; 1.410 + private boolean emptyRequestPayload; 1.411 + private boolean emptyResponsePayload; 1.412 + private Map<QName, ? extends EditableWSDLMessage> messages; 1.413 + 1.414 + public void freeze(EditableWSDLModel parent) { 1.415 + messages = parent.getMessages(); 1.416 + operation = owner.getPortType().get(name.getLocalPart()); 1.417 + for(EditableWSDLBoundFault bf : wsdlBoundFaults){ 1.418 + bf.freeze(this); 1.419 + } 1.420 + } 1.421 + 1.422 + public void setAnonymous(ANONYMOUS anonymous) { 1.423 + this.anonymous = anonymous; 1.424 + } 1.425 + 1.426 + /** 1.427 + * @inheritDoc 1.428 + */ 1.429 + @Override 1.430 + public ANONYMOUS getAnonymous() { 1.431 + return anonymous; 1.432 + } 1.433 +}