ohair@286: /* ohair@286: * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. ohair@286: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ohair@286: * ohair@286: * This code is free software; you can redistribute it and/or modify it ohair@286: * under the terms of the GNU General Public License version 2 only, as ohair@286: * published by the Free Software Foundation. Oracle designates this ohair@286: * particular file as subject to the "Classpath" exception as provided ohair@286: * by Oracle in the LICENSE file that accompanied this code. ohair@286: * ohair@286: * This code is distributed in the hope that it will be useful, but WITHOUT ohair@286: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ohair@286: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ohair@286: * version 2 for more details (a copy is included in the LICENSE file that ohair@286: * accompanied this code). ohair@286: * ohair@286: * You should have received a copy of the GNU General Public License version ohair@286: * 2 along with this work; if not, write to the Free Software Foundation, ohair@286: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ohair@286: * ohair@286: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@286: * or visit www.oracle.com if you need additional information or have any ohair@286: * questions. ohair@286: */ ohair@286: ohair@286: package com.sun.xml.internal.ws.model.wsdl; ohair@286: ohair@286: import com.sun.istack.internal.NotNull; ohair@286: import com.sun.xml.internal.ws.api.BindingID; ohair@286: import com.sun.xml.internal.ws.api.SOAPVersion; ohair@286: import com.sun.xml.internal.ws.api.model.ParameterBinding; ohair@286: import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation; ohair@286: import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundPortType; ohair@286: import com.sun.xml.internal.ws.resources.ClientMessages; ohair@286: import com.sun.xml.internal.ws.util.QNameMap; ohair@286: import com.sun.xml.internal.ws.util.exception.LocatableWebServiceException; ohair@286: ohair@286: import javax.jws.WebParam.Mode; ohair@286: import javax.jws.soap.SOAPBinding; ohair@286: import javax.jws.soap.SOAPBinding.Style; ohair@286: import javax.xml.namespace.QName; ohair@286: import javax.xml.stream.XMLStreamReader; ohair@286: import javax.xml.ws.soap.MTOMFeature; ohair@286: ohair@286: /** ohair@286: * Implementation of {@link WSDLBoundPortType} ohair@286: * ohair@286: * @author Vivek Pandey ohair@286: */ ohair@286: public final class WSDLBoundPortTypeImpl extends AbstractFeaturedObjectImpl implements WSDLBoundPortType { ohair@286: private final QName name; ohair@286: private final QName portTypeName; ohair@286: private WSDLPortTypeImpl portType; ohair@286: private BindingID bindingId; ohair@286: private final @NotNull WSDLModelImpl owner; ohair@286: private final QNameMap bindingOperations = new QNameMap(); ohair@286: ohair@286: /** ohair@286: * Operations keyed by the payload tag name. ohair@286: */ ohair@286: private QNameMap payloadMap; ohair@286: /** ohair@286: * {@link #payloadMap} doesn't allow null key, so we store the value for it here. ohair@286: */ ohair@286: private WSDLBoundOperationImpl emptyPayloadOperation; ohair@286: ohair@286: ohair@286: ohair@286: public WSDLBoundPortTypeImpl(XMLStreamReader xsr,@NotNull WSDLModelImpl owner, QName name, QName portTypeName) { ohair@286: super(xsr); ohair@286: this.owner = owner; ohair@286: this.name = name; ohair@286: this.portTypeName = portTypeName; ohair@286: owner.addBinding(this); ohair@286: } ohair@286: ohair@286: public QName getName() { ohair@286: return name; ohair@286: } ohair@286: ohair@286: public @NotNull WSDLModelImpl getOwner() { ohair@286: return owner; ohair@286: } ohair@286: ohair@286: public WSDLBoundOperationImpl get(QName operationName) { ohair@286: return bindingOperations.get(operationName); ohair@286: } ohair@286: ohair@286: /** ohair@286: * Populates the Map that holds operation name as key and {@link WSDLBoundOperation} as the value. ohair@286: * ohair@286: * @param opName Must be non-null ohair@286: * @param ptOp Must be non-null ohair@286: * @throws NullPointerException if either opName or ptOp is null ohair@286: */ ohair@286: public void put(QName opName, WSDLBoundOperationImpl ptOp) { ohair@286: bindingOperations.put(opName,ptOp); ohair@286: } ohair@286: ohair@286: public QName getPortTypeName() { ohair@286: return portTypeName; ohair@286: } ohair@286: ohair@286: public WSDLPortTypeImpl getPortType() { ohair@286: return portType; ohair@286: } ohair@286: ohair@286: public Iterable getBindingOperations() { ohair@286: return bindingOperations.values(); ohair@286: } ohair@286: ohair@286: public BindingID getBindingId() { ohair@286: //Should the default be SOAP1.1/HTTP binding? For now lets keep it for ohair@286: //JBI bug 6509800 ohair@286: return (bindingId==null)?BindingID.SOAP11_HTTP:bindingId; ohair@286: } ohair@286: ohair@286: public void setBindingId(BindingID bindingId) { ohair@286: this.bindingId = bindingId; ohair@286: } ohair@286: ohair@286: /** ohair@286: * sets whether the {@link WSDLBoundPortType} is rpc or lit ohair@286: */ ohair@286: private Style style = Style.DOCUMENT; ohair@286: public void setStyle(Style style){ ohair@286: this.style = style; ohair@286: } ohair@286: ohair@286: public SOAPBinding.Style getStyle() { ohair@286: return style; ohair@286: } ohair@286: ohair@286: public boolean isRpcLit(){ ohair@286: return Style.RPC==style; ohair@286: } ohair@286: ohair@286: public boolean isDoclit(){ ohair@286: return Style.DOCUMENT==style; ohair@286: } ohair@286: ohair@286: ohair@286: /** ohair@286: * Gets the {@link ParameterBinding} for a given operation, part name and the direction - IN/OUT ohair@286: * ohair@286: * @param operation wsdl:operation@name value. Must be non-null. ohair@286: * @param part wsdl:part@name such as value of soap:header@part. Must be non-null. ohair@286: * @param mode {@link Mode#IN} or {@link Mode@OUT}. Must be non-null. ohair@286: * @return null if the binding could not be resolved for the part. ohair@286: */ ohair@286: public ParameterBinding getBinding(QName operation, String part, Mode mode) { ohair@286: WSDLBoundOperationImpl op = get(operation); ohair@286: if (op == null) { ohair@286: //TODO throw exception ohair@286: return null; ohair@286: } ohair@286: if ((Mode.IN == mode) || (Mode.INOUT == mode)) ohair@286: return op.getInputBinding(part); ohair@286: else ohair@286: return op.getOutputBinding(part); ohair@286: } ohair@286: ohair@286: /** ohair@286: * Gets mime:content@part value which is the MIME type for a given operation, part and {@link Mode}. ohair@286: * ohair@286: * @param operation wsdl:operation@name value. Must be non-null. ohair@286: * @param part wsdl:part@name such as value of soap:header@part. Must be non-null. ohair@286: * @param mode {@link Mode#IN} or {@link Mode@OUT}. Must be non-null. ohair@286: * @return null if the binding could not be resolved for the part. ohair@286: */ ohair@286: public String getMimeType(QName operation, String part, Mode mode) { ohair@286: WSDLBoundOperationImpl op = get(operation); ohair@286: if (Mode.IN == mode) ohair@286: return op.getMimeTypeForInputPart(part); ohair@286: else ohair@286: return op.getMimeTypeForOutputPart(part); ohair@286: } ohair@286: ohair@286: public WSDLBoundOperationImpl getOperation(String namespaceUri, String localName) { ohair@286: if(namespaceUri==null && localName == null) ohair@286: return emptyPayloadOperation; ohair@286: else{ ohair@286: return payloadMap.get((namespaceUri==null)?"":namespaceUri,localName); ohair@286: } ohair@286: } ohair@286: ohair@286: public void enableMTOM() { ohair@286: features.add(new MTOMFeature()); ohair@286: } ohair@286: ohair@286: public boolean isMTOMEnabled() { ohair@286: return features.isEnabled(MTOMFeature.class); ohair@286: } ohair@286: ohair@286: public SOAPVersion getSOAPVersion(){ ohair@286: return getBindingId().getSOAPVersion(); ohair@286: } ohair@286: ohair@286: void freeze() { ohair@286: portType = owner.getPortType(portTypeName); ohair@286: if(portType == null){ ohair@286: throw new LocatableWebServiceException( ohair@286: ClientMessages.UNDEFINED_PORT_TYPE(portTypeName), getLocation()); ohair@286: } ohair@286: portType.freeze(); ohair@286: ohair@286: for (WSDLBoundOperationImpl op : bindingOperations.values()) { ohair@286: op.freeze(owner); ohair@286: } ohair@286: ohair@286: freezePayloadMap(); ohair@286: owner.finalizeRpcLitBinding(this); ohair@286: } ohair@286: ohair@286: private void freezePayloadMap() { ohair@286: if(style== Style.RPC) { ohair@286: payloadMap = new QNameMap(); ohair@286: for(WSDLBoundOperationImpl op : bindingOperations.values()){ ohair@286: payloadMap.put(op.getReqPayloadName(), op); ohair@286: } ohair@286: } else { ohair@286: payloadMap = new QNameMap(); ohair@286: // For doclit The tag will be the operation that has the same input part descriptor value ohair@286: for(WSDLBoundOperationImpl op : bindingOperations.values()){ ohair@286: QName name = op.getReqPayloadName(); ohair@286: if(name == null){ ohair@286: //empty payload ohair@286: emptyPayloadOperation = op; ohair@286: continue; ohair@286: } ohair@286: ohair@286: payloadMap.put(name, op); ohair@286: } ohair@286: } ohair@286: } ohair@286: }