[jboss-cvs] JBossAS SVN: r67198 - in projects/microcontainer/trunk: container/src/main/org/jboss/metadata/plugins/loader and 25 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Nov 16 14:53:14 EST 2007


Author: alesj
Date: 2007-11-16 14:53:14 -0500 (Fri, 16 Nov 2007)
New Revision: 67198

Added:
   projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/file/FileMatcher.java
Modified:
   projects/microcontainer/trunk/container/src/main/org/jboss/metadata/plugins/context/AbstractMetaDataContext.java
   projects/microcontainer/trunk/container/src/main/org/jboss/metadata/plugins/context/CachingMetaDataContext.java
   projects/microcontainer/trunk/container/src/main/org/jboss/metadata/plugins/loader/AbstractMetaDataLoader.java
   projects/microcontainer/trunk/container/src/main/org/jboss/metadata/spi/retrieval/MetaDataRetrieval.java
   projects/microcontainer/trunk/container/src/main/org/jboss/metadata/spi/retrieval/MetaDataRetrievalToMetaDataBridge.java
   projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/retrieval/support/TestMetaDataRetrieval.java
   projects/microcontainer/trunk/deployers-client-spi/src/main/org/jboss/deployers/client/spi/DeployerClient.java
   projects/microcontainer/trunk/deployers-client-spi/src/main/org/jboss/deployers/client/spi/IncompleteDeploymentException.java
   projects/microcontainer/trunk/deployers-client-spi/src/main/org/jboss/deployers/client/spi/IncompleteDeployments.java
   projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployersImpl.java
   projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/main/MainDeployerImpl.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/AbstractDeployerTest.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/test/MockClassLoaderDependenciesUnitTestCase.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDescribeDeployer.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestFlowDeployer.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestSimpleDeployer.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestSimpleDeployer2.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestSimpleDeployer3.java
   projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/Deployers.java
   projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractComponentDeployer.java
   projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractOptionalRealDeployer.java
   projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractRealDeployer.java
   projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractRealDeployerWithInput.java
   projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractSimpleRealDeployer.java
   projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/DeploymentContext.java
   projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/DeploymentUnit.java
   projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java
   projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentUnit.java
   projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractStructuralDeployers.java
   projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContext.java
   projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/AbstractVFSRealDeployer.java
   projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/StructureDeployer.java
   projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/VFSStructuralDeployers.java
   projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/AbstractCandidateStructureVisitor.java
   projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/BeanMetaDataDeployer.java
   projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/StructureDeployerWrapper.java
   projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/VFSStructuralDeployersImpl.java
   projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/explicit/DeclaredStructure.java
   projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/file/FileStructure.java
   projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/jar/JARStructure.java
   projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/war/WARStructure.java
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/ear/support/MockEarStructureDeployer.java
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/jar/test/CombinedJARStructureUnitTestCase.java
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/war/test/CombinedWARStructureUnitTestCase.java
   projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/deployers/OSGiStructure.java
Log:
Work on 187, 188, 218, .bsh, StructureDeployer.
TODO tests (see forum thread)!

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/metadata/plugins/context/AbstractMetaDataContext.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/metadata/plugins/context/AbstractMetaDataContext.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/metadata/plugins/context/AbstractMetaDataContext.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -39,6 +39,7 @@
 import org.jboss.metadata.spi.retrieval.cummulative.CummulativeMetaDatasItem;
 import org.jboss.metadata.spi.scope.Scope;
 import org.jboss.metadata.spi.scope.ScopeKey;
+import org.jboss.metadata.spi.scope.ScopeLevel;
 import org.jboss.metadata.spi.signature.Signature;
 
 /**
@@ -300,4 +301,26 @@
       }
       return (parent == null || parent.isEmpty());
    }
+
+   public MetaDataRetrieval getScopedRetrieval(ScopeLevel level)
+   {
+      List<MetaDataRetrieval> matchingRetrievals = new ArrayList<MetaDataRetrieval>();
+      List<MetaDataRetrieval> localRetrievals = getLocalRetrievals();
+      for (MetaDataRetrieval localRetrieval : localRetrievals)
+      {
+         ScopeKey scopeKey = localRetrieval.getScope();
+         if (scopeKey.getScopeLevel(level) != null)
+            matchingRetrievals.add(localRetrieval);
+      }
+
+      if (matchingRetrievals.isEmpty() == false)
+      {
+         if (matchingRetrievals.size() > 1)
+            return new AbstractMetaDataContext(null, matchingRetrievals);
+         else
+            return matchingRetrievals.get(0);
+      }
+
+      return null;
+   }
 }

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/metadata/plugins/context/CachingMetaDataContext.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/metadata/plugins/context/CachingMetaDataContext.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/metadata/plugins/context/CachingMetaDataContext.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -34,6 +34,7 @@
 import org.jboss.metadata.spi.retrieval.MetaDataRetrieval;
 import org.jboss.metadata.spi.retrieval.MetaDatasItem;
 import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.metadata.spi.scope.ScopeLevel;
 
 /**
  * CachingMetaDataContext.
@@ -56,6 +57,7 @@
    /** All meta data */
    private volatile MetaDatasItem cachedMetaDatasItem;
 
+   /** Cached components */
    private volatile Map<Signature, MetaDataRetrieval> cachedComponents;
    
    /** The valid time */
@@ -64,6 +66,12 @@
    /** Is empty */
    private volatile Boolean empty;
 
+   /** The scoped context */
+   private volatile MetaDataRetrieval scopedContext;
+
+   /** Was scoped context check done */
+   private volatile boolean scopedRetrievalExecuted;
+
    /**
     * Create a new CachingMetaDataContext.
     * 
@@ -279,4 +287,14 @@
          empty = super.isEmpty();
       return empty; 
    }
+
+   public MetaDataRetrieval getScopedRetrieval(ScopeLevel level)
+   {
+      if (cachedComponents == null || scopedRetrievalExecuted == false)
+      {
+         scopedRetrievalExecuted = true;
+         scopedContext = super.getScopedRetrieval(level);
+      }
+      return scopedContext;
+   }
 }

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/metadata/plugins/loader/AbstractMetaDataLoader.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/metadata/plugins/loader/AbstractMetaDataLoader.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/metadata/plugins/loader/AbstractMetaDataLoader.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -28,11 +28,13 @@
 import org.jboss.metadata.spi.retrieval.AnnotationsItem;
 import org.jboss.metadata.spi.retrieval.Item;
 import org.jboss.metadata.spi.retrieval.MetaDataItem;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrieval;
 import org.jboss.metadata.spi.retrieval.MetaDatasItem;
 import org.jboss.metadata.spi.retrieval.ValidTime;
 import org.jboss.metadata.spi.retrieval.helper.AnnotationToMetaDataBridge;
 import org.jboss.metadata.spi.retrieval.helper.AnnotationsToMetaDatasBridge;
 import org.jboss.metadata.spi.scope.ScopeKey;
+import org.jboss.metadata.spi.scope.ScopeLevel;
 
 /**
  * AbstractMetaDataLoader.
@@ -113,6 +115,14 @@
       return new AnnotationsToMetaDatasBridge(annotations);
    }
 
+   public MetaDataRetrieval getScopedRetrieval(ScopeLevel level)
+   {
+      if (getScope().getScopeLevel(level) != null)
+         return this;
+
+      return null;
+   }
+
    /**
     * Invalidate
     */

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/metadata/spi/retrieval/MetaDataRetrieval.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/metadata/spi/retrieval/MetaDataRetrieval.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/metadata/spi/retrieval/MetaDataRetrieval.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -24,6 +24,7 @@
 import java.lang.annotation.Annotation;
 
 import org.jboss.metadata.spi.scope.ScopeKey;
+import org.jboss.metadata.spi.scope.ScopeLevel;
 import org.jboss.metadata.spi.signature.Signature;
 
 /**
@@ -116,4 +117,12 @@
     * @return true if metadata empty
     */
    boolean isEmpty();
+
+   /**
+    * Get scoped retrieval for level param.
+    *
+    * @param level the scope level
+    * @return list of retrieval instances
+    */
+   MetaDataRetrieval getScopedRetrieval(ScopeLevel level);
 }

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/metadata/spi/retrieval/MetaDataRetrievalToMetaDataBridge.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/metadata/spi/retrieval/MetaDataRetrievalToMetaDataBridge.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/metadata/spi/retrieval/MetaDataRetrievalToMetaDataBridge.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -22,15 +22,10 @@
 package org.jboss.metadata.spi.retrieval;
 
 import java.lang.annotation.Annotation;
-import java.util.List;
-import java.util.ArrayList;
 
 import org.jboss.metadata.spi.MetaData;
-import org.jboss.metadata.spi.context.MetaDataContext;
-import org.jboss.metadata.spi.scope.ScopeKey;
 import org.jboss.metadata.spi.scope.ScopeLevel;
 import org.jboss.metadata.spi.signature.Signature;
-import org.jboss.metadata.plugins.context.AbstractMetaDataContext;
 
 /**
  * MetaDataRetrievalToMetaDataBridge.
@@ -173,22 +168,10 @@
       if (level == null)
          throw new IllegalArgumentException("Null scope level");
 
-      if (retrieval instanceof MetaDataContext)
-      {
-         MetaDataContext context = (MetaDataContext)retrieval;
-         List<MetaDataRetrieval> matchingRetrievals = new ArrayList<MetaDataRetrieval>();
-         List<MetaDataRetrieval> localRetrievals = context.getLocalRetrievals();
-         for (MetaDataRetrieval localRetrieval : localRetrievals)
-         {
-            ScopeKey scopeKey = localRetrieval.getScope();
-            if (scopeKey.getScopeLevel(level) != null)
-               matchingRetrievals.add(localRetrieval);
-         }
-         if (matchingRetrievals.isEmpty() == false)
-            return new MetaDataRetrievalToMetaDataBridge(new AbstractMetaDataContext(context, matchingRetrievals));
-      }
-      else if (retrieval.getScope().getScopeLevel(level) != null)
-         return new MetaDataRetrievalToMetaDataBridge(new AbstractMetaDataContext(retrieval));
+      MetaDataRetrieval scopedRetrieval = retrieval.getScopedRetrieval(level);
+      if (scopedRetrieval != null)
+         return new MetaDataRetrievalToMetaDataBridge(scopedRetrieval);
+
       return null;
    }
 

Modified: projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/retrieval/support/TestMetaDataRetrieval.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/retrieval/support/TestMetaDataRetrieval.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/retrieval/support/TestMetaDataRetrieval.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -102,11 +102,19 @@
 
    public MetaDataRetrieval getComponentMetaDataRetrieval(Signature signature)
    {
+      lastMethod = "getComponentMetaDataRetrieval";
       return null;
    }
 
    public boolean isEmpty()
    {
+      lastMethod = "isEmpty";
       return true;
    }
+
+   public MetaDataRetrieval getScopedRetrieval(ScopeLevel level)
+   {
+      lastMethod = "getScopedRetrieval";
+      return null;
+   }
 }

Modified: projects/microcontainer/trunk/deployers-client-spi/src/main/org/jboss/deployers/client/spi/DeployerClient.java
===================================================================
--- projects/microcontainer/trunk/deployers-client-spi/src/main/org/jboss/deployers/client/spi/DeployerClient.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-client-spi/src/main/org/jboss/deployers/client/spi/DeployerClient.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -85,21 +85,20 @@
    void process();
 
    /**
-    * Deploy a deployment
+    * Deploy the deployments
     * 
-    * @param deployment the deployment
+    * @param deployments the deployments
     * @throws DeploymentException for any error
     */
