Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2008-01-19 05:59:08 +0000
committerslewis2008-01-19 05:59:08 +0000
commitf5b1cdc8a7df165f70ac52053febf69a2779f558 (patch)
tree69bf3a84fa350d61a6178d84e680326b07664946 /framework/bundles/org.eclipse.ecf.discovery
parent4d7b7c103a405c27ec98ca796acbd86dc88466d9 (diff)
downloadorg.eclipse.ecf-f5b1cdc8a7df165f70ac52053febf69a2779f558.tar.gz
org.eclipse.ecf-f5b1cdc8a7df165f70ac52053febf69a2779f558.tar.xz
org.eclipse.ecf-f5b1cdc8a7df165f70ac52053febf69a2779f558.zip
Added IServiceInfoAdapter in discovery API. Provided implementation (in ServiceInfo class), and added test code.
Diffstat (limited to 'framework/bundles/org.eclipse.ecf.discovery')
-rw-r--r--framework/bundles/org.eclipse.ecf.discovery/META-INF/MANIFEST.MF6
-rw-r--r--framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IDiscoveryContainerAdapter.java6
-rw-r--r--framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IServiceInfo.java3
-rw-r--r--framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IServiceInfoAdapter.java42
-rw-r--r--framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/ServiceInfo.java60
-rw-r--r--framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/internal/discovery/DiscoveryPlugin.java60
6 files changed, 166 insertions, 11 deletions
diff --git a/framework/bundles/org.eclipse.ecf.discovery/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf.discovery/META-INF/MANIFEST.MF
index 3596cfecf..43d023bb1 100644
--- a/framework/bundles/org.eclipse.ecf.discovery/META-INF/MANIFEST.MF
+++ b/framework/bundles/org.eclipse.ecf.discovery/META-INF/MANIFEST.MF
@@ -15,5 +15,7 @@ Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1,
J2SE-1.4
Require-Bundle: org.eclipse.equinox.common,
org.eclipse.ecf
-Import-Package: org.eclipse.osgi.util;version="1.1.0",
- org.osgi.framework;version="1.3.0"
+Import-Package: org.eclipse.osgi.util,
+ org.osgi.framework,
+ org.osgi.service.log;version="1.3.0",
+ org.osgi.util.tracker
diff --git a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IDiscoveryContainerAdapter.java b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IDiscoveryContainerAdapter.java
index 2fe40ad4b..b2705aef7 100644
--- a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IDiscoveryContainerAdapter.java
+++ b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IDiscoveryContainerAdapter.java
@@ -30,6 +30,12 @@ import org.eclipse.ecf.discovery.identity.*;
*/
public interface IDiscoveryContainerAdapter extends IAdaptable {
+ /** ECF Service Property Names **/
+ public static final String CONTAINER_FACTORY_NAME_PROPERTY = "org.eclipse.ecf.containerFactoryName"; //$NON-NLS-1$
+ public static final String CONTAINER_CONNECT_TARGET_PROTOCOL = "org.eclipse.ecf.connectTargetProtocol"; //$NON-NLS-1$
+ public static final String CONTAINER_CONNECT_REQUIRES_PASSWORD = "org.eclipse.ecf.connectContextRequiresPassword"; //$NON-NLS-1$
+ public static final String CONTAINER_CONNECT_PATH = "org.eclipse.ecf.connectTargetPath"; //$NON-NLS-1$
+
/**
* Add a service listener. The given listener will have its method called
* when a service is discovered.
diff --git a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IServiceInfo.java b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IServiceInfo.java
index c58bb4fdb..facc746b2 100644
--- a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IServiceInfo.java
+++ b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IServiceInfo.java
@@ -10,6 +10,7 @@
package org.eclipse.ecf.discovery;
import java.net.URI;
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.ecf.discovery.identity.IServiceID;
/**
@@ -17,7 +18,7 @@ import org.eclipse.ecf.discovery.identity.IServiceID;
* remotely discoverable service
*
*/
-public interface IServiceInfo {
+public interface IServiceInfo extends IAdaptable {
/**
* Get URI for service
*
diff --git a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IServiceInfoAdapter.java b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IServiceInfoAdapter.java
new file mode 100644
index 000000000..6adca7520
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IServiceInfoAdapter.java
@@ -0,0 +1,42 @@
+/****************************************************************************
+ * Copyright (c) 2008 Composent, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Composent, Inc. - initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.ecf.discovery;
+
+/**
+ * Adapter for IServiceInfo instances.
+ */
+public interface IServiceInfoAdapter {
+
+ /**
+ * Get container name associated with this service info.
+ * @return the container factory name. Will return <code>null</code> if no
+ * container factory name associated with this service info.
+ */
+ public String getContainerFactoryName();
+
+ /**
+ * Get the targetID for accessing the remote container.
+ * @return String targetID for use in connecting to the remote container. Will return <code>null</code>
+ * if there is incomplete/absent information for the info.
+ */
+ public String getTarget();
+
+ /**
+ * Set the container properties.
+ *
+ * @param containerFactoryName set the containerFactoryName for this info. May not be <code>null</code>.
+ * @param connectProtocol set the connectProtocol for the target. May not be <code>null</code>.
+ * @param connectPath set the connect path for the target. May be <code>null</code>.
+ * @param requiresPassword set whether the target requires a password. May be <code>null</code>.
+ */
+ public void setContainerProperties(String containerFactoryName, String connectProtocol, String connectPath, Boolean requiresPassword);
+}
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 9b9cb72ef..6a85d4d27 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
@@ -11,13 +11,16 @@ package org.eclipse.ecf.discovery;
import java.io.Serializable;
import java.net.URI;
+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;
/**
* Base implementation of {@link IServiceInfo}. Subclasses
* may be created as appropriate.
*/
-public class ServiceInfo implements IServiceInfo, Serializable {
+public class ServiceInfo implements IServiceInfo, Serializable, IServiceInfoAdapter {
private static final long serialVersionUID = -5651115550295457142L;
@@ -34,16 +37,18 @@ public class ServiceInfo implements IServiceInfo, Serializable {
protected IServiceProperties properties;
- public ServiceInfo() {
+ protected ServiceInfo() {
// null constructor for subclasses
}
public ServiceInfo(URI anURI, IServiceID serviceID, int priority, int weight, IServiceProperties props) {
this.uri = anURI;
+ Assert.isNotNull(this.uri);
this.serviceID = serviceID;
+ Assert.isNotNull(serviceID);
this.priority = priority;
this.weight = weight;
- this.properties = props;
+ this.properties = (props == null) ? new ServiceProperties() : props;
}
public ServiceInfo(URI anURI, IServiceID serviceID, IServiceProperties props) {
@@ -112,4 +117,53 @@ public class ServiceInfo implements IServiceInfo, Serializable {
return buf.toString();
}
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ */
+ public Object getAdapter(Class adapter) {
+ if (adapter.isInstance(this)) {
+ return this;
+ }
+ final IAdapterManager adapterManager = DiscoveryPlugin.getDefault().getAdapterManager();
+ if (adapterManager == null)
+ return null;
+ return adapterManager.loadAdapter(this, adapter.getName());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IServiceInfoAdapter#getContainerFactoryName()
+ */
+ public String getContainerFactoryName() {
+ return (properties == null) ? null : properties.getPropertyString(IDiscoveryContainerAdapter.CONTAINER_FACTORY_NAME_PROPERTY);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IServiceInfoAdapter#getTarget()
+ */
+ public String getTarget() {
+ if (uri == null || properties == null)
+ return null;
+ String targetValue = properties.getPropertyString(IDiscoveryContainerAdapter.CONTAINER_CONNECT_TARGET_PROTOCOL);
+ StringBuffer target = new StringBuffer(targetValue);
+ String auth = uri.getAuthority();
+ String path = properties.getPropertyString(IDiscoveryContainerAdapter.CONTAINER_CONNECT_PATH);
+ if (path == null)
+ path = "/"; //$NON-NLS-1$
+ target.append("://").append(auth).append("/").append(path); //$NON-NLS-1$ //$NON-NLS-2$
+ return target.toString();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IServiceInfoAdapter#setContainerProperties(java.lang.String, java.lang.String, java.lang.String, java.lang.Boolean)
+ */
+ public void setContainerProperties(String containerFactoryName, String connectProtocol, String connectPath, Boolean requiresPassword) {
+ Assert.isNotNull(containerFactoryName);
+ properties.setPropertyString(IDiscoveryContainerAdapter.CONTAINER_FACTORY_NAME_PROPERTY, containerFactoryName);
+ Assert.isNotNull(connectProtocol);
+ properties.setPropertyString(IDiscoveryContainerAdapter.CONTAINER_CONNECT_TARGET_PROTOCOL, connectProtocol);
+ if (connectPath != null)
+ properties.setPropertyString(IDiscoveryContainerAdapter.CONTAINER_CONNECT_PATH, connectPath);
+ if (requiresPassword != null)
+ properties.setPropertyString(IDiscoveryContainerAdapter.CONTAINER_CONNECT_REQUIRES_PASSWORD, requiresPassword.toString());
+ }
}
diff --git a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/internal/discovery/DiscoveryPlugin.java b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/internal/discovery/DiscoveryPlugin.java
index 27c7d4864..1179e46c5 100644
--- a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/internal/discovery/DiscoveryPlugin.java
+++ b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/internal/discovery/DiscoveryPlugin.java
@@ -9,8 +9,13 @@
package org.eclipse.ecf.internal.discovery;
+import org.eclipse.core.runtime.*;
+import org.eclipse.ecf.core.util.LogHelper;
+import org.eclipse.ecf.core.util.PlatformHelper;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.ServiceTracker;
/**
* The main plugin class to be used in the desktop.
@@ -22,6 +27,11 @@ public class DiscoveryPlugin implements BundleActivator {
// The shared instance.
private static DiscoveryPlugin plugin;
+ private BundleContext context;
+
+ private ServiceTracker adapterManagerTracker;
+ private ServiceTracker logServiceTracker = null;
+
/**
* The constructor.
*/
@@ -30,22 +40,62 @@ public class DiscoveryPlugin implements BundleActivator {
plugin = this;
}
+ public IAdapterManager getAdapterManager() {
+ // First, try to get the adapter manager via
+ if (adapterManagerTracker == null) {
+ adapterManagerTracker = new ServiceTracker(this.context, IAdapterManager.class.getName(), null);
+ adapterManagerTracker.open();
+ }
+ IAdapterManager adapterManager = (IAdapterManager) adapterManagerTracker.getService();
+ // Then, if the service isn't there, try to get from Platform class via
+ // PlatformHelper class
+ if (adapterManager == null)
+ adapterManager = PlatformHelper.getPlatformAdapterManager();
+ if (adapterManager == null)
+ getDefault().log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "Cannot get adapter manager", null)); //$NON-NLS-1$
+ return adapterManager;
+ }
+
+ public LogService getLogService() {
+ if (logServiceTracker == null) {
+ logServiceTracker = new ServiceTracker(this.context, LogService.class.getName(), null);
+ logServiceTracker.open();
+ }
+ return (LogService) logServiceTracker.getService();
+ }
+
+ public void log(IStatus status) {
+ LogService logService = getLogService();
+ if (logService != null) {
+ logService.log(LogHelper.getLogCode(status), LogHelper.getLogMessage(status), status.getException());
+ }
+ }
+
/**
* This method is called upon plug-in activation
- * @param context
+ * @param ctxt the bundle context
* @throws Exception
*/
- public void start(BundleContext context) throws Exception {
- // nothing to do
+ public void start(BundleContext ctxt) throws Exception {
+ this.context = ctxt;
}
/**
* This method is called when the plug-in is stopped
- * @param context
+ * @param ctxt the bundle context
* @throws Exception
*/
- public void stop(BundleContext context) throws Exception {
+ public void stop(BundleContext ctxt) throws Exception {
+ if (logServiceTracker != null) {
+ logServiceTracker.close();
+ logServiceTracker = null;
+ }
+ if (adapterManagerTracker != null) {
+ adapterManagerTracker.close();
+ adapterManagerTracker = null;
+ }
plugin = null;
+ this.context = null;
}
/**

Back to the top