src/share/jaxws_classes/com/sun/xml/internal/ws/client/PortInfo.java

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/client/PortInfo.java	Tue Mar 06 16:09:35 2012 -0800
     1.3 @@ -0,0 +1,215 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2010, 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.client;
    1.30 +
    1.31 +import com.sun.istack.internal.NotNull;
    1.32 +import com.sun.istack.internal.Nullable;
    1.33 +import com.sun.xml.internal.ws.api.BindingID;
    1.34 +import com.sun.xml.internal.ws.api.EndpointAddress;
    1.35 +import com.sun.xml.internal.ws.api.WSService;
    1.36 +import com.sun.xml.internal.ws.api.policy.PolicyResolverFactory;
    1.37 +import com.sun.xml.internal.ws.api.policy.PolicyResolver;
    1.38 +import com.sun.xml.internal.ws.api.client.WSPortInfo;
    1.39 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
    1.40 +import com.sun.xml.internal.ws.binding.BindingImpl;
    1.41 +import com.sun.xml.internal.ws.binding.WebServiceFeatureList;
    1.42 +import com.sun.xml.internal.ws.model.wsdl.WSDLPortImpl;
    1.43 +import com.sun.xml.internal.ws.model.wsdl.WSDLModelImpl;
    1.44 +import com.sun.xml.internal.ws.policy.PolicyMap;
    1.45 +import com.sun.xml.internal.ws.policy.jaxws.PolicyUtil;
    1.46 +
    1.47 +import javax.xml.namespace.QName;
    1.48 +import javax.xml.ws.WebServiceFeature;
    1.49 +
    1.50 +/**
    1.51 + * Information about a port.
    1.52 + * <p/>
    1.53 + * This object is owned by {@link WSServiceDelegate} to keep track of a port,
    1.54 + * since a port maybe added dynamically.
    1.55 + *
    1.56 + * @author JAXWS Development Team
    1.57 + */
    1.58 +public class PortInfo implements WSPortInfo {
    1.59 +    private final @NotNull WSServiceDelegate owner;
    1.60 +
    1.61 +    public final @NotNull QName portName;
    1.62 +    public final @NotNull EndpointAddress targetEndpoint;
    1.63 +    public final @NotNull BindingID bindingId;
    1.64 +
    1.65 +    public final @NotNull PolicyMap policyMap;
    1.66 +    /**
    1.67 +     * If a port is known statically to a WSDL, {@link PortInfo} may
    1.68 +     * have the corresponding WSDL model. This would occur when the
    1.69 +     * service was created with the WSDL location and the port is defined
    1.70 +     * in the WSDL.
    1.71 +     * <p/>
    1.72 +     * If this is a {@link SEIPortInfo}, then this is always non-null.
    1.73 +     */
    1.74 +    public final @Nullable WSDLPort portModel;
    1.75 +
    1.76 +    public PortInfo(WSServiceDelegate owner, EndpointAddress targetEndpoint, QName name, BindingID bindingId) {
    1.77 +        this.owner = owner;
    1.78 +        this.targetEndpoint = targetEndpoint;
    1.79 +        this.portName = name;
    1.80 +        this.bindingId = bindingId;
    1.81 +        this.portModel = getPortModel(owner, name);
    1.82 +        this.policyMap = createPolicyMap();
    1.83 +
    1.84 +    }
    1.85 +
    1.86 +    public PortInfo(@NotNull WSServiceDelegate owner, @NotNull WSDLPort port) {
    1.87 +        this.owner = owner;
    1.88 +        this.targetEndpoint = port.getAddress();
    1.89 +        this.portName = port.getName();
    1.90 +        this.bindingId = port.getBinding().getBindingId();
    1.91 +        this.portModel = port;
    1.92 +        this.policyMap = createPolicyMap();
    1.93 +    }
    1.94 +
    1.95 +    public PolicyMap getPolicyMap() {
    1.96 +        return policyMap;
    1.97 +    }
    1.98 +
    1.99 +    public PolicyMap createPolicyMap() {
   1.100 +       PolicyMap map;
   1.101 +       if(portModel != null) {
   1.102 +            map = ((WSDLModelImpl) portModel.getOwner().getParent()).getPolicyMap();
   1.103 +       } else {
   1.104 +           map = PolicyResolverFactory.create().resolve(new PolicyResolver.ClientContext(null,owner.getContainer()));
   1.105 +       }
   1.106 +       //still map is null, create a empty map
   1.107 +       if(map == null)
   1.108 +           map = PolicyMap.createPolicyMap(null);
   1.109 +       return map;
   1.110 +    }
   1.111 +    /**
   1.112 +     * Creates {@link BindingImpl} for this {@link PortInfo}.
   1.113 +     *
   1.114 +     * @param webServiceFeatures
   1.115 +     *      User-specified features.
   1.116 +     * @param portInterface
   1.117 +     *      Null if this is for dispatch. Otherwise the interface the proxy is going to implement
   1.118 +     * @return
   1.119 +     *      The initialized BindingImpl
   1.120 +     */
   1.121 +    public BindingImpl createBinding(WebServiceFeature[] webServiceFeatures, Class<?> portInterface) {
   1.122 +        return createBinding(new WebServiceFeatureList(webServiceFeatures), portInterface, null);
   1.123 +    }
   1.124 +
   1.125 +    public BindingImpl createBinding(WebServiceFeatureList webServiceFeatures, Class<?> portInterface,
   1.126 +                BindingImpl existingBinding) {
   1.127 +                if (existingBinding != null) {
   1.128 +                        webServiceFeatures.addAll(existingBinding.getFeatures());
   1.129 +                }
   1.130 +
   1.131 +        Iterable<WebServiceFeature> configFeatures;
   1.132 +        //TODO incase of Dispatch, provide a way to User for complete control of the message processing by giving
   1.133 +        // ability to turn off the WSDL/Policy based features and its associated tubes.
   1.134 +
   1.135 +        //Even in case of Dispatch, merge all features configured via WSDL/Policy or deployment configuration
   1.136 +        if (portModel != null) {
   1.137 +            // could have merged features from this.policyMap, but some features are set in WSDLModel which are not there in PolicyMap
   1.138 +            // for ex: <wsaw:UsingAddressing> wsdl extn., and since the policyMap features are merged into WSDLModel anyway during postFinished(),
   1.139 +            // So, using here WsdlModel for merging is right.
   1.140 +
   1.141 +            // merge features from WSDL
   1.142 +            configFeatures = portModel.getFeatures();
   1.143 +        } else {
   1.144 +            configFeatures = PolicyUtil.getPortScopedFeatures(policyMap, owner.getServiceName(),portName);
   1.145 +        }
   1.146 +        webServiceFeatures.mergeFeatures(configFeatures, false);
   1.147 +
   1.148 +        // merge features from interceptor
   1.149 +        webServiceFeatures.mergeFeatures(owner.serviceInterceptor.preCreateBinding(this, portInterface, webServiceFeatures), false);
   1.150 +
   1.151 +        BindingImpl bindingImpl = BindingImpl.create(bindingId, webServiceFeatures.toArray());
   1.152 +        owner.getHandlerConfigurator().configureHandlers(this,bindingImpl);
   1.153 +        return bindingImpl;
   1.154 +    }
   1.155 +
   1.156 +    //This method is used for Dispatch client only
   1.157 +    private WSDLPort getPortModel(WSServiceDelegate owner, QName portName) {
   1.158 +
   1.159 +        if (owner.getWsdlService() != null){
   1.160 +            Iterable<WSDLPortImpl> ports = owner.getWsdlService().getPorts();
   1.161 +            for (WSDLPortImpl port : ports){
   1.162 +                if (port.getName().equals(portName))
   1.163 +                    return port;
   1.164 +            }
   1.165 +        }
   1.166 +        return null;
   1.167 +    }
   1.168 +
   1.169 +//
   1.170 +// implementation of API PortInfo interface
   1.171 +//
   1.172 +
   1.173 +    @Nullable
   1.174 +    public WSDLPort getPort() {
   1.175 +        return portModel;
   1.176 +    }
   1.177 +
   1.178 +    @NotNull
   1.179 +    public WSService getOwner() {
   1.180 +        return owner;
   1.181 +    }
   1.182 +
   1.183 +    @NotNull
   1.184 +    public BindingID getBindingId() {
   1.185 +        return bindingId;
   1.186 +    }
   1.187 +
   1.188 +    @NotNull
   1.189 +    public EndpointAddress getEndpointAddress() {
   1.190 +        return targetEndpoint;
   1.191 +    }
   1.192 +
   1.193 +    /**
   1.194 +     * @deprecated
   1.195 +     *      Only meant to be used via {@link javax.xml.ws.handler.PortInfo}.
   1.196 +     *      Use {@link WSServiceDelegate#getServiceName()}.
   1.197 +     */
   1.198 +    public QName getServiceName() {
   1.199 +        return owner.getServiceName();
   1.200 +    }
   1.201 +
   1.202 +    /**
   1.203 +     *      Only meant to be used via {@link javax.xml.ws.handler.PortInfo}.
   1.204 +     *      Use {@link #portName}.
   1.205 +     */
   1.206 +    public QName getPortName() {
   1.207 +        return portName;
   1.208 +    }
   1.209 +
   1.210 +    /**
   1.211 +     * @deprecated
   1.212 +     *      Only meant to be used via {@link javax.xml.ws.handler.PortInfo}.
   1.213 +     *      Use {@link #bindingId}.
   1.214 +     */
   1.215 +    public String getBindingID() {
   1.216 +        return bindingId.toString();
   1.217 +    }
   1.218 +}

mercurial