Merge branch 'master' of ssh://slewis@git.eclipse.org:29418/ecf/org.eclipse.ecf.git
diff --git a/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/r_osgi/impl/ChannelEndpointImpl.java b/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/r_osgi/impl/ChannelEndpointImpl.java
index 46bd978..100dba8 100644
--- a/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/r_osgi/impl/ChannelEndpointImpl.java
+++ b/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/r_osgi/impl/ChannelEndpointImpl.java
@@ -218,6 +218,8 @@
 			t.printStackTrace();
 	}
 	
+	private static final boolean topicsDisabled = System.getProperty("ch.ethz.iks.r_osgi.topic.filter","").equals("*");
+	
 	/**
 	 * create a new channel endpoint.
 	 * 
@@ -1598,7 +1600,7 @@
 			// ch.ethz.iks.r_osgi.impl.RemoteOSGiServiceImpl.setupTrackers(...).new
 			// ServiceTrackerCustomizer() {...}.removedService(ServiceReference,
 			// Object)) with null as the topicsAdded list. Thus, ignore null.
-			if (topicsAdded != null && topicsAdded.length > 0) {
+			if (!topicsDisabled && topicsAdded != null && topicsAdded.length > 0) {
 				// register handler
 				final Dictionary properties = new Hashtable();
 				properties.put(EventConstants.EVENT_TOPIC, topicsAdded);
@@ -1618,11 +1620,11 @@
 				remoteTopics.addAll(Arrays.asList(topicsAdded));
 			}
 
-			if (remoteTopics.size() == 0) {
+			if (remoteTopics.size() == 0 && handlerReg != null) {
 				// unregister handler
 				handlerReg.unregister();
 				handlerReg = null;
-			} else {
+			} else if (handlerReg != null) {
 				// update topics
 				final Dictionary properties = new Hashtable();
 				properties.put(EventConstants.EVENT_TOPIC, remoteTopics
diff --git a/providers/bundles/org.eclipse.ecf.provider.r_osgi/META-INF/MANIFEST.MF b/providers/bundles/org.eclipse.ecf.provider.r_osgi/META-INF/MANIFEST.MF
index 54cbf37..6eba4cb 100644
--- a/providers/bundles/org.eclipse.ecf.provider.r_osgi/META-INF/MANIFEST.MF
+++ b/providers/bundles/org.eclipse.ecf.provider.r_osgi/META-INF/MANIFEST.MF
@@ -3,13 +3,15 @@
 Bundle-Name: %plugin.name
 Bundle-SymbolicName: org.eclipse.ecf.provider.r_osgi;singleton:=true
 Automatic-Module-Name: org.eclipse.ecf.provider.r_osgi
-Bundle-Version: 3.6.301.qualifier
+Bundle-Version: 3.6.400.qualifier
 Import-Package: ch.ethz.iks.r_osgi;version="[1.0.1,2.0.0)",
  org.eclipse.ecf.core.util.reflection,
+ org.eclipse.ecf.osgi.services.remoteserviceadmin;version="1.3.0",
  org.eclipse.ecf.remoteservice.asyncproxy;version="[1.0.0,3.0.0)",
  org.eclipse.equinox.concurrent.future;version="[1.0.0,2.0.0)",
  org.osgi.framework;version="[1.3.0,2.0.0)",
  org.osgi.framework.wiring;version="[1.2.0,3.0.0)",
+ org.osgi.service.remoteserviceadmin;version="1.1.0",
  org.osgi.util.tracker;version="[1.3.3,2.0.0)"
 Require-Bundle: org.eclipse.ecf;bundle-version="[3.1.0,4.0.0)",
  org.eclipse.ecf.provider;bundle-version="[4.0.0,5.0.0)",
diff --git a/providers/bundles/org.eclipse.ecf.provider.r_osgi/pom.xml b/providers/bundles/org.eclipse.ecf.provider.r_osgi/pom.xml
index a6f5560..8bf605c 100644
--- a/providers/bundles/org.eclipse.ecf.provider.r_osgi/pom.xml
+++ b/providers/bundles/org.eclipse.ecf.provider.r_osgi/pom.xml
@@ -10,6 +10,6 @@
   </parent>
   <groupId>org.eclipse.ecf</groupId>
   <artifactId>org.eclipse.ecf.provider.r_osgi</artifactId>
-  <version>3.6.301-SNAPSHOT</version>
+  <version>3.4.400-SNAPSHOT</version>
   <packaging>eclipse-plugin</packaging>
 </project>
diff --git a/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/R_OSGiRemoteServiceContainer.java b/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/R_OSGiRemoteServiceContainer.java
index 1e39ed5..f64981a 100644
--- a/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/R_OSGiRemoteServiceContainer.java
+++ b/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/R_OSGiRemoteServiceContainer.java
@@ -24,6 +24,7 @@
 import org.eclipse.ecf.core.events.*;
 import org.eclipse.ecf.core.identity.*;
 import org.eclipse.ecf.core.security.IConnectContext;
+import org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription;
 import org.eclipse.ecf.provider.r_osgi.identity.*;
 import org.eclipse.ecf.remoteservice.*;
 import org.eclipse.ecf.remoteservice.events.IRemoteServiceRegisteredEvent;
@@ -33,6 +34,7 @@
 import org.osgi.framework.Constants;
 import org.osgi.framework.wiring.BundleCapability;
 import org.osgi.framework.wiring.BundleRevision;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
 import org.osgi.util.tracker.ServiceTracker;
 import org.osgi.util.tracker.ServiceTrackerCustomizer;
 
@@ -42,7 +44,7 @@
  * 
  * @author Jan S. Rellermeyer, ETH Zurich
  */
