[jboss-cvs] JBossAS SVN: r72178 - in projects/microcontainer/trunk/kernel/src: tests/org/jboss/test/kernel/annotations/support and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Apr 14 10:24:55 EDT 2008


Author: alesj
Date: 2008-04-14 10:24:55 -0400 (Mon, 14 Apr 2008)
New Revision: 72178

Added:
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/MyOwnDependency.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/SecurityDomain.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/SecurityDomainAnnotationPlugin.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/SecurityDomainDependencyFactory.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/OwnDependencyTestCase.java
Modified:
   projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/api/annotations/Dependency.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/AbstractRunAnnotationsTest.java
Log:
[JBMICROCONT-81]; providing a test for providing your custom dependency.

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/api/annotations/Dependency.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/api/annotations/Dependency.java	2008-04-14 14:14:24 UTC (rev 72177)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/api/annotations/Dependency.java	2008-04-14 14:24:55 UTC (rev 72178)
@@ -30,11 +30,24 @@
  * Dependency.
  * 
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  * @version $Revision: 44529 $
  */
 @Retention(RetentionPolicy.RUNTIME)
 @Target(ElementType.ANNOTATION_TYPE)
 public @interface Dependency
 {
+   /**
+    * Get the name.
+    *
+    * @return the name
+    */
    String name();
+
+   /**
+    * Get the helper factory class.
+    *
+    * @return the factory class
+    */
+   Class<?> factory() default void.class;
 }

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/MyOwnDependency.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/MyOwnDependency.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/MyOwnDependency.java	2008-04-14 14:24:55 UTC (rev 72178)
@@ -0,0 +1,30 @@
+/*
+* 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>
+ */
+ at SecurityDomain(domain = "somedomain")
+public class MyOwnDependency
+{
+}

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/SecurityDomain.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/SecurityDomain.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/SecurityDomain.java	2008-04-14 14:24:55 UTC (rev 72178)
@@ -0,0 +1,42 @@
+/*
+* 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.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+import org.jboss.beans.metadata.api.annotations.Dependency;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target(ElementType.TYPE)
+ at Dependency(name="domain", factory= SecurityDomainDependencyFactory.class)
+public @interface SecurityDomain
+{
+   String domain();
+
+   String securityManagerName() default "SecurityManager";
+}

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/SecurityDomainAnnotationPlugin.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/SecurityDomainAnnotationPlugin.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/SecurityDomainAnnotationPlugin.java	2008-04-14 14:24:55 UTC (rev 72178)
@@ -0,0 +1,58 @@
+/*
+* 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.util.List;
+
+import org.jboss.beans.metadata.api.annotations.Dependency;
+import org.jboss.beans.metadata.spi.MetaDataVisitorNode;
+import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.dependency.spi.DependencyItem;
+import org.jboss.kernel.plugins.annotations.ClassAnnotationPlugin;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.reflect.spi.ClassInfo;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class SecurityDomainAnnotationPlugin extends ClassAnnotationPlugin<SecurityDomain>
+{
+   public SecurityDomainAnnotationPlugin()
+   {
+      super(SecurityDomain.class);
+   }
+
+   protected List<? extends MetaDataVisitorNode> internalApplyAnnotation(ClassInfo info, MetaData retrieval, SecurityDomain annotation, KernelControllerContext context) throws Throwable
+   {
+      Dependency dependency = annotation.annotationType().getAnnotation(Dependency.class);
+      if (dependency == null)
+         throw new IllegalArgumentException("Null @Dependency.");
+
+      DependencyInfo dependencies = context.getDependencyInfo();
+      SecurityDomainDependencyFactory factory = (SecurityDomainDependencyFactory)dependency.factory().newInstance();
+      DependencyItem item = factory.createDependencyItem(annotation, dependency);
+      dependencies.addIDependOn(item);
+
+      return null;
+   }
+}

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/SecurityDomainDependencyFactory.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/SecurityDomainDependencyFactory.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/SecurityDomainDependencyFactory.java	2008-04-14 14:24:55 UTC (rev 72178)
@@ -0,0 +1,38 @@
+/*
+* 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.beans.metadata.api.annotations.Dependency;
+import org.jboss.dependency.spi.DependencyItem;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.plugins.AbstractDependencyItem;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class SecurityDomainDependencyFactory
+{
+   public DependencyItem createDependencyItem(SecurityDomain annotation, Dependency dependency)
+   {
+      return new AbstractDependencyItem(annotation.domain(), dependency.name(), ControllerState.INSTANTIATED, null);
+   }
+}

Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/AbstractRunAnnotationsTest.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/AbstractRunAnnotationsTest.java	2008-04-14 14:14:24 UTC (rev 72177)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/AbstractRunAnnotationsTest.java	2008-04-14 14:24:55 UTC (rev 72178)
@@ -104,7 +104,9 @@
       try
       {
          KernelControllerContext context = controller.install(beanMetaData, target);
-         checkContextState(context);         
+         checkContextState(context);
+         if (target == null)
+            target = clazz.cast(context.getTarget());
          doTestAfterInstall(clazz, target);
       }
       finally

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/OwnDependencyTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/OwnDependencyTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/OwnDependencyTestCase.java	2008-04-14 14:24:55 UTC (rev 72178)
@@ -0,0 +1,57 @@
+/*
+* 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 org.jboss.dependency.spi.ControllerState;
+import org.jboss.kernel.plugins.annotations.BasicBeanAnnotationAdapter;
+import org.jboss.kernel.plugins.annotations.BeanAnnotationAdapter;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.test.kernel.annotations.support.SecurityDomainAnnotationPlugin;
+import org.jboss.test.kernel.annotations.support.MyOwnDependency;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class OwnDependencyTestCase extends AbstractBeanAnnotationAdapterTest
+{
+   public OwnDependencyTestCase(String name)
+   {
+      super(name);
+   }
+
+   protected BeanAnnotationAdapter getBeanAnnotationAdapterClass()
+   {
+      BasicBeanAnnotationAdapter adapter = BasicBeanAnnotationAdapter.INSTANCE;
+      adapter.addAnnotationPlugin(new SecurityDomainAnnotationPlugin());
+      return adapter;
+   }
+
+   public void testCustomDependency() throws Throwable
+   {
+      runAnnotationsOnTarget(new MyOwnDependency());
+   }
+
+   protected void checkContextState(KernelControllerContext context)
+   {
+      assertEquals(ControllerState.DESCRIBED, context.getState());
+   }
+}




More information about the jboss-cvs-commits mailing list