-   void deploy(Deployment deployment) throws DeploymentException;
+   void deploy(Deployment... deployments) throws DeploymentException;
 
    /**
-    * Undeploy a deployment
+    * Undeploy the deployments
     * 
-    * @param deployment the deployment
-    * @return true when the deployment was undeployed
+    * @param deployments the deployments
     * @throws DeploymentException for any error
     */
-   boolean undeploy(Deployment deployment) throws DeploymentException;
+   void undeploy(Deployment... deployments) throws DeploymentException;
 
    /**
     * Check all the deployments are complete
@@ -109,29 +108,44 @@
    void checkComplete() throws DeploymentException;
 
    /**
-    * Check a single deployment is complete
+    * Check if deployments are complete
     * 
     * @param deployment the deployment
-    * @throws DeploymentException when the deployment is not complete
+    * @throws DeploymentException when some deployments are not complete
     */
-   void checkComplete(Deployment deployment) throws DeploymentException;
+   void checkComplete(Deployment... deployment) throws DeploymentException;
 
    /**
-    * Check a single deployment is complete
+    * Check if deployments are complete
     * 
-    * @param name the deployment name
-    * @throws DeploymentException when the deployment is not complete
+    * @param names the deployment name
+    * @throws DeploymentException when some deployments are not complete
     */
-   void checkComplete(String name) throws DeploymentException;
+   void checkComplete(String... names) throws DeploymentException;
    
    /**
-    * Undeploy a deployment by name
+    * Check if deployments are recognized
+    *
+    * @param deployments the deployments
+    * @throws DeploymentException when some deployments are not recognized
+    */
+   void checkStructureComplete(Deployment... deployments) throws DeploymentException;
+
+   /**
+    * Check if deployments are recognized
+    *
+    * @param names the deployment names
+    * @throws DeploymentException when some deployments are not recognized
+    */
+   void checkStructureComplete(String... names) throws DeploymentException;
+
+   /**
+    * Undeploy a deployments by name
     * 
-    * @param name the name of the deployment
-    * @return true when the deployment was undeployed
+    * @param names the names of the deployments
     * @throws DeploymentException for any error
     */
-   boolean undeploy(String name) throws DeploymentException;
+   void undeploy(String... names) throws DeploymentException;
 
    /**
     * Get a the state of deployment

Modified: projects/microcontainer/trunk/deployers-client-spi/src/main/org/jboss/deployers/client/spi/IncompleteDeploymentException.java
===================================================================
--- projects/microcontainer/trunk/deployers-client-spi/src/main/org/jboss/deployers/client/spi/IncompleteDeploymentException.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-client-spi/src/main/org/jboss/deployers/client/spi/IncompleteDeploymentException.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -21,11 +21,6 @@
 */
 package org.jboss.deployers.client.spi;
 
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
 import org.jboss.deployers.spi.DeploymentException;
 
 /**
@@ -72,86 +67,20 @@
       return incompleteDeployments;
    }
 
-   // TODO JBMICROCONT-188 Some of the calculations done in this method should be done upfront in IncompleteDeployments instead!
    @Override
    public String getMessage()
    {
       StringBuilder buffer = new StringBuilder();
       buffer.append("Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):\n");
-
       // Display all the missing deployers
-      Collection<String> deploymentsMissingDeployers = incompleteDeployments.getDeploymentsMissingDeployer();
-      if (deploymentsMissingDeployers.isEmpty() == false)
-      {
-         buffer.append("\n*** DEPLOYMENTS MISSING DEPLOYERS: Name\n\n");
-         for (String name : deploymentsMissingDeployers)
-            buffer.append(name).append('\n');
-      }
-
+      buffer.append(incompleteDeployments.getDeploymentsMissingDeployerInfo());
       // Display all the incomplete deployments
-      Map<String, Throwable> deploymentsInError = incompleteDeployments.getDeploymentsInError();
-      if (deploymentsInError.isEmpty() == false)
-      {
-         buffer.append("\n*** DEPLOYMENTS IN ERROR: Name -> Error\n\n");
-         for (Map.Entry<String, Throwable> entry : deploymentsInError.entrySet())
-            buffer.append(entry.getKey()).append(" -> ").append(entry.getValue().toString()).append("\n\n");
-      }
-
-      // Popluate the potential root causes
-      Map<String, String> rootCauses = new HashMap<String, String>();
-
-      // Missing dependencies are root causes
-      Map<String, Set<MissingDependency>> contextsMissingDependencies = incompleteDeployments.getContextsMissingDependencies();
-      if (contextsMissingDependencies.isEmpty() == false)
-      {
-         for (Map.Entry<String, Set<MissingDependency>> entry : contextsMissingDependencies.entrySet())
-         {
-            for (MissingDependency dependency : entry.getValue())
-               rootCauses.put(dependency.getDependency(), dependency.getActualState());
-         }
-      }
-
-      // Errors are root causes
-      Map<String, Throwable> contextsInError = incompleteDeployments.getContextsInError();
-      if (contextsInError.isEmpty() == false)
-      {
-         for (Map.Entry<String, Throwable> entry : contextsInError.entrySet())
-         {
-            Throwable t = entry.getValue();
-            if (t == null)
-               rootCauses.put(entry.getKey(), "** UNKNOWN ERROR **");
-            else
-               rootCauses.put(entry.getKey(), t.toString());
-         }
-      }
-
+      buffer.append(incompleteDeployments.getDeploymentsInErrorInfo());
       // Display all the missing dependencies
-      if (contextsMissingDependencies.isEmpty() == false)
-      {
-         buffer.append("\n*** CONTEXTS MISSING DEPENDENCIES: Name -> Dependency{Required State:Actual State}\n\n");
-         for (Map.Entry<String, Set<MissingDependency>> entry : contextsMissingDependencies.entrySet())
-         {
-            String name = entry.getKey();
-            buffer.append(name).append("\n");
-            for (MissingDependency dependency : entry.getValue())
-            {
-               buffer.append(" -> ").append(dependency.getDependency());
-               buffer.append('{').append(dependency.getRequiredState());
-               buffer.append(':').append(dependency.getActualState()).append("}");
-               buffer.append("\n");
-            }
-            buffer.append('\n');
-            
-            // It is not a root cause if it has missing dependencies
-            rootCauses.remove(name);
-         }
-      }
-      if (rootCauses.isEmpty() == false)
-      {
-         buffer.append("\n*** CONTEXTS IN ERROR: Name -> Error\n\n");
-         for (Map.Entry<String, String> entry : rootCauses.entrySet())
-            buffer.append(entry.getKey()).append(" -> ").append(entry.getValue()).append("\n\n");
-      }
+      buffer.append(incompleteDeployments.getContextsMissingDependenciesInfo());
+      // Display all contexts in error
+      buffer.append(incompleteDeployments.getContextsInErrorInfo());
+      // buffer to string
       return buffer.toString();
    }
 }

Modified: projects/microcontainer/trunk/deployers-client-spi/src/main/org/jboss/deployers/client/spi/IncompleteDeployments.java
===================================================================
--- projects/microcontainer/trunk/deployers-client-spi/src/main/org/jboss/deployers/client/spi/IncompleteDeployments.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-client-spi/src/main/org/jboss/deployers/client/spi/IncompleteDeployments.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -28,6 +28,7 @@
 import java.util.Set;
 import java.util.TreeMap;
 import java.util.TreeSet;
+import java.util.HashMap;
 
 /**
  * IncompleteDeployments.
@@ -52,6 +53,18 @@
    /** Contexts missing dependencies */
    private Map<String, Set<MissingDependency>> contextsMissingDependencies;
 
