[jboss-cvs] JBossAS SVN: r59439 - in projects/osgi/trunk/deployment/src/main/org/jboss/osgi: deployers metadata/plugins metadata/spi

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jan 9 10:33:22 EST 2007


Author: alesj
Date: 2007-01-09 10:33:13 -0500 (Tue, 09 Jan 2007)
New Revision: 59439

Added:
   projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleMetaDataDeployer.java
   projects/osgi/trunk/deployment/src/main/org/jboss/osgi/metadata/plugins/AbstractBundleMetaData.java
   projects/osgi/trunk/deployment/src/main/org/jboss/osgi/metadata/spi/BundleMetaData.java
Modified:
   projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleClassLoaderDeployer.java
   projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleLifecycleDeployer.java
Log:
bundle components

Modified: projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleClassLoaderDeployer.java
===================================================================
--- projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleClassLoaderDeployer.java	2007-01-09 14:17:16 UTC (rev 59438)
+++ projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleClassLoaderDeployer.java	2007-01-09 15:33:13 UTC (rev 59439)
@@ -23,6 +23,7 @@
 
 import org.jboss.deployers.plugins.deployers.helpers.AbstractTopLevelClassLoaderDeployer;
 import org.jboss.deployers.spi.structure.DeploymentContext;
+import org.jboss.osgi.metadata.spi.BundleMetaData;
 import org.jboss.osgi.core.platform.spi.BundleAdapter;
 
 /**
@@ -35,9 +36,10 @@
 
    public ClassLoader createTopLevelClassLoader(DeploymentContext context) throws Exception
    {
-      BundleAdapter bundleAdapter = context.getTransientAttachments().getAttachment(BundleAdapter.class);
-      if (bundleAdapter != null)
+      BundleMetaData bundleMD = context.getTransientAttachments().getAttachment(BundleMetaData.class);
+      if (bundleMD != null)
       {
+         BundleAdapter bundleAdapter = bundleMD.getBundleAdapter();
          // TODO - create CL
          return null;
       }

Modified: projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleLifecycleDeployer.java
===================================================================
--- projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleLifecycleDeployer.java	2007-01-09 14:17:16 UTC (rev 59438)
+++ projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleLifecycleDeployer.java	2007-01-09 15:33:13 UTC (rev 59439)
@@ -21,20 +21,81 @@
 */
 package org.jboss.osgi.deployers;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+import org.jboss.deployers.plugins.deployers.helpers.AbstractParsingDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
 import org.jboss.osgi.core.platform.spi.OSGiPlatform;
+import org.jboss.osgi.core.platform.spi.BundleAdapter;
+import org.jboss.osgi.metadata.spi.BundleMetaData;
+import org.jboss.osgi.metadata.plugins.AbstractBundleMetaData;
+import org.jboss.virtual.VirtualFile;
 
 /**
  * TODO - handle manifest, jar, BundleContext (ClassLoader), BundleActivatorMetaData, ...
  *
  * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
  */
-public class BundleLifecycleDeployer // extends AbstractXXXDeployer
+public class BundleLifecycleDeployer extends AbstractParsingDeployer<BundleMetaData>
 {
    private OSGiPlatform platform;
 
    public BundleLifecycleDeployer(OSGiPlatform platform)
    {
+      super(BundleMetaData.class);
       this.platform = platform;
    }
 
+   public void deploy(DeploymentUnit unit) throws DeploymentException
+   {
+      createMetaData(unit, null, ".mf");
+   }
+
+   protected BundleMetaData parse(DeploymentUnit unit, VirtualFile file, BundleMetaData root) throws Exception
+   {
+      Manifest manifest = null;
+      // we can add this part of the code to VFS code - extracting the current one
+      InputStream stream = file.openStream();
+      try
+      {
+         manifest = new Manifest(stream);
+      }
+      finally
+      {
+         try
+         {
+            stream.close();
+         }
+         catch (IOException ignored)
+         {
+         }
+      }
+      // get activator from manifest
+      Attributes attributes = manifest.getMainAttributes();
+      String activatorClassName = attributes.getValue("Bundle-Activator");
+      // install bundle - TODO is this ok to deploy bundle?
+      BundleAdapter bundleAdapter = platform.installBundle(file.getParent().getPathName(), null);
+      return new AbstractBundleMetaData(bundleAdapter, activatorClassName);
+   }
+
+   public void undeploy(DeploymentUnit unit)
+   {
+      try
+      {
+         BundleMetaData bmd = unit.getTransientManagedObjects().getAttachment(BundleMetaData.class);
+         if (bmd != null)
+         {
+            platform.uninstallBundle(bmd.getBundleAdapter().getBundleId());
+         }
+      }
+      catch (Exception e)
+      {
+         log.error("Exception while uninstalling bundle:" + unit);
+      }
+   }
+
 }

