[jboss-cvs] JBossAS SVN: r66175 - in projects/microcontainer/trunk: deployers-impl/src/tests/org/jboss/test/deployers/scope/support and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Oct 16 07:35:59 EDT 2007


Author: adrian at jboss.org
Date: 2007-10-16 07:35:59 -0400 (Tue, 16 Oct 2007)
New Revision: 66175

Added:
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestClassAnnotation.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestClassAspect.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponent1.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponent2.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentCreator.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentMetaDataLoader.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentMetaDataRepositoryLoader.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentMetaDataRepositoryPopulator.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/test/LoaderMetaDataRepositoryUnitTestCase.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/test/PopulateMetaDataRepositoryUnitTestCase.java
Modified:
   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/TestComponentMetaData.java
   projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java
Log:
Examples of instance level annotations coming from object models

Modified: 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	2007-10-16 11:02:33 UTC (rev 66174)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/DeployersScopeTestSuite.java	2007-10-16 11:35:59 UTC (rev 66175)
@@ -26,6 +26,8 @@
 import junit.textui.TestRunner;
 
 import org.jboss.test.deployers.scope.test.DeployerScopeUnitTestCase;
+import org.jboss.test.deployers.scope.test.LoaderMetaDataRepositoryUnitTestCase;
+import org.jboss.test.deployers.scope.test.PopulateMetaDataRepositoryUnitTestCase;
 
 /**
  * Deployers Scope Test Suite.
@@ -45,6 +47,8 @@
       TestSuite suite = new TestSuite("Deployers Scope Tests");
 
       suite.addTest(DeployerScopeUnitTestCase.suite());
+      suite.addTest(PopulateMetaDataRepositoryUnitTestCase.suite());
+      suite.addTest(LoaderMetaDataRepositoryUnitTestCase.suite());
 
       return suite;
    }

Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestClassAnnotation.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestClassAnnotation.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestClassAnnotation.java	2007-10-16 11:35:59 UTC (rev 66175)
@@ -0,0 +1,37 @@
+/*
+* 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.test.deployers.scope.support;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * TestClassAnnotation.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface TestClassAnnotation
+{
+   String where();
+}

Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestClassAspect.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestClassAspect.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestClassAspect.java	2007-10-16 11:35:59 UTC (rev 66175)
@@ -0,0 +1,48 @@
+/*
+* 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.test.deployers.scope.support;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+
+/**
+ * TestClassAspect.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestClassAspect implements Interceptor
+{
+   public static TestClassAnnotation classAnnotation;
+   
+   public String getName()
+   {
+      return getClass().getName();
+   }
+
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      classAnnotation = invocation.getAdvisor().getMetadata().getAnnotation(TestClassAnnotation.class);
+      return invocation.invokeNext();
+   }
+
+}

Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponent1.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponent1.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponent1.java	2007-10-16 11:35:59 UTC (rev 66175)
@@ -0,0 +1,36 @@
+/*
+* 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.test.deployers.scope.support;
+
+/**
+ * TestComponent1.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+ at TestClassAnnotation(where="Class")
+public class TestComponent1
+{
+   public void doSomething()
+   {
+   }
+}

Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponent2.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponent2.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponent2.java	2007-10-16 11:35:59 UTC (rev 66175)
@@ -0,0 +1,35 @@
+/*
+* 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.test.deployers.scope.support;
+
+/**
+ * TestComponent2.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestComponent2
+{
+   public void doSomething()
+   {
+   }
+}

Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentCreator.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentCreator.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentCreator.java	2007-10-16 11:35:59 UTC (rev 66175)
@@ -0,0 +1,100 @@
+/*
+* 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.test.deployers.scope.support;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.advice.AdviceBinding;
+import org.jboss.aop.advice.GenericInterceptorFactory;
+import org.jboss.aop.proxy.container.AOPProxyFactory;
+import org.jboss.aop.proxy.container.AOPProxyFactoryParameters;
+import org.jboss.aop.proxy.container.GeneratedAOPProxyFactory;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployerWithInput;
+import org.jboss.deployers.spi.deployer.helpers.DeploymentVisitor;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * TestComponentMetaDataRepositoryPopulator.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestComponentCreator extends AbstractRealDeployerWithInput<TestComponentMetaData>
+{
+   AOPProxyFactory proxyFactory;
+   
+   public TestComponentCreator()
+   {
+      setDeploymentVisitor(new TestComponentMetaDataVisitor());
+      setWantComponents(true);
+      proxyFactory = new GeneratedAOPProxyFactory();
+      
+      AspectManager domain = AspectManager.instance();
+      
+      try
+      {
+         AdviceBinding binding = new AdviceBinding("execution(* @" + TestClassAnnotation.class.getName() + "->*(..))", null);
+         binding.addInterceptorFactory(new GenericInterceptorFactory(TestClassAspect.class));
+         domain.addBinding(binding);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Error setting up advices ", e);
+      }
+   }
+   
+   public class TestComponentMetaDataVisitor implements DeploymentVisitor<TestComponentMetaData>
+   {
+      public Class<TestComponentMetaData> getVisitorType()
+      {
+         return TestComponentMetaData.class;
+      }
+
+      public void deploy(DeploymentUnit unit, TestComponentMetaData deployment) throws DeploymentException
+      {
+         Class<?> deploymentClass = deployment.clazz;
+         
+         Object target;
+         
+         try
+         {
+            target = deploymentClass.newInstance();
+         }
+         catch (Exception e)
+         {
+            throw DeploymentException.rethrowAsDeploymentException("Error instantiating object", e);
+         }
+         
+         AOPProxyFactoryParameters params = new AOPProxyFactoryParameters();
+         params.setTarget(target);
+         params.setMetaData(unit.getMetaData());
+         params.setMetaDataHasInstanceLevelData(true);
+         Object proxy = proxyFactory.createAdvisedProxy(params);
+         unit.addAttachment("proxy", proxy);
+      }
+
+      public void undeploy(DeploymentUnit unit, TestComponentMetaData deployment)
+      {
+         unit.removeAttachment("proxy");
+      }
+   }
+}

Modified: 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	2007-10-16 11:02:33 UTC (rev 66174)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentMetaData.java	2007-10-16 11:35:59 UTC (rev 66175)
@@ -21,6 +21,10 @@
 */
 package org.jboss.test.deployers.scope.support;
 
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * TestComponentMetaData.
  * 
