[jboss-cvs] JBossAS SVN: r68101 - in projects/microcontainer/trunk/kernel/src: main/org/jboss/kernel/plugins/dependency and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Dec 10 09:28:05 EST 2007


Author: alesj
Date: 2007-12-10 09:28:05 -0500 (Mon, 10 Dec 2007)
New Revision: 68101

Added:
   projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/AbstractBeanAnnotationAdapter.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestAnnotationAdapter.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestAnnotationPlugin.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestApplyOnly.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestApplyOnlyBean.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestApplyOnlyPlugin.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanup.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanupBean.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanupOnly.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanupOnlyBean.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanupOnlyPlugin.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanupPlugin.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/AbstractBeanAnnotationAdapterTestCase.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/CleanupAnnotationTestCase.java
Modified:
   projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/BasicBeanAnnotationAdapter.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/BeanAnnotationAdapterFactory.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/DescribeAction.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/AnnotationSupportTestSuite.java
Log:
Annotations Cleanup(Only) check tests.

Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/AbstractBeanAnnotationAdapter.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/AbstractBeanAnnotationAdapter.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/AbstractBeanAnnotationAdapter.java	2007-12-10 14:28:05 UTC (rev 68101)
@@ -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.kernel.plugins.annotations;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Target;
+import java.lang.annotation.Retention;
+import java.lang.annotation.ElementType;
+
+import org.jboss.logging.Logger;
+import org.jboss.beans.metadata.spi.MetaDataVisitor;
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.kernel.spi.metadata.KernelMetaDataRepository;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.config.Configurator;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.metadata.spi.signature.ConstructorSignature;
+import org.jboss.metadata.spi.signature.MethodSignature;
+import org.jboss.metadata.spi.signature.FieldSignature;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.ConstructorInfo;
+import org.jboss.reflect.spi.MethodInfo;
+import org.jboss.reflect.spi.FieldInfo;
+
+/**
+ * Abstract bean annotation handler.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at SuppressWarnings("unchecked")
+public abstract class AbstractBeanAnnotationAdapter implements BeanAnnotationAdapter
+{
+   protected Logger log = Logger.getLogger(AbstractBeanAnnotationAdapter.class);
+
+   protected Set<AnnotationPlugin> classAnnotationPlugins = new HashSet<AnnotationPlugin>();
+   protected Set<AnnotationPlugin> constructorAnnotationPlugins = new HashSet<AnnotationPlugin>();
+   protected Set<AnnotationPlugin> propertyAnnotationPlugins = new HashSet<AnnotationPlugin>();
+   protected Set<AnnotationPlugin> methodAnnotationPlugins = new HashSet<AnnotationPlugin>();
+   protected Set<AnnotationPlugin> fieldAnnotationPlugins = new HashSet<AnnotationPlugin>();
+
+   protected void addAnnotationPlugin(AnnotationPlugin plugin)
+   {
+      Class<? extends Annotation> annotation = plugin.getAnnotation();
+      if (annotation.getAnnotation(Target.class) == null)
+         log.warn("Annotation " + annotation + " missing @Target annotation!");
+      if (annotation.getAnnotation(Retention.class) == null)
+         log.warn("Annotation " + annotation + " missing @Retention annotation!");
+
+      Set supported = plugin.getSupportedTypes();
+      if (supported.contains(ElementType.TYPE))
+      {
+         classAnnotationPlugins.add(plugin);
+      }
+      if (supported.contains(ElementType.CONSTRUCTOR))
+      {
+         constructorAnnotationPlugins.add(plugin);
+      }
+      if (supported.contains(ElementType.METHOD))
+      {
+         if (plugin instanceof PropertyAware)
+            propertyAnnotationPlugins.add(plugin);
+         else
+            methodAnnotationPlugins.add(plugin);
+      }
+      if (supported.contains(ElementType.FIELD))
+      {
+         fieldAnnotationPlugins.add(plugin);
+      }
+   }
+
+   public void applyAnnotations(MetaDataVisitor visitor) throws Throwable
+   {
+      handleAnnotations(visitor, true);
+   }
+
+   public void cleanAnnotations(MetaDataVisitor visitor) throws Throwable
+   {
+      handleAnnotations(visitor, false);
+   }
+
+   /**
+    * Handle apply or cleanup of annotations.
+    *
+    * @param visitor the metadata visitor
+    * @param isApplyPhase is this apply phase
+    * @throws Throwable for any error
+    */
+   protected void handleAnnotations(MetaDataVisitor visitor, boolean isApplyPhase) throws Throwable
+   {
+      if (visitor == null)
+         throw new IllegalArgumentException("Null meta data visitor.");
+
+      KernelControllerContext context = visitor.getControllerContext();
+      Kernel kernel = context.getKernel();
+      KernelMetaDataRepository repository = kernel.getMetaDataRepository();
+      MetaData retrieval = repository.getMetaData(context);
+
+      boolean trace = log.isTraceEnabled();
+      BeanInfo info = context.getBeanInfo();
+      Object name = context.getName();
+      if (trace)
+         log.trace(name + " apply annotations");
+
+      // class
+      ClassInfo classInfo = info.getClassInfo();
+      for(AnnotationPlugin plugin : classAnnotationPlugins)
+      {
+         if (isApplyPhase)
+            plugin.applyAnnotation(classInfo, retrieval, visitor);
+         else
+            plugin.cleanAnnotation(classInfo, retrieval, visitor);
+      }
+
+      // constructors
+      Set<ConstructorInfo> constructors = info.getConstructors();
+      if (constructors != null && constructors.isEmpty() == false)
+      {
+         for(ConstructorInfo ci : constructors)
+         {
+            Signature cis = new ConstructorSignature(Configurator.getParameterTypes(trace, ci.getParameterTypes()));
+            MetaData cmdr = retrieval.getComponentMetaData(cis);
+            if (cmdr != null)
+            {
+               for(AnnotationPlugin plugin : constructorAnnotationPlugins)
+               {
+                  if (isApplyPhase)
+                     plugin.applyAnnotation(ci, cmdr, visitor);
+                  else
+                     plugin.cleanAnnotation(ci, cmdr, visitor);
+               }
+            }
+            else if (trace)
+               log.trace("No annotations for " + ci);
+         }
+      }
+      else if (trace)
+         log.trace("No constructors");
+
+      // properties
+      Set<MethodInfo> visitedMethods = new HashSet<MethodInfo>();
+      Set<PropertyInfo> properties = info.getProperties();
+      if (properties != null && properties.isEmpty() == false)
+      {
+         for(PropertyInfo pi : properties)
+         {
+            MethodInfo setter = pi.getSetter();
+            if (setter != null)
+            {
+               visitedMethods.add(setter);
+               Signature sis = new MethodSignature(setter);
+               MetaData cmdr = retrieval.getComponentMetaData(sis);
+               if (cmdr != null)
+               {
+                  for(AnnotationPlugin plugin : propertyAnnotationPlugins)
+                  {
+                     if (isApplyPhase)
+                        plugin.applyAnnotation(pi, cmdr, visitor);
+                     else
+                        plugin.cleanAnnotation(pi, cmdr, visitor);
+                  }
+               }
+               else if (trace)
+                  log.trace("No annotations for property " + pi.getName());
+            }
+         }
+      }
+      else if (trace)
+         log.trace("No properties");
+
+      // methods
+      Set<MethodInfo> methods = info.getMethods();
+      if (methods != null && methods.isEmpty() == false)
+      {
+         for(MethodInfo mi : methods)
+         {
+            if (visitedMethods.contains(mi) == false)
+            {
+               Signature mis = new MethodSignature(mi);
+               MetaData cmdr = retrieval.getComponentMetaData(mis);
+               if (cmdr != null)
+               {
+                  for(AnnotationPlugin plugin : methodAnnotationPlugins)
+                  {
+                     if (isApplyPhase)
+                        plugin.applyAnnotation(mi, cmdr, visitor);
+                     else
+                        plugin.cleanAnnotation(mi, cmdr, visitor);
+                  }
+               }
+               else if (trace)
+                  log.trace("No annotations for " + mi);
+            }
+         }
+      }
+      else if (trace)
+         log.trace("No methods");
+
+      // static methods
+      MethodInfo[] staticMethods = classInfo.getDeclaredMethods();
+      if (staticMethods != null && staticMethods.length != 0)
+      {
+         for(MethodInfo smi : staticMethods)
+         {
+            if (smi.isStatic() && smi.isPublic())
+            {
+               Signature mis = new MethodSignature(smi);
+               MetaData cmdr = retrieval.getComponentMetaData(mis);
+               if (cmdr != null)
+               {
+                  for(AnnotationPlugin plugin : methodAnnotationPlugins)
+                  {
+                     if (isApplyPhase)
+                        plugin.applyAnnotation(smi, cmdr, visitor);
+                     else
+                        plugin.cleanAnnotation(smi, cmdr, visitor);
+                  }
+               }
+               else if (trace)
+                  log.trace("No annotations for " + smi);
+            }
+         }
+      }
+      else if (trace)
+         log.trace("No static methods");
+
+      // fields
+      FieldInfo[] fields = classInfo.getDeclaredFields();
+      if (fields != null && fields.length > 0)
+      {
+         for(FieldInfo fi : fields)
+         {
+            Signature fis = new FieldSignature(fi.getName());
+            MetaData cmdr = retrieval.getComponentMetaData(fis);
+            if (cmdr != null)
+            {
+               for(AnnotationPlugin plugin : fieldAnnotationPlugins)
+               {
+                  if (isApplyPhase)
+                     plugin.applyAnnotation(fi, cmdr, visitor);
+                  else
+                     plugin.cleanAnnotation(fi, cmdr, visitor);
+               }
+            }
+            else if (trace)
+               log.trace("No annotations for field " + fi.getName());
+         }
+      }
+      else if (trace)
+         log.trace("No fields");
+   }
+}

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/BasicBeanAnnotationAdapter.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/BasicBeanAnnotationAdapter.java	2007-12-10 14:27:36 UTC (rev 68100)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/BasicBeanAnnotationAdapter.java	2007-12-10 14:28:05 UTC (rev 68101)
@@ -21,47 +21,13 @@
 */
 package org.jboss.kernel.plugins.annotations;
 
