*/
public static Port getPort(WSDLManager manager, EndpointReferenceType ref) throws WSDLException {
Definition def = getWSDLDefinition(manager, ref);
if (def == null) {
throw new WSDLException(WSDLException.OTHER_ERROR, "unable to find definition for reference");
}
MetadataType metadata = ref.getMetadata();
for (Object obj : metadata.getAny()) {
if (obj instanceof JAXBElement) {
Object jaxbVal = ((JAXBElement<?>)obj).getValue();
if (jaxbVal instanceof ServiceNameType) {
Port port = null;
ServiceNameType snt = (ServiceNameType)jaxbVal;
if (LOG.isLoggable(Level.FINEST)) {
LOG.log(Level.FINEST, "found service name " + snt.getValue().getLocalPart());
}
Service service = def.getService(snt.getValue());
if (service == null) {
LOG.log(Level.WARNING, "can't find the service name ["
+ snt.getValue()
+ "], using the default service name in wsdl");
service = (Service)def.getServices().values().iterator().next();
if (service == null) {
return null;
}
}
String endpoint = snt.getEndpointName();
if ("".equals(endpoint) && service.getPorts().size() == 1) {
port = (Port)service.getPorts().values().iterator().next();
} else {
port = service.getPort(endpoint);
}
// FIXME this needs to be looked at service.getPort(endpoint)
//should not return null when endpoint is valid
if (port == null) {
LOG.log(Level.WARNING, "can't find the port name ["
+ endpoint
+ "], using the default port name in wsdl");
port = (Port)service.getPorts().values().iterator().next();
}
return port;
}
}
}
if (def.getServices().size() == 1) {
Service service = (Service)def.getServices().values().iterator().next();
if (service.getPorts().size() == 1) {
return (Port)service.getPorts().values().iterator().next();
}
}
QName serviceName = getServiceName(ref, null);
if (null != serviceName) {
if (StringUtils.isEmpty(serviceName.getNamespaceURI())) {
serviceName = new QName(def.getTargetNamespace(), serviceName.getLocalPart());
}
Service service = def.getService(serviceName);
if (service == null) {
throw new WSDLException(WSDLException.OTHER_ERROR, "Cannot find service for " + serviceName);
}
if (service.getPorts().size() == 1) {
return (Port)service.getPorts().values().iterator().next();
}
String str = getPortName(ref);
LOG.log(Level.FINE, "getting port " + str + " from service " + service.getQName());
Port port = service.getPort(str);
if (port == null) {
throw new WSDLException(WSDLException.OTHER_ERROR, "unable to find port " + str);
}
return port;
}
// TODO : throw exception here
return null;