-class R_OSGiRemoteServiceContainer implements IOSGiRemoteServiceContainerAdapter, IRemoteServiceContainerAdapter, IContainer, RemoteServiceListener {
+class R_OSGiRemoteServiceContainer implements IOSGiRemoteServiceContainerAdapter, IRemoteServiceContainerAdapter, IContainer, RemoteServiceListener, IRSAConsumerContainerAdapter {
 
 	// the bundle context.
 	private BundleContext context;
@@ -557,6 +559,8 @@
 			return this;
 		} else if (adapter.equals(IContainer.class)) {
 			return this;
+		} else if (adapter.equals(IRSAConsumerContainerAdapter.class)) {
+			return this;
 		}
 		return null;
 	}
@@ -885,4 +889,57 @@
 		}
 	}
 
+	public IRemoteServiceReference[] importEndpoint(Map<String, Object> endpointDescriptionProperties) throws ContainerConnectException, InvalidSyntaxException {
+		EndpointDescription endpointDescription = new EndpointDescription(endpointDescriptionProperties);
+		ID endpointContainerID = endpointDescription.getContainerID();
+		Assert.isNotNull(endpointContainerID);
+		// Get connect target ID. May be null
+		ID tID = endpointDescription.getConnectTargetID();
+		if (tID == null)
+			tID = endpointContainerID;
+		final ID targetID = tID;
+		return getRemoteServiceReferences(targetID, getIDFilter(endpointDescription, targetID), endpointDescription.getInterfaces().iterator().next(), getRemoteServiceFilter(endpointDescription));
+	}
+
+	private String getRemoteServiceFilter(EndpointDescription endpointDescription) {
+
+		String intf = endpointDescription.getInterfaces().iterator().next();
+		String packageName = intf.substring(0, intf.lastIndexOf('.'));
+		String edRsFilter = endpointDescription.getRemoteServiceFilter();
+		// if edRsFilter is explicitly set, then simply use it
+		if (edRsFilter == null) {
+			Version intfPackageVersion = endpointDescription.getPackageVersion(packageName);
+			edRsFilter = "(" + RemoteConstants.ENDPOINT_PACKAGE_VERSION_ + packageName + "=" + intfPackageVersion + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+		}
+		long rsId = 0;
+		// if the ECF remote service id is present in properties, allow it to
+		// override
+		Long l = endpointDescription.getRemoteServiceId();
+		if (l != null)
+			rsId = l.longValue();
+		// if rsId is still zero, use the endpoint.service.id from
+		// endpoint description
+		if (rsId == 0)
+			rsId = endpointDescription.getServiceId();
+		// If it's *still* zero, then just use the raw filter
+		if (rsId == 0) {
+			// It's not known...so we just return the 'raw' remote service
+			// filter
+			return edRsFilter;
+		}
+		// It's a real remote service id...so we return
+		StringBuffer result = new StringBuffer("(&(") //$NON-NLS-1$
+				.append(org.eclipse.ecf.remoteservice.Constants.SERVICE_ID).append("=").append(rsId).append(")"); //$NON-NLS-1$ //$NON-NLS-2$
+		if (edRsFilter != null)
+			result.append(edRsFilter);
+		result.append(")"); //$NON-NLS-1$
+		return result.toString();
+	}
+
+	private ID[] getIDFilter(EndpointDescription endpointDescription, ID endpointID) {
+		ID[] idFilter = endpointDescription.getIDFilter();
+		// If it is null,
+		return (idFilter == null) ? new ID[] {endpointID} : idFilter;
+	}
+
 }