[webbeans-commits] Webbeans SVN: r117 - in ri/trunk: webbeans-ri/src/main/java/org/jboss/webbeans/event and 3 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Wed Oct 15 04:19:05 EDT 2008
Author: dallen6
Date: 2008-10-15 04:19:05 -0400 (Wed, 15 Oct 2008)
New Revision: 117
Added:
ri/trunk/webbeans-api/src/main/java/javax/webbeans/DuplicateBindingTypeException.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/bindings/TameAnnotationLiteral.java
Modified:
ri/trunk/webbeans-api/src/main/java/javax/webbeans/Event.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.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/EventTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/FishStereotypeAnnotationLiteral.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/RiverFishStereotypeAnnotationLiteral.java
Log:
Refactored event implementation and updated event APIs to latest specification revision.
Added: ri/trunk/webbeans-api/src/main/java/javax/webbeans/DuplicateBindingTypeException.java
===================================================================
--- ri/trunk/webbeans-api/src/main/java/javax/webbeans/DuplicateBindingTypeException.java (rev 0)
+++ ri/trunk/webbeans-api/src/main/java/javax/webbeans/DuplicateBindingTypeException.java 2008-10-15 08:19:05 UTC (rev 117)
@@ -0,0 +1,50 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package javax.webbeans;
+
+/**
+ * This exception is thrown whenever more than one binding type instance of the
+ * same type is used with the API.
+ *
+ * @author David Allen
+ */
+public class DuplicateBindingTypeException extends RuntimeException
+{
+
+ private static final long serialVersionUID = 4194175477451120383L;
+
+ public DuplicateBindingTypeException()
+ {
+ super();
+ }
+
+ public DuplicateBindingTypeException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public DuplicateBindingTypeException(String message)
+ {
+ super(message);
+ }
+
+ public DuplicateBindingTypeException(Throwable cause)
+ {
+ super(cause);
+ }
+
+}
Property changes on: ri/trunk/webbeans-api/src/main/java/javax/webbeans/DuplicateBindingTypeException.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/webbeans-api/src/main/java/javax/webbeans/Event.java
===================================================================
--- ri/trunk/webbeans-api/src/main/java/javax/webbeans/Event.java 2008-10-07 16:30:19 UTC (rev 116)
+++ ri/trunk/webbeans-api/src/main/java/javax/webbeans/Event.java 2008-10-15 08:19:05 UTC (rev 117)
@@ -19,6 +19,8 @@
import java.lang.annotation.Annotation;
+import javax.webbeans.manager.Observer;
+
/**
*
* @author Pete Muir
@@ -29,4 +31,6 @@
public void fire(T event, Annotation... bindings);
+ public void observes(Observer<T> observe, Annotation... bindings);
+
}
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-07 16:30:19 UTC (rev 116)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java 2008-10-15 08:19:05 UTC (rev 117)
@@ -2,54 +2,123 @@
import java.lang.annotation.Annotation;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Set;
import java.util.HashSet;
+import javax.webbeans.BindingType;
import javax.webbeans.Current;
+import javax.webbeans.DuplicateBindingTypeException;
import javax.webbeans.Event;
import javax.webbeans.manager.Manager;
+import javax.webbeans.manager.Observer;
-import org.jboss.webbeans.BeanImpl;
-import org.jboss.webbeans.model.EventComponentModel;
-
/**
- * Implementation of an event as a simple component.
+ * Implementation of the {@link Event} interface used for the container provided
+ * Web Bean to be injected for an observable event. See section 7.4 of the JSR
+ * for more details on how this bean is provided by the container and used.
*
* @author David Allen
- *
+ *
*/
-public class EventImpl<T> extends BeanImpl<T> implements Event<T>
+public class EventImpl<T> implements Event<T>
{
+ private Collection<? extends Annotation> eventBindings;
+
// The current WB manager
@Current
protected Manager webBeansManager;
- /**
- * Creates a simple implementation of {@link Event} with no default
- * event bindings.
- */
- public EventImpl(EventComponentModel<T> componentMetaModel) {
- super(componentMetaModel);
+ public EventImpl(Annotation... eventBindings)
+ {
+ this.eventBindings = Arrays.asList(eventBindings);
}
-
- /* (non-Javadoc)
- * @see javax.webbeans.Event#fire(java.lang.Object, java.lang.annotation.Annotation[])
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.webbeans.Event#fire(java.lang.Object,
+ * java.lang.annotation.Annotation[])
*/
public void fire(T event, Annotation... bindings)
{
- // Combine the annotations passed here with the annotations (event bindings)
+ // Combine the annotations passed here with the annotations (event
+ // bindings)
// specified on the @Observable object.
Set<Annotation> eventBindings = new HashSet<Annotation>();
eventBindings.addAll(this.getBindingTypes());
- eventBindings.addAll(Arrays.asList(bindings));
-
+ // eventBindings.addAll(Arrays.asList(bindings));
+ addAnnotationBindings(eventBindings, bindings);
+
// Invoke the container method to fire the event per 7.2
- webBeansManager.fireEvent(event, eventBindings.toArray(new Annotation[0]));
+ webBeansManager
+ .fireEvent(event, eventBindings.toArray(new Annotation[0]));
}
+ public void observes(Observer<T> observe, Annotation... bindings)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * Adds each of the annotation bindings to the set, but if any binding
+ * already exists in the set, a {@link DuplicateBindingTypeException} is
+ * thrown.
+ *
+ * @param bindingsSet
+ * @param bindings
+ * @throws DuplicateBindingTypeException
+ * if any of bindings are duplicates
+ */
+ private void addAnnotationBindings(Set<Annotation> bindingsSet,
+ Annotation[] bindings)
+ {
+ if (bindings != null)
+ {
+ Set<Class<? extends Annotation>> bindingTypes = new HashSet<Class<? extends Annotation>>();
+ for (Annotation annotation : bindings)
+ {
+ // Check that the binding type is indeed a binding type
+ Annotation[] bindingAnnotations = annotation.annotationType()
+ .getAnnotations();
+ boolean isBindingType = false;
+ for (Annotation bindingAnnotation : bindingAnnotations)
+ {
+ if (bindingAnnotation.annotationType().equals(BindingType.class))
+ {
+ isBindingType = true;
+ }
+ }
+ if (!isBindingType)
+ throw new IllegalArgumentException("Annotation " + annotation
+ + " is not a binding type");
+
+ // Check that no binding type was specified more than once in the
+ // annotations
+ if (bindingTypes.contains(annotation.annotationType()))
+ {
+ throw new DuplicateBindingTypeException();
+ } else
+ {
+ bindingTypes.add(annotation.annotationType());
+ }
+ }
+ bindingsSet.addAll(Arrays.asList(bindings));
+ }
+
+ }
+
+ private Collection<? extends Annotation> getBindingTypes()
+ {
+ // Get the binding types directly from the model for the component
+ return this.eventBindings;
+ }
+
// TODO Remove the setter for the manager once WB injection is working
public void setManager(Manager manager)
{
this.webBeansManager = manager;
}
+
}
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-07 16:30:19 UTC (rev 116)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/EventComponentModel.java 2008-10-15 08:19:05 UTC (rev 117)
@@ -9,7 +9,7 @@
/**
* Web Beans component meta model for the container instantiated, injectable,
- * observable events (Section 7.2).
+ * observable events (Section 7.4).
*
* @author David Allen
*
@@ -56,7 +56,7 @@
@Override
protected void initType()
{
- // TODO Type is null but maybe should be EventImpl
+ // TODO Get the class for Event and use it for the type
this.type = null;
}
@@ -69,7 +69,7 @@
@Override
protected String getDefaultName()
{
- // TODO Auto-generated method stub
+ // No name per 7.4
return null;
}
@@ -80,21 +80,12 @@
}
/* (non-Javadoc)
- * @see org.jboss.webbeans.model.AbstractComponentModel#checkDeploymentType()
- */
- @Override
- protected void checkDeploymentType()
- {
- // TODO Let super class check deployment type once initType() is fixed.
- }
-
- /* (non-Javadoc)
* @see org.jboss.webbeans.model.AbstractComponentModel#initDeploymentType(org.jboss.webbeans.ManagerImpl)
*/
@Override
protected void initDeploymentType(ManagerImpl container)
{
- // This is always @Standard per 7.2
+ // This is always @Standard per 7.4
this.deploymentType = new StandardAnnotationLiteral();
}
@@ -104,7 +95,7 @@
@Override
protected void initName()
{
- // No name per 7.2
+ // No name per 7.4
this.name = null;
}
@@ -114,7 +105,7 @@
@Override
protected void initScopeType()
{
- // This is always @Dependent per 7.2
+ // This is always @Dependent per 7.4
this.scopeType = new DependentAnnotationLiteral();
}
Added: 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 (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventComponentModelTest.java 2008-10-15 08:19:05 UTC (rev 117)
@@ -0,0 +1,96 @@
+package org.jboss.webbeans.test;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Set;
+
+import javax.webbeans.Dependent;
+import javax.webbeans.Event;
+import javax.webbeans.Standard;
+
+import org.jboss.webbeans.bindings.StandardAnnotationLiteral;
+import org.jboss.webbeans.injectable.ComponentConstructor;
+import org.jboss.webbeans.introspector.SimpleAnnotatedItem;
+import org.jboss.webbeans.model.EventComponentModel;
+import org.jboss.webbeans.test.bindings.AnotherDeploymentTypeAnnotationLiteral;
+import org.jboss.webbeans.test.mock.MockContainerImpl;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Unit tests for the component model used only for the container supplied
+ * Event component.
+ *
+ * @author David Allen
+ *
+ */
+public class EventComponentModelTest
+{
+ private MockContainerImpl manager = null;
+ private EventComponentModel<Event<? extends Object>> eventComponentModel = null;
+
+ @BeforeMethod
+ public void before() throws Exception
+ {
+ List<Annotation> enabledDeploymentTypes = new ArrayList<Annotation>();
+ enabledDeploymentTypes.add(new StandardAnnotationLiteral());
+ enabledDeploymentTypes.add(new AnotherDeploymentTypeAnnotationLiteral());
+ manager = new MockContainerImpl(enabledDeploymentTypes);
+ eventComponentModel = new EventComponentModel<Event<? extends Object>>(
+ new SimpleAnnotatedItem<Object>(
+ new HashMap<Class<? extends Annotation>, Annotation>()),
+ new SimpleAnnotatedItem<Object>(
+ new HashMap<Class<? extends Annotation>, Annotation>()),
+ manager);
+
+ }
+
+ /**
+ * The name should always be null since this type of component is not allowed to have a name.
+ */
+ @Test(groups = "eventbus")
+ public void testName()
+ {
+ assert eventComponentModel.getName() == null;
+ }
+
+ /**
+ * The scope type should always be @Dependent
+ */
+ @Test(groups = "eventbus")
+ public void testScopeType()
+ {
+ assert eventComponentModel.getScopeType().annotationType().equals(Dependent.class);
+ }
+
+ /**
+ * The deployment type should always be @Standard
+ */
+ @Test(groups = "eventbus")
+ public void testDeploymentType()
+ {
+ assert eventComponentModel.getDeploymentType().annotationType().equals(Standard.class);
+ }
+
+ @Test(groups = "eventbus")
+ public void testApiTypes()
+ {
+ Set<Class> apis = eventComponentModel.getApiTypes();
+ assert apis.size() >= 1;
+ for (Class api : apis)
+ {
+ api.equals(Event.class);
+ }
+ }
+
+ @Test(groups = "eventbus")
+ public void testConstructor()
+ {
+ ComponentConstructor<Event<? extends Object>> constructor = eventComponentModel.getConstructor();
+ assert constructor != null;
+ Event<? extends Object> event = constructor.invoke(manager);
+ assert event != null;
+ }
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventComponentModelTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-07 16:30:19 UTC (rev 116)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventTest.java 2008-10-15 08:19:05 UTC (rev 117)
@@ -2,20 +2,20 @@
import java.lang.annotation.Annotation;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import javax.webbeans.Current;
+import javax.webbeans.DuplicateBindingTypeException;
import javax.webbeans.Event;
import org.jboss.webbeans.bindings.StandardAnnotationLiteral;
import org.jboss.webbeans.event.EventImpl;
-import org.jboss.webbeans.introspector.SimpleAnnotatedItem;
-import org.jboss.webbeans.model.EventComponentModel;
-import org.jboss.webbeans.test.annotations.FishStereotype;
-import org.jboss.webbeans.test.annotations.RiverFishStereotype;
+import org.jboss.webbeans.test.annotations.AnimalStereotype;
+import org.jboss.webbeans.test.annotations.Tame;
+import org.jboss.webbeans.test.annotations.Synchronous;
+import org.jboss.webbeans.test.bindings.AnimalStereotypeAnnotationLiteral;
import org.jboss.webbeans.test.bindings.AnotherDeploymentTypeAnnotationLiteral;
import org.jboss.webbeans.test.bindings.FishStereotypeAnnotationLiteral;
-import org.jboss.webbeans.test.bindings.RiverFishStereotypeAnnotationLiteral;
+import org.jboss.webbeans.test.bindings.TameAnnotationLiteral;
+import org.jboss.webbeans.test.bindings.SynchronousAnnotationLiteral;
import org.jboss.webbeans.test.components.DangerCall;
import org.jboss.webbeans.test.mock.MockContainerImpl;
import org.jboss.webbeans.util.Reflections;
@@ -26,7 +26,7 @@
* Tests for the implementation of an Event component.
*
* @author David Allen
- *
+ *
*/
public class EventTest
{
@@ -42,23 +42,49 @@
}
/**
- * Tests the {@link Event#fire(Object, Annotation...)} method with a sample event
- * component.
+ * Tests the {@link Event#fire(Object, Annotation...)} method with a sample
+ * event component.
*/
@SuppressWarnings("unchecked")
@Test(groups = "eventbus")
public void testFireEvent()
{
DangerCall anEvent = new DangerCall();
- EventComponentModel<DangerCall> eventComponentModel =
- new EventComponentModel<DangerCall>(
- new SimpleAnnotatedItem<Object>(new HashMap<Class<? extends Annotation>, Annotation>()),
- new SimpleAnnotatedItem<Object>(new HashMap<Class<? extends Annotation>, Annotation>()),
- manager);
- EventImpl<DangerCall> eventComponent = new EventImpl<DangerCall>(eventComponentModel);
+ // 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);
eventComponent.setManager(manager);
- eventComponent.fire(anEvent, new FishStereotypeAnnotationLiteral(), new RiverFishStereotypeAnnotationLiteral());
+ eventComponent.fire(anEvent, new TameAnnotationLiteral(),
+ new SynchronousAnnotationLiteral());
assert anEvent.equals(manager.getEvent());
- assert Reflections.annotationSetMatches(manager.getEventBindings(), Current.class, FishStereotype.class, RiverFishStereotype.class);
+ assert Reflections.annotationSetMatches(manager.getEventBindings(),
+ AnimalStereotype.class, Tame.class,
+ Synchronous.class);
+
+ // Test duplicate annotations on the fire method call
+ boolean duplicateDetected = false;
+ try
+ {
+ eventComponent.fire(anEvent, new TameAnnotationLiteral(),
+ new TameAnnotationLiteral());
+ } catch (DuplicateBindingTypeException e)
+ {
+ duplicateDetected = true;
+ }
+ assert duplicateDetected;
+
+ // Test annotations that are not binding types
+ boolean nonBindingTypeDetected = false;
+ try
+ {
+ eventComponent.fire(anEvent, new FishStereotypeAnnotationLiteral());
+ }
+ catch (IllegalArgumentException e)
+ {
+ nonBindingTypeDetected = true;
+ }
+ assert nonBindingTypeDetected;
}
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/FishStereotypeAnnotationLiteral.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/FishStereotypeAnnotationLiteral.java 2008-10-07 16:30:19 UTC (rev 116)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/FishStereotypeAnnotationLiteral.java 2008-10-15 08:19:05 UTC (rev 117)
@@ -2,9 +2,9 @@
import javax.webbeans.AnnotationLiteral;
-import org.jboss.webbeans.test.annotations.RiverFishStereotype;
+import org.jboss.webbeans.test.annotations.FishStereotype;
-public class FishStereotypeAnnotationLiteral extends AnnotationLiteral<RiverFishStereotype> implements RiverFishStereotype
+public class FishStereotypeAnnotationLiteral extends AnnotationLiteral<FishStereotype> implements FishStereotype
{
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/RiverFishStereotypeAnnotationLiteral.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/RiverFishStereotypeAnnotationLiteral.java 2008-10-07 16:30:19 UTC (rev 116)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/RiverFishStereotypeAnnotationLiteral.java 2008-10-15 08:19:05 UTC (rev 117)
@@ -2,9 +2,9 @@
import javax.webbeans.AnnotationLiteral;
-import org.jboss.webbeans.test.annotations.FishStereotype;
+import org.jboss.webbeans.test.annotations.RiverFishStereotype;
-public class RiverFishStereotypeAnnotationLiteral extends AnnotationLiteral<FishStereotype> implements FishStereotype
+public class RiverFishStereotypeAnnotationLiteral extends AnnotationLiteral<RiverFishStereotype> implements RiverFishStereotype
{
}
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/TameAnnotationLiteral.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/TameAnnotationLiteral.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/TameAnnotationLiteral.java 2008-10-15 08:19:05 UTC (rev 117)
@@ -0,0 +1,10 @@
+package org.jboss.webbeans.test.bindings;
+
+import javax.webbeans.AnnotationLiteral;
+
+import org.jboss.webbeans.test.annotations.Tame;
+
+public class TameAnnotationLiteral extends AnnotationLiteral<Tame> implements Tame
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/TameAnnotationLiteral.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
More information about the weld-commits
mailing list