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

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 408
b0610cd08440
permissions
-rw-r--r--

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.NotNull;
    29 import com.sun.xml.internal.ws.api.BindingID;
    30 import com.sun.xml.internal.ws.api.SOAPVersion;
    31 import com.sun.xml.internal.ws.api.model.ParameterBinding;
    32 import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
    33 import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundPortType;
    34 import com.sun.xml.internal.ws.resources.ClientMessages;
    35 import com.sun.xml.internal.ws.util.QNameMap;
    36 import com.sun.xml.internal.ws.util.exception.LocatableWebServiceException;
    38 import javax.jws.WebParam.Mode;
    39 import javax.jws.soap.SOAPBinding;
    40 import javax.jws.soap.SOAPBinding.Style;
    41 import javax.xml.namespace.QName;
    42 import javax.xml.stream.XMLStreamReader;
    43 import javax.xml.ws.soap.MTOMFeature;
    45 /**
    46  * Implementation of {@link WSDLBoundPortType}
    47  *
    48  * @author Vivek Pandey
    49  */
    50 public final class WSDLBoundPortTypeImpl extends AbstractFeaturedObjectImpl implements WSDLBoundPortType {
    51     private final QName name;
    52     private final QName portTypeName;
    53     private WSDLPortTypeImpl portType;
    54     private BindingID bindingId;
    55     private final @NotNull WSDLModelImpl owner;
    56     private final QNameMap<WSDLBoundOperationImpl> bindingOperations = new QNameMap<WSDLBoundOperationImpl>();
    58     /**
    59      * Operations keyed by the payload tag name.
    60      */
    61     private QNameMap<WSDLBoundOperationImpl> payloadMap;
    62     /**
    63      * {@link #payloadMap} doesn't allow null key, so we store the value for it here.
    64      */
    65     private WSDLBoundOperationImpl emptyPayloadOperation;
    69     public WSDLBoundPortTypeImpl(XMLStreamReader xsr,@NotNull WSDLModelImpl owner, QName name, QName portTypeName) {
    70         super(xsr);
    71         this.owner = owner;
    72         this.name = name;
    73         this.portTypeName = portTypeName;
    74         owner.addBinding(this);
    75     }
    77     public QName getName() {
    78         return name;
    79     }
    81     public @NotNull WSDLModelImpl getOwner() {
    82         return owner;
    83     }
    85     public WSDLBoundOperationImpl get(QName operationName) {
    86         return bindingOperations.get(operationName);
    87     }
    89     /**
    90      * Populates the Map that holds operation name as key and {@link WSDLBoundOperation} as the value.
    91      *
    92      * @param opName Must be non-null
    93      * @param ptOp   Must be non-null
    94      * @throws NullPointerException if either opName or ptOp is null
    95      */
    96     public void put(QName opName, WSDLBoundOperationImpl ptOp) {
    97         bindingOperations.put(opName,ptOp);
    98     }
   100     public QName getPortTypeName() {
   101         return portTypeName;
   102     }
   104     public WSDLPortTypeImpl getPortType() {
   105         return portType;
   106     }
   108     public Iterable<WSDLBoundOperationImpl> getBindingOperations() {
   109         return bindingOperations.values();
   110     }
   112     public BindingID getBindingId() {
   113         //Should the default be SOAP1.1/HTTP binding? For now lets keep it for
   114         //JBI bug 6509800
   115         return (bindingId==null)?BindingID.SOAP11_HTTP:bindingId;
   116     }
   118     public void setBindingId(BindingID bindingId) {
   119         this.bindingId = bindingId;
   120     }
   122     /**
   123      * sets whether the {@link WSDLBoundPortType} is rpc or lit
   124      */
   125     private Style style = Style.DOCUMENT;
   126     public void setStyle(Style style){
   127         this.style = style;
   128     }
   130     public SOAPBinding.Style getStyle() {
   131         return style;
   132     }
   134     public boolean isRpcLit(){
   135         return Style.RPC==style;
   136     }
   138     public boolean isDoclit(){
   139         return Style.DOCUMENT==style;
   140     }
   143     /**
   144      * Gets the {@link ParameterBinding} for a given operation, part name and the direction - IN/OUT
   145      *
   146      * @param operation wsdl:operation@name value. Must be non-null.
   147      * @param part      wsdl:part@name such as value of soap:header@part. Must be non-null.
   148      * @param mode      {@link Mode#IN} or {@link Mode#OUT}. Must be non-null.
   149      * @return null if the binding could not be resolved for the part.
   150      */
   151     public ParameterBinding getBinding(QName operation, String part, Mode mode) {
   152         WSDLBoundOperationImpl op = get(operation);
   153         if (op == null) {
   154             //TODO throw exception
   155             return null;
   156         }
   157         if ((Mode.IN == mode) || (Mode.INOUT == mode))
   158             return op.getInputBinding(part);
   159         else
   160             return op.getOutputBinding(part);
   161     }
   163     /**
   164      * Gets mime:content@part value which is the MIME type for a given operation, part and {@link Mode}.
   165      *
   166      * @param operation wsdl:operation@name value. Must be non-null.
   167      * @param part      wsdl:part@name such as value of soap:header@part. Must be non-null.
   168      * @param mode      {@link Mode#IN} or {@link Mode#OUT}. Must be non-null.
   169      * @return null if the binding could not be resolved for the part.
   170      */
   171     public String getMimeType(QName operation, String part, Mode mode) {
   172         WSDLBoundOperationImpl op = get(operation);
   173         if (Mode.IN == mode)
   174             return op.getMimeTypeForInputPart(part);
   175         else
   176             return op.getMimeTypeForOutputPart(part);
   177     }
   179     public WSDLBoundOperationImpl getOperation(String namespaceUri, String localName) {
   180         if(namespaceUri==null && localName == null)
   181             return emptyPayloadOperation;
   182         else{
   183             return payloadMap.get((namespaceUri==null)?"":namespaceUri,localName);
   184         }
   185     }
   187     public void enableMTOM() {
   188         features.add(new MTOMFeature());
   189     }
   191     public boolean isMTOMEnabled() {
   192         return features.isEnabled(MTOMFeature.class);
   193     }
   195     public SOAPVersion getSOAPVersion(){
   196         return getBindingId().getSOAPVersion();
   197     }
   199     void freeze() {
   200         portType = owner.getPortType(portTypeName);
   201         if(portType == null){
   202             throw new LocatableWebServiceException(
   203                     ClientMessages.UNDEFINED_PORT_TYPE(portTypeName), getLocation());
   204         }
   205         portType.freeze();
   207         for (WSDLBoundOperationImpl op : bindingOperations.values()) {
   208             op.freeze(owner);
   209         }
   211         freezePayloadMap();
   212         owner.finalizeRpcLitBinding(this);
   213     }
   215     private void freezePayloadMap() {
   216         if(style== Style.RPC) {
   217             payloadMap = new QNameMap<WSDLBoundOperationImpl>();
   218             for(WSDLBoundOperationImpl op : bindingOperations.values()){
   219                 payloadMap.put(op.getReqPayloadName(), op);
   220             }
   221         } else {
   222             payloadMap = new QNameMap<WSDLBoundOperationImpl>();
   223             // For doclit The tag will be the operation that has the same input part descriptor value
   224             for(WSDLBoundOperationImpl op : bindingOperations.values()){
   225                 QName name = op.getReqPayloadName();
   226                 if(name == null){
   227                     //empty payload
   228                     emptyPayloadOperation = op;
   229                     continue;
   230                 }
   232                 payloadMap.put(name, op);
   233             }
   234         }
   235     }
   236 }

mercurial