[Jboss-cvs] JBossAS SVN: r56906 - in projects/microcontainer/trunk/deployers/src: main/org/jboss/deployers/plugins/deployer main/org/jboss/deployers/plugins/deployers/helpers main/org/jboss/deployers/plugins/deployers/kernel main/org/jboss/deployers/spi/deployer tests/org/jboss/test/deployers/bean/test

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Sep 16 06:18:40 EDT 2006


Author: adrian at jboss.org
Date: 2006-09-16 06:18:25 -0400 (Sat, 16 Sep 2006)
New Revision: 56906

Added:
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractComponentDeployer.java
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractSimpleRealDeployer.java
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractTypedDeployer.java
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/SimpleDeploymentVisitor.java
Removed:
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/KernelDeployer.java
Modified:
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractParsingDeployer.java
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractRealDeployer.java
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/SchemaResolverDeployer.java
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/BeanDeployer.java
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/BeanMetaDataDeployer.java
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/KernelDeploymentDeployer.java
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/Deployer.java
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java
   projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/bean/test/BeanDeployerUnitTestCase.java
Log:
[JBMICROCONT-5] - Rework some of the plumbing in the deployers.
Less plumbing in the deployment implementations means less errors.

Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java	2006-09-16 04:24:24 UTC (rev 56905)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java	2006-09-16 10:18:25 UTC (rev 56906)
@@ -23,8 +23,10 @@
 
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.jboss.deployers.plugins.attachments.AbstractAttachments;
 import org.jboss.deployers.plugins.structure.ComponentDeploymentContext;
@@ -193,6 +195,23 @@
       return deploymentContext.getTransientManagedObjects();
    }
 
+   @SuppressWarnings("unchecked")
+   // TODO optimize
+   public <T> Set<? extends T> getAllMetaData(Class<T> type)
+   {
+      if (type == null)
+         throw new IllegalArgumentException("Null type");
+      
+      Set<T> result = new HashSet<T>();
+      Map<String, Object> attachments = getAttachments();
+      for (Object object : attachments.values())
+      {
+         if (type.isInstance(object))
+            result.add((T) object);
+      }
+      return result;
+   }
+
    @Deprecated
    public DeploymentContext getDeploymentContext()
    {

Added: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractComponentDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractComponentDeployer.java	2006-09-16 04:24:24 UTC (rev 56905)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractComponentDeployer.java	2006-09-16 10:18:25 UTC (rev 56906)
@@ -0,0 +1,106 @@
+/*
+* 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.deployers.plugins.deployers.helpers;
+
+import java.util.Set;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
+
+/**
+ * AbstractComponentDeployer.
+ * 
+ * @param <D> the deployment type
+ * @param <C> the component type
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractComponentDeployer<D, C> extends AbstractRealDeployer<D>
+{
+   /** The component visitor */
+   private SimpleDeploymentVisitor<C> visitor;
+
+   /** The component type */
+   private Class<C> componentType;
+
+   public int getRelativeOrder()
+   {
+      return COMPONENT_DEPLOYER;
+   }
+   
+   /**
+    * Set the component visitor
+    * 
+    * @param visitor the visitor
+    * @throws IllegalArgumentException if the visitor is null
+    */
+   protected void setComponentVisitor(SimpleDeploymentVisitor<C> visitor)
+   {
+      if (visitor == null)
+         throw new IllegalArgumentException("Null visitor");
+      this.visitor = visitor;
+      componentType = visitor.getVisitorType();
+      if (componentType == null)
+         throw new IllegalArgumentException("Null visitor type");
+   }
+
+   public void deploy(DeploymentUnit unit) throws DeploymentException
+   {
+      super.deploy(unit);
+      
+      try
+      {
+         deployComponents(unit);
+      }
+      catch (Throwable t)
+      {
+         undeployComponents(unit);
+         throw DeploymentException.rethrowAsDeploymentException("Error deploying: " + unit.getName(), t);
+      }
+   }
+   
+   public void undeploy(DeploymentUnit unit)
+   {
+      super.undeploy(unit);
+      undeployComponents(unit);
+   }
+
+   protected void deployComponents(DeploymentUnit unit) throws DeploymentException
+   {
+      if (visitor == null)
+         return;
+
+      Set<? extends C> components = unit.getAllMetaData(componentType);
+      for (C component : components)
+         visitor.deploy(unit, component);
+   }
+   
+   protected void undeployComponents(DeploymentUnit unit)
+   {
+      if (visitor == null)
+         return;
+      
+      Set<? extends C> components = unit.getAllMetaData(componentType);
+      for (C component : components)
+         visitor.undeploy(unit, component);
+   }
+}

Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractParsingDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractParsingDeployer.java	2006-09-16 04:24:24 UTC (rev 56905)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractParsingDeployer.java	2006-09-16 10:18:25 UTC (rev 56906)
@@ -23,7 +23,6 @@
 
 import java.util.List;
 
