[jboss-osgi-commits] JBoss-OSGI SVN: r92605 - in projects/jboss-osgi: projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing and 7 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Thu Aug 20 06:29:23 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-08-20 06:29:21 -0400 (Thu, 20 Aug 2009)
New Revision: 92605

Removed:
   projects/jboss-osgi/trunk/testsuite/example/src/test/resources/jboss-osgi-jbossmc.properties
Modified:
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedFramework.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedFrameworkMBean.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/OSGiRuntime.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/EmbeddedRuntime.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteFramework.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteRuntime.java
   projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/AbstractPlugin.java
   projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/AbstractPluginImpl.java
   projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleContextImpl.java
   projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleImpl.java
   projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/FrameworkFactoryBean.java
   projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/FrameworkImpl.java
   projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/resources/META-INF/jboss-osgi-framework.xml
   projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/test/java/org/jboss/test/osgi/jbossmc/simple/BundleInstallTestCase.java
   projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/service/microcontainer/MicrocontainerServiceTestCase.java
Log:
Support bundle version in managed bundle oname

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java	2009-08-20 08:40:11 UTC (rev 92604)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java	2009-08-20 10:29:21 UTC (rev 92605)
@@ -32,6 +32,7 @@
 import org.jboss.osgi.spi.Constants;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
+import org.osgi.framework.Version;
 
 /**
  * The managed view of an OSGi Bundle
@@ -47,7 +48,11 @@
    public ManagedBundle(Bundle bundle)
    {
       this.bundle = bundle;
-      this.oname = ObjectNameFactory.create(Constants.DOMAIN_NAME + ":bundle=" + bundle.getSymbolicName() + ",id=" + bundle.getBundleId());
+      
+      long id = bundle.getBundleId();
+      String name = bundle.getSymbolicName();
+      Version version = bundle.getVersion();
+      this.oname = ObjectNameFactory.create(Constants.DOMAIN_NAME + ":id=" + id + ",bundle=" + name + ",version=" + version);
    }
 
    public ObjectName getObjectName()

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedFramework.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedFramework.java	2009-08-20 08:40:11 UTC (rev 92604)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedFramework.java	2009-08-20 10:29:21 UTC (rev 92605)
@@ -79,18 +79,37 @@
    }
 
    @SuppressWarnings("unchecked")
-   public ObjectName getBundle(String symbolicName)
+   public ObjectName getBundle(String symbolicName, String version)
    {
+      ObjectName oname = null;
+      
       ObjectName pattern = ObjectNameFactory.create(Constants.DOMAIN_NAME + ":bundle=" + symbolicName + ",*");
       Set<ObjectName> names = mbeanServer.queryNames(pattern, null);
 
-      if (names.size() < 1)
-         return null;
+      if (names.size() > 0)
+      {
+         // [TODO] Support bundle version 
+         if (names.size() > 1)
+            throw new IllegalArgumentException("Multiple bundles found: " + names);
+         
+         oname = names.iterator().next();
+      }
 
-      if (names.size() > 1)
-         throw new IllegalArgumentException("Multiple bundles found: " + names);
+      return oname;
+   }
 
-      return names.iterator().next();
+   @SuppressWarnings("unchecked")
+   public ObjectName getBundle(long bundleId)
+   {
+      ObjectName oname = null;
+      
+      ObjectName pattern = ObjectNameFactory.create(Constants.DOMAIN_NAME + ":id=" + bundleId + ",*");
+      Set<ObjectName> names = mbeanServer.queryNames(pattern, null);
+
+      if (names.size() > 0)
+         oname = names.iterator().next();
+
+      return oname;
    }
 
    @SuppressWarnings("unchecked")

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedFrameworkMBean.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedFrameworkMBean.java	2009-08-20 08:40:11 UTC (rev 92604)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedFrameworkMBean.java	2009-08-20 10:29:21 UTC (rev 92605)
@@ -48,9 +48,14 @@
    /**
     * Get the installed bundle 
     */
