[jboss-osgi-commits] JBoss-OSGI SVN: r92725 - in projects/jboss-osgi/projects/runtime/microcontainer/trunk/src: main/java/org/jboss/osgi/plugins/facade/api and 4 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Mon Aug 24 02:19:18 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-08-24 02:19:18 -0400 (Mon, 24 Aug 2009)
New Revision: 92725

Added:
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/api/
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/api/AbstractPlugin.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/api/AutoInstallPlugin.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/api/BundleStoragePlugin.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/AbstractPluginImpl.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/AutoInstallPluginImpl.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/BundleStoragePluginImpl.java
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/OSGiBundleState.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/bundle/test/BundleContextUnitTestCase.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml
Log:
[JBOSGI-134] Add support for BundleContext.getDataFile()

Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/api/AbstractPlugin.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/api/AbstractPlugin.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/api/AbstractPlugin.java	2009-08-24 06:19:18 UTC (rev 92725)
@@ -0,0 +1,42 @@
+/*
+ * 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.api;
+
+//$Id$
+
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
+
+/**
+ * The base of all framework plugins
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 20-Aug-2009
+ */
+public interface AbstractPlugin
+{
+   OSGiBundleManager getBundleManager();
+
+   <T extends AbstractPlugin> T getPlugin(Class<T> clazz);
+
+   <T extends AbstractPlugin> T getOptionalPlugin(Class<T> clazz);
+
+}
\ No newline at end of file


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

Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/api/AutoInstallPlugin.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/api/AutoInstallPlugin.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/api/AutoInstallPlugin.java	2009-08-24 06:19:18 UTC (rev 92725)
@@ -0,0 +1,40 @@
+/*
+ * 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.api;
+
+import org.osgi.framework.BundleException;
+
+
+//$Id$
+
+/**
+ * A plugin that installs/starts bundles on framework startup.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 18-Aug-2009
+ */
+public interface AutoInstallPlugin extends AbstractPlugin
+{
+   void installBundles() throws BundleException;
+   
+   void startBundles() throws BundleException;
+}
\ No newline at end of file


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

Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/api/BundleStoragePlugin.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/api/BundleStoragePlugin.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/api/BundleStoragePlugin.java	2009-08-24 06:19:18 UTC (rev 92725)
@@ -0,0 +1,44 @@
+/*
+ * 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.api;
+
+// $Id$
+
+import java.io.File;
+
+import org.osgi.framework.Bundle;
+
+/**
+ * An abstraction of a bundle persistent storage system.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 18-Aug-2009
+ */
+public interface BundleStoragePlugin extends AbstractPlugin 
+{
+   void cleanStorage(String propValue);
+   
+   File getStorageDir(Bundle bundle);
+   
+   File getDataFile(Bundle bundle, String filename);
+
+}
\ No newline at end of file


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

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-08-24 05:53:22 UTC (rev 92724)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java	2009-08-24 06:19:18 UTC (rev 92725)
@@ -28,6 +28,7 @@
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.Dictionary;
+import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
@@ -53,6 +54,7 @@
 import org.jboss.deployers.vfs.spi.client.VFSDeployment;
 import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
 import org.jboss.logging.Logger;
+import org.jboss.osgi.plugins.facade.api.AbstractPlugin;
 import org.jboss.osgi.plugins.filter.NoFilter;
 import org.jboss.osgi.plugins.metadata.AbstractOSGiMetaData;
 import org.jboss.osgi.spi.metadata.OSGiMetaData;