Added: projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleMetaDataDeployer.java
===================================================================
--- projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleMetaDataDeployer.java	2007-01-09 14:17:16 UTC (rev 59438)
+++ projects/osgi/trunk/deployment/src/main/org/jboss/osgi/deployers/BundleMetaDataDeployer.java	2007-01-09 15:33:13 UTC (rev 59439)
@@ -0,0 +1,80 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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.deployers;
+
+import org.jboss.deployers.plugins.deployers.helpers.AbstractRealDeployer;
+import org.jboss.deployers.plugins.deployers.helpers.SimpleDeploymentVisitor;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
+import org.jboss.osgi.core.platform.spi.BundleAdapter;
+import org.jboss.osgi.metadata.spi.BundleActivatorMetaData;
+import org.jboss.osgi.metadata.spi.BundleMetaData;
+
+/**
+ * TODO - javadoc
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class BundleMetaDataDeployer extends AbstractRealDeployer<BundleMetaData>
+{
+   public BundleMetaDataDeployer()
+   {
+      setDeploymentVisitor(new BundleMetaDataVisitor());
+   }
+
+   protected static void addBundleComponent(DeploymentUnit unit, Class clazz, Object value)
+   {
+      DeploymentUnit component = unit.addComponent(value.toString());
+      component.addAttachment(clazz.getName(), value);
+   }
+
+   protected static void removeBundleComponent(DeploymentUnit unit, Object value)
+   {
+      unit.removeComponent(value.toString());
+   }
+
+   /**
+    * KernelDeploymentVisitor.
+    */
+   public static class BundleMetaDataVisitor implements SimpleDeploymentVisitor<BundleMetaData>
+   {
+      public Class<BundleMetaData> getVisitorType()
+      {
+         return BundleMetaData.class;
+      }
+
+      public void deploy(DeploymentUnit unit, BundleMetaData bmd) throws DeploymentException
+      {
+         addBundleComponent(unit, BundleAdapter.class, bmd.getBundleAdapter());
+         if (bmd.getBundleActivator() != null)
+            addBundleComponent(unit, BundleActivatorMetaData.class, bmd.getBundleActivator());
+      }
+
+      public void undeploy(DeploymentUnit unit, BundleMetaData bmd)
+      {
+         removeBundleComponent(unit, bmd.getBundleAdapter());
+         if (bmd.getBundleActivator() != null)
+            removeBundleComponent(unit, bmd.getBundleActivator());
+      }
+   }
+
+}

Added: projects/osgi/trunk/deployment/src/main/org/jboss/osgi/metadata/plugins/AbstractBundleMetaData.java
===================================================================
--- projects/osgi/trunk/deployment/src/main/org/jboss/osgi/metadata/plugins/AbstractBundleMetaData.java	2007-01-09 14:17:16 UTC (rev 59438)
+++ projects/osgi/trunk/deployment/src/main/org/jboss/osgi/metadata/plugins/AbstractBundleMetaData.java	2007-01-09 15:33:13 UTC (rev 59439)
@@ -0,0 +1,55 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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.metadata.plugins;
+
+import org.jboss.osgi.metadata.spi.BundleMetaData;
+import org.jboss.osgi.metadata.spi.BundleActivatorMetaData;
+import org.jboss.osgi.core.platform.spi.BundleAdapter;
+
+/**
+ * TODO - comment, javadoc
+ * 
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class AbstractBundleMetaData implements BundleMetaData
+{
+   private BundleAdapter bundleAdapter;
+
+   private BundleActivatorMetaData bundleActivator;
+
+   public AbstractBundleMetaData(BundleAdapter bundleAdapter, String bundleActivatorClass)
+   {
+      this.bundleAdapter = bundleAdapter;
+      this.bundleActivator = new AbstractBundleActivatorMetaData(bundleActivatorClass);
+   }
+
+   public BundleAdapter getBundleAdapter()
+   {
+      return bundleAdapter;
+   }
+
+   public BundleActivatorMetaData getBundleActivator()
+   {
+      return bundleActivator;
+   }
+
+}

Added: projects/osgi/trunk/deployment/src/main/org/jboss/osgi/metadata/spi/BundleMetaData.java
===================================================================
--- projects/osgi/trunk/deployment/src/main/org/jboss/osgi/metadata/spi/BundleMetaData.java	2007-01-09 14:17:16 UTC (rev 59438)
+++ projects/osgi/trunk/deployment/src/main/org/jboss/osgi/metadata/spi/BundleMetaData.java	2007-01-09 15:33:13 UTC (rev 59439)
@@ -0,0 +1,36 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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.metadata.spi;
+
+import org.jboss.osgi.core.platform.spi.BundleAdapter;
+
+/**
+ * TODO - javadoc
+ * 
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface BundleMetaData
+{
+   BundleAdapter getBundleAdapter();
+
+   BundleActivatorMetaData getBundleActivator();
+}




More information about the jboss-cvs-commits mailing list