[jboss-cvs] JBossAS SVN: r93175 - in projects/jboss-osgi/projects/runtime/microcontainer/trunk: .settings and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Sep 3 11:04:34 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-09-03 11:04:34 -0400 (Thu, 03 Sep 2009)
New Revision: 93175

Added:
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/.settings/org.eclipse.jdt.core.prefs
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/PackageAdminImpl.java
Modified:
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/.classpath
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleWrapper.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/MicrocontainerServiceImpl.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/StartLevelImpl.java
Log:
Add initial PackageAdmin implementation

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/.classpath
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/.classpath	2009-09-03 15:02:41 UTC (rev 93174)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/.classpath	2009-09-03 15:04:34 UTC (rev 93175)
@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-	<classpathentry kind="src" path="src/main/java"/>
-	<classpathentry kind="src" path="target/generated-sources/javacc"/>
-	<classpathentry excluding="**" kind="src" path="src/main/resources"/>
+	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
+	<classpathentry kind="src" output="target/classes" path="target/generated-sources/javacc"/>
+	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
 	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
 	<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>

Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/.settings/org.eclipse.jdt.core.prefs	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/.settings/org.eclipse.jdt.core.prefs	2009-09-03 15:04:34 UTC (rev 93175)
@@ -0,0 +1,5 @@
+#Thu Sep 03 16:27:07 CEST 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.source=1.5

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java	2009-09-03 15:02:41 UTC (rev 93174)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java	2009-09-03 15:04:34 UTC (rev 93175)
@@ -54,6 +54,7 @@
 import org.jboss.osgi.plugins.facade.api.BundleStoragePlugin;
 import org.jboss.osgi.plugins.facade.api.FrameworkEventsPlugin;
 import org.jboss.osgi.plugins.facade.service.MicrocontainerServiceImpl;
+import org.jboss.osgi.plugins.facade.service.PackageAdminImpl;
 import org.jboss.osgi.plugins.facade.service.StartLevelImpl;
 import org.jboss.osgi.plugins.filter.NoFilter;
 import org.jboss.osgi.plugins.metadata.AbstractOSGiMetaData;
@@ -62,7 +63,6 @@
 import org.jboss.virtual.VFS;
 import org.jboss.virtual.VirtualFile;
 import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
 import org.osgi.framework.Filter;
@@ -199,6 +199,14 @@
    }
 
    /**
+    * Get the kernel
+    */
+   public Kernel getKernel()
+   {
+      return kernel;
+   }
+   
+   /**
     * Set the framework properties
     * 
     * @param properties the properties
@@ -636,7 +644,8 @@
    {
       try
       {
-         deployerClient.change(bundleState.getDeploymentUnit().getName(), DeploymentStages.CLASSLOADER);
+         String name = bundleState.getDeploymentUnit().getName();
+         deployerClient.change(name, DeploymentStages.CLASSLOADER);
       }
       catch (DeploymentException e)
       {
@@ -882,9 +891,9 @@
       systemBundle.createBundleContext();
 
       // Register build-in services 
-      BundleContext sysContext = systemBundle.getBundleContext();
-      new MicrocontainerServiceImpl(kernel, sysContext);
-      new StartLevelImpl(sysContext);
+      new MicrocontainerServiceImpl(this);
+      new PackageAdminImpl(this);
+      new StartLevelImpl(this);
       
       // All installed bundles must be started
       AutoInstallPlugin autoInstall = getOptionalPlugin(AutoInstallPlugin.class);

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java	2009-09-03 15:02:41 UTC (rev 93174)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java	2009-09-03 15:04:34 UTC (rev 93175)
@@ -85,7 +85,7 @@
     * 
     * @return the unit.
     */
-   DeploymentUnit getDeploymentUnit()
+   public DeploymentUnit getDeploymentUnit()
    {
       return unit;
    }

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleWrapper.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleWrapper.java	2009-09-03 15:02:41 UTC (rev 93174)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleWrapper.java	2009-09-03 15:04:34 UTC (rev 93175)
@@ -65,7 +65,7 @@
     * 
     * @return the bundle state
     */