@@ -30,7 +34,11 @@
 public class TestComponentMetaData
 {
    public String name;
+
+   public Class<?> clazz;
    
+   public List<Annotation> classAnnotations = new ArrayList<Annotation>();
+   
    public TestComponentMetaData(String name)
    {
       this.name = name;

Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentMetaDataLoader.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentMetaDataLoader.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentMetaDataLoader.java	2007-10-16 11:35:59 UTC (rev 66175)
@@ -0,0 +1,92 @@
+/*
+* 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.test.deployers.scope.support;
+
+import java.lang.annotation.Annotation;
+
+import org.jboss.metadata.plugins.loader.AbstractMetaDataLoader;
+import org.jboss.metadata.spi.retrieval.AnnotationItem;
+import org.jboss.metadata.spi.retrieval.AnnotationsItem;
+import org.jboss.metadata.spi.retrieval.MetaDataItem;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrieval;
+import org.jboss.metadata.spi.retrieval.simple.SimpleAnnotationItem;
+import org.jboss.metadata.spi.retrieval.simple.SimpleAnnotationsItem;
+import org.jboss.metadata.spi.scope.ScopeKey;
+import org.jboss.metadata.spi.signature.Signature;
+
+/**
+ * TestComponentMetaDataLoader.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestComponentMetaDataLoader extends AbstractMetaDataLoader
+{
+   TestComponentMetaData componentMetaData;
+   
+   public TestComponentMetaDataLoader(ScopeKey scopeKey, TestComponentMetaData componentMetaData)
+   {
+      super(scopeKey);
+      this.componentMetaData = componentMetaData;
+   }
+   
+   public MetaDataRetrieval getComponentMetaDataRetrieval(Signature signature)
+   {
+      // TODO method/field annotations go here
+      return null;
+   }
+
+   public boolean isEmpty()
+   {
+      return componentMetaData.classAnnotations.isEmpty();
+   }
+
+   public <T extends Annotation> AnnotationItem<T> retrieveAnnotation(Class<T> annotationType)
+   {
+      for (Annotation annotation : componentMetaData.classAnnotations)
+      {
+         if (annotation.annotationType().equals(annotationType))
+            return new SimpleAnnotationItem<T>(annotationType.cast(annotation));
+      }
+      return null;
+   }
+
+   @SuppressWarnings("unchecked")
+   public AnnotationsItem retrieveAnnotations()
+   {
+      if (componentMetaData.classAnnotations.isEmpty())
+         return SimpleAnnotationsItem.NO_ANNOTATIONS;
+      
+      Annotation[] annotations = componentMetaData.classAnnotations.toArray(new Annotation[0]);
+      AnnotationItem[] items = new AnnotationItem[annotations.length];
+      for (int i = 0; i < items.length; ++i)
+         items[i] = new SimpleAnnotationItem(annotations[i]);
+      return new SimpleAnnotationsItem(items);
+   }
+
+   @SuppressWarnings("unchecked")
+   public MetaDataItem retrieveMetaData(String name)
+   {
+      // TODO Non annotations go here
+      return null;
+   }
+}

Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentMetaDataRepositoryLoader.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentMetaDataRepositoryLoader.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentMetaDataRepositoryLoader.java	2007-10-16 11:35:59 UTC (rev 66175)
@@ -0,0 +1,89 @@
+/*
+* 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.test.deployers.scope.support;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployerWithInput;
+import org.jboss.deployers.spi.deployer.helpers.DeploymentVisitor;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.metadata.plugins.loader.reflection.AnnotatedElementMetaDataLoader;
+import org.jboss.metadata.plugins.repository.basic.BasicMetaDataRepository;
+import org.jboss.metadata.spi.scope.Scope;
+import org.jboss.metadata.spi.scope.ScopeKey;
+
+/**
+ * TestComponentMetaDataRepositoryPopulator.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestComponentMetaDataRepositoryLoader extends AbstractRealDeployerWithInput<TestComponentMetaData>
+{
+   private BasicMetaDataRepository repository;
+
+   public TestComponentMetaDataRepositoryLoader()
+   {
+      setDeploymentVisitor(new TestComponentMetaDataVisitor());
+      setWantComponents(true);
+      setOutput(TestComponentMetaData.class);
+   }
+   
+   public void setRepository(BasicMetaDataRepository repository)
+   {
+      this.repository = repository;
+   }
+   
+   public class TestComponentMetaDataVisitor implements DeploymentVisitor<TestComponentMetaData>
+   {
+      public Class<TestComponentMetaData> getVisitorType()
+      {
+         return TestComponentMetaData.class;
+      }
+
+      public void deploy(DeploymentUnit unit, TestComponentMetaData deployment) throws DeploymentException
+      {
+         // Create a scope for the class
+         AnnotatedElementMetaDataLoader loader = new AnnotatedElementMetaDataLoader(deployment.clazz);
+         repository.addMetaDataRetrieval(loader);
+
+         // Add it to our scope
+         ScopeKey key = unit.getScope();
+         for (Scope scope : loader.getScope().getScopes())
+            key.addScope(scope);
+         
+         // Add the loader
+         ScopeKey mutableScope = unit.getMutableScope();
+         TestComponentMetaDataLoader componentMetaDataLoader = new TestComponentMetaDataLoader(mutableScope, deployment);
+         repository.addMetaDataRetrieval(componentMetaDataLoader);
+      }
+
+      public void undeploy(DeploymentUnit unit, TestComponentMetaData deployment)
+      {
+         // Remove the scopes
+         AnnotatedElementMetaDataLoader loader = new AnnotatedElementMetaDataLoader(deployment.getClass());
+         repository.removeMetaDataRetrieval(loader.getScope());
+
+         ScopeKey mutableScope = unit.getMutableScope();
+         repository.removeMetaDataRetrieval(mutableScope);
+      }
+   }
+}

Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentMetaDataRepositoryPopulator.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentMetaDataRepositoryPopulator.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/support/TestComponentMetaDataRepositoryPopulator.java	2007-10-16 11:35:59 UTC (rev 66175)
@@ -0,0 +1,89 @@
+/*
+* 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.test.deployers.scope.support;
+
+import java.lang.annotation.Annotation;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployerWithInput;
+import org.jboss.deployers.spi.deployer.helpers.DeploymentVisitor;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.metadata.plugins.loader.reflection.AnnotatedElementMetaDataLoader;
+import org.jboss.metadata.plugins.repository.basic.BasicMetaDataRepository;
+import org.jboss.metadata.spi.MutableMetaData;
+import org.jboss.metadata.spi.scope.Scope;
+import org.jboss.metadata.spi.scope.ScopeKey;
+
+/**
+ * TestComponentMetaDataRepositoryPopulator.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestComponentMetaDataRepositoryPopulator extends AbstractRealDeployerWithInput<TestComponentMetaData>
+{
+   private BasicMetaDataRepository repository;
+
+   public TestComponentMetaDataRepositoryPopulator()
+   {
+      setDeploymentVisitor(new TestComponentMetaDataVisitor());
+      setWantComponents(true);
+      setOutput(TestComponentMetaData.class);
+   }
+   
+   public void setRepository(BasicMetaDataRepository repository)
+   {
+      this.repository = repository;
+   }
+   
+   public class TestComponentMetaDataVisitor implements DeploymentVisitor<TestComponentMetaData>
+   {
+      public Class<TestComponentMetaData> getVisitorType()
+      {
+         return TestComponentMetaData.class;
+      }
+
+      public void deploy(DeploymentUnit unit, TestComponentMetaData deployment) throws DeploymentException
+      {
+         // Create a scope for the class
+         AnnotatedElementMetaDataLoader loader = new AnnotatedElementMetaDataLoader(deployment.clazz);
+         repository.addMetaDataRetrieval(loader);
+
+         // Add it to our scope
+         ScopeKey key = unit.getScope();
+         for (Scope scope : loader.getScope().getScopes())
+            key.addScope(scope);
+         
+         // Populate the instance annotations
+         MutableMetaData mutable = unit.getMutableMetaData();
+         for (Annotation annotation : deployment.classAnnotations)
+            mutable.addAnnotation(annotation);
+      }
+
+      public void undeploy(DeploymentUnit unit, TestComponentMetaData deployment)
+      {
+         // Remove the scope
+         AnnotatedElementMetaDataLoader loader = new AnnotatedElementMetaDataLoader(deployment.getClass());
+         repository.removeMetaDataRetrieval(loader.getScope());
+      }
+   }
+}

Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/test/LoaderMetaDataRepositoryUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/test/LoaderMetaDataRepositoryUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/test/LoaderMetaDataRepositoryUnitTestCase.java	2007-10-16 11:35:59 UTC (rev 66175)
@@ -0,0 +1,163 @@
+/*
+* 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.lang.annotation.Annotation;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.annotation.factory.AnnotationCreator;
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+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.structure.spi.DeploymentUnit;
+import org.jboss.metadata.plugins.repository.basic.BasicMetaDataRepository;
+import org.jboss.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.scope.support.TestClassAnnotation;
+import org.jboss.test.deployers.scope.support.TestClassAspect;
+import org.jboss.test.deployers.scope.support.TestComponent1;
+import org.jboss.test.deployers.scope.support.TestComponent2;
+import org.jboss.test.deployers.scope.support.TestComponentCreator;
+import org.jboss.test.deployers.scope.support.TestComponentDeployer;
+import org.jboss.test.deployers.scope.support.TestComponentMetaData;
+import org.jboss.test.deployers.scope.support.TestComponentMetaDataContainer;
+import org.jboss.test.deployers.scope.support.TestComponentMetaDataRepositoryLoader;
+
+/**
+ * LoaderMetaDataRepositoryUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class LoaderMetaDataRepositoryUnitTestCase extends AbstractDeployerTest
+{
+   private TestComponentDeployer deployer1 = new TestComponentDeployer();
+   private TestComponentMetaDataRepositoryLoader deployer2 = new TestComponentMetaDataRepositoryLoader();
+   private TestComponentCreator deployer3 = new TestComponentCreator();
+
+   private BasicMetaDataRepository repository;
+   
+   public static Test suite()
+   {
+      return new TestSuite(LoaderMetaDataRepositoryUnitTestCase.class);
+   }
+   
+   public LoaderMetaDataRepositoryUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testClassAnnotation() throws Exception
+   {
+      DeployerClient main = getMainDeployer();
+      
+      Deployment a = createSimpleDeployment("A");
+      TestComponentMetaData c = new TestComponentMetaData("C");
+      c.clazz = TestComponent1.class;
+      TestComponentMetaDataContainer md = new TestComponentMetaDataContainer(c);
+      addMetaData(a, md);
+      main.addDeployment(a);
+      try
+      {
+         main.process();
+         main.checkComplete();
+         DeploymentUnit unit = getDeploymentUnit(main, "A");
+         List<DeploymentUnit> components = unit.getComponents();
+         assertEquals(1, components.size());
+         DeploymentUnit component = components.get(0);
+         TestComponent1 proxy = component.getAttachment("proxy", TestComponent1.class);
+         
+         TestClassAspect.classAnnotation = null;
+         proxy.doSomething();
+         
+         TestClassAnnotation annotation = TestClassAspect.classAnnotation;
+         assertNotNull(annotation);
+         assertEquals("Class", annotation.where());
+      }
+      finally
+      {
+         main.removeDeployment(a);
+         main.process();
+      }
+   }
+
+   public void testInstanceAnnotation() throws Exception
+   {
+      DeployerClient main = getMainDeployer();
+      
+      Deployment a = createSimpleDeployment("A");
+      TestComponentMetaData c = new TestComponentMetaData("C");
+      c.clazz = TestComponent2.class;
+      c.classAnnotations.add((Annotation) AnnotationCreator.createAnnotation("@" + TestClassAnnotation.class.getName() + "(where=\"Instance\")", getClass().getClassLoader()));
+      TestComponentMetaDataContainer md = new TestComponentMetaDataContainer(c);
+      addMetaData(a, md);
+      main.addDeployment(a);
+      try
+      {
+         main.process();
+         main.checkComplete();
+         DeploymentUnit unit = getDeploymentUnit(main, "A");
+         List<DeploymentUnit> components = unit.getComponents();
+         assertEquals(1, components.size());
+         DeploymentUnit component = components.get(0);
+         TestComponent2 proxy = component.getAttachment("proxy", TestComponent2.class);
+         
+         TestClassAspect.classAnnotation = null;
+         proxy.doSomething();
+         
+         TestClassAnnotation annotation = TestClassAspect.classAnnotation;
+         assertNotNull(annotation);
+         assertEquals("Instance", annotation.where());
+      }
+      finally
+      {
+         main.removeDeployment(a);
+         main.process();
+      }
+   }
+   
+   protected static void addMetaData(PredeterminedManagedObjectAttachments attachments, TestComponentMetaDataContainer md)
+   {
+      MutableAttachments mutable = (MutableAttachments) attachments.getPredeterminedManagedObjects();
+      mutable.addAttachment(TestComponentMetaDataContainer.class, md);
+   }
+   
+   protected DeployerClient getMainDeployer()
+   {
+      return createMainDeployer(deployer1, deployer2, deployer3);
+   }
+
+   @Override
+   protected Deployers createDeployers()
+   {
+      DeployersImpl deployers = (DeployersImpl) super.createDeployers();
+      repository = new BasicMetaDataRepository();
+      deployers.setRepository(repository);
+      deployer2.setRepository(repository);
+      return deployers;
+   }
+}

Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/test/PopulateMetaDataRepositoryUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/test/PopulateMetaDataRepositoryUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/scope/test/PopulateMetaDataRepositoryUnitTestCase.java	2007-10-16 11:35:59 UTC (rev 66175)
@@ -0,0 +1,163 @@
+/*
+* 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.lang.annotation.Annotation;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.annotation.factory.AnnotationCreator;
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+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.structure.spi.DeploymentUnit;
+import org.jboss.metadata.plugins.repository.basic.BasicMetaDataRepository;
+import org.jboss.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.scope.support.TestClassAnnotation;
+import org.jboss.test.deployers.scope.support.TestClassAspect;
+import org.jboss.test.deployers.scope.support.TestComponent1;
+import org.jboss.test.deployers.scope.support.TestComponent2;
+import org.jboss.test.deployers.scope.support.TestComponentCreator;
+import org.jboss.test.deployers.scope.support.TestComponentDeployer;
+import org.jboss.test.deployers.scope.support.TestComponentMetaData;
+import org.jboss.test.deployers.scope.support.TestComponentMetaDataContainer;
+import org.jboss.test.deployers.scope.support.TestComponentMetaDataRepositoryPopulator;
+
+/**
+ * PopulateMetaDataRepositoryUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class PopulateMetaDataRepositoryUnitTestCase extends AbstractDeployerTest
+{
+   private TestComponentDeployer deployer1 = new TestComponentDeployer();
+   private TestComponentMetaDataRepositoryPopulator deployer2 = new TestComponentMetaDataRepositoryPopulator();
+   private TestComponentCreator deployer3 = new TestComponentCreator();
+
+   private BasicMetaDataRepository repository;
+   
+   public static Test suite()
+   {
+      return new TestSuite(PopulateMetaDataRepositoryUnitTestCase.class);
+   }
+   
+   public PopulateMetaDataRepositoryUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testClassAnnotation() throws Exception
+   {
+      DeployerClient main = getMainDeployer();
+      
+      Deployment a = createSimpleDeployment("A");
+      TestComponentMetaData c = new TestComponentMetaData("C");
+      c.clazz = TestComponent1.class;
+      TestComponentMetaDataContainer md = new TestComponentMetaDataContainer(c);
+      addMetaData(a, md);
+      main.addDeployment(a);
+      try
+      {
+         main.process();
+         main.checkComplete();
+         DeploymentUnit unit = getDeploymentUnit(main, "A");
+         List<DeploymentUnit> components = unit.getComponents();
+         assertEquals(1, components.size());
+         DeploymentUnit component = components.get(0);
+         TestComponent1 proxy = component.getAttachment("proxy", TestComponent1.class);
+         
+         TestClassAspect.classAnnotation = null;
+         proxy.doSomething();
+         
+         TestClassAnnotation annotation = TestClassAspect.classAnnotation;
+         assertNotNull(annotation);
+         assertEquals("Class", annotation.where());
+      }
+      finally
+      {
+         main.removeDeployment(a);
+         main.process();
+      }
+   }
+
+   public void testInstanceAnnotation() throws Exception
+   {
+      DeployerClient main = getMainDeployer();
+      
+      Deployment a = createSimpleDeployment("A");
+      TestComponentMetaData c = new TestComponentMetaData("C");
+      c.clazz = TestComponent2.class;
+      c.classAnnotations.add((Annotation) AnnotationCreator.createAnnotation("@" + TestClassAnnotation.class.getName() + "(where=\"Instance\")", getClass().getClassLoader()));
+      TestComponentMetaDataContainer md = new TestComponentMetaDataContainer(c);
+      addMetaData(a, md);
+      main.addDeployment(a);
+      try
+      {
+         main.process();
+         main.checkComplete();
+         DeploymentUnit unit = getDeploymentUnit(main, "A");
+         List<DeploymentUnit> components = unit.getComponents();
+         assertEquals(1, components.size());
+         DeploymentUnit component = components.get(0);
+         TestComponent2 proxy = component.getAttachment("proxy", TestComponent2.class);
+         
+         TestClassAspect.classAnnotation = null;
+         proxy.doSomething();
+         
+         TestClassAnnotation annotation = TestClassAspect.classAnnotation;
+         assertNotNull(annotation);
+         assertEquals("Instance", annotation.where());
+      }
+      finally
+      {
+         main.removeDeployment(a);
+         main.process();
+      }
+   }
+   
+   protected static void addMetaData(PredeterminedManagedObjectAttachments attachments, TestComponentMetaDataContainer md)
+   {
+      MutableAttachments mutable = (MutableAttachments) attachments.getPredeterminedManagedObjects();
+      mutable.addAttachment(TestComponentMetaDataContainer.class, md);
+   }
+   
+   protected DeployerClient getMainDeployer()
+   {
+      return createMainDeployer(deployer1, deployer2, deployer3);
+   }
+
+   @Override
+   protected Deployers createDeployers()
+   {
+      DeployersImpl deployers = (DeployersImpl) super.createDeployers();
+      repository = new BasicMetaDataRepository();
+      deployers.setRepository(repository);
+      deployer2.setRepository(repository);
+      return deployers;
+   }
+}

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-10-16 11:02:33 UTC (rev 66174)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java	2007-10-16 11:35:59 UTC (rev 66175)
@@ -50,6 +50,7 @@
 import org.jboss.logging.Logger;
 import org.jboss.metadata.spi.MetaData;
 import org.jboss.metadata.spi.MutableMetaData;
+import org.jboss.metadata.spi.context.MetaDataContext;
 import org.jboss.metadata.spi.loader.MutableMetaDataLoader;
 import org.jboss.metadata.spi.repository.MutableMetaDataRepository;
 import org.jboss.metadata.spi.retrieval.MetaDataRetrieval;
@@ -236,9 +237,30 @@
          initMutableMetaDataRetrieval(repository, deploymentContext);
          retrieval = repository.getMetaDataRetrieval(mutableScope);
       }
-      if (retrieval == null || retrieval instanceof MutableMetaDataLoader == false)
+      
+      // Nothing
+      if (retrieval == null)
          return null;
-      return (MutableMetaDataLoader) retrieval;
+
+      // This is mutable
+      if (retrieval instanceof MutableMetaDataLoader)
+         return (MutableMetaDataLoader) retrieval;
+
+      // We have a context, see if there is a mutable in the locals
+      if (retrieval instanceof MetaDataContext)
+      {
+         MetaDataContext context = (MetaDataContext) retrieval;
+         List<MetaDataRetrieval> locals = context.getLocalRetrievals();
+         if (locals != null)
+         {
+            for (MetaDataRetrieval local : locals)
+            {
+               if (local instanceof MutableMetaDataLoader)
+                  return (MutableMetaDataLoader) local;
+            }
+         }
+      }
+      return null;
    }
 
    /**




More information about the jboss-cvs-commits mailing list