+   /** Deployments in error info */
+   private String deploymentsInErrorInfo;
+
+   /** Missing deployers info */
+   private String deploymentsMissingDeployerInfo;
+
+   /** Contexts in error info */
+   private String contextsInErrorInfo;
+
+   /** Contexts missing dependencies info */
+   private String contextsMissingDependenciesInfo;
+
    /**
     * Create a new IncompleteDeploymentException.
     * 
@@ -141,6 +154,147 @@
    }
 
    /**
+    * Get the info about deployments in error.
+    *
+    * @return string info
+    */
+   public String getDeploymentsInErrorInfo()
+   {
+      if (deploymentsInErrorInfo == null)
+      {
+         StringBuilder buffer = new StringBuilder();
+         // Display all the incomplete deployments
+         Map<String, Throwable> deploymentsInError = getDeploymentsInError();
+         if (deploymentsInError.isEmpty() == false)
+         {
+            buffer.append("\n*** DEPLOYMENTS IN ERROR: Name -> Error\n\n");
+            for (Map.Entry<String, Throwable> entry : deploymentsInError.entrySet())
+               buffer.append(entry.getKey()).append(" -> ").append(entry.getValue().toString()).append("\n\n");
+         }
+         deploymentsInErrorInfo = buffer.toString();
+      }
+      return deploymentsInErrorInfo;
+   }
+
+   /**
+    * Get the info about missing deployers.
+    *
+    * @return string info
+    */
+   public String getDeploymentsMissingDeployerInfo()
+   {
+      if (deploymentsMissingDeployerInfo == null)
+      {
+         StringBuilder buffer = new StringBuilder();
+         // Display all the missing deployers
+         Collection<String> deploymentsMissingDeployers = getDeploymentsMissingDeployer();
+         if (deploymentsMissingDeployers.isEmpty() == false)
+         {
+            buffer.append("\n*** DEPLOYMENTS MISSING DEPLOYERS: Name\n\n");
+            for (String name : deploymentsMissingDeployers)
+               buffer.append(name).append('\n');
+         }
+         deploymentsMissingDeployerInfo = buffer.toString();
+      }
+      return deploymentsMissingDeployerInfo;
+   }
+
+   /**
+    * Calculate upfront context errors.
+    */
+   protected void calculateContextsError()
+   {
+      // Popluate the potential root causes
+      Map<String, String> rootCauses = new HashMap<String, String>();
+
+      // Missing dependencies are root causes
+      Map<String, Set<MissingDependency>> contextsMissingDependencies = getContextsMissingDependencies();
+      if (contextsMissingDependencies.isEmpty() == false)
+      {
+         for (Map.Entry<String, Set<MissingDependency>> entry : contextsMissingDependencies.entrySet())
+         {
+            for (MissingDependency dependency : entry.getValue())
+               rootCauses.put(dependency.getDependency(), dependency.getActualState());
+         }
+      }
+
+      // Errors are root causes
+      Map<String, Throwable> contextsInError = getContextsInError();
+      if (contextsInError.isEmpty() == false)
+      {
+         for (Map.Entry<String, Throwable> entry : contextsInError.entrySet())
+         {
+            Throwable t = entry.getValue();
+            if (t == null)
+               rootCauses.put(entry.getKey(), "** UNKNOWN ERROR **");
+            else
+               rootCauses.put(entry.getKey(), t.toString());
+         }
+      }
+
+      StringBuilder buffer = new StringBuilder();
+
+      // Display all the missing dependencies
+      if (contextsMissingDependencies.isEmpty() == false)
+      {
+         buffer.append("\n*** CONTEXTS MISSING DEPENDENCIES: Name -> Dependency{Required State:Actual State}\n\n");
+         for (Map.Entry<String, Set<MissingDependency>> entry : contextsMissingDependencies.entrySet())
+         {
+            String name = entry.getKey();
+            buffer.append(name).append("\n");
+            for (MissingDependency dependency : entry.getValue())
+            {
+               buffer.append(" -> ").append(dependency.getDependency());
+               buffer.append('{').append(dependency.getRequiredState());
+               buffer.append(':').append(dependency.getActualState()).append("}");
+               buffer.append("\n");
+            }
+            buffer.append('\n');
+
+            // It is not a root cause if it has missing dependencies
+            rootCauses.remove(name);
+         }
+      }
+      contextsMissingDependenciesInfo = buffer.toString();
+
+      // reset buffer
+      buffer.setLength(0);
+
+      if (rootCauses.isEmpty() == false)
+      {
+         buffer.append("\n*** CONTEXTS IN ERROR: Name -> Error\n\n");
+         for (Map.Entry<String, String> entry : rootCauses.entrySet())
+            buffer.append(entry.getKey()).append(" -> ").append(entry.getValue()).append("\n\n");
+      }
+      contextsInErrorInfo = buffer.toString();
+   }
+
+   /**
+    * Get the contexts in error info.
+    *
+    * @return string info
+    */
+   public String getContextsInErrorInfo()
+   {
+      if (contextsInErrorInfo == null)
+         calculateContextsError();
+
+      return contextsInErrorInfo;
+   }
+
+   /**
+    * Get the contexts missing dependecies info
+    * @return
+    */
+   public String getContextsMissingDependenciesInfo()
+   {
+      if (contextsMissingDependenciesInfo == null)
+         calculateContextsError();
+
+      return contextsMissingDependenciesInfo;
+   }
+
+   /**
     * Search for componentName in strings.
     *
     * @param componentName component's name

Modified: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployersImpl.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployersImpl.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployersImpl.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -38,6 +38,7 @@
 import org.jboss.dependency.spi.ControllerState;
 import org.jboss.dependency.spi.DependencyInfo;
 import org.jboss.dependency.spi.DependencyItem;
+import org.jboss.deployers.client.spi.Deployment;
 import org.jboss.deployers.client.spi.IncompleteDeploymentException;
 import org.jboss.deployers.client.spi.IncompleteDeployments;
 import org.jboss.deployers.client.spi.MissingDependency;
@@ -86,7 +87,7 @@
    
    /** The scope builder */
    private ScopeBuilder scopeBuilder;
-   
+
    /**
     * Create a new DeployersImpl.
     *
@@ -526,7 +527,7 @@
       return result;
    }
 
-   public void checkComplete(Collection<DeploymentContext> errors, Collection<DeploymentContext> missingDeployer) throws DeploymentException
+   public void checkComplete(Collection<DeploymentContext> errors, Collection<Deployment> missingDeployer) throws DeploymentException
    {
       Map<String, Throwable> deploymentsInError = null;
       Collection<String> deploymentsMissingDeployer = null;
@@ -543,108 +544,219 @@
       if (missingDeployer != null && missingDeployer.isEmpty() == false)
       {
          deploymentsMissingDeployer = new HashSet<String>();
-         for (DeploymentContext context : missingDeployer)
+         for (Deployment context : missingDeployer)
             deploymentsMissingDeployer.add(context.getName());
       }
-      
-      if (controller != null)
+
+      List<ControllerState> states = controller.getStates();
+
+      Set<ControllerContext> notInstalled = controller.getNotInstalled();
+      if (notInstalled.isEmpty() == false)
       {
-         List<ControllerState> states = controller.getStates();
-         
-         Set<ControllerContext> notInstalled = controller.getNotInstalled();
+         for (Iterator<ControllerContext> i = notInstalled.iterator(); i.hasNext();)
+         {
+            ControllerContext context = i.next();
+            if (context.getState().equals(context.getRequiredState()))
+               i.remove();
+         }
          if (notInstalled.isEmpty() == false)
          {
-            for (Iterator<ControllerContext> i = notInstalled.iterator(); i.hasNext();)
+            contextsInError = new HashMap<String, Throwable>();
+            contextsMissingDependencies = new HashMap<String, Set<MissingDependency>>();
+            for (ControllerContext context : notInstalled)
             {
-               ControllerContext context = i.next();
-               if (context.getState().equals(context.getRequiredState()))
-                  i.remove();
+               checkControllerContext(context, contextsInError, contextsMissingDependencies, states);
             }
-            if (notInstalled.isEmpty() == false)
+         }
+      }
+
+      IncompleteDeployments incomplete = new IncompleteDeployments(deploymentsInError, deploymentsMissingDeployer, contextsInError, contextsMissingDependencies);
+      if (incomplete.isIncomplete())
+         throw new IncompleteDeploymentException(incomplete);
+   }
+
+   /**
+    * Check controller context.
+    *
+    * @param context the controller context
+    * @param contextsInError contexts in error map
+    * @param contextsMissingDependencies contexts missing dependecies map
+    * @param states controller states
+    */
+   protected final void checkControllerContext(
+         ControllerContext context,
+         Map<String, Throwable> contextsInError,
+         Map<String, Set<MissingDependency>> contextsMissingDependencies,
+         List<ControllerState> states)
+   {
+      if (context.getState().equals(ControllerState.ERROR))
+         contextsInError.put(context.getName().toString(), getRootCause(context.getError()));
+      else
+      {
+         String name = context.getName().toString();
+         Set<MissingDependency> dependencies = new HashSet<MissingDependency>();
+         DependencyInfo dependsInfo = context.getDependencyInfo();
+         for (DependencyItem item : dependsInfo.getIDependOn(null))
+         {
+            if (item.isResolved() == false)
             {
-               contextsInError = new HashMap<String, Throwable>();
-               contextsMissingDependencies = new HashMap<String, Set<MissingDependency>>();
-               for (ControllerContext context : notInstalled)
+               String dependency;
+               ControllerState actualState = null;
+               String actualStateString;
+               Object iDependOn = item.getIDependOn();
+               if (iDependOn == null)
                {
-                  if (context.getState().equals(ControllerState.ERROR))
-                     contextsInError.put(context.getName().toString(), getRootCause(context.getError()));
+                  dependency = "<UNKNOWN>";
+                  actualStateString = "** UNRESOLVED " + item.toHumanReadableString() + " **";
+               }
+               else
+               {
+                  dependency = iDependOn.toString();
+                  ControllerContext other = controller.getContext(item.getIDependOn(), null);
+                  if (other == null)
+                     actualStateString = "** NOT FOUND **";
                   else
                   {
-                     String name = context.getName().toString();
-                     Set<MissingDependency> dependencies = new HashSet<MissingDependency>();
-                     DependencyInfo dependsInfo = context.getDependencyInfo();
-                     for (DependencyItem item : dependsInfo.getIDependOn(null))
-                     {
-                        if (item.isResolved() == false)
-                        {
-                           String dependency;
-                           ControllerState actualState = null;
-                           String actualStateString;
-                           Object iDependOn = item.getIDependOn();
-                           if (iDependOn == null)
-                           {
-                              dependency = "<UNKNOWN>";
-                              actualStateString = "** UNRESOLVED " + item.toHumanReadableString() + " **";
-                           }
-                           else
-                           {
-                              dependency = iDependOn.toString();
-                              ControllerContext other = controller.getContext(item.getIDependOn(), null);
-                              if (other == null)
-                                 actualStateString = "** NOT FOUND **";
-                              else
-                              {
-                                 actualState = other.getState();
-                                 actualStateString = actualState.getStateString();
-                              }
-                           }
-                           ControllerState requiredState = item.getWhenRequired();
-                           String requiredStateString = requiredState.getStateString();
-                           int required = states.indexOf(requiredState);
-                           int actual = actualState == null ? -1 : states.indexOf(actualState);
-                           if (required > actual)
-                           {
-                              MissingDependency missing = new MissingDependency(name, dependency, requiredStateString, actualStateString);
-                              dependencies.add(missing);
-                           }
-                        }
-                     }
-                     contextsMissingDependencies.put(name, dependencies);
+                     actualState = other.getState();
+                     actualStateString = actualState.getStateString();
                   }
                }
+               ControllerState requiredState = item.getWhenRequired();
+               String requiredStateString = requiredState.getStateString();
+               int required = states.indexOf(requiredState);
+               int actual = actualState == null ? -1 : states.indexOf(actualState);
+               if (required > actual)
+               {
+                  MissingDependency missing = new MissingDependency(name, dependency, requiredStateString, actualStateString);
+                  dependencies.add(missing);
+               }
             }
          }
+         contextsMissingDependencies.put(name, dependencies);
       }
-      
-      IncompleteDeployments incomplete = new IncompleteDeployments(deploymentsInError, deploymentsMissingDeployer, contextsInError, contextsMissingDependencies);
-      if (incomplete.isIncomplete())
-         throw new IncompleteDeploymentException(incomplete);
    }
 
-   public void checkComplete(DeploymentContext context) throws DeploymentException
+   public void checkComplete(DeploymentContext... contexts) throws DeploymentException
    {
-      Map<String, Throwable> deploymentsInError = null;
-      Collection<String> deploymentsMissingDeployer = null;
-      Map<String, Throwable> contextsInError = null;
-      Map<String, Set<MissingDependency>> contextsMissingDependencies = null;
+      checkComplete(true, contexts);
+   }
 
-      if (context == null)
-         throw new IllegalArgumentException("Null context");
-      
-      Throwable problem = context.getProblem();
-      if (problem != null)
-         deploymentsInError = Collections.singletonMap(context.getName(), problem);
-      
-      if (context.isDeployed() == false)
-         deploymentsMissingDeployer = Collections.singleton(context.getName());
+   public void checkStructureComplete(DeploymentContext... contexts) throws DeploymentException
+   {
+      checkComplete(false, contexts);
+   }
 