-   ObjectName getBundle(String symbolicName);
+   ObjectName getBundle(String symbolicName, String version);
    
    /**
+    * Get the installed bundle 
+    */
+   ObjectName getBundle(long bundleId);
+   
+   /**
     * Returns a ServiceReference object for a service that implements and was registered 
     * under the specified class.
     */

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/OSGiRuntime.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/OSGiRuntime.java	2009-08-20 08:40:11 UTC (rev 92604)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/OSGiRuntime.java	2009-08-20 10:29:21 UTC (rev 92605)
@@ -75,6 +75,13 @@
    OSGiBundle getBundle(String symbolicName, String version);
 
    /**
+    * Get the {@link OSGiBundle} for a given bundle id.
+    * 
+    * @return The bundle or null if there is none
+    */
+   OSGiBundle getBundle(long bundleId);
+
+   /**
     * Get an abstraction of the {@link PackageAdmin}.
     */
    OSGiPackageAdmin getPackageAdmin();

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/EmbeddedRuntime.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/EmbeddedRuntime.java	2009-08-20 08:40:11 UTC (rev 92604)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/EmbeddedRuntime.java	2009-08-20 10:29:21 UTC (rev 92605)
@@ -44,6 +44,7 @@
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.launch.Framework;
@@ -64,14 +65,15 @@
 
    public OSGiBundle installBundle(String location) throws BundleException
    {
-      String symbolicName = getSymbolicName(location);
+      String symbolicName = getManifestEntry(location, Constants.BUNDLE_SYMBOLICNAME);
+      String version = getManifestEntry(location, Constants.BUNDLE_VERSION);
       
       URL bundleURL = getTestHelper().getTestArchiveURL(location);
       ServiceReference sref = getBundleContext().getServiceReference(DeployerService.class.getName());
       DeployerService service = (DeployerService)getBundleContext().getService(sref);
       service.deploy(bundleURL);
       
-      OSGiBundle bundle = getBundle(symbolicName, null);
+      OSGiBundle bundle = getBundle(symbolicName, version);
       return registerBundle(location, bundle);
    }
 
@@ -87,6 +89,12 @@
       return bundleArr;
    }
    