-import org.jboss.deployers.plugins.deployer.AbstractSimpleDeployer;
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.deployer.DeploymentUnit;
 import org.jboss.virtual.VirtualFile;
@@ -35,38 +34,23 @@
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @version $Revision: 1.1 $
  */
-public abstract class AbstractParsingDeployer<T> extends AbstractSimpleDeployer
+public abstract class AbstractParsingDeployer<T> extends AbstractTypedDeployer<T>
 {
-   /** The expected type */
-   private final Class<T> expectedType;
-   
    /**
     * Create a new AbstractParsingDeployer.
     * 
-    * @param expectedType the expected type
-    * @throws IllegalArgumentException if the expected type is null
+    * @param deploymentType the deployment type
+    * @throws IllegalArgumentException if the deployment type is null
     */
-   protected AbstractParsingDeployer(Class<T> expectedType)
+   protected AbstractParsingDeployer(Class<T> deploymentType)
    {
-      if (expectedType == null)
-         throw new IllegalArgumentException("Null expectedType");
-      this.expectedType = expectedType;
+      super(deploymentType);
    }
 
    public int getRelativeOrder()
    {
       return PARSER_DEPLOYER;
    }
-
-   /**
-    * Get the expected type
-    * 
-    * @return the expected type
-    */
-   protected Class<T> getExpectedType()
-   {
-      return expectedType;
-   }
    
    /**
     * Get some meta data
@@ -77,7 +61,7 @@
     */
    protected T getMetaData(DeploymentUnit unit, String key)
    {
-      return unit.getAttachment(key, expectedType);
+      return unit.getAttachment(key, getDeploymentType());
    }
    
    /**
@@ -90,7 +74,7 @@
     */
    protected void createMetaData(DeploymentUnit unit, String name, String suffix) throws DeploymentException
    {
-      createMetaData(unit, name, suffix, expectedType.getName());
+      createMetaData(unit, name, suffix, getDeploymentType().getName());
    }
    
    /**
@@ -127,7 +111,7 @@
          return;
       
       // Register it
-      unit.getTransientManagedObjects().addAttachment(key, result, expectedType);
+      unit.getTransientManagedObjects().addAttachment(key, result, getDeploymentType());
    }
 
    /**

Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractRealDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractRealDeployer.java	2006-09-16 04:24:24 UTC (rev 56905)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractRealDeployer.java	2006-09-16 10:18:25 UTC (rev 56906)
@@ -21,57 +21,83 @@
 */
 package org.jboss.deployers.plugins.deployers.helpers;
 
-import java.util.HashSet;
-import java.util.Map;
 import java.util.Set;
 
 import org.jboss.deployers.plugins.deployer.AbstractSimpleDeployer;
+import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.deployer.DeploymentUnit;
 
 /**
  * AbstractRealDeployer.
  * 
- * @param <T> the expected type
+ * @param <T> the deployment type
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @version $Revision: 1.1 $
  */
 public abstract class AbstractRealDeployer<T> extends AbstractSimpleDeployer
 {
-   /** The expected type */
-   private Class<T> expectedType;
+   /** The visitor */
+   private SimpleDeploymentVisitor<T> visitor;
 
-   /**
-    * Create a new AbstractRealDeployer.
-    * 
-    * @param expectedType the expected type
-    * @throws IllegalArgumentException if the expected type is null
-    */
-   public AbstractRealDeployer(Class<T> expectedType)
+   /** The deployment type */
+   private Class<T> deploymentType;
+
+   /** Whether the warning has been displayed */
+   private boolean warned;
+
+   public int getRelativeOrder()
    {
-      if (expectedType == null)
-         throw new IllegalArgumentException("Null expectedType");
-      this.expectedType = expectedType;
+      return REAL_DEPLOYER;
    }
-   
+
    /**
-    * Get all the metadata for the expected type
+    * Set the deployment visitor
     * 
-    * @param unit the unit
-    * @return a set of metadata matching the type
+    * @param visitor the visitor
+    * @throws IllegalArgumentException if the visitor is null
     */
-   @SuppressWarnings("unchecked")
-   protected Set<T> getAllMetaData(DeploymentUnit unit)
+   protected void setDeploymentVisitor(SimpleDeploymentVisitor<T> visitor)
    {
-      if (unit == null)
-         throw new IllegalArgumentException("Null unit");
-      
-      Set<T> result = new HashSet<T>();
-      Map<String, Object> attachments = unit.getAttachments();
-      for (Object object : attachments.values())
+      if (visitor == null)
+         throw new IllegalArgumentException("Null visitor");
+      this.visitor = visitor;
+      deploymentType = visitor.getVisitorType();
+      if (deploymentType == null)
+         throw new IllegalArgumentException("Null visitor type");
+   }
+
+   public void deploy(DeploymentUnit unit) throws DeploymentException
+   {
+      if (visitor == null)
       {
-         if (expectedType.isInstance(object))
-            result.add((T) object);
+         if (warned == false)
+         {
+            log.error("INTERNAL ERROR: Visitor is null for " + getClass().getName());
+            warned = true;
+         }
+         return;
       }
-      return result;
+
+      try
+      {
+         Set<? extends T> deployments = unit.getAllMetaData(deploymentType);
+         for (T deployment : deployments)
+            visitor.deploy(unit, deployment);
+      }
+      catch (Throwable t)
+      {
+         undeploy(unit);
+         throw DeploymentException.rethrowAsDeploymentException("Error deploying: " + unit.getName(), t);
+      }
    }
+
+   public void undeploy(DeploymentUnit unit)
+   {
+      if (visitor == null)
+         return;
+      Set<? extends T> deployments = unit.getAllMetaData(deploymentType);
+      for (T deployment : deployments)
+         visitor.undeploy(unit, deployment);
+   }
+
 }

Added: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractSimpleRealDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractSimpleRealDeployer.java	2006-09-16 04:24:24 UTC (rev 56905)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractSimpleRealDeployer.java	2006-09-16 10:18:25 UTC (rev 56906)
@@ -0,0 +1,69 @@
+/*
+* 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.deployers.plugins.deployers.helpers;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
+
+/**
+ * AbstractSimpleRealDeployer.
+ * 
+ * @param <T> the deployment type
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractSimpleRealDeployer<T> extends AbstractTypedDeployer<T>
+{
+   /**
+    * Create a new AbstractSimpleRealDeployer.
+    * 
+    * @param deploymentType the deployment type
+    * @throws IllegalArgumentException for a null deployment type
+    */
+   public AbstractSimpleRealDeployer(Class<T> deploymentType)
+   {
+      super(deploymentType);
+   }
+
+   public int getRelativeOrder()
+   {
+      return REAL_DEPLOYER;
+   }
+   
+   public void deploy(DeploymentUnit unit) throws DeploymentException
+   {
+      T deployment = unit.getAttachment(getDeploymentType());
+      if (deployment != null)
+         deploy(unit, deployment);
+   }
+
+   public void undeploy(DeploymentUnit unit)
+   {
+      T deployment = unit.getAttachment(getDeploymentType());
+      if (deployment != null)
+         undeploy(unit, deployment);
+   }
+   
+   public abstract void deploy(DeploymentUnit unit, T deployment) throws DeploymentException;
+
+   public abstract void undeploy(DeploymentUnit unit, T deployment);
+}

