// import bindings and portTypes needed by services and ports
QName serviceQName = wsBinding.getServiceName();
String portName = wsBinding.getPortName();
if (serviceQName != null) {
Service service = def.getService(serviceQName);
if (portName != null) {
Port port = service.getPort(portName);
Port newPort = copyPort(newDef, port, wsBinding);
if (newPort != null) {
importBinding(port.getBinding(), wsdlDefinition, newDef, imports);
ports.add(newPort);
} else {
error(monitor, "InvalidPort", wsBinding, serviceQName.toString(), portName,
component.getName(), contract.getName());
}
} else {
for (Object port : service.getPorts().values()) {
Port newPort = copyPort(newDef, (Port)port, wsBinding);
if (newPort != null) {
importBinding(((Port)port).getBinding(), wsdlDefinition, newDef, imports);
ports.add(newPort);
} else {
// not an error, just ignore the port
warning(monitor, "IgnoringPort", wsBinding, serviceQName.toString(), ((Port)port).getName(),
component.getName(), contract.getName());
}
}
if (ports.size() == 0) {
error(monitor, "NoValidPorts", wsBinding, serviceQName.toString(),
component.getName(), contract.getName());
}
}
}
// replace original WSDL definition by the generated definition
def = newDef;
} else {
// The WSDL definition was generated by Interface2WSDLGenerator.
// Reuse it instead of creating a new definition here.
}
// add a service and ports to the generated definition
WSDLDefinitionGenerator helper =
new WSDLDefinitionGenerator(BindingWSDLGenerator.requiresSOAP12(wsBinding));
WSDLInterface wi = (WSDLInterface)wsBinding.getBindingInterfaceContract().getInterface();
PortType portType = wi.getPortType();
Service service = helper.createService(def, portType);
if (wsBinding.getBinding() == null && ports.size() == 0) {
Binding binding = helper.createBinding(def, portType);
if (BindingWSDLGenerator.requiresSOAP12(wsBinding)) {
def.addNamespace("soap12", "http://schemas.xmlsoap.org/wsdl/soap12/");
} else {
def.addNamespace("soap11", "http://schemas.xmlsoap.org/wsdl/soap/");
}
helper.createBindingOperations(def, binding, portType);
binding.setUndefined(false);
def.addBinding(binding);
String endpointURI = computeActualURI(wsBinding, null);
Port port = helper.createPort(def, binding, service, endpointURI);
wsBinding.setService(service);
wsBinding.setPort(port);
} else {
if (ports.size() > 0) {
// there are one or more user-specified valid ports
for (Port port : ports) {
service.addPort(port);
}
if (ports.size() == 1) {
// only one port, so use it
wsBinding.setPort(ports.get(0));
} else {