001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036: package com.sun.xml.ws.client;
037:
038: import com.sun.istack.NotNull;
039: import com.sun.istack.Nullable;
040: import com.sun.xml.ws.api.BindingID;
041: import com.sun.xml.ws.api.EndpointAddress;
042: import com.sun.xml.ws.api.WSService;
043: import com.sun.xml.ws.api.client.WSPortInfo;
044: import com.sun.xml.ws.api.model.wsdl.WSDLPort;
045: import com.sun.xml.ws.binding.BindingImpl;
046: import com.sun.xml.ws.binding.WebServiceFeatureList;
047: import com.sun.xml.ws.model.wsdl.WSDLPortImpl;
048:
049: import javax.xml.namespace.QName;
050: import javax.xml.ws.WebServiceFeature;
051: import javax.xml.ws.WebServiceException;
052:
053: /**
054: * Information about a port.
055: * <p/>
056: * This object is owned by {@link WSServiceDelegate} to keep track of a port,
057: * since a port maybe added dynamically.
058: *
059: * @author JAXWS Development Team
060: */
061: public class PortInfo implements WSPortInfo {
062: private final @NotNull
063: WSServiceDelegate owner;
064:
065: public final @NotNull
066: QName portName;
067: public final @NotNull
068: EndpointAddress targetEndpoint;
069: public final @NotNull
070: BindingID bindingId;
071:
072: /**
073: * If a port is known statically to a WSDL, {@link PortInfo} may
074: * have the corresponding WSDL model. This would occur when the
075: * service was created with the WSDL location and the port is defined
076: * in the WSDL.
077: * <p/>
078: * If this is a {@link SEIPortInfo}, then this is always non-null.
079: */
080: public final @Nullable
081: WSDLPort portModel;
082:
083: public PortInfo(WSServiceDelegate owner,
084: EndpointAddress targetEndpoint, QName name,
085: BindingID bindingId) {
086: this .owner = owner;
087: this .targetEndpoint = targetEndpoint;
088: this .portName = name;
089: this .bindingId = bindingId;
090: this .portModel = getPortModel(owner, name);
091: }
092:
093: public PortInfo(@NotNull
094: WSServiceDelegate owner, @NotNull
095: WSDLPort port) {
096: this .owner = owner;
097: this .targetEndpoint = port.getAddress();
098: this .portName = port.getName();
099: this .bindingId = port.getBinding().getBindingId();
100: this .portModel = port;
101: }
102:
103: /**
104: * Creates {@link BindingImpl} for this {@link PortInfo}.
105: *
106: * @param webServiceFeatures
107: * User-specified features.
108: * @param portInterface
109: * Null if this is for dispatch. Otherwise the interface the proxy is going to implement
110: */
111: public BindingImpl createBinding(
112: WebServiceFeature[] webServiceFeatures,
113: Class<?> portInterface) {
114: WebServiceFeatureList r = new WebServiceFeatureList(
115: webServiceFeatures);
116: if (portModel != null)
117: // merge features from WSDL
118: r.mergeFeatures(portModel,
119: portInterface == null/*if dispatch, true*/, false);
120:
121: // merge features from interceptor
122: for (WebServiceFeature wsf : owner.serviceInterceptor
123: .preCreateBinding(this , portInterface, r))
124: r.add(wsf);
125:
126: BindingImpl bindingImpl = BindingImpl.create(bindingId, r
127: .toArray());
128: owner.getHandlerConfigurator().configureHandlers(this ,
129: bindingImpl);
130:
131: return bindingImpl;
132: }
133:
134: //This method is used for Dispatch client only
135: private WSDLPort getPortModel(WSServiceDelegate owner,
136: QName portName) {
137:
138: if (owner.getWsdlService() != null) {
139: Iterable<WSDLPortImpl> ports = owner.getWsdlService()
140: .getPorts();
141: for (WSDLPortImpl port : ports) {
142: if (port.getName().equals(portName))
143: return port;
144: }
145: }
146: return null;
147: }
148:
149: //
150: // implementation of API PortInfo interface
151: //
152:
153: @Nullable
154: public WSDLPort getPort() {
155: return portModel;
156: }
157:
158: @NotNull
159: public WSService getOwner() {
160: return owner;
161: }
162:
163: @NotNull
164: public BindingID getBindingId() {
165: return bindingId;
166: }
167:
168: @NotNull
169: public EndpointAddress getEndpointAddress() {
170: return targetEndpoint;
171: }
172:
173: /**
174: * @deprecated
175: * Only meant to be used via {@link javax.xml.ws.handler.PortInfo}.
176: * Use {@link WSServiceDelegate#getServiceName()}.
177: */
178: public QName getServiceName() {
179: return owner.getServiceName();
180: }
181:
182: /**
183: * @deprecated
184: * Only meant to be used via {@link javax.xml.ws.handler.PortInfo}.
185: * Use {@link #portName}.
186: */
187: public QName getPortName() {
188: return portName;
189: }
190:
191: /**
192: * @deprecated
193: * Only meant to be used via {@link javax.xml.ws.handler.PortInfo}.
194: * Use {@link #bindingId}.
195: */
196: public String getBindingID() {
197: return bindingId.toString();
198: }
199: }
|