Added: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractTypedDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractTypedDeployer.java	2006-09-16 04:24:24 UTC (rev 56905)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractTypedDeployer.java	2006-09-16 10:18:25 UTC (rev 56906)
@@ -0,0 +1,60 @@
+/*
+* 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.deployers.plugins.deployers.helpers;
+
+import org.jboss.deployers.plugins.deployer.AbstractSimpleDeployer;
+
+/**
+ * AbstractTypedDeployer.
+ * 
+ * @param <T> the deployment type
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractTypedDeployer<T> extends AbstractSimpleDeployer
+{
+   /** The deployment type */
+   private Class<T> deploymentType;
+
+   /**
+    * Create a new AbstractTypedDeployer.
+    * 
+    * @param deploymentType the deployment type
+    * @throws IllegalArgumentException for a null deployment type
+    */
+   public AbstractTypedDeployer(Class<T> deploymentType)
+   {
+      if (deploymentType == null)
+         throw new IllegalArgumentException("Null deploymentType");
+      this.deploymentType = deploymentType;
+   }
+
+   /**
+    * Get the deployment type
+    * 
+    * @return the type
+    */
+   protected Class<T> getDeploymentType()
+   {
+      return deploymentType;
+   }
+}

Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/SchemaResolverDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/SchemaResolverDeployer.java	2006-09-16 04:24:24 UTC (rev 56905)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/SchemaResolverDeployer.java	2006-09-16 10:18:25 UTC (rev 56906)
@@ -49,12 +49,12 @@
    /**
     * Create a new SchemaResolverDeployer.
     * 
-    * @param expectedType the expected type
-    * @throws IllegalArgumentException if the expected type is null
+    * @param deploymentType the deployment type
+    * @throws IllegalArgumentException for a null deployment type
     */