@@ -79,6 +81,9 @@
 {
    /** The log */
    private static final Logger log = Logger.getLogger(OSGiBundleManager.class); 
+
+   /** The bundle manager's bean name: OSGiBundleManager */
+   public static final String BEAN_BUNDLE_MANAGER = "OSGiBundleManager";
    
    /** The framework version */
    private static String OSGi_FRAMEWORK_VERSION = "r4v42"; // todo externalise
@@ -115,9 +120,10 @@
 
    /** The system bundle */
    private OSGiSystemBundle systemBundle;
-
-   public static final String BEAN_BUNDLE_MANAGER = "OSGiBundleManager";
    
+   /** The registered manager plugins */
+   private Map<Class<?>, AbstractPlugin> plugins = new HashMap<Class<?>, AbstractPlugin>();
+   
    static
    {
       AccessController.doPrivileged(new PrivilegedAction<Object>()
@@ -178,6 +184,62 @@
    }
    
    /**
+    * Get a plugin that is registered with the bundle manager.
+    * @throws IllegalStateException if the requested plugin class is not registered
+    */
+   @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;
+   }
+
+   /**
+    * Get an optional plugin that is registered with the bundle manager.
+    * @return The plugin instance or null if the requested plugin class is not registered
+    */
+   @SuppressWarnings("unchecked")
+   public <T extends AbstractPlugin> T getOptionalPlugin(Class<T> clazz)
+   {
+      return (T)plugins.get(clazz);
+   }
+   
+   /**
+    * Add a plugin
+    */
+   public void addPlugin(AbstractPlugin plugin)
+   {
+      Class<? extends AbstractPlugin> clazz = plugin.getClass();
+      for (Class<?> interf : clazz.getInterfaces())
+      {
+         if (AbstractPlugin.class.isAssignableFrom(interf))
+         {
+            log.debug("Add plugin: " + clazz.getName());
+            plugins.put(interf, plugin);
+         }
+      }
+   }
+   
+   /**
+    * Add a plugin
+    */
+   public void removePlugin(AbstractPlugin plugin)
+   {
+      Class<? extends AbstractPlugin> clazz = plugin.getClass();
+      for (Class<?> interf : clazz.getInterfaces())
+      {
+         if (AbstractPlugin.class.isAssignableFrom(interf))
+         {
+            log.debug("Remove plugin: " + clazz.getName());
+            plugins.remove(interf);
+         }
+      }
+   }
+   
+   /**
     * Are we active
     * 
     * @return true when the system is active
@@ -380,7 +442,7 @@
     * 
     * @return the system bundle
     */
-   OSGiSystemBundle getSystemBundle()
+   public OSGiSystemBundle getSystemBundle()
    {
       return systemBundle;
    }
@@ -416,7 +478,7 @@
     * @return the property
     * @throws SecurityException if the caller doesn't have the relevant property permission
     */
-   public static String getProperty(String key)
+   public String getProperty(String key)
    {
       if (key == null)
          return null;
@@ -432,6 +494,7 @@
          return OSGi_FRAMEWORK_OS_VERSION; 
       if (Constants.FRAMEWORK_PROCESSOR.equals(key))
          return OSGi_FRAMEWORK_PROCESSOR; 
+      
       return System.getProperty(key);
    }
 

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-08-24 05:53:22 UTC (rev 92724)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java	2009-08-24 06:19:18 UTC (rev 92725)
@@ -50,6 +50,7 @@
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
 import org.jboss.kernel.spi.dependency.KernelController;
 import org.jboss.logging.Logger;
+import org.jboss.osgi.plugins.facade.api.BundleStoragePlugin;
 import org.jboss.osgi.plugins.filter.NoFilter;
 import org.jboss.osgi.spi.NotImplementedException;
 import org.jboss.osgi.spi.metadata.OSGiMetaData;
@@ -308,14 +309,14 @@
    public String getProperty(String key)
    {
       checkValidBundleContext();
-      return OSGiBundleManager.getProperty(key);
+      return bundleManager.getProperty(key);
    }
 
    public File getDataFile(String filename)
    {
       checkValidBundleContext();
-      // todo getDataFile
-      return null;
+      BundleStoragePlugin storagePlugin = bundleManager.getPlugin(BundleStoragePlugin.class);
+      return storagePlugin.getDataFile(this, filename);
    }
 
    public URL getEntry(String path)

Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/AbstractPluginImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/AbstractPluginImpl.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/AbstractPluginImpl.java	2009-08-24 06:19:18 UTC (rev 92725)
@@ -0,0 +1,58 @@
+/*
+ * 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.plugins;
+
+//$Id$
+
+import org.jboss.osgi.plugins.facade.api.AbstractPlugin;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
+
+/**
+ * The base class of all framework plugins.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 18-Aug-2009
+ */
+public abstract class AbstractPluginImpl implements AbstractPlugin
+{
+   protected OSGiBundleManager bundleManager;
+
+   public AbstractPluginImpl(OSGiBundleManager bundleManager)
+   {
+      this.bundleManager = bundleManager;
+   }
+   
+   public OSGiBundleManager getBundleManager()
+   {
+      return bundleManager;
+   }
+
+   public <T extends AbstractPlugin> T getPlugin(Class<T> clazz)
+   {
+      return bundleManager.getPlugin(clazz);
+   }
+   
+   public <T extends AbstractPlugin> T getOptionalPlugin(Class<T> clazz)
+   {
+      return bundleManager.getOptionalPlugin(clazz);
+   }
+}
\ No newline at end of file


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

Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/AutoInstallPluginImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/AutoInstallPluginImpl.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/AutoInstallPluginImpl.java	2009-08-24 06:19:18 UTC (rev 92725)
@@ -0,0 +1,97 @@
+/*
+ * 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.plugins;
+
+//$Id$
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.logging.Logger;
+import org.jboss.osgi.plugins.facade.api.AutoInstallPlugin;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+/**
+ * A plugin that installs/starts bundles on framework startup.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 18-Aug-2009
+ */
+public class AutoInstallPluginImpl extends AbstractPluginImpl implements AutoInstallPlugin
+{
+   // Provide logging
+   final Logger log = Logger.getLogger(AutoInstallPluginImpl.class);
+   
+   private List<URL> autoInstall;
+   private List<URL> autoStart;
+   
+   private Map<URL, Bundle> autoBundles = new HashMap<URL, Bundle>();
+   
+   public AutoInstallPluginImpl(OSGiBundleManager bundleManager)
+   {
+      super(bundleManager);
+   }
+
+   
+   public void setAutoInstall(List<URL> autoInstall)
+   {
+      this.autoInstall = autoInstall;
+   }
+
+   public void setAutoStart(List<URL> autoStart)
+   {
+      this.autoStart = autoStart;
+   }
+
+   public void installBundles() throws BundleException
+   {
+      // Add the autoStart bundles to autoInstall
+      for (URL bundleURL : autoStart)
+      {
+         autoInstall.add(bundleURL);
+      }
+
+      // Install autoInstall bundles
+      for (URL bundleURL : autoInstall)
+      {
+         Bundle bundle = bundleManager.install(bundleURL);
+         autoBundles.put(bundleURL, bundle);
+      }
+   }
+
+   public void startBundles() throws BundleException
+   {
+      // Start autoStart bundles
+      for (URL bundleURL : autoStart)
+      {
+         Bundle bundle = autoBundles.get(bundleURL);
+         if (bundle != null)
+         {
+            bundle.start();
+         }
+      }
+   }
+}
\ No newline at end of file


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

Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/BundleStoragePluginImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/BundleStoragePluginImpl.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/BundleStoragePluginImpl.java	2009-08-24 06:19:18 UTC (rev 92725)
@@ -0,0 +1,102 @@
+/*
+ * 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.plugins;
+
+//$Id$
+
+import java.io.File;
+import java.io.IOException;
+
+import org.jboss.logging.Logger;
+import org.jboss.osgi.plugins.facade.api.BundleStoragePlugin;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+
+/**
+ * A simple implementation of a BundleStorage
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 18-Aug-2009
+ */
+public class BundleStoragePluginImpl extends AbstractPluginImpl implements BundleStoragePlugin
+{
+   // Provide logging
+   final Logger log = Logger.getLogger(BundleStoragePluginImpl.class);
+
+   private String storageArea;
+
+   public BundleStoragePluginImpl(OSGiBundleManager bundleManager)
+   {
+      super(bundleManager);
+   }
+
+   public void cleanStorage(String propValue)
+   {
+      // [TODO] Support values other than 'onFirstInit'
+      if (Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT.equals(propValue))
+      {
+         File storage = new File(getStorageArea());
+         storage.delete();
+      }
+   }
+
+   public File getDataFile(Bundle bundle, String filename)
+   {
+      File bundleDir = getStorageDir(bundle);
+      File dataFile = new File(bundleDir.getAbsolutePath() + "/" + filename);
+      dataFile.getParentFile().mkdirs();
+      return dataFile;
+   }
+
+   public File getStorageDir(Bundle bundle)
+   {
+      File bundleDir = new File(getStorageArea() + "/bundle-" + bundle.getBundleId());
+      if (bundleDir.exists() == false)
+         bundleDir.mkdirs();
+
+      return bundleDir;
+   }
+
+   private String getStorageArea()
+   {
+      if (storageArea == null)
+      {
+         String dirName = bundleManager.getProperty(Constants.FRAMEWORK_STORAGE);
+         if (dirName == null)
+         {
+            try
+            {
+               File tmpFile = File.createTempFile("Constants.FRAMEWORK_STORAGE", null);
+               dirName = tmpFile.getParent();
+               tmpFile.delete();
+            }
+            catch (IOException ex)
+            {
+               throw new IllegalStateException("Cannot create temp storage file", ex);
+            }
+         }
+         storageArea = dirName;
+      }
+      return storageArea;
+   }
+}
\ No newline at end of file


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

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/bundle/test/BundleContextUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/bundle/test/BundleContextUnitTestCase.java	2009-08-24 05:53:22 UTC (rev 92724)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/bundle/test/BundleContextUnitTestCase.java	2009-08-24 06:19:18 UTC (rev 92725)
@@ -21,6 +21,7 @@
 */
 package org.jboss.test.osgi.bundle.test;
 
+import java.io.File;
 import java.util.Arrays;
 import java.util.Dictionary;
 import java.util.HashSet;
@@ -488,7 +489,10 @@
          bundle.start();
          BundleContext bundleContext = bundle.getBundleContext();
          assertNotNull(bundleContext);
-         assertNull(bundleContext.getDataFile("blah"));
+         
+         File dataFile = bundleContext.getDataFile("blah");
+         assertNotNull(dataFile);
+         assertTrue(dataFile.toString().endsWith("/blah"));
       }
       finally
       {

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml	2009-08-24 05:53:22 UTC (rev 92724)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml	2009-08-24 06:19:18 UTC (rev 92725)
@@ -10,8 +10,14 @@
   
   <bean name="OSGiBundleManager" class="org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager">
     <constructor><parameter><inject bean="MainDeployer" /></parameter></constructor>
+    <incallback method="addPlugin" />
+    <uncallback method="removePlugin" />
   </bean>
   
+  <bean name="OSGiStoragePlugin" class="org.jboss.osgi.plugins.facade.plugins.BundleStoragePluginImpl">
+    <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+  </bean>
+  
   <!--
   ********************************
   *                              *  



More information about the jboss-osgi-commits mailing list