[jboss-osgi-commits] JBoss-OSGI SVN: r95042 - in projects/jboss-osgi: trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment and 1 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Fri Oct 16 10:58:10 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-10-16 10:58:09 -0400 (Fri, 16 Oct 2009)
New Revision: 95042

Added:
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/Attachments.java
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/DeploymentBase.java
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentImpl.java
Modified:
   projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/integration/AbstractMicrocontainerService.java
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/Deployment.java
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/DeploymentServiceBase.java
Log:
Add support for deployment attachments

Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/integration/AbstractMicrocontainerService.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/integration/AbstractMicrocontainerService.java	2009-10-16 14:50:10 UTC (rev 95041)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/integration/AbstractMicrocontainerService.java	2009-10-16 14:58:09 UTC (rev 95042)
@@ -126,7 +126,8 @@
       try
       {
          MainDeployer mainDeployer = (MainDeployer)getRegisteredBean("MainDeployer");
-         mainDeployer.removeDeployment((String)dep.getMetadata());
+         VFSDeployment vfsdep = dep.getAttachment(VFSDeployment.class);
+         mainDeployer.removeDeployment(vfsdep.getName());
          mainDeployer.process();
          return true;
       }
@@ -151,16 +152,16 @@
          for (Deployment dep : depArr)
          {
             VirtualFile file = VFS.createNewRoot(dep.getLocation());
-            VFSDeployment deployment = deploymentFactory.createVFSDeployment(file);
-            dep.setMetadata(deployment.getName());
+            VFSDeployment vfsdep = deploymentFactory.createVFSDeployment(file);
+            dep.addAttachment(VFSDeployment.class, vfsdep);
             registry.registerBundleDeployment(dep);
-            depList.add(deployment);
+            depList.add(vfsdep);
             
-            MutableAttachments att = (MutableAttachments)deployment.getPredeterminedManagedObjects();
+            MutableAttachments att = (MutableAttachments)vfsdep.getPredeterminedManagedObjects();
             att.addAttachment(OSGiConstants.PROPERTY_START_LEVEL, new Integer(dep.getStartLevel()));
             att.addAttachment(OSGiConstants.PROPERTY_AUTO_START, new Boolean(dep.isAutoStart()));
             
-            mainDeployer.addDeployment(deployment);
+            mainDeployer.addDeployment(vfsdep);
          }
 
          // Process the deployments
@@ -194,7 +195,8 @@
          for (Deployment dep : depArr)
          {
             registry.unregisterBundleDeployment(dep);
-            mainDeployer.removeDeployment((String)dep.getMetadata());
+            VFSDeployment vfsdep = dep.getAttachment(VFSDeployment.class);
+            mainDeployer.removeDeployment(vfsdep.getName());
          }
          mainDeployer.process();
       }