-   public SchemaResolverDeployer(Class<T> expectedType)
+   public SchemaResolverDeployer(Class<T> deploymentType)
    {
-      super(expectedType);
+      super(deploymentType);
    }
 
    /**
@@ -90,6 +90,6 @@
       if (parsed == null)
          throw new DeploymentException("The xml " + file.getPathName() + " is not well formed!");
 
-      return getExpectedType().cast(parsed);
+      return getDeploymentType().cast(parsed);
    }
 }

Added: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/SimpleDeploymentVisitor.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/SimpleDeploymentVisitor.java	2006-09-16 04:24:24 UTC (rev 56905)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/SimpleDeploymentVisitor.java	2006-09-16 10:18:25 UTC (rev 56906)
@@ -0,0 +1,59 @@
+/*
+* 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.deployers.plugins.deployers.helpers;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
+
+/**
+ * SimpleDeploymentVisitor.
+ * 
+ * @param <T> the deployment type
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface SimpleDeploymentVisitor<T>
+{
+   /**
+    * Get the visitor type
+    * 
+    * @return the visitor type
+    */
+   Class<T> getVisitorType();
+   
+   /**
+    * Deploy the deployment
+    * 
+    * @param unit the deployment unit
+    * @param deployment the deployment
+    * @throws DeploymentException the deployment exception
+    */
+   void deploy(DeploymentUnit unit, T deployment) throws DeploymentException;
+   
+   /**
+    * Undeploy the deployment
+    * 
+    * @param unit the deployment unit
+    * @param deployment the deployment
+    */
+   void undeploy(DeploymentUnit unit, T deployment);
+}

Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/BeanDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/BeanDeployer.java	2006-09-16 04:24:24 UTC (rev 56905)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/BeanDeployer.java	2006-09-16 10:18:25 UTC (rev 56906)
@@ -31,10 +31,8 @@
  * BeanDeployer.<p>
  * 
  * This deployer is responsible for looking for -beans.xml
- * and creating the metadata object.<p>
+ * and creating the metadata object.
  * 
