Author: angelo.vandersijpt at luminis.eu
Date: Wed Dec 22 21:37:48 2010
New Revision: 536

Log:
AMDATU-200 Introduced a ServiceDependentActivator to help with our JAX-RS 
issues.

Added:
   
trunk/amdatu-libraries/utilities/src/main/java/org/amdatu/libraries/utilities/osgi/
   
trunk/amdatu-libraries/utilities/src/main/java/org/amdatu/libraries/utilities/osgi/ServiceDependentActivator.java
   
trunk/amdatu-web/rest-jaxrs/src/main/java/org/amdatu/web/rest/jaxrs/JaxRsSpi.java
Removed:
   
trunk/amdatu-web/rest-jaxrs/src/main/java/org/amdatu/web/rest/jaxrs/osgi/Activator.java
Modified:
   
trunk/amdatu-authentication/oauth-server/src/main/java/org/amdatu/authentication/oauth/server/osgi/Activator.java
   trunk/amdatu-authentication/tokenprovider/pom.xml
   
trunk/amdatu-authentication/tokenprovider/src/main/java/org/amdatu/authentication/tokenprovider/osgi/Activator.java
   trunk/amdatu-authorization/login-service/pom.xml
   
trunk/amdatu-authorization/login-service/src/main/java/org/amdatu/authorization/login/service/osgi/Activator.java
   
trunk/amdatu-authorization/useradmin-rest/src/main/java/org/amdatu/authorization/useradmin/rest/osgi/Activator.java
   trunk/amdatu-example/course-service/pom.xml
   
trunk/amdatu-example/course-service/src/main/java/org/amdatu/example/course/service/osgi/Activator.java
   trunk/amdatu-example/oauth/pom.xml
   
trunk/amdatu-example/oauth/src/main/java/org/amdatu/example/oauth/osgi/Activator.java
   
trunk/amdatu-opensocial/gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/osgi/Activator.java
   trunk/amdatu-semanticweb/sparqlendpoint/pom.xml
   
trunk/amdatu-semanticweb/sparqlendpoint/src/main/java/org/amdatu/semanticweb/sparqlendpoint/Activator.java
   trunk/amdatu-web/rest-jaxrs/pom.xml
   
trunk/amdatu-web/rest-wink/src/main/java/org/amdatu/web/rest/wink/service/WinkRegistrationServiceImpl.java

Modified: 
trunk/amdatu-authentication/oauth-server/src/main/java/org/amdatu/authentication/oauth/server/osgi/Activator.java
==============================================================================
--- 
trunk/amdatu-authentication/oauth-server/src/main/java/org/amdatu/authentication/oauth/server/osgi/Activator.java
   (original)
+++ 
trunk/amdatu-authentication/oauth-server/src/main/java/org/amdatu/authentication/oauth/server/osgi/Activator.java
   Wed Dec 22 21:37:48 2010
@@ -36,10 +36,11 @@
 import org.amdatu.authentication.oauth.server.service.OAuthServiceProviderImpl;
 import org.amdatu.authentication.oauth.server.service.OAuthTokenProviderImpl;
 import org.amdatu.authentication.tokenprovider.TokenProvider;
+import org.amdatu.libraries.utilities.osgi.ServiceDependentActivator;
 import org.amdatu.web.httpcontext.HttpContextServiceFactory;
 import org.amdatu.web.httpcontext.ResourceProvider;
+import org.amdatu.web.rest.jaxrs.JaxRsSpi;
 import org.apache.felix.dm.Component;
-import org.apache.felix.dm.DependencyActivatorBase;
 import org.apache.felix.dm.DependencyManager;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.cm.ManagedService;
@@ -49,10 +50,15 @@
  * This is the activator for the authorization bundle
  * @author ivol
  */
