[jboss-cvs] JBossAS SVN: r60951 - in projects/microcontainer/branches/2_0/deployers/src: main/org/jboss/deployers/plugins/structure and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Feb 27 13:04:43 EST 2007


Author: scott.stark at jboss.org
Date: 2007-02-27 13:04:43 -0500 (Tue, 27 Feb 2007)
New Revision: 60951

Modified:
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/AbstractDeploymentContext.java
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java
   projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/attachments/test/DeploymentAttachmentsInterceptUnitTestCase.java
   projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/attachments/test/DeploymentUnitAttachmentsUnitTestCase.java
   projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/attachments/test/DeploymentUnitPredeterminedManagedObjectsUnitTestCase.java
   projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/attachments/test/DeploymentUnitTransientAttachmentsUnitTestCase.java
   projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/attachments/test/DeploymentUnitTransientManagedObjectsUnitTestCase.java
   projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/jaxp/test/JAXPDeployerUnitTestCase.java
Log:
JBMICROCONT-151, refactor the attachment api on DeploymentUnit to facilitate proper usage

Modified: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java	2007-02-27 17:15:07 UTC (rev 60950)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java	2007-02-27 18:04:43 UTC (rev 60951)
@@ -29,7 +29,6 @@
 import java.util.Map;
 import java.util.Set;
 
-import org.jboss.deployers.plugins.attachments.AbstractAttachments;
 import org.jboss.deployers.plugins.structure.ComponentDeploymentContext;
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.attachments.Attachments;
@@ -49,7 +48,7 @@
  * @author Scott.Stark at jboss.org
  * @version $Revision: 1.1 $
  */
-public class AbstractDeploymentUnit extends AbstractAttachments
+public class AbstractDeploymentUnit
    implements DeploymentUnit, Serializable
 {
    private static final Logger log = Logger.getLogger(AbstractDeploymentUnit.class);
@@ -168,7 +167,7 @@
       return false;
    }
 
-   public Map<String, Object> getAttachments()
+   public Map<String, Object> getAllMetaData()
    {
       DeploymentContext parent = deploymentContext.getParent();
       if (deploymentContext.isComponent() == false)
@@ -188,12 +187,64 @@
       return Collections.unmodifiableMap(result);
    }
 
+   /**
+    * 
+    */
    public Object addAttachment(String name, Object attachment)
    {
       deploymentContext.deployed();
-      return deploymentContext.getTransientAttachments().addAttachment(name, attachment);
+      Object prevAttachment = null;
+      if( attachment instanceof Serializable )
+         prevAttachment = deploymentContext.getTransientManagedObjects().addAttachment(name, attachment);
+      else
+         prevAttachment = deploymentContext.getTransientAttachments().addAttachment(name, attachment);
+      return prevAttachment;
    }
 
+   public <T> T addAttachment(Class<T> type, T attachment)
+   {
+      if (type == null)
+         throw new IllegalArgumentException("Null type");
+      return addAttachment(type.getName(), attachment, type);
+   }
+   public <T> T addAttachment(String name, T attachment, Class<T> expectedType)
+   {
+      if (expectedType == null)
+         throw new IllegalArgumentException("Null expectedType");
+      Object result = addAttachment(name, attachment);
+      if (result == null)
+         return null;
+      return expectedType.cast(result);
+   }
+
+   public <T> T getAttachment(String name, Class<T> expectedType)
+   {
+      if (expectedType == null)
+         throw new IllegalArgumentException("Null expectedType");
+      Object result = getAttachment(name);
+      if (result == null)
+         return null;
+      return expectedType.cast(result);
+   }
+
+   public <T> T getAttachment(Class<T> type)
+   {
+      if (type == null)
+         throw new IllegalArgumentException("Null type");
+      return getAttachment(type.getName(), type);
+   }
+
+   public Attachments getAttachments()
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+
+   public Attachments getTransientAttachments()
+   {
+      return deploymentContext.getTransientAttachments();
+   }
+
    public Object getAttachment(String name)
    {
       DeploymentContext parent = deploymentContext.getParent();
@@ -285,9 +336,35 @@
       return false;
    }
 