- * The {@link KernelDeployer} does the real work of deployment.
- * 
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @version $Revision: 1.1 $
  */

Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/BeanMetaDataDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/BeanMetaDataDeployer.java	2006-09-16 04:24:24 UTC (rev 56905)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/BeanMetaDataDeployer.java	2006-09-16 10:18:25 UTC (rev 56906)
@@ -21,10 +21,8 @@
 */
 package org.jboss.deployers.plugins.deployers.kernel;
 
-import java.util.Set;
-
 import org.jboss.beans.metadata.spi.BeanMetaData;
-import org.jboss.deployers.plugins.deployers.helpers.AbstractRealDeployer;
+import org.jboss.deployers.plugins.deployers.helpers.AbstractSimpleRealDeployer;
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.deployer.DeploymentUnit;
 import org.jboss.kernel.Kernel;
@@ -33,15 +31,15 @@
 import org.jboss.kernel.spi.dependency.KernelControllerContext;
 
 /**
- * KernelDeployer.<p>
+ * BeanMetaDataDeployer.<p>
  * 
  * This deployer is responsible for deploying all metadata of
- * type {@link org.jboss.kernel.spi.deployment.KernelDeployment}.
+ * type {@link org.jboss.beans.metadata.spi.BeanMetaData}.
  * 
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @version $Revision: 1.1 $
  */
-public class BeanMetaDataDeployer extends AbstractRealDeployer<BeanMetaData>
+public class BeanMetaDataDeployer extends AbstractSimpleRealDeployer<BeanMetaData>
 {
    /** The kernel controller */
    private final KernelController controller;
@@ -60,29 +58,22 @@
       controller = kernel.getController();
    }
 
-   public void deploy(DeploymentUnit unit) throws DeploymentException
+   public void deploy(DeploymentUnit unit, BeanMetaData deployment) throws DeploymentException
    {
-      Set<BeanMetaData> beans = getAllMetaData(unit);
-      for (BeanMetaData bean : beans)
-      {
-         KernelControllerContext context = new AbstractKernelControllerContext(null, bean, null);
+      KernelControllerContext context = new AbstractKernelControllerContext(null, deployment, null);
 
-         try
-         {
-            controller.install(context);
-         }
-         catch (Throwable t)
-         {
-            undeploy(unit); // TODO better unwind
-            throw DeploymentException.rethrowAsDeploymentException("Error deploying: " + bean.getName(), t);
-         }
+      try
+      {
+         controller.install(context);
       }
+      catch (Throwable t)
+      {
+         throw DeploymentException.rethrowAsDeploymentException("Error deploying: " + deployment.getName(), t);
+      }
    }
 
-   public void undeploy(DeploymentUnit unit)
+   public void undeploy(DeploymentUnit unit, BeanMetaData deployment)
    {
-      Set<BeanMetaData> beans = getAllMetaData(unit);
-      for (BeanMetaData bean : beans)
-         controller.uninstall(bean.getName());
+      controller.uninstall(deployment.getName());
    }
 }

