src/share/jaxws_classes/com/sun/xml/internal/ws/model/wsdl/WSDLBoundPortTypeImpl.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/WSDLBoundPortTypeImpl.java	Tue Mar 06 16:09:35 2012 -0800
     1.3 @@ -0,0 +1,236 @@
     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.NotNull;
    1.32 +import com.sun.xml.internal.ws.api.BindingID;
    1.33 +import com.sun.xml.internal.ws.api.SOAPVersion;
    1.34 +import com.sun.xml.internal.ws.api.model.ParameterBinding;
    1.35 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
    1.36 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundPortType;
    1.37 +import com.sun.xml.internal.ws.resources.ClientMessages;
    1.38 +import com.sun.xml.internal.ws.util.QNameMap;
    1.39 +import com.sun.xml.internal.ws.util.exception.LocatableWebServiceException;
    1.40 +
    1.41 +import javax.jws.WebParam.Mode;
    1.42 +import javax.jws.soap.SOAPBinding;
    1.43 +import javax.jws.soap.SOAPBinding.Style;
    1.44 +import javax.xml.namespace.QName;
    1.45 +import javax.xml.stream.XMLStreamReader;
    1.46 +import javax.xml.ws.soap.MTOMFeature;
    1.47 +
    1.48 +/**
    1.49 + * Implementation of {@link WSDLBoundPortType}
    1.50 + *
    1.51 + * @author Vivek Pandey
    1.52 + */
    1.53 +public final class WSDLBoundPortTypeImpl extends AbstractFeaturedObjectImpl implements WSDLBoundPortType {
    1.54 +    private final QName name;
    1.55 +    private final QName portTypeName;
    1.56 +    private WSDLPortTypeImpl portType;
    1.57 +    private BindingID bindingId;
    1.58 +    private final @NotNull WSDLModelImpl owner;
    1.59 +    private final QNameMap<WSDLBoundOperationImpl> bindingOperations = new QNameMap<WSDLBoundOperationImpl>();
    1.60 +
    1.61 +    /**
    1.62 +     * Operations keyed by the payload tag name.
    1.63 +     */
    1.64 +    private QNameMap<WSDLBoundOperationImpl> payloadMap;
    1.65 +    /**
    1.66 +     * {@link #payloadMap} doesn't allow null key, so we store the value for it here.
    1.67 +     */
    1.68 +    private WSDLBoundOperationImpl emptyPayloadOperation;
    1.69 +
    1.70 +
    1.71 +
    1.72 +    public WSDLBoundPortTypeImpl(XMLStreamReader xsr,@NotNull WSDLModelImpl owner, QName name, QName portTypeName) {
    1.73 +        super(xsr);
    1.74 +        this.owner = owner;
    1.75 +        this.name = name;
    1.76 +        this.portTypeName = portTypeName;
    1.77 +        owner.addBinding(this);
    1.78 +    }
    1.79 +
    1.80 +    public QName getName() {
    1.81 +        return name;
    1.82 +    }
    1.83 +
    1.84 +    public @NotNull WSDLModelImpl getOwner() {
    1.85 +        return owner;
    1.86 +    }
    1.87 +
    1.88 +    public WSDLBoundOperationImpl get(QName operationName) {
    1.89 +        return bindingOperations.get(operationName);
    1.90 +    }
    1.91 +
    1.92 +    /**
    1.93 +     * Populates the Map that holds operation name as key and {@link WSDLBoundOperation} as the value.
    1.94 +     *
    1.95 +     * @param opName Must be non-null
    1.96 +     * @param ptOp   Must be non-null
    1.97 +     * @throws NullPointerException if either opName or ptOp is null
    1.98 +     */
    1.99 +    public void put(QName opName, WSDLBoundOperationImpl ptOp) {
   1.100 +        bindingOperations.put(opName,ptOp);
   1.101 +    }
   1.102 +
   1.103 +    public QName getPortTypeName() {
   1.104 +        return portTypeName;
   1.105 +    }
   1.106 +
   1.107 +    public WSDLPortTypeImpl getPortType() {
   1.108 +        return portType;
   1.109 +    }
   1.110 +
   1.111 +    public Iterable<WSDLBoundOperationImpl> getBindingOperations() {
   1.112 +        return bindingOperations.values();
   1.113 +    }
   1.114 +
   1.115 +    public BindingID getBindingId() {
   1.116 +        //Should the default be SOAP1.1/HTTP binding? For now lets keep it for
   1.117 +        //JBI bug 6509800
   1.118 +        return (bindingId==null)?BindingID.SOAP11_HTTP:bindingId;
   1.119 +    }
   1.120 +
   1.121 +    public void setBindingId(BindingID bindingId) {
   1.122 +        this.bindingId = bindingId;
   1.123 +    }
   1.124 +
   1.125 +    /**
   1.126 +     * sets whether the {@link WSDLBoundPortType} is rpc or lit
   1.127 +     */
   1.128 +    private Style style = Style.DOCUMENT;
   1.129 +    public void setStyle(Style style){
   1.130 +        this.style = style;
   1.131 +    }
   1.132 +
   1.133 +    public SOAPBinding.Style getStyle() {
   1.134 +        return style;
   1.135 +    }
   1.136 +
   1.137 +    public boolean isRpcLit(){
   1.138 +        return Style.RPC==style;
   1.139 +    }
   1.140 +
   1.141 +    public boolean isDoclit(){
   1.142 +        return Style.DOCUMENT==style;
   1.143 +    }
   1.144 +
   1.145 +
   1.146 +    /**
   1.147 +     * Gets the {@link ParameterBinding} for a given operation, part name and the direction - IN/OUT
   1.148 +     *
   1.149 +     * @param operation wsdl:operation@name value. Must be non-null.
   1.150 +     * @param part      wsdl:part@name such as value of soap:header@part. Must be non-null.
   1.151 +     * @param mode      {@link Mode#IN} or {@link Mode@OUT}. Must be non-null.
   1.152 +     * @return null if the binding could not be resolved for the part.
   1.153 +     */
   1.154 +    public ParameterBinding getBinding(QName operation, String part, Mode mode) {
   1.155 +        WSDLBoundOperationImpl op = get(operation);
   1.156 +        if (op == null) {
   1.157 +            //TODO throw exception
   1.158 +            return null;
   1.159 +        }
   1.160 +        if ((Mode.IN == mode) || (Mode.INOUT == mode))
   1.161 +            return op.getInputBinding(part);
   1.162 +        else
   1.163 +            return op.getOutputBinding(part);
   1.164 +    }
   1.165 +
   1.166 +    /**
   1.167 +     * Gets mime:content@part value which is the MIME type for a given operation, part and {@link Mode}.
   1.168 +     *
   1.169 +     * @param operation wsdl:operation@name value. Must be non-null.
   1.170 +     * @param part      wsdl:part@name such as value of soap:header@part. Must be non-null.
   1.171 +     * @param mode      {@link Mode#IN} or {@link Mode@OUT}. Must be non-null.
   1.172 +     * @return null if the binding could not be resolved for the part.
   1.173 +     */
   1.174 +    public String getMimeType(QName operation, String part, Mode mode) {
   1.175 +        WSDLBoundOperationImpl op = get(operation);
   1.176 +        if (Mode.IN == mode)
   1.177 +            return op.getMimeTypeForInputPart(part);
   1.178 +        else
   1.179 +            return op.getMimeTypeForOutputPart(part);
   1.180 +    }
   1.181 +
   1.182 +    public WSDLBoundOperationImpl getOperation(String namespaceUri, String localName) {
   1.183 +        if(namespaceUri==null && localName == null)
   1.184 +            return emptyPayloadOperation;
   1.185 +        else{
   1.186 +            return payloadMap.get((namespaceUri==null)?"":namespaceUri,localName);
   1.187 +        }
   1.188 +    }
   1.189 +
   1.190 +    public void enableMTOM() {
   1.191 +        features.add(new MTOMFeature());
   1.192 +    }
   1.193 +
   1.194 +    public boolean isMTOMEnabled() {
   1.195 +        return features.isEnabled(MTOMFeature.class);
   1.196 +    }
   1.197 +
   1.198 +    public SOAPVersion getSOAPVersion(){
   1.199 +        return getBindingId().getSOAPVersion();
   1.200 +    }
   1.201 +
   1.202 +    void freeze() {
   1.203 +        portType = owner.getPortType(portTypeName);
   1.204 +        if(portType == null){
   1.205 +            throw new LocatableWebServiceException(
   1.206 +                    ClientMessages.UNDEFINED_PORT_TYPE(portTypeName), getLocation());
   1.207 +        }
   1.208 +        portType.freeze();
   1.209 +
   1.210 +        for (WSDLBoundOperationImpl op : bindingOperations.values()) {
   1.211 +            op.freeze(owner);
   1.212 +        }
   1.213 +
   1.214 +        freezePayloadMap();
   1.215 +        owner.finalizeRpcLitBinding(this);
   1.216 +    }
   1.217 +
   1.218 +    private void freezePayloadMap() {
   1.219 +        if(style== Style.RPC) {
   1.220 +            payloadMap = new QNameMap<WSDLBoundOperationImpl>();
   1.221 +            for(WSDLBoundOperationImpl op : bindingOperations.values()){
   1.222 +                payloadMap.put(op.getReqPayloadName(), op);
   1.223 +            }
   1.224 +        } else {
   1.225 +            payloadMap = new QNameMap<WSDLBoundOperationImpl>();
   1.226 +            // For doclit The tag will be the operation that has the same input part descriptor value
   1.227 +            for(WSDLBoundOperationImpl op : bindingOperations.values()){
   1.228 +                QName name = op.getReqPayloadName();
   1.229 +                if(name == null){
   1.230 +                    //empty payload
   1.231 +                    emptyPayloadOperation = op;
   1.232 +                    continue;
   1.233 +                }
   1.234 +
   1.235 +                payloadMap.put(name, op);
   1.236 +            }
   1.237 +        }
   1.238 +    }
   1.239 +}

mercurial