src/share/jaxws_classes/com/sun/xml/internal/ws/model/wsdl/WSDLBoundOperationImpl.java

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

mercurial