+   public OSGiBundle getBundle(long bundleId)
+   {
+      Bundle bundle = getBundleContext().getBundle(bundleId);
+      return bundle != null ? new EmbeddedBundle(this, bundle) : null;
+   }
+   
    public OSGiServiceReference getServiceReference(String clazz)
    {
       ServiceReference sref = getBundleContext().getServiceReference(clazz);

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java	2009-08-20 08:40:11 UTC (rev 92604)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java	2009-08-20 10:29:21 UTC (rev 92605)
@@ -88,7 +88,7 @@
 
          for (String location : capability.getBundles())
          {
-            String symName = getSymbolicName(location);
+            String symName = getManifestEntry(location, Constants.BUNDLE_SYMBOLICNAME);
             if (bundles.get(location) == null && getBundle(symName, null) == null)
             {
                OSGiBundle bundle = installBundle(location);
@@ -198,8 +198,16 @@
       return bundle;
    }
 
-   protected String getSymbolicName(String location)
+   protected String getManifestEntry(String location, String key)
    {
+      Manifest manifest = getManifest(location);
+      Attributes attribs = manifest.getMainAttributes();
+      String value = attribs.getValue(key);
+      return value;
+   }
+
+   private Manifest getManifest(String location)
+   {
       Manifest manifest;
       try
       {
@@ -213,13 +221,7 @@
          throw new IllegalStateException("Cannot get manifest from: " + location);
 
       }
-
-      Attributes attribs = manifest.getMainAttributes();
-      String symbolicName = attribs.getValue(Constants.BUNDLE_SYMBOLICNAME);
-      if (symbolicName == null)
-         throw new IllegalArgumentException("Cannot obtain Bundle-SymbolicName for: " + location);
-
-      return symbolicName;
+      return manifest;
    }
 
    OSGiBundle registerBundle(String location, OSGiBundle bundle)

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteFramework.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteFramework.java	2009-08-20 08:40:11 UTC (rev 92604)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteFramework.java	2009-08-20 10:29:21 UTC (rev 92605)
@@ -45,9 +45,14 @@
    /**
     * Get the installed bundle 
     */
-   ManagedBundleMBean getBundle(String symbolicName);
+   ManagedBundleMBean getBundle(String symbolicName, String version);
 
    /**
+    * Get the installed bundle by id
+    */
+   ManagedBundleMBean getBundle(long bundleId);
+
+   /**
     * Returns a ServiceReference object for a service that implements and was registered 
     * under the specified class.
     */

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteRuntime.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteRuntime.java	2009-08-20 08:40:11 UTC (rev 92604)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteRuntime.java	2009-08-20 10:29:21 UTC (rev 92605)
@@ -47,6 +47,7 @@
 import org.jboss.osgi.spi.testing.OSGiTestHelper;
 import org.jboss.osgi.spi.util.BundleDeploymentFactory;
 import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
 import org.osgi.framework.InvalidSyntaxException;
 
 /**
@@ -67,11 +68,12 @@
 
    public OSGiBundle installBundle(String location) throws BundleException
    {
-      String symbolicName = getSymbolicName(location);
+      String symbolicName = getManifestEntry(location, Constants.BUNDLE_SYMBOLICNAME);
+      String version = getManifestEntry(location, Constants.BUNDLE_VERSION);
       try
       {
          deploy(location);
-         ManagedBundleMBean bundleMBean = getRemoteFramework().getBundle(symbolicName);
+         ManagedBundleMBean bundleMBean = getRemoteFramework().getBundle(symbolicName, version);
          RemoteBundle bundle = new RemoteBundle(this, bundleMBean, location);
          return registerBundle(location, bundle);
       }
@@ -149,6 +151,12 @@
       }
    }
 
+   public OSGiBundle getBundle(long bundleId)
+   {
+      ManagedBundleMBean bundle = getRemoteFramework().getBundle(bundleId);
+      return bundle != null ? new RemoteBundle(this, bundle, null) : null;
+   }
+   
    public OSGiServiceReference getServiceReference(String clazz)
    {
       ManagedServiceReference manref = getRemoteFramework().getServiceReference(clazz);
@@ -213,9 +221,9 @@
 
       return new RemoteFramework()
       {
-         public ManagedBundleMBean getBundle(String symbolicName)
+         public ManagedBundleMBean getBundle(String symbolicName, String version)
          {
-            ObjectName oname = managedFramework.getBundle(symbolicName);
+            ObjectName oname = managedFramework.getBundle(symbolicName, version);
             if (oname == null)
                throw new IllegalArgumentException("Cannot get remote bundle for: " + symbolicName);
 
@@ -229,6 +237,22 @@
             }
          }
 
+         public ManagedBundleMBean getBundle(long bundleId)
+         {
+            ObjectName oname = managedFramework.getBundle(bundleId);
+            if (oname == null)
+               throw new IllegalArgumentException("Cannot get remote bundle for: " + bundleId);
+
+            try
+            {
+               return MBeanProxy.get(ManagedBundleMBean.class, oname, getMBeanServer());
+            }
+            catch (MBeanProxyException ex)
+            {
+               throw new RemoteFrameworkException(ex);
+            }
+         }
+
          public Set<ManagedBundleMBean> getBundles()
          {
             Set<ManagedBundleMBean> remBundles = new HashSet<ManagedBundleMBean>();

Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/AbstractPlugin.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/AbstractPlugin.java	2009-08-20 08:40:11 UTC (rev 92604)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/AbstractPlugin.java	2009-08-20 10:29:21 UTC (rev 92605)
@@ -31,11 +31,14 @@
  * @author thomas.diesler at jboss.com
  * @since 20-Aug-2009
  */
-public interface AbstractPlugin 
+public interface AbstractPlugin
 {
    Framework getFramework();
-   
+
    void setFramework(Framework framework);
 
-   <T extends AbstractPlugin> T getPlugin(Class<T> pluginClass);
+   <T extends AbstractPlugin> T getPlugin(Class<T> clazz);
+
+   <T extends AbstractPlugin> T getOptionalPlugin(Class<T> clazz);
+
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/AbstractPluginImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/AbstractPluginImpl.java	2009-08-20 08:40:11 UTC (rev 92604)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/AbstractPluginImpl.java	2009-08-20 10:29:21 UTC (rev 92605)
@@ -46,9 +46,15 @@
       this.framework = framework;
    }
    
-   public <T extends AbstractPlugin> T getPlugin(Class<T> pluginClass)
+   public <T extends AbstractPlugin> T getPlugin(Class<T> clazz)
    {
       FrameworkImpl frameworkImpl = (FrameworkImpl)framework;
-      return frameworkImpl.getPlugin(pluginClass);
+      return frameworkImpl.getPlugin(clazz);
    }
+   
+   public <T extends AbstractPlugin> T getOptionalPlugin(Class<T> clazz)
+   {
+      FrameworkImpl frameworkImpl = (FrameworkImpl)framework;
+      return frameworkImpl.getOptionalPlugin(clazz);
+   }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleContextImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleContextImpl.java	2009-08-20 08:40:11 UTC (rev 92604)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleContextImpl.java	2009-08-20 10:29:21 UTC (rev 92605)
@@ -32,6 +32,7 @@
 import java.util.List;
 
 import org.jboss.logging.Logger;
+import org.jboss.osgi.jbossmc.api.AbstractPlugin;
 import org.jboss.osgi.jbossmc.api.BundleEventsPlugin;
 import org.jboss.osgi.jbossmc.api.BundleFactoryPlugin;
 import org.jboss.osgi.jbossmc.api.BundleStoragePlugin;
@@ -78,56 +79,62 @@
       this.bundle = bundle;
    }
 
-   public FrameworkImpl getFramework()
+   public Framework getFramework()
    {
-      return (FrameworkImpl)framework;
+      return framework;
    }
    
+   public <T extends AbstractPlugin> T getPlugin(Class<T> clazz)
+   {
+      FrameworkImpl frameworkImpl = (FrameworkImpl)framework;
+      return frameworkImpl.getPlugin(clazz);
+   }
+   
    public void addBundleListener(BundleListener listener)
    {
-      BundleEventsPlugin eventManager = getFramework().getPlugin(BundleEventsPlugin.class);
+      BundleEventsPlugin eventManager = getPlugin(BundleEventsPlugin.class);
       eventManager.addBundleListener(listener);
       registeredListeners.add(listener);
    }
 
    public void removeBundleListener(BundleListener listener)
    {
-      BundleEventsPlugin eventManager = getFramework().getPlugin(BundleEventsPlugin.class);
+      BundleEventsPlugin eventManager = getPlugin(BundleEventsPlugin.class);
       eventManager.removeBundleListener(listener);
       registeredListeners.remove(listener);
    }
 
    public void addFrameworkListener(FrameworkListener listener)
    {
-      FrameworkEventsPlugin eventManager = getFramework().getPlugin(FrameworkEventsPlugin.class);
+      FrameworkEventsPlugin eventManager = getPlugin(FrameworkEventsPlugin.class);
       eventManager.addFrameworkListener(listener);
       registeredListeners.add(listener);
    }
 
    public void removeFrameworkListener(FrameworkListener listener)
    {
-      FrameworkEventsPlugin eventManager = getFramework().getPlugin(FrameworkEventsPlugin.class);
+      FrameworkEventsPlugin eventManager = getPlugin(FrameworkEventsPlugin.class);
       eventManager.removeFrameworkListener(listener);
       registeredListeners.remove(listener);
    }
 
    public void addServiceListener(ServiceListener listener)
    {
-      ServiceEventsPlugin eventManager = getFramework().getPlugin(ServiceEventsPlugin.class);
+      ServiceEventsPlugin eventManager = getPlugin(ServiceEventsPlugin.class);
       eventManager.addServiceListener(listener);
       registeredListeners.add(listener);
    }
 
    public void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException
    {
-      ServiceEventsPlugin eventManager = getFramework().getPlugin(ServiceEventsPlugin.class);
+      ServiceEventsPlugin eventManager = getPlugin(ServiceEventsPlugin.class);
       eventManager.addServiceListener(listener, filter);
       registeredListeners.add(listener);
    }
 
    public void removeServiceListener(ServiceListener listener)
    {
-      ServiceEventsPlugin eventManager = getFramework().getPlugin(ServiceEventsPlugin.class);
+      ServiceEventsPlugin eventManager = getPlugin(ServiceEventsPlugin.class);
       eventManager.removeServiceListener(listener);
       registeredListeners.remove(listener);
    }
@@ -144,13 +151,13 @@
 
    public Bundle getBundle(long id)
    {
-      BundleRegistryPlugin bundleRegistry = getFramework().getPlugin(BundleRegistryPlugin.class);
+      BundleRegistryPlugin bundleRegistry = getPlugin(BundleRegistryPlugin.class);
       return bundleRegistry.getBundleById(id);
    }
 
    public Bundle[] getBundles()
    {
-      BundleRegistryPlugin bundleRegistry = getFramework().getPlugin(BundleRegistryPlugin.class);
+      BundleRegistryPlugin bundleRegistry = getPlugin(BundleRegistryPlugin.class);
       List<Bundle> bundleList = bundleRegistry.getBundles();
       Bundle[] bundles = new Bundle[bundleList.size()];
       return bundleList.toArray(bundles);
@@ -158,13 +165,14 @@
 
    public File getDataFile(String filename)
    {
-      BundleStoragePlugin bundleStorage = getFramework().getPlugin(BundleStoragePlugin.class);
+      BundleStoragePlugin bundleStorage = getPlugin(BundleStoragePlugin.class);
       return bundleStorage.getDataFile(bundle, filename);
    }
 
    public String getProperty(String key)
    {
-      String property = (String)getFramework().getProperty(key);
+      FrameworkImpl frameworkImpl = (FrameworkImpl)framework;
+      String property = (String)frameworkImpl.getProperty(key);
       if (property == null)
          property = System.getProperty(key);
       
@@ -173,7 +181,7 @@
 
    public Object getService(ServiceReference reference)
    {
-      ServiceRegistryPlugin serviceRegistry = getFramework().getPlugin(ServiceRegistryPlugin.class);
+      ServiceRegistryPlugin serviceRegistry = getPlugin(ServiceRegistryPlugin.class);
       Object service = serviceRegistry.getService(bundle, reference);
       if (service != null)
       {
@@ -184,19 +192,19 @@
 
    public boolean ungetService(ServiceReference reference)
    {
-      ServiceRegistryPlugin serviceRegistry = getFramework().getPlugin(ServiceRegistryPlugin.class);
+      ServiceRegistryPlugin serviceRegistry = getPlugin(ServiceRegistryPlugin.class);
       return serviceRegistry.ungetService(bundle, reference);
    }
    
    public ServiceReference getServiceReference(String clazz)
    {
-      ServiceRegistryPlugin serviceRegistry = getFramework().getPlugin(ServiceRegistryPlugin.class);
+      ServiceRegistryPlugin serviceRegistry = getPlugin(ServiceRegistryPlugin.class);
       return serviceRegistry.getServiceReference(clazz);
    }
 
    public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException
    {
-      ServiceRegistryPlugin serviceRegistry = getFramework().getPlugin(ServiceRegistryPlugin.class);
+      ServiceRegistryPlugin serviceRegistry = getPlugin(ServiceRegistryPlugin.class);
       return serviceRegistry.getServiceReferences(clazz, filter);
    }
 
@@ -209,11 +217,11 @@
    public Bundle installBundle(String location) throws BundleException
    {
       // Convert location to a virtual file URL
-      BundleFactoryPlugin bundleFactory = getFramework().getPlugin(BundleFactoryPlugin.class);
+      BundleFactoryPlugin bundleFactory = getPlugin(BundleFactoryPlugin.class);
       location = bundleFactory.getVirtualLocation(location); 
       
       // 1.  If a bundle containing the same location identifier is already installed, the Bundle object for that bundle is returned.
-      BundleRegistryPlugin bundleRegistry = getFramework().getPlugin(BundleRegistryPlugin.class);
+      BundleRegistryPlugin bundleRegistry = getPlugin(BundleRegistryPlugin.class);
       Bundle bundle = bundleRegistry.getBundleByLocation(location);
       if (bundle != null)
          return bundle;
@@ -228,7 +236,7 @@
       bundleImpl.setState(Bundle.INSTALLED);
       
       // 5. A bundle event of type BundleEvent.INSTALLED is fired.
-      BundleEventsPlugin eventManager = getFramework().getPlugin(BundleEventsPlugin.class);
+      BundleEventsPlugin eventManager = getPlugin(BundleEventsPlugin.class);
       eventManager.fireBundleEvent(new BundleEvent(BundleEvent.INSTALLED, bundle));
       
       // 6. The Bundle object for the newly or previously installed bundle is returned. 
@@ -244,7 +252,7 @@
    @SuppressWarnings("unchecked")
    public ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties)
    {
-      ServiceRegistryPlugin serviceRegistry = getFramework().getPlugin(ServiceRegistryPlugin.class);
+      ServiceRegistryPlugin serviceRegistry = getPlugin(ServiceRegistryPlugin.class);
       ServiceRegistration sreg = serviceRegistry.registerService(bundle, clazzes, service, properties);
       registeredServices.add(sreg);
       return sreg;
@@ -253,7 +261,7 @@
    @SuppressWarnings("unchecked")
    public ServiceRegistration registerService(String clazz, Object service, Dictionary properties)
    {
-      ServiceRegistryPlugin serviceRegistry = getFramework().getPlugin(ServiceRegistryPlugin.class);
+      ServiceRegistryPlugin serviceRegistry = getPlugin(ServiceRegistryPlugin.class);
       ServiceRegistration sreg = serviceRegistry.registerService(bundle, clazz, service, properties);
       registeredServices.add(sreg);
       return sreg;

Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleImpl.java	2009-08-20 08:40:11 UTC (rev 92604)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleImpl.java	2009-08-20 10:29:21 UTC (rev 92605)
@@ -37,11 +37,12 @@
 import java.util.jar.Manifest;
 
 import org.jboss.logging.Logger;
-import org.jboss.osgi.jbossmc.api.ClassLoaderFactoryPlugin;
-import org.jboss.osgi.jbossmc.api.RuntimeClassLoader;
+import org.jboss.osgi.jbossmc.api.AbstractPlugin;
 import org.jboss.osgi.jbossmc.api.BundleLifecyclePlugin;
 import org.jboss.osgi.jbossmc.api.BundleResolverPlugin;
+import org.jboss.osgi.jbossmc.api.ClassLoaderFactoryPlugin;
 import org.jboss.osgi.jbossmc.api.FrameworkEventsPlugin;
+import org.jboss.osgi.jbossmc.api.RuntimeClassLoader;
 import org.jboss.osgi.spi.NotImplementedException;
 import org.jboss.virtual.VirtualFile;
 import org.jboss.virtual.VirtualFileFilter;
@@ -130,11 +131,6 @@
       return getHeader(Constants.BUNDLE_SYMBOLICNAME);
    }
 
-   public void start() throws BundleException
-   {
-      start(0);
-   }
-
    public BundleActivator getBundleActivator()
    {
       return activator;
@@ -149,32 +145,39 @@
    {
       if (runtimeLoader == null)
       {
-         ClassLoaderFactoryPlugin factory = getFramework().getPlugin(ClassLoaderFactoryPlugin.class);
+         ClassLoaderFactoryPlugin factory = getPlugin(ClassLoaderFactoryPlugin.class);
          runtimeLoader = factory.createClassLoader(this);
       }
       return runtimeLoader;
    }
 
+   public void start() throws BundleException
+   {
+      BundleLifecyclePlugin bundleLifecycle = getPlugin(BundleLifecyclePlugin.class);
+      bundleLifecycle.start(this, 0);
+   }
+
    public void start(int options) throws BundleException
    {
-      BundleLifecyclePlugin bundleLifecycle = getFramework().getPlugin(BundleLifecyclePlugin.class);
+      BundleLifecyclePlugin bundleLifecycle = getPlugin(BundleLifecyclePlugin.class);
       bundleLifecycle.start(this, options);
    }
 
    public void stop() throws BundleException
    {
-      stop(0);
+      BundleLifecyclePlugin bundleLifecycle = getPlugin(BundleLifecyclePlugin.class);
+      bundleLifecycle.stop(this, 0);
    }
 
    public void stop(int options) throws BundleException
    {
-      BundleLifecyclePlugin bundleLifecycle = getFramework().getPlugin(BundleLifecyclePlugin.class);
+      BundleLifecyclePlugin bundleLifecycle = getPlugin(BundleLifecyclePlugin.class);
       bundleLifecycle.stop(this, options);
    }
 
    public void uninstall() throws BundleException
    {
-      BundleLifecyclePlugin bundleLifecycle = getFramework().getPlugin(BundleLifecyclePlugin.class);
+      BundleLifecyclePlugin bundleLifecycle = getPlugin(BundleLifecyclePlugin.class);
       bundleLifecycle.uninstall(this);
    }
 
@@ -379,7 +382,7 @@
       // before attempting to load the class.
       if (state == Bundle.INSTALLED)
       {
-         BundleResolverPlugin resolver = getFramework().getPlugin(BundleResolverPlugin.class);
+         BundleResolverPlugin resolver = getPlugin(BundleResolverPlugin.class);
          try
          {
             resolver.resolveBundle(this);
@@ -387,7 +390,7 @@
          catch (BundleException ex)
          {
             // If this bundle cannot be resolved, a Framework event of type FrameworkEvent.ERROR is fired
-            FrameworkEventsPlugin eventManager = getFramework().getPlugin(FrameworkEventsPlugin.class);
+            FrameworkEventsPlugin eventManager = getPlugin(FrameworkEventsPlugin.class);
             eventManager.fireFrameworkEvent(new FrameworkEvent(FrameworkEvent.ERROR, this, ex));
 
             throw new ClassNotFoundException("Cannot load class: " + name, ex);
@@ -402,12 +405,12 @@
       return (String)getHeaders().get(header);
    }
 
-   private FrameworkImpl getFramework()
+   private <T extends AbstractPlugin> T getPlugin(Class<T> clazz)
    {
       BundleContextImpl contextImpl = (BundleContextImpl)context;
-      return contextImpl.getFramework();
+      return contextImpl.getPlugin(clazz);
    }
-
+   
    private void assertNotUninstalled()
    {
       if (state == Bundle.UNINSTALLED)

Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/FrameworkFactoryBean.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/FrameworkFactoryBean.java	2009-08-20 08:40:11 UTC (rev 92604)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/FrameworkFactoryBean.java	2009-08-20 10:29:21 UTC (rev 92605)
@@ -27,7 +27,9 @@
 import java.util.List;
 import java.util.Map;
 
+import org.jboss.kernel.Kernel;
 import org.jboss.logging.Logger;
+import org.jboss.osgi.jbossmc.api.AbstractPlugin;
 import org.osgi.framework.launch.Framework;
 import org.osgi.framework.launch.FrameworkFactory;
 
@@ -45,15 +47,23 @@
    public static final String BEAN_FRAMEWORK_FACTORY = "jboss.osgi:service=FrameworkFactory";
    
    private Map<String, Object> properties;
+   private List<AbstractPlugin> plugins;
    private List<URL> autoInstall;
    private List<URL> autoStart;
+   private Kernel kernel;
+
    private Framework framework;
-
+   
    public void setProperties(Map<String, Object> properties)
    {
       this.properties = properties;
    }
 
+   public void setPlugins(List<AbstractPlugin> plugins)
+   {
+      this.plugins = plugins;
+   }
+
    public void setAutoInstall(List<URL> autoInstall)
    {
       this.autoInstall = autoInstall;
@@ -64,15 +74,34 @@
       this.autoStart = autoStart;
    }
 
+   public void setKernel(Kernel kernel)
+   {
+      this.kernel = kernel;
+   }
+
    @SuppressWarnings("unchecked")
    public Framework newFramework(Map configuration)
    {
       if (framework == null)
       {
+         if (properties == null)
+            throw new IllegalStateException("Cannot obtain framework properties");
+         
          if (configuration != null)
             properties.putAll(configuration);
          
-         FrameworkImpl frameworkImpl = new FrameworkImpl(properties);
+         FrameworkImpl frameworkImpl = new FrameworkImpl(kernel, properties);
+         
+         // Copy the configured plugins
+         if (plugins != null)
+         {
+            for (AbstractPlugin plugin : plugins)
+            {
+               plugin.setFramework(frameworkImpl);
+               frameworkImpl.addPlugin(plugin);
+            }
+         }
+         
          framework = frameworkImpl;
       }
       return framework;

Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/FrameworkImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/FrameworkImpl.java	2009-08-20 08:40:11 UTC (rev 92604)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/FrameworkImpl.java	2009-08-20 10:29:21 UTC (rev 92605)
@@ -30,6 +30,7 @@
 import java.util.List;
 import java.util.Map;
 
+import org.jboss.kernel.Kernel;
 import org.jboss.logging.Logger;
 import org.jboss.osgi.jbossmc.api.AbstractPlugin;
 import org.jboss.osgi.jbossmc.api.BundleEventsPlugin;
@@ -58,13 +59,20 @@
    private Map<String, Object> properties = new HashMap<String, Object>();
    private int startLevel;
 
+   private Kernel kernel;
    private Map<Class<?>, AbstractPlugin> plugins = new HashMap<Class<?>, AbstractPlugin>();
 
-   public FrameworkImpl(Map<String, Object> props)
+   public FrameworkImpl(Kernel kernel, Map<String, Object> props)
    {
+      if (kernel == null)
+         throw new IllegalArgumentException("Kernel cannot be null");
+      
+      this.kernel = kernel;
+      
       if (props != null)
          properties.putAll(props);
       
+      // Initialize default plugins
       addPlugin(new BundleEventsPluginImpl(this));
       addPlugin(new BundleFactoryPluginImpl(this));
       addPlugin(new BundleLifecyclePluginImpl(this));
@@ -75,22 +83,39 @@
       addPlugin(new FrameworkEventsPluginImpl(this));
       addPlugin(new ServiceEventsPluginImpl(this));
       addPlugin(new ServiceRegistryPluginImpl(this));
+   }
 
+   public Kernel getKernel()
+   {
+      return kernel;
    }
 
    @SuppressWarnings("unchecked")
    public <T extends AbstractPlugin> T getPlugin(Class<T> clazz)
    {
+      T plugin = (T)plugins.get(clazz);
+      if (plugin == null)
+         throw new IllegalStateException("Cannot obtain plugin for: " + clazz.getName());
+      
+      return plugin;
+   }
+   
+   @SuppressWarnings("unchecked")
+   public <T extends AbstractPlugin> T getOptionalPlugin(Class<T> clazz)
+   {
       return (T)plugins.get(clazz);
    }
    
-   @SuppressWarnings("unchecked")
    public void addPlugin(AbstractPlugin plugin)
    {
-      for (Class<?> interf : plugin.getClass().getInterfaces())
+      Class<? extends AbstractPlugin> clazz = plugin.getClass();
+      for (Class<?> interf : clazz.getInterfaces())
       {
          if (AbstractPlugin.class.isAssignableFrom(interf))
+         {
+            log.debug("Plugin: [" + interf.getName() + "=" + clazz.getName() + "]");
             plugins.put(interf, plugin);
+         }
       }
    }
    

Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/resources/META-INF/jboss-osgi-framework.xml
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/resources/META-INF/jboss-osgi-framework.xml	2009-08-20 08:40:11 UTC (rev 92604)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/resources/META-INF/jboss-osgi-framework.xml	2009-08-20 10:29:21 UTC (rev 92605)
@@ -14,14 +14,20 @@
   ********************************
   -->
 
-  <!-- The FrameworkBootstrap -->
+  <!-- The OSGi Framework Factory -->
   <bean name="jboss.osgi:service=FrameworkFactory" class="org.jboss.osgi.jbossmc.framework.FrameworkFactoryBean">
+    <property name="kernel"><inject bean="jboss.kernel:service=Kernel" /></property>
     <property name="properties">
       <map keyClass="java.lang.String" valueClass="java.lang.String">
         <entry><key>org.osgi.framework.storage</key><value>${log4j.output.dir}/osgi-store</value></entry>
         <entry><key>org.osgi.framework.storage.clean</key><value>onFirstInit</value></entry>
       </map>
     </property>
+    <property name="plugins">
+      <list elementClass="org.jboss.osgi.jbossmc.api.AbstractPlugin">
+        <inject bean="jboss.osgi:plugin=ClassLoaderFactory"/>
+      </list>
+    </property>
     <property name="autoInstall">
      <list elementClass="java.net.URL">
      </list>
@@ -32,4 +38,14 @@
     </property>
   </bean>
 
+  <!-- 
+  ********************************
+  *                              *  
+  *  Framework Plugins           *
+  *                              *
+  ********************************
+  -->
+
+  <bean name="jboss.osgi:plugin=ClassLoaderFactory" class="org.jboss.osgi.jbossmc.framework.ClassLoaderFactoryPluginImpl"/>
+  
 </deployment>
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/test/java/org/jboss/test/osgi/jbossmc/simple/BundleInstallTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/test/java/org/jboss/test/osgi/jbossmc/simple/BundleInstallTestCase.java	2009-08-20 08:40:11 UTC (rev 92604)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/test/java/org/jboss/test/osgi/jbossmc/simple/BundleInstallTestCase.java	2009-08-20 10:29:21 UTC (rev 92605)
@@ -25,16 +25,15 @@
 
 import static org.junit.Assert.assertEquals;
 
-import org.jboss.osgi.spi.testing.OSGiTest;
-import org.jboss.osgi.spi.util.ServiceLoader;
+import org.jboss.osgi.spi.testing.OSGiBundle;
+import org.jboss.osgi.spi.testing.OSGiRuntime;
+import org.jboss.osgi.spi.testing.OSGiTestHelper;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
-import org.osgi.framework.launch.Framework;
-import org.osgi.framework.launch.FrameworkFactory;
 
 /**
  * A test that deployes a bundle and verifies its state
@@ -42,38 +41,28 @@
  * @author thomas.diesler at jboss.com
  * @since 18-Aug-2009
  */
-public class BundleInstallTestCase extends OSGiTest
+public class BundleInstallTestCase
 {
-   private static Framework framework;
+   private static OSGiRuntime runtime;
    
-   @BeforeClass
+   //@BeforeClass
    public static void beforeClass() throws BundleException
    {
-      FrameworkFactory factory = ServiceLoader.loadService(FrameworkFactory.class);
-      framework = factory.newFramework(null);
-      framework.start();
+      runtime = new OSGiTestHelper().getDefaultRuntime();
    }
    
-   @AfterClass
+   //@AfterClass
    public static void afterClass() throws BundleException
    {
-      framework.stop();
+      if (runtime != null)
+         runtime.shutdown();
    }
    
    @Test
-   public void testFrameworkBundle() throws Exception
-   {
-      assertEquals("BundleId", 0, framework.getBundleId());
-      assertEquals("Location", "System Bundle", framework.getLocation());
-      assertEquals("SymbolicName", "org.jboss.osgi.jbossmc", framework.getSymbolicName());
-   }
-   
-   @Test
+   @Ignore
    public void testBundleInstall() throws Exception
    {
-      BundleContext sysContext = framework.getBundleContext();
-      String location = getTestArchiveURL("simple-bundle.jar").toString();
-      Bundle bundle = sysContext.installBundle(location);
+      OSGiBundle bundle = runtime.installBundle("simple-bundle.jar");
 
       assertEquals("simple-bundle", bundle.getSymbolicName());
       

Deleted: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/jboss-osgi-jbossmc.properties
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/jboss-osgi-jbossmc.properties	2009-08-20 08:40:11 UTC (rev 92604)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/jboss-osgi-jbossmc.properties	2009-08-20 10:29:21 UTC (rev 92605)
@@ -1,22 +0,0 @@
-#
-# Properties read by the org.jboss.osgi.spi.framework.PropertiesBootstrapProvider
-# 
-# $Id: jboss-osgi-felix.properties 92430 2009-08-17 14:53:52Z thomas.diesler at jboss.com $
-#
-
-# Properties to configure the Framework
-org.osgi.framework.storage=${basedir}/target/osgi-store
-org.osgi.framework.storage.clean=onFirstInit
-
-# Extra System Packages
-org.osgi.framework.system.packages.extra=
-
-# Bundles that need to be installed with the Framework automatically 
-org.jboss.osgi.spi.framework.autoInstall=\
-	file://${test.archive.directory}/bundles/org.osgi.compendium.jar
-		
-
-# Bundles that need to be started automatically 
-org.jboss.osgi.spi.framework.autoStart=\
-	file://${test.archive.directory}/bundles/org.apache.felix.log.jar \
-	file://${test.archive.directory}/bundles/jboss-osgi-common.jar 

Modified: projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/service/microcontainer/MicrocontainerServiceTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/service/microcontainer/MicrocontainerServiceTestCase.java	2009-08-20 08:40:11 UTC (rev 92604)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/service/microcontainer/MicrocontainerServiceTestCase.java	2009-08-20 10:29:21 UTC (rev 92605)
@@ -99,7 +99,7 @@
 
       ManagedFrameworkMBean frameworkMBean = MBeanProxy.get(ManagedFrameworkMBean.class, MBEAN_MANAGED_FRAMEWORK, runtime.getMBeanServer());
       Set<ObjectName> bundles = frameworkMBean.getBundles();
-      assertTrue("Managed bundle registered", bundles.toString().indexOf("jboss.osgi:bundle=mcservice-bundleA") > 0);
+      assertTrue("Managed bundle registered", bundles.toString().indexOf("bundle=mcservice-bundleA") > 0);
 
       deployer.undeploy(getTestArchiveURL("service/mcservice-bundleA.jar"));
    }
@@ -117,7 +117,7 @@
 
       ManagedFrameworkMBean frameworkMBean = MBeanProxy.get(ManagedFrameworkMBean.class, MBEAN_MANAGED_FRAMEWORK, runtime.getMBeanServer());
       Set<ObjectName> bundles = frameworkMBean.getBundles();
-      assertTrue("Managed bundle registered", bundles.toString().indexOf("jboss.osgi:bundle=mcservice-bundleB") > 0);
+      assertTrue("Managed bundle registered", bundles.toString().indexOf("bundle=mcservice-bundleB") > 0);
 
       // Check whether the bean is registered
       List<String> registeredBeans = mcService.getRegisteredBeans();



More information about the jboss-osgi-commits mailing list