+   public <T> T removeAttachment(String name, Class<T> expectedType)
+   {
+      if (expectedType == null)
+         throw new IllegalArgumentException("Null expectedType");
+      Object result = removeAttachment(name);
+      if (result == null)
+         return null;
+      return expectedType.cast(result);
+   }
+
+   public <T> T removeAttachment(Class<T> type)
+   {
+      if (type == null)
+         throw new IllegalArgumentException("Null type");
+      return removeAttachment(type.getName(), type);
+   }
+
    public Object removeAttachment(String name)
    {
-      return deploymentContext.getTransientAttachments().removeAttachment(name);
+      Object attachment = null;
+      if( deploymentContext.getTransientManagedObjects().isAttachmentPresent(name) )
+         attachment = deploymentContext.getTransientManagedObjects().removeAttachment(name);         
+      if( deploymentContext.getTransientAttachments().isAttachmentPresent(name) )
+      {
+         Object ta = deploymentContext.getTransientAttachments().removeAttachment(name);
+         if( attachment == null )
+            attachment = ta;
+      }
+      return attachment;
    }
 
    public Attachments getTransientManagedObjects()
@@ -345,7 +422,7 @@
          throw new IllegalArgumentException("Null type");
       
       Set<T> result = new HashSet<T>();
-      Map<String, Object> attachments = getAttachments();
+      Map<String, Object> attachments = getAllMetaData();
       for (Object object : attachments.values())
       {
          if (type.isInstance(object))

Modified: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/AbstractDeploymentContext.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/AbstractDeploymentContext.java	2007-02-27 17:15:07 UTC (rev 60950)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/AbstractDeploymentContext.java	2007-02-27 18:04:43 UTC (rev 60951)
@@ -107,11 +107,11 @@
    private Attachments predeterminedManagedObjects = new AttachmentsImpl();
    
    /** The attachments */
-   private transient Attachments transientAttachments =
+   private transient Attachments transientAttachments = new AttachmentsImpl();
+
+   /** The managed objects */
+   private transient Attachments transientManagedObjects =
       GeneratedAOPProxyFactory.createProxy(new AttachmentsImpl(), Attachments.class);
-   
-   /** The managed objects */
-   private transient Attachments transientManagedObjects = new AttachmentsImpl();
 
    /** Throwable */
    private Throwable problem;

Modified: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java	2007-02-27 17:15:07 UTC (rev 60950)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java	2007-02-27 18:04:43 UTC (rev 60951)
@@ -22,6 +22,7 @@
 package org.jboss.deployers.spi.deployer;
 
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.jboss.deployers.spi.DeploymentException;
@@ -40,7 +41,7 @@
  * @author Scott.Stark at jboss.org
  * @version $Revision: 1.1 $
  */
-public interface DeploymentUnit extends Attachments
+public interface DeploymentUnit
 {
    /**
     * Get the deployment units name
@@ -130,17 +131,143 @@
     * @throws DeploymentException for any error
     */
    boolean createClassLoader(ClassLoaderFactory factory) throws DeploymentException;
-   
+
    /**
-    * Get the managed objects
+    * Add attachment. This adds the attachment to the TransientManagedObjects
+    * if its Serializable, otherwise its added to the TransientAttachments.
+    *
+    * @param <T> the expected type
+    * @param attachment the attachment
+    * @param type the type
+    * @return any previous attachment
+    * @throws IllegalArgumentException for a null name, attachment or type
+    */
+   public <T> T addAttachment(Class<T> type, T attachment);
+
+   /**
+    * Add attachment. This adds the attachment to the TransientManagedObjects
+    * if its Serializable, otherwise its added to the TransientAttachments.
+    *
+    * @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 addAttachment(String name, Object attachment);
+
+   /**
+    * Add attachment. This adds the attachment to the TransientManagedObjects
+    * if its Serializable, otherwise its added to the TransientAttachments.
+    *
+    * @param <T> the expected type
+    * @param name the name of the attachment
+    * @param attachment the attachment
+    * @param expectedType the expected type
+    * @return any previous attachment
+    * @throws IllegalArgumentException for a null name, attachment or expectedType
+    */
+   public <T> T addAttachment(String name, T attachment, Class<T> expectedType);
+
+   /**
+    * Get attachment by name. This traverses the associated deployment
+    * attachment sets in the order of highest priority to lowest and returns the
+    * first set with a match.
     * 
+    * @param <T> the expected type
+    * @param type the type
+    * @return the attachment or null if not present
+    * @throws IllegalArgumentException for a null name or type
+    */
+   Object getAttachment(String name);
+
+   /**
+    * Get attachment. This traverses the associated deployment attachment
+    * sets in the order of highest priority to lowest and returns the
+    * first set with a match.
+    * 
+    * @param <T> the expected type
+    * @param type the type
+    * @return the attachment or null if not present
+    * @throws IllegalArgumentException for a null name or type
+    */
+   <T> T getAttachment(Class<T> type);
+
+   /**
+    * Get attachment by name and cast it to T. This traverses the associated
+    * deployment attachment sets in the order of highest priority to lowest
+    * and returns the first set with a match.
+    * 
+    * @param <T> the expected type
+    * @param name the name of the attachment
+    * @param expectedType the expected type
+    * @return the attachment or null if not present
+    * @throws IllegalArgumentException for a null name or expectedType
+    */
+   <T> T getAttachment(String name, Class<T> expectedType);
+
+   /**
+    * Remove attachment
+    * 
+    * @param name the name of the attachment
+    * @return the attachment or null if not present
+    * @throws IllegalArgumentException for a null name
+    */
+   Object removeAttachment(String name);
+
+   /**
+    * Remove attachment
+    * 
+    * @param <T> the expected type
+    * @param name the name of the attachment
+    * @return the attachment or null if not present
+    * @param expectedType the expected type
+    * @throws IllegalArgumentException for a null name or expectedType
+    */
+   <T> T removeAttachment(String name, Class<T> expectedType);
+
+   /**
+    * Remove attachment
+    * 
+    * @param <T> the expected type
+    * @return the attachment or null if not present
+    * @param type the type
+    * @throws IllegalArgumentException for a null name or type
+    */
+   <T> T removeAttachment(Class<T> type);
+
+   /**
+    * Get the deployment managed object metadata attachments. This is a set
+    * of metadata that is saved as a persistent state of the deployment. These
+    * attachments may be overriden by PredeterminedManagedObjects configured
+    * by management layers. 
+    * 
     * @return the managed objects
     */
    Attachments getTransientManagedObjects();
-   
+
    /**
-    * Get all the metadata for the expected type
+    * Get the deployment transient attachments. This collection of metadata
+    * is not stored as part of the persistent state of the deployment. Its
+    * primary use is to share metadata between deployers/aspects.
     * 
+    * @return the managed objects
+    */
+   Attachments getTransientAttachments();
+
+   /**
+    * Get all the attachments. This typically merges the
+    * attachments from the TransientAttachments, TransientManagedObjects,
+    * and the PredeterminedManagedObjects in that order. 
+    * 
+    * @return the unmodifiable attachments
+    */
+   Attachments getAttachments();
+
+   /**
+    * Get all the metadata for the expected type. This typically merges the
+    * attachments from the TransientAttachments, TransientManagedObjects,
+    * and the PredeterminedManagedObjects in that order.
+    * 
     * @param <T> the type to get
     * @param type the type
     * @return a set of metadata matching the type
@@ -149,6 +276,15 @@
    <T> Set<? extends T> getAllMetaData(Class<T> type);
 
    /**
+    * Get all the metadata. This typically merges the
+    * attachments from the TransientAttachments, TransientManagedObjects,
+    * and the PredeterminedManagedObjects in that order.
+    * 
+    * @return a map of metadata from the attachment sets
+    */
+   Map<String, Object> getAllMetaData();
+
+   /**
     * Add a component
     * 
     * @param name the name

Modified: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/attachments/test/DeploymentAttachmentsInterceptUnitTestCase.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/attachments/test/DeploymentAttachmentsInterceptUnitTestCase.java	2007-02-27 17:15:07 UTC (rev 60950)
+++ projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/attachments/test/DeploymentAttachmentsInterceptUnitTestCase.java	2007-02-27 18:04:43 UTC (rev 60951)
@@ -57,7 +57,7 @@
       unit = new AbstractDeploymentUnit(context);
       context.setDeploymentUnit(unit);
       // Integrate with aop
-      mutable = TrackingAdvice.wrapAttachments(unit);
+      mutable = TrackingAdvice.wrapAttachments(unit.getAttachments());
    }
 
    @Override
@@ -184,7 +184,7 @@
 
    protected Attachments getAttachments()
    {
-      return unit;
+      return unit.getAttachments();
    }
 
    protected Attachments getMutable()

Modified: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/attachments/test/DeploymentUnitAttachmentsUnitTestCase.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/attachments/test/DeploymentUnitAttachmentsUnitTestCase.java	2007-02-27 17:15:07 UTC (rev 60950)
+++ projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/attachments/test/DeploymentUnitAttachmentsUnitTestCase.java	2007-02-27 18:04:43 UTC (rev 60951)
@@ -52,12 +52,12 @@
       AbstractDeploymentContext context = new AbstractDeploymentContext("attachments");
       unit = new AbstractDeploymentUnit(context);
       context.setDeploymentUnit(unit);
-      mutable = unit;
+      mutable = unit.getAttachments();
    }
 
    protected Attachments getAttachments()
    {
-      return unit;
+      return unit.getAttachments();
    }
 
    protected Attachments getMutable()

Modified: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/attachments/test/DeploymentUnitPredeterminedManagedObjectsUnitTestCase.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/attachments/test/DeploymentUnitPredeterminedManagedObjectsUnitTestCase.java	2007-02-27 17:15:07 UTC (rev 60950)
+++ projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/attachments/test/DeploymentUnitPredeterminedManagedObjectsUnitTestCase.java	2007-02-27 18:04:43 UTC (rev 60951)
@@ -57,7 +57,7 @@
 
    protected Attachments getAttachments()
    {
-      return unit;
+      return unit.getAttachments();
    }
 
    protected Attachments getMutable()

Modified: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/attachments/test/DeploymentUnitTransientAttachmentsUnitTestCase.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/attachments/test/DeploymentUnitTransientAttachmentsUnitTestCase.java	2007-02-27 17:15:07 UTC (rev 60950)
+++ projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/attachments/test/DeploymentUnitTransientAttachmentsUnitTestCase.java	2007-02-27 18:04:43 UTC (rev 60951)
@@ -57,7 +57,7 @@
 
    protected Attachments getAttachments()
    {
-      return unit;
+      return unit.getAttachments();
    }
 
    protected Attachments getMutable()

Modified: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/attachments/test/DeploymentUnitTransientManagedObjectsUnitTestCase.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/attachments/test/DeploymentUnitTransientManagedObjectsUnitTestCase.java	2007-02-27 17:15:07 UTC (rev 60950)
+++ projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/attachments/test/DeploymentUnitTransientManagedObjectsUnitTestCase.java	2007-02-27 18:04:43 UTC (rev 60951)
@@ -57,7 +57,7 @@
 
    protected Attachments getAttachments()
    {
-      return unit;
+      return unit.getAttachments();
    }
 
    protected Attachments getMutable()

Modified: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/jaxp/test/JAXPDeployerUnitTestCase.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/jaxp/test/JAXPDeployerUnitTestCase.java	2007-02-27 17:15:07 UTC (rev 60950)
+++ projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/jaxp/test/JAXPDeployerUnitTestCase.java	2007-02-27 18:04:43 UTC (rev 60951)
@@ -111,7 +111,7 @@
    {
       main.addDeploymentContext(context);
       if( mo != null )
-         context.getTransientManagedObjects().addAttachment(clazz, mo);
+         context.getTransientAttachments().addAttachment(clazz, mo);
       main.process();
       assertEquals("DeploymentState", DeploymentState.DEPLOYED, context.getState());
    }




More information about the jboss-cvs-commits mailing list