diff options
Diffstat (limited to 'framework/bundles/org.eclipse.ecf.discovery')
4 files changed, 35 insertions, 2 deletions
diff --git a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/ServiceInfo.java b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/ServiceInfo.java index 740359bb1..6c5a0f0ab 100644 --- a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/ServiceInfo.java +++ b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/ServiceInfo.java @@ -10,11 +10,12 @@ package org.eclipse.ecf.discovery; import java.io.Serializable; -import java.net.URI; +import java.net.*; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IAdapterManager; import org.eclipse.ecf.discovery.identity.IServiceID; import org.eclipse.ecf.internal.discovery.DiscoveryPlugin; +import org.eclipse.ecf.internal.discovery.Messages; /** * Base implementation of {@link IServiceInfo}. Subclasses @@ -26,6 +27,7 @@ public class ServiceInfo implements IServiceInfo, Serializable, IContainerServic public static final int DEFAULT_PRIORITY = 0; public static final int DEFAULT_WEIGHT = 0; + public static final String DEFAULT_PROTOCOL = "xxxxx"; //$NON-NLS-1$ protected URI uri = null; @@ -51,6 +53,31 @@ public class ServiceInfo implements IServiceInfo, Serializable, IContainerServic this.properties = (props == null) ? new ServiceProperties() : props; } + public ServiceInfo(String host, int port, IServiceID serviceID, int priority, int weight, IServiceProperties props) { + try { + if (host == null) + host = InetAddress.getLocalHost().getHostAddress(); + uri = new URI(DEFAULT_PROTOCOL, null, host, port, null, null, null); + } catch (URISyntaxException e) { + throw new IllegalArgumentException(Messages.ServiceInfo_EXCEPTION_INVALID_HOST_ARG); + } catch (UnknownHostException e) { + throw new IllegalArgumentException(Messages.ServiceInfo_EXCEPTION_NO_LOCALHOST); + } + this.serviceID = serviceID; + Assert.isNotNull(serviceID); + this.priority = priority; + this.weight = weight; + this.properties = (props == null) ? new ServiceProperties() : props; + } + + public ServiceInfo(String host, int port, IServiceID serviceID, IServiceProperties props) { + this(host, port, serviceID, DEFAULT_PRIORITY, DEFAULT_WEIGHT, props); + } + + public ServiceInfo(String host, int port, IServiceID serviceID) { + this(host, port, serviceID, new ServiceProperties()); + } + public ServiceInfo(URI anURI, IServiceID serviceID, IServiceProperties props) { this(anURI, serviceID, DEFAULT_PRIORITY, DEFAULT_WEIGHT, props); } @@ -147,6 +174,8 @@ public class ServiceInfo implements IServiceInfo, Serializable, IContainerServic if (connectTarget != null) return connectTarget; String t = properties.getPropertyString(IDiscoveryContainerAdapter.CONTAINER_CONNECT_TARGET_PROTOCOL); + if (t == null) + return null; StringBuffer target = new StringBuffer(t); String auth = uri.getAuthority(); String path = properties.getPropertyString(IDiscoveryContainerAdapter.CONTAINER_CONNECT_TARGET_PATH); diff --git a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/service/IDiscoveryService.java b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/service/IDiscoveryService.java index 7f7ba48c2..27b359947 100644 --- a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/service/IDiscoveryService.java +++ b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/service/IDiscoveryService.java @@ -20,5 +20,5 @@ import org.eclipse.ecf.discovery.IDiscoveryContainerAdapter; */ public interface IDiscoveryService extends IDiscoveryContainerAdapter { // All methods provided by superclass - + public static final String CONTAINER_ID = "org.eclipse.ecf.discovery.containerID"; //$NON-NLS-1$ } diff --git a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/internal/discovery/Messages.java b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/internal/discovery/Messages.java index db397ef0a..e26822594 100644 --- a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/internal/discovery/Messages.java +++ b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/internal/discovery/Messages.java @@ -18,6 +18,8 @@ import org.eclipse.osgi.util.NLS; */ public class Messages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.ecf.internal.discovery.messages"; //$NON-NLS-1$ + public static String ServiceInfo_EXCEPTION_INVALID_HOST_ARG; + public static String ServiceInfo_EXCEPTION_NO_LOCALHOST; public static String ServiceTypeID_EXCEPTION_SERVICE_TYPE_ID_NOT_NULL; public static String ServiceTypeID_EXCEPTION_SERVICE_TYPE_ID_NOT_PARSEABLE; static { diff --git a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/internal/discovery/messages.properties b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/internal/discovery/messages.properties index 3ab8c19b9..e25eb48f2 100644 --- a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/internal/discovery/messages.properties +++ b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/internal/discovery/messages.properties @@ -1,2 +1,4 @@ +ServiceInfo_EXCEPTION_INVALID_HOST_ARG=Invalid host argument +ServiceInfo_EXCEPTION_NO_LOCALHOST=Cannot get localhost address ServiceTypeID_EXCEPTION_SERVICE_TYPE_ID_NOT_NULL=ServiceTypeID cannot be null ServiceTypeID_EXCEPTION_SERVICE_TYPE_ID_NOT_PARSEABLE=ServiceTypeID cannot be parsed |