-      // TODO JBMICROCONT-187 go through controller contexts for the deployment + related contexts
-      
+   /**
+    * Check if deployments are complete.
+    *
+    * @param contexts the deployment contexts
+    * @param checkContexts do we check contexts
+    * @throws DeploymentException throw error if deployment is incomplete
+    */
+   protected void checkComplete(boolean checkContexts, DeploymentContext... contexts) throws DeploymentException
+   {
+      if (contexts == null)
+         throw new IllegalArgumentException("Null contexts");
+
+      Map<String, Throwable> deploymentsInError = new HashMap<String, Throwable>();
+      Collection<String> deploymentsMissingDeployer = new HashSet<String>();
+      Map<String, Throwable> contextsInError = new HashMap<String, Throwable>();
+      Map<String, Set<MissingDependency>> contextsMissingDependencies = new HashMap<String, Set<MissingDependency>>();
+
+      for(DeploymentContext context : contexts)
+      {
+         Throwable problem = context.getProblem();
+         if (problem != null)
+            deploymentsInError.put(context.getName(), problem);
+
+         if (context.isDeployed() == false)
+            deploymentsMissingDeployer.add(context.getName());
+
+         if (checkContexts)
+         {
+            Set<ControllerContext> notInstalled = controller.getNotInstalled();
+            List<ControllerState> states = controller.getStates();
+            checkComplete(context, contextsInError, contextsMissingDependencies, notInstalled, states);
+         }
+      }
+
+      // reset if not used
+      if (deploymentsInError.isEmpty())
+         deploymentsInError = null;
+      if (deploymentsMissingDeployer.isEmpty())
+         deploymentsMissingDeployer = null;
+      if (contextsInError.isEmpty())
+         contextsInError = null;
+      if (contextsMissingDependencies.isEmpty())
+         contextsMissingDependencies = null;
+
       IncompleteDeployments incomplete = new IncompleteDeployments(deploymentsInError, deploymentsMissingDeployer, contextsInError, contextsMissingDependencies);
       if (incomplete.isIncomplete())
          throw new IncompleteDeploymentException(incomplete);
    }
 
+   /**
+    * Check complete on deployment context.
+    *
+    * @param context the deployment context
+    * @param contextsInError contexts in error map
+    * @param contextsMissingDependencies contexts missing dependecies map
+    * @param notInstalled the not installed contexts
+    * @param states controller states
+    */
+   protected final void checkComplete(
+         DeploymentContext context,
+         Map<String, Throwable> contextsInError,
+         Map<String, Set<MissingDependency>> contextsMissingDependencies,
+         Set<ControllerContext> notInstalled,
+         List<ControllerState> states)
+   {
+      DeploymentControllerContext dcc = context.getTransientAttachments().getAttachment(ControllerContext.class.getName(), DeploymentControllerContext.class);
+      checkControllerContext(dcc, contextsInError, contextsMissingDependencies, notInstalled, states);
+
+      Set<Object> names = context.getControllerContextNames();
+      if (names != null && names.isEmpty() == false)
+      {
+         for(Object name : names)
+         {
+            ControllerContext cc = controller.getContext(name, null);
+            checkControllerContext(cc, contextsInError, contextsMissingDependencies, notInstalled, states);
+         }
+      }
+
+      List<DeploymentContext> children = context.getChildren();
+      if (children != null && children.isEmpty() == false)
+      {
+         for(DeploymentContext child : children)
+            checkComplete(child, contextsInError, contextsMissingDependencies, notInstalled, states);
+      }
+   }
+
+   /**
+    * Check complete on deployment context.
+    *
+    * @param context the deployment context
+    * @param contextsInError contexts in error map
+    * @param contextsMissingDependencies contexts missing dependecies map
+    * @param notInstalled the not installed contexts
+    * @param states controller states
+    */
+   protected void checkControllerContext(
+         ControllerContext context,
+         Map<String, Throwable> contextsInError,
+         Map<String, Set<MissingDependency>> contextsMissingDependencies,
+         Set<ControllerContext> notInstalled,
+         List<ControllerState> states)
+   {
+      if (context != null)
+      {
+         if (context.getState().equals(context.getRequiredState()) == false && notInstalled.contains(context))
+         {
+            checkControllerContext(context, contextsInError, contextsMissingDependencies, states);
+         }
+      }
+   }
+
    public void install(ControllerContext context, ControllerState fromState, ControllerState toState) throws Throwable
    {
       DeploymentControllerContext deploymentControllerContext = (DeploymentControllerContext) context;

Modified: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/main/MainDeployerImpl.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/main/MainDeployerImpl.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/main/MainDeployerImpl.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -29,6 +29,7 @@
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import org.jboss.deployers.client.spi.Deployment;
 import org.jboss.deployers.client.spi.main.MainDeployer;
@@ -80,14 +81,17 @@
    private Map<String, DeploymentContext> errorDeployments = new ConcurrentHashMap<String, DeploymentContext>();
    
    /** Deployments missing deployers */
-   private Map<String, DeploymentContext> missingDeployers = new ConcurrentHashMap<String, DeploymentContext>();
+   private Map<String, Deployment> missingDeployers = new ConcurrentHashMap<String, Deployment>();
 
    /** The undeploy work */
    private List<DeploymentContext> undeploy = new CopyOnWriteArrayList<DeploymentContext>();
    
    /** The deploy work */
    private List<DeploymentContext> deploy = new CopyOnWriteArrayList<DeploymentContext>();
-   
+
+   /** The process lock */
+   private ReentrantReadWriteLock processLock = new ReentrantReadWriteLock();
+
    /**
     * Get the deployers
     * 
@@ -156,6 +160,7 @@
    {
       if (name == null)
          throw new IllegalArgumentException("Null name");
+
       return allDeployments.get(name);
    }
 
@@ -206,7 +211,7 @@
       return Collections.unmodifiableCollection(errorDeployments.values());
    }
 
-   public Collection<DeploymentContext> getMissingDeployer()
+   public Collection<Deployment> getMissingDeployer()
    {
       return Collections.unmodifiableCollection(missingDeployers.values());
    }
@@ -225,23 +230,35 @@
       return result;
    }
 
-   public synchronized void addDeployment(Deployment deployment) throws DeploymentException
+   public void addDeployment(Deployment deployment) throws DeploymentException
    {
+      addDeployment(deployment, true);
+   }
+
+   /**
+    * Add a deployment
+    *
+    * @param deployment the deployment
+    * @param addToDeploy should we add this deployment to deploy collection
+    * @throws DeploymentException for any error
+    */
+   protected void addDeployment(Deployment deployment, boolean addToDeploy) throws DeploymentException
+   {
       if (deployment == null)
          throw new DeploymentException("Null context");
       
       if (shutdown.get())
          throw new DeploymentException("The main deployer is shutdown");
-      
+
       String name = deployment.getName();
       log.debug("Add deployment: " + name);
-      
+
       DeploymentContext previous = topLevelDeployments.get(name);
       boolean topLevelFound = false;
       if (previous != null)
       {
          log.debug("Removing previous deployment: " + previous.getName());
-         removeContext(previous);
+         removeContext(previous, addToDeploy);
          topLevelFound = true;
       }
 
@@ -249,33 +266,70 @@
       {
          previous = allDeployments.get(name);
          if (previous != null)
-            throw new IllegalStateException("Deployment already exists as a subdeployment: " + name); 
+            throw new IllegalStateException("Deployment already exists as a subdeployment: " + name);
       }
 
+      DeploymentContext context = null;
       try
       {
-         DeploymentContext context = determineStructure(deployment);
+         context = determineStructure(deployment);
          if (DeploymentState.ERROR.equals(context.getState()))
             errorDeployments.put(name, context);
-         
+
          topLevelDeployments.put(name, context);
-         addContext(context);
+         addContext(context, addToDeploy);
       }
+      catch (DeploymentException e)
+      {
+         missingDeployers.put(name, deployment);
+         throw e;
+      }
       catch (Throwable t)
       {
+         // was structure determined?
+         if (context != null)
+            missingDeployers.put(name, deployment);
+
          throw DeploymentException.rethrowAsDeploymentException("Error determining deployment structure for " + name, t);
       }
    }
 
-   public synchronized boolean removeDeployment(Deployment deployment) throws DeploymentException
+   public boolean removeDeployment(Deployment deployment) throws DeploymentException
    {
+      return removeDeployment(deployment, true);
+   }
+
+   /**
+    * Remove a deployment by name
+    *
+    * @param deployment thedeployment
+    * @param addToUndeploy should we add to undeploy collection
+    * @return false when the context was previously unknown
+    * @throws DeploymentException for any error
+    */
+   protected boolean removeDeployment(Deployment deployment, boolean addToUndeploy) throws DeploymentException
+   {
       if (deployment == null)
          throw new DeploymentException("Null deployment");
-      return removeDeployment(deployment.getName());
+
+      return removeDeployment(deployment.getName(), addToUndeploy);
    }
 
-   public synchronized boolean removeDeployment(String name) throws DeploymentException
+   public boolean removeDeployment(String name) throws DeploymentException
    {
+      return removeDeployment(name, true);  
+   }
+
+   /**
+    * Remove a deployment by name
+    *
+    * @param name the name of the deployment
+    * @param addToUndeploy should we add to undeploy collection
+    * @return false when the context was previously unknown
+    * @throws DeploymentException for any error
+    */
+   protected boolean removeDeployment(String name, boolean addToUndeploy) throws DeploymentException
+   {
       if (name == null)
          throw new DeploymentException("Null name");
 
@@ -283,38 +337,114 @@
          throw new IllegalStateException("The main deployer is shutdown");
 
       log.debug("Remove deployment context: " + name);
-      
+
       DeploymentContext context = topLevelDeployments.remove(name);
       if (context == null)
          return false;
-      
-      removeContext(context);
-      
+
+      removeContext(context, addToUndeploy);
+
       return true;
    }
-   
-   public void deploy(Deployment deployment) throws DeploymentException
+
+   public void deploy(Deployment... deployments) throws DeploymentException
    {
-      addDeployment(deployment);
-      // TODO JBMICROCONT-187 just process this deployment
-      process();
-      checkComplete(deployment);
+      if (deployments == null)
+         throw new IllegalArgumentException("Null deployments.");
+
+      lockProcess();
+      try
+      {
+         DeploymentContext[] contexts = new DeploymentContext[deployments.length];
+         for(int i = 0; i < deployments.length; i++)
+         {
+            try
+            {
+               addDeployment(deployments[i]);
+               DeploymentContext context = getDeploymentContext(deployments[i].getName(), true);
+               deployers.process(Collections.singletonList(context), null);
+               contexts[i] = context;
+            }
+            catch(Throwable t)
+            {
+               Deployment[] deployedDeployments = new Deployment[i];
+               System.arraycopy(deployments, 0, deployedDeployments, 0, i);
+               undeploy(deployedDeployments);
+               throw DeploymentException.rethrowAsDeploymentException("Unable to deploy deployments.", t);
+            }
+         }
+         try
+         {
+            deployers.checkComplete(contexts);
+         }
+         catch (DeploymentException e)
+         {
+            Deployment[] deployedDeployments = new Deployment[contexts.length];
+            for(int i = 0; i < contexts.length; i++)
+               deployedDeployments[i] = contexts[i].getDeployment();
+
+            undeploy(deployedDeployments);
+            throw e;
+         }
+      }
+      finally
+      {
+         unlockProcess();
+      }
    }
 
-   public boolean undeploy(Deployment deployment) throws DeploymentException
+   public void undeploy(Deployment... deployments) throws DeploymentException
    {
-      if (deployment == null)
-         throw new DeploymentException("Null deployment");
+      if (deployments == null)
+         throw new IllegalArgumentException("Null deployments.");
 
-      return undeploy(deployment.getName());
+      lockProcess();
+      try
+      {
+         for(Deployment deployment : deployments)
+         {
+            DeploymentContext context = getDeploymentContext(deployment.getName());
+            if (context != null)
+            {
+               try
+               {
+                  removeDeployment(deployment, false);
+                  deployers.process(null, Collections.singletonList(context));
+               }
+               catch (DeploymentException e)
+               {
+                  if (log.isTraceEnabled())
+                     log.trace("Ignored exception while undeploying deployment " + deployment.getName() + ":" + e);
+               }
+            }
+            else if (log.isTraceEnabled())
+            {
+               log.trace("No such deployment present: " + deployment.getName());
+            }
+         }
+      }
+      finally
+      {
+         unlockProcess();
+      }
    }
 
-   public boolean undeploy(String name) throws DeploymentException
+   public void undeploy(String... names) throws DeploymentException
    {
-      boolean result = removeDeployment(name);
-      // TODO JBMICROCONT-187 just process this deployment
-      process();
-      return result;
+      if (names == null)
+         throw new IllegalArgumentException("Null names.");
+
+      List<Deployment> deployments = new ArrayList<Deployment>();
+      for(String name : names)
+      {
+         DeploymentContext context = getDeploymentContext(name);
+         if (context != null)
+            deployments.add(context.getDeployment());
+         else if (log.isTraceEnabled())
+            log.trace("No such deployment present: " + name);
+      }
+      if (deployments.isEmpty() == false)
+         undeploy(deployments.toArray(new Deployment[deployments.size()]));
    }
 
    public void process()
@@ -324,30 +454,28 @@
 
       List<DeploymentContext> undeployContexts = null;
       List<DeploymentContext> deployContexts = null;
-      synchronized (this)
+
+      if (deployers == null)
+         throw new IllegalStateException("No deployers");
+
+      if (undeploy.isEmpty() == false)
       {
-         if (deployers == null)
-            throw new IllegalStateException("No deployers");
+         // Undeploy in reverse order (subdeployments first)
+         undeployContexts = new ArrayList<DeploymentContext>(undeploy.size());
+         for (int i = undeploy.size() - 1; i >= 0; --i)
+            undeployContexts.add(undeploy.get(i));
+         undeploy.clear();
+      }
+      if (deploy.isEmpty() == false)
+      {
+         deployContexts = new ArrayList<DeploymentContext>(deploy);
+         deploy.clear();
+      }
 
-         if (undeploy.isEmpty() == false)
-         {
-            // Undeploy in reverse order (subdeployments first)
-            undeployContexts = new ArrayList<DeploymentContext>(undeploy.size());
-            for (int i = undeploy.size() -1; i >= 0; --i)
-               undeployContexts.add(undeploy.get(i));
-            undeploy.clear();
-         }
-         if (deploy.isEmpty() == false)
-         {
-            deployContexts = new ArrayList<DeploymentContext>(deploy);
-            deploy.clear();
-         }
-         
-         if (undeployContexts == null && deployContexts == null)
-         {
-            log.debug("Asked to process() when there is nothing to do.");
-            return;
-         }
+      if (undeployContexts == null && deployContexts == null)
+      {
+         log.debug("Asked to process() when there is nothing to do.");
+         return;
       }
 
       try
@@ -367,52 +495,120 @@
          throw new RuntimeException("Unexpected error in process()", t);
       }
    }
