1 /* 2 * Copyright (c) 1997, 2013, 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 */ 25 26 package com.sun.xml.internal.ws.model.wsdl; 27 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.api.model.wsdl.editable.EditableWSDLBoundOperation; 35 import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLBoundPortType; 36 import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLModel; 37 import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLPortType; 38 import com.sun.xml.internal.ws.resources.ClientMessages; 39 import com.sun.xml.internal.ws.util.QNameMap; 40 import com.sun.xml.internal.ws.util.exception.LocatableWebServiceException; 41 42 import javax.jws.WebParam.Mode; 43 import javax.jws.soap.SOAPBinding; 44 import javax.jws.soap.SOAPBinding.Style; 45 import javax.xml.namespace.QName; 46 import javax.xml.stream.XMLStreamReader; 47 import javax.xml.ws.soap.MTOMFeature; 48 49 /** 50 * Implementation of {@link WSDLBoundPortType} 51 * 52 * @author Vivek Pandey 53 */ 54 public final class WSDLBoundPortTypeImpl extends AbstractFeaturedObjectImpl implements EditableWSDLBoundPortType { 55 private final QName name; 56 private final QName portTypeName; 57 private EditableWSDLPortType portType; 58 private BindingID bindingId; 59 private final @NotNull EditableWSDLModel owner; 60 private final QNameMap<EditableWSDLBoundOperation> bindingOperations = new QNameMap<EditableWSDLBoundOperation>(); 61 62 /** 63 * Operations keyed by the payload tag name. 64 */ 65 private QNameMap<EditableWSDLBoundOperation> payloadMap; 66 /** 67 * {@link #payloadMap} doesn't allow null key, so we store the value for it here. 68 */ 69 private EditableWSDLBoundOperation emptyPayloadOperation; 70 71 72 WSDLBoundPortTypeImpl(XMLStreamReader xsr,@NotNull EditableWSDLModel owner, QName name, QName portTypeName)73 public WSDLBoundPortTypeImpl(XMLStreamReader xsr,@NotNull EditableWSDLModel owner, QName name, QName portTypeName) { 74 super(xsr); 75 this.owner = owner; 76 this.name = name; 77 this.portTypeName = portTypeName; 78 owner.addBinding(this); 79 } 80 getName()81 public QName getName() { 82 return name; 83 } 84 getOwner()85 public @NotNull EditableWSDLModel getOwner() { 86 return owner; 87 } 88 get(QName operationName)89 public EditableWSDLBoundOperation get(QName operationName) { 90 return bindingOperations.get(operationName); 91 } 92 93 /** 94 * Populates the Map that holds operation name as key and {@link WSDLBoundOperation} as the value. 95 * 96 * @param opName Must be non-null 97 * @param ptOp Must be non-null 98 * @throws NullPointerException if either opName or ptOp is null 99 */ put(QName opName, EditableWSDLBoundOperation ptOp)100 public void put(QName opName, EditableWSDLBoundOperation ptOp) { 101 bindingOperations.put(opName,ptOp); 102 } 103 getPortTypeName()104 public QName getPortTypeName() { 105 return portTypeName; 106 } 107 getPortType()108 public EditableWSDLPortType getPortType() { 109 return portType; 110 } 111 getBindingOperations()112 public Iterable<EditableWSDLBoundOperation> getBindingOperations() { 113 return bindingOperations.values(); 114 } 115 getBindingId()116 public BindingID getBindingId() { 117 //Should the default be SOAP1.1/HTTP binding? For now lets keep it for 118 //JBI bug 6509800 119 return (bindingId==null)?BindingID.SOAP11_HTTP:bindingId; 120 } 121 setBindingId(BindingID bindingId)122 public void setBindingId(BindingID bindingId) { 123 this.bindingId = bindingId; 124 } 125 126 /** 127 * sets whether the {@link WSDLBoundPortType} is rpc or lit 128 */ 129 private Style style = Style.DOCUMENT; setStyle(Style style)130 public void setStyle(Style style){ 131 this.style = style; 132 } 133 getStyle()134 public SOAPBinding.Style getStyle() { 135 return style; 136 } 137 isRpcLit()138 public boolean isRpcLit(){ 139 return Style.RPC==style; 140 } 141 isDoclit()142 public boolean isDoclit(){ 143 return Style.DOCUMENT==style; 144 } 145 146 147 /** 148 * Gets the {@link ParameterBinding} for a given operation, part name and the direction - IN/OUT 149 * 150 * @param operation wsdl:operation@name value. Must be non-null. 151 * @param part wsdl:part@name such as value of soap:header@part. Must be non-null. 152 * @param mode {@link Mode#IN} or {@link Mode#OUT}. Must be non-null. 153 * @return null if the binding could not be resolved for the part. 154 */ getBinding(QName operation, String part, Mode mode)155 public ParameterBinding getBinding(QName operation, String part, Mode mode) { 156 EditableWSDLBoundOperation op = get(operation); 157 if (op == null) { 158 //TODO throw exception 159 return null; 160 } 161 if ((Mode.IN == mode) || (Mode.INOUT == mode)) 162 return op.getInputBinding(part); 163 else 164 return op.getOutputBinding(part); 165 } 166 getOperation(String namespaceUri, String localName)167 public EditableWSDLBoundOperation getOperation(String namespaceUri, String localName) { 168 if(namespaceUri==null && localName == null) 169 return emptyPayloadOperation; 170 else{ 171 return payloadMap.get((namespaceUri==null)?"":namespaceUri,localName); 172 } 173 } 174 freeze()175 public void freeze() { 176 portType = owner.getPortType(portTypeName); 177 if(portType == null){ 178 throw new LocatableWebServiceException( 179 ClientMessages.UNDEFINED_PORT_TYPE(portTypeName), getLocation()); 180 } 181 portType.freeze(); 182 183 for (EditableWSDLBoundOperation op : bindingOperations.values()) { 184 op.freeze(owner); 185 } 186 187 freezePayloadMap(); 188 owner.finalizeRpcLitBinding(this); 189 } 190 freezePayloadMap()191 private void freezePayloadMap() { 192 if(style== Style.RPC) { 193 payloadMap = new QNameMap<EditableWSDLBoundOperation>(); 194 for(EditableWSDLBoundOperation op : bindingOperations.values()){ 195 payloadMap.put(op.getRequestPayloadName(), op); 196 } 197 } else { 198 payloadMap = new QNameMap<EditableWSDLBoundOperation>(); 199 // For doclit The tag will be the operation that has the same input part descriptor value 200 for(EditableWSDLBoundOperation op : bindingOperations.values()){ 201 QName name = op.getRequestPayloadName(); 202 if(name == null){ 203 //empty payload 204 emptyPayloadOperation = op; 205 continue; 206 } 207 208 payloadMap.put(name, op); 209 } 210 } 211 } 212 } 213