package com.sun.xml.internal.ws.client;
import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.Nullable;
import com.sun.xml.internal.ws.api.BindingID;
import com.sun.xml.internal.ws.api.EndpointAddress;
import com.sun.xml.internal.ws.api.WSService;
import com.sun.xml.internal.ws.api.client.WSPortInfo;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
import com.sun.xml.internal.ws.binding.BindingImpl;
import com.sun.xml.internal.ws.binding.WebServiceFeatureList;
import com.sun.xml.internal.ws.model.wsdl.WSDLPortImpl;
import javax.xml.namespace.QName;
import javax.xml.ws.WebServiceFeature;
import javax.xml.ws.WebServiceException;
public class PortInfo implements WSPortInfo {
private final @NotNull WSServiceDelegate owner;
public final @NotNull QName portName;
public final @NotNull EndpointAddress targetEndpoint;
public final @NotNull BindingID bindingId;
public final @Nullable WSDLPort portModel;
public PortInfo(WSServiceDelegate owner, EndpointAddress targetEndpoint, QName name, BindingID bindingId) {
this.owner = owner;
this.targetEndpoint = targetEndpoint;
this.portName = name;
this.bindingId = bindingId;
this.portModel = getPortModel(owner, name);
}
public PortInfo(@NotNull WSServiceDelegate owner, @NotNull WSDLPort port) {
this.owner = owner;
this.targetEndpoint = port.getAddress();
this.portName = port.getName();
this.bindingId = port.getBinding().getBindingId();
this.portModel = port;
}
public BindingImpl createBinding(WebServiceFeature[] webServiceFeatures, Class<?> portInterface) {
WebServiceFeatureList r = new WebServiceFeatureList(webServiceFeatures);
if (portModel != null)
r.mergeFeatures(portModel, portInterface==null, false);
for( WebServiceFeature wsf : owner.serviceInterceptor.preCreateBinding(this,portInterface,r) )
r.add(wsf);
BindingImpl bindingImpl = BindingImpl.create(bindingId, r.toArray());
owner.getHandlerConfigurator().configureHandlers(this,bindingImpl);
return bindingImpl;
}
private WSDLPort getPortModel(WSServiceDelegate owner, QName portName) {
if (owner.getWsdlService() != null){
Iterable<WSDLPortImpl> ports = owner.getWsdlService().getPorts();
for (WSDLPortImpl port : ports){
if (port.getName().equals(portName))
return port;
}
}
return null;
}
@Nullable
public WSDLPort getPort() {
return portModel;
}
@NotNull
public WSService getOwner() {
return owner;
}
@NotNull
public BindingID getBindingId() {
return bindingId;
}
@NotNull
public EndpointAddress getEndpointAddress() {
return targetEndpoint;
}
public QName getServiceName() {
return owner.getServiceName();
}
public QName getPortName() {
return portName;
}
public String getBindingID() {
return bindingId.toString();
}
}