-public class Activator extends DependencyActivatorBase {
+public class Activator extends ServiceDependentActivator {
 
     @Override
-    public void init(BundleContext context, DependencyManager manager) throws 
Exception {
+    protected Class<?>[] getRequiredServices() {
+        return new Class<?>[] { JaxRsSpi.class };
+    }
+
+    @Override
+    public void initWithDependencies(BundleContext context, DependencyManager 
manager) throws Exception {
         // Create and register the OAuth token provider service component.
         manager.add(
             createComponent()
@@ -108,6 +114,7 @@
     }
 
     @Override
-    public void destroy(BundleContext context, DependencyManager manager) 
throws Exception {
+    public void destroy(BundleContext bundleContext, DependencyManager 
dependencyManager) throws Exception {
     }
+    
 }

Modified: trunk/amdatu-authentication/tokenprovider/pom.xml
==============================================================================
--- trunk/amdatu-authentication/tokenprovider/pom.xml   (original)
+++ trunk/amdatu-authentication/tokenprovider/pom.xml   Wed Dec 22 21:37:48 2010
@@ -27,6 +27,12 @@
       <scope>provided</scope>
       <type>bundle</type>
     </dependency>    
+    <dependency>
+      <groupId>org.amdatu.libraries</groupId>
+      <artifactId>utilities</artifactId>
+      <version>${platform.version}</version>
+      <scope>compile</scope>
+    </dependency>
   </dependencies>
   
   <build>

Modified: 
trunk/amdatu-authentication/tokenprovider/src/main/java/org/amdatu/authentication/tokenprovider/osgi/Activator.java
==============================================================================
--- 
trunk/amdatu-authentication/tokenprovider/src/main/java/org/amdatu/authentication/tokenprovider/osgi/Activator.java
 (original)
+++ 
trunk/amdatu-authentication/tokenprovider/src/main/java/org/amdatu/authentication/tokenprovider/osgi/Activator.java
 Wed Dec 22 21:37:48 2010
@@ -19,7 +19,8 @@
 import org.amdatu.authentication.tokenprovider.TokenProvider;
 import org.amdatu.authentication.tokenprovider.TokenStorageProvider;
 import org.amdatu.authentication.tokenprovider.service.TokenProviderImpl;
-import org.apache.felix.dm.DependencyActivatorBase;
+import org.amdatu.libraries.utilities.osgi.ServiceDependentActivator;
+import org.amdatu.web.rest.jaxrs.JaxRsSpi;
 import org.apache.felix.dm.DependencyManager;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.log.LogService;
@@ -28,10 +29,15 @@
  * This is the activator for the authorization bundle
  * @author ivol
  */
-public class Activator extends DependencyActivatorBase {
+public class Activator extends ServiceDependentActivator {
 
     @Override
-    public void init(BundleContext context, DependencyManager manager) throws 
Exception {
+    protected Class<?>[] getRequiredServices() {
+        return new Class<?>[] { JaxRsSpi.class };
+    }
+
+    @Override
+    public void initWithDependencies(BundleContext context, DependencyManager 
manager) throws Exception {
         // Create and register the Token provider service component.
         manager.add(
             createComponent()
@@ -51,8 +57,8 @@
             
.add(createServiceDependency().setService(TokenProvider.class).setRequired(true)));
    */    
     }
 
-
     @Override
-    public void destroy(BundleContext context, DependencyManager manager) 
throws Exception {
+    public void destroy(BundleContext bundleContext, DependencyManager 
dependencyManager) throws Exception {
     }
+    
 }

Modified: trunk/amdatu-authorization/login-service/pom.xml
==============================================================================
--- trunk/amdatu-authorization/login-service/pom.xml    (original)
+++ trunk/amdatu-authorization/login-service/pom.xml    Wed Dec 22 21:37:48 2010
@@ -39,6 +39,12 @@
       <version>${platform.version}</version>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>org.amdatu.libraries</groupId>
+      <artifactId>utilities</artifactId>
+      <version>${platform.version}</version>
+      <scope>compile</scope>
+    </dependency>
   </dependencies>
 
   <build>

Modified: 
trunk/amdatu-authorization/login-service/src/main/java/org/amdatu/authorization/login/service/osgi/Activator.java
==============================================================================
--- 
trunk/amdatu-authorization/login-service/src/main/java/org/amdatu/authorization/login/service/osgi/Activator.java
   (original)
+++ 
trunk/amdatu-authorization/login-service/src/main/java/org/amdatu/authorization/login/service/osgi/Activator.java
   Wed Dec 22 21:37:48 2010
@@ -19,8 +19,9 @@
 import org.amdatu.authentication.tokenprovider.TokenProvider;
 import org.amdatu.authorization.login.service.LoginService;
 import org.amdatu.authorization.login.service.service.LoginServiceImpl;
+import org.amdatu.libraries.utilities.osgi.ServiceDependentActivator;
 import org.amdatu.web.httpcontext.HttpContextServiceFactory;
-import org.apache.felix.dm.DependencyActivatorBase;
+import org.amdatu.web.rest.jaxrs.JaxRsSpi;
 import org.apache.felix.dm.DependencyManager;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.log.LogService;
@@ -30,13 +31,18 @@
  * This is the activator for the authorization bundle
  * @author ivol
  */
-public class Activator extends DependencyActivatorBase {
+public class Activator extends ServiceDependentActivator {
     // The resource identifier for this bundle. Resources are only considered 
to be 'ours' when
     // it is prefixed with this id
     public final static String RESOURCE_ID = "authorization";
 
     @Override
-    public void init(BundleContext context, DependencyManager manager) throws 
Exception {
+    protected Class<?>[] getRequiredServices() {
+        return new Class<?>[] { JaxRsSpi.class };
+    }
+
+    @Override
+    public void initWithDependencies(BundleContext context, DependencyManager 
manager) throws Exception {
         // Create and register the authorization service.
         manager.add(
                 createComponent()
@@ -51,6 +57,7 @@
     }
 
     @Override
-    public void destroy(BundleContext context, DependencyManager manager) 
throws Exception {
+    public void destroy(BundleContext bundleContext, DependencyManager 
dependencyManager) throws Exception {
     }
+    
 }

Modified: 
trunk/amdatu-authorization/useradmin-rest/src/main/java/org/amdatu/authorization/useradmin/rest/osgi/Activator.java
==============================================================================
--- 
trunk/amdatu-authorization/useradmin-rest/src/main/java/org/amdatu/authorization/useradmin/rest/osgi/Activator.java
 (original)
+++ 
trunk/amdatu-authorization/useradmin-rest/src/main/java/org/amdatu/authorization/useradmin/rest/osgi/Activator.java
 Wed Dec 22 21:37:48 2010
@@ -18,8 +18,9 @@
 
 import org.amdatu.authorization.useradmin.rest.service.GroupsResource;
 import org.amdatu.authorization.useradmin.rest.service.UsersResource;
+import org.amdatu.libraries.utilities.osgi.ServiceDependentActivator;
+import org.amdatu.web.rest.jaxrs.JaxRsSpi;
 import org.amdatu.web.rest.jaxrs.RESTService;
-import org.apache.felix.dm.DependencyActivatorBase;
 import org.apache.felix.dm.DependencyManager;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.log.LogService;
@@ -30,9 +31,14 @@
  * 
  * @author ivol
  */
-public class Activator extends DependencyActivatorBase {
+public class Activator extends ServiceDependentActivator {
 
-    public void init(BundleContext context, DependencyManager manager) throws 
Exception {
+    @Override
+    protected Class<?>[] getRequiredServices() {
+        return new Class<?>[] { JaxRsSpi.class };
+    }
+
+    public void initWithDependencies(BundleContext context, DependencyManager 
manager) throws Exception {
         // Create the users resource service and register it as REST service
         manager.add(createComponent()
             .setInterface(RESTService.class.getName(), null)
@@ -48,6 +54,8 @@
             
.add(createServiceDependency().setService(UserAdmin.class).setRequired(true)));
     }
 
-    public void destroy(BundleContext context, DependencyManager manager) 
throws Exception {
+    @Override
+    public void destroy(BundleContext bundleContext, DependencyManager 
dependencyManager) throws Exception {
     }
+
 }

Modified: trunk/amdatu-example/course-service/pom.xml
==============================================================================
--- trunk/amdatu-example/course-service/pom.xml (original)
+++ trunk/amdatu-example/course-service/pom.xml Wed Dec 22 21:37:48 2010
@@ -83,6 +83,12 @@
       <scope>provided</scope>
       <type>bundle</type>
     </dependency>   
+    <dependency>
+      <groupId>org.amdatu.libraries</groupId>
+      <artifactId>utilities</artifactId>
+      <version>${platform.version}</version>
+      <scope>compile</scope>
+    </dependency>
   </dependencies>
   
   <build>

Modified: 
trunk/amdatu-example/course-service/src/main/java/org/amdatu/example/course/service/osgi/Activator.java
==============================================================================
--- 
trunk/amdatu-example/course-service/src/main/java/org/amdatu/example/course/service/osgi/Activator.java
     (original)
+++ 
trunk/amdatu-example/course-service/src/main/java/org/amdatu/example/course/service/osgi/Activator.java
     Wed Dec 22 21:37:48 2010
@@ -22,11 +22,12 @@
 import org.amdatu.example.course.service.service.CourseServiceImpl;
 import org.amdatu.example.course.service.service.ProfileDataProvider;
 import org.amdatu.core.config.templates.ConfigTemplateManager;
+import org.amdatu.libraries.utilities.osgi.ServiceDependentActivator;
 import org.amdatu.web.httpcontext.HttpContextServiceFactory;
 import org.amdatu.web.httpcontext.ResourceProvider;
 import org.amdatu.opensocial.profile.PersonService;
 import org.amdatu.semanticweb.sesame.SesameService;
-import org.apache.felix.dm.DependencyActivatorBase;
+import org.amdatu.web.rest.jaxrs.JaxRsSpi;
 import org.apache.felix.dm.DependencyManager;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.cm.ConfigurationAdmin;
@@ -37,13 +38,17 @@
  * This is the activator for the course service bundle
  * @author ivol
  */
-public class Activator extends DependencyActivatorBase {
+public class Activator extends ServiceDependentActivator {
     // The resource identifier for this bundle. Resources are only considered 
to be 'ours' when
     // it is prefixed with this id
     public final static String RESOURCE_ID = "examples/course";
- 
+
+    @Override
+    protected Class<?>[] getRequiredServices() {
+        return new Class<?>[] { JaxRsSpi.class };
+    }
     @Override
-    public void init(BundleContext context, DependencyManager manager) throws 
Exception {  
+    public void initWithDependencies(BundleContext context, DependencyManager 
manager) throws Exception {
         // Create and register the course service
         manager.add(
                 createComponent()
@@ -86,6 +91,7 @@
     }
 
     @Override
-    public void destroy(BundleContext context, DependencyManager manager) 
throws Exception {
+    public void destroy(BundleContext bundleContext, DependencyManager 
dependencyManager) throws Exception {
     }
+    
 }

Modified: trunk/amdatu-example/oauth/pom.xml
==============================================================================
--- trunk/amdatu-example/oauth/pom.xml  (original)
+++ trunk/amdatu-example/oauth/pom.xml  Wed Dec 22 21:37:48 2010
@@ -53,6 +53,12 @@
       <version>20090211</version>
       <scope>compile</scope>
     </dependency>
+    <dependency>
+      <groupId>org.amdatu.libraries</groupId>
+      <artifactId>utilities</artifactId>
+      <version>${platform.version}</version>
+      <scope>compile</scope>
+    </dependency>
   </dependencies> 
   
   <build>

Modified: 
trunk/amdatu-example/oauth/src/main/java/org/amdatu/example/oauth/osgi/Activator.java
==============================================================================
--- 
trunk/amdatu-example/oauth/src/main/java/org/amdatu/example/oauth/osgi/Activator.java
       (original)
+++ 
trunk/amdatu-example/oauth/src/main/java/org/amdatu/example/oauth/osgi/Activator.java
       Wed Dec 22 21:37:48 2010
@@ -21,10 +21,11 @@
 import org.amdatu.example.oauth.service.DummyInterface;
 import org.amdatu.example.oauth.service.OAuthGadgetsRegistrationServiceImpl;
 import org.amdatu.example.oauth.service.OAuthProtectedResource;
+import org.amdatu.libraries.utilities.osgi.ServiceDependentActivator;
 import org.amdatu.opensocial.gadgetmanagement.GadgetManagement;
 import org.amdatu.web.httpcontext.HttpContextServiceFactory;
 import org.amdatu.web.httpcontext.ResourceProvider;
-import org.apache.felix.dm.DependencyActivatorBase;
+import org.amdatu.web.rest.jaxrs.JaxRsSpi;
 import org.apache.felix.dm.DependencyManager;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.http.HttpService;
@@ -34,13 +35,18 @@
  * This is the OSGi activator for this bundle.
  * @author ivol
  */
-public class Activator extends DependencyActivatorBase {
+public class Activator extends ServiceDependentActivator {
     // The resource identifier for this bundle. Resources are only considered 
to be 'ours' when
     // it is prefixed with this id.
     public final static String RESOURCE_ID = "examples/oauth";
 
     @Override
-    public void init(BundleContext context, DependencyManager manager) throws 
Exception {
+    protected Class<?>[] getRequiredServices() {
+        return new Class<?>[] { JaxRsSpi.class };
+    }
+
+    @Override
+    public void initWithDependencies(BundleContext context, DependencyManager 
manager) throws Exception {
         // Create the FriendsGadgetService which has dependencies with the Log 
service
         // and HTTP service
         manager.add(createComponent()
@@ -62,6 +68,7 @@
     }
 
     @Override
-    public void destroy(BundleContext arg0, DependencyManager arg1) throws 
Exception {
+    public void destroy(BundleContext bundleContext, DependencyManager 
dependencyManager) throws Exception {
     }
+    
 }
\ No newline at end of file

Added: 
trunk/amdatu-libraries/utilities/src/main/java/org/amdatu/libraries/utilities/osgi/ServiceDependentActivator.java
==============================================================================
--- (empty file)
+++ 
trunk/amdatu-libraries/utilities/src/main/java/org/amdatu/libraries/utilities/osgi/ServiceDependentActivator.java
   Wed Dec 22 21:37:48 2010
@@ -0,0 +1,43 @@
+package org.amdatu.libraries.utilities.osgi;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyActivatorBase;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Helper class to create an activator that needs other services to be 'up' 
before the rest
+ * of the activator is executed.
+ * The most prominent use case for this activator is the use of 'marker' 
interface that state
+ * the availability of some non-OSGi service.
+ */
+public abstract class ServiceDependentActivator extends 
DependencyActivatorBase {
+    @Override
+    public final void init(BundleContext context, DependencyManager manager) 
throws Exception {
+        Object watcher = new SpiWatcher();
+
+        Component spiWatcherComponent = 
createComponent().setImplementation(watcher);
+        for (Class<?> spiService : getRequiredServices()) {
+            
spiWatcherComponent.add(createServiceDependency().setService(spiService).setRequired(true));
+        }
+
+        manager.add(spiWatcherComponent);
+    }
+
+    /**
+     * Gets an array of all services that should be 'up' before the rest of 
activator is started.
+     * Once the rest of the activator is started, you will not have access to 
these services by default.
+     */
+    protected abstract Class<?>[] getRequiredServices();
+
+    public abstract void initWithDependencies(BundleContext context, 
DependencyManager manager) throws Exception;
+
+    private class SpiWatcher {
+        private volatile DependencyManager m_dependencyManager;
+        private volatile BundleContext m_bundleContext;
+
+        public void start() throws Exception {
+            initWithDependencies(m_bundleContext, m_dependencyManager);
+        }
+    }
+}

Modified: 
trunk/amdatu-opensocial/gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/osgi/Activator.java
==============================================================================
--- 
trunk/amdatu-opensocial/gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/osgi/Activator.java
   (original)
+++ 
trunk/amdatu-opensocial/gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/osgi/Activator.java
   Wed Dec 22 21:37:48 2010
@@ -19,12 +19,13 @@
 import org.amdatu.authentication.tokenprovider.TokenProvider;
 import org.amdatu.cassandra.listener.ColumnFamilyAvailable;
 import org.amdatu.cassandra.persistencemanager.CassandraPersistenceManager;
+import org.amdatu.libraries.utilities.osgi.ServiceDependentActivator;
 import org.amdatu.opensocial.gadgetmanagement.GadgetManagement;
 import 
org.amdatu.opensocial.gadgetmanagement.service.GadgetManagementServiceImpl;
 import org.amdatu.opensocial.shindig.GadgetStore;
 import org.amdatu.web.httpcontext.HttpContextServiceFactory;
 import org.amdatu.web.httpcontext.ResourceProvider;
-import org.apache.felix.dm.DependencyActivatorBase;
+import org.amdatu.web.rest.jaxrs.JaxRsSpi;
 import org.apache.felix.dm.DependencyManager;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.log.LogService;
@@ -34,13 +35,18 @@
  * This is the activator for the gadget management bundle
  * @author ivol
  */
-public class Activator extends DependencyActivatorBase {
+public class Activator extends ServiceDependentActivator {
     // The resource identifier for this bundle. Resources are only considered 
to be 'ours' when
     // it is prefixed with this id
     public final static String RESOURCE_ID = "gadgetstore";
-    
+
+    @Override
+    protected Class<?>[] getRequiredServices() {
+        return new Class<?>[] { JaxRsSpi.class };
+    }
+
     @Override
-    public void init(BundleContext context, DependencyManager manager) throws 
Exception {
+    public void initWithDependencies(BundleContext context, DependencyManager 
manager) throws Exception {
         // Create and register the gadget management service.
         String gadgetFilter = "(" + ColumnFamilyAvailable.FILTER_NAME + "=" + 
GadgetStore.CF_GADGET + ")";
         String keyspaceFilter =
@@ -61,6 +67,6 @@
     }
 
     @Override
-    public void destroy(BundleContext context, DependencyManager manager) 
throws Exception {
+    public void destroy(BundleContext bundleContext, DependencyManager 
dependencyManager) throws Exception {
     }
 }

Modified: trunk/amdatu-semanticweb/sparqlendpoint/pom.xml
==============================================================================
--- trunk/amdatu-semanticweb/sparqlendpoint/pom.xml     (original)
+++ trunk/amdatu-semanticweb/sparqlendpoint/pom.xml     Wed Dec 22 21:37:48 2010
@@ -51,6 +51,12 @@
       <scope>provided</scope>   
       <type>bundle</type>
     </dependency>
+    <dependency>
+      <groupId>org.amdatu.libraries</groupId>
+      <artifactId>utilities</artifactId>
+      <version>${platform.version}</version>
+      <scope>compile</scope>
+    </dependency>
   </dependencies> 
     
   <build>

Modified: 
trunk/amdatu-semanticweb/sparqlendpoint/src/main/java/org/amdatu/semanticweb/sparqlendpoint/Activator.java
==============================================================================
--- 
trunk/amdatu-semanticweb/sparqlendpoint/src/main/java/org/amdatu/semanticweb/sparqlendpoint/Activator.java
  (original)
+++ 
trunk/amdatu-semanticweb/sparqlendpoint/src/main/java/org/amdatu/semanticweb/sparqlendpoint/Activator.java
  Wed Dec 22 21:37:48 2010
@@ -16,12 +16,13 @@
  */
 package org.amdatu.semanticweb.sparqlendpoint;
 
+import org.amdatu.libraries.utilities.osgi.ServiceDependentActivator;
 import org.amdatu.opensocial.gadgetmanagement.GadgetManagement;
 import org.amdatu.semanticweb.sesame.SesameService;
 import org.amdatu.semanticweb.sparqlendpoint.service.SPARQLEndpointServiceImpl;
 import org.amdatu.web.httpcontext.HttpContextServiceFactory;
 import org.amdatu.web.httpcontext.ResourceProvider;
-import org.apache.felix.dm.DependencyActivatorBase;
+import org.amdatu.web.rest.jaxrs.JaxRsSpi;
 import org.apache.felix.dm.DependencyManager;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.log.LogService;
@@ -30,13 +31,18 @@
  * This is the OSGi activator for this gadget bundle.
  * @author ivol
  */
-public class Activator extends DependencyActivatorBase {
+public class Activator extends ServiceDependentActivator {
     // The resource identifier for this bundle. Resources are only considered 
to be 'ours' when
     // it is prefixed with this id
     public final static String RESOURCE_ID = "gadget/sparqlendpoint";
 
     @Override
-    public void init(BundleContext context, DependencyManager manager) throws 
Exception {
+    protected Class<?>[] getRequiredServices() {
+        return new Class<?>[] { JaxRsSpi.class };
+    }
+
+    @Override
+    public void initWithDependencies(BundleContext context, DependencyManager 
manager) throws Exception {
         // Create the SPARQLEndpointServiceImpl which has dependencies with 
the Log service
         // and HTTP service
         
manager.add(createComponent().setInterface(ResourceProvider.class.getName(), 
null).setImplementation(
@@ -49,6 +55,7 @@
     }
 
     @Override
-    public void destroy(BundleContext arg0, DependencyManager arg1) throws 
Exception {
+    public void destroy(BundleContext bundleContext, DependencyManager 
dependencyManager) throws Exception {
     }
+    
 }

Modified: trunk/amdatu-web/rest-jaxrs/pom.xml
==============================================================================
--- trunk/amdatu-web/rest-jaxrs/pom.xml (original)
+++ trunk/amdatu-web/rest-jaxrs/pom.xml Wed Dec 22 21:37:48 2010
@@ -35,7 +35,6 @@
         <artifactId>maven-bundle-plugin</artifactId>
         <configuration>
           <instructions>
-            
<Bundle-Activator>org.amdatu.web.rest.jaxrs.osgi.Activator</Bundle-Activator>
             
<Bundle-SymbolicName>org.amdatu.web.rest.jaxrs</Bundle-SymbolicName>
             <Embed-Dependency>*;scope=compile</Embed-Dependency>
             <Embed-Transitive>true</Embed-Transitive>

Added: 
trunk/amdatu-web/rest-jaxrs/src/main/java/org/amdatu/web/rest/jaxrs/JaxRsSpi.java
==============================================================================
--- (empty file)
+++ 
trunk/amdatu-web/rest-jaxrs/src/main/java/org/amdatu/web/rest/jaxrs/JaxRsSpi.java
   Wed Dec 22 21:37:48 2010
@@ -0,0 +1,7 @@
+package org.amdatu.web.rest.jaxrs;
+
+/**
+ * Marker interface used to signal the 'readyness' of our JAS RS spi.
+ */
+public interface JaxRsSpi {
+}

Modified: 
trunk/amdatu-web/rest-wink/src/main/java/org/amdatu/web/rest/wink/service/WinkRegistrationServiceImpl.java
==============================================================================
--- 
trunk/amdatu-web/rest-wink/src/main/java/org/amdatu/web/rest/wink/service/WinkRegistrationServiceImpl.java
  (original)
+++ 
trunk/amdatu-web/rest-wink/src/main/java/org/amdatu/web/rest/wink/service/WinkRegistrationServiceImpl.java
  Wed Dec 22 21:37:48 2010
@@ -34,7 +34,9 @@
 
 import org.amdatu.web.httpcontext.HttpContextServiceFactory;
 import org.amdatu.web.httpcontext.ResourceProvider;
+import org.amdatu.web.rest.jaxrs.JaxRsSpi;
 import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
 import org.apache.wink.common.internal.runtime.RuntimeDelegateImpl;
 import org.apache.wink.server.utils.RegistrationUtils;
 import org.osgi.framework.BundleContext;
@@ -56,6 +58,7 @@
     // Services injected by the Felix dependency manager
     private volatile HttpService m_httpService;
     private volatile LogService m_logService;
+    private volatile DependencyManager m_dependencyManager;
     private volatile BundleContext m_bundleContext;
     private volatile HttpContextServiceFactory m_httpContextServiceFactory;
 
@@ -65,6 +68,7 @@
     // Our HTTP context
     private Component m_httpContextComponent;
     private HttpContext m_httpContext;
+    private Component m_spiComponent;
 
     /**
      * The init() method is invoked by the Felix dependency manager.
@@ -76,6 +80,7 @@
 
         // Set the runtime delegate
         setRuntimeDelegate();
+        registerSpiService();
 
         m_logService.log(LogService.LOG_INFO, getClass().getName() + " service 
initialized");
     }
@@ -84,6 +89,7 @@
      * The destroy() method is invoked by the Felix dependency manager.
      */
     public void destroy() {
+        removeSpiService();
         // When the Wink application is destroyed, unregister Wink servlets
         while (m_registeredServlets.size() > 0) {
             String servletUrl = m_registeredServlets.get(0);
@@ -137,6 +143,18 @@
         RuntimeDelegate.setInstance(new RuntimeDelegateImpl());
     }
 
+    private void registerSpiService() {
+        m_spiComponent = m_dependencyManager.createComponent()
+                .setInterface(JaxRsSpi.class.getName(), null)
+                .setImplementation(new JaxRsSpi(){});
+
+        m_dependencyManager.add(m_spiComponent);
+    }
+
+    private void removeSpiService() {
+        m_dependencyManager.remove(m_spiComponent);
+    }
+
     public void onAdded(ServiceReference ref, Object service) {
         // Check if this is a JAX-RS annotated class
         if (service.getClass().getAnnotation(Path.class) != null) {

Reply via email to