[webbeans-commits] Webbeans SVN: r125 - in ri/trunk/webbeans-ri/src: main/java/org/jboss/webbeans/injectable and 3 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Tue Oct 21 07:42:04 EDT 2008
Author: dallen6
Date: 2008-10-21 07:42:04 -0400 (Tue, 21 Oct 2008)
New Revision: 125
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/Injectable.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/SimpleConstructor.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedConstructor.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractClassComponentModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/EventComponentModel.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventComponentModelTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ObserverTest.java
Log:
Finished changes to the container provided Event implementation to use the new Injectables and a few other bug fixes with related classes.
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java 2008-10-20 20:37:29 UTC (rev 124)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java 2008-10-21 11:42:04 UTC (rev 125)
@@ -29,11 +29,16 @@
@Current
protected Manager webBeansManager;
- public EventImpl(Annotation... eventBindings)
+ /**
+ * Used to set the event bindings for this type of event after it is constructed
+ * with the default constructor.
+ * @param eventBindings Annotations that are bindings for the event
+ */
+ public void setEventBindings(Annotation... eventBindings)
{
this.eventBindings = Arrays.asList(eventBindings);
}
-
+
/*
* (non-Javadoc)
*
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/Injectable.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/Injectable.java 2008-10-20 20:37:29 UTC (rev 124)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/Injectable.java 2008-10-21 11:42:04 UTC (rev 125)
@@ -30,7 +30,7 @@
public Annotation[] getBindingTypes()
{
- return (Annotation[]) annotatedItem.getAnnotations().toArray();
+ return annotatedItem.getAnnotations().toArray(new Annotation[0]);
}
protected Injectable() {}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/SimpleConstructor.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/SimpleConstructor.java 2008-10-20 20:37:29 UTC (rev 124)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/SimpleConstructor.java 2008-10-21 11:42:04 UTC (rev 125)
@@ -19,7 +19,6 @@
private AnnotatedConstructor<T> constructor;
- @SuppressWarnings("unchecked")
public SimpleConstructor(Constructor<T> constructor)
{
super(constructor.getParameterTypes(), constructor.getParameterAnnotations());
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedConstructor.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedConstructor.java 2008-10-20 20:37:29 UTC (rev 124)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedConstructor.java 2008-10-21 11:42:04 UTC (rev 125)
@@ -21,7 +21,7 @@
@Override
public String toString()
{
- return constructor + " " + getAnnotatedConstructor().toString();
+ return constructor.toGenericString();
}
public Constructor<T> getDelegate()
@@ -29,7 +29,6 @@
return constructor;
}
- @SuppressWarnings("unchecked")
public Class<? extends T> getType()
{
return constructor.getDeclaringClass();
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractClassComponentModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractClassComponentModel.java 2008-10-20 20:37:29 UTC (rev 124)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractClassComponentModel.java 2008-10-21 11:42:04 UTC (rev 125)
@@ -87,13 +87,11 @@
{
log.finest("Component type specified in XML");
this.type = getXmlAnnotatedItem().getDelegate();
- return;
}
else if (getAnnotatedItem().getDelegate() != null)
{
log.finest("Component type specified in Java");
this.type = getAnnotatedItem().getDelegate();
- return;
}
else
{
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/EventComponentModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/EventComponentModel.java 2008-10-20 20:37:29 UTC (rev 124)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/EventComponentModel.java 2008-10-21 11:42:04 UTC (rev 125)
@@ -1,11 +1,17 @@
package org.jboss.webbeans.model;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.util.logging.Logger;
+
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.bindings.DependentAnnotationLiteral;
import org.jboss.webbeans.bindings.StandardAnnotationLiteral;
import org.jboss.webbeans.injectable.ComponentConstructor;
+import org.jboss.webbeans.injectable.SimpleConstructor;
import org.jboss.webbeans.introspector.AnnotatedItem;
-import org.jboss.webbeans.introspector.SimpleAnnotatedItem;
+import org.jboss.webbeans.introspector.SimpleAnnotatedField;
+import org.jboss.webbeans.util.LoggerUtil;
/**
* Web Beans component meta model for the container instantiated, injectable,
@@ -14,13 +20,16 @@
* @author David Allen
*
*/
-public class EventComponentModel<T> extends AbstractComponentModel<T, Object>
+public class EventComponentModel<T> extends AbstractComponentModel<T, Field>
{
+ private static Logger log = LoggerUtil.getLogger(LOGGER_NAME);
+
private String location;
- private AnnotatedItem<T, Object> annotatedItem;
- private AnnotatedItem<T, Object> xmlAnnotatedItem;
+ private SimpleAnnotatedField<T> annotatedItem;
+ private SimpleAnnotatedField<T> xmlAnnotatedItem;
+ private ComponentConstructor<T> constructor;
- public EventComponentModel(SimpleAnnotatedItem<T, Object> annotatedItem, SimpleAnnotatedItem<T, Object> xmlAnnotatedItem, ManagerImpl manager)
+ public EventComponentModel(SimpleAnnotatedField<T> annotatedItem, SimpleAnnotatedField<T> xmlAnnotatedItem, ManagerImpl manager)
{
this.annotatedItem = annotatedItem;
this.xmlAnnotatedItem = xmlAnnotatedItem;
@@ -28,10 +37,28 @@
}
@Override
+ protected void init(ManagerImpl container)
+ {
+ super.init(container);
+ this.initConstructor();
+ }
+
+ /**
+ * Initializes the constructor field of this class.
+ */
+ @SuppressWarnings("unchecked")
+ protected void initConstructor()
+ {
+ // There should only be one constructor for the event implementation used here
+ Constructor[] constructors = this.annotatedItem.getType().getConstructors();
+ Constructor<T> classConstructor = (Constructor<T>)constructors[0];
+ constructor = new SimpleConstructor<T>(classConstructor);
+ }
+
+ @Override
public ComponentConstructor<T> getConstructor()
{
- // TODO No constructor is needed, but make sure this does not brake instantiation
- return null;
+ return constructor;
}
@Override
@@ -53,15 +80,23 @@
/* (non-Javadoc)
* @see org.jboss.webbeans.model.AbstractClassComponentModel#initType()
*/
+ @SuppressWarnings("unchecked")
@Override
protected void initType()
{
- // TODO Get the class for Event and use it for the type
- this.type = null;
+ if (getXmlAnnotatedItem().getDelegate() != null)
+ {
+ log.finest("Component type specified in XML");
+ this.type = (Class<T>) xmlAnnotatedItem.getType();
+ } else if (getAnnotatedItem().getDelegate() != null)
+ {
+ log.finest("Component type specified in Java");
+ this.type = (Class<T>) annotatedItem.getType();
+ }
}
@Override
- protected AnnotatedItem<T, Object> getAnnotatedItem()
+ protected AnnotatedItem<T, Field> getAnnotatedItem()
{
return this.annotatedItem;
}
@@ -74,7 +109,7 @@
}
@Override
- protected AnnotatedItem<T, Object> getXmlAnnotatedItem()
+ protected AnnotatedItem<T, Field> getXmlAnnotatedItem()
{
return this.xmlAnnotatedItem;
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventComponentModelTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventComponentModelTest.java 2008-10-20 20:37:29 UTC (rev 124)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventComponentModelTest.java 2008-10-21 11:42:04 UTC (rev 125)
@@ -1,8 +1,8 @@
package org.jboss.webbeans.test;
import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Set;
@@ -11,10 +11,12 @@
import javax.webbeans.Standard;
import org.jboss.webbeans.bindings.StandardAnnotationLiteral;
+import org.jboss.webbeans.event.EventImpl;
import org.jboss.webbeans.injectable.ComponentConstructor;
-import org.jboss.webbeans.introspector.SimpleAnnotatedItem;
+import org.jboss.webbeans.introspector.SimpleAnnotatedField;
import org.jboss.webbeans.model.EventComponentModel;
import org.jboss.webbeans.test.bindings.AnotherDeploymentTypeAnnotationLiteral;
+import org.jboss.webbeans.test.components.DangerCall;
import org.jboss.webbeans.test.mock.MockContainerImpl;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -29,7 +31,8 @@
public class EventComponentModelTest
{
private MockContainerImpl manager = null;
- private EventComponentModel<Event<? extends Object>> eventComponentModel = null;
+ private EventComponentModel<EventImpl<DangerCall>> eventComponentModel = null;
+ EventImpl<DangerCall> eventModelField = null;
@BeforeMethod
public void before() throws Exception
@@ -38,11 +41,10 @@
enabledDeploymentTypes.add(new StandardAnnotationLiteral());
enabledDeploymentTypes.add(new AnotherDeploymentTypeAnnotationLiteral());
manager = new MockContainerImpl(enabledDeploymentTypes);
- eventComponentModel = new EventComponentModel<Event<? extends Object>>(
- new SimpleAnnotatedItem<Event<? extends Object>, Object>(
- new HashMap<Class<? extends Annotation>, Annotation>()),
- new SimpleAnnotatedItem<Event<? extends Object>, Object>(
- new HashMap<Class<? extends Annotation>, Annotation>()),
+ Field eventModelField = this.getClass().getDeclaredField("eventModelField");
+ eventComponentModel = new EventComponentModel<EventImpl<DangerCall>>(
+ new SimpleAnnotatedField<EventImpl<DangerCall>>(eventModelField),
+ new SimpleAnnotatedField<EventImpl<DangerCall>>(eventModelField),
manager);
}
@@ -88,9 +90,9 @@
@Test(groups = "eventbus")
public void testConstructor()
{
- ComponentConstructor<Event<? extends Object>> constructor = eventComponentModel.getConstructor();
+ ComponentConstructor<EventImpl<DangerCall>> constructor = eventComponentModel.getConstructor();
assert constructor != null;
- Event<? extends Object> event = constructor.invoke(manager);
+ Event<DangerCall> event = constructor.invoke(manager);
assert event != null;
}
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventTest.java 2008-10-20 20:37:29 UTC (rev 124)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventTest.java 2008-10-21 11:42:04 UTC (rev 125)
@@ -28,6 +28,7 @@
* @author David Allen
*
*/
+ at SpecVersion("20081012")
public class EventTest
{
private MockContainerImpl manager = null;
@@ -42,19 +43,19 @@
}
/**
- * Tests the {@link Event#fire(Object, Annotation...)} method with a sample
- * event component.
+ * Tests the {@link Event#fire(Object, Annotation...)} method with a locally
+ * instantiated implementation.
*/
@SuppressWarnings("unchecked")
- @Test(groups = "eventbus")
+ @Test(groups = "eventbus") @SpecAssertion(section="7.4")
public void testFireEvent()
{
DangerCall anEvent = new DangerCall();
// Create a test annotation for the event and use it to construct the
// event object
Annotation[] annotations = new Annotation[] { new AnimalStereotypeAnnotationLiteral() };
- EventImpl<DangerCall> eventComponent = new EventImpl<DangerCall>(
- annotations);
+ EventImpl<DangerCall> eventComponent = new EventImpl<DangerCall>();
+ eventComponent.setEventBindings(annotations);
eventComponent.setManager(manager);
eventComponent.fire(anEvent, new TameAnnotationLiteral(),
new SynchronousAnnotationLiteral());
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ObserverTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ObserverTest.java 2008-10-20 20:37:29 UTC (rev 124)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ObserverTest.java 2008-10-21 11:42:04 UTC (rev 125)
@@ -32,6 +32,7 @@
* @author David Allen
*
*/
+ at SpecVersion("20081012")
public class ObserverTest
{
private ManagerImpl manager;
@@ -75,7 +76,7 @@
* {@link org.jboss.webbeans.event.ObserverImpl#getEventBindingTypes()}.
*/
@SuppressWarnings("unchecked")
- @Test(groups = "eventbus")
+ @Test(groups = "eventbus") @SpecAssertion(section="7.3")
public final void testGetEventBindingTypes() throws Exception
{
Observer<Event> o = new ObserverImpl<Event>(tuna, om, Event.class);
@@ -91,7 +92,7 @@
* @throws
* @throws Exception
*/
- @Test(groups = "eventbus")
+ @Test(groups = "eventbus") @SpecAssertion(section="7.3")
public final void testGetEventType() throws Exception
{
Observer<Event> o = new ObserverImpl<Event>(tuna, om, Event.class);
@@ -103,7 +104,7 @@
* {@link org.jboss.webbeans.event.ObserverImpl#notify(javax.webbeans.Container, java.lang.Object)}
* .
*/
- @Test(groups = "eventbus")
+ @Test(groups = "eventbus") @SpecAssertion(section={"7.2","7.3"})
public final void testNotify() throws Exception
{
AnObserver observerInstance = new AnObserver();
More information about the weld-commits
mailing list