[jboss-cvs] JBossAS SVN: r73487 - in projects/microcontainer/trunk/kernel/src: main/org/jboss/kernel/plugins/annotations and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon May 19 05:25:12 EDT 2008
Author: alesj
Date: 2008-05-19 05:25:12 -0400 (Mon, 19 May 2008)
New Revision: 73487
Added:
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/api/annotations/Bean.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/api/annotations/BeanFactory.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/BeanAnnotationPlugin.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/BeanAnnotationHolder.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/BeanAnnotationTestCase.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/BasicBeanMetaDataAnnotationAdapter.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/AnnotationSupportTestSuite.java
Log:
@Bean(Factory) annotation.
Copied: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/api/annotations/Bean.java (from rev 73436, projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/api/annotations/Inject.java)
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/api/annotations/Bean.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/api/annotations/Bean.java 2008-05-19 09:25:12 UTC (rev 73487)
@@ -0,0 +1,135 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.beans.metadata.api.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.jboss.metadata.spi.annotation.InstanceAnnotation;
+import org.jboss.beans.metadata.api.model.AutowireType;
+import org.jboss.beans.info.spi.BeanAccessMode;
+import org.jboss.dependency.spi.ControllerMode;
+import org.jboss.dependency.spi.ErrorHandlingMode;
+
+/**
+ * Mark the MC bean.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target({ElementType.TYPE})
+ at InstanceAnnotation(false)
+public @interface Bean
+{
+ /**
+ * Get the name.
+ *
+ * This is only meant to be used before
+ * bean meta data is already installed
+ * in Controller.
+ *
+ * @return bean's name
+ */
+ String name() default "";
+
+ /**
+ * Get the aliases.
+ *
+ * This is only meant to be used before
+ * bean meta data is already installed
+ * in Controller.
+ *
+ * @return the aliases
+ */
+ String[] aliases() default {};
+
+ /**
+ * Get the parent.
+ *
+ * This is only meant to be used before
+ * bean meta data is already installed
+ * in Controller.
+ *
+ * @return the parent
+ */
+ String parent() default "";
+
+ /**
+ * Is abstract metadata.
+ *
+ * This is only meant to be used before
+ * bean meta data is already installed
+ * in Controller.
+ *
+ * @return is abstract
+ */
+ boolean isAbstract() default false;
+
+ /**
+ * Get the autowire type.
+ *
+ * @return the autowire type
+ */
+ AutowireType autowireType() default AutowireType.NONE;
+
+ /**
+ * Get the mode
+ *
+ * Note that this is only gonna be
+ * used after Describe state.
+ *
+ * @return the mode
+ */
+ ControllerMode mode() default ControllerMode.AUTOMATIC;
+
+ /**
+ * Get error handling mode
+ *
+ * Note that this is only gonna be
+ * used after Describe state.
+ *
+ * @return the error handling mode
+ */
+ ErrorHandlingMode errorHandlingMode() default ErrorHandlingMode.DISCARD;
+
+ /**
+ * Get the access mode
+ *
+ * @return the access mode
+ */
+ BeanAccessMode accessMode() default BeanAccessMode.STANDARD;
+
+ /**
+ * Is this bean is a candidate for
+ * getting injected via contextual matching
+ * or callback resolution.
+ *
+ * This is only meant to be used before
+ * bean meta data is already installed
+ * in Controller.
+ *
+ * @return true (default) if used for autowiring
+ */
+ boolean autowireCandidate() default true;
+}
\ No newline at end of file
Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/api/annotations/BeanFactory.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/api/annotations/BeanFactory.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/api/annotations/BeanFactory.java 2008-05-19 09:25:12 UTC (rev 73487)
@@ -0,0 +1,74 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.beans.metadata.api.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.jboss.beans.info.spi.BeanAccessMode;
+import org.jboss.dependency.spi.ControllerMode;
+import org.jboss.metadata.spi.annotation.InstanceAnnotation;
+
+/**
+ * Mark the MC bean factory.
+ *
+ * Only useful before actual metadata instantiation,
+ * since we need to instantiate GenericBeanFactoryMetaData
+ * and not BeanMetaData.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target({ElementType.TYPE})
+ at InstanceAnnotation(false)
+public @interface BeanFactory
+{
+ /**
+ * Get the name.
+ *
+ * @return bean's name
+ */
+ String name() default "";
+
+ /**
+ * Get the aliases.
+ *
+ * @return the aliases
+ */
+ String[] aliases() default {};
+
+ /**
+ * Get the mode
+ *
+ * @return the mode
+ */
+ ControllerMode mode() default ControllerMode.AUTOMATIC;
+
+ /**
+ * Get the access mode
+ *
+ * @return the access mode
+ */
+ BeanAccessMode accessMode() default BeanAccessMode.STANDARD;
+}
\ No newline at end of file
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 2008-05-19 04:53:11 UTC (rev 73486)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/BasicBeanAnnotationAdapter.java 2008-05-19 09:25:12 UTC (rev 73487)
@@ -44,6 +44,7 @@
// -- plugins
// class
+ addAnnotationPlugin(BeanAnnotationPlugin.INSTANCE);
addAnnotationPlugin(AliasesAnnotationPlugin.INSTANCE);
addAnnotationPlugin(DemandsAnnotationPlugin.INSTANCE);
addAnnotationPlugin(DependsAnnotationPlugin.INSTANCE);
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/BasicBeanMetaDataAnnotationAdapter.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/BasicBeanMetaDataAnnotationAdapter.java 2008-05-19 04:53:11 UTC (rev 73486)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/BasicBeanMetaDataAnnotationAdapter.java 2008-05-19 09:25:12 UTC (rev 73487)
@@ -43,6 +43,7 @@
adapters = new CopyOnWriteArraySet<Annotation2ValueMetaDataAdapter<? extends Annotation>>();
// class
+ addAnnotationPlugin(BeanAnnotationPlugin.INSTANCE);
addAnnotationPlugin(AliasMetaDataAnnotationPlugin.INSTANCE);
addAnnotationPlugin(DemandsAnnotationPlugin.INSTANCE);
addAnnotationPlugin(DependsAnnotationPlugin.INSTANCE);
Copied: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/BeanAnnotationPlugin.java (from rev 73436, projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/DependsAnnotationPlugin.java)
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/BeanAnnotationPlugin.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/BeanAnnotationPlugin.java 2008-05-19 09:25:12 UTC (rev 73487)
@@ -0,0 +1,64 @@
+/*
+* 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.List;
+
+import org.jboss.beans.metadata.api.annotations.Bean;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.MetaDataVisitorNode;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.reflect.spi.ClassInfo;
+
+/**
+ * Bean annotation plugin.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class BeanAnnotationPlugin extends ClassAnnotationPlugin<Bean>
+{
+ public static final BeanAnnotationPlugin INSTANCE = new BeanAnnotationPlugin();
+
+ protected BeanAnnotationPlugin()
+ {
+ super(Bean.class);
+ }
+
+ protected List<? extends MetaDataVisitorNode> internalApplyAnnotation(ClassInfo info, Bean annotation, BeanMetaData beanMetaData)
+ {
+ AbstractBeanMetaData abmd = checkIfNotAbstractBeanMetaDataSpecific(beanMetaData);
+
+ if (abmd.getAutowireType() == null)
+ abmd.setAutowireType(annotation.autowireType());
+ if (abmd.getMode() == null)
+ abmd.setMode(annotation.mode());
+ if (abmd.getErrorHandlingMode() == null)
+ abmd.setErrorHandlingMode(annotation.errorHandlingMode());
+ if (abmd.getAccessMode() == null)
+ abmd.setAccessMode(annotation.accessMode());
+
+ // we don't put bmd back to be inspected
+ // since the changes we apply *here* don't really
+ // trigger any change in metadata - all enums
+ return null;
+ }
+}
\ No newline at end of file
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/BeanAnnotationHolder.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/BeanAnnotationHolder.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/BeanAnnotationHolder.java 2008-05-19 09:25:12 UTC (rev 73487)
@@ -0,0 +1,41 @@
+/*
+* 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.Bean;
+import org.jboss.beans.metadata.api.model.AutowireType;
+import org.jboss.beans.info.spi.BeanAccessMode;
+import org.jboss.dependency.spi.ControllerMode;
+import org.jboss.dependency.spi.ErrorHandlingMode;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at Bean(
+ autowireType = AutowireType.CONSTRUCTOR,
+ mode = ControllerMode.ASYNCHRONOUS,
+ errorHandlingMode = ErrorHandlingMode.MANUAL,
+ accessMode = BeanAccessMode.ALL
+)
+public class BeanAnnotationHolder
+{
+}
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 2008-05-19 04:53:11 UTC (rev 73486)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/AnnotationSupportTestSuite.java 2008-05-19 09:25:12 UTC (rev 73487)
@@ -46,6 +46,7 @@
suite.addTest(FactoryMethodBadTestCase.suite());
suite.addTest(CleanupAnnotationTestCase.suite());
suite.addTest(AfterInstantiateAnnotationsTestCase.suite());
+ suite.addTest(BeanAnnotationTestCase.suite());
return suite;
}
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/BeanAnnotationTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/BeanAnnotationTestCase.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/BeanAnnotationTestCase.java 2008-05-19 09:25:12 UTC (rev 73487)
@@ -0,0 +1,91 @@
+/*
+* 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.beans.info.spi.BeanAccessMode;
+import org.jboss.beans.metadata.api.model.AutowireType;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.dependency.spi.ControllerMode;
+import org.jboss.dependency.spi.ErrorHandlingMode;
+import org.jboss.kernel.spi.annotations.AnnotationToBeanMetaDataFactory;
+import org.jboss.test.kernel.annotations.support.BeanAnnotationHolder;
+import org.jboss.test.kernel.config.test.AbstractKernelConfigTest;
+
+/**
+ * BeanAnnotationTestCase.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class BeanAnnotationTestCase extends AbstractKernelConfigTest
+{
+ public BeanAnnotationTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(BeanAnnotationTestCase.class);
+ }
+
+ public void testInitialValues() throws Throwable
+ {
+ SecurityManager sm = suspendSecurity();
+ try
+ {
+ BeanMetaData bmd = AnnotationToBeanMetaDataFactory.createBeanMetaData(BeanAnnotationHolder.class);
+ assertEquals(AutowireType.CONSTRUCTOR, bmd.getAutowireType());
+ assertEquals(ControllerMode.ASYNCHRONOUS, bmd.getMode());
+ assertEquals(ErrorHandlingMode.MANUAL, bmd.getErrorHandlingMode());
+ assertEquals(BeanAccessMode.STANDARD, bmd.getAccessMode()); // standard, since we set it in A2BMD
+ }
+ finally
+ {
+ resumeSecurity(sm);
+ }
+ }
+
+ public void testOverriddenValues() throws Throwable
+ {
+ SecurityManager sm = suspendSecurity();
+ try
+ {
+ AbstractBeanMetaData abmd = new AbstractBeanMetaData();
+ abmd.setAutowireType(AutowireType.BY_NAME);
+ abmd.setMode(ControllerMode.DISABLED);
+ abmd.setErrorHandlingMode(ErrorHandlingMode.DISCARD);
+ abmd.setAccessMode(BeanAccessMode.FIELDS);
+
+ BeanMetaData bmd = AnnotationToBeanMetaDataFactory.fillBeanMetaData(BeanAnnotationHolder.class, BeanAccessMode.FIELDS, abmd);
+ assertEquals(AutowireType.BY_NAME, bmd.getAutowireType());
+ assertEquals(ControllerMode.DISABLED, bmd.getMode());
+ assertEquals(ErrorHandlingMode.DISCARD, bmd.getErrorHandlingMode());
+ assertEquals(BeanAccessMode.FIELDS, bmd.getAccessMode());
+ }
+ finally
+ {
+ resumeSecurity(sm);
+ }
+ }
+}
More information about the jboss-cvs-commits
mailing list