ohair@286: /* mkos@408: * Copyright (c) 1997, 2013, 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; mkos@408: import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLBoundOperation; mkos@408: import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLBoundPortType; mkos@408: import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLModel; mkos@408: import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLPortType; 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: */ mkos@408: public final class WSDLBoundPortTypeImpl extends AbstractFeaturedObjectImpl implements EditableWSDLBoundPortType { ohair@286: private final QName name; ohair@286: private final QName portTypeName; mkos@408: private EditableWSDLPortType portType; ohair@286: private BindingID bindingId; mkos@408: private final @NotNull EditableWSDLModel owner; mkos@408: private final QNameMap bindingOperations = new QNameMap(); ohair@286: ohair@286: /** ohair@286: * Operations keyed by the payload tag name. ohair@286: */ mkos@408: private QNameMap payloadMap; ohair@286: /** ohair@286: * {@link #payloadMap} doesn't allow null key, so we store the value for it here. ohair@286: */ mkos@408: private EditableWSDLBoundOperation emptyPayloadOperation; ohair@286: ohair@286: ohair@286: mkos@408: public WSDLBoundPortTypeImpl(XMLStreamReader xsr,@NotNull EditableWSDLModel 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: mkos@408: public @NotNull EditableWSDLModel getOwner() { ohair@286: return owner; ohair@286: } ohair@286: mkos@408: public EditableWSDLBoundOperation 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: */ mkos@408: public void put(QName opName, EditableWSDLBoundOperation ptOp) { ohair@286: bindingOperations.put(opName,ptOp); ohair@286: } ohair@286: ohair@286: public QName getPortTypeName() { ohair@286: return portTypeName; ohair@286: } ohair@286: mkos@408: public EditableWSDLPortType getPortType() { ohair@286: return portType; ohair@286: } ohair@286: mkos@408: 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. alanb@368: * @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) { mkos@408: EditableWSDLBoundOperation 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: mkos@408: public EditableWSDLBoundOperation 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: mkos@408: public 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: mkos@408: for (EditableWSDLBoundOperation 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) { mkos@408: payloadMap = new QNameMap(); mkos@408: for(EditableWSDLBoundOperation op : bindingOperations.values()){ mkos@408: payloadMap.put(op.getRequestPayloadName(), op); ohair@286: } ohair@286: } else { mkos@408: payloadMap = new QNameMap(); ohair@286: // For doclit The tag will be the operation that has the same input part descriptor value mkos@408: for(EditableWSDLBoundOperation op : bindingOperations.values()){ mkos@408: QName name = op.getRequestPayloadName(); 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: }