[jboss-cvs] JBossAS SVN: r87986 - branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 29 06:18:00 EDT 2009


Author: emuckenhuber
Date: 2009-04-29 06:17:59 -0400 (Wed, 29 Apr 2009)
New Revision: 87986

Modified:
   branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/AbstractProfileDeployment.java
Log:
add transient attachment notion to profile deployment.

Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/AbstractProfileDeployment.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/AbstractProfileDeployment.java	2009-04-29 09:48:19 UTC (rev 87985)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/AbstractProfileDeployment.java	2009-04-29 10:17:59 UTC (rev 87986)
@@ -25,6 +25,7 @@
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
+import org.jboss.deployers.vfs.spi.client.VFSDeployment;
 import org.jboss.profileservice.spi.ProfileDeployment;
 import org.jboss.virtual.VirtualFile;
 
@@ -36,7 +37,7 @@
  */
 public class AbstractProfileDeployment implements ProfileDeployment
 {
-   
+
    /** The name. */
    private String name;
    
@@ -46,8 +47,11 @@
    /** The attachments. */
    private Map<String, Object> attachments = new ConcurrentHashMap<String, Object>();
    
+   /** The transient attachments. */
+   private transient Map<String, Object> transientAttachments = new ConcurrentHashMap<String, Object>();
+   
    /** The serialVersionUID. */
-   private static final long serialVersionUID = -2600392045205267112L;
+   private static final long serialVersionUID = -2208890215429044674L;
    
    /**
     * Get the vfs file name safely.
@@ -105,6 +109,16 @@
    }
    
    /**
+    * Get all attachments.
+    * 
+    * @return the attachments
+    */
+   public Map<String, Object> getAttachments()
+   {
+      return Collections.unmodifiableMap(this.attachments);
+   }
+   
+   /**
     * Get attachment.
     * 
     * @param name the name of the attachment
@@ -119,6 +133,32 @@
       
       return this.attachments.get(name);
    }
+   
+   /**
+    * Get attachment.
+    * 
+    * @param <T> the expected type
+    * @param name the name of the attachment
+    * @param expected the expected type
+    * @return the attachment or null if not present
+    * 
+    * @throws IllegalArgumentException for a null name
+    */
+   public <T> T getAttachment(String name, Class<T> expectedType)
+   {
+      if(expectedType == null)
+         throw new IllegalArgumentException("null expected type");
+      
+      Object attachment = getAttachment(name);
+      if(attachment == null)
+         return null;
+     
+      if(expectedType.isInstance(attachment) == false)
+         throw new IllegalStateException("attachment " + name + 
+            " with value " + attachment + " is not of the expected type " + expectedType);
+      
+      return expectedType.cast(attachment);
+   }
 
    /**
     * Add attachment.
@@ -140,15 +180,98 @@
    }
    
    /**
-    * Get all attachments.
+    * Remove attachment.
     * 
-    * @return the attachments
+    * @param name the attachment name
+    * @return the attachment or null if not present
+    * 
+    * @throws IllegalArgumentException for a null name
     */
-   public Map<String, Object> getAttachments()
+   public Object removeAttachment(String name)
    {
-      return Collections.unmodifiableMap(this.attachments);
+      if(name == null)
+         throw new IllegalArgumentException("Null attachment name.");
+      
+      return this.attachments.remove(name);
    }
    
+   /**
+    * Get the transient attachment. 
+    * 
+    * @param name the name of the attachment
+    * @return the attachment or null if not present
+    * 
+    * @throws IllegalArgumentException for a null name
+    */
+   public Object getTransientAttachment(String name)
+   {
+      if(name == null)
+         throw new IllegalArgumentException("Null attachment name.");
+      
+      return transientAttachments;
+   }
+   
+   /**
+    * Get transient attachment.
+    * 
+    * @param <T> the expected type
+    * @param name the name of the attachment
+    * @param expected the expected type
+    * @return the attachment or null if not present
+    * 
+    * @throws IllegalArgumentException for a null name
+    */
+   public <T> T getTransientAttachment(String name, Class<T> expectedType)
+   {
+      if(expectedType == null)
+         throw new IllegalArgumentException("null expected type");
+      
+      Object attachment = getTransientAttachment(name);
+      if(attachment == null)
+         return null;
+     
+      if(expectedType.isInstance(attachment) == false)
+         throw new IllegalStateException("attachment " + name + 
+            " with value " + attachment + " is not of the expected type " + expectedType);
+      
+      return expectedType.cast(attachment);
+   }
+   
+   /**
+    * Add transient attachment
+    * 
+    * @param name the name of the attachment
+    * @param attachment the attachment
+    * @return any previous attachment
+    * 
+    * @throws IllegalArgumentException for a null name or attachment 
+    */
+   public Object addTransientAttachment(String name, Object attachment)
+   {
+      if(name == null)
+         throw new IllegalArgumentException("Null attachment name.");
+      if(attachment == null)
+         throw new IllegalArgumentException("Null attachment.");
+      
+      return this.transientAttachments.put(name, attachment);
+   }
+   
+   /**
+    * Remove transient attachment.
+    * 
+    * @param name the attachment name
+    * @return the attachment or null if not present
+    * 
+    * @throws IllegalArgumentException for a null name
+    */
+   public Object removeTransientAttachment(String name)
+   {
+      if(name == null)
+         throw new IllegalArgumentException("Null attachment name.");
+      
+      return this.transientAttachments.remove(name);
+   }
+   
    public String toString()
    {
       return "AbstractProfileDeployment(" + root != null ? root.getName() : name + ")";




More information about the jboss-cvs-commits mailing list