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