[jboss-cvs] JBossAS SVN: r64960 - in projects/microcontainer/trunk: deployers-impl/src/tests/org/jboss/test/deployers and 8 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Aug 30 04:39:48 EDT 2007


Author: adrian at jboss.org
Date: 2007-08-30 04:39:48 -0400 (Thu, 30 Aug 2007)
New Revision: 64960

Added:
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/DeployersScopeTestSuite.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentDeployer.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentMetaData.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentMetaDataContainer.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/test/
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/test/DeployerScopeUnitTestCase.java
   projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/scope/
   projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/scope/ScopeBuilder.java
   projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/scope/helpers/
   projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/scope/helpers/DefaultScopeBuilder.java
Modified:
   projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployersImpl.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/DeployersImplTestSuite.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/ComponentDeploymentContext.java
   projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentContext.java
Log:
[JBMICROCONT-196] - API for scopes and MetaData access in the deployers

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-08-30 04:58:25 UTC (rev 64959)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployersImpl.java	2007-08-30 08:39:48 UTC (rev 64960)
@@ -52,8 +52,11 @@
 import org.jboss.deployers.spi.deployer.managed.ManagedObjectCreator;
 import org.jboss.deployers.structure.spi.DeploymentContext;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.scope.ScopeBuilder;
+import org.jboss.kernel.spi.dependency.KernelController;
 import org.jboss.logging.Logger;
 import org.jboss.managed.api.ManagedObject;
+import org.jboss.metadata.spi.repository.MutableMetaDataRepository;
 
 /**
  * DeployersImpl.
@@ -69,6 +72,9 @@
    /** The dependency state machine */
    private AbstractController controller;
    
+   /** The repository */
+   private MutableMetaDataRepository repository;
+   
    /** The deployment stages by name */
    private Map<String, DeploymentStage> stages = new ConcurrentHashMap<String, DeploymentStage>();
    
@@ -78,6 +84,9 @@
    /** The deployers by stage and type */
    private Map<String, List<Deployer>> deployersByStage = new HashMap<String, List<Deployer>>();
    
+   /** The scope builder */
+   private ScopeBuilder scopeBuilder;
+   
    /**
     * Create a new DeployersImpl.
     *
@@ -270,6 +279,56 @@
       log.debug("Added stage " + stageName + " before " + preceeds);
    }
 
+   /**
+    * Get the scopeBuilder.
+    * 
+    * @return the scopeBuilder.
+    */
+   public ScopeBuilder getScopeBuilder()
+   {
+      return scopeBuilder;
+   }
+
+   /**
+    * Set the scopeBuilder.
+    * 
+    * @param scopeBuilder the scopeBuilder.
+    */
+   public void setScopeBuilder(ScopeBuilder scopeBuilder)
+   {
+      this.scopeBuilder = scopeBuilder;
+   }
+
+   /**
+    * Get the repository.
+    * 
+    * @return the repository.
+    */
+   public MutableMetaDataRepository getRepository()
+   {
+      return repository;
+   }
+
+   /**
+    * Set the repository.
+    * 
+    * @param repository the repository.
+    */
+   public void setRepository(MutableMetaDataRepository repository)
+   {
+      this.repository = repository;
+   }
+
+   public void start()
+   {
+      // Bootstrap the repository
+      if (repository == null && controller instanceof KernelController)
+      {
+         KernelController kernelController = (KernelController) controller;
+         repository = kernelController.getKernel().getMetaDataRepository().getMetaDataRepository();
+      }
+   }
+   
    public Map<String, ManagedObject> getManagedObjects(DeploymentContext context) throws DeploymentException
    {
       if (context == null)
@@ -382,6 +441,7 @@
                // This is now in the abstract classloader deployer.undeploy,
                // but left here in case somebody isn't using that.
                removeClassLoader(context);
+               cleanup(context);
                log.debug("Fully Undeployed " + context.getName());
             }
             catch (Throwable t)
@@ -406,6 +466,10 @@
                context.setState(DeploymentState.DEPLOYING);
                log.debug("Deploying " + context.getName());
                context.getTransientAttachments().addAttachment(ControllerContext.class, deploymentControllerContext);
+               if (scopeBuilder != null)
+                  context.getTransientAttachments().addAttachment(ScopeBuilder.class, scopeBuilder);
+               if (repository != null)
+                  context.getTransientAttachments().addAttachment(MutableMetaDataRepository.class, repository);
             }
             catch (Throwable t)
             {
@@ -1023,4 +1087,26 @@
             removeClassLoader(child);
       }
    }
+
+   /**
+    * Cleanup the deployment context
+    * 
+    * @param context the context
+    */
+   private static void cleanup(DeploymentContext context)
+   {
+      context.cleanup();
+      List<DeploymentContext> children = context.getChildren();
+      if (children != null && children.isEmpty() == false)
+      {
+         for (DeploymentContext child : children)
+            cleanup(child);
+      }
+      List<DeploymentContext> components = context.getComponents();
+      if (components != null && components.isEmpty() == false)
+      {
+         for (DeploymentContext component : components)
+            cleanup(component);
+      }
+   }
 }

Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/DeployersImplTestSuite.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/DeployersImplTestSuite.java	2007-08-30 04:58:25 UTC (rev 64959)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/DeployersImplTestSuite.java	2007-08-30 08:39:48 UTC (rev 64960)
@@ -24,6 +24,7 @@
 import org.jboss.test.deployers.classloading.DeployersClassLoadingTestSuite;
 import org.jboss.test.deployers.deployer.DeployersDeployerTestSuite;
 import org.jboss.test.deployers.managed.DeployersManagedTestSuite;
