[webbeans-commits] Webbeans SVN: r260 - in ri/trunk/webbeans-ri/src: main/java/org/jboss/webbeans/injectable and 4 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Thu Nov 6 09:40:22 EST 2008
Author: pete.muir at jboss.org
Date: 2008-11-06 09:40:22 -0500 (Thu, 06 Nov 2008)
New Revision: 260
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java
Removed:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerBean.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/BeanConstructor.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/EnterpriseConstructor.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/JMSConstructor.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/MethodConstructor.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/ProducerMethodBeanModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBeanModelTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodBeanLifecycleTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/util/Util.java
Log:
Wire in producer methods
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2008-11-06 14:01:57 UTC (rev 259)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2008-11-06 14:40:22 UTC (rev 260)
@@ -21,11 +21,6 @@
this.manager = manager;
}
- protected T getInstance()
- {
- return getModel().getConstructor().invoke(manager);
- }
-
protected void bindInterceptors()
{
// TODO
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerBean.java 2008-11-06 14:01:57 UTC (rev 259)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerBean.java 2008-11-06 14:40:22 UTC (rev 260)
@@ -1,32 +0,0 @@
-package org.jboss.webbeans.bean;
-
-import org.jboss.webbeans.ManagerImpl;
-import org.jboss.webbeans.model.bean.ProducerMethodBeanModel;
-
-public class ProducerBean<T> extends AbstractBean<T>
-{
-
- private ProducerMethodBeanModel<T> model;
-
- public ProducerBean(ProducerMethodBeanModel<T> model, ManagerImpl manager)
- {
- super(manager);
- this.model = model;
- }
-
- @Override
- public ProducerMethodBeanModel<T> getModel()
- {
- return model;
- }
-
- @Override
- public T create()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
-
-
-}
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java (from rev 258, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerBean.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java 2008-11-06 14:40:22 UTC (rev 260)
@@ -0,0 +1,31 @@
+package org.jboss.webbeans.bean;
+
+import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.model.bean.ProducerMethodBeanModel;
+
+public class ProducerMethodBean<T> extends AbstractBean<T>
+{
+
+ private ProducerMethodBeanModel<T> model;
+
+ public ProducerMethodBean(ProducerMethodBeanModel<T> model, ManagerImpl manager)
+ {
+ super(manager);
+ this.model = model;
+ }
+
+ @Override
+ public ProducerMethodBeanModel<T> getModel()
+ {
+ return model;
+ }
+
+ @Override
+ public T create()
+ {
+ return model.getConstructor().invoke(manager, manager.getInstance(model.getDeclaringBean()));
+ }
+
+
+
+}
Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2008-11-06 14:01:57 UTC (rev 259)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2008-11-06 14:40:22 UTC (rev 260)
@@ -19,7 +19,7 @@
@Override
public T create()
{
- T instance = getInstance();
+ T instance = model.getConstructor().invoke(manager);
bindDecorators();
bindInterceptors();
injectEjbAndCommonFields();
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/BeanConstructor.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/BeanConstructor.java 2008-11-06 14:01:57 UTC (rev 259)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/BeanConstructor.java 2008-11-06 14:40:22 UTC (rev 260)
@@ -5,6 +5,6 @@
public interface BeanConstructor<T, S>
{
- public T invoke(ManagerImpl manager);
+ public T invoke(ManagerImpl manager, Object instance);
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/EnterpriseConstructor.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/EnterpriseConstructor.java 2008-11-06 14:01:57 UTC (rev 259)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/EnterpriseConstructor.java 2008-11-06 14:40:22 UTC (rev 260)
@@ -28,4 +28,9 @@
}
}
+ public T invoke(ManagerImpl manager, Object instance)
+ {
+ return invoke(manager);
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/JMSConstructor.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/JMSConstructor.java 2008-11-06 14:01:57 UTC (rev 259)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/JMSConstructor.java 2008-11-06 14:40:22 UTC (rev 260)
@@ -25,5 +25,10 @@
// TODO Auto-generated method stub
return null;
}
+
+ public T invoke(ManagerImpl manager, Object instance)
+ {
+ return invoke(manager);
+ }
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/MethodConstructor.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/MethodConstructor.java 2008-11-06 14:01:57 UTC (rev 259)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/MethodConstructor.java 2008-11-06 14:40:22 UTC (rev 260)
@@ -4,6 +4,7 @@
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.introspector.AnnotatedMethod;
+import org.jboss.webbeans.util.Reflections;
public class MethodConstructor<T> extends InjectableMethod<T> implements
BeanConstructor<T, AnnotatedMethod<T>>
@@ -13,17 +14,10 @@
{
super(method);
}
-
- @Override
- public AnnotatedMethod<T> getAnnotatedItem()
- {
- return null;
- }
- public T invoke(ManagerImpl manager)
+ public T invoke(ManagerImpl manager, Object instance)
{
- // TODO Auto-generated method stub
- return null;
+ return (T) Reflections.invokeAndWrap(getAnnotatedItem().getDelegate(), instance, getParameterValues(manager));
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/ProducerMethodBeanModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/ProducerMethodBeanModel.java 2008-11-06 14:01:57 UTC (rev 259)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/ProducerMethodBeanModel.java 2008-11-06 14:40:22 UTC (rev 260)
@@ -13,6 +13,7 @@
import javax.webbeans.Observes;
import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.bean.AbstractBean;
import org.jboss.webbeans.injectable.InjectableMethod;
import org.jboss.webbeans.injectable.InjectableParameter;
import org.jboss.webbeans.injectable.MethodConstructor;
@@ -28,16 +29,17 @@
private AnnotatedItem<T, Method> xmlAnnotatedItem;
private AnnotatedMethod<T> annotatedMethod;
- private BeanModel<?, ?> declaringBean;
+ private AbstractBean<?> declaringBean;
// Cached values
private String location;
private Type declaredBeanType;
- public ProducerMethodBeanModel(AnnotatedMethod<T> annotatedMethod, AnnotatedMethod<T> xmlAnnotatedMethod, ManagerImpl manager)
+ public ProducerMethodBeanModel(AnnotatedMethod<T> annotatedMethod, AnnotatedMethod<T> xmlAnnotatedMethod, ManagerImpl manager, AbstractBean<?> declaringBean)
{
this.annotatedMethod = annotatedMethod;
this.xmlAnnotatedItem = xmlAnnotatedMethod;
+ this.declaringBean = declaringBean;
init(manager);
}
@@ -74,18 +76,9 @@
super.initDeploymentType();
if (getDeploymentType() == null)
{
- if (getDeclaringBean() == null)
- {
- initDeclaringBean(manager);
- }
deploymentType = declaringBean.getDeploymentType();
}
}
-
- protected void initDeclaringBean(ManagerImpl container)
- {
- declaringBean = container.getModelManager().getBeanModel(getAnnotatedItem().getDelegate().getDeclaringClass());
- }
public MethodConstructor<T> getConstructor()
{
@@ -236,7 +229,7 @@
return removeMethod;
}
- public BeanModel<?, ?> getDeclaringBean()
+ public AbstractBean<?> getDeclaringBean()
{
return declaringBean;
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java 2008-11-06 14:01:57 UTC (rev 259)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java 2008-11-06 14:40:22 UTC (rev 260)
@@ -248,11 +248,11 @@
return type.getTypeParameters().length > 0;
}
- public static Object invokeAndWrap(Method method, Object instance)
+ public static Object invokeAndWrap(Method method, Object instance, Object... parameters)
{
try
{
- return method.invoke(instance);
+ return method.invoke(instance, parameters);
}
catch (IllegalArgumentException e)
{
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBeanModelTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBeanModelTest.java 2008-11-06 14:01:57 UTC (rev 259)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBeanModelTest.java 2008-11-06 14:40:22 UTC (rev 260)
@@ -92,7 +92,7 @@
{
BeanConstructor<EventImpl<DangerCall>, ?> constructor = eventBeanModel.getConstructor();
assert constructor != null;
- Event<DangerCall> event = constructor.invoke(manager);
+ Event<DangerCall> event = constructor.invoke(manager, null);
assert event != null;
}
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodBeanLifecycleTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodBeanLifecycleTest.java 2008-11-06 14:01:57 UTC (rev 259)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodBeanLifecycleTest.java 2008-11-06 14:40:22 UTC (rev 260)
@@ -1,11 +1,31 @@
package org.jboss.webbeans.test;
+import static org.jboss.webbeans.test.util.Util.createProducerMethodBean;
+import static org.jboss.webbeans.test.util.Util.createSimpleWebBean;
+
+import java.lang.reflect.Method;
+
import javax.webbeans.DefinitionException;
+import org.jboss.webbeans.bean.ProducerMethodBean;
+import org.jboss.webbeans.bean.SimpleBean;
+import org.jboss.webbeans.test.beans.SpiderProducer;
+import org.jboss.webbeans.test.beans.Tarantula;
import org.testng.annotations.Test;
-public class ProducerMethodBeanLifecycleTest
+public class ProducerMethodBeanLifecycleTest extends AbstractTest
{
+
+ @Test(groups="producerMethod") @SpecAssertion(section="5.6")
+ public void testProducerMethodBeanCreate() throws Exception
+ {
+ SimpleBean<SpiderProducer> spiderProducer = createSimpleWebBean(SpiderProducer.class, manager);
+ manager.addBean(spiderProducer);
+ Method method = SpiderProducer.class.getMethod("produceTarantula");
+ ProducerMethodBean<Tarantula> tarantulaBean = createProducerMethodBean(Tarantula.class, method, manager, spiderProducer);
+ Tarantula tarantula = tarantulaBean.create();
+ assert tarantula != null;
+ }
@Test(groups="producerMethod") @SpecAssertion(section="3.3")
public void testNonDependentProducerMethodThatReturnsNull()
@@ -43,13 +63,13 @@
}
- @Test(groups="producerMethod") @SpecAssertion(section="3.4")
+ @Test(groups="producerMethod") @SpecAssertion(section={"3.4", "5.6"})
public void testProducerMethodReturnsNullIsDependent()
{
assert false;
}
- @Test(groups="producerMethod", expectedExceptions=DefinitionException.class) @SpecAssertion(section="3.4")
+ @Test(groups="producerMethod", expectedExceptions=DefinitionException.class) @SpecAssertion(section={"3.4", "5.6"})
public void testProducerMethodReturnsNullIsNotDependent()
{
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/util/Util.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/util/Util.java 2008-11-06 14:01:57 UTC (rev 259)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/util/Util.java 2008-11-06 14:40:22 UTC (rev 260)
@@ -5,7 +5,8 @@
import java.util.HashMap;
import org.jboss.webbeans.ManagerImpl;
-import org.jboss.webbeans.bean.ProducerBean;
+import org.jboss.webbeans.bean.AbstractBean;
+import org.jboss.webbeans.bean.ProducerMethodBean;
import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.introspector.AnnotatedMethod;
@@ -42,19 +43,29 @@
return new EnterpriseBeanModel<T>(new SimpleAnnotatedClass<T>(clazz), xmlAnnotatedType, manager);
}
- public static <T> ProducerBean<T> createProducerMethodBean(Class<T> type, Method method, ManagerImpl manager)
+ public static <T> ProducerMethodBean<T> createProducerMethodBean(Class<T> type, Method method, ManagerImpl manager, AbstractBean<?> declaringBean)
{
- return new ProducerBean<T>(createProducerModel(type, method, null, manager), manager);
+ return new ProducerMethodBean<T>(createProducerModel(type, method, null, manager, declaringBean), manager);
}
+ public static <T> ProducerMethodBean<T> createProducerMethodBean(Class<T> type, Method method, ManagerImpl manager)
+ {
+ return createProducerMethodBean(type, method, manager, null);
+ }
+
public static <T> ProducerMethodBeanModel<T> createProducerModel(Class<T> type, Method method, ManagerImpl manager)
{
return createProducerModel(type, method, null, manager);
}
+ public static <T> ProducerMethodBeanModel<T> createProducerModel(Class<T> type, Method method, AnnotatedMethod<T> xmlAnnotatedMethod, ManagerImpl manager, AbstractBean<?> declaringBean)
+ {
+ return new ProducerMethodBeanModel<T>(new SimpleAnnotatedMethod<T>(method), xmlAnnotatedMethod, manager, declaringBean);
+ }
+
public static <T> ProducerMethodBeanModel<T> createProducerModel(Class<T> type, Method method, AnnotatedMethod<T> xmlAnnotatedMethod, ManagerImpl manager)
{
- return new ProducerMethodBeanModel<T>(new SimpleAnnotatedMethod<T>(method), xmlAnnotatedMethod, manager);
+ return createProducerModel(type, method, xmlAnnotatedMethod, manager, null);
}
@Deprecated
More information about the weld-commits
mailing list