-   
+
+   // enable locking - so that we don't pick up current single deployments
    public void shutdown()
    {
-      while (topLevelDeployments.isEmpty() == false)
+      lockProcess();
+      try
       {
-         // Remove all the contexts
-         for (DeploymentContext context : topLevelDeployments.values())
+         while (topLevelDeployments.isEmpty() == false)
          {
-            topLevelDeployments.remove(context.getName());
-            removeContext(context);
+            // Remove all the contexts
+            for (DeploymentContext context : topLevelDeployments.values())
+            {
+               topLevelDeployments.remove(context.getName());
+               removeContext(context, true);
+            }
+
+            // Do it
+            process();
          }
-         
-         // Do it
-         process();
+
+         shutdown.set(true);
       }
-      
-      shutdown.set(true);
+      finally
+      {
+         unlockProcess();
+      }
    }
 
    public void checkComplete() throws DeploymentException
    {
       if (deployers == null)
          throw new IllegalStateException("Null deployers");
-      
+
       deployers.checkComplete(errorDeployments.values(), missingDeployers.values());
    }
 
-   public void checkComplete(Deployment deployment) throws DeploymentException
+   /**
+    * Get the names from deployments.
+    *
+    * @param deployments the deployments
+    * @return depolyment names
+    */
+   protected static String[] getDeploymentNames(Deployment... deployments)
    {
-      if (deployment == null)
-         throw new IllegalArgumentException("Null deployment");
-      checkComplete(deployment.getName());
+      if (deployments == null)
+         throw new IllegalArgumentException("Null deployments");
+
+      String[] names = new String[deployments.length];
+      for(int i = 0; i < deployments.length; i++)
+      {
+         if (deployments[i] == null)
+            throw new IllegalArgumentException("Null deployment: " + i);
+         names[i] = deployments[i].getName();
+      }
+      return names;
    }
 
-   public void checkComplete(String name) throws DeploymentException
+   /**
+    * Get the deployment contexts.
+    *
+    * @param names the deployment names
+    * @return depolyment contexts
+    * @throws DeploymentException if context is not found
+    */
+   protected DeploymentContext[] getDeploymentContexts(String... names) throws DeploymentException
    {
-      if (name == null)
-         throw new IllegalArgumentException("Null name");
-      DeploymentContext context = getDeploymentContext(name);
-      if (context == null)
-         throw new DeploymentException("Deployment not found " + name);
+      if (names == null)
+         throw new IllegalArgumentException("Null names");
+
+      DeploymentContext[] contexts = new DeploymentContext[names.length];
+      for(int i = 0; i < names.length; i++)
+         contexts[i] = getDeploymentContext(names[i], true);
+
+      return contexts;
+   }
+
+   public void checkComplete(Deployment... deployments) throws DeploymentException
+   {
+      if (deployments == null)
+         throw new IllegalArgumentException("Null deployments");
+
+      checkComplete(getDeploymentNames(deployments));
+   }
+
+   public void checkComplete(String... names) throws DeploymentException
+   {
+      if (names == null)
+         throw new IllegalArgumentException("Null names");
+
       if (deployers == null)
          throw new IllegalStateException("Null deployers");
-      deployers.checkComplete(context);
+
+      deployers.checkComplete(getDeploymentContexts(names));
    }
 
+   public void checkStructureComplete(Deployment... deployments) throws DeploymentException
+   {
+      if (deployments == null)
+         throw new IllegalArgumentException("Null deployments");
+
+      checkStructureComplete(getDeploymentNames(deployments));
+   }
+
+   public void checkStructureComplete(String... names) throws DeploymentException
+   {
+      if (names == null)
+         throw new IllegalArgumentException("Null names");
+
+      if (deployers == null)
+         throw new IllegalStateException("Null deployers");
+
+      deployers.checkStructureComplete(getDeploymentContexts(names));
+   }
+
    public DeploymentState getDeploymentState(String name)
    {
       DeploymentContext context = getDeploymentContext(name);
@@ -421,15 +617,9 @@
       return context.getState();
    }
 
-   /**
-    * 
-    */
    public ManagedDeployment getManagedDeployment(String name) throws DeploymentException
    {
-      DeploymentContext context = getDeploymentContext(name);
-      if (context == null)
-         throw new IllegalArgumentException("Context not found: " + name);
-      
+      DeploymentContext context = getDeploymentContext(name, true);
       Map<String, ManagedObject> rootMOs = getManagedObjects(context);
       ManagedDeployment root = mgtDeploymentCreator.build(context.getDeploymentUnit(), rootMOs, null);
       for (DeploymentContext childContext : context.getChildren())
@@ -441,10 +631,7 @@
 
    public Map<String, ManagedObject> getManagedObjects(String name) throws DeploymentException
    {
-      DeploymentContext context = getDeploymentContext(name);
-      if (context == null)
-         throw new IllegalArgumentException("Context not found: " + name);
-
+      DeploymentContext context = getDeploymentContext(name, true);
       return getManagedObjects(context);
    }
 
@@ -533,11 +720,12 @@
    }
    
    /**
-    * Add a context
-    * 
+    * Add a context.
+    *
     * @param context the context
+    * @param addToDeploy should we add to deploy collection
     */
-   private void addContext(DeploymentContext context)
+   private void addContext(DeploymentContext context, boolean addToDeploy)
    {
       allDeployments.put(context.getName(), context);
       if (context.getState() == DeploymentState.ERROR)
@@ -549,8 +737,8 @@
       DeploymentContext parent = context.getParent();
       log.debug("Scheduling deployment: " + context.getName() + " parent=" + parent);
 
-      // Process the parent only
-      if (context.isTopLevel())
+      // Process the top level only
+      if (context.isTopLevel() && addToDeploy)
          deploy.add(context);
       
       // Add all the children
@@ -558,16 +746,17 @@
       if (children != null)
       {
          for (DeploymentContext child : children)
-            addContext(child);
+            addContext(child, addToDeploy);
       }
    }
    
    /**
     * Remove a context
-    * 
+    *
     * @param context the context
+    * @param addToUndeploy add to undeploy collection
     */
-   private void removeContext(DeploymentContext context)
+   private void removeContext(DeploymentContext context, boolean addToUndeploy)
    {
       String name = context.getName();
       allDeployments.remove(name);
@@ -579,7 +768,7 @@
       log.debug("Scheduling undeployment: " + name + " parent=" + parent);
 
       // Process the top level only
-      if (context.isTopLevel())
+      if (context.isTopLevel() && addToUndeploy)
          undeploy.add(context);
       
       // Remove all the children
@@ -587,7 +776,23 @@
       if (children != null)
       {
          for (DeploymentContext child : children)
-            removeContext(child);
+            removeContext(child, addToUndeploy);
       }
    }
+
+   /**
+    * Lock process.
+    */
+   protected void lockProcess()
+   {
+      processLock.writeLock().lock();
+   }
+
+   /**
+    * Unlock process.
+    */
+   protected void unlockProcess()
+   {
+      processLock.writeLock().unlock();
+   }
 }

Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/AbstractDeployerTest.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/AbstractDeployerTest.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/AbstractDeployerTest.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -157,22 +157,27 @@
       assertNotNull(name + " not found", unit);
       return unit;
    }
