[jboss-cvs] JBossAS SVN: r84819 - in projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed: plugins and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Feb 26 14:20:14 EST 2009


Author: scott.stark at jboss.org
Date: 2009-02-26 14:20:14 -0500 (Thu, 26 Feb 2009)
New Revision: 84819

Modified:
   projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedDeployment.java
   projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/ManagedDeploymentImpl.java
Log:
JBMAN-58, Add attachment notion to ManagedDeployment

Modified: projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedDeployment.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedDeployment.java	2009-02-26 18:59:00 UTC (rev 84818)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedDeployment.java	2009-02-26 19:20:14 UTC (rev 84819)
@@ -165,4 +165,38 @@
     * @return the deployment
     */
    public ManagedDeployment addModule(String deplymentBaseName, DeploymentTemplateInfo info);
+
+   /**
+    * Get an attachment from the deployment.
+    * 
+    * @see #setAttachment(String, Object)
+    * 
+    * @param name the name
+    * @return the attachment
+    */
+   Object getAttachment(String name);
+   
+   /**
+    * Get an attachment from the deployment,
+    * uses the expected type as both the name
+    * and to cast the resulting object.
+    * 
+    * @param <T> the expected type
+    * @param expectedType the expected type
+    * @return the attachment
+    * @throws ClassCastException when the object is not of the expected type
+    */
+   <T> T getAttachment(Class<T> expectedType);
+
+   /**
+    * Set an attachment against the deployment. Attachments added to a deployment
+    * are serialized to external clients like admin tools, so the attachment
+    * type should be restricted to jdk types and commonly provided management
+    * related classes.
+    * 
+    * @param name the name
+    * @param attachment the attachment, pass null to remove an attachment
+    * @throws IllegalArgumentException for a null name
+    */
+   void setAttachment(String name, Object attachment);
 }

Modified: projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/ManagedDeploymentImpl.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/ManagedDeploymentImpl.java	2009-02-26 18:59:00 UTC (rev 84818)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/ManagedDeploymentImpl.java	2009-02-26 19:20:14 UTC (rev 84819)
@@ -61,7 +61,9 @@
    private Map<String, ManagedComponent> components = new HashMap<String, ManagedComponent>();
    /** The child deployemnts */
    private List<ManagedDeployment> children = new ArrayList<ManagedDeployment>();
-   
+   /** The attachments map */
+   private transient Map<String, Object> attachments;
+
    public ManagedDeploymentImpl(String name, String simpleName, DeploymentPhase phase,
          ManagedDeployment parent, Map<String, ManagedObject> unitMOs)
    {
@@ -181,6 +183,30 @@
       return unitMOs.get(name);
    }
 
+   public <T> T getAttachment(Class<T> expectedType)
+   {
+      T tvalue = null;
+      Object value = getAttachment(expectedType.getName());
+      if(value != null)
+         tvalue = expectedType.cast(value);
+      return tvalue;
+   }
+
+   public Object getAttachment(String name)
+   {
+      Object value = null;
+      if(attachments != null)
+         value = attachments.get(name);
+      return value;
+   }
+
+   public synchronized void setAttachment(String name, Object attachment)
+   {
+      if(attachments == null)
+         attachments = new HashMap<String, Object>();
+      attachments.put(name, attachment);
+   }
+
    public String toString()
    {
       StringBuilder tmp = new StringBuilder(super.toString());




More information about the jboss-cvs-commits mailing list