+import org.jboss.test.deployers.scope.DeployersScopeTestSuite;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -49,6 +50,7 @@
       suite.addTest(DeployersDeployerTestSuite.suite());
       suite.addTest(DeployersManagedTestSuite.suite());
       suite.addTest(DeployersClassLoadingTestSuite.suite());
+      suite.addTest(DeployersScopeTestSuite.suite());
 
       return suite;
    }

Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/DeployersScopeTestSuite.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/DeployersScopeTestSuite.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/DeployersScopeTestSuite.java	2007-08-30 08:39:48 UTC (rev 64960)
@@ -0,0 +1,51 @@
+/*
+* 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.test.deployers.scope;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.jboss.test.deployers.scope.test.DeployerScopeUnitTestCase;
+
+/**
+ * Deployers Scope Test Suite.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 37459 $
+ */
+public class DeployersScopeTestSuite extends TestSuite
+{
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("Deployers Scope Tests");
+
+      suite.addTest(DeployerScopeUnitTestCase.suite());
+
+      return suite;
+   }
+}

Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentDeployer.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentDeployer.java	2007-08-30 08:39:48 UTC (rev 64960)
@@ -0,0 +1,110 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.test.deployers.scope.support;
+
+import java.util.List;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.helpers.AbstractComponentDeployer;
+import org.jboss.deployers.spi.deployer.helpers.DeploymentVisitor;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * TestDeploymentDeployer.
+ * 
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestComponentDeployer extends AbstractComponentDeployer<TestComponentMetaDataContainer, TestComponentMetaData>
+{
+   public TestComponentDeployer()
+   {
+      setDeploymentVisitor(new TestComponentMetaDataContainerVisitor());
+      setComponentVisitor(new TestComponentMetaDataVisitor());
+   }
+
+   protected static void addTestComponent(DeploymentUnit unit, TestComponentMetaData test)
+   {
+      DeploymentUnit component = unit.addComponent(test.name);
+      component.addAttachment(TestComponentMetaData.class, test);
+   }
+
+   protected static void removeTestComponent(DeploymentUnit unit, TestComponentMetaData test)
+   {
+      unit.removeComponent(test.name);
+   }
+   
+   public class TestComponentMetaDataContainerVisitor implements DeploymentVisitor<TestComponentMetaDataContainer>
+   {
+      public Class<TestComponentMetaDataContainer> getVisitorType()
+      {
+         return TestComponentMetaDataContainer.class;
+      }
+
+      public void deploy(DeploymentUnit unit, TestComponentMetaDataContainer deployment) throws DeploymentException
+      {
+         try
+         {
+            List<TestComponentMetaData> tests = deployment.componentMetaData;
+            if (tests == null || tests.isEmpty())
+               return;
+            
+            for (TestComponentMetaData test : tests)
+               addTestComponent(unit, test);
+         }
+         catch (Throwable t)
+         {
+            throw DeploymentException.rethrowAsDeploymentException("Error deploying: " + deployment, t);
+         }
+      }
+
+      public void undeploy(DeploymentUnit unit, TestComponentMetaDataContainer deployment)
+      {
+         List<TestComponentMetaData> tests = deployment.componentMetaData;
+         if (tests == null)
+            return;
+         
+         for (TestComponentMetaData test : tests)
+         {
+            unit.removeComponent(test.name);
+         }
+      }
+   }
+
+   public static class TestComponentMetaDataVisitor implements DeploymentVisitor<TestComponentMetaData>
+   {
+      public Class<TestComponentMetaData> getVisitorType()
+      {
+         return TestComponentMetaData.class;
+      }
+
+      public void deploy(DeploymentUnit unit, TestComponentMetaData deployment) throws DeploymentException
+      {
+         addTestComponent(unit, deployment);
+      }
+
+      public void undeploy(DeploymentUnit unit, TestComponentMetaData deployment)
+      {
+         removeTestComponent(unit, deployment);
+      }
+   }
+}

Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentMetaData.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentMetaData.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentMetaData.java	2007-08-30 08:39:48 UTC (rev 64960)
@@ -0,0 +1,43 @@
+/*
+* 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.test.deployers.scope.support;
+
+/**
+ * TestComponentMetaData.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestComponentMetaData
+{
+   public String name;
+   
+   public TestComponentMetaData(String name)
+   {
+      this.name = name;
+   }
+   
+   public String toString()
+   {
+      return name;
+   }
+}

Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentMetaDataContainer.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentMetaDataContainer.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentMetaDataContainer.java	2007-08-30 08:39:48 UTC (rev 64960)
@@ -0,0 +1,43 @@
+/*
+* 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.test.deployers.scope.support;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * TestComponentMetaDataContainer.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestComponentMetaDataContainer
+{
+   public List<TestComponentMetaData> componentMetaData;
+   
+   public TestComponentMetaDataContainer(TestComponentMetaData... metaDatas)
+   {
+      componentMetaData = new ArrayList<TestComponentMetaData>();
+      for (TestComponentMetaData metaData: metaDatas)
+         componentMetaData.add(metaData);
+   }
+}

Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/test/DeployerScopeUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/test/DeployerScopeUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/test/DeployerScopeUnitTestCase.java	2007-08-30 08:39:48 UTC (rev 64960)
@@ -0,0 +1,275 @@
+/*
+* 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.test.deployers.scope.test;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.client.spi.DeploymentFactory;
+import org.jboss.deployers.plugins.deployers.DeployersImpl;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
+import org.jboss.deployers.spi.attachments.PredeterminedManagedObjectAttachments;
+import org.jboss.deployers.spi.deployer.Deployers;
+import org.jboss.deployers.spi.structure.ContextInfo;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.metadata.plugins.repository.basic.BasicMetaDataRepository;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.metadata.spi.MutableMetaData;
+import org.jboss.metadata.spi.scope.CommonLevels;
+import org.jboss.metadata.spi.scope.ScopeKey;
+import org.jboss.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.scope.support.TestComponentDeployer;
+import org.jboss.test.deployers.scope.support.TestComponentMetaData;
+import org.jboss.test.deployers.scope.support.TestComponentMetaDataContainer;
+
+/**
+ * DeployerScopeUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class DeployerScopeUnitTestCase extends AbstractDeployerTest
+{
+   private static final DeploymentFactory factory = new DeploymentFactory();
+
+   private TestComponentDeployer deployer = new TestComponentDeployer();
+
+   private BasicMetaDataRepository repository;
+   
+   private Set<ScopeKey> scopes = new HashSet<ScopeKey>();
+   
+   public static ScopeKey SCOPE_A = createAppScope("A");
+   public static ScopeKey SCOPE_AA = createScope("A", "A");
+
+   public static ScopeKey createAppScope(String app)
+   {
+      return new ScopeKey(CommonLevels.APPLICATION, app);
+   }
+
+   public static ScopeKey createDepScope(String dep)
+   {
+      return new ScopeKey(CommonLevels.DEPLOYMENT, dep);
+   }
+
+   public static ScopeKey createInstanceScope(String name)
+   {
+      return new ScopeKey(CommonLevels.INSTANCE, name);
+   }
+
+   public static ScopeKey createScope(String app, String dep)
+   {
+      ScopeKey result = ScopeKey.DEFAULT_SCOPE.clone();
+      result.addScope(CommonLevels.APPLICATION, app);
+      result.addScope(CommonLevels.DEPLOYMENT, dep);
+      return result;
+   }
+
+   public static ScopeKey createComponentScope(String app, String dep, String comp)
+   {
+      ScopeKey result = createScope(app, dep);
+      result.addScope(CommonLevels.INSTANCE, comp);
+      return result;
+   }
+   
+   public static Test suite()
+   {
+      return new TestSuite(DeployerScopeUnitTestCase.class);
+   }
+   
+   public DeployerScopeUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testSimpleScope() throws Exception
+   {
+      DeployerClient main = getMainDeployer();
+      
+      Deployment a = createSimpleDeployment("A");
+      main.addDeployment(a);
+      main.process();
+      
+      DeploymentUnit unit = getDeploymentUnit(main, "A");
+      assertScope(SCOPE_AA, SCOPE_A, unit);
+      
+      main.removeDeployment(a);
+      main.process();
+      assertNoScopes();
+   }
+
+   public void testSubDeploymentScope() throws Exception
+   {
+      DeployerClient main = getMainDeployer();
+      
+      Deployment a = createSimpleDeployment("A");
+      factory.addContext(a, "A1");
+      factory.addContext(a, "A2");
+      main.addDeployment(a);
+      main.process();
+
+      DeploymentUnit unit = getDeploymentUnit(main, "A");
+      assertScope(SCOPE_AA, SCOPE_A, unit);
+
+      List<DeploymentUnit> children = unit.getChildren();
+      assertEquals(2, children.size());
+      for (DeploymentUnit child : children)
+      {
+         ScopeKey scope = createScope("A", child.getName());
+         ScopeKey mutable = createDepScope(child.getName());
+         assertScope(scope, mutable, child);
+      }
+
+      main.removeDeployment(a);
+      main.process();
+      assertNoScopes();
+   }
+
+   public void testSimpleComponents() throws Exception
+   {
+      DeployerClient main = getMainDeployer();
+      
+      Deployment a = createSimpleDeployment("A");
+      TestComponentMetaData c1 = new TestComponentMetaData("C1");
+      TestComponentMetaData c2 = new TestComponentMetaData("C2");
+      TestComponentMetaDataContainer md = new TestComponentMetaDataContainer(c1, c2);
+      addMetaData(a, md);
+      main.addDeployment(a);
+      main.process();
+
+      DeploymentUnit unit = getDeploymentUnit(main, "A");
+      assertScope(SCOPE_AA, SCOPE_A, unit);
+
+      List<DeploymentUnit> components = unit.getComponents();
+      assertEquals(2, components.size());
+      for (DeploymentUnit component : components)
+      {
+         ScopeKey scope = createComponentScope("A", "A", component.getName());
+         ScopeKey mutable = createInstanceScope(component.getName());
+         assertScope(scope, mutable, component);
+      }
+
+      main.removeDeployment(a);
+      main.process();
+      assertNoScopes();
+   }
+
+   public void testSubDeploymentScopeWithComponents() throws Exception
+   {
+      DeployerClient main = getMainDeployer();
+      
+      Deployment a = createSimpleDeployment("A");
+      ContextInfo a1 = factory.addContext(a, "A1");
+      TestComponentMetaData a1c1 = new TestComponentMetaData("A1C1");
+      TestComponentMetaData a1c2 = new TestComponentMetaData("A1C2");
+      TestComponentMetaDataContainer md1 = new TestComponentMetaDataContainer(a1c1, a1c2);
+      addMetaData(a1, md1);
+      ContextInfo a2 = factory.addContext(a, "A2");
+      TestComponentMetaData a2c1 = new TestComponentMetaData("A2C1");
+      TestComponentMetaData a2c2 = new TestComponentMetaData("A2C2");
+      TestComponentMetaDataContainer md2 = new TestComponentMetaDataContainer(a2c1, a2c2);
+      addMetaData(a2, md2);
+      main.addDeployment(a);
+      main.process();
+
+      DeploymentUnit unit = getDeploymentUnit(main, "A");
+      assertScope(SCOPE_AA, SCOPE_A, unit);
+
+      List<DeploymentUnit> children = unit.getChildren();
+      assertEquals(2, children.size());
+      for (DeploymentUnit child : children)
+      {
+         ScopeKey scope = createScope("A", child.getName());
+         ScopeKey mutable = createDepScope(child.getName());
+         assertScope(scope, mutable, child);
+
+         List<DeploymentUnit> components = child.getComponents();
+         assertEquals(2, components.size());
+         for (DeploymentUnit component : components)
+         {
+            scope = createComponentScope("A", child.getName(), component.getName());
+            mutable = createInstanceScope(component.getName());
+            assertScope(scope, mutable, component);
+         }
+      }
+
+      main.removeDeployment(a);
+      main.process();
+      assertNoScopes();
+   }
+
+   protected void assertScope(ScopeKey scope, ScopeKey mutable, DeploymentUnit unit)
+   {
+      scopes.add(scope);
+      scopes.add(mutable);
+      
+      assertEquals(scope, unit.getScope());
+      assertEquals(mutable, unit.getMutableScope());
+      
+      MetaData metaData = unit.getMetaData();
+      assertNotNull("Should have metadata for " + unit.getName(), metaData);
+      String expected = null;
+      DeploymentUnit parent = unit.getParent();
+      if (parent != null)
+         expected = parent.getName();
+      assertEquals(expected, metaData.getMetaData("test"));
+      
+      MutableMetaData mutableMetaData = unit.getMutableMetaData();
+      mutableMetaData.addMetaData("test", unit.getName(), String.class);
+      
+      assertEquals(unit.getName(), metaData.getMetaData("test"));
+   }
+   
+   protected void assertNoScopes()
+   {
+      for (ScopeKey scope : scopes)
+      {
+         assertNull(scope + " should have been removed", repository.getMetaData(scope));
+         assertNull(scope + " should have been removed", repository.getMetaDataRetrieval(scope));
+      }
+   }
+   
+   protected static void addMetaData(PredeterminedManagedObjectAttachments attachments, TestComponentMetaDataContainer md)
+   {
+      MutableAttachments mutable = (MutableAttachments) attachments.getPredeterminedManagedObjects();
+      mutable.addAttachment(TestComponentMetaDataContainer.class, md);
+   }
+   
+   protected DeployerClient getMainDeployer()
+   {
+      return createMainDeployer(deployer);
+   }
+
+   @Override
+   protected Deployers createDeployers()
+   {
+      DeployersImpl deployers = (DeployersImpl) super.createDeployers();
+      repository = new BasicMetaDataRepository();
+      deployers.setRepository(repository);
+      return deployers;
+   }
+}

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-08-30 04:58:25 UTC (rev 64959)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/DeploymentContext.java	2007-08-30 08:39:48 UTC (rev 64960)
@@ -30,6 +30,9 @@
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.DeploymentState;
 import org.jboss.deployers.spi.attachments.ManagedObjectsWithTransientAttachments;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.metadata.spi.MutableMetaData;
+import org.jboss.metadata.spi.scope.ScopeKey;
 
 /**
  * DeploymentContext.
@@ -109,6 +112,48 @@
    Set<String> getTypes();
    
    /**
+    * Get the scope
+    * 
+    * @return the scope
+    */
+   ScopeKey getScope();
+   
+   /**
+    * Set the scope
+    * 
+    * @param key the scope key
+    */
+   void setScope(ScopeKey key);
+   
+   /**
+    * Get the mutable scope
+    * 
+    * @return the mutable scope
+    */
+   ScopeKey getMutableScope();
+   
+   /**
+    * Set the mutable scope
+    * 
+    * @param key the mutable scope key
+    */
+   void setMutableScope(ScopeKey key);
+
+   /**
+    * Get the metadata for this deployment context
+    * 
+    * @return the metadata
+    */
+   MetaData getMetaData();
+
+   /**
+    * Get the mutable metadata for this deployment context
+    * 
+    * @return the metadata
+    */
+   MutableMetaData getMutableMetaData();
+
+   /**
     * Get the deployment state
     * 
     * @return the state
@@ -320,4 +365,9 @@
     * @param problem the problem
     */
    void setProblem(Throwable problem);
