summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Liebig2008-02-12 09:29:21 (EST)
committerStefan Liebig2008-02-12 09:29:21 (EST)
commita98cb03924a0f2c6e7fb911f5326b38f5309ce16 (patch)
treeadc865faddb5e5191e79b076617d1fedd9aa8f69
parent9a10d73654e0a7000f199729ef1f59f1b1f83fcc (diff)
downloadorg.eclipse.riena-a98cb03924a0f2c6e7fb911f5326b38f5309ce16.zip
org.eclipse.riena-a98cb03924a0f2c6e7fb911f5326b38f5309ce16.tar.gz
org.eclipse.riena-a98cb03924a0f2c6e7fb911f5326b38f5309ce16.tar.bz2
uses new service injector
-rw-r--r--org.eclipse.riena.communication.publisher/src/org/eclipse/riena/internal/communication/publisher/Activator.java191
-rw-r--r--org.eclipse.riena.communication.publisher/src/org/eclipse/riena/internal/communication/publisher/ServiceHooksProxy.java10
2 files changed, 98 insertions, 103 deletions
diff --git a/org.eclipse.riena.communication.publisher/src/org/eclipse/riena/internal/communication/publisher/Activator.java b/org.eclipse.riena.communication.publisher/src/org/eclipse/riena/internal/communication/publisher/Activator.java
index 162326e..06e43b8 100644
--- a/org.eclipse.riena.communication.publisher/src/org/eclipse/riena/internal/communication/publisher/Activator.java
+++ b/org.eclipse.riena.communication.publisher/src/org/eclipse/riena/internal/communication/publisher/Activator.java
@@ -21,109 +21,106 @@ import org.eclipse.riena.communication.core.publisher.IServicePublishEventDispat
import org.eclipse.riena.communication.core.publisher.IServicePublisher;
import org.eclipse.riena.communication.core.publisher.RSDPublisherProperties;
import org.eclipse.riena.communication.core.util.CommunicationUtil;
-import org.eclipse.riena.core.service.ServiceInjector;
+import org.eclipse.riena.core.service.Injector;
+import org.eclipse.riena.core.service.ServiceId;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
-
public class Activator implements BundleActivator {
- private ServicePublishEventDispatcher dispachter;
- private ServiceInjector publisherInjector;
- private UpdateNotifierRemoteService updateNotifierRemoteService;
- private static BundleContext context;
-
- /*
- * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
- */
- public void start(BundleContext context) throws Exception {
- Activator.context = context;
-
- dispachter = new ServicePublishEventDispatcher(context);
- publisherInjector = new ServiceInjector(context, IServicePublisher.ID, dispachter, "addServicePublisher", "removeServicePublisher");
- publisherInjector.start();
-
- // register as OSGi service, the start will pick up the OSGi service and
- // publish it
- Dictionary<String, Object> properties = new Hashtable<String, Object>(3);
- properties.put(RSDPublisherProperties.PROP_IS_REMOTE, "true");
- properties.put(RSDPublisherProperties.PROP_REMOTE_PROTOCOL, "hessian");
- properties.put(RSDPublisherProperties.PROP_REMOTE_PATH, "/ServicePublisherWS");
-
- context.registerService(IServicePublishEventDispatcher.ID, dispachter, properties);
-
- dispachter.start();
-
- // register UpdateNotified so all services trigger the
- // servicePublishEventDispatcher
- updateNotifierRemoteService = new UpdateNotifierRemoteService(dispachter);
- context.addServiceListener(updateNotifierRemoteService);
- context.registerService(IServiceHook.ID, new IServiceHook() {
-
- public void afterService(ServiceContext context) {
- System.out.println("after service (in hook)");
- context.getMessageContext().addResponseHeader("Set-Cookie", "x-scpserver-test-sessionid=11");
- }
-
- public void beforeService(ServiceContext context) {
- System.out.println("before service (in hook)");
- Map<String, List<String>> headers = context.getMessageContext().listRequestHeaders();
- for (String hName : headers.keySet()) {
- StringBuffer sb = new StringBuffer();
- for (String hValue : headers.get(hName)) {
- sb.append(hValue + ", ");
- }
- System.out.println("header: name:" + hName + " value:" + sb);
- }
- }
- }, null);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
- */
- public void stop(BundleContext context) throws Exception {
- context.removeServiceListener(updateNotifierRemoteService);
- dispachter.stop();
- dispachter = null;
- publisherInjector.dispose();
- publisherInjector = null;
- updateNotifierRemoteService = null;
- Activator.context = null;
- }
-
- public static BundleContext getContext() {
- return context;
- }
-
- class UpdateNotifierRemoteService implements ServiceListener {
- ServicePublishEventDispatcher dispatcher;
-
- UpdateNotifierRemoteService(ServicePublishEventDispatcher dispatcher) {
- this.dispatcher = dispatcher;
- }
-
- public void serviceChanged(ServiceEvent event) {
- ServiceReference serviceRef = event.getServiceReference();
-
- // check if we are getting the event for a new remote service
- String isRemote = CommunicationUtil.accessProperty(serviceRef.getProperty(RSDPublisherProperties.PROP_IS_REMOTE), null);
- String remoteType = CommunicationUtil.accessProperty(serviceRef.getProperty(RSDPublisherProperties.PROP_REMOTE_PROTOCOL), null);
- if (remoteType == null || remoteType.length() == 0) {
- return;
- }
- if ("true".equals(isRemote)) {
- if (event.getType() == ServiceEvent.UNREGISTERING) {
- dispatcher.unpublish(event.getServiceReference());
- } else if (event.getType() == ServiceEvent.REGISTERED) {
- dispatcher.publish(event.getServiceReference());
- }
- }
- }
- }
+ private ServicePublishEventDispatcher dispatcher;
+ private Injector publisherInjector;
+ private UpdateNotifierRemoteService updateNotifierRemoteService;
+ private static BundleContext context;
+
+ /*
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ Activator.context = context;
+
+ dispatcher = new ServicePublishEventDispatcher(context);
+ publisherInjector = new ServiceId(IServicePublisher.ID).injectInto(dispatcher).start(context);
+
+ // register as OSGi service, the start will pick up the OSGi service and
+ // publish it
+ Dictionary<String, Object> properties = new Hashtable<String, Object>(3);
+ properties.put(RSDPublisherProperties.PROP_IS_REMOTE, "true");
+ properties.put(RSDPublisherProperties.PROP_REMOTE_PROTOCOL, "hessian");
+ properties.put(RSDPublisherProperties.PROP_REMOTE_PATH, "/ServicePublisherWS");
+
+ context.registerService(IServicePublishEventDispatcher.ID, dispatcher, properties);
+
+ dispatcher.start();
+
+ // register UpdateNotified so all services trigger the
+ // servicePublishEventDispatcher
+ updateNotifierRemoteService = new UpdateNotifierRemoteService(dispatcher);
+ context.addServiceListener(updateNotifierRemoteService);
+ context.registerService(IServiceHook.ID, new IServiceHook() {
+
+ public void afterService(ServiceContext context) {
+ System.out.println("after service (in hook)");
+ context.getMessageContext().addResponseHeader("Set-Cookie", "x-scpserver-test-sessionid=11");
+ }
+
+ public void beforeService(ServiceContext context) {
+ System.out.println("before service (in hook)");
+ Map<String, List<String>> headers = context.getMessageContext().listRequestHeaders();
+ for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
+ System.out.println("header: name:" + entry.getKey() + " value: " + entry.getValue());
+ }
+ }
+ }, null);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ context.removeServiceListener(updateNotifierRemoteService);
+ dispatcher.stop();
+ dispatcher = null;
+ publisherInjector.stop();
+ publisherInjector = null;
+ updateNotifierRemoteService = null;
+ Activator.context = null;
+ }
+
+ public static BundleContext getContext() {
+ return context;
+ }
+
+ class UpdateNotifierRemoteService implements ServiceListener {
+ ServicePublishEventDispatcher dispatcher;
+
+ UpdateNotifierRemoteService(ServicePublishEventDispatcher dispatcher) {
+ this.dispatcher = dispatcher;
+ }
+
+ public void serviceChanged(ServiceEvent event) {
+ ServiceReference serviceRef = event.getServiceReference();
+
+ // check if we are getting the event for a new remote service
+ String isRemote = CommunicationUtil.accessProperty(serviceRef
+ .getProperty(RSDPublisherProperties.PROP_IS_REMOTE), null);
+ String remoteType = CommunicationUtil.accessProperty(serviceRef
+ .getProperty(RSDPublisherProperties.PROP_REMOTE_PROTOCOL), null);
+ if (remoteType == null || remoteType.length() == 0) {
+ return;
+ }
+ if ("true".equals(isRemote)) {
+ if (event.getType() == ServiceEvent.UNREGISTERING) {
+ dispatcher.unpublish(event.getServiceReference());
+ } else if (event.getType() == ServiceEvent.REGISTERED) {
+ dispatcher.publish(event.getServiceReference());
+ }
+ }
+ }
+ }
}
diff --git a/org.eclipse.riena.communication.publisher/src/org/eclipse/riena/internal/communication/publisher/ServiceHooksProxy.java b/org.eclipse.riena.communication.publisher/src/org/eclipse/riena/internal/communication/publisher/ServiceHooksProxy.java
index 50ed4a5..c33b387 100644
--- a/org.eclipse.riena.communication.publisher/src/org/eclipse/riena/internal/communication/publisher/ServiceHooksProxy.java
+++ b/org.eclipse.riena.communication.publisher/src/org/eclipse/riena/internal/communication/publisher/ServiceHooksProxy.java
@@ -23,20 +23,18 @@ import org.eclipse.riena.communication.core.hooks.IServiceHook;
import org.eclipse.riena.communication.core.hooks.IServiceMessageContext;
import org.eclipse.riena.communication.core.hooks.IServiceMessageContextAccessor;
import org.eclipse.riena.communication.core.hooks.ServiceContext;
-import org.eclipse.riena.core.service.ServiceInjector;
+import org.eclipse.riena.core.service.ServiceId;
public class ServiceHooksProxy extends AbstractHooksProxy implements InvocationHandler {
private HashSet<IServiceHook> serviceHooks = new HashSet<IServiceHook>();
- private ServiceInjector si;
private RemoteServiceDescription rsd;
private IServiceMessageContextAccessor mca;
private Subject subject;
public ServiceHooksProxy(Object serviceInstance) {
super(serviceInstance);
- si = new ServiceInjector(Activator.getContext(), IServiceHook.ID, this, "addServiceHook", "removeServiceHook");
- si.start();
+ new ServiceId(IServiceHook.ID).injectInto(this).start(Activator.getContext());
}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
@@ -75,11 +73,11 @@ public class ServiceHooksProxy extends AbstractHooksProxy implements InvocationH
}
}
- public void addServiceHook(IServiceHook serviceHook) {
+ public void bind(IServiceHook serviceHook) {
serviceHooks.add(serviceHook);
}
- public void removeServiceHook(IServiceHook serviceHook) {
+ public void unbind(IServiceHook serviceHook) {
serviceHooks.remove(serviceHook);
}