[jboss-cvs] JBossAS SVN: r92661 - in projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src: main/java/org/jboss/osgi/plugins/facade/bundle and 6 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Aug 21 07:58:48 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-08-21 07:58:47 -0400 (Fri, 21 Aug 2009)
New Revision: 92661

Added:
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/launch/
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFramework.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/resources/META-INF/
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/resources/META-INF/services/
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/resources/META-INF/services/org.osgi.framework.launch.FrameworkFactory
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/launch/
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/launch/FrameworkLaunchTestCase.java
Modified:
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
Log:
[JBOSGI-128] Add Framework launch API

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java	2009-08-21 11:58:24 UTC (rev 92660)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java	2009-08-21 11:58:47 UTC (rev 92661)
@@ -108,6 +108,8 @@
 
    /** The system bundle */
    private OSGiSystemBundle systemBundle;
+
+   public static final String BEAN_BUNDLE_MANAGER = "OSGiBundleManager";
    
    static
    {

Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFramework.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFramework.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFramework.java	2009-08-21 11:58:47 UTC (rev 92661)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.plugins.facade.launch;
+
+// $Id$
+
+import org.jboss.logging.Logger;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleWrapper;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.launch.Framework;
+
+/**
+ * An impementation of an OSGi Framework
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 21-Aug-2009
+ */
+public class OSGiFramework extends OSGiBundleWrapper implements Framework
+{
+   // Provide logging
+   final Logger log = Logger.getLogger(OSGiFramework.class);
+   
+   private OSGiBundleManager bundleManager;
+   
+   public OSGiFramework(OSGiBundleManager bundleManager, OSGiBundleState bundleState)
+   {
+      super(bundleState);
+      this.bundleManager = bundleManager;
+   }
+
+   public void init() throws BundleException
+   {
+      // TODO Auto-generated method stub
+      
+   }
+
+   public FrameworkEvent waitForStop(long timeout) throws InterruptedException
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFramework.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java	2009-08-21 11:58:47 UTC (rev 92661)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.plugins.facade.launch;
+
+// $Id$
+
+import java.net.URL;
+import java.util.Map;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerMode;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.bootstrap.AbstractBootstrap;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer;
+import org.jboss.logging.Logger;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
+import org.osgi.framework.launch.Framework;
+import org.osgi.framework.launch.FrameworkFactory;
+
+/**
+ * An impementation of an OSGi FrameworkFactory
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 21-Aug-2009
+ */
+public class OSGiFrameworkFactory implements FrameworkFactory
+{
+   // Provide logging
+   final Logger log = Logger.getLogger(OSGiFrameworkFactory.class);
+
+   @SuppressWarnings("unchecked")
+   public Framework newFramework(Map configuration)
+   {
+      // Bootstrap the kernel
+      AbstractBootstrap bootstrap = new BasicBootstrap();
+      bootstrap.run();
+      
+      Kernel kernel = bootstrap.getKernel();
+      
+      BasicXMLDeployer deployer = new BasicXMLDeployer(kernel, ControllerMode.AUTOMATIC);
+      
+      String common = "/bootstrap/bootstrap.xml";
+      URL url = getClass().getResource(common);
+      if (url == null)
+         throw new IllegalStateException(common + " not found");
+      
+      try
+      {
+         deployer.deploy(url);
+      }
+      catch (Throwable ex)
+      {
+         throw new IllegalStateException("Cannot deploy bootstrap beans", ex);
+      }
+
+      ControllerContext managerContext = kernel.getController().getInstalledContext(OSGiBundleManager.BEAN_BUNDLE_MANAGER);
+      if (managerContext == null)
+         throw new IllegalStateException("Cannot obtain installed bean: " + OSGiBundleManager.BEAN_BUNDLE_MANAGER);
+      
+      OSGiBundleManager manager = (OSGiBundleManager)managerContext.getTarget();
+      OSGiBundleState sysBundle = manager.getBundle(0);
+      
+      return new OSGiFramework(manager, sysBundle);
+   }
+
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/resources/META-INF/services/org.osgi.framework.launch.FrameworkFactory
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/resources/META-INF/services/org.osgi.framework.launch.FrameworkFactory	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/resources/META-INF/services/org.osgi.framework.launch.FrameworkFactory	2009-08-21 11:58:47 UTC (rev 92661)
@@ -0,0 +1 @@
+org.jboss.osgi.plugins.facade.launch.OSGiFrameworkFactory
\ No newline at end of file

Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/launch/FrameworkLaunchTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/launch/FrameworkLaunchTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/launch/FrameworkLaunchTestCase.java	2009-08-21 11:58:47 UTC (rev 92661)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.osgi.launch;
+
+// $Id$
+
+import static org.junit.Assert.assertEquals;
+
+import org.jboss.osgi.spi.util.ServiceLoader;
+import org.junit.Test;
+import org.osgi.framework.launch.Framework;
+import org.osgi.framework.launch.FrameworkFactory;
+
+/**
+ * Test OSGi System bundle access
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 27-Jul-2009
+ */
+public class FrameworkLaunchTestCase 
+{
+   @Test
+   public void testFrameworkLaunch()
+   {
+      FrameworkFactory factory = ServiceLoader.loadService(FrameworkFactory.class);
+      Framework framework = factory.newFramework(null);
+      
+      assertEquals("BundleId == 0", 0, framework.getBundleId());
+      assertEquals("SymbolicName", "system.bundle", framework.getSymbolicName());
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/launch/FrameworkLaunchTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF




More information about the jboss-cvs-commits mailing list