Deleted: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/KernelDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/KernelDeployer.java	2006-09-16 04:24:24 UTC (rev 56905)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/KernelDeployer.java	2006-09-16 10:18:25 UTC (rev 56906)
@@ -1,84 +0,0 @@
-/*
-* 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.deployers.plugins.deployers.kernel;
-
-import java.util.Set;
-
-import org.jboss.deployers.plugins.deployers.helpers.AbstractRealDeployer;
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.DeploymentUnit;
-import org.jboss.kernel.Kernel;
-import org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer;
-import org.jboss.kernel.spi.deployment.KernelDeployment;
-
-/**
- * KernelDeployer.<p>
- * 
- * This deployer is responsible for deploying all metadata of
- * type {@link org.jboss.kernel.spi.deployment.KernelDeployment}.
- * 
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class KernelDeployer extends AbstractRealDeployer<KernelDeployment>
-{
-   /** The kernel deployer */
-   private final BasicXMLDeployer deployer;
-   
-   /**
-    * Create a new BeanDeployer.
-    * 
-    * @param kernel the kernel
-    * @throws IllegalArgumentException for a null kernel
-    */
-   public KernelDeployer(Kernel kernel)
-   {
-      super(KernelDeployment.class);
-      if (kernel == null)
-         throw new IllegalArgumentException("Null kernel");
-      deployer = new BasicXMLDeployer(kernel);
-   }
-
-   public void deploy(DeploymentUnit unit) throws DeploymentException
-   {
-      Set<KernelDeployment> deployments = getAllMetaData(unit);
-      for (KernelDeployment deployment : deployments)
-      {
-         try
-         {
-            deployer.deploy(deployment);
-         }
-         catch (Throwable t)
-         {
-            undeploy(unit); // TODO better unwind
-            throw DeploymentException.rethrowAsDeploymentException("Error deploying: " + deployment.getName(), t);
-         }
-      }
-   }
-
-   public void undeploy(DeploymentUnit unit)
-   {
-      Set<KernelDeployment> deployments = getAllMetaData(unit);
-      for (KernelDeployment deployment : deployments)
-         deployer.undeploy(deployment);
-   }
-}

Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/KernelDeploymentDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/KernelDeploymentDeployer.java	2006-09-16 04:24:24 UTC (rev 56905)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/KernelDeploymentDeployer.java	2006-09-16 10:18:25 UTC (rev 56906)
@@ -22,22 +22,23 @@
 package org.jboss.deployers.plugins.deployers.kernel;
 
 import java.util.List;
-import java.util.Set;
 
 import org.jboss.beans.metadata.spi.BeanMetaData;
-import org.jboss.deployers.plugins.deployers.helpers.AbstractRealDeployer;
+import org.jboss.deployers.plugins.deployers.helpers.AbstractComponentDeployer;
+import org.jboss.deployers.plugins.deployers.helpers.SimpleDeploymentVisitor;
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.deployer.DeploymentUnit;
 import org.jboss.kernel.spi.deployment.KernelDeployment;
 
-public class KernelDeploymentDeployer extends AbstractRealDeployer<KernelDeployment>
+public class KernelDeploymentDeployer extends AbstractComponentDeployer<KernelDeployment, BeanMetaData>
 {
    /**
     * Create a new KernelDeploymentDeployer.
     */
    public KernelDeploymentDeployer()
    {
-      super(KernelDeployment.class);
+      setDeploymentVisitor(new KernelDeploymentVisitor());
+      setComponentVisitor(new BeanMetaDataVisitor());
    }
 
    public int getRelativeOrder()
@@ -45,28 +46,60 @@
       return COMPONENT_DEPLOYER;
    }
 
-   public void deploy(DeploymentUnit unit) throws DeploymentException
+   protected static void addBeanComponent(DeploymentUnit unit, BeanMetaData bean)
    {
-      Set<KernelDeployment> deployments = getAllMetaData(unit);
-      for (KernelDeployment deployment : deployments)
+      DeploymentUnit component = unit.addComponent(bean.getName());
+      component.addAttachment(BeanMetaData.class.getName(), bean);
+   }
+
+   protected static void removeBeanComponent(DeploymentUnit unit, BeanMetaData bean)
+   {
+      unit.removeComponent(bean.getName());
+   }
+   
+   /**
+    * KernelDeploymentVisitor.
+    */
+   public static class KernelDeploymentVisitor implements SimpleDeploymentVisitor<KernelDeployment>
+   {
+      public Class<KernelDeployment> getVisitorType()
       {
+         return KernelDeployment.class;
+      }
+
+      public void deploy(DeploymentUnit unit, KernelDeployment deployment) throws DeploymentException
+      {
          List<BeanMetaData> beans = deployment.getBeans();
          for (BeanMetaData bean : beans)
-         {
-            DeploymentUnit component = unit.addComponent(bean.getName());
-            component.addAttachment(BeanMetaData.class.getName(), bean);
-         }
+            addBeanComponent(unit, bean);
       }
-   }
 