-   
+
+   @Deprecated
    protected DeploymentUnit deploy(DeployerClient main, Deployment deployment) throws Exception
    {
       main.deploy(deployment);
-      DeploymentUnit unit = assertDeploymentUnit(main, deployment.getName());
-      return unit;
+      return assertDeploymentUnit(main, deployment.getName());
    }
    
    protected DeploymentUnit assertDeploy(DeployerClient main, Deployment deployment) throws Exception
    {
       main.deploy(deployment);
-      DeploymentUnit unit = assertDeploymentUnit(main, deployment.getName());
-      main.checkComplete();
-      return unit;
+      return assertDeploymentUnit(main, deployment.getName());
    }
-   
+
+   protected DeploymentUnit addDeployment(DeployerClient main, Deployment deployment) throws Exception
+   {
+      main.addDeployment(deployment);
+      main.process();
+      return assertDeploymentUnit(main, deployment.getName());
+   }
+
    protected void assertUndeploy(DeployerClient main, Deployment deployment) throws Exception
    {
       main.undeploy(deployment);

Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/test/MockClassLoaderDependenciesUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/test/MockClassLoaderDependenciesUnitTestCase.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/test/MockClassLoaderDependenciesUnitTestCase.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -160,7 +160,7 @@
       Deployment deploymentA = createSimpleDeployment(NameA);
       ClassLoaderMetaData classLoaderMetaData = addMetaData(deploymentA, null, A.class);
       addRequireModule(classLoaderMetaData, "B", null);
-      DeploymentUnit unitA = deploy(deployer, deploymentA);
+      DeploymentUnit unitA = addDeployment(deployer, deploymentA);
       
       assertNoClassLoader(unitA);
 
@@ -200,7 +200,7 @@
       Deployment deploymentA = createSimpleDeployment(NameA);
       ClassLoaderMetaData classLoaderMetaData = addMetaData(deploymentA, null, A.class);
       addRequireModule(classLoaderMetaData, "B", null);
-      DeploymentUnit unitA = deploy(deployer, deploymentA);
+      DeploymentUnit unitA = addDeployment(deployer, deploymentA);
       
       assertNoClassLoader(unitA);
 
@@ -241,7 +241,7 @@
       Deployment deploymentA = createSimpleDeployment(NameA);
       ClassLoaderMetaData classLoaderMetaData = addMetaData(deploymentA, null, A.class);
       addRequireModule(classLoaderMetaData, "B", null);
-      DeploymentUnit unitA = deploy(deployer, deploymentA);
+      DeploymentUnit unitA = addDeployment(deployer, deploymentA);
       
       assertNoClassLoader(unitA);
 

Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDescribeDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDescribeDeployer.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDescribeDeployer.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -46,7 +46,7 @@
       setStage(DeploymentStages.DESCRIBE);
    }
    
-   public void deploy(DeploymentUnit unit) throws DeploymentException
+   public void internalDeploy(DeploymentUnit unit) throws DeploymentException
    {
       deployed.add(unit.getName());
       TestDependencyMetaData dependencies = unit.getAttachment(TestDependencyMetaData.class);
@@ -58,7 +58,7 @@
    }
    
    @Override
-   public void undeploy(DeploymentUnit unit)
+   public void internalUndeploy(DeploymentUnit unit)
    {
       undeployed.add(unit.getName());
       TestDependencyMetaData dependencies = unit.getAttachment(TestDependencyMetaData.class);

Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestFlowDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestFlowDeployer.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestFlowDeployer.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -100,13 +100,13 @@
       return undeployed;
    }
 
-   public void deploy(DeploymentUnit unit) throws DeploymentException
+   public void internalDeploy(DeploymentUnit unit) throws DeploymentException
    {
       unit.getTypes().add(getType());
       deployed.put(unit.getName(), ++order);
    }
 
-   public void undeploy(DeploymentUnit unit)
+   public void internalUndeploy(DeploymentUnit unit)
    {
       undeployed.put(unit.getName(), ++order);
    }

Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestSimpleDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestSimpleDeployer.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestSimpleDeployer.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -122,7 +122,7 @@
       return undeployed;
    }
 
-   public void deploy(DeploymentUnit unit) throws DeploymentException
+   public void internalDeploy(DeploymentUnit unit) throws DeploymentException
    {
       log.debug(this + " deploy  : " + unit.getName());
       unit.getTypes().add(getType());
@@ -131,7 +131,7 @@
          throw new DeploymentException("Asked to fail");
    }
 
-   public void undeploy(DeploymentUnit unit)
+   public void internalUndeploy(DeploymentUnit unit)
    {
       log.debug(this + " undeploy: " + unit.getName());
       undeployed.put(unit.getName(), ++order);

Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestSimpleDeployer2.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestSimpleDeployer2.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestSimpleDeployer2.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -67,7 +67,7 @@
       undeployed.clear();
    }
 
-   public void deploy(DeploymentUnit unit) throws DeploymentException
+   public void internalDeploy(DeploymentUnit unit) throws DeploymentException
    {
       log.debug(this + " deploy  : " + unit.getName());
       deployed.add(unit.getName());
@@ -84,7 +84,7 @@
       }
    }
 
-   public void undeploy(DeploymentUnit unit)
+   public void internalUndeploy(DeploymentUnit unit)
    {
       log.debug(this + " undeploy: " + unit.getName());
       undeployed.add(unit.getName());

Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestSimpleDeployer3.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestSimpleDeployer3.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestSimpleDeployer3.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -66,7 +66,7 @@
       undeployed.clear();
    }
 
-   public void deploy(DeploymentUnit unit) throws DeploymentException
+   public void internalDeploy(DeploymentUnit unit) throws DeploymentException
    {
       log.debug(this + " deploy  : " + unit.getName());
       deployed.add(unit.getName());
@@ -74,7 +74,7 @@
          throw new RuntimeException("Asked to fail");
    }
 
-   public void undeploy(DeploymentUnit unit)
+   public void internalUndeploy(DeploymentUnit unit)
    {
       log.debug(this + " undeploy: " + unit.getName());
       undeployed.add(unit.getName());

Modified: projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/Deployers.java
===================================================================
--- projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/Deployers.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/Deployers.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -27,6 +27,7 @@
 
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.structure.spi.DeploymentContext;
+import org.jboss.deployers.client.spi.Deployment;
 import org.jboss.managed.api.ManagedObject;
 
 /**
@@ -61,13 +62,21 @@
     * @param missingDeployer the deployments missing a deployer
     * @throws DeploymentException when some deployment is not complete
     */
-   void checkComplete(Collection<DeploymentContext> errors, Collection<DeploymentContext> missingDeployer) throws DeploymentException;
+   void checkComplete(Collection<DeploymentContext> errors, Collection<Deployment> missingDeployer) throws DeploymentException;
 
    /**
-    * Check a single deployment is complete
+    * Check if deployments are complete
     * 
-    * @param context the deployment
+    * @param contexts the deployments
     * @throws DeploymentException when the deployment is not complete
     */
-   void checkComplete(DeploymentContext context) throws DeploymentException;
+   void checkComplete(DeploymentContext... contexts) throws DeploymentException;
+
+   /**
+    * Check if deployments are structurally complete
+    *
+    * @param contexts the deployments
+    * @throws DeploymentException when the deployment is not complete
+    */
+   void checkStructureComplete(DeploymentContext... contexts) throws DeploymentException;
 }

Modified: projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractComponentDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractComponentDeployer.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractComponentDeployer.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -74,9 +74,9 @@
       addInput(componentType);
    }
 
-   public void deploy(DeploymentUnit unit) throws DeploymentException
+   public void internalDeploy(DeploymentUnit unit) throws DeploymentException
    {
-      super.deploy(unit);
+      super.internalDeploy(unit);
       
       try
       {
@@ -89,9 +89,9 @@
       }
    }
    
-   public void undeploy(DeploymentUnit unit)
+   public void internalUndeploy(DeploymentUnit unit)
    {
-      super.undeploy(unit);
+      super.internalUndeploy(unit);
       undeployComponents(unit);
    }
 

Modified: projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractOptionalRealDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractOptionalRealDeployer.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractOptionalRealDeployer.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -53,7 +53,7 @@
       setInputs(optionalInput);
    }
 
-   public void deploy(DeploymentUnit unit) throws DeploymentException
+   public void internalDeploy(DeploymentUnit unit) throws DeploymentException
    {
       deploy(unit, unit.getAttachment(optionalInput));
    }
@@ -69,7 +69,7 @@
 
 
    @Override
-   public void undeploy(DeploymentUnit unit)
+   public void internalUndeploy(DeploymentUnit unit)
    {
       undeploy(unit, unit.getAttachment(optionalInput));
    }

Modified: projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractRealDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractRealDeployer.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractRealDeployer.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -22,15 +22,21 @@
 package org.jboss.deployers.spi.deployer.helpers;
 
 import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
 
 /**
  * AbstractRealDeployer.
  * 
  * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
  * @version $Revision: 1.1 $
  */
 public abstract class AbstractRealDeployer extends AbstractDeployer
 {
+   /** Use unit name for controller context name */
+   private boolean useUnitName;
+
    /**
     * Create a new AbstractRealDeployer.
     */
@@ -38,4 +44,89 @@
    {
       setStage(DeploymentStages.REAL);
    }
+
+   public final void deploy(DeploymentUnit unit) throws DeploymentException
+   {
+      internalDeploy(unit);
+
+      if (isControllerContextNameCandidate(unit))
+      {
+         addControllerContextName(unit);
+      }
+   }
+
+   /**
+    * Should we set controller context name on unit?
+    *
+    * @param unit the dpeloyment unit
+    * @return true if we should use unit's name as controller context name
+    */
+   protected boolean isControllerContextNameCandidate(DeploymentUnit unit)
+   {
+      return useUnitName && unit.isComponent();
+   }
+
+   protected void internalDeploy(DeploymentUnit unit) throws DeploymentException
+   {
+   }
+
+   /**
+    * Add controller context name.
+    *
+    * @param unit the deployment unit
+    */
+   protected void addControllerContextName(DeploymentUnit unit)
+   {
+      unit.addControllerContextName(unit.getName());
+   }
+
+   /**
+    * Remove controller context name.
+    *
+    * @param unit the deployment unit
+    */
+   protected void removeControllerContextName(DeploymentUnit unit)
+   {
+      unit.removeControllerContextName(unit.getName());
+   }
+
+   public final void undeploy(DeploymentUnit unit)
+   {
+      try
+      {
+         removeControllerContextName(unit);
+      }
+      catch (Throwable t)
+      {
+         if (log.isTraceEnabled())
+            log.trace("Exception while removing unit name: " + t);
+      }
+
+      internalUndeploy(unit);
+   }
+
+   protected void internalUndeploy(DeploymentUnit unit)
+   {
+      // nothing
+   }
+
+   /**
+    * Should we use unit name for controller context name.
+    *
+    * @return true if usage is allowed
+    */
+   public boolean isUseUnitName()
+   {
+      return useUnitName;
+   }
+
+   /**
+    * Set use unit name for controller context name.
+    *
+    * @param useUnitName flag to allow unit name usage
+    */
+   public void setUseUnitName(boolean useUnitName)
+   {
+      this.useUnitName = useUnitName;
+   }
 }

