1 package com.ontotext.ordi.wsmo4rdf.remote.client; 2 3 import java.net.MalformedURLException; 4 import java.net.URL; 5 6 import javax.xml.namespace.QName; 7 8 import com.ontotext.ordi.wsmo4rdf.remote.ORDIServiceType; 9 import com.ontotext.ordi.wsmo4rdf.remote.client.conn.WsmoConnectionService; 10 import com.ontotext.ordi.wsmo4rdf.remote.client.conn.WsmoConnectionService_Service; 11 import com.ontotext.ordi.wsmo4rdf.remote.client.fact.RemoteFactory; 12 import com.ontotext.ordi.wsmo4rdf.remote.client.fact.RemoteFactory_Service; 13 import com.ontotext.ordi.wsmo4rdf.remote.client.src.WsmoSourceService; 14 import com.ontotext.ordi.wsmo4rdf.remote.client.src.WsmoSourceService_Service; 15 16 public class RemoteWsmo4rdfGate { 17 private final String host; 18 private final int port; 19 20 private final RemoteFactory factoryService; 21 private final WsmoSourceService sourceService; 22 private final WsmoConnectionService connectionService; 23 24 public RemoteWsmo4rdfGate(final String host, final int port) { 25 this.host = host; 26 this.port = port; 27 28 this.factoryService = getRemoteFactoryPort(); 29 this.sourceService = getWsmoSourceServicePort(); 30 this.connectionService = getWsmoConnectionServicePort(); 31 } 32 33 public String getHost() { 34 return host; 35 } 36 37 public int getPort() { 38 return port; 39 } 40 41 private RemoteFactory getRemoteFactoryPort() { 42 URL wsdlUrl = constructWsdlUrl(host, port, ORDIServiceType.FACTORY); 43 44 QName svcQName = new QName("http://server.remote.wsmo4rdf.ordi.ontotext.com/", "RemoteFactory"); 45 RemoteFactory_Service webService = new RemoteFactory_Service(wsdlUrl, svcQName); 46 return webService.getRemoteFactoryImplPort(); 47 } 48 49 private WsmoSourceService getWsmoSourceServicePort() { 50 URL wsdlUrl = constructWsdlUrl(host, port, ORDIServiceType.SOURCE); 51 52 QName svcQName = new QName("http://server.remote.wsmo4rdf.ordi.ontotext.com/", "WsmoSourceService"); 53 WsmoSourceService_Service webService = new WsmoSourceService_Service(wsdlUrl, svcQName); 54 return webService.getWsmoSourceServiceImplPort(); 55 } 56 57 private WsmoConnectionService getWsmoConnectionServicePort() { 58 URL wsdlUrl = constructWsdlUrl(host, port, ORDIServiceType.CONNECTION); 59 60 QName svcQName = new QName("http://server.remote.wsmo4rdf.ordi.ontotext.com/", "WsmoConnectionService"); 61 WsmoConnectionService_Service webService = new WsmoConnectionService_Service(wsdlUrl, svcQName); 62 return webService.getWsmoConnectionServiceImplPort(); 63 } 64 65 private static URL constructWsdlUrl(final String host, final int port, ORDIServiceType service) { 66 if ( host == null || port < 0 || service == null) { 67 throw new IllegalArgumentException(); 68 } 69 70 URL wsdlUrl = null; 71 try { 72 wsdlUrl = new URL("http://" + host + ":" + port + "/" + service.getServiceName()+ "?wsdl"); 73 } catch (MalformedURLException e) { 74 throw new IllegalArgumentException("URL construction failed"); 75 } 76 assert(wsdlUrl != null); 77 return wsdlUrl; 78 } 79 80 public RemoteFactory getFactoryService() { 81 return factoryService; 82 } 83 84 public WsmoSourceService getSourceService() { 85 return sourceService; 86 } 87 88 public WsmoConnectionService getConnectionService() { 89 return connectionService; 90 } 91 }