Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkuppe2009-03-14 15:58:01 +0000
committermkuppe2009-03-14 15:58:01 +0000
commit5c312c35386ba8fe426628ab0b92f8d5020db46e (patch)
treee6e4e4ce5de9a6088bf2c2982b8a84e330b51536 /tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender
parentf0f65a02534c9ed554959418feb6287df05f69a7 (diff)
downloadorg.eclipse.ecf-5c312c35386ba8fe426628ab0b92f8d5020db46e.tar.gz
org.eclipse.ecf-5c312c35386ba8fe426628ab0b92f8d5020db46e.tar.xz
org.eclipse.ecf-5c312c35386ba8fe426628ab0b92f8d5020db46e.zip
Add new bundle that intercepts and overwrite IDiscoveryAdvertiser registrations to make them available via RFC119
Diffstat (limited to 'tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender')
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/.classpath7
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/.project34
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/.settings/org.eclipse.pde.core.prefs5
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/META-INF/MANIFEST.MF14
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/OSGI-INF/l10n/bundle.properties3
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/about.html28
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/build.properties6
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/src/org/eclipse/ecf/tests/discovery/remote_extender/Activator.java97
9 files changed, 202 insertions, 0 deletions
diff --git a/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/.classpath b/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/.classpath
new file mode 100644
index 000000000..6f3b481ac
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.1%Foundation-1.1"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/.project b/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/.project
new file mode 100644
index 000000000..4524ca017
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/.project
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.ecf.tests.discovery.remote-extender</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
+ </natures>
+</projectDescription>
diff --git a/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/.settings/org.eclipse.jdt.core.prefs b/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..576ef45aa
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Sat Mar 14 14:31:00 CET 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.3
diff --git a/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/.settings/org.eclipse.pde.core.prefs b/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/.settings/org.eclipse.pde.core.prefs
new file mode 100644
index 000000000..5a22e23cb
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/.settings/org.eclipse.pde.core.prefs
@@ -0,0 +1,5 @@
+#Sat Mar 14 14:30:28 CET 2009
+eclipse.preferences.version=1
+pluginProject.equinox=false
+pluginProject.extensions=false
+resolve.requirebundle=false
diff --git a/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/META-INF/MANIFEST.MF b/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..04d9010ed
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/META-INF/MANIFEST.MF
@@ -0,0 +1,14 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %Bundle-Name.0
+Bundle-SymbolicName: org.eclipse.ecf.tests.discovery.remote_extender
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.eclipse.ecf.tests.discovery.remote_extender.Activator
+Import-Package: org.eclipse.ecf.discovery;version="3.0.0",
+ org.osgi.framework;version="1.3.0",
+ org.osgi.framework.hooks.service;version="1.0.0"
+Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1,
+ J2SE-1.4
+Bundle-Vendor: %Bundle-Vendor.0
+Export-Package: org.eclipse.ecf.tests.discovery.remote_extender;version="1.0.0"
+Bundle-ActivationPolicy: lazy
diff --git a/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/OSGI-INF/l10n/bundle.properties b/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/OSGI-INF/l10n/bundle.properties
new file mode 100644
index 000000000..a218455e3
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/OSGI-INF/l10n/bundle.properties
@@ -0,0 +1,3 @@
+#Properties file for org.eclipse.ecf.tests.discovery.remote-extender
+Bundle-Vendor.0 = Eclipse.org
+Bundle-Name.0 = ECF Discovery Provider Remote Extender \ No newline at end of file
diff --git a/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/about.html b/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/about.html
new file mode 100644
index 000000000..4c79781a5
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 25, 2008</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html> \ No newline at end of file
diff --git a/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/build.properties b/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/build.properties
new file mode 100644
index 000000000..050eb13cb
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/build.properties
@@ -0,0 +1,6 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ OSGI-INF/l10n/bundle.properties,\
+ about.html
diff --git a/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/src/org/eclipse/ecf/tests/discovery/remote_extender/Activator.java b/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/src/org/eclipse/ecf/tests/discovery/remote_extender/Activator.java
new file mode 100644
index 000000000..33bc8727a
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.discovery.remote-extender/src/org/eclipse/ecf/tests/discovery/remote_extender/Activator.java
@@ -0,0 +1,97 @@
+package org.eclipse.ecf.tests.discovery.remote_extender;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.eclipse.ecf.discovery.IDiscoveryAdvertiser;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.hooks.service.EventHook;
+
+public class Activator implements BundleActivator, EventHook {
+
+ private static final String SERVICE = IDiscoveryAdvertiser.class.getName();
+
+ private Filter filter;
+ private Map overwrites;
+ private BundleContext context;
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext aContext) throws Exception {
+ context = aContext;
+ overwrites = new HashMap();
+ filter = context.createFilter("(&" +
+ "(" + Constants.OBJECTCLASS + "=" + SERVICE + ")" +
+ "(!(osgi.remote.interfaces=" + SERVICE + "))" +
+ ")");
+ context.registerService(EventHook.class.getName(), this, null);
+
+ ServiceReference[] serviceReferences = context.getAllServiceReferences(SERVICE, null);
+ if(serviceReferences != null) {
+ for (int i = 0; i < serviceReferences.length; i++) {
+ ServiceReference serviceReference = serviceReferences[i];
+ overwriteServiceRegistration(serviceReference);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ this.context = null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.framework.hooks.service.EventHook#event(org.osgi.framework.ServiceEvent, java.util.Collection)
+ */
+ public void event(ServiceEvent event, Collection contexts) {
+ ServiceReference serviceReference = event.getServiceReference();
+ // either this bundle is not active or it is not responsible
+ if(context != null || !filter.match(serviceReference)) {
+ return;
+ }
+
+ switch (event.getType()) {
+ case ServiceEvent.MODIFIED:
+ throw new UnsupportedOperationException("not yet implemented");
+ case ServiceEvent.MODIFIED_ENDMATCH:
+ throw new UnsupportedOperationException("not yet implemented");
+ case ServiceEvent.REGISTERED:
+ contexts.clear();
+ overwriteServiceRegistration(serviceReference);
+ break;
+ case ServiceEvent.UNREGISTERING:
+ ServiceRegistration serviceRegistration = (ServiceRegistration) overwrites.get(serviceReference);
+ serviceRegistration.unregister();
+ break;
+ }
+ }
+
+ private void overwriteServiceRegistration(ServiceReference aServiceReference) {
+ Properties props = new Properties();
+ String[] keys = aServiceReference.getPropertyKeys();
+ for (int i = 0; i < keys.length; i++) {
+ String key = keys[i];
+ if(!Constants.SERVICE_ID.equals(key) || Constants.SERVICE_RANKING.equals(key)) {
+ props.put(key, aServiceReference.getProperty(key));
+ }
+ }
+ props.put("osgi.remote.interfaces", SERVICE);
+ Object service = this.context.getService(aServiceReference);
+ // keep in mind that this removes all other interfaces the service was originally registered for
+ ServiceRegistration serviceRegistration = context.registerService(SERVICE, service, props);
+ overwrites.put(aServiceReference, serviceRegistration);
+ }
+}

Back to the top