+   
+   /**
+    * Cleanup the deployment context
+    */
+   void cleanup();
 }

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-08-30 04:58:25 UTC (rev 64959)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/DeploymentUnit.java	2007-08-30 08:39:48 UTC (rev 64960)
@@ -28,6 +28,9 @@
 import org.jboss.dependency.spi.DependencyItem;
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.attachments.MutableAttachments;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.metadata.spi.MutableMetaData;
+import org.jboss.metadata.spi.scope.ScopeKey;
 
 /**
  * DeploymentUnit.<p>
@@ -82,8 +85,50 @@
     * in this deployment.
     */
    Set<String> getTypes();
+   
+   /**
+    * Get the scope
+    * 
+    * @return the scope
+    */
+   ScopeKey getScope();
+   
+   /**
+    * Set the scope
+    * 
+    * @param key the scope key
+    */
+   void setScope(ScopeKey key);
+   
+   /**
+    * Get the mutable scope
+    * 
+    * @return the mutable scope
+    */
+   ScopeKey getMutableScope();
+   
+   /**
+    * Set the mutable scope
+    * 
+    * @param key the mutable scope key
+    */
+   void setMutableScope(ScopeKey key);
 
    /**
+    * Get the metadata for this deployment unit
+    * 
+    * @return the metadata
+    */
+   MetaData getMetaData();
+
+   /**
+    * Get the mutable metadata for this deployment unit
+    * 
+    * @return the metadata
+    */
+   MutableMetaData getMutableMetaData();
+   
+   /**
     * Gets the classloader for this deployment unit
     * 
     * @return the classloader
@@ -146,6 +191,13 @@
    List<DeploymentUnit> getChildren();
    
    /**
+    * Get the components
+    * 
+    * @return the components
+    */
+   List<DeploymentUnit> getComponents();
+   
+   /**
     * Whether this unit is a component
     * 
     * @return true for a component

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-08-30 04:58:25 UTC (rev 64959)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java	2007-08-30 08:39:48 UTC (rev 64960)
@@ -45,7 +45,15 @@
 import org.jboss.deployers.structure.spi.DeploymentContextVisitor;
 import org.jboss.deployers.structure.spi.DeploymentResourceLoader;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.scope.ScopeBuilder;
+import org.jboss.deployers.structure.spi.scope.helpers.DefaultScopeBuilder;
 import org.jboss.logging.Logger;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.metadata.spi.MutableMetaData;
+import org.jboss.metadata.spi.loader.MutableMetaDataLoader;
+import org.jboss.metadata.spi.repository.MutableMetaDataRepository;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrieval;
+import org.jboss.metadata.spi.scope.ScopeKey;
 
 /**
  * AbstractDeploymentContext.
@@ -60,7 +68,7 @@
    private static final long serialVersionUID = 7368360479461613969L;
 
    /** The log */