-   public void undeploy(DeploymentUnit unit)
-   {
-      Set<KernelDeployment> deployments = getAllMetaData(unit);
-      for (KernelDeployment deployment : deployments)
+      public void undeploy(DeploymentUnit unit, KernelDeployment deployment)
       {
          List<BeanMetaData> beans = deployment.getBeans();
          for (BeanMetaData bean : beans)
-            unit.removeComponent(bean.getName());
+            removeBeanComponent(unit, bean);
       }
    }
+
+   /**
+    * BeanMetaDataVisitor.
+    */
+   public static class BeanMetaDataVisitor implements SimpleDeploymentVisitor<BeanMetaData>
+   {
+      public Class<BeanMetaData> getVisitorType()
+      {
+         return BeanMetaData.class;
+      }
+
+      public void deploy(DeploymentUnit unit, BeanMetaData deployment) throws DeploymentException
+      {
+         addBeanComponent(unit, deployment);
+      }
+
+      public void undeploy(DeploymentUnit unit, BeanMetaData deployment)
+      {
+         removeBeanComponent(unit, deployment);
+      }
+   }
 }

Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/Deployer.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/Deployer.java	2006-09-16 04:24:24 UTC (rev 56905)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/Deployer.java	2006-09-16 10:18:25 UTC (rev 56906)
@@ -43,6 +43,9 @@
 
    /** The component order */
    public static final int COMPONENT_DEPLOYER = 4000;
+
+   /** The real order */
+   public static final int REAL_DEPLOYER = 10000;
    
    /**
     * Whether the deployer is relevant for this unit

Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java	2006-09-16 04:24:24 UTC (rev 56905)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java	2006-09-16 10:18:25 UTC (rev 56906)
@@ -22,6 +22,7 @@
 package org.jboss.deployers.spi.deployer;
 
 import java.util.List;
+import java.util.Set;
 
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.attachments.Attachments;
@@ -91,6 +92,17 @@
    Attachments getTransientManagedObjects();
    
    /**
+    * Get all the metadata for the expected type
+    * 
+    * @param <T> the type to get
+    * @param unit the unit
+    * @param type the type
+    * @return a set of metadata matching the type
+    * @throws IllegalArgumentException if the type is null 
+    */
+   <T> Set<? extends T> getAllMetaData(Class<T> type);
+
+   /**
     * Add a component
     * 
     * @param name the name

Modified: projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/bean/test/BeanDeployerUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/bean/test/BeanDeployerUnitTestCase.java	2006-09-16 04:24:24 UTC (rev 56905)
+++ projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/bean/test/BeanDeployerUnitTestCase.java	2006-09-16 10:18:25 UTC (rev 56906)
@@ -25,7 +25,8 @@
 import junit.framework.TestSuite;
 
 import org.jboss.deployers.plugins.deployers.kernel.BeanDeployer;
-import org.jboss.deployers.plugins.deployers.kernel.KernelDeployer;
+import org.jboss.deployers.plugins.deployers.kernel.BeanMetaDataDeployer;
+import org.jboss.deployers.plugins.deployers.kernel.KernelDeploymentDeployer;
 import org.jboss.deployers.plugins.deployment.MainDeployerImpl;
 import org.jboss.deployers.plugins.structure.vfs.file.FileStructure;
 import org.jboss.deployers.plugins.structure.vfs.jar.JARStructure;
@@ -73,9 +74,11 @@
          main.addStructureDeployer(new FileStructure());
          
          BeanDeployer beanDeployer = new BeanDeployer();
-         KernelDeployer kernelDeployer = new KernelDeployer(kernel);
+         KernelDeploymentDeployer kernelDeploymentDeployer = new KernelDeploymentDeployer();
+         BeanMetaDataDeployer beanMetaDataDeployer = new BeanMetaDataDeployer(kernel);
          main.addDeployer(beanDeployer);
-         main.addDeployer(kernelDeployer);
+         main.addDeployer(kernelDeploymentDeployer);
+         main.addDeployer(beanMetaDataDeployer);
       }
       catch (Throwable t)
       {




More information about the jboss-cvs-commits mailing list