Tue, 09 Apr 2013 14:51:13 +0100
8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com
1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.xml.internal.ws.model.wsdl;
28 import com.sun.istack.internal.Nullable;
29 import com.sun.istack.internal.NotNull;
30 import com.sun.xml.internal.ws.api.model.ParameterBinding;
31 import com.sun.xml.internal.ws.api.model.wsdl.*;
32 import com.sun.xml.internal.ws.model.RuntimeModeler;
34 import javax.jws.WebParam.Mode;
35 import javax.jws.soap.SOAPBinding.Style;
36 import javax.xml.namespace.QName;
37 import javax.xml.stream.XMLStreamReader;
38 import java.util.*;
40 /**
41 * Implementation of {@link WSDLBoundOperation}
42 *
43 * @author Vivek Pandey
44 */
45 public final class WSDLBoundOperationImpl extends AbstractExtensibleImpl implements WSDLBoundOperation {
46 private final QName name;
48 // map of wsdl:part to the binding
49 private final Map<String, ParameterBinding> inputParts;
50 private final Map<String, ParameterBinding> outputParts;
51 private final Map<String, ParameterBinding> faultParts;
52 private final Map<String, String> inputMimeTypes;
53 private final Map<String, String> outputMimeTypes;
54 private final Map<String, String> faultMimeTypes;
56 private boolean explicitInputSOAPBodyParts = false;
57 private boolean explicitOutputSOAPBodyParts = false;
58 private boolean explicitFaultSOAPBodyParts = false;
60 private Boolean emptyInputBody;
61 private Boolean emptyOutputBody;
62 private Boolean emptyFaultBody;
64 private final Map<String, WSDLPartImpl> inParts;
65 private final Map<String, WSDLPartImpl> outParts;
66 private final Map<String, WSDLPartImpl> fltParts;
67 private final List<WSDLBoundFaultImpl> wsdlBoundFaults;
68 private WSDLOperationImpl operation;
69 private String soapAction;
70 private ANONYMOUS anonymous;
72 private final WSDLBoundPortTypeImpl owner;
74 /**
75 *
76 * @param name wsdl:operation name qualified value
77 */
78 public WSDLBoundOperationImpl(XMLStreamReader xsr, WSDLBoundPortTypeImpl owner, QName name) {
79 super(xsr);
80 this.name = name;
81 inputParts = new HashMap<String, ParameterBinding>();
82 outputParts = new HashMap<String, ParameterBinding>();
83 faultParts = new HashMap<String, ParameterBinding>();
84 inputMimeTypes = new HashMap<String, String>();
85 outputMimeTypes = new HashMap<String, String>();
86 faultMimeTypes = new HashMap<String, String>();
87 inParts = new HashMap<String, WSDLPartImpl>();
88 outParts = new HashMap<String, WSDLPartImpl>();
89 fltParts = new HashMap<String, WSDLPartImpl>();
90 wsdlBoundFaults = new ArrayList<WSDLBoundFaultImpl>();
91 this.owner = owner;
92 }
94 public QName getName(){
95 return name;
96 }
98 public String getSOAPAction() {
99 return soapAction;
100 }
102 public void setSoapAction(String soapAction) {
103 this.soapAction = soapAction!=null?soapAction:"";
104 }
106 public WSDLPartImpl getPart(String partName, Mode mode) {
107 if(mode==Mode.IN){
108 return inParts.get(partName);
109 }else if(mode==Mode.OUT){
110 return outParts.get(partName);
111 }
112 return null;
113 }
115 public void addPart(WSDLPartImpl part, Mode mode){
116 if(mode==Mode.IN)
117 inParts.put(part.getName(), part);
118 else if(mode==Mode.OUT)
119 outParts.put(part.getName(), part);
120 }
122 /**
123 * Map of wsdl:input part name and the binding as {@link ParameterBinding}
124 *
125 * @return empty Map if there is no parts
126 */
127 public Map<String, ParameterBinding> getInputParts() {
128 return inputParts;
129 }
131 /**
132 * Map of wsdl:output part name and the binding as {@link ParameterBinding}
133 *
134 * @return empty Map if there is no parts
135 */
136 public Map<String, ParameterBinding> getOutputParts() {
137 return outputParts;
138 }
140 /**
141 * Map of wsdl:fault part name and the binding as {@link ParameterBinding}
142 *
143 * @return empty Map if there is no parts
144 */
145 public Map<String, ParameterBinding> getFaultParts() {
146 return faultParts;
147 }
149 // TODO: what's the difference between this and inputParts/outputParts?
150 public Map<String,WSDLPart> getInParts() {
151 return Collections.<String,WSDLPart>unmodifiableMap(inParts);
152 }
154 public Map<String,WSDLPart> getOutParts() {
155 return Collections.<String,WSDLPart>unmodifiableMap(outParts);
156 }
158 @NotNull
159 public List<WSDLBoundFaultImpl> getFaults() {
160 return wsdlBoundFaults;
161 }
163 public void addFault(@NotNull WSDLBoundFaultImpl fault){
164 wsdlBoundFaults.add(fault);
165 }
168 /**
169 * Map of mime:content@part and the mime type from mime:content@type for wsdl:output
170 *
171 * @return empty Map if there is no parts
172 */
173 public Map<String, String> getInputMimeTypes() {
174 return inputMimeTypes;
175 }
177 /**
178 * Map of mime:content@part and the mime type from mime:content@type for wsdl:output
179 *
180 * @return empty Map if there is no parts
181 */
182 public Map<String, String> getOutputMimeTypes() {
183 return outputMimeTypes;
184 }
186 /**
187 * Map of mime:content@part and the mime type from mime:content@type for wsdl:fault
188 *
189 * @return empty Map if there is no parts
190 */
191 public Map<String, String> getFaultMimeTypes() {
192 return faultMimeTypes;
193 }
195 /**
196 * Gets {@link ParameterBinding} for a given wsdl part in wsdl:input
197 *
198 * @param part Name of wsdl:part, must be non-null
199 * @return null if the part is not found.
200 */
201 public ParameterBinding getInputBinding(String part){
202 if(emptyInputBody == null){
203 if(inputParts.get(" ") != null)
204 emptyInputBody = true;
205 else
206 emptyInputBody = false;
207 }
208 ParameterBinding block = inputParts.get(part);
209 if(block == null){
210 if(explicitInputSOAPBodyParts || emptyInputBody)
211 return ParameterBinding.UNBOUND;
212 return ParameterBinding.BODY;
213 }
215 return block;
216 }
218 /**
219 * Gets {@link ParameterBinding} for a given wsdl part in wsdl:output
220 *
221 * @param part Name of wsdl:part, must be non-null
222 * @return null if the part is not found.
223 */
224 public ParameterBinding getOutputBinding(String part){
225 if(emptyOutputBody == null){
226 if(outputParts.get(" ") != null)
227 emptyOutputBody = true;
228 else
229 emptyOutputBody = false;
230 }
231 ParameterBinding block = outputParts.get(part);
232 if(block == null){
233 if(explicitOutputSOAPBodyParts || emptyOutputBody)
234 return ParameterBinding.UNBOUND;
235 return ParameterBinding.BODY;
236 }
238 return block;
239 }
241 /**
242 * Gets {@link ParameterBinding} for a given wsdl part in wsdl:fault
243 *
244 * @param part Name of wsdl:part, must be non-null
245 * @return null if the part is not found.
246 */
247 public ParameterBinding getFaultBinding(String part){
248 if(emptyFaultBody == null){
249 if(faultParts.get(" ") != null)
250 emptyFaultBody = true;
251 else
252 emptyFaultBody = false;
253 }
254 ParameterBinding block = faultParts.get(part);
255 if(block == null){
256 if(explicitFaultSOAPBodyParts || emptyFaultBody)
257 return ParameterBinding.UNBOUND;
258 return ParameterBinding.BODY;
259 }
261 return block;
262 }
264 /**
265 * Gets the MIME type for a given wsdl part in wsdl:input
266 *
267 * @param part Name of wsdl:part, must be non-null
268 * @return null if the part is not found.
269 */
270 public String getMimeTypeForInputPart(String part){
271 return inputMimeTypes.get(part);
272 }
274 /**
275 * Gets the MIME type for a given wsdl part in wsdl:output
276 *
277 * @param part Name of wsdl:part, must be non-null
278 * @return null if the part is not found.
279 */
280 public String getMimeTypeForOutputPart(String part){
281 return outputMimeTypes.get(part);
282 }
284 /**
285 * Gets the MIME type for a given wsdl part in wsdl:fault
286 *
287 * @param part Name of wsdl:part, must be non-null
288 * @return null if the part is not found.
289 */
290 public String getMimeTypeForFaultPart(String part){
291 return faultMimeTypes.get(part);
292 }
294 public WSDLOperationImpl getOperation() {
295 return operation;
296 }
299 public WSDLBoundPortType getBoundPortType() {
300 return owner;
301 }
303 public void setInputExplicitBodyParts(boolean b) {
304 explicitInputSOAPBodyParts = b;
305 }
307 public void setOutputExplicitBodyParts(boolean b) {
308 explicitOutputSOAPBodyParts = b;
309 }
311 public void setFaultExplicitBodyParts(boolean b) {
312 explicitFaultSOAPBodyParts = b;
313 }
315 private Style style = Style.DOCUMENT;
316 public void setStyle(Style style){
317 this.style = style;
318 }
320 public @Nullable QName getReqPayloadName() {
321 if (emptyRequestPayload)
322 return null;
324 if (requestPayloadName != null)
325 return requestPayloadName;
327 if(style.equals(Style.RPC)){
328 String ns = getRequestNamespace() != null ? getRequestNamespace() : name.getNamespaceURI();
329 requestPayloadName = new QName(ns, name.getLocalPart());
330 return requestPayloadName;
331 }else{
332 QName inMsgName = operation.getInput().getMessage().getName();
333 WSDLMessageImpl message = messages.get(inMsgName);
334 for(WSDLPartImpl part:message.parts()){
335 ParameterBinding binding = getInputBinding(part.getName());
336 if(binding.isBody()){
337 requestPayloadName = part.getDescriptor().name();
338 return requestPayloadName;
339 }
340 }
342 //Its empty payload
343 emptyRequestPayload = true;
344 }
345 //empty body
346 return null;
347 }
349 public @Nullable QName getResPayloadName() {
350 if (emptyResponsePayload)
351 return null;
353 if (responsePayloadName != null)
354 return responsePayloadName;
356 if(style.equals(Style.RPC)){
357 String ns = getResponseNamespace() != null ? getResponseNamespace() : name.getNamespaceURI();
358 responsePayloadName = new QName(ns, name.getLocalPart()+"Response");
359 return responsePayloadName;
360 }else{
361 QName outMsgName = operation.getOutput().getMessage().getName();
362 WSDLMessageImpl message = messages.get(outMsgName);
363 for(WSDLPartImpl part:message.parts()){
364 ParameterBinding binding = getOutputBinding(part.getName());
365 if(binding.isBody()){
366 responsePayloadName = part.getDescriptor().name();
367 return responsePayloadName;
368 }
369 }
371 //Its empty payload
372 emptyResponsePayload = true;
373 }
374 //empty body
375 return null;
376 }
379 private String reqNamespace;
380 private String respNamespace;
382 /**
383 * For rpclit gives namespace value on soapbinding:body@namespace
384 *
385 * @return non-null for rpclit and null for doclit
386 * @see RuntimeModeler#processRpcMethod(JavaMethodImpl, String, String, Method)
387 */
388 public String getRequestNamespace(){
389 return (reqNamespace != null)?reqNamespace:name.getNamespaceURI();
390 }
392 public void setRequestNamespace(String ns){
393 reqNamespace = ns;
394 }
397 /**
398 * For rpclit gives namespace value on soapbinding:body@namespace
399 *
400 * @return non-null for rpclit and null for doclit
401 * @see RuntimeModeler#processRpcMethod(JavaMethodImpl, String, String, Method)
402 */
403 public String getResponseNamespace(){
404 return (respNamespace!=null)?respNamespace:name.getNamespaceURI();
405 }
407 public void setResponseNamespace(String ns){
408 respNamespace = ns;
409 }
411 WSDLBoundPortTypeImpl getOwner(){
412 return owner;
413 }
415 private QName requestPayloadName;
416 private QName responsePayloadName;
417 private boolean emptyRequestPayload;
418 private boolean emptyResponsePayload;
419 private Map<QName, WSDLMessageImpl> messages;
421 void freeze(WSDLModelImpl parent) {
422 messages = parent.getMessages();
423 operation = owner.getPortType().get(name.getLocalPart());
424 for(WSDLBoundFaultImpl bf : wsdlBoundFaults){
425 bf.freeze(this);
426 }
427 }
429 public void setAnonymous(ANONYMOUS anonymous) {
430 this.anonymous = anonymous;
431 }
433 /**
434 * @inheritDoc
435 */
436 public ANONYMOUS getAnonymous() {
437 return anonymous;
438 }
439 }