-   protected Logger log = Logger.getLogger(getClass());
+   private static final Logger log = Logger.getLogger(AbstractDeploymentContext.class);
    
    /** The name */
    private String name;
@@ -113,7 +121,159 @@
    /** The context comparator */
    private Comparator<DeploymentContext> comparator = DefaultDeploymentContextComparator.INSTANCE;
    
+   /** The scope */
+   private ScopeKey scope;
+   
+   /** The mutable scope */
+   private ScopeKey mutableScope;
+
    /**
+    * Get the scope builder for a deployment context
+    * 
+    * @param deploymentContext the deployment context
+    * @return the scope builder
+    */
+   public static ScopeBuilder getScopeBuilder(DeploymentContext deploymentContext)
+   {
+      if (deploymentContext == null)
+         throw new IllegalArgumentException("Null deployment context");
+      ScopeBuilder builder = deploymentContext.getTransientAttachments().getAttachment(ScopeBuilder.class);
+      if (builder != null)
+         return builder;
+      DeploymentContext parent = deploymentContext.getParent();
+      if (parent != null)
+         return getScopeBuilder(parent);
+      return DefaultScopeBuilder.INSTANCE;
+   }
+
+   /**
+    * Get the repository for a deployment context
+    * 
+    * @param deploymentContext the deployment context
+    * @return the repository
+    */
+   public static MutableMetaDataRepository getRepository(DeploymentContext deploymentContext)
+   {
+      if (deploymentContext == null)
+         throw new IllegalArgumentException("Null deployment context");
+
+      MutableMetaDataRepository repository = deploymentContext.getTransientAttachments().getAttachment(MutableMetaDataRepository.class);
+      if (repository != null)
+         return repository;
+      DeploymentContext parent = deploymentContext.getParent();
+      if (parent == null)
+         return null;
+      return getRepository(parent);
+   }
+
+   /**
+    * Cleanup the repository
+    * 
+    * @param deploymentContext the deployment context
+    */
+   public static void cleanupRepository(DeploymentContext deploymentContext)
+   {
+      MutableMetaDataRepository repository = getRepository(deploymentContext);
+      if (repository == null)
+         return;
+      
+      try
+      {
+         ScopeKey scope = deploymentContext.getScope();
+         repository.removeMetaDataRetrieval(scope);
+      }
+      catch (Throwable ignored)
+      {
+      }
+
+      try
+      {
+         ScopeKey scope = deploymentContext.getMutableScope();
+         repository.removeMetaDataRetrieval(scope);
+      }
+      catch (Throwable ignored)
+      {
+      }
+   }
+
+   /**
+    * Get the metadata for a deployment context
+    * 
+    * @param deploymentContext the deployment context
+    * @return the metaData
+    */
+   public static MetaData getMetaData(DeploymentContext deploymentContext)
+   {
+      MutableMetaDataRepository repository = getRepository(deploymentContext);
+      if (repository == null)
+         return null;
+      
+      MetaData metaData = repository.getMetaData(deploymentContext.getScope());
+      if (metaData == null)
+      {
+         initMetaDataRetrieval(repository, deploymentContext);
+         metaData = repository.getMetaData(deploymentContext.getScope());
+      }
+      return metaData;
+   }
+
+   /**
+    * Get the mutable metadata for a deployment context
+    * 
+    * @param deploymentContext the deployment context
+    * @return the metaData
+    */
+   public static MutableMetaDataLoader getMutableMetaData(DeploymentContext deploymentContext)
+   {
+      MutableMetaDataRepository repository = getRepository(deploymentContext);
+      if (repository == null)
+         return null;
+
+      ScopeKey mutableScope = deploymentContext.getMutableScope();
+      MetaDataRetrieval retrieval = repository.getMetaDataRetrieval(mutableScope);
+      if (retrieval == null)
+      {
+         initMutableMetaDataRetrieval(repository, deploymentContext);
+         retrieval = repository.getMetaDataRetrieval(mutableScope);
+      }
+      if (retrieval == null || retrieval instanceof MutableMetaDataLoader == false)
+         return null;
+      return (MutableMetaDataLoader) retrieval;
+   }
+
+   /**
+    * Initialise the metadata retrieval for a deployment context
+    * 
+    * @param deploymentContext the deployment context
+    */
+   private static void initMetaDataRetrieval(MutableMetaDataRepository repository, DeploymentContext deploymentContext)
+   {
+      if (deploymentContext == null)
+         throw new IllegalArgumentException("Null deployment context");
+
+      ScopeBuilder builder = deploymentContext.getTransientAttachments().getAttachment(ScopeBuilder.class);
+      if (builder == null)
+         builder = DefaultScopeBuilder.INSTANCE;
+      builder.initMetaDataRetrieval(repository, deploymentContext);
+   }
+
+   /**
+    * Initialise the metadata retrieval for a deployment context
+    * 
+    * @param deploymentContext the deployment context
+    */
+   private static void initMutableMetaDataRetrieval(MutableMetaDataRepository repository, DeploymentContext deploymentContext)
+   {
+      if (deploymentContext == null)
+         throw new IllegalArgumentException("Null deployment context");
+
+      ScopeBuilder builder = deploymentContext.getTransientAttachments().getAttachment(ScopeBuilder.class);
+      if (builder == null)
+         builder = DefaultScopeBuilder.INSTANCE;
+      builder.initMutableMetaDataRetrieval(repository, deploymentContext);
+   }
+   
+   /**
     * For serialization
     */
    public AbstractDeploymentContext()
