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