-import java.lang.annotation.Annotation;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.jboss.beans.info.spi.BeanInfo;
-import org.jboss.beans.info.spi.PropertyInfo;
-import org.jboss.beans.metadata.spi.MetaDataVisitor;
-import org.jboss.kernel.Kernel;
-import org.jboss.kernel.plugins.config.Configurator;
-import org.jboss.kernel.spi.dependency.KernelControllerContext;
-import org.jboss.kernel.spi.metadata.KernelMetaDataRepository;
-import org.jboss.logging.Logger;
-import org.jboss.metadata.spi.MetaData;
-import org.jboss.metadata.spi.signature.ConstructorSignature;
-import org.jboss.metadata.spi.signature.FieldSignature;
-import org.jboss.metadata.spi.signature.MethodSignature;
-import org.jboss.metadata.spi.signature.Signature;
-import org.jboss.reflect.spi.ClassInfo;
-import org.jboss.reflect.spi.ConstructorInfo;
-import org.jboss.reflect.spi.FieldInfo;
-import org.jboss.reflect.spi.MethodInfo;
-
 /**
  * Basic bean annotation handler.
  *
  * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
  */
- at SuppressWarnings("unchecked")
-public class BasicBeanAnnotationAdapter implements BeanAnnotationAdapter
+public class BasicBeanAnnotationAdapter extends AbstractBeanAnnotationAdapter
 {
-   protected Logger log = Logger.getLogger(BasicBeanAnnotationAdapter.class);
-
-   protected Set<AnnotationPlugin> classAnnotationPlugins = new HashSet<AnnotationPlugin>();
-   protected Set<AnnotationPlugin> constructorAnnotationPlugins = new HashSet<AnnotationPlugin>();
-   protected Set<AnnotationPlugin> propertyAnnotationPlugins = new HashSet<AnnotationPlugin>();
-   protected Set<AnnotationPlugin> methodAnnotationPlugins = new HashSet<AnnotationPlugin>();
-   protected Set<AnnotationPlugin> fieldAnnotationPlugins = new HashSet<AnnotationPlugin>();
-
    public BasicBeanAnnotationAdapter()
    {
       // -- adapters
@@ -125,216 +91,4 @@
       addAnnotationPlugin(new UninstallMethodParameterAnnotationPlugin(adapters));
       // field
    }
-
-   protected void addAnnotationPlugin(AnnotationPlugin plugin)
-   {
-      Class<? extends Annotation> annotation = plugin.getAnnotation();
-      if (annotation.getAnnotation(Target.class) == null)
-         log.warn("Annotation " + annotation + " missing @Target annotation!");
-      if (annotation.getAnnotation(Retention.class) == null)
-         log.warn("Annotation " + annotation + " missing @Retention annotation!");
-
-      Set supported = plugin.getSupportedTypes();
-      if (supported.contains(ElementType.TYPE))
-      {
-         classAnnotationPlugins.add(plugin);
-      }
-      if (supported.contains(ElementType.CONSTRUCTOR))
-      {
-         constructorAnnotationPlugins.add(plugin);
-      }
-      if (supported.contains(ElementType.METHOD))
-      {
-         if (plugin instanceof PropertyAware)
-            propertyAnnotationPlugins.add(plugin);
-         else
-            methodAnnotationPlugins.add(plugin);
-      }
-      if (supported.contains(ElementType.FIELD))
-      {
-         fieldAnnotationPlugins.add(plugin);
-      }
-   }
-
-   public void applyAnnotations(MetaDataVisitor visitor) throws Throwable
-   {
-      handleAnnotations(visitor, true);
-   }
-
-   public void cleanAnnotations(MetaDataVisitor visitor) throws Throwable
-   {
-      handleAnnotations(visitor, false);
-   }
-
-   /**
-    * Handle apply or cleanup of annotations.
-    *
-    * @param visitor the metadata visitor
-    * @param isApplyPhase is this apply phase
-    * @throws Throwable for any error
-    */
-   protected void handleAnnotations(MetaDataVisitor visitor, boolean isApplyPhase) throws Throwable
-   {
-      if (visitor == null)
-         throw new IllegalArgumentException("Null meta data visitor.");
-
-      KernelControllerContext context = visitor.getControllerContext();
-      Kernel kernel = context.getKernel();
-      KernelMetaDataRepository repository = kernel.getMetaDataRepository();
-      MetaData retrieval = repository.getMetaData(context);
-
-      boolean trace = log.isTraceEnabled();
-      BeanInfo info = context.getBeanInfo();
-      Object name = context.getName();
-      if (trace)
-         log.trace(name + " apply annotations");
-
-      // class
-      ClassInfo classInfo = info.getClassInfo();
-      for(AnnotationPlugin plugin : classAnnotationPlugins)
-      {
-         if (isApplyPhase)
-            plugin.applyAnnotation(classInfo, retrieval, visitor);
-         else
-            plugin.cleanAnnotation(classInfo, retrieval, visitor);
-      }
-
-      // constructors
-      Set<ConstructorInfo> constructors = info.getConstructors();
-      if (constructors != null && constructors.isEmpty() == false)
-      {
-         for(ConstructorInfo ci : constructors)
-         {
-            Signature cis = new ConstructorSignature(Configurator.getParameterTypes(trace, ci.getParameterTypes()));
-            MetaData cmdr = retrieval.getComponentMetaData(cis);
-            if (cmdr != null)
-            {
-               for(AnnotationPlugin plugin : constructorAnnotationPlugins)
-               {
-                  if (isApplyPhase)
-                     plugin.applyAnnotation(ci, cmdr, visitor);
-                  else
-                     plugin.cleanAnnotation(ci, cmdr, visitor);
-               }
-            }
-            else if (trace)
-               log.trace("No annotations for " + ci);
-         }
-      }
-      else if (trace)
-         log.trace("No constructors");
-
-      // properties
-      Set<MethodInfo> visitedMethods = new HashSet<MethodInfo>();
-      Set<PropertyInfo> properties = info.getProperties();
-      if (properties != null && properties.isEmpty() == false)
-      {
-         for(PropertyInfo pi : properties)
-         {
-            MethodInfo setter = pi.getSetter();
-            if (setter != null)
-            {
-               visitedMethods.add(setter);
-               Signature sis = new MethodSignature(setter);
-               MetaData cmdr = retrieval.getComponentMetaData(sis);
-               if (cmdr != null)
-               {
-                  for(AnnotationPlugin plugin : propertyAnnotationPlugins)
-                  {
-                     if (isApplyPhase)
-                        plugin.applyAnnotation(pi, cmdr, visitor);
-                     else
-                        plugin.cleanAnnotation(pi, cmdr, visitor);
-                  }
-               }
-               else if (trace)
-                  log.trace("No annotations for property " + pi.getName());
-            }
-         }
-      }
-      else if (trace)
-         log.trace("No properties");
-
-      // methods
-      Set<MethodInfo> methods = info.getMethods();
-      if (methods != null && methods.isEmpty() == false)
-      {
-         for(MethodInfo mi : methods)
-         {
-            if (visitedMethods.contains(mi) == false)
-            {
-               Signature mis = new MethodSignature(mi);
-               MetaData cmdr = retrieval.getComponentMetaData(mis);
-               if (cmdr != null)
-               {
-                  for(AnnotationPlugin plugin : methodAnnotationPlugins)
-                  {
-                     if (isApplyPhase)
-                        plugin.applyAnnotation(mi, cmdr, visitor);
-                     else
-                        plugin.cleanAnnotation(mi, cmdr, visitor);
-                  }
-               }
-               else if (trace)
-                  log.trace("No annotations for " + mi);
-            }
-         }
-      }
-      else if (trace)
-         log.trace("No methods");
-
-      // static methods
-      MethodInfo[] staticMethods = classInfo.getDeclaredMethods();
-      if (staticMethods != null && staticMethods.length != 0)
-      {
-         for(MethodInfo smi : staticMethods)
-         {
-            if (smi.isStatic() && smi.isPublic())
-            {
-               Signature mis = new MethodSignature(smi);
-               MetaData cmdr = retrieval.getComponentMetaData(mis);
-               if (cmdr != null)
-               {
-                  for(AnnotationPlugin plugin : methodAnnotationPlugins)
-                  {
-                     if (isApplyPhase)
-                        plugin.applyAnnotation(smi, cmdr, visitor);
-                     else
-                        plugin.cleanAnnotation(smi, cmdr, visitor);
-                  }
-               }
-               else if (trace)
-                  log.trace("No annotations for " + smi);
-            }
-         }
-      }
-      else if (trace)
-         log.trace("No static methods");
-
-      // fields
-      FieldInfo[] fields = classInfo.getDeclaredFields();
-      if (fields != null && fields.length > 0)
-      {
-         for(FieldInfo fi : fields)
-         {
-            Signature fis = new FieldSignature(fi.getName());
-            MetaData cmdr = retrieval.getComponentMetaData(fis);
-            if (cmdr != null)
-            {
-               for(AnnotationPlugin plugin : fieldAnnotationPlugins)
-               {
-                  if (isApplyPhase)
-                     plugin.applyAnnotation(fi, cmdr, visitor);
-                  else
-                     plugin.cleanAnnotation(fi, cmdr, visitor);
-               }
-            }
-            else if (trace)
-               log.trace("No annotations for field " + fi.getName());
-         }
-      }
-      else if (trace)
-         log.trace("No fields");
-   }
-
 }

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/BeanAnnotationAdapterFactory.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/BeanAnnotationAdapterFactory.java	2007-12-10 14:27:36 UTC (rev 68100)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/BeanAnnotationAdapterFactory.java	2007-12-10 14:28:05 UTC (rev 68101)
@@ -21,6 +21,12 @@
 */
 package org.jboss.kernel.plugins.annotations;
 
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.jboss.logging.Logger;
+import org.jboss.reflect.plugins.introspection.ReflectionUtils;
+
 /**
  * BeanAnnotationAdapter factory.
  *
@@ -28,14 +34,56 @@
  */
 public class BeanAnnotationAdapterFactory
 {
-   private static final BeanAnnotationAdapter adapter = new BasicBeanAnnotationAdapter();
+   private static Logger log = Logger.getLogger(BeanAnnotationAdapterFactory.class);
+   private static final BeanAnnotationAdapterFactory factory = new BeanAnnotationAdapterFactory();
 
+   private String adapterClassName = BasicBeanAnnotationAdapter.class.getName();
+   private BeanAnnotationAdapter adapter;
+
+   private BeanAnnotationAdapterFactory()
+   {
+   }
+
+   public static BeanAnnotationAdapterFactory getInstance()
+   {
+      return factory;
+   }
+
+   public void setAdapterClassName(String adapterClassName)
+   {
+      this.adapterClassName = adapterClassName;
+   }
+
    /**
     * Get the BeanAnnotationAdapter instance.
     * @return the BeanAnnotationAdapter instance
     */
-   public static BeanAnnotationAdapter getBeanAnnotationAdapter()
+   public BeanAnnotationAdapter getBeanAnnotationAdapter()
    {
+      if (adapter == null)
+         adapter = AccessController.doPrivileged(new AdapterLookup());
+
       return adapter;
    }
+
+   private class AdapterLookup implements PrivilegedAction<BeanAnnotationAdapter>
+   {
+      public BeanAnnotationAdapter run()
+      {
+         try
+         {
+            String adapterClass = System.getProperty("org.jboss.kernel.plugins.annotations.BeanAnnotationAdapter", adapterClassName);
+            if (log.isTraceEnabled())
+               log.trace("Instantiating bean annotation adapter: " + adapterClass);
+            Object result = ReflectionUtils.newInstance(adapterClass);
+            return BeanAnnotationAdapter.class.cast(result);
+         }
+         catch (Throwable t)
+         {
+            log.warn("Exception while creating bean annotation adapter instance: " + t);
+            return new BasicBeanAnnotationAdapter();
+         }
+      }
+   }
+
 }

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/DescribeAction.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/DescribeAction.java	2007-12-10 14:27:36 UTC (rev 68100)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/DescribeAction.java	2007-12-10 14:28:05 UTC (rev 68101)
@@ -26,6 +26,7 @@
 import org.jboss.beans.info.spi.BeanInfo;
 import org.jboss.classadapter.spi.DependencyBuilderListItem;
 import org.jboss.kernel.plugins.annotations.BeanAnnotationAdapterFactory;