@@ -194,7 +354,47 @@
    {
       return deploymentTypes;
    }
+   
+   public ScopeKey getScope()
+   {
+      if (scope == null)
+      {
+         ScopeBuilder builder = getScopeBuilder(this);
+         scope = builder.getDeploymentScope(this);
+      }
+      return scope;
+   }
 
+   public void setScope(ScopeKey scope)
+   {
+      this.scope = scope;
+   }
+
+   public ScopeKey getMutableScope()
+   {
+      if (mutableScope == null)
+      {
+         ScopeBuilder builder = getScopeBuilder(this);
+         mutableScope = builder.getMutableDeploymentScope(this);
+      }
+      return mutableScope;
+   }
+
+   public void setMutableScope(ScopeKey mutableScope)
+   {
+      this.mutableScope = mutableScope;
+   }
+
+   public MetaData getMetaData()
+   {
+      return getMetaData(this);
+   }
+
+   public MutableMetaData getMutableMetaData()
+   {
+      return getMutableMetaData(this);
+   }
+
    public DeploymentState getState()
    {
       return state;
@@ -373,6 +573,7 @@
       if (componentComponents.isEmpty() == false)
          log.warn("Removing component " + name + " which still has components " + componentComponents);
       boolean result = components.remove(component);
+      component.cleanup();
       if (result)
          log.debug("Removed component " + component.getName() + " from " + getName());
       return result;
@@ -514,6 +715,11 @@
       deployed = true;
    }
 
