[jboss-cvs] JBossAS SVN: r83627 - in projects/microcontainer/trunk/kernel/src: test/java/org/jboss/test/kernel/deployment/support and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jan 29 13:38:58 EST 2009
Author: alesj
Date: 2009-01-29 13:38:57 -0500 (Thu, 29 Jan 2009)
New Revision: 83627
Added:
projects/microcontainer/trunk/kernel/src/main/java/org/jboss/beans/metadata/spi/factory/PropertyMap.java
projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/deployment/support/FirstBean2.java
projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/deployment/test/BeanFactoryContextualInjectionTestCase.java
projects/microcontainer/trunk/kernel/src/test/resources/org/jboss/test/kernel/deployment/test/BeanFactoryContextualInjectionTestCase.xml
Modified:
projects/microcontainer/trunk/kernel/src/main/java/org/jboss/beans/metadata/spi/factory/GenericBeanFactoryMetaData.java
projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/deployment/test/DeploymentTestSuite.java
Log:
[JBMICROCONT-405]; support contextual injection into beanfactory.
Modified: projects/microcontainer/trunk/kernel/src/main/java/org/jboss/beans/metadata/spi/factory/GenericBeanFactoryMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/java/org/jboss/beans/metadata/spi/factory/GenericBeanFactoryMetaData.java 2009-01-29 17:19:16 UTC (rev 83626)
+++ projects/microcontainer/trunk/kernel/src/main/java/org/jboss/beans/metadata/spi/factory/GenericBeanFactoryMetaData.java 2009-01-29 18:38:57 UTC (rev 83627)
@@ -23,9 +23,7 @@
import java.io.Serializable;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.xml.bind.annotation.XmlAttribute;
@@ -60,8 +58,6 @@
import org.jboss.beans.metadata.spi.DependencyMetaData;
import org.jboss.beans.metadata.spi.InstallMetaData;
import org.jboss.beans.metadata.spi.LifecycleMetaData;
-import org.jboss.beans.metadata.spi.MetaDataVisitor;
-import org.jboss.beans.metadata.spi.MetaDataVisitorNode;
import org.jboss.beans.metadata.spi.PropertyMetaData;
import org.jboss.beans.metadata.spi.SupplyMetaData;
import org.jboss.beans.metadata.spi.ValueMetaData;
@@ -75,6 +71,7 @@
* GenericBeanFactoryMetaData.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
* @version $Revision: 59429 $
*/
@XmlRootElement(name="beanfactory")
@@ -626,28 +623,4 @@
}
return builder.getBeanMetaData();
}
-
- /**
- * PropertyMap.
- */
- private class PropertyMap extends HashMap<String, ValueMetaData> implements MetaDataVisitorNode
- {
- /** The serialVersionUID */
- private static final long serialVersionUID = -4295725682462294630L;
-
- public void initialVisit(MetaDataVisitor visitor)
- {
- visitor.initialVisit(this);
- }
-
- public void describeVisit(MetaDataVisitor vistor)
- {
- vistor.describeVisit(this);
- }
-
- public Iterator<? extends MetaDataVisitorNode> getChildren()
- {
- return values().iterator();
- }
- }
}
\ No newline at end of file
Copied: projects/microcontainer/trunk/kernel/src/main/java/org/jboss/beans/metadata/spi/factory/PropertyMap.java (from rev 83617, projects/microcontainer/trunk/kernel/src/main/java/org/jboss/beans/metadata/spi/factory/GenericBeanFactoryMetaData.java)
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/java/org/jboss/beans/metadata/spi/factory/PropertyMap.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/main/java/org/jboss/beans/metadata/spi/factory/PropertyMap.java 2009-01-29 18:38:57 UTC (rev 83627)
@@ -0,0 +1,186 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.beans.metadata.spi.factory;
+
+import java.io.Serializable;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.beans.metadata.plugins.TypeProvider;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.MetaDataVisitor;
+import org.jboss.beans.metadata.spi.MetaDataVisitorNode;
+import org.jboss.beans.metadata.spi.RelatedClassMetaData;
+import org.jboss.beans.metadata.spi.ValueMetaData;
+import org.jboss.config.plugins.property.PropertyConfiguration;
+import org.jboss.config.spi.Configuration;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.util.JBossObject;
+import org.jboss.util.JBossStringBuilder;
+
+/**
+ * PropertyMap.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+class PropertyMap extends HashMap<String, ValueMetaData> implements MetaDataVisitorNode, TypeProvider
+{
+ /** The configuration */
+ private static Configuration configuration;
+
+ static
+ {
+ // get Configuration instance
+ configuration = AccessController.doPrivileged(new PrivilegedAction<Configuration>()
+ {
+ public Configuration run()
+ {
+ return new PropertyConfiguration();
+ }
+ });
+ }
+
+ /**
+ * The serialVersionUID
+ */
+ private static final long serialVersionUID = -4295725682462294630L;
+
+ public void initialVisit(MetaDataVisitor visitor)
+ {
+ visitor.initialVisit(this);
+ }
+
+ public void describeVisit(MetaDataVisitor vistor)
+ {
+ vistor.describeVisit(this);
+ }
+
+ public Iterator<? extends MetaDataVisitorNode> getChildren()
+ {
+ return values().iterator();
+ }
+
+ public ValueMetaData put(String name, ValueMetaData value)
+ {
+ ValueInfo info = new ValueInfo(name, value);
+ return super.put(name, info);
+ }
+
+ public TypeInfo getType(MetaDataVisitor visitor, MetaDataVisitorNode previous) throws Throwable
+ {
+ ValueInfo valueInfo = null;
+ for (ValueMetaData value : values())
+ {
+ if (value.equals(previous))
+ {
+ valueInfo = ValueInfo.class.cast(value);
+ break;
+ }
+ }
+ if (valueInfo == null)
+ throw new IllegalArgumentException("No matching value (" + previous + ") found: " + values());
+
+ KernelControllerContext context = visitor.getControllerContext();
+ BeanMetaData bmd = context.getBeanMetaData();
+ Set<RelatedClassMetaData> related = bmd.getRelated();
+ if (related == null || related.size() != 1)
+ throw new IllegalArgumentException("Invalid information for contextual injection: " + bmd);
+ // TODO - perhaps match which related metadata is the right one
+ RelatedClassMetaData beanClassMetaData = related.iterator().next();
+ BeanInfo beanInfo = configuration.getBeanInfo(beanClassMetaData.getClassName(), context.getClassLoader());
+ PropertyInfo pi = beanInfo.getProperty(valueInfo.name);
+ TypeInfo typeInfo = pi.getType();
+ if (typeInfo.isCollection() || typeInfo.isMap())
+ {
+ throw new IllegalArgumentException("Cannot handle collection or map: " + valueInfo);
+ }
+ return typeInfo;
+ }
+
+ private static class ValueInfo extends JBossObject implements ValueMetaData, Serializable
+ {
+ private static final long serialVersionUID = 1L;
+
+ private String name;
+ private ValueMetaData value;
+
+ private ValueInfo(String name, ValueMetaData value)
+ {
+ this.name = name;
+ this.value = value;
+ }
+
+ public Object getUnderlyingValue()
+ {
+ return value.getUnderlyingValue();
+ }
+
+ public Object getValue(TypeInfo info, ClassLoader cl) throws Throwable
+ {
+ return value.getValue(info, cl);
+ }
+
+ public void initialVisit(MetaDataVisitor vistor)
+ {
+ value.initialVisit(vistor);
+ }
+
+ public void describeVisit(MetaDataVisitor vistor)
+ {
+ value.describeVisit(vistor);
+ }
+
+ public Iterator<? extends MetaDataVisitorNode> getChildren()
+ {
+ return value.getChildren();
+ }
+
+ public void toShortString(JBossStringBuilder buffer)
+ {
+ value.toShortString(buffer);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return value.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ return value.equals(obj);
+ }
+
+ public String toShortString()
+ {
+ return value.toShortString();
+ }
+ }
+}
Property changes on: projects/microcontainer/trunk/kernel/src/main/java/org/jboss/beans/metadata/spi/factory/PropertyMap.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/deployment/support/FirstBean2.java (from rev 83617, projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/deployment/support/FirstBean.java)
===================================================================
--- projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/deployment/support/FirstBean2.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/deployment/support/FirstBean2.java 2009-01-29 18:38:57 UTC (rev 83627)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.deployment.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class FirstBean2
+{
+ private RealTM tm;
+
+ public RealTM getTm()
+ {
+ return tm;
+ }
+
+ public void setTm(RealTM tm)
+ {
+ this.tm = tm;
+ }
+}
\ No newline at end of file
Property changes on: projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/deployment/support/FirstBean2.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/deployment/test/BeanFactoryContextualInjectionTestCase.java (from rev 83617, projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/deployment/test/BeanMetaDataFactoryTestCase.java)
===================================================================
--- projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/deployment/test/BeanFactoryContextualInjectionTestCase.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/deployment/test/BeanFactoryContextualInjectionTestCase.java 2009-01-29 18:38:57 UTC (rev 83627)
@@ -0,0 +1,51 @@
+/*
+* 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.test.kernel.deployment.test;
+
+import junit.framework.Test;
+import org.jboss.beans.metadata.spi.factory.BeanFactory;
+import org.jboss.test.kernel.deployment.support.FirstBean2;
+
+/**
+ * BeanFactoryContextualInjectionTestCase.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class BeanFactoryContextualInjectionTestCase extends AbstractDeploymentTest
+{
+ public static Test suite()
+ {
+ return suite(BeanFactoryContextualInjectionTestCase.class);
+ }
+
+ public BeanFactoryContextualInjectionTestCase(String name) throws Throwable
+ {
+ super(name);
+ }
+
+ public void testContextualInjection() throws Throwable
+ {
+ BeanFactory bf = assertBean("FirstBean", BeanFactory.class);
+ FirstBean2 bean = (FirstBean2)bf.createBean();
+ assertNotNull(bean.getTm());
+ }
+}
\ No newline at end of file
Property changes on: projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/deployment/test/BeanFactoryContextualInjectionTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Modified: projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/deployment/test/DeploymentTestSuite.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/deployment/test/DeploymentTestSuite.java 2009-01-29 17:19:16 UTC (rev 83626)
+++ projects/microcontainer/trunk/kernel/src/test/java/org/jboss/test/kernel/deployment/test/DeploymentTestSuite.java 2009-01-29 18:38:57 UTC (rev 83627)
@@ -75,6 +75,7 @@
suite.addTest(GetInstanceTestCase.suite());
suite.addTest(NullifyTestCase.suite());
suite.addTest(TransitiveBeansTestCase.suite());
+ suite.addTest(BeanFactoryContextualInjectionTestCase.suite());
// bean container tests
suite.addTest(BeanContainerUsageTestCase.suite());
suite.addTest(BeanContainerUsageMDTestCase.suite());
Copied: projects/microcontainer/trunk/kernel/src/test/resources/org/jboss/test/kernel/deployment/test/BeanFactoryContextualInjectionTestCase.xml (from rev 83617, projects/microcontainer/trunk/kernel/src/test/resources/org/jboss/test/kernel/deployment/test/TransitiveBeansTestCase.xml)
===================================================================
--- projects/microcontainer/trunk/kernel/src/test/resources/org/jboss/test/kernel/deployment/test/BeanFactoryContextualInjectionTestCase.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/test/resources/org/jboss/test/kernel/deployment/test/BeanFactoryContextualInjectionTestCase.xml 2009-01-29 18:38:57 UTC (rev 83627)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="RealTM" class="org.jboss.test.kernel.deployment.support.RealTM"/>
+
+ <beanfactory name="FirstBean" class="org.jboss.test.kernel.deployment.support.FirstBean2">
+ <property name="tm"><inject/></property>
+ </beanfactory>
+
+</deployment>
More information about the jboss-cvs-commits
mailing list