[jboss-osgi-commits] JBoss-OSGI SVN: r98019 - in projects/jboss-osgi/projects: spi/trunk/src/main/java/org/jboss/osgi/spi/util and 1 other directory.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Sat Dec 19 09:07:46 EST 2009


Author: thomas.diesler at jboss.com
Date: 2009-12-19 09:07:46 -0500 (Sat, 19 Dec 2009)
New Revision: 98019

Modified:
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java
Log:
Cache bundle header for default locale
Fix NPE in BundleInfo.

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java	2009-12-19 11:36:12 UTC (rev 98018)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java	2009-12-19 14:07:46 UTC (rev 98019)
@@ -96,6 +96,24 @@
    private AtomicInteger state = new AtomicInteger(Bundle.UNINSTALLED);
 
    /**
+    * Assert that the given bundle is an instance of AbstractBundleState
+    * @throws IllegalArgumentException if the given bundle is not an instance of AbstractBundleState
+    */
+   public static AbstractBundleState assertBundleState(Bundle bundle)
+   {
+      if (bundle == null)
+         throw new IllegalArgumentException("Null bundle");
+
+      if (bundle instanceof OSGiBundleWrapper)
+         bundle = ((OSGiBundleWrapper)bundle).getBundleState();
+
+      if (bundle instanceof AbstractBundleState == false)
+         throw new IllegalArgumentException("Not an AbstractBundleState: " + bundle);
+
+      return (AbstractBundleState)bundle;
+   }
+
+   /**
     * Get the bundleManager.
     * 
     * @return the bundleManager.
@@ -220,8 +238,8 @@
       return getHeaders(null);
    }
 
-   @SuppressWarnings("rawtypes")
-   public Dictionary getHeaders(String locale)
+   @SuppressWarnings("unchecked")
+   public Dictionary<String, String> getHeaders(String locale)
    {
       checkAdminPermission(AdminPermission.METADATA);
 
@@ -243,33 +261,14 @@
       if (baseName == null)
          baseName = Constants.BUNDLE_LOCALIZATION_DEFAULT_BASENAME;
 
-      // The Framework searches for localization entries by appending suffixes to
-      // the localization base name according to a specified locale and finally
-      // appending the .properties suffix. If a translation is not found, the locale
-      // must be made more generic by first removing the variant, then the country
-      // and finally the language until an entry is found that contains a valid 
-      // translation.
-      String entryPath = baseName + "_" + locale + ".properties";
-      URL entryURL = getEntryInternal(entryPath);
-      while (entryURL == null)
+      // Get the resource bundle URL for the given base and locale
+      URL entryURL = getLocalizationEntryPath(baseName, locale);
+      
+      // If the specified locale entry could not be found fall back to the default locale entry
+      if (entryURL == null)
       {
-         if (entryPath.equals(baseName + ".properties"))
-            break;
-         
-         int lastIndex = locale.lastIndexOf('_');
-         if (lastIndex > 0)
-         {
-            locale = locale.substring(0, lastIndex);
-            entryPath = baseName + "_" + locale + ".properties";
-         }
-         else
-         {
-            entryPath = baseName + ".properties";
-         }
-         
-         // The bundle's class loader is not used to search for localization entries. Only
-         // the contents of the bundle and its attached fragments are searched.
-         entryURL = getEntryInternal(entryPath);
+         String defaultLocale = Locale.getDefault().toString();
+         entryURL = getLocalizationEntryPath(baseName, defaultLocale);
       }
 
       // Read the resource bundle
@@ -313,6 +312,39 @@
       return new CaseInsensitiveDictionary(locHeaders);
    }
 
+   private URL getLocalizationEntryPath(String baseName, String locale)
+   {
+      // The Framework searches for localization entries by appending suffixes to
+      // the localization base name according to a specified locale and finally
+      // appending the .properties suffix. If a translation is not found, the locale
+      // must be made more generic by first removing the variant, then the country
+      // and finally the language until an entry is found that contains a valid translation.
+      
+      String entryPath = baseName + "_" + locale + ".properties";
+      URL entryURL = getEntryInternal(entryPath);
+      while (entryURL == null)
+      {
+         if (entryPath.equals(baseName + ".properties"))
+            break;
+         
+         int lastIndex = locale.lastIndexOf('_');
+         if (lastIndex > 0)
+         {
+            locale = locale.substring(0, lastIndex);
+            entryPath = baseName + "_" + locale + ".properties";
+         }
+         else
+         {
+            entryPath = baseName + ".properties";
+         }
+         
+         // The bundle's class loader is not used to search for localization entries. Only
+         // the contents of the bundle and its attached fragments are searched.
+         entryURL = getEntryInternal(entryPath);
+      }
+      return entryURL;
+   }
+
    // Get the entry without checking permissions and bundle state. 
    abstract URL getEntryInternal(String path);
 
@@ -636,11 +668,7 @@
       return bundleState.getBundleInternal();
    }
 
-   @Override
-   public String toString()
-   {
-      return "Bundle{" + getCanonicalName() + "}";
-   }
+   public abstract void uninstall() throws BundleException;
 
    /**
     * Get the canonical name of the bundle
@@ -812,17 +840,9 @@
       }
    }
 
-   public static AbstractBundleState assertBundleState(Bundle bundle)
+   @Override
+   public String toString()
    {
-      if (bundle == null)
-         throw new IllegalArgumentException("Null bundle");
-
-      if (bundle instanceof OSGiBundleWrapper)
-         bundle = ((OSGiBundleWrapper)bundle).getBundleState();
-
-      if (bundle instanceof AbstractBundleState == false)
-         throw new IllegalArgumentException("Not an AbstractBundleState: " + bundle);
-
-      return (AbstractBundleState)bundle;
+      return "Bundle{" + getCanonicalName() + "}";
    }
 }

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java	2009-12-19 11:36:12 UTC (rev 98018)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java	2009-12-19 14:07:46 UTC (rev 98019)
@@ -26,6 +26,7 @@
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.List;
 import java.util.Set;
@@ -64,7 +65,10 @@
 
    /** The list of deployment units */
    private List<DeploymentUnit> units = new ArrayList<DeploymentUnit>();
