Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Alexander Kuppe2010-06-11 08:12:44 -0400
committerMarkus Alexander Kuppe2010-06-11 08:12:44 -0400
commite1fcd4c9cd712ddeb5292697e895cc1da3f611c4 (patch)
tree2717bbf9edbac8fa9f62f2af1f627f9931e9488c /tests/bundles/org.eclipse.ecf.tests.provider.dnssd
parent658e88cc968fa3738be74d2c69727da2c988b77d (diff)
downloadorg.eclipse.ecf-e1fcd4c9cd712ddeb5292697e895cc1da3f611c4.tar.gz
org.eclipse.ecf-e1fcd4c9cd712ddeb5292697e895cc1da3f611c4.tar.xz
org.eclipse.ecf-e1fcd4c9cd712ddeb5292697e895cc1da3f611c4.zip
WIP - bug 314998: [Discovery][DNS-SD] Make provider configurable with Configuration Admin
https://bugs.eclipse.org/bugs/show_bug.cgi?id=314998
Diffstat (limited to 'tests/bundles/org.eclipse.ecf.tests.provider.dnssd')
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.dnssd/META-INF/MANIFEST.MF4
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.dnssd/src/org/eclipse/ecf/tests/provider/dnssd/Activator.java88
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.dnssd/src/org/eclipse/ecf/tests/provider/dnssd/DnsSdDiscoveryServiceTestWithParamsSet.java7
3 files changed, 93 insertions, 6 deletions
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.dnssd/META-INF/MANIFEST.MF b/tests/bundles/org.eclipse.ecf.tests.provider.dnssd/META-INF/MANIFEST.MF
index 1aabfc917..7e82b5d28 100644
--- a/tests/bundles/org.eclipse.ecf.tests.provider.dnssd/META-INF/MANIFEST.MF
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.dnssd/META-INF/MANIFEST.MF
@@ -11,3 +11,7 @@ Require-Bundle: org.eclipse.equinox.common;bundle-version="3.4.0",
org.eclipse.ecf.provider.dnssd;bundle-version="1.0.0",
org.eclipse.ecf.tests.discovery;bundle-version="2.0.0",
org.junit;bundle-version="3.8.2"
+Bundle-ActivationPolicy: lazy
+Import-Package: org.osgi.framework;version="1.3.0",
+ org.osgi.service.cm;version="1.2.0"
+Bundle-Activator: org.eclipse.ecf.tests.provider.dnssd.Activator
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.dnssd/src/org/eclipse/ecf/tests/provider/dnssd/Activator.java b/tests/bundles/org.eclipse.ecf.tests.provider.dnssd/src/org/eclipse/ecf/tests/provider/dnssd/Activator.java
new file mode 100644
index 000000000..c90eac5fb
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.dnssd/src/org/eclipse/ecf/tests/provider/dnssd/Activator.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Markus Alexander Kuppe.
+ * 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:
+ * Markus Alexander Kuppe (ecf-dev_eclipse.org <at> lemmster <dot> de) - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.tests.provider.dnssd;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.eclipse.ecf.discovery.IDiscoveryLocator;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+public class Activator implements BundleActivator {
+ private static Activator instance;
+
+ private Filter filter;
+
+ private BundleContext context;
+
+ public Activator() {
+ instance = this;
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ this.context = context;
+
+ final ServiceReference configAdminServiceRef = context
+ .getServiceReference(ConfigurationAdmin.class.getName());
+
+ if (configAdminServiceRef != null) {
+ ConfigurationAdmin configAdmin = (ConfigurationAdmin) context
+ .getService(configAdminServiceRef);
+
+ Configuration config = configAdmin.createFactoryConfiguration(
+ DnsSdDiscoveryServiceTest.ECF_DISCOVERY_DNSSD, null);
+ Dictionary properties = new Hashtable();
+ properties.put("searchPath", new String[]{DnsSdDiscoveryServiceTest.DOMAIN});
+ properties.put("resolver", "8.8.8.8");
+ config.update(properties);
+
+ filter = context.createFilter("(" + Constants.SERVICE_PID + "=" + config.getPid() + ")");
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ context = null;
+ }
+
+ public static Activator getDefault() {
+ return instance;
+ }
+
+ public IDiscoveryLocator getDiscoveryLocator() {
+ //TODO need to block until the service comes available
+ ServiceReference[] references = null;
+ try {
+ references = context.getServiceReferences(IDiscoveryLocator.class.getName(), filter.toString());
+ } catch (InvalidSyntaxException e) {
+ // may never happen
+ e.printStackTrace();
+ return null;
+ }
+ for (int i = 0; i < references.length;) {
+ ServiceReference serviceReference = references[i];
+ return (IDiscoveryLocator) context.getService(serviceReference);
+ }
+ return null;
+ }
+}
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.dnssd/src/org/eclipse/ecf/tests/provider/dnssd/DnsSdDiscoveryServiceTestWithParamsSet.java b/tests/bundles/org.eclipse.ecf.tests.provider.dnssd/src/org/eclipse/ecf/tests/provider/dnssd/DnsSdDiscoveryServiceTestWithParamsSet.java
index 985e19722..66a0905c9 100644
--- a/tests/bundles/org.eclipse.ecf.tests.provider.dnssd/src/org/eclipse/ecf/tests/provider/dnssd/DnsSdDiscoveryServiceTestWithParamsSet.java
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.dnssd/src/org/eclipse/ecf/tests/provider/dnssd/DnsSdDiscoveryServiceTestWithParamsSet.java
@@ -11,7 +11,6 @@
package org.eclipse.ecf.tests.provider.dnssd;
import org.eclipse.ecf.discovery.IDiscoveryLocator;
-import org.eclipse.ecf.provider.dnssd.DnsSdDisocoveryLocator;
public class DnsSdDiscoveryServiceTestWithParamsSet extends
DnsSdDiscoveryServiceTest {
@@ -26,10 +25,6 @@ public class DnsSdDiscoveryServiceTestWithParamsSet extends
* @see org.eclipse.ecf.tests.discovery.DiscoveryServiceTest#getDiscoveryLocator()
*/
protected IDiscoveryLocator getDiscoveryLocator() {
- DnsSdDisocoveryLocator locator = (DnsSdDisocoveryLocator) super.getDiscoveryLocator();
- locator.setSearchPath(new String[]{DOMAIN});
- locator.setResolver(RESOLVER);
- return locator;
+ return Activator.getDefault().getDiscoveryLocator();
}
-
}

Back to the top