Modified: projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractRealDeployerWithInput.java
===================================================================
--- projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractRealDeployerWithInput.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractRealDeployerWithInput.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -87,7 +87,7 @@
    }
 
    @SuppressWarnings("unchecked")
-   public void deploy(DeploymentUnit unit) throws DeploymentException
+   public void internalDeploy(DeploymentUnit unit) throws DeploymentException
    {
       if (visitor == null)
       {
@@ -126,7 +126,7 @@
       }
    }
 
-   public void undeploy(DeploymentUnit unit)
+   public void internalUndeploy(DeploymentUnit unit)
    {
       if (visitor == null)
          return;

Modified: projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractSimpleRealDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractSimpleRealDeployer.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractSimpleRealDeployer.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -55,7 +55,7 @@
       return (Class<? extends T>) input;
    }
 
-   public void deploy(DeploymentUnit unit) throws DeploymentException
+   public void internalDeploy(DeploymentUnit unit) throws DeploymentException
    {
       T deployment = unit.getAttachment(getInput());
       if (deployment != null)
@@ -66,7 +66,7 @@
       }
    }
 
-   public void undeploy(DeploymentUnit unit)
+   public void internalUndeploy(DeploymentUnit unit)
    {
       T deployment = unit.getAttachment(getInput());
       if (deployment != null)

Modified: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/DeploymentContext.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/DeploymentContext.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/DeploymentContext.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -51,6 +51,27 @@
    String getName();
 
    /**
+    * Get the controller context names.
+    *
+    * @return the names
+    */
+   Set<Object> getControllerContextNames();
+
+   /**
+    * Add controller context name.
+    *
+    * @param name the controller context name
+    */
+   void addControllerContextName(Object name);
+
+   /**
+    * Remove controller context name.
+    *
+    * @param name the controller context name
+    */
+   void removeControllerContextName(Object name);
+
+   /**
     * Get the simple vfs name of the deployment unit. This is the simple
     * name of the virtual file .
     * 

Modified: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/DeploymentUnit.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/DeploymentUnit.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/DeploymentUnit.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -52,6 +52,27 @@
    String getName();
 
    /**
+    * Get the controller context names.
+    *
+    * @return the names
+    */
+   Set<Object> getControllerContextNames();
+
+   /**
+    * Add controller context name.
+    *
+    * @param name the controller context name
+    */
+   void addControllerContextName(Object name);
+
+   /**
+    * Remove controller context name.
+    *
+    * @param name the controller context name
+    */
+   void removeControllerContextName(Object name);
+
+   /**
     * Get the simple vfs name of the deployment unit. This is the simple
     * name of the virtual file .
     * 

Modified: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -31,6 +31,7 @@
 import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
+import java.util.HashSet;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.CopyOnWriteArraySet;
 
@@ -73,7 +74,10 @@
    
    /** The name */
    private String name;
-   
+
+   /** The controller context names - should be serializable */
+   private Set<Object> controllerContextNames;
+
    /** The simple name */
    private String simpleName;
 
@@ -340,6 +344,30 @@
       return name;
    }
 
+   public Set<Object> getControllerContextNames()
+   {
+      return controllerContextNames != null ? Collections.unmodifiableSet(getControllerContextNames()) : null;
+   }
+
+   public synchronized void addControllerContextName(Object name)
+   {
+      if (controllerContextNames == null)
+         controllerContextNames = new HashSet<Object>();
+      controllerContextNames.add(name);
+   }
+
+   public synchronized void removeControllerContextName(Object name)
+   {
+      if (controllerContextNames != null)
+      {
+         controllerContextNames.remove(name);
+         if (controllerContextNames.isEmpty())
+            controllerContextNames = null;
+      }
+      else
+         log.warn("Removing name on null names: " + name);
+   }
+
    public String getSimpleName()
    {
       return simpleName;

Modified: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentUnit.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentUnit.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentUnit.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -87,7 +87,22 @@
    {
       return deploymentContext.getName();
    }
-   
+
+   public Set<Object> getControllerContextNames()
+   {
+      return deploymentContext.getControllerContextNames();
+   }
+
+   public void addControllerContextName(Object name)
+   {
+      deploymentContext.addControllerContextName(name);
+   }
+
+   public void removeControllerContextName(Object name)
+   {
+      deploymentContext.removeControllerContextName(name);
+   }
+
    public String getSimpleName()
    {
       return deploymentContext.getSimpleName();

Modified: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractStructuralDeployers.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractStructuralDeployers.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractStructuralDeployers.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -23,7 +23,6 @@
 
 import org.jboss.deployers.client.spi.Deployment;
 import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.DeploymentState;
 import org.jboss.deployers.spi.attachments.Attachments;
 import org.jboss.deployers.spi.structure.StructureMetaData;
 import org.jboss.deployers.spi.structure.StructureMetaDataFactory;
@@ -68,8 +67,6 @@
       if (builder == null)
          throw new IllegalStateException("No structure builder has been configured");
       
-      Throwable problem = null;
-
       Attachments attachments = deployment.getPredeterminedManagedObjects();
       StructureMetaData structureMetaData = attachments.getAttachment(StructureMetaData.class);
       if (structureMetaData == null)
@@ -79,19 +76,17 @@
          {
             determineStructure(deployment, structureMetaData);
          }
+         catch (DeploymentException e)
+         {
+            throw e;
+         }
          catch (Throwable t)
          {
-            problem = t;
+            throw DeploymentException.rethrowAsDeploymentException("Exception determining structure: " + deployment, t);
          }
       }
       
-      DeploymentContext result = structureBuilder.populateContext(deployment, structureMetaData);
-      if (problem != null)
-      {
-         result.setState(DeploymentState.ERROR);
-         result.setProblem(problem);
-      }
-      return result;
+      return structureBuilder.populateContext(deployment, structureMetaData);
    }
    
    protected void determineStructure(Deployment deployment, StructureMetaData structure) throws Exception

Modified: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContext.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContext.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContext.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -25,6 +25,7 @@
 import java.util.Comparator;
 import java.util.List;
 import java.util.Set;
+import java.util.HashSet;
 import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.jboss.dependency.spi.DependencyInfo;
@@ -62,7 +63,10 @@
    
    /** The name */
    private String name;
-   
+
+   /** The controller context names - should be serializable */
+   private Set<Object> controllerContextNames;
+
    /** The deployment unit */
    private DeploymentUnit unit;
 
@@ -113,6 +117,30 @@
       return name;
    }
 
+   public Set<Object> getControllerContextNames()
+   {
+      return controllerContextNames != null ? Collections.unmodifiableSet(getControllerContextNames()) : null;
+   }
+
+   public synchronized void addControllerContextName(Object name)
+   {
+      if (controllerContextNames == null)
+         controllerContextNames = new HashSet<Object>();
+      controllerContextNames.add(name);
+   }
+
+   public synchronized void removeControllerContextName(Object name)
+   {
+      if (controllerContextNames != null)
+      {
+         controllerContextNames.remove(name);
+         if (controllerContextNames.isEmpty())
+            controllerContextNames = null;
+      }
+      else
+         log.warn("Removing name on null names: " + name);
+   }
+
    public String getSimpleName()
    {
       return parent.getSimpleName();

Modified: projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/BeanMetaDataDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/BeanMetaDataDeployer.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/BeanMetaDataDeployer.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -57,6 +57,7 @@
          throw new IllegalArgumentException("Null kernel");
       controller = kernel.getController();
       setComponentsOnly(true);
+      setUseUnitName(true);
    }
 
    @Override

Modified: projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/StructureDeployerWrapper.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/StructureDeployerWrapper.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/StructureDeployerWrapper.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -22,6 +22,7 @@
 package org.jboss.deployers.vfs.plugins.structure;
 
 import org.jboss.deployers.spi.structure.StructureMetaData;
+import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.vfs.spi.structure.StructureDeployer;
 import org.jboss.deployers.vfs.spi.structure.VFSStructuralDeployers;
 import org.jboss.logging.Logger;
@@ -56,28 +57,20 @@
       log = Logger.getLogger(deployer.getClass());
    }
    
-   public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers)
+   public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers) throws DeploymentException
    {
       if (file == null)
          throw new IllegalArgumentException("Null file");
-      
-      try
+
+      boolean result = deployer.determineStructure(root, parent, file, metaData, deployers);
+      if (log.isTraceEnabled())
       {
-         boolean result = deployer.determineStructure(root, parent, file, metaData, deployers);
-         if (log.isTraceEnabled())
-         {
-            if (result == false)
-               log.trace("Not recognised: " + file.getName());
-            else
-               log.trace("Recognised: " + file.getName());
-         }
-         return result;
+         if (result == false)
+            log.trace("Not recognised: " + file.getName());
+         else
+            log.trace("Recognised: " + file.getName());
       }
-      catch (Throwable t)
-      {
-         log.warn("Error during determineStructure: " + file.getName(), t);
-         return false;
-      }
+      return result;
    }
    
    public int getRelativeOrder()

Modified: projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/VFSStructuralDeployersImpl.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/VFSStructuralDeployersImpl.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/VFSStructuralDeployersImpl.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -133,7 +133,7 @@
       log.debug("Removed structure deployer " + deployer);
    }
    
-   public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData structureMetaData)
+   public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData structureMetaData) throws DeploymentException
    {
       StructureMetaData structure = StructureMetaDataFactory.createStructureMetaData();
       boolean result = doDetermineStructure(root, parent, file, structure);
@@ -169,8 +169,9 @@
     * @param file the file
     * @param structureMetaData the structure metadata
     * @return true when recognised
+    * @throws DeploymentException for any error
     */
-   protected boolean doDetermineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData structureMetaData)
+   protected boolean doDetermineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData structureMetaData) throws DeploymentException
    {
       StructureDeployer[] theDeployers; 
       synchronized (this)

Modified: projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/explicit/DeclaredStructure.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/explicit/DeclaredStructure.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/explicit/DeclaredStructure.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -25,6 +25,7 @@
 import java.net.URL;
 
 import org.jboss.deployers.spi.structure.StructureMetaData;
+import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.vfs.spi.structure.VFSStructuralDeployers;
 import org.jboss.deployers.vfs.spi.structure.helpers.AbstractStructureDeployer;
 import org.jboss.virtual.VirtualFile;
@@ -48,7 +49,7 @@
       setRelativeOrder(0);
    }
 
-   public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers)
+   public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers) throws DeploymentException
    {
       try
       {
@@ -81,7 +82,7 @@
       }
       catch (Exception e)
       {
-         log.warn("Error determining structure: " + file.getName(), e);
+         throw DeploymentException.rethrowAsDeploymentException("Error determining structure: " + file.getName(), e);
       }
       return false;
    }