+   public void cleanup()
+   {
+      cleanupRepository(this);
+   }
+   
    @Override
    public String toString()
    {

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-08-30 04:58:25 UTC (rev 64959)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentUnit.java	2007-08-30 08:39:48 UTC (rev 64960)
@@ -41,6 +41,9 @@
 import org.jboss.deployers.structure.spi.DeploymentContext;
 import org.jboss.deployers.structure.spi.DeploymentResourceLoader;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.metadata.spi.MutableMetaData;
+import org.jboss.metadata.spi.scope.ScopeKey;
 
 /**
  * AbstractDeploymentUnit.<p>
@@ -100,6 +103,36 @@
       return deploymentContext.getTypes();
    }
 
+   public ScopeKey getScope()
+   {
+      return deploymentContext.getScope();
+   }
+
+   public void setScope(ScopeKey key)
+   {
+      deploymentContext.setScope(key);
+   }
+
+   public ScopeKey getMutableScope()
+   {
+      return deploymentContext.getMutableScope();
+   }
+
+   public void setMutableScope(ScopeKey key)
+   {
+      deploymentContext.setMutableScope(key);
+   }
+
+   public MetaData getMetaData()
+   {
+      return deploymentContext.getMetaData();
+   }
+
+   public MutableMetaData getMutableMetaData()
+   {
+      return deploymentContext.getMutableMetaData();
+   }
+
    public ClassLoader getClassLoader()
    {
       ClassLoader cl = deploymentContext.getClassLoader();
@@ -150,6 +183,21 @@
       return result;
    }
 
+   public List<DeploymentUnit> getComponents()
+   {
+      List<DeploymentContext> components = deploymentContext.getComponents();
+      if (components == null || components.isEmpty())
+         return Collections.emptyList();
+      
+      List<DeploymentUnit> result = new ArrayList<DeploymentUnit>(components.size());
+      for (DeploymentContext component : components)
+      {
+         DeploymentUnit unit = component.getDeploymentUnit();
+         result.add(unit);
+      }
+      return result;
+   }
+
    /**
     * Create a component deployment context
     * 

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-08-30 04:58:25 UTC (rev 64959)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContext.java	2007-08-30 08:39:48 UTC (rev 64960)
@@ -39,7 +39,11 @@
 import org.jboss.deployers.structure.spi.DeploymentContextVisitor;
 import org.jboss.deployers.structure.spi.DeploymentResourceLoader;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.scope.ScopeBuilder;
 import org.jboss.logging.Logger;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.metadata.spi.MutableMetaData;
+import org.jboss.metadata.spi.scope.ScopeKey;
 
 /**
  * AbstractDeploymentContext.
@@ -74,6 +78,12 @@
    /** The managed objects */
    private transient MutableAttachments transientManagedObjects = AttachmentsFactory.createMutableAttachments();
    
+   /** The scope */
+   private ScopeKey scope;
+   
+   /** The mutable scope */
+   private ScopeKey mutableScope;
+   
    /**
     * For serialization
     */
@@ -138,6 +148,46 @@
       return parent.getTypes();
    }
 