+import org.jboss.kernel.plugins.annotations.BeanAnnotationAdapter;
 import org.jboss.kernel.spi.dependency.KernelController;
 import org.jboss.kernel.spi.dependency.KernelControllerContext;
 import org.jboss.kernel.spi.metadata.KernelMetaDataRepository;
@@ -63,7 +64,7 @@
          annotationsVisitor.before();
          try
          {
-            BeanAnnotationAdapterFactory.getBeanAnnotationAdapter().applyAnnotations(annotationsVisitor);
+            getBeanAnnotationAdapter().applyAnnotations(annotationsVisitor);
          }
          finally
          {
@@ -79,7 +80,7 @@
       annotationsVisitor.before();
       try
       {
-         BeanAnnotationAdapterFactory.getBeanAnnotationAdapter().cleanAnnotations(annotationsVisitor);
+         getBeanAnnotationAdapter().cleanAnnotations(annotationsVisitor);
       }
       catch(Throwable t)
       {
@@ -90,4 +91,10 @@
          annotationsVisitor.after();
       }
    }
+
+   protected BeanAnnotationAdapter getBeanAnnotationAdapter()
+   {
+      BeanAnnotationAdapterFactory factory = BeanAnnotationAdapterFactory.getInstance();
+      return factory.getBeanAnnotationAdapter();
+   }
 }