-   AbstractBundleState getBundleState()
+   public AbstractBundleState getBundleState()
    {
       return bundleState;
    }

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/MicrocontainerServiceImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/MicrocontainerServiceImpl.java	2009-09-03 15:02:41 UTC (rev 93174)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/MicrocontainerServiceImpl.java	2009-09-03 15:04:34 UTC (rev 93175)
@@ -41,6 +41,7 @@
 import org.jboss.kernel.spi.dependency.KernelController;
 import org.jboss.kernel.spi.dependency.KernelControllerContext;
 import org.jboss.logging.Logger;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
 import org.jboss.osgi.spi.management.MicrocontainerServiceMBean;
 import org.jboss.osgi.spi.service.MicrocontainerService;
 import org.osgi.framework.BundleContext;
@@ -61,19 +62,17 @@
    /** The log */
    private static final Logger log = Logger.getLogger(MicrocontainerServiceImpl.class);
    
-   private Kernel kernel;
    private BundleContext sysContext;
+   private Kernel kernel;
 
-   public MicrocontainerServiceImpl(Kernel kernel, BundleContext sysContext)
+   public MicrocontainerServiceImpl(OSGiBundleManager bundleManager)
    {
-      if (kernel == null)
-         throw new IllegalArgumentException("Null kernel");
-      if (sysContext == null)
-         throw new IllegalArgumentException("Null sysContext");
-
-      this.kernel = kernel;
-      this.sysContext = sysContext;
+      if (bundleManager == null)
+         throw new IllegalArgumentException("Null bundleManager");
       
+      this.sysContext = bundleManager.getSystemBundle();
+      this.kernel = bundleManager.getKernel();
+      
       installKernelBean(BEAN_SYSTEM_BUNDLE_CONTEXT, sysContext);
       sysContext.registerService(MicrocontainerService.class.getName(), this, null);
 

Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/PackageAdminImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/PackageAdminImpl.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/PackageAdminImpl.java	2009-09-03 15:04:34 UTC (rev 93175)
@@ -0,0 +1,228 @@
+/*
+ * 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.service;
+
+//$Id: StartLevelImpl.java 93118 2009-09-02 08:24:44Z thomas.diesler at jboss.com $
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.classloading.plugins.metadata.PackageCapability;
+import org.jboss.classloading.spi.metadata.CapabilitiesMetaData;
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.logging.Logger;
+import org.jboss.osgi.plugins.facade.bundle.AbstractBundleState;
+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.jboss.osgi.spi.NotImplementedException;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Version;
+import org.osgi.service.packageadmin.ExportedPackage;
+import org.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.service.packageadmin.RequiredBundle;
+
+/**
+ * An implementation of the {@link PackageAdmin}.
+ * 
+ * [TODO] Move this service to a plugin and implement properly 
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 03-Sep-2009
+ */
+public class PackageAdminImpl implements PackageAdmin
+{
+   /** The log */
+   private static final Logger log = Logger.getLogger(PackageAdminImpl.class);
+
+   private OSGiBundleManager bundleManager;
+   
+   public PackageAdminImpl(OSGiBundleManager bundleManager)
+   {
+      if (bundleManager == null)
+         throw new IllegalArgumentException("Null bundleManager");
+      
+      this.bundleManager = bundleManager;
+      
+      BundleContext sysContext = bundleManager.getSystemBundle().getBundleContext();
+      sysContext.registerService(PackageAdmin.class.getName(), this, null);
+   }
+
+   @SuppressWarnings("unchecked")
+   public Bundle getBundle(Class clazz)
+   {
+      throw new NotImplementedException();
+   }
+
+   public int getBundleType(Bundle bundle)
+   {
+      throw new NotImplementedException();
+   }
+
+   public Bundle[] getBundles(String symbolicName, String versionRange)
+   {
+      throw new NotImplementedException();
+   }
+
+   public ExportedPackage getExportedPackage(String name)
+   {
+      throw new NotImplementedException();
+   }
+
+   public ExportedPackage[] getExportedPackages(Bundle bundle)
+   {
+      OSGiBundleState bundleState = assertBundleState(bundle);
+      DeploymentUnit unit = bundleState.getDeploymentUnit();
+      ClassLoadingMetaData metaData = unit.getAttachment(ClassLoadingMetaData.class);
+      if (metaData == null)
+         throw new IllegalStateException("Cannot obtain ClassLoadingMetaData");
+      
+      List<ExportedPackage> exported = new ArrayList<ExportedPackage>();
+      CapabilitiesMetaData capabilities = metaData.getCapabilities();
+      for (Capability capability : capabilities.getCapabilities())
+      {
+         if (capability instanceof PackageCapability)
+         {
+            exported.add(new ExportedPackageImpl(bundleState, (PackageCapability)capability));
+         }
+      }
+      if (exported.size() == 0)
+         return null;
+      
+      ExportedPackage[] result = new ExportedPackage[exported.size()];
+      exported.toArray(result);
+      
+      return result;
+   }
+
+   public ExportedPackage[] getExportedPackages(String name)
+   {
+      throw new NotImplementedException();
+   }
+
+   public Bundle[] getFragments(Bundle bundle)
+   {
+      throw new NotImplementedException();
+   }
+
+   public Bundle[] getHosts(Bundle bundle)
+   {
+      throw new NotImplementedException();
+   }
+
+   public RequiredBundle[] getRequiredBundles(String symbolicName)
+   {
+      throw new NotImplementedException();
+   }
+
+   public void refreshPackages(Bundle[] bundles)
+   {
+      log.warn("Ignore refreshPackages");
+   }
+
+   public boolean resolveBundles(Bundle[] bundles)
+   {
+      List<OSGiBundleState> bundleStates = new ArrayList<OSGiBundleState>();
+      if (bundles == null)
+      {
+         for (AbstractBundleState aux : bundleManager.getBundles())
+         {
+            if (aux.getState() == Bundle.INSTALLED)
+               bundleStates.add((OSGiBundleState)aux);
+         }
+      }
+      else
+      {
+         for (Bundle bundle : bundles)
+         {
+            bundleStates.add(assertBundleState(bundle));
+         }
+      }
+      
+      boolean result = true;
+      for (OSGiBundleState bundleState : bundleStates)
+      {
+         result &= bundleManager.resolve(bundleState, false);
+      }
+      
+      return result;
+   }
+
+   private OSGiBundleState assertBundleState(Bundle bundle)
+   {
+      AbstractBundleState abstractState = null;
+      if (bundle instanceof OSGiBundleState)
+         abstractState = (OSGiBundleState)bundle;
+      if (bundle instanceof OSGiBundleWrapper)
+         abstractState = ((OSGiBundleWrapper)bundle).getBundleState();
+
+      if (abstractState instanceof OSGiBundleState == false)
+         throw new IllegalArgumentException("Cannot obtain bunde state from: " + bundle);
+      
+      return (OSGiBundleState)abstractState;
+   }
+   
+   private static class ExportedPackageImpl implements ExportedPackage
+   {
+      private Bundle bundle;
+      private PackageCapability capability;
+      
+      public ExportedPackageImpl(AbstractBundleState bundle, PackageCapability capability)
+      {
+         this.bundle = bundle.getBundle();
+         this.capability = capability;
+      }
+
+      public Bundle getExportingBundle()
+      {
+         return bundle;
+      }
+
+      public Bundle[] getImportingBundles()
+      {
+         throw new NotImplementedException();
+      }
+
+      public String getName()
+      {
+         return capability.getName();
+      }
+
+      public String getSpecificationVersion()
+      {
+         throw new NotImplementedException();
+      }
+
+      public Version getVersion()
+      {
+         return Version.parseVersion(capability.getVersion().toString());
+      }
+
+      public boolean isRemovalPending()
+      {
+         throw new NotImplementedException();
+      }
+   }
+}
\ No newline at end of file

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/StartLevelImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/StartLevelImpl.java	2009-09-03 15:02:41 UTC (rev 93174)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/StartLevelImpl.java	2009-09-03 15:04:34 UTC (rev 93175)
@@ -24,6 +24,7 @@
 //$Id$
 
 import org.jboss.logging.Logger;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.startlevel.StartLevel;
@@ -41,11 +42,12 @@
    /** The log */
    private static final Logger log = Logger.getLogger(StartLevelImpl.class);
 
-   public StartLevelImpl(BundleContext sysContext)
+   public StartLevelImpl(OSGiBundleManager bundleManager)
    {
-      if (sysContext == null)
-         throw new IllegalArgumentException("Null sysContext");
+      if (bundleManager == null)
+         throw new IllegalArgumentException("Null bundleManager");
       
+      BundleContext sysContext = bundleManager.getSystemBundle();
       sysContext.registerService(StartLevel.class.getName(), this, null);
    }
    




More information about the jboss-cvs-commits mailing list