+   public ScopeKey getScope()
+   {
+      if (scope == null)
+      {
+         ScopeBuilder builder = AbstractDeploymentContext.getScopeBuilder(this);
+         scope = builder.getComponentScope(this);
+      }
+      return scope;
+   }
+
+   public void setScope(ScopeKey scope)
+   {
+      this.scope = scope;
+   }
+
+   public ScopeKey getMutableScope()
+   {
+      if (mutableScope == null)
+      {
+         ScopeBuilder builder = AbstractDeploymentContext.getScopeBuilder(this);
+         mutableScope = builder.getMutableComponentScope(this);
+      }
+      return mutableScope;
+   }
+
+   public void setMutableScope(ScopeKey mutableScope)
+   {
+      this.mutableScope = mutableScope;
+   }
+
+   public MetaData getMetaData()
+   {
+      return AbstractDeploymentContext.getMetaData(this);
+   }
+
+   public MutableMetaData getMutableMetaData()
+   {
+      return AbstractDeploymentContext.getMutableMetaData(this);
+   }
+
    public DeploymentState getState()
    {
       return parent.getState();
@@ -254,7 +304,9 @@
    {
       if (component == null)
          throw new IllegalArgumentException("Null component");
-      return components.remove(component);
+      boolean result = components.remove(component);
+      component.cleanup();
+      return result;
    }
 
    public ClassLoader getResourceClassLoader()
@@ -399,6 +451,11 @@
       return parent.isDeployed();
    }
 
+   public void cleanup()
+   {
+      AbstractDeploymentContext.cleanupRepository(this);
+   }
+
    public String toString()
    {
       StringBuilder buffer = new StringBuilder();

Added: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/scope/ScopeBuilder.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/scope/ScopeBuilder.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/scope/ScopeBuilder.java	2007-08-30 08:39:48 UTC (rev 64960)
@@ -0,0 +1,83 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, 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.structure.spi.scope;
+
+import org.jboss.deployers.structure.spi.DeploymentContext;
+import org.jboss.metadata.spi.repository.MutableMetaDataRepository;
+import org.jboss.metadata.spi.scope.ScopeKey;
+
+/**
+ * ScopeBuilder.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface ScopeBuilder
+{
+   /**
+    * Get the scope for a deployment
+    * 
+    * @param context the context
+    * @return the key
+    */
+   ScopeKey getDeploymentScope(DeploymentContext context);
+
+   /**
+    * Get the mutable scope for a deployment
+    * 
+    * @param context the context
+    * @return the key
+    */
+   ScopeKey getMutableDeploymentScope(DeploymentContext context);
+
+   /**
+    * Get the scope for a component
+    * 
+    * @param context the context
+    * @return the key
+    */
+   ScopeKey getComponentScope(DeploymentContext context);
+
+   /**
+    * Get the mutable scope for a component
+    * 
+    * @param context the context
+    * @return the key
+    */
+   ScopeKey getMutableComponentScope(DeploymentContext context);
+   
+   /**
+    * Initialise the metadata retrievals for a deployment context
+    *
+    * @param repository the repository
+    * @param context the context
+    */
+   void initMetaDataRetrieval(MutableMetaDataRepository repository, DeploymentContext context);
+   
+   /**
+    * Initialise the mutable metadata retrieval for a deployment context
+    *
+    * @param repository the repository
+    * @param context the context
+    */
+   void initMutableMetaDataRetrieval(MutableMetaDataRepository repository, DeploymentContext context);
+}