\ No newline at end of file

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestAnnotationAdapter.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestAnnotationAdapter.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestAnnotationAdapter.java	2007-12-10 14:28:05 UTC (rev 68101)
@@ -0,0 +1,39 @@
+/*
+* 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.kernel.annotations.support;
+
+import org.jboss.kernel.plugins.annotations.AbstractBeanAnnotationAdapter;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TestAnnotationAdapter extends AbstractBeanAnnotationAdapter
+{
+   public static final TestAnnotationAdapter INSTANCE = new TestAnnotationAdapter();
+
+   private TestAnnotationAdapter()
+   {
+      addAnnotationPlugin(TestCleanupPlugin.INSTANCE);
+      addAnnotationPlugin(TestCleanupOnlyPlugin.INSTANCE);
+      addAnnotationPlugin(TestApplyOnlyPlugin.INSTANCE);
+   }
+}

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestAnnotationPlugin.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestAnnotationPlugin.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestAnnotationPlugin.java	2007-12-10 14:28:05 UTC (rev 68101)
@@ -0,0 +1,78 @@
+/*
+* 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.kernel.annotations.support;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Annotation;
+import java.util.List;
+
+import org.jboss.reflect.spi.MethodInfo;
+import org.jboss.kernel.plugins.annotations.AbstractAnnotationPlugin;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.beans.metadata.spi.MetaDataVisitorNode;
+import org.jboss.metadata.spi.MetaData;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TestAnnotationPlugin<T extends Annotation> extends AbstractAnnotationPlugin<MethodInfo, T>
+{
+   private boolean applied;
+   private boolean cleaned;
+
+   public TestAnnotationPlugin(Class<T> clazz)
+   {
+      super(clazz);
+   }
+
+   protected boolean isElementTypeSupported(ElementType type)
+   {
+      return true;
+   }
+
+   protected List<? extends MetaDataVisitorNode> internalApplyAnnotation(MethodInfo info, MetaData retrieval, T annotation, KernelControllerContext context) throws Throwable
+   {
+      applied = true;
+      return null;
+   }
+
+   protected void internalCleanAnnotation(MethodInfo info, MetaData retrieval, T annotation, KernelControllerContext context) throws Throwable
+   {
+      cleaned = true;
+   }
+
+   public void reset()
+   {
+      applied = false;
+      cleaned = false;
+   }
+
+   public boolean isApplied()
+   {
+      return applied;
+   }
+
+   public boolean isCleaned()
+   {
+      return cleaned;
+   }
+}

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestApplyOnly.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestApplyOnly.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestApplyOnly.java	2007-12-10 14:28:05 UTC (rev 68101)
@@ -0,0 +1,36 @@
+/*
+* 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.kernel.annotations.support;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at Target(ElementType.METHOD)
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface TestApplyOnly
+{
+}

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestApplyOnlyBean.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestApplyOnlyBean.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestApplyOnlyBean.java	2007-12-10 14:28:05 UTC (rev 68101)
@@ -0,0 +1,34 @@
+/*
+* 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.kernel.annotations.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TestApplyOnlyBean
+{
+   @TestApplyOnly
+   public String getName()
+   {
+      return null;
+   }
+}

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestApplyOnlyPlugin.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestApplyOnlyPlugin.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestApplyOnlyPlugin.java	2007-12-10 14:28:05 UTC (rev 68101)
@@ -0,0 +1,35 @@
+/*
+* 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.kernel.annotations.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TestApplyOnlyPlugin extends TestAnnotationPlugin<TestApplyOnly>
+{
+   public static final TestApplyOnlyPlugin INSTANCE = new TestApplyOnlyPlugin();
+
+   private TestApplyOnlyPlugin()
+   {
+      super(TestApplyOnly.class);
+   }
+}

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanup.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanup.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanup.java	2007-12-10 14:28:05 UTC (rev 68101)
@@ -0,0 +1,39 @@
+/*
+* 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.kernel.annotations.support;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import org.jboss.beans.metadata.api.annotations.Cleanup;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at Target(ElementType.METHOD)
+ at Retention(RetentionPolicy.RUNTIME)
+ at Cleanup
+public @interface TestCleanup
+{
+}

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanupBean.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanupBean.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanupBean.java	2007-12-10 14:28:05 UTC (rev 68101)
@@ -0,0 +1,34 @@
+/*
+* 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.kernel.annotations.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TestCleanupBean
+{
+   @TestCleanup
+   public String getName()
+   {
+      return null;
+   }
+}

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanupOnly.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanupOnly.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanupOnly.java	2007-12-10 14:28:05 UTC (rev 68101)
@@ -0,0 +1,39 @@
+/*
+* 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.kernel.annotations.support;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.jboss.beans.metadata.api.annotations.CleanupOnly;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at Target(ElementType.METHOD)
+ at Retention(RetentionPolicy.RUNTIME)
+ at CleanupOnly
+public @interface TestCleanupOnly
+{
+}

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanupOnlyBean.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanupOnlyBean.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanupOnlyBean.java	2007-12-10 14:28:05 UTC (rev 68101)
@@ -0,0 +1,34 @@
+/*
+* 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.kernel.annotations.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TestCleanupOnlyBean
+{
+   @TestCleanupOnly
+   public String getName()
+   {
+      return null;
+   }
+}

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanupOnlyPlugin.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanupOnlyPlugin.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanupOnlyPlugin.java	2007-12-10 14:28:05 UTC (rev 68101)
@@ -0,0 +1,35 @@
+/*
+* 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.kernel.annotations.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TestCleanupOnlyPlugin extends TestAnnotationPlugin<TestCleanupOnly>
+{
+   public static final TestCleanupOnlyPlugin INSTANCE = new TestCleanupOnlyPlugin();
+
+   private TestCleanupOnlyPlugin()
+   {
+      super(TestCleanupOnly.class);
+   }
+}

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanupPlugin.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanupPlugin.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/TestCleanupPlugin.java	2007-12-10 14:28:05 UTC (rev 68101)
@@ -0,0 +1,35 @@
+/*
+* 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.kernel.annotations.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TestCleanupPlugin extends TestAnnotationPlugin<TestCleanup>
+{
+   public static final TestCleanupPlugin INSTANCE = new TestCleanupPlugin();
+   
+   private TestCleanupPlugin()
+   {
+      super(TestCleanup.class);
+   }
+}

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/AbstractBeanAnnotationAdapterTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/AbstractBeanAnnotationAdapterTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/AbstractBeanAnnotationAdapterTestCase.java	2007-12-10 14:28:05 UTC (rev 68101)
@@ -0,0 +1,140 @@
+/*
+* 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.kernel.annotations.test;
+
+import java.lang.annotation.Annotation;
+import java.util.Collections;
+import java.util.Set;
+
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.annotations.BeanAnnotationAdapter;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.kernel.plugins.config.property.PropertyKernelConfig;
+import org.jboss.kernel.plugins.dependency.AbstractKernelController;
+import org.jboss.kernel.plugins.dependency.DescribeAction;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.test.BaseTestCase;
+
+/**
+ * Abstract bean annotation adapter test.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AbstractBeanAnnotationAdapterTestCase extends BaseTestCase
+{
+   protected AbstractBeanAnnotationAdapterTestCase(String name)
+   {
+      super(name);
+   }
+
+   protected abstract BeanAnnotationAdapter getBeanAnnotationAdapterClass();
+
+   protected Set<Annotation> getAnnotations()
+   {
+      return Collections.emptySet();
+   }
+
+   protected void runAnnotations(Object bean) throws Throwable
+   {
+      applyAnnotations(bean);
+      cleanAnnotations(bean);
+   }
+
+   protected void applyAnnotations(Object bean) throws Throwable
+   {
+      handleAnnotations(bean, true);
+   }
+
+   protected void cleanAnnotations(Object bean) throws Throwable
+   {
+      handleAnnotations(bean, false);
+   }
+
+   protected void handleAnnotations(Object bean, boolean isApplyPhase) throws Throwable
+   {
+      // bootstrap
+      BasicBootstrap bootstrap = new BasicBootstrap(new TestKernelConfig());
+      bootstrap.run();
+      Kernel kernel = bootstrap.getKernel();
+      KernelController controller = kernel.getController();
+      assertInstanceOf(controller, TestController.class);
+      String name = bean.toString();
+      AbstractBeanMetaData beanMetaData = new AbstractBeanMetaData(name, bean.getClass().getName());
+      try
+      {
+         controller.install(beanMetaData, bean);
+      }
+      finally
+      {
+         controller.uninstall(name);
+      }
+   }
+
+   private class TestKernelConfig extends PropertyKernelConfig
+   {
+      public TestKernelConfig()
+      {
+         super(null);
+      }
+
+      public KernelController createKernelController() throws Throwable
+      {
+         return new TestController();
+      }
+   }
+
+   private class TestController extends AbstractKernelController
+   {
+      private TestDescribeAction describe = new TestDescribeAction();
+
+      public TestController() throws Exception
+      {
+      }
+
+      protected void install(ControllerContext context, ControllerState fromState, ControllerState toState) throws Throwable
+      {
+         if (ControllerState.DESCRIBED.equals(toState))
+            describe.install(context);
+         else
+            super.install(context, fromState, toState);
+      }
+
+      protected void uninstall(ControllerContext context, ControllerState fromState, ControllerState toState)
+      {
+         if (ControllerState.DESCRIBED.equals(fromState))
+            describe.uninstall(context);
+         else
+            super.uninstall(context, fromState, toState);
+      }
+   }
+
+   private class TestDescribeAction extends DescribeAction
+   {
+      protected BeanAnnotationAdapter getBeanAnnotationAdapter()
+      {
+         return getBeanAnnotationAdapterClass();
+      }
+   }
+}

Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/AnnotationSupportTestSuite.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/AnnotationSupportTestSuite.java	2007-12-10 14:27:36 UTC (rev 68100)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/AnnotationSupportTestSuite.java	2007-12-10 14:28:05 UTC (rev 68101)
@@ -44,6 +44,7 @@
       suite.addTest(FactoryMethodTestCase.suite());
       suite.addTest(FactoryMethodXMLTestCase.suite());
       suite.addTest(FactoryMethodBadTestCase.suite());
+      suite.addTest(CleanupAnnotationTestCase.suite());
 
       return suite;
    }

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/CleanupAnnotationTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/CleanupAnnotationTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/CleanupAnnotationTestCase.java	2007-12-10 14:28:05 UTC (rev 68101)
@@ -0,0 +1,98 @@
+/*
+* 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.kernel.annotations.test;
+
+import junit.framework.Test;
+import org.jboss.kernel.plugins.annotations.BeanAnnotationAdapter;
+import org.jboss.test.kernel.annotations.support.TestAnnotationAdapter;
+import org.jboss.test.kernel.annotations.support.TestCleanupOnlyPlugin;
+import org.jboss.test.kernel.annotations.support.TestCleanupPlugin;
+import org.jboss.test.kernel.annotations.support.TestApplyOnlyPlugin;
+import org.jboss.test.kernel.annotations.support.TestCleanupBean;
+import org.jboss.test.kernel.annotations.support.TestCleanupOnlyBean;
+import org.jboss.test.kernel.annotations.support.TestApplyOnlyBean;
+
+/**
+ * Test the @Cleanup and @CleanupOnly
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class CleanupAnnotationTestCase extends AbstractBeanAnnotationAdapterTestCase
+{
+   public CleanupAnnotationTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(CleanupAnnotationTestCase.class);
+   }
+
+   protected BeanAnnotationAdapter getBeanAnnotationAdapterClass()
+   {
+      return TestAnnotationAdapter.INSTANCE;
+   }
+
+   protected void reset()
+   {
+      TestCleanupPlugin.INSTANCE.reset();
+      TestCleanupOnlyPlugin.INSTANCE.reset();
+      TestApplyOnlyPlugin.INSTANCE.reset();
+   }
+
+   public void testCleanup() throws Throwable
+   {
+      reset();
+      runAnnotations(new TestCleanupBean());
+      assertTrue(TestCleanupPlugin.INSTANCE.isApplied());
+      assertTrue(TestCleanupPlugin.INSTANCE.isCleaned());
+      assertFalse(TestCleanupOnlyPlugin.INSTANCE.isApplied());
+      assertFalse(TestCleanupOnlyPlugin.INSTANCE.isCleaned());
+      assertFalse(TestApplyOnlyPlugin.INSTANCE.isApplied());
+      assertFalse(TestApplyOnlyPlugin.INSTANCE.isCleaned());
+   }
+
+   public void testCleanupOnly() throws Throwable
+   {
+      reset();
+      runAnnotations(new TestCleanupOnlyBean());
+      assertFalse(TestCleanupPlugin.INSTANCE.isApplied());
+      assertFalse(TestCleanupPlugin.INSTANCE.isCleaned());
+      assertFalse(TestCleanupOnlyPlugin.INSTANCE.isApplied());
+      assertTrue(TestCleanupOnlyPlugin.INSTANCE.isCleaned());
+      assertFalse(TestApplyOnlyPlugin.INSTANCE.isApplied());
+      assertFalse(TestApplyOnlyPlugin.INSTANCE.isCleaned());
+   }
+
+   public void testApplyOnly() throws Throwable
+   {
+      reset();
+      runAnnotations(new TestApplyOnlyBean());
+      assertFalse(TestCleanupPlugin.INSTANCE.isApplied());
+      assertFalse(TestCleanupPlugin.INSTANCE.isCleaned());
+      assertFalse(TestCleanupOnlyPlugin.INSTANCE.isApplied());
+      assertFalse(TestCleanupOnlyPlugin.INSTANCE.isCleaned());
+      assertTrue(TestApplyOnlyPlugin.INSTANCE.isApplied());
+      assertFalse(TestApplyOnlyPlugin.INSTANCE.isCleaned());
+   }
+}




More information about the jboss-cvs-commits mailing list