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

Tue, 06 Mar 2012 16:09:35 -0800

author
ohair
date
Tue, 06 Mar 2012 16:09:35 -0800
changeset 286
f50545b5e2f1
child 368
0989ad8c0860
permissions
-rw-r--r--

7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom

ohair@286 1 /*
ohair@286 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 package com.sun.xml.internal.ws.model.wsdl;
ohair@286 27
ohair@286 28 import com.sun.istack.internal.NotNull;
ohair@286 29 import com.sun.xml.internal.ws.api.BindingID;
ohair@286 30 import com.sun.xml.internal.ws.api.SOAPVersion;
ohair@286 31 import com.sun.xml.internal.ws.api.model.ParameterBinding;
ohair@286 32 import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
ohair@286 33 import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundPortType;
ohair@286 34 import com.sun.xml.internal.ws.resources.ClientMessages;
ohair@286 35 import com.sun.xml.internal.ws.util.QNameMap;
ohair@286 36 import com.sun.xml.internal.ws.util.exception.LocatableWebServiceException;
ohair@286 37
ohair@286 38 import javax.jws.WebParam.Mode;
ohair@286 39 import javax.jws.soap.SOAPBinding;
ohair@286 40 import javax.jws.soap.SOAPBinding.Style;
ohair@286 41 import javax.xml.namespace.QName;
ohair@286 42 import javax.xml.stream.XMLStreamReader;
ohair@286 43 import javax.xml.ws.soap.MTOMFeature;
ohair@286 44
ohair@286 45 /**
ohair@286 46 * Implementation of {@link WSDLBoundPortType}
ohair@286 47 *
ohair@286 48 * @author Vivek Pandey
ohair@286 49 */
ohair@286 50 public final class WSDLBoundPortTypeImpl extends AbstractFeaturedObjectImpl implements WSDLBoundPortType {
ohair@286 51 private final QName name;
ohair@286 52 private final QName portTypeName;
ohair@286 53 private WSDLPortTypeImpl portType;
ohair@286 54 private BindingID bindingId;
ohair@286 55 private final @NotNull WSDLModelImpl owner;
ohair@286 56 private final QNameMap<WSDLBoundOperationImpl> bindingOperations = new QNameMap<WSDLBoundOperationImpl>();
ohair@286 57
ohair@286 58 /**
ohair@286 59 * Operations keyed by the payload tag name.
ohair@286 60 */
ohair@286 61 private QNameMap<WSDLBoundOperationImpl> payloadMap;
ohair@286 62 /**
ohair@286 63 * {@link #payloadMap} doesn't allow null key, so we store the value for it here.
ohair@286 64 */
ohair@286 65 private WSDLBoundOperationImpl emptyPayloadOperation;
ohair@286 66
ohair@286 67
ohair@286 68
ohair@286 69 public WSDLBoundPortTypeImpl(XMLStreamReader xsr,@NotNull WSDLModelImpl owner, QName name, QName portTypeName) {
ohair@286 70 super(xsr);
ohair@286 71 this.owner = owner;
ohair@286 72 this.name = name;
ohair@286 73 this.portTypeName = portTypeName;
ohair@286 74 owner.addBinding(this);
ohair@286 75 }
ohair@286 76
ohair@286 77 public QName getName() {
ohair@286 78 return name;
ohair@286 79 }
ohair@286 80
ohair@286 81 public @NotNull WSDLModelImpl getOwner() {
ohair@286 82 return owner;
ohair@286 83 }
ohair@286 84
ohair@286 85 public WSDLBoundOperationImpl get(QName operationName) {
ohair@286 86 return bindingOperations.get(operationName);
ohair@286 87 }
ohair@286 88
ohair@286 89 /**
ohair@286 90 * Populates the Map that holds operation name as key and {@link WSDLBoundOperation} as the value.
ohair@286 91 *
ohair@286 92 * @param opName Must be non-null
ohair@286 93 * @param ptOp Must be non-null
ohair@286 94 * @throws NullPointerException if either opName or ptOp is null
ohair@286 95 */
ohair@286 96 public void put(QName opName, WSDLBoundOperationImpl ptOp) {
ohair@286 97 bindingOperations.put(opName,ptOp);
ohair@286 98 }
ohair@286 99
ohair@286 100 public QName getPortTypeName() {
ohair@286 101 return portTypeName;
ohair@286 102 }
ohair@286 103
ohair@286 104 public WSDLPortTypeImpl getPortType() {
ohair@286 105 return portType;
ohair@286 106 }
ohair@286 107
ohair@286 108 public Iterable<WSDLBoundOperationImpl> getBindingOperations() {
ohair@286 109 return bindingOperations.values();
ohair@286 110 }
ohair@286 111
ohair@286 112 public BindingID getBindingId() {
ohair@286 113 //Should the default be SOAP1.1/HTTP binding? For now lets keep it for
ohair@286 114 //JBI bug 6509800
ohair@286 115 return (bindingId==null)?BindingID.SOAP11_HTTP:bindingId;
ohair@286 116 }
ohair@286 117
ohair@286 118 public void setBindingId(BindingID bindingId) {
ohair@286 119 this.bindingId = bindingId;
ohair@286 120 }
ohair@286 121
ohair@286 122 /**
ohair@286 123 * sets whether the {@link WSDLBoundPortType} is rpc or lit
ohair@286 124 */
ohair@286 125 private Style style = Style.DOCUMENT;
ohair@286 126 public void setStyle(Style style){
ohair@286 127 this.style = style;
ohair@286 128 }
ohair@286 129
ohair@286 130 public SOAPBinding.Style getStyle() {
ohair@286 131 return style;
ohair@286 132 }
ohair@286 133
ohair@286 134 public boolean isRpcLit(){
ohair@286 135 return Style.RPC==style;
ohair@286 136 }
ohair@286 137
ohair@286 138 public boolean isDoclit(){
ohair@286 139 return Style.DOCUMENT==style;
ohair@286 140 }
ohair@286 141
ohair@286 142
ohair@286 143 /**
ohair@286 144 * Gets the {@link ParameterBinding} for a given operation, part name and the direction - IN/OUT
ohair@286 145 *
ohair@286 146 * @param operation wsdl:operation@name value. Must be non-null.
ohair@286 147 * @param part wsdl:part@name such as value of soap:header@part. Must be non-null.
ohair@286 148 * @param mode {@link Mode#IN} or {@link Mode@OUT}. Must be non-null.
ohair@286 149 * @return null if the binding could not be resolved for the part.
ohair@286 150 */
ohair@286 151 public ParameterBinding getBinding(QName operation, String part, Mode mode) {
ohair@286 152 WSDLBoundOperationImpl op = get(operation);
ohair@286 153 if (op == null) {
ohair@286 154 //TODO throw exception
ohair@286 155 return null;
ohair@286 156 }
ohair@286 157 if ((Mode.IN == mode) || (Mode.INOUT == mode))
ohair@286 158 return op.getInputBinding(part);
ohair@286 159 else
ohair@286 160 return op.getOutputBinding(part);
ohair@286 161 }
ohair@286 162
ohair@286 163 /**
ohair@286 164 * Gets mime:content@part value which is the MIME type for a given operation, part and {@link Mode}.
ohair@286 165 *
ohair@286 166 * @param operation wsdl:operation@name value. Must be non-null.
ohair@286 167 * @param part wsdl:part@name such as value of soap:header@part. Must be non-null.
ohair@286 168 * @param mode {@link Mode#IN} or {@link Mode@OUT}. Must be non-null.
ohair@286 169 * @return null if the binding could not be resolved for the part.
ohair@286 170 */
ohair@286 171 public String getMimeType(QName operation, String part, Mode mode) {
ohair@286 172 WSDLBoundOperationImpl op = get(operation);
ohair@286 173 if (Mode.IN == mode)
ohair@286 174 return op.getMimeTypeForInputPart(part);
ohair@286 175 else
ohair@286 176 return op.getMimeTypeForOutputPart(part);
ohair@286 177 }
ohair@286 178
ohair@286 179 public WSDLBoundOperationImpl getOperation(String namespaceUri, String localName) {
ohair@286 180 if(namespaceUri==null && localName == null)
ohair@286 181 return emptyPayloadOperation;
ohair@286 182 else{
ohair@286 183 return payloadMap.get((namespaceUri==null)?"":namespaceUri,localName);
ohair@286 184 }
ohair@286 185 }
ohair@286 186
ohair@286 187 public void enableMTOM() {
ohair@286 188 features.add(new MTOMFeature());
ohair@286 189 }
ohair@286 190
ohair@286 191 public boolean isMTOMEnabled() {
ohair@286 192 return features.isEnabled(MTOMFeature.class);
ohair@286 193 }
ohair@286 194
ohair@286 195 public SOAPVersion getSOAPVersion(){
ohair@286 196 return getBindingId().getSOAPVersion();
ohair@286 197 }
ohair@286 198
ohair@286 199 void freeze() {
ohair@286 200 portType = owner.getPortType(portTypeName);
ohair@286 201 if(portType == null){
ohair@286 202 throw new LocatableWebServiceException(
ohair@286 203 ClientMessages.UNDEFINED_PORT_TYPE(portTypeName), getLocation());
ohair@286 204 }
ohair@286 205 portType.freeze();
ohair@286 206
ohair@286 207 for (WSDLBoundOperationImpl op : bindingOperations.values()) {
ohair@286 208 op.freeze(owner);
ohair@286 209 }
ohair@286 210
ohair@286 211 freezePayloadMap();
ohair@286 212 owner.finalizeRpcLitBinding(this);
ohair@286 213 }
ohair@286 214
ohair@286 215 private void freezePayloadMap() {
ohair@286 216 if(style== Style.RPC) {
ohair@286 217 payloadMap = new QNameMap<WSDLBoundOperationImpl>();
ohair@286 218 for(WSDLBoundOperationImpl op : bindingOperations.values()){
ohair@286 219 payloadMap.put(op.getReqPayloadName(), op);
ohair@286 220 }
ohair@286 221 } else {
ohair@286 222 payloadMap = new QNameMap<WSDLBoundOperationImpl>();
ohair@286 223 // For doclit The tag will be the operation that has the same input part descriptor value
ohair@286 224 for(WSDLBoundOperationImpl op : bindingOperations.values()){
ohair@286 225 QName name = op.getReqPayloadName();
ohair@286 226 if(name == null){
ohair@286 227 //empty payload
ohair@286 228 emptyPayloadOperation = op;
ohair@286 229 continue;
ohair@286 230 }
ohair@286 231
ohair@286 232 payloadMap.put(name, op);
ohair@286 233 }
ohair@286 234 }
ohair@286 235 }
ohair@286 236 }

mercurial