Added: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/scope/helpers/DefaultScopeBuilder.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/scope/helpers/DefaultScopeBuilder.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/scope/helpers/DefaultScopeBuilder.java	2007-08-30 08:39:48 UTC (rev 64960)
@@ -0,0 +1,138 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, 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.structure.spi.scope.helpers;
+
+import java.util.ArrayList;
+
+import org.jboss.deployers.structure.spi.DeploymentContext;
+import org.jboss.deployers.structure.spi.scope.ScopeBuilder;
+import org.jboss.metadata.plugins.context.AbstractMetaDataContext;
+import org.jboss.metadata.plugins.loader.memory.MemoryMetaDataLoader;
+import org.jboss.metadata.spi.repository.MutableMetaDataRepository;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrieval;
+import org.jboss.metadata.spi.scope.CommonLevels;
+import org.jboss.metadata.spi.scope.Scope;
+import org.jboss.metadata.spi.scope.ScopeKey;
+
+/**
+ * DefaultScopeBuilder.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class DefaultScopeBuilder implements ScopeBuilder
+{
+   /** The singleton instance */
+   public static final DefaultScopeBuilder INSTANCE = new DefaultScopeBuilder();
+
+   public ScopeKey getDeploymentScope(DeploymentContext context)
+   {
+      if (context == null)
+         throw new IllegalArgumentException("Null context");
+      
+      DeploymentContext top = context.getTopLevel();
+      
+      ScopeKey result = ScopeKey.DEFAULT_SCOPE.clone();
+      result.addScope(CommonLevels.APPLICATION, top.getName());
+      result.addScope(CommonLevels.DEPLOYMENT, context.getName());
+      return result;
+   }
+
+   public ScopeKey getMutableDeploymentScope(DeploymentContext context)
+   {
+      if (context == null)
+         throw new IllegalArgumentException("Null context");
+
+      if (context.isTopLevel())
+         return new ScopeKey(CommonLevels.APPLICATION, context.getName());
+      else
+         return new ScopeKey(CommonLevels.DEPLOYMENT, context.getName());
+   }
+
+   public ScopeKey getComponentScope(DeploymentContext context)
+   {
+      if (context == null)
+         throw new IllegalArgumentException("Null context");
+
+      DeploymentContext parent = context;
+      while (parent.isComponent())
+      {
+         parent = context.getParent();
+         if (parent == null)
+            throw new IllegalStateException("Component has no regular parent?");
+      }
+      ScopeKey result = parent.getScope().clone();
+      result.addScope(CommonLevels.INSTANCE, context.getName());
+      return result;
+   }
+
+   public ScopeKey getMutableComponentScope(DeploymentContext context)
+   {
+      if (context == null)
+         throw new IllegalArgumentException("Null context");
+
+      return new ScopeKey(CommonLevels.INSTANCE, context.getName());
+   }
+
+   public void initMetaDataRetrieval(MutableMetaDataRepository repository, DeploymentContext context)
+   {
+      if (repository == null)
+         throw new IllegalArgumentException("Null repository");
+      if (context == null)
+         throw new IllegalArgumentException("Null context");
+
+      ScopeKey scopeKey = context.getScope();
+      
+      ArrayList<MetaDataRetrieval> retrievals = new ArrayList<MetaDataRetrieval>();
+      for (Scope scope : scopeKey.getScopes())
+      {
+         ScopeKey thisScope = new ScopeKey(scope);
+         MetaDataRetrieval retrieval = repository.getMetaDataRetrieval(thisScope);
+         if (retrieval == null)
+         {
+            retrieval = new MemoryMetaDataLoader(thisScope);
+            repository.addMetaDataRetrieval(retrieval);
+         }
+         retrievals.add(0, retrieval);
+      }
+      AbstractMetaDataContext metaDataContext = new AbstractMetaDataContext(null, retrievals);
+      repository.addMetaDataRetrieval(metaDataContext);
+   }
+
+   public void initMutableMetaDataRetrieval(MutableMetaDataRepository repository, DeploymentContext context)
+   {
+      if (repository == null)
+         throw new IllegalArgumentException("Null repository");
+      if (context == null)
+         throw new IllegalArgumentException("Null context");
+
+      ScopeKey scopeKey = context.getMutableScope();
+      MetaDataRetrieval retrieval = repository.getMetaDataRetrieval(scopeKey);
+      if (retrieval == null)
+      {
+         retrieval = new MemoryMetaDataLoader(scopeKey);
+         repository.addMetaDataRetrieval(retrieval);
+      }
+      AbstractMetaDataContext metaDataContext = new AbstractMetaDataContext(null, retrieval);
+      repository.addMetaDataRetrieval(metaDataContext);
+   }
+}

Modified: projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentContext.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentContext.java	2007-08-30 04:58:25 UTC (rev 64959)
+++ projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentContext.java	2007-08-30 08:39:48 UTC (rev 64960)
@@ -31,6 +31,7 @@
 import org.jboss.deployers.structure.spi.helpers.AbstractDeploymentContext;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentContext;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentResourceLoader;
+import org.jboss.logging.Logger;
 import org.jboss.virtual.VFSUtils;
 import org.jboss.virtual.VirtualFile;
 
@@ -45,6 +46,9 @@
    /** The serialVersionUID */
    private static final long serialVersionUID = 4474515937180482776L;
 
+   /** The log */
+   private static final Logger log = Logger.getLogger(AbstractVFSDeploymentContext.class);
+
    /** The root virtual file */
    private VirtualFile root;
    




More information about the jboss-cvs-commits mailing list