Added: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/Attachments.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/Attachments.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/Attachments.java	2009-10-16 14:58:09 UTC (rev 95042)
@@ -0,0 +1,160 @@
+/*
+ * 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.deployment;
+
+// $Id$
+
+import java.util.Collection;
+
+/**
+ * An interface for general Attachments
+ * 
+ * @author Thomas.Diesler at jboss.com
+ * @since 20-Apr-2007
+ */
+public interface Attachments
+{
+   /** Get attachment keys */
+   Collection<Key> getAttachmentKeys();
+
+   /** Add arbitrary attachment */
+   <T> T addAttachment(Class<T> clazz, Object value);
+
+   /** Add arbitrary attachment with name */
+   <T> T addAttachment(Class<T> clazz, String name, Object value);
+
+   /** Add arbitrary attachment with name */
+   Object addAttachment(String name, Object value);
+
+   /** Get an arbitrary attachment */
+   <T> T getAttachment(Class<T> clazz);
+
+   /** Get an arbitrary attachment */
+   <T> T getAttachment(Class<T> clazz, String name);
+
+   /** Get an arbitrary attachment */
+   Object getAttachment(String name);
+
+   /** Remove arbitrary attachments */
+   <T> T removeAttachment(Class<T> clazz);
+
+   /** Remove arbitrary attachments */
+   <T> T removeAttachment(Class<T> clazz, String name);
+
+   /** Remove arbitrary attachments */
+   Object removeAttachment(String name);
+
+   /**
+    * A key for attachements
+    */
+   public static class Key
+   {
+      private Class<?> clazz;
+      private String name;
+
+      /**
+       * Construct the key with optional class and name
+       */
+      public Key(Class<?> clazz, String name)
+      {
+         this.clazz = clazz;
+         this.name = name;
+      }
+
+      public static Key valueOf(String key)
+      {
+         int index = key.indexOf(",");
+         if (key.startsWith("[") && key.endsWith("]") && index > 0)
+         {
+            Class<?> classPart = null;
+            String className = key.substring(1, index);
+            String namePart = key.substring(index + 1, key.length() - 1);
+            if (className.length() > 0 && !className.equals("null"))
+            {
+               try
+               {
+                  classPart = Class.forName(className);
+               }
+               catch (ClassNotFoundException ex)
+               {
+                  throw new IllegalArgumentException("Cannot find class '" + className + "' in: " + key);
+               }
+            }
+            return new Key(classPart, namePart);
+         }
+         return null;
+      }
+
+      /**
+       * Get the class part for this key
+       * 
+       * @return maybe null
+       */
+      public Class<?> getClassPart()
+      {
+         return clazz;
+      }
+
+      /**
+       * Get the name part for this key
+       * 
+       * @return maybe null
+       */
+      public String getNamePart()
+      {
+         return name;
+      }
+
+      /**
+       * Two keys are equal if their {@link #toString()} is equal
+       */
+      public boolean equals(Object obj)
+      {
+         if (!(obj instanceof Key))
+            return false;
+         if (obj == this)
+            return true;
+         return obj.toString().equals(toString());
+      }
+
+      /**
+       * Two keys have the same hashCode if their {@link #toString()} is equal
+       */
+      public int hashCode()
+      {
+         return toString().hashCode();
+      }
+
+      /**
+       * Returns the String repesentation of this Key.
+       * <p/>
+       * 
+       * <pre>
+       * &quot;[&quot; + clazz + &quot;,&quot; + name + &quot;]&quot;
+       * </pre>
+       */
+      public String toString()
+      {
+         return "[" + clazz + "," + name + "]";
+      }
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/Attachments.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/Deployment.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/Deployment.java	2009-10-16 14:50:10 UTC (rev 95041)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/Deployment.java	2009-10-16 14:58:09 UTC (rev 95042)
@@ -21,7 +21,6 @@
  */
 package org.jboss.osgi.deployment;
 
-import java.io.Serializable;
 import java.net.URL;
 
 //$Id$
@@ -32,123 +31,40 @@
  * @author thomas.diesler at jboss.com
  * @since 27-May-2009
  */
-public class Deployment implements Serializable
+public interface Deployment extends Attachments
 {
-   private static final long serialVersionUID = 1L;
-   
-   private URL location;
-   private String symbolicName;
-   private String version;
-   private int startLevel;
-   private boolean autoStart;
-   private Object metadata;
-
-   public Deployment(URL location, String symbolicName, String version)
-   {
-      if (location == null)
-         throw new IllegalArgumentException("Location cannot be null");
-      if (symbolicName == null)
-         throw new IllegalArgumentException("Symbolic name cannot be null");
-      
-      if (version == null)
-         version = "0.0.0";
-      
-      this.symbolicName = symbolicName;
-      this.location = location;
-      this.version = version;
-   }
-
    /**
     * Get the bundle location
     */
-   public URL getLocation()
-   {
-      return location;
-   }
+   public URL getLocation();
 
    /**
     * Get the bundle symbolic name
     */
-   public String getSymbolicName()
-   {
-      return symbolicName;
-   }
+   public String getSymbolicName();
 
    /**
     * Get the bundle version
     */
-   public String getVersion()
-   {
-      return version;
-   }
+   public String getVersion();
 
    /**
     * Get the start level associated with this deployment
     */
-   public int getStartLevel()
-   {
-      return startLevel;
-   }
+   public int getStartLevel();
 
    /**
     * Set the start level associated with this deployment
     */
-   public void setStartLevel(int startLevel)
-   {
-      this.startLevel = startLevel;
-   }
+   public void setStartLevel(int startLevel);
 
    /**
     * Get the autostart flag associated with this deployment
     */
-   public boolean isAutoStart()
-   {
-      return autoStart;
-   }
+   public boolean isAutoStart();
 
    /**
     * Set the autostart flag associated with this deployment
     */
-   public void setAutoStart(boolean autoStart)
-   {
-      this.autoStart = autoStart;
-   }
-
-   /**
-    * Get extra meta data associated with this deployment
-    */
-   public Object getMetadata()
-   {
-      return metadata;
-   }
-
-   /**
-    * Set extra meta data associated with this deployment
-    */
-   public void setMetadata(Object metadata)
-   {
-      this.metadata = metadata;
-   }
-
-   @Override
-   public boolean equals(Object obj)
-   {
-      if (!(obj instanceof Deployment))
-         return false;
-      
-      Deployment other = (Deployment)obj;
-      return symbolicName.equals(other.symbolicName) && version.equals(other.version);
-   }
-
-   @Override
-   public int hashCode()
-   {
-      return toString().hashCode();
-   }
-
-   @Override
-   public String toString()
-   {
-      return "[" + symbolicName + "-" + version + ",url=" + location + "]";
-   }
+   public void setAutoStart(boolean autoStart);
 }
\ No newline at end of file

Added: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/DeploymentBase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/DeploymentBase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/DeploymentBase.java	2009-10-16 14:58:09 UTC (rev 95042)
@@ -0,0 +1,120 @@
+/*
+ * 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.deployment;
+
+// $Id$
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * Basic attachments.
+ * 
+ * @author Thomas.Diesler at jboss.com
+ * @since 20-Apr-2007
+ */
+public abstract class DeploymentBase implements Attachments
+{
+  private Map<Key, Object> attachments = new HashMap<Key, Object>();
+  
+  /** Construct the execution context with no attachments */
+  public DeploymentBase()
+  {
+    
+  }
+  
+  /** Construct the execution context with given attachments */
+  public DeploymentBase(Attachments att)
+  {
+    if (att != null)
+    {
+      for (Key key : att.getAttachmentKeys())
+      {
+        Object value = att.getAttachment(key.getClassPart(), key.getNamePart());
+        this.attachments.put(key, value);
+      }
+    }
+  }
+
+  public Collection<Key> getAttachmentKeys()
+  {
+    return attachments.keySet();
+  }
+
+  @SuppressWarnings("unchecked")
+  public <T> T getAttachment(Class<T> clazz)
+  {
+    return (T)attachments.get(new Key(clazz, null));
+  }
+
+  @SuppressWarnings("unchecked")
+  public <T> T getAttachment(Class<T> clazz, String name)
+  {
+    return (T)attachments.get(new Key(clazz, name));
+  }
+
+  public Object getAttachment(String name)
+  {
+    return attachments.get(new Key(null, name));
+  }
+
+  @SuppressWarnings("unchecked")
+  public <T> T addAttachment(Class<T> clazz, Object obj)
+  {
+    return (T)attachments.put(new Key(clazz, null), obj);
+  }
+
+  @SuppressWarnings("unchecked")
+  public <T> T addAttachment(Class<T> clazz, String name, Object obj)
+  {
+    return (T)attachments.put(new Key(clazz, name), obj);
+  }
+
+  public Object addAttachment(String name, Object obj)
+  {
+    return attachments.put(new Key(null, name), obj);
+  }
+
+  @SuppressWarnings("unchecked")
+  public <T> T removeAttachment(Class<T> clazz)
+  {
+    return (T)attachments.remove(new Key(clazz, null));
+  }
+
+  @SuppressWarnings("unchecked")
+  public <T> T removeAttachment(Class<T> clazz, String name)
+  {
+    return (T)attachments.remove(new Key(clazz, name));
+  }
+
+  public Object removeAttachment(String name)
+  {
+    return attachments.remove(new Key(null, name));
+  }
+  
+  public String toString()
+  {
+    return attachments.toString();
+  }
+}


Property changes on: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/DeploymentBase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/DeploymentServiceBase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/DeploymentServiceBase.java	2009-10-16 14:50:10 UTC (rev 95041)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/DeploymentServiceBase.java	2009-10-16 14:58:09 UTC (rev 95042)
@@ -29,6 +29,7 @@
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;
 
+import org.jboss.osgi.deployment.internal.DeploymentImpl;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
 
@@ -97,6 +98,6 @@
          throw new BundleException("Cannot obtain Bundle-SymbolicName for: " + url);
 
       String version = attribs.getValue(Constants.BUNDLE_VERSION);
-      return new Deployment(url, symbolicName, version);
+      return new DeploymentImpl(url, symbolicName, version);
    }
 }
