[jboss-cvs] JBossAS SVN: r83808 - in projects/microcontainer/trunk/kernel/src: main/java/org/jboss/beans/metadata/spi/builder and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Feb 3 07:35:47 EST 2009
Author: alesj
Date: 2009-02-03 07:35:47 -0500 (Tue, 03 Feb 2009)
New Revision: 83808
Added:
projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/config/support/SimpleAnnotationImpl.java
Modified:
projects/microcontainer/trunk/kernel/src/main/java/org/jboss/beans/metadata/plugins/builder/BeanMetaDataBuilderImpl.java
projects/microcontainer/trunk/kernel/src/main/java/org/jboss/beans/metadata/spi/builder/BeanMetaDataBuilder.java
projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/config/test/BeanMetaDataBuilderTestCase.java
Log:
Add new helper methods to BMDB.
Modified: projects/microcontainer/trunk/kernel/src/main/java/org/jboss/beans/metadata/plugins/builder/BeanMetaDataBuilderImpl.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/java/org/jboss/beans/metadata/plugins/builder/BeanMetaDataBuilderImpl.java 2009-02-03 11:52:44 UTC (rev 83807)
+++ projects/microcontainer/trunk/kernel/src/main/java/org/jboss/beans/metadata/plugins/builder/BeanMetaDataBuilderImpl.java 2009-02-03 12:35:47 UTC (rev 83808)
@@ -43,6 +43,8 @@
import org.jboss.beans.metadata.plugins.AbstractDemandMetaData;
import org.jboss.beans.metadata.plugins.AbstractDependencyMetaData;
import org.jboss.beans.metadata.plugins.AbstractDependencyValueMetaData;
+import org.jboss.beans.metadata.plugins.AbstractFeatureMetaData;
+import org.jboss.beans.metadata.plugins.AbstractInjectionValueMetaData;
import org.jboss.beans.metadata.plugins.AbstractInstallMetaData;
import org.jboss.beans.metadata.plugins.AbstractListMetaData;
import org.jboss.beans.metadata.plugins.AbstractMapMetaData;
@@ -54,7 +56,6 @@
import org.jboss.beans.metadata.plugins.DirectAnnotationMetaData;
import org.jboss.beans.metadata.plugins.StringValueMetaData;
import org.jboss.beans.metadata.plugins.ThisValueMetaData;
-import org.jboss.beans.metadata.plugins.AbstractInjectionValueMetaData;
import org.jboss.beans.metadata.spi.AnnotationMetaData;
import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.beans.metadata.spi.BeanMetaDataFactory;
@@ -71,6 +72,7 @@
import org.jboss.dependency.spi.ControllerMode;
import org.jboss.dependency.spi.ControllerState;
import org.jboss.dependency.spi.ErrorHandlingMode;
+import org.jboss.dependency.spi.graph.SearchInfo;
/**
* Helper class.
@@ -649,7 +651,49 @@
return this;
}
+ public BeanMetaDataBuilder addPropertyAnnotation(String name, String annotation)
+ {
+ AnnotationMetaData amd = createAnnotationMetaData(annotation);
+ return addPropertyAnnotation(name, amd);
+ }
+
+ public BeanMetaDataBuilder addPropertyAnnotation(String name, String annotation, boolean replace)
+ {
+ AnnotationMetaData amd = createAnnotationMetaData(annotation, replace);
+ return addPropertyAnnotation(name, amd);
+ }
+
+ public BeanMetaDataBuilder addPropertyAnnotation(String name, Annotation annotation)
+ {
+ AnnotationMetaData amd = createAnnotationMetaData(annotation);
+ return addPropertyAnnotation(name, amd);
+ }
+
/**
+ * Add property annotation metadata.
+ *
+ * @param name the property name
+ * @param amd the annotation metadata
+ * @return this builder
+ */
+ protected BeanMetaDataBuilder addPropertyAnnotation(String name, AnnotationMetaData amd)
+ {
+ PropertyMetaData pmd = beanMetaData.getProperty(name);
+ Set<AnnotationMetaData> annotations = pmd.getAnnotations();
+ if (annotations == null)
+ {
+ if (pmd instanceof AbstractFeatureMetaData == false)
+ throw new IllegalArgumentException("PropertyMetaData is not AbstractFeatureMetaData instance: " + pmd);
+
+ annotations = new HashSet<AnnotationMetaData>();
+ AbstractFeatureMetaData afmd = AbstractFeatureMetaData.class.cast(pmd);
+ afmd.setAnnotations(annotations);
+ }
+ annotations.add(amd);
+ return this;
+ }
+
+ /**
* Remove previous matching property.
*
* @param properties the properties
@@ -994,13 +1038,15 @@
return new AbstractDependencyValueMetaData(bean, property);
}
- public ValueMetaData createInject(Object bean, String property, ControllerState whenRequired, ControllerState dependentState)
+ public ValueMetaData createInject(Object bean, String property, ControllerState whenRequired, ControllerState dependentState, SearchInfo search)
{
AbstractDependencyValueMetaData result = createAbstractDependencyValueMetaData(bean, property);
if (whenRequired != null)
result.setWhenRequiredState(whenRequired);
if (dependentState != null)
result.setDependentState(dependentState);
+ if (search != null)
+ result.setSearch(search);
return result;
}
@@ -1014,7 +1060,7 @@
return new AbstractInjectionValueMetaData();
}
- public ValueMetaData createContextualInject(ControllerState whenRequired, ControllerState dependentState, AutowireType autowire, InjectOption option)
+ public ValueMetaData createContextualInject(ControllerState whenRequired, ControllerState dependentState, AutowireType autowire, InjectOption option, SearchInfo search)
{
AbstractInjectionValueMetaData result = createAbstractInjectionValueMetaData();
if (whenRequired != null)
@@ -1025,6 +1071,8 @@
result.setInjectionType(autowire);
if (option != null)
result.setInjectionOption(option);
+ if (search != null)
+ result.setSearch(search);
return result;
}
Modified: projects/microcontainer/trunk/kernel/src/main/java/org/jboss/beans/metadata/spi/builder/BeanMetaDataBuilder.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/java/org/jboss/beans/metadata/spi/builder/BeanMetaDataBuilder.java 2009-02-03 11:52:44 UTC (rev 83807)
+++ projects/microcontainer/trunk/kernel/src/main/java/org/jboss/beans/metadata/spi/builder/BeanMetaDataBuilder.java 2009-02-03 12:35:47 UTC (rev 83808)
@@ -36,12 +36,13 @@
import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.beans.metadata.spi.BeanMetaDataFactory;
import org.jboss.beans.metadata.spi.ClassLoaderMetaData;
+import org.jboss.beans.metadata.spi.RelatedClassMetaData;
import org.jboss.beans.metadata.spi.ValueMetaData;
-import org.jboss.beans.metadata.spi.RelatedClassMetaData;
import org.jboss.dependency.spi.Cardinality;
import org.jboss.dependency.spi.ControllerMode;
import org.jboss.dependency.spi.ControllerState;
import org.jboss.dependency.spi.ErrorHandlingMode;
+import org.jboss.dependency.spi.graph.SearchInfo;
/**
* BeanMetaDataBuilder contract.
@@ -460,6 +461,34 @@
public abstract BeanMetaDataBuilder addPropertyMetaData(String name, Collection<ValueMetaData> value);
/**
+ * Add a property annotation.
+ *
+ * @param name the property name
+ * @param annotation the annotation
+ * @return the builder
+ */
+ public abstract BeanMetaDataBuilder addPropertyAnnotation(String name, String annotation);
+
+ /**
+ * Add a property annotation.
+ *
+ * @param name the property name
+ * @param annotation the annotation
+ * @param replace the replace flag
+ * @return the builder
+ */
+ public abstract BeanMetaDataBuilder addPropertyAnnotation(String name, String annotation, boolean replace);
+
+ /**
+ * Add a property annotation.
+ *
+ * @param name the property name
+ * @param annotation the annotation
+ * @return the builder
+ */
+ public abstract BeanMetaDataBuilder addPropertyAnnotation(String name, Annotation annotation);
+
+ /**
* Add a property, replace it if it already exists
*
* @param name the property name
@@ -1611,9 +1640,24 @@
* @param dependentState the state of the injected bean
* @return the injection
*/
- public abstract ValueMetaData createInject(Object bean, String property, ControllerState whenRequired, ControllerState dependentState);
+ public ValueMetaData createInject(Object bean, String property, ControllerState whenRequired, ControllerState dependentState)
+ {
+ return createInject(bean, property, whenRequired, dependentState, null);
+ }
/**
+ * Create an injection
+ *
+ * @param bean the bean to inject
+ * @param property the property of the bean
+ * @param whenRequired when the injection is required
+ * @param dependentState the state of the injected bean
+ * @param search the search info
+ * @return the injection
+ */
+ public abstract ValueMetaData createInject(Object bean, String property, ControllerState whenRequired, ControllerState dependentState, SearchInfo search);
+
+ /**
* Create contextual injection.
*
* @return the contextual injection
@@ -1644,9 +1688,24 @@
* @param option the inject option
* @return the contextual injection
*/
- public abstract ValueMetaData createContextualInject(ControllerState whenRequired, ControllerState dependentState, AutowireType autowire, InjectOption option);
+ public ValueMetaData createContextualInject(ControllerState whenRequired, ControllerState dependentState, AutowireType autowire, InjectOption option)
+ {
+ return createContextualInject(whenRequired, dependentState, autowire, option, null);
+ }
/**
+ * Create contextual injection.
+ *
+ * @param whenRequired when the injection is required
+ * @param dependentState the state of the injected bean
+ * @param autowire the autowire type
+ * @param option the inject option
+ * @param search the search info
+ * @return the contextual injection
+ */
+ public abstract ValueMetaData createContextualInject(ControllerState whenRequired, ControllerState dependentState, AutowireType autowire, InjectOption option, SearchInfo search);
+
+ /**
* Create a new collection
*
* @return the collection
Copied: projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/config/support/SimpleAnnotationImpl.java (from rev 83617, projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/config/support/SimpleAnnotation.java)
===================================================================
--- projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/config/support/SimpleAnnotationImpl.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/config/support/SimpleAnnotationImpl.java 2009-02-03 12:35:47 UTC (rev 83808)
@@ -0,0 +1,40 @@
+/*
+* 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.config.support;
+
+import java.lang.annotation.Annotation;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class SimpleAnnotationImpl implements SimpleAnnotation
+{
+ public String name()
+ {
+ return null;
+ }
+
+ public Class<? extends Annotation> annotationType()
+ {
+ return SimpleAnnotation.class;
+ }
+}
\ No newline at end of file
Property changes on: projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/config/support/SimpleAnnotationImpl.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/config/test/BeanMetaDataBuilderTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/config/test/BeanMetaDataBuilderTestCase.java 2009-02-03 11:52:44 UTC (rev 83807)
+++ projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/config/test/BeanMetaDataBuilderTestCase.java 2009-02-03 12:35:47 UTC (rev 83808)
@@ -36,15 +36,18 @@
import org.jboss.beans.metadata.plugins.AbstractRelatedClassMetaData;
import org.jboss.beans.metadata.plugins.InstallCallbackMetaData;
import org.jboss.beans.metadata.plugins.UninstallCallbackMetaData;
+import org.jboss.beans.metadata.plugins.AbstractDependencyValueMetaData;
import org.jboss.beans.metadata.plugins.builder.BeanMetaDataBuilderFactory;
+import org.jboss.beans.metadata.spi.AnnotationMetaData;
import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.beans.metadata.spi.BeanMetaDataFactory;
import org.jboss.beans.metadata.spi.CallbackMetaData;
+import org.jboss.beans.metadata.spi.LifecycleMetaData;
+import org.jboss.beans.metadata.spi.PropertyMetaData;
import org.jboss.beans.metadata.spi.RelatedClassMetaData;
import org.jboss.beans.metadata.spi.ValueMetaData;
-import org.jboss.beans.metadata.spi.LifecycleMetaData;
-import org.jboss.beans.metadata.spi.PropertyMetaData;
import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.dependency.plugins.graph.Search;
import org.jboss.dependency.spi.Cardinality;
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.dependency.spi.ControllerState;
@@ -56,6 +59,7 @@
import org.jboss.kernel.spi.dependency.KernelControllerContext;
import org.jboss.metadata.spi.MetaData;
import org.jboss.test.kernel.config.support.SimpleAnnotation;
+import org.jboss.test.kernel.config.support.SimpleAnnotationImpl;
import org.jboss.test.kernel.config.support.SimpleBean;
import org.jboss.test.kernel.config.support.SimpleCallbackBean;
import org.jboss.test.kernel.config.support.SimpleLifecycleBean;
@@ -926,4 +930,35 @@
assertNotNull(vmd);
assertNull(vmd.getUnderlyingValue());
}
+
+ public void testSearch() throws Throwable
+ {
+ BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder("test");
+ builder.addPropertyMetaData("ci", builder.createContextualInject(null, null, null, null, Search.WIDTH));
+ BeanMetaData bmd = builder.getBeanMetaData();
+ Set<PropertyMetaData> properties = bmd.getProperties();
+ assertNotNull(properties);
+ assertEquals(1, properties.size());
+ PropertyMetaData pmd = properties.iterator().next();
+ ValueMetaData vmd = pmd.getValue();
+ assertNotNull(vmd);
+ AbstractDependencyValueMetaData advmd = assertInstanceOf(vmd, AbstractDependencyValueMetaData.class);
+ assertEquals(Search.WIDTH, advmd.getSearch());
+ }
+
+ public void testPropertyAnnotations() throws Throwable
+ {
+ BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder("test");
+ builder.addPropertyMetaData("ci", builder.createContextualInject());
+ builder.addPropertyAnnotation("ci", new SimpleAnnotationImpl());
+ BeanMetaData bmd = builder.getBeanMetaData();
+
+ Set<PropertyMetaData> properties = bmd.getProperties();
+ assertNotNull(properties);
+ assertEquals(1, properties.size());
+ PropertyMetaData pmd = properties.iterator().next();
+ Set<AnnotationMetaData> annotations = pmd.getAnnotations();
+ assertNotNull(annotations);
+ assertEquals(1, annotations.size());
+ }
}
More information about the jboss-cvs-commits
mailing list