Added: projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/file/FileMatcher.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/file/FileMatcher.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/file/FileMatcher.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -0,0 +1,40 @@
+/*
+* 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.vfs.plugins.structure.file;
+
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Matches virtual file to check if it can be deployed.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface FileMatcher
+{
+   /**
+    * Check if file param is deployable.
+    *
+    * @param file the virtual file
+    * @return true if we have a match, false otherwise
+    */
+   boolean isDeployable(VirtualFile file);
+}

Modified: projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/file/FileStructure.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/file/FileStructure.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/file/FileStructure.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -26,9 +26,12 @@
 
 import org.jboss.deployers.spi.structure.ContextInfo;
 import org.jboss.deployers.spi.structure.StructureMetaData;
+import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.vfs.spi.structure.VFSStructuralDeployers;
 import org.jboss.deployers.vfs.spi.structure.helpers.AbstractStructureDeployer;
 import org.jboss.virtual.VirtualFile;
+import org.jboss.beans.metadata.api.annotations.Install;
+import org.jboss.beans.metadata.api.annotations.Uninstall;
 
 /**
  * FileStructure is a simple suffix recognition structure deployer.
@@ -41,6 +44,9 @@
    /** The file suffixes */
    private static Set<String> fileSuffixes = new CopyOnWriteArraySet<String>();
 
+   /** The file matchers */
+   private Set<FileMatcher> fileMatchers = new CopyOnWriteArraySet<FileMatcher>();
+
    // Initialise known suffixes
    static
    {
@@ -110,6 +116,18 @@
       return fileSuffixes.remove(suffix);
    }
    
+   @Install
+   public boolean addFileMatcher(FileMatcher fm)
+   {
+      return fileMatchers.add(fm);
+   }
+
+   @Uninstall
+   public boolean removeFileMatcher(FileMatcher fm)
+   {
+      return fileMatchers.remove(fm);   
+   }
+
    /**
     * Whether this is an archive
     *
@@ -121,16 +139,33 @@
    {
       if (name == null)
          throw new IllegalArgumentException("Null name");
-      
-      int index = name.lastIndexOf('-');
-      if (index == -1)
-         return false;
-      String suffix = name.substring(index);
-      return fileSuffixes.contains(suffix);
+
+      for(String suffix : fileSuffixes)
+      {
+         if (name.endsWith(suffix))
+            return true;
+      }
+      return false;
    }
 
-   public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers)
+   /**
+    * Check is some file matcher recognizes the file.
+    *
+    * @param file the virtual file
+    * @return true if recognized, false otherwise
+    */
+   protected boolean checkFileMatchers(VirtualFile file)
    {
+      for(FileMatcher fm : fileMatchers)
+      {
+         if (fm.isDeployable(file))
+            return true;
+      }
+      return false;
+   }
+
+   public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers) throws DeploymentException
+   {
       ContextInfo context = null;
       try
       {
@@ -143,7 +178,7 @@
             // See if this is a top-level by checking the parent
             if (isTopLevel(parent) == false)
             {
-               if (isKnownFile(file.getName()) == false)
+               if (isKnownFile(file.getName()) == false && checkFileMatchers(file) == false)
                {
                   if (trace)
                      log.trace("... no - it is not a top level file and not a known name");
@@ -178,10 +213,10 @@
       }
       catch (Exception e)
       {
-         log.warn("Error determining structure: " + file.getName(), e);
          if (context != null)
             metaData.removeContext(context);
-         return false;
+
+         throw DeploymentException.rethrowAsDeploymentException("Error determining structure: " + file.getName(), e);
       }
    }
 }

Modified: projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/jar/JARStructure.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/jar/JARStructure.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/jar/JARStructure.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -26,6 +26,7 @@
 
 import org.jboss.deployers.spi.structure.ContextInfo;
 import org.jboss.deployers.spi.structure.StructureMetaData;
+import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.vfs.spi.structure.VFSStructuralDeployers;
 import org.jboss.deployers.vfs.spi.structure.helpers.AbstractStructureDeployer;
 import org.jboss.virtual.VirtualFile;
@@ -78,7 +79,7 @@
       JarUtils.setJarSuffixes(suffixes);
    }
 
-   public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers)
+   public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers) throws DeploymentException
    {
       ContextInfo context = null;
       try
@@ -130,11 +131,11 @@
       }
       catch (Exception e)
       {
-         log.warn("Error determining structure: " + file.getName(), e);
          // Remove the invalid context
-         if( context != null )
+         if(context != null)
             metaData.removeContext(context);
-         return false;
+
+         throw DeploymentException.rethrowAsDeploymentException("Error determining structure: " + file.getName(), e);
       }
    }
 }

Modified: projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/war/WARStructure.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/war/WARStructure.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/war/WARStructure.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -26,6 +26,7 @@
 
 import org.jboss.deployers.spi.structure.ContextInfo;
 import org.jboss.deployers.spi.structure.StructureMetaData;
+import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.vfs.spi.structure.VFSStructuralDeployers;
 import org.jboss.deployers.vfs.spi.structure.helpers.AbstractStructureDeployer;
 import org.jboss.virtual.VirtualFile;
@@ -79,7 +80,7 @@
       this.webInfLibFilter = webInfLibFilter;
    }
 
-   public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers)
+   public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers) throws DeploymentException
    {
       ContextInfo context = null;
       try
@@ -145,11 +146,11 @@
       }
       catch (Exception e)
       {
-         log.warn("Error determining structure: " + file.getName(), e);
          // Remove the invalid context
          if (context != null)
             metaData.removeContext(context);
-         return false;
+
+         throw DeploymentException.rethrowAsDeploymentException("Error determining structure: " + file.getName(), e);
       }
    }
 }

Modified: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/ear/support/MockEarStructureDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/ear/support/MockEarStructureDeployer.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/ear/support/MockEarStructureDeployer.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -29,6 +29,7 @@
 
 import org.jboss.deployers.spi.structure.ContextInfo;
 import org.jboss.deployers.spi.structure.StructureMetaData;
+import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.vfs.spi.structure.VFSStructuralDeployers;
 import org.jboss.deployers.vfs.spi.structure.helpers.AbstractStructureDeployer;
 import org.jboss.virtual.VirtualFile;
@@ -83,7 +84,7 @@
       this.earLibFilter = earLibFilter;
    }
 
-   public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers)
+   public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers) throws DeploymentException
    {
       ContextInfo context = null;
       boolean valid = false;

Modified: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/jar/test/CombinedJARStructureUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/jar/test/CombinedJARStructureUnitTestCase.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/jar/test/CombinedJARStructureUnitTestCase.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -47,9 +47,9 @@
 
    public void testRootNotAnArchive() throws Throwable
    {
-      // The file structure deployer recognises these for the combined test
-      assertDeployNoChildren("/structure/jar/notanarchive", "NotAnArchive.jar");
-      assertDeployNoChildren("/structure/jar/notanarchive", "NotAnArchive.zip");
+      // should not be valid anymore!
+      assertNotValid("/structure/jar/notanarchive", "NotAnArchive.jar");
+      assertNotValid("/structure/jar/notanarchive", "NotAnArchive.zip");
    }
 
    public void testSubdeploymentIsKnownFile() throws Throwable

Modified: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/war/test/CombinedWARStructureUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/war/test/CombinedWARStructureUnitTestCase.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/war/test/CombinedWARStructureUnitTestCase.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -53,8 +53,8 @@
 
    public void testNotAnArchive() throws Throwable
    {
-      // The file deployer recognises in the combined test
-      assertDeployNoChildren("/structure/war/notanarchive", "notanarchive.war");
+      // should not be valid
+      assertNotValid("/structure/war/notanarchive", "notanarchive.war");
    }
 
    protected VFSDeploymentContext determineStructure(VFSDeployment deployment) throws Exception

Modified: projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/AbstractVFSRealDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/AbstractVFSRealDeployer.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/AbstractVFSRealDeployer.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -36,7 +36,7 @@
 @Deprecated
 public abstract class AbstractVFSRealDeployer extends AbstractRealDeployer
 {
-   public void deploy(DeploymentUnit unit) throws DeploymentException
+   public void internalDeploy(DeploymentUnit unit) throws DeploymentException
    {
       if (unit instanceof VFSDeploymentUnit == false)
          return;
@@ -45,7 +45,7 @@
       deploy(vfsDeploymentUnit);
    }
 
-   public void undeploy(DeploymentUnit unit)
+   public void internalUndeploy(DeploymentUnit unit)
    {
       if (unit instanceof VFSDeploymentUnit == false)
          return;

Modified: projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/StructureDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/StructureDeployer.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/StructureDeployer.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -22,6 +22,7 @@
 package org.jboss.deployers.vfs.spi.structure;
 
 import org.jboss.deployers.spi.Ordered;
+import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.structure.StructureMetaData;
 import org.jboss.virtual.VirtualFile;
 
@@ -43,6 +44,7 @@
     * @param metaData the structure metadata to build
     * @param deployers the available structure deployers
     * @return true when it is recognised
+    * @throws DeploymentException for any error
     */
-   boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers);
+   boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers) throws DeploymentException;
 }

Modified: projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/VFSStructuralDeployers.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/VFSStructuralDeployers.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/VFSStructuralDeployers.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -22,6 +22,7 @@
 package org.jboss.deployers.vfs.spi.structure;
 
 import org.jboss.deployers.spi.structure.StructureMetaData;
+import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.virtual.VirtualFile;
 
 /**
@@ -40,6 +41,7 @@
     * @param file the virtual file
     * @param structureMetaData the structure metadata
     * @return true when recognised, false otherwise
+    * @throws DeploymentException for any error
     */
-   boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData structureMetaData);
+   boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData structureMetaData) throws DeploymentException;
 }

Modified: projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/AbstractCandidateStructureVisitor.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/AbstractCandidateStructureVisitor.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/AbstractCandidateStructureVisitor.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -176,7 +176,6 @@
          catch (Exception e)
          {
             log.debug("Ignoring " + file + " reason=" + e);
-            return;
          }
       }
    }

Modified: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/deployers/OSGiStructure.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/deployers/OSGiStructure.java	2007-11-16 19:37:25 UTC (rev 67197)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/deployers/OSGiStructure.java	2007-11-16 19:53:14 UTC (rev 67198)
@@ -22,6 +22,7 @@
 package org.jboss.osgi.plugins.deployers;
 
 import org.jboss.deployers.spi.structure.StructureMetaData;
+import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.vfs.spi.structure.VFSStructuralDeployers;
 import org.jboss.deployers.vfs.spi.structure.helpers.AbstractStructureDeployer;
 import org.jboss.virtual.VirtualFile;
@@ -40,7 +41,7 @@
       setRelativeOrder(10001);
    }
 
-   public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers)
+   public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers) throws DeploymentException
    {
       // todo - see JarStructure
       return false;




More information about the jboss-cvs-commits mailing list