[jboss-cvs] JBossAS SVN: r93031 - in projects/jboss-osgi/trunk: testsuite/example and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Aug 31 10:27:49 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-08-31 10:27:48 -0400 (Mon, 31 Aug 2009)
New Revision: 93031

Modified:
   projects/jboss-osgi/trunk/reactor/blueprint/impl/src/main/java/org/jboss/osgi/blueprint/container/BlueprintContainerImpl.java
   projects/jboss-osgi/trunk/reactor/blueprint/impl/src/main/java/org/jboss/osgi/blueprint/container/ServiceManager.java
   projects/jboss-osgi/trunk/testsuite/example/pom.xml
   projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
Log:
Use BP bundle to register the services 

Modified: projects/jboss-osgi/trunk/reactor/blueprint/impl/src/main/java/org/jboss/osgi/blueprint/container/BlueprintContainerImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/blueprint/impl/src/main/java/org/jboss/osgi/blueprint/container/BlueprintContainerImpl.java	2009-08-31 14:25:43 UTC (rev 93030)
+++ projects/jboss-osgi/trunk/reactor/blueprint/impl/src/main/java/org/jboss/osgi/blueprint/container/BlueprintContainerImpl.java	2009-08-31 14:27:48 UTC (rev 93031)
@@ -122,7 +122,10 @@
 
    public BundleContext getBundleContext()
    {
-      return bundle.getBundleContext();
+      BundleContext bundleContext = bundle.getBundleContext();
+      if (bundleContext == null)
+         throw new IllegalStateException("BundleContext not available");
+      return bundleContext;
    }
 
    public Set<String> getComponentIds()

Modified: projects/jboss-osgi/trunk/reactor/blueprint/impl/src/main/java/org/jboss/osgi/blueprint/container/ServiceManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/blueprint/impl/src/main/java/org/jboss/osgi/blueprint/container/ServiceManager.java	2009-08-31 14:25:43 UTC (rev 93030)
+++ projects/jboss-osgi/trunk/reactor/blueprint/impl/src/main/java/org/jboss/osgi/blueprint/container/ServiceManager.java	2009-08-31 14:27:48 UTC (rev 93031)
@@ -29,6 +29,7 @@
 
 import org.jboss.osgi.blueprint.BlueprintContext;
 import org.jboss.osgi.blueprint.reflect.ServiceMetadataImpl;
+import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.blueprint.container.BlueprintContainer;
 import org.osgi.service.blueprint.reflect.BeanMetadata;
@@ -37,21 +38,19 @@
 import org.osgi.service.blueprint.reflect.Target;
 
 /**
- * Service managers maintain the registration of an OSGi service
- * object. Service managers provide a proxied ServiceRegistration object. 
+ * Service managers maintain the registration of an OSGi service object. Service managers provide a proxied ServiceRegistration object.
  * 
- * A service manager is enabled if all the mandatory service references in its
- * dependencies are satisfied.
- *  
+ * A service manager is enabled if all the mandatory service references in its dependencies are satisfied.
+ * 
  * @author thomas.diesler at jboss.com
  * @since 17-Jun-2009
  */
 public class ServiceManager extends AbstractManager
 {
    private ServiceMetadataImpl serviceMetadata;
-   
+
    private BeanManager anonymousBean;
-   private List<ServiceRegistration> serviceRegs = new ArrayList<ServiceRegistration>(); 
+   private List<ServiceRegistration> serviceRegs = new ArrayList<ServiceRegistration>();
 
    public ServiceManager(BlueprintContext context, BlueprintContainer container, ServiceMetadata compMetadata)
    {
@@ -63,7 +62,7 @@
       if (target instanceof BeanMetadata)
       {
          ManagerFactory factory = new ManagerFactory(context, container);
-         anonymousBean = (BeanManager)factory.createManager((BeanMetadata)target);         
+         anonymousBean = (BeanManager)factory.createManager((BeanMetadata)target);
       }
    }
 
@@ -71,7 +70,7 @@
    public void install()
    {
       super.install();
-      
+
       if (anonymousBean != null)
          anonymousBean.install();
    }
@@ -80,7 +79,7 @@
    public void activate()
    {
       super.activate();
-      
+
       // Get the BeanManager that backs this service
       BeanManager beanManager = anonymousBean;
       if (beanManager == null)
@@ -89,15 +88,16 @@
          BlueprintContainerImpl impl = (BlueprintContainerImpl)container;
          beanManager = (BeanManager)impl.getComponentManager(target.getComponentId());
       }
-      
+
       // Activate the BeanManager that backs this service
       beanManager.activate();
-      
+
       // Register the the target bean as a services
       Object targetBean = beanManager.getTargetBean();
+      BundleContext bundleContext = ((BlueprintContainerImpl)container).getBundleContext();
       for (String interf : serviceMetadata.getInterfaces())
       {
-         ServiceRegistration sreg = context.getBundleContext().registerService(interf, targetBean, null);
+         ServiceRegistration sreg = bundleContext.registerService(interf, targetBean, null);
          serviceRegs.add(sreg);
       }
    }
@@ -108,12 +108,22 @@
       // Unregister the services
       List<ServiceRegistration> list = new ArrayList<ServiceRegistration>(serviceRegs);
       Collections.reverse(list);
+
       for (ServiceRegistration sreg : list)
-         sreg.unregister();
-      
+      {
+         try
+         {
+            sreg.unregister();
+         }
+         catch (IllegalStateException ex)
+         {
+            // This ServiceRegistration object has already been unregistered
+         }
+      }
+
       if (anonymousBean != null)
          anonymousBean.shutdown();
-      
+
       super.shutdown();
    }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/testsuite/example/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/pom.xml	2009-08-31 14:25:43 UTC (rev 93030)
+++ projects/jboss-osgi/trunk/testsuite/example/pom.xml	2009-08-31 14:27:48 UTC (rev 93031)
@@ -223,8 +223,6 @@
             <configuration>
               <excludes>
                 <exclude>${target.container.excludes}</exclude>
-                <exclude>org/jboss/test/osgi/example/blueprint/**</exclude>
-                <exclude>org/jboss/test/osgi/example/microcontainer/**</exclude>
               </excludes>
             </configuration>
           </plugin>

Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml	2009-08-31 14:25:43 UTC (rev 93030)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml	2009-08-31 14:27:48 UTC (rev 93031)
@@ -21,7 +21,15 @@
           <!-- [JBOSGI-145]  JAXB classes are loaded from the system classpath -->
           com.sun.xml.internal.bind.v2,
           
+          org.jboss.beans.metadata.plugins;version=2.0,
+          org.jboss.beans.metadata.plugins.builder;version=2.0,
+          org.jboss.beans.metadata.spi;version=2.0,
+          org.jboss.beans.metadata.spi.builder;version=2.0,
+          org.jboss.dependency.spi;version=2.0,
+          org.jboss.kernel.spi.dependency;version=2.0,
           org.jboss.logging;version=2.0,
+          
+          org.jboss.osgi.spi;version=1.0,
           org.jboss.osgi.spi.capability;version=1.0,
           org.jboss.osgi.spi.framework;version=1.0,
           org.jboss.osgi.spi.logging;version=1.0,




More information about the jboss-cvs-commits mailing list