-
+   
+   /** The headers localized with the default locale */
+   Dictionary<String, String> headersOnUninstall;
+   
    /**
     * Create a new BundleState.
     * 
@@ -86,6 +90,19 @@
       addDeploymentUnit(unit);
    }
 
+   /**
+    * Assert that the given bundle is an instance of OSGiBundleState
+    * @throws IllegalArgumentException if the given bundle is not an instance of OSGiBundleState
+    */
+   public static OSGiBundleState assertBundleState(Bundle bundle)
+   {
+      bundle = AbstractBundleState.assertBundleState(bundle);
+      if (bundle instanceof OSGiBundleState == false)
+         throw new IllegalArgumentException("Not an OSGiBundleState: " + bundle);
+
+      return (OSGiBundleState)bundle;
+   }
+   
    @Override
    public OSGiMetaData getMetaData()
    {
@@ -479,9 +496,24 @@
       }
    }
 
+   @Override
+   public Dictionary<String, String> getHeaders(String locale)
+   {
+      // This method must continue to return Manifest header information while this bundle is in the UNINSTALLED state, 
+      // however the header values must only be available in the raw and default locale values
+      if (getState() == Bundle.UNINSTALLED)
+         return headersOnUninstall;
+      
+      return super.getHeaders(locale);
+   }
+
    public void uninstall() throws BundleException
    {
       checkAdminPermission(AdminPermission.LIFECYCLE); // [TODO] extension bundles
+      
+      // Cache the headers in the default locale 
+      headersOnUninstall = getHeaders(null);
+      
       getBundleManager().uninstallBundle(this);
    }
 
@@ -496,18 +528,4 @@
    {
       getBundleManager().removeContext(service, getDeploymentUnit());
    }
-
-   public static OSGiBundleState assertBundleState(Bundle bundle)
-   {
-      if (bundle == null)
-         throw new IllegalArgumentException("Null bundle");
-
-      if (bundle instanceof OSGiBundleWrapper)
-         bundle = ((OSGiBundleWrapper)bundle).getBundleState();
-
-      if (bundle instanceof OSGiBundleState == false)
-         throw new IllegalArgumentException("Not an OSGiBundleState: " + bundle);
-
-      return (OSGiBundleState)bundle;
-   }
 }

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java	2009-12-19 11:36:12 UTC (rev 98018)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java	2009-12-19 14:07:46 UTC (rev 98019)
@@ -33,7 +33,6 @@
 import org.jboss.dependency.spi.ControllerContext;
 import org.jboss.osgi.framework.metadata.OSGiMetaData;
 import org.jboss.osgi.framework.metadata.internal.AbstractOSGiMetaData;
-import org.jboss.osgi.spi.NotImplementedException;
 import org.jboss.util.collection.ConcurrentSet;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
@@ -167,8 +166,7 @@
 
    public void start(int options) throws BundleException
    {
-      // [JBOSGI-138] Proper system BundleContext implementation
-      throw new NotImplementedException();
+      // do nothing
    }
 
    public void stop(int options) throws BundleException

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java	2009-12-19 11:36:12 UTC (rev 98018)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java	2009-12-19 14:07:46 UTC (rev 98019)
@@ -134,8 +134,7 @@
             throw new IllegalArgumentException("Invalid Bundle-ManifestVersion:=1 for " + symbolicName);
 
          // Generate default symbolic name
-         String name = getManifestHeader(Constants.BUNDLE_NAME);
-         symbolicName = name.replace(' ', '-');
+         symbolicName = "anonymous-bundle";
          
          // Parse the Bundle-Version string
          try



More information about the jboss-osgi-commits mailing list