\ No newline at end of file

Added: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentImpl.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentImpl.java	2009-10-16 14:58:09 UTC (rev 95042)
@@ -0,0 +1,157 @@
+/*
+ * 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.deployment.internal;
+
+import java.io.Serializable;
+import java.net.URL;
+
+import org.jboss.osgi.deployment.DeploymentBase;
+import org.jboss.osgi.deployment.Deployment;
+
+//$Id$
+
+/**
+ * An abstraction of a bundle deployment
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 27-May-2009
+ */
+public class DeploymentImpl extends DeploymentBase implements Deployment, Serializable
+{
+   private static final long serialVersionUID = 1L;
+   
+   private URL location;
+   private String symbolicName;
+   private String version;
+   private int startLevel;
+   private boolean autoStart;
+   private Object metadata;
+
+   public DeploymentImpl(URL location, String symbolicName, String version)
+   {
+      if (location == null)
+         throw new IllegalArgumentException("Location cannot be null");
+      if (symbolicName == null)
+         throw new IllegalArgumentException("Symbolic name cannot be null");
+      
+      if (version == null)
+         version = "0.0.0";
+      
+      this.symbolicName = symbolicName;
+      this.location = location;
+      this.version = version;
+   }
+
+   /**
+    * Get the bundle location
+    */
+   public URL getLocation()
+   {
+      return location;
+   }
+
+   /**
+    * Get the bundle symbolic name
+    */
+   public String getSymbolicName()
+   {
+      return symbolicName;
+   }
+
+   /**
+    * Get the bundle version
+    */
+   public String getVersion()
+   {
+      return version;
+   }
+
+   /**
+    * Get the start level associated with this deployment
+    */
+   public int getStartLevel()
+   {
+      return startLevel;
+   }
+
+   /**
+    * Set the start level associated with this deployment
+    */
+   public void setStartLevel(int startLevel)
+   {
+      this.startLevel = startLevel;
+   }
+
+   /**
+    * Get the autostart flag associated with this deployment
+    */
+   public boolean isAutoStart()
+   {
+      return autoStart;
+   }
+
+   /**
+    * Set the autostart flag associated with this deployment
+    */
+   public void setAutoStart(boolean autoStart)
+   {
+      this.autoStart = autoStart;
+   }
+
+   /**
+    * Get extra meta data associated with this deployment
+    */
+   public Object getMetadata()
+   {
+      return metadata;
+   }
+
+   /**
+    * Set extra meta data associated with this deployment
+    */
+   public void setMetadata(Object metadata)
+   {
+      this.metadata = metadata;
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (!(obj instanceof DeploymentImpl))
+         return false;
+      
+      DeploymentImpl other = (DeploymentImpl)obj;
+      return symbolicName.equals(other.symbolicName) && version.equals(other.version);
+   }
+
+   @Override
+   public int hashCode()
+   {
+      return toString().hashCode();
+   }
+
+   @Override
+   public String toString()
+   {
+      return "[" + symbolicName + "-" + version + ",url=" + location + "]";
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentImpl.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF



More information about the jboss-osgi-commits mailing list