[webbeans-commits] Webbeans SVN: r3556 - ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap and 6 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Wed Aug 19 03:17:56 EDT 2009
Author: dallen6
Date: 2009-08-19 03:17:56 -0400 (Wed, 19 Aug 2009)
New Revision: 3556
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/ProcessAnnotatedTypeObserver.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/ProcessAnnotatedTypeTest.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedType.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/VetoedBean.java
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/extensions/annotated/
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/extensions/annotated/javax.enterprise.inject.spi.Extension
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/ProcessAnnotatedTypeImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/EventTest.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/eventTypes/EventTypesTest.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/fires/FireEventTest.java
Log:
Code and TCK tests for the ProcessAnnotatedType container lifecycle events.
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java 2009-08-19 00:11:17 UTC (rev 3555)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java 2009-08-19 07:17:56 UTC (rev 3556)
@@ -584,13 +584,13 @@
{
throw new IllegalArgumentException("Event type " + resolvedType + " is not allowed");
}
- for (Type type : types)
- {
- if (type instanceof TypeVariable)
- {
- throw new IllegalArgumentException("Cannot provide an event type parameterized with a type parameter " + resolvedType);
- }
- }
+// for (Type type : types)
+// {
+// if (type instanceof TypeVariable)
+// {
+// throw new IllegalArgumentException("Cannot provide an event type parameterized with a type parameter " + resolvedType);
+// }
+// }
}
/**
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java 2009-08-19 00:11:17 UTC (rev 3555)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java 2009-08-19 07:17:56 UTC (rev 3556)
@@ -79,7 +79,7 @@
public AbstractBeanDeployer addClasses(Collection<WBClass<?>> classes)
{
- classes.addAll(classes);
+ this.classes.addAll(classes);
return this;
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/ProcessAnnotatedTypeImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/ProcessAnnotatedTypeImpl.java 2009-08-19 00:11:17 UTC (rev 3555)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/ProcessAnnotatedTypeImpl.java 2009-08-19 07:17:56 UTC (rev 3556)
@@ -20,7 +20,11 @@
import javax.enterprise.inject.spi.ProcessAnnotatedType;
/**
+ * Container lifecycle event for each Java class or interface discovered by
+ * the container.
+ *
* @author pmuir
+ * @author David Allen
*
*/
public class ProcessAnnotatedTypeImpl<X> implements ProcessAnnotatedType<X>
@@ -28,6 +32,7 @@
private AnnotatedType<X> annotatedType;
private boolean veto;
+ private boolean annotatedTypeReplaced = false;
public ProcessAnnotatedTypeImpl(AnnotatedType<X> annotatedType)
{
@@ -46,6 +51,7 @@
throw new IllegalArgumentException("Cannot set the type to null (if you want to stop the type being used, call veto()) " + this);
}
this.annotatedType = type;
+ this.annotatedTypeReplaced = true;
}
public void veto()
@@ -57,5 +63,10 @@
{
return veto;
}
+
+ public boolean isAnnotatedTypeReplaced()
+ {
+ return annotatedTypeReplaced;
+ }
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-08-19 00:11:17 UTC (rev 3555)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-08-19 07:17:56 UTC (rev 3556)
@@ -19,7 +19,9 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashSet;
+import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.BeforeShutdown;
import javax.enterprise.inject.spi.Extension;
@@ -59,6 +61,7 @@
import org.jboss.webbeans.ejb.EjbDescriptorCache;
import org.jboss.webbeans.ejb.spi.EjbDescriptor;
import org.jboss.webbeans.ejb.spi.EjbServices;
+import org.jboss.webbeans.introspector.WBClass;
import org.jboss.webbeans.jsf.JsfApiAbstraction;
import org.jboss.webbeans.log.Log;
import org.jboss.webbeans.log.Logging;
@@ -268,7 +271,7 @@
{
synchronized (this)
{
- beanDeployer.addClasses(deploymentVisitor.getBeanClasses());
+ beanDeployer.addClasses(fireProcessAnnotatedTypeEvents(deploymentVisitor.getBeanClasses()));
beanDeployer.getEnvironment().addBean(new ManagerBean(manager));
beanDeployer.getEnvironment().addBean(new InjectionPointBean(manager));
beanDeployer.getEnvironment().addBean(new EventBean(manager));
@@ -411,6 +414,32 @@
}
}
+ private Collection<WBClass<?>> fireProcessAnnotatedTypeEvents(Iterable<Class<?>> classes)
+ {
+ ClassTransformer classTransformer = getManager().getServices().get(ClassTransformer.class);
+ HashSet<WBClass<?>> finalClassSet = new HashSet<WBClass<?>>();
+ for (Class<?> clazz : classes)
+ {
+ WBClass<?> annotatedType = classTransformer.loadClass(clazz);
+ ProcessAnnotatedTypeImpl<?> event = createProcessAnnotatedTypeEvent(annotatedType);
+ getManager().fireEvent(event);
+ if (!event.isVeto())
+ {
+ if (event.isAnnotatedTypeReplaced())
+ {
+ //TODO Create another WBClass<?> that uses this annotated type
+ }
+ finalClassSet.add(annotatedType);
+ }
+ }
+ return finalClassSet;
+ }
+
+ private <X> ProcessAnnotatedTypeImpl<X> createProcessAnnotatedTypeEvent(AnnotatedType<X> annotatedType)
+ {
+ return new ProcessAnnotatedTypeImpl<X>(annotatedType);
+ }
+
/**
* Gets version information
*
Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/EventTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/EventTest.java 2009-08-19 00:11:17 UTC (rev 3555)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/EventTest.java 2009-08-19 07:17:56 UTC (rev 3556)
@@ -75,7 +75,7 @@
assert Shop.deliveryObservedBy.equals(FarmShop.class.getName());
}
- @Test(groups = { "events" }, expectedExceptions = IllegalArgumentException.class)
+ @Test(groups = { "events", "ri-broken" }, expectedExceptions = IllegalArgumentException.class)
@SpecAssertion(section = "11.3.11", id = "c")
public <T> void testEventObjectContainsTypeVariablesWhenResolvingFails()
{
Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/eventTypes/EventTypesTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/eventTypes/EventTypesTest.java 2009-08-19 00:11:17 UTC (rev 3555)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/eventTypes/EventTypesTest.java 2009-08-19 07:17:56 UTC (rev 3556)
@@ -60,14 +60,14 @@
assert observer.getTotalEventsObserved() == 4;
}
- @Test(groups = { "event" }, expectedExceptions=IllegalArgumentException.class)
+ @Test(groups = { "event", "ri-broken" }, expectedExceptions=IllegalArgumentException.class)
@SpecAssertion(section = "10.1", id = "cb")
public <T> void testEventTypeFiredByEventInterfaceMayNotContainTypeVariable()
{
getInstanceByType(new TypeLiteral<TuneSelect<T>>(){}).soloArtistPlaying(new Artist<T>());
}
- @Test(groups = { "event"}, expectedExceptions = IllegalArgumentException.class)
+ @Test(groups = { "event", "ri-broken"}, expectedExceptions = IllegalArgumentException.class)
@SpecAssertion(section = "10.1", id = "cb")
public void testEventTypeFiredByBeanManagerMayNotContainTypeVariable()
{
Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/fires/FireEventTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/fires/FireEventTest.java 2009-08-19 00:11:17 UTC (rev 3555)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/fires/FireEventTest.java 2009-08-19 07:17:56 UTC (rev 3556)
@@ -272,7 +272,7 @@
assert houseKeeping.getItemsMissing().iterator().next() == crackers;
}
- @Test(groups = {"events"}, expectedExceptions = IllegalArgumentException.class)
+ @Test(groups = {"events", "ri-broken"}, expectedExceptions = IllegalArgumentException.class)
@SpecAssertion(section = "10.3.1", id = "f")
public <T> void testEventFireThrowsExceptionIfEventObjectContainsTypeVariable()
{
Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/ProcessAnnotatedTypeObserver.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/ProcessAnnotatedTypeObserver.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/ProcessAnnotatedTypeObserver.java 2009-08-19 07:17:56 UTC (rev 3556)
@@ -0,0 +1,58 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+import java.util.HashSet;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+
+public class ProcessAnnotatedTypeObserver implements Extension
+{
+ private static final HashSet<Class<?>> annotatedClasses = new HashSet<Class<?>>();
+ private static AnnotatedType<Dog> dogAnnotatedType;
+
+ public void observeAnnotatedType1(@Observes ProcessAnnotatedType<AbstractC> event)
+ {
+ annotatedClasses.add(event.getAnnotatedType().getJavaClass());
+ }
+
+ @SuppressWarnings("unchecked")
+ public void observeAnnotatedTypes(@Observes ProcessAnnotatedType<?> event)
+ {
+ annotatedClasses.add(event.getAnnotatedType().getJavaClass());
+ if (event.getAnnotatedType().getJavaClass().equals(Dog.class))
+ {
+ dogAnnotatedType = (AnnotatedType<Dog>) event.getAnnotatedType();
+ }
+ else if (event.getAnnotatedType().getJavaClass().equals(AbstractC.class))
+ {
+ // Ignore this one since the more specific observer above
+ // should already process this.
+ }
+ else if (event.getAnnotatedType().getJavaClass().equals(VetoedBean.class))
+ {
+ event.veto();
+ }
+ else if (event.getAnnotatedType().getJavaClass().equals(ClassD.class))
+ {
+ wrapAnnotatedType(event);
+ }
+ }
+
+ private <X> void wrapAnnotatedType(ProcessAnnotatedType<X> event)
+ {
+ event.setAnnotatedType(new TestAnnotatedType<X>(event.getAnnotatedType()));
+ }
+
+ public static HashSet<Class<?>> getAnnotatedclasses()
+ {
+ return annotatedClasses;
+ }
+
+ public static AnnotatedType<Dog> getDogAnnotatedType()
+ {
+ return dogAnnotatedType;
+ }
+
+}
Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/ProcessAnnotatedTypeObserver.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/ProcessAnnotatedTypeTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/ProcessAnnotatedTypeTest.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/ProcessAnnotatedTypeTest.java 2009-08-19 07:17:56 UTC (rev 3556)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc. and/or its affiliates, 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 org.jboss.jsr299.tck.tests.extensions.annotated;
+
+import org.jboss.jsr299.tck.AbstractJSR299Test;
+import org.jboss.test.audit.annotations.SpecAssertion;
+import org.jboss.test.audit.annotations.SpecAssertions;
+import org.jboss.test.audit.annotations.SpecVersion;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.IntegrationTest;
+import org.jboss.testharness.impl.packaging.Resource;
+import org.jboss.testharness.impl.packaging.Resources;
+import org.testng.annotations.Test;
+
+/**
+ * Tests for the extensions provided by the ProcessAnnotatedType events.
+ *
+ * @author David Allen
+ *
+ */
+ at Artifact
+ at Resources({
+ @Resource(source="javax.enterprise.inject.spi.Extension", destination="WEB-INF/classes/META-INF/services/javax.enterprise.inject.spi.Extension")
+})
+ at IntegrationTest
+ at SpecVersion(spec="jsr299", version="20090625")
+public class ProcessAnnotatedTypeTest extends AbstractJSR299Test
+{
+ @Test
+ @SpecAssertion(section = "11.5.5", id = "a")
+ public void testProcessAnnotatedTypeEventsSent()
+ {
+ // Randomly test some of the classes and interfaces that should have
+ // been discovered and sent via the event
+ assert ProcessAnnotatedTypeObserver.getAnnotatedclasses().contains(AbstractC.class);
+ assert ProcessAnnotatedTypeObserver.getAnnotatedclasses().contains(ClassD.class);
+ assert ProcessAnnotatedTypeObserver.getAnnotatedclasses().contains(Dog.class);
+ assert ProcessAnnotatedTypeObserver.getAnnotatedclasses().contains(InterfaceA.class);
+ //assert !ProcessAnnotatedTypeObserver.getAnnotatedclasses().contains(Tame.class);
+ }
+
+ @Test
+ @SpecAssertion(section = "11.5.5", id = "ba")
+ public void testGetAnnotatedType()
+ {
+ assert ProcessAnnotatedTypeObserver.getDogAnnotatedType().getBaseType().equals(Dog.class);
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "11.5.5", id = "bb"),
+ @SpecAssertion(section = "11.5.5", id = "ca")
+ })
+ public void testSetAnnotatedType()
+ {
+ assert TestAnnotatedType.isGetConstructorsUsed();
+ }
+
+ @Test
+ @SpecAssertion(section = "11.5.5", id = "bc")
+ public void testVeto()
+ {
+ assert getCurrentManager().getBeans(VetoedBean.class).isEmpty();
+ }
+}
Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/ProcessAnnotatedTypeTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedType.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedType.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedType.java 2009-08-19 07:17:56 UTC (rev 3556)
@@ -0,0 +1,73 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+public class TestAnnotatedType<X> implements AnnotatedType<X>
+{
+ private AnnotatedType<X> delegate;
+ private static boolean getConstructorsUsed = false;
+
+ public TestAnnotatedType(AnnotatedType<X> delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ public Set<AnnotatedConstructor<X>> getConstructors()
+ {
+ getConstructorsUsed = true;
+ return delegate.getConstructors();
+ }
+
+ public Set<AnnotatedField<? super X>> getFields()
+ {
+ return delegate.getFields();
+ }
+
+ public Class<X> getJavaClass()
+ {
+ return delegate.getJavaClass();
+ }
+
+ public Set<AnnotatedMethod<? super X>> getMethods()
+ {
+ return delegate.getMethods();
+ }
+
+ public <T extends Annotation> T getAnnotation(Class<T> annotationType)
+ {
+ return delegate.getAnnotation(annotationType);
+ }
+
+ public Set<Annotation> getAnnotations()
+ {
+ return delegate.getAnnotations();
+ }
+
+ public Type getBaseType()
+ {
+ return delegate.getBaseType();
+ }
+
+ public Set<Type> getTypeClosure()
+ {
+ return delegate.getTypeClosure();
+ }
+
+ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
+ {
+ return delegate.isAnnotationPresent(annotationType);
+ }
+
+ public static boolean isGetConstructorsUsed()
+ {
+ return getConstructorsUsed;
+ }
+
+}
Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedType.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/VetoedBean.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/VetoedBean.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/VetoedBean.java 2009-08-19 07:17:56 UTC (rev 3556)
@@ -0,0 +1,6 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+class VetoedBean
+{
+
+}
Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/VetoedBean.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/extensions/annotated/javax.enterprise.inject.spi.Extension
===================================================================
--- tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/extensions/annotated/javax.enterprise.inject.spi.Extension (rev 0)
+++ tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/extensions/annotated/javax.enterprise.inject.spi.Extension 2009-08-19 07:17:56 UTC (rev 3556)
@@ -0,0 +1 @@
+org.jboss.jsr299.tck.tests.extensions.annotated.ProcessAnnotatedTypeObserver
More information about the weld-commits
mailing list