Author: pete.muir(a)jboss.org
Date: 2009-10-09 09:47:55 -0400 (Fri, 09 Oct 2009)
New Revision: 3909
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/CheckableInjectionTarget.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/Cow.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/CowProducer.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/AbstractProcessBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessInjectionTargetImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessManagedBeanImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessSessionBeanImpl.java
Removed:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/BirdCageInjectionTarget.java
Modified:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/Cat.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/ProducerProcessor.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/ProducerTest.java
core/trunk/cdi-api/src/main/java/javax/enterprise/inject/spi/ProcessSessionBean.java
core/trunk/impl/src/main/java/org/jboss/weld/BeanManagerImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractProducerBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractReceiverBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/InterceptorImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerField.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/SessionBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/ee/PersistenceContextProducerField.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/AbstractBeanDeployer.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessProducerImpl.java
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/manager/EjbDescriptorLookupTest.java
Log:
Support for ProcessProducer.set and ProcessInjectionTarget
Deleted:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/BirdCageInjectionTarget.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/BirdCageInjectionTarget.java 2009-10-09
13:42:39 UTC (rev 3908)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/BirdCageInjectionTarget.java 2009-10-09
13:47:55 UTC (rev 3909)
@@ -1,60 +0,0 @@
-package org.jboss.jsr299.tck.tests.extensions.producer;
-
-import java.util.Set;
-
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.InjectionTarget;
-
-class BirdCageInjectionTarget implements InjectionTarget<BirdCage>
-{
- private InjectionTarget<BirdCage> wrappedInjectionTarget;
- private static boolean injectCalled;
-
- public BirdCageInjectionTarget(InjectionTarget<BirdCage>
originalInjectionTarget)
- {
- this.wrappedInjectionTarget = originalInjectionTarget;
- }
-
- public void inject(BirdCage instance, CreationalContext<BirdCage> ctx)
- {
- injectCalled = true;
- wrappedInjectionTarget.inject(instance, ctx);
- }
-
- public void postConstruct(BirdCage instance)
- {
- wrappedInjectionTarget.postConstruct(instance);
- }
-
- public void preDestroy(BirdCage instance)
- {
- wrappedInjectionTarget.preDestroy(instance);
- }
-
- public void dispose(BirdCage instance)
- {
- wrappedInjectionTarget.dispose(instance);
- }
-
- public Set<InjectionPoint> getInjectionPoints()
- {
- return wrappedInjectionTarget.getInjectionPoints();
- }
-
- public BirdCage produce(CreationalContext<BirdCage> ctx)
- {
- return wrappedInjectionTarget.produce(ctx);
- }
-
- public static boolean isInjectCalled()
- {
- return injectCalled;
- }
-
- public static void setInjectCalled(boolean injectCalled)
- {
- BirdCageInjectionTarget.injectCalled = injectCalled;
- }
-
-}
Modified:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/Cat.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/Cat.java 2009-10-09
13:42:39 UTC (rev 3908)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/Cat.java 2009-10-09
13:47:55 UTC (rev 3909)
@@ -15,8 +15,8 @@
@Inject
public Cat(LitterBox litterBox)
{
+ assert litterBox != null;
constructorCalled = true;
- assert litterBox != null;
}
@Inject
Copied:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/CheckableInjectionTarget.java
(from rev 3904,
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/BirdCageInjectionTarget.java)
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/CheckableInjectionTarget.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/CheckableInjectionTarget.java 2009-10-09
13:47:55 UTC (rev 3909)
@@ -0,0 +1,60 @@
+package org.jboss.jsr299.tck.tests.extensions.producer;
+
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.InjectionTarget;
+
+class CheckableInjectionTarget<T> implements InjectionTarget<T>
+{
+ private InjectionTarget<T> wrappedInjectionTarget;
+ private static boolean injectCalled;
+
+ public CheckableInjectionTarget(InjectionTarget<T> originalInjectionTarget)
+ {
+ this.wrappedInjectionTarget = originalInjectionTarget;
+ }
+
+ public void inject(T instance, CreationalContext<T> ctx)
+ {
+ injectCalled = true;
+ wrappedInjectionTarget.inject(instance, ctx);
+ }
+
+ public void postConstruct(T instance)
+ {
+ wrappedInjectionTarget.postConstruct(instance);
+ }
+
+ public void preDestroy(T instance)
+ {
+ wrappedInjectionTarget.preDestroy(instance);
+ }
+
+ public void dispose(T instance)
+ {
+ wrappedInjectionTarget.dispose(instance);
+ }
+
+ public Set<InjectionPoint> getInjectionPoints()
+ {
+ return wrappedInjectionTarget.getInjectionPoints();
+ }
+
+ public T produce(CreationalContext<T> ctx)
+ {
+ return wrappedInjectionTarget.produce(ctx);
+ }
+
+ public static boolean isInjectCalled()
+ {
+ return injectCalled;
+ }
+
+ public static void setInjectCalled(boolean injectCalled)
+ {
+ CheckableInjectionTarget.injectCalled = injectCalled;
+ }
+
+}
Property changes on:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/CheckableInjectionTarget.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/Cow.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/Cow.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/Cow.java 2009-10-09
13:47:55 UTC (rev 3909)
@@ -0,0 +1,6 @@
+package org.jboss.jsr299.tck.tests.extensions.producer;
+
+public class Cow
+{
+
+}
Property changes on:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/Cow.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/CowProducer.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/CowProducer.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/CowProducer.java 2009-10-09
13:47:55 UTC (rev 3909)
@@ -0,0 +1,15 @@
+package org.jboss.jsr299.tck.tests.extensions.producer;
+
+import javax.enterprise.inject.Produces;
+
+public class CowProducer
+{
+
+ @Produces @Noisy
+ public Cow produceNoisyCow()
+ {
+ return new Cow();
+ }
+
+
+}
Property changes on:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/CowProducer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/ProducerProcessor.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/ProducerProcessor.java 2009-10-09
13:42:39 UTC (rev 3908)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/ProducerProcessor.java 2009-10-09
13:47:55 UTC (rev 3909)
@@ -1,10 +1,14 @@
package org.jboss.jsr299.tck.tests.extensions.producer;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.AnnotatedField;
import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.InjectionTarget;
import javax.enterprise.inject.spi.ProcessInjectionTarget;
import javax.enterprise.inject.spi.ProcessProducer;
@@ -17,6 +21,7 @@
private static Producer<Dog> quietDogProducer;
private static InjectionTarget<Dog> dogInjectionTarget;
private static AnnotatedType<Dog> dogAnnotatedType;
+ private static boolean overriddenCowProducerCalled;
public void processDogProducerProducer(@Observes ProcessProducer<DogProducer,
Dog> producerEvent)
{
@@ -32,9 +37,9 @@
}
}
- public void processCatProducer(@Observes ProcessInjectionTarget<Cat>
producerEvent)
+ public void processCatProducer(@Observes ProcessInjectionTarget<Cat> event)
{
- catInjectionTarget = producerEvent.getInjectionTarget();
+ catInjectionTarget = event.getInjectionTarget();
}
public void processDogInjectionTarget(@Observes ProcessInjectionTarget<Dog>
injectionTargetEvent)
@@ -43,7 +48,36 @@
dogInjectionTarget = injectionTargetEvent.getInjectionTarget();
dogAnnotatedType = injectionTargetEvent.getAnnotatedType();
}
+
+ public void processCowProducer(@Observes ProcessProducer<CowProducer, Cow>
event)
+ {
+ final Producer<Cow> producer = event.getProducer();
+ event.setProducer(new Producer<Cow>()
+ {
+ public void dispose(Cow instance)
+ {
+ producer.dispose(instance);
+ }
+
+ public Set<InjectionPoint> getInjectionPoints()
+ {
+ return producer.getInjectionPoints();
+ }
+
+ public Cow produce(CreationalContext<Cow> ctx)
+ {
+ overriddenCowProducerCalled = true;
+ return producer.produce(ctx);
+ }
+ });
+ }
+
+ public void processBirdCage(@Observes ProcessInjectionTarget<BirdCage> event)
+ {
+ event.setInjectionTarget(new
CheckableInjectionTarget(event.getInjectionTarget()));
+ }
+
public static Producer<Dog> getNoisyDogProducer()
{
return noisyDogProducer;
@@ -68,4 +102,14 @@
{
return dogAnnotatedType;
}
+
+ public static void reset()
+ {
+ overriddenCowProducerCalled = false;
+ }
+
+ public static boolean isOverriddenCowProducerCalled()
+ {
+ return overriddenCowProducerCalled;
+ }
}
Modified:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/ProducerTest.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/ProducerTest.java 2009-10-09
13:42:39 UTC (rev 3908)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/producer/ProducerTest.java 2009-10-09
13:47:55 UTC (rev 3909)
@@ -30,24 +30,25 @@
// Must be an integration test as it needs a resource copied to a folder
@IntegrationTest
@SpecVersion(spec="cdi", version="PFD2")
-// TODO All tests fall under WBRI-345 for now, please create new issues for any failing
tests after WBRI-345 is done
public class ProducerTest extends AbstractJSR299Test
{
- @Test(groups = "ri-broken")
+ @Test
@SpecAssertions({
@SpecAssertion(section = "11.2", id = "ba")
})
- public void testProduceCallsInitializerAndConstructor()
+ public void testProduceAndInjectCallsInitializerAndConstructor()
{
InjectionTarget<Cat> injectionTarget =
ProducerProcessor.getCatInjectionTarget();
Bean<Cat> catBean = getUniqueBean(Cat.class);
Cat.reset();
- injectionTarget.produce(getCurrentManager().createCreationalContext(catBean));
+ CreationalContext<Cat> ctx =
getCurrentManager().createCreationalContext(catBean);
+ Cat instance = injectionTarget.produce(ctx);
assert Cat.isConstructorCalled();
+ injectionTarget.inject(instance, ctx);
assert Cat.isInitializerCalled();
}
- @Test(groups = "ri-broken")
+ @Test
@SpecAssertions({
@SpecAssertion(section = "11.2", id = "c")
})
@@ -61,7 +62,7 @@
cat.ping();
}
- @Test(groups = "ri-broken")
+ @Test
@SpecAssertions({
@SpecAssertion(section = "11.2", id = "da")
})
@@ -80,42 +81,30 @@
assert injectionPointPresent;
}
- @Test(groups = "ri-broken")
+ @Test
@SpecAssertions({
- @SpecAssertion(section = "11.2", id = "db")
+ @SpecAssertion(section = "11.2", id = "db"),
+ @SpecAssertion(section = "11.2", id = "dc")
})
public void testGetInjectionPointsForConstructorAndInitializer()
{
InjectionTarget<Cat> injectionTarget =
ProducerProcessor.getCatInjectionTarget();
assert injectionTarget.getInjectionPoints().size() == 3;
- boolean dogIPPresent = false;
+ boolean constructorIPPresent = false;
+ boolean initializerMethodIPPresent = false;
for (InjectionPoint injectionPoint : injectionTarget.getInjectionPoints())
{
- if (injectionPoint.getType().equals(Dog.class))
+ if (injectionPoint.getType().equals(LitterBox.class))
{
- dogIPPresent = true;
+ constructorIPPresent = true;
}
- }
- assert dogIPPresent;
- }
-
- @Test(groups = "ri-broken")
- @SpecAssertions({
- @SpecAssertion(section = "11.2", id = "dc")
- })
- public void testGetInjectionPointsForInitializer()
- {
- InjectionTarget<Cat> injectionTarget =
ProducerProcessor.getCatInjectionTarget();
- assert injectionTarget.getInjectionPoints().size() == 3;
- boolean injectionPointPresent = false;
- for (InjectionPoint injectionPoint : injectionTarget.getInjectionPoints())
- {
if (injectionPoint.getType().equals(Bird.class))
{
- injectionPointPresent = true;
+ initializerMethodIPPresent = true;
}
}
- assert injectionPointPresent;
+ assert initializerMethodIPPresent;
+ assert constructorIPPresent;
}
@Test
@@ -136,6 +125,17 @@
assert DogProducer.isNoisyDogProducerCalled();
assert dog.getColor().equals(DogProducer.NOISY_DOG_COLOR);
}
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "11.5.7", id="e")
+ })
+ public void testSetProducerOverridesProducer()
+ {
+ ProducerProcessor.reset();
+ assert getInstanceByType(Cow.class, new AnnotationLiteral<Noisy>() {})
instanceof Cow;
+ assert ProducerProcessor.isOverriddenCowProducerCalled();
+ }
@Test
@SpecAssertions({
@@ -184,7 +184,7 @@
}
@SuppressWarnings("unchecked")
- @Test(groups = "ri-broken")
+ @Test
@SpecAssertions({
@SpecAssertion(section = "11.2", id = "i"),
@SpecAssertion(section = "11.5.6", id = "ba"),
@@ -201,7 +201,7 @@
assert dog.getDogBone() != null;
}
- @Test(groups = "ri-broken")
+ @Test
@SpecAssertions({
@SpecAssertion(section = "11.2", id = "j")
})
@@ -214,7 +214,7 @@
assert Dog.isPostConstructCalled();
}
- @Test(groups = "ri-broken")
+ @Test
@SpecAssertions({
@SpecAssertion(section = "11.2", id = "k")
})
@@ -227,19 +227,19 @@
assert Dog.isPreDestroyCalled();
}
- @Test(groups = "ri-broken")
+ @Test
@SpecAssertions({
@SpecAssertion(section = "11.5.6", id = "bb"),
@SpecAssertion(section = "11.5.6", id = "ea")
})
public void testSettingInjectionTargetReplacesIt()
{
- BirdCageInjectionTarget.setInjectCalled(false);
+ CheckableInjectionTarget.setInjectCalled(false);
getInstanceByType(BirdCage.class);
- assert BirdCageInjectionTarget.isInjectCalled();
+ assert CheckableInjectionTarget.isInjectCalled();
}
- @Test(groups = "ri-broken")
+ @Test
@SpecAssertions({
@SpecAssertion(section = "11.5.6", id = "aba")
})
Modified:
core/trunk/cdi-api/src/main/java/javax/enterprise/inject/spi/ProcessSessionBean.java
===================================================================
---
core/trunk/cdi-api/src/main/java/javax/enterprise/inject/spi/ProcessSessionBean.java 2009-10-09
13:42:39 UTC (rev 3908)
+++
core/trunk/cdi-api/src/main/java/javax/enterprise/inject/spi/ProcessSessionBean.java 2009-10-09
13:47:55 UTC (rev 3909)
@@ -17,9 +17,9 @@
package javax.enterprise.inject.spi;
-public interface ProcessSessionBean<X> extends ProcessBean<Object>
+public interface ProcessSessionBean<X> extends ProcessManagedBean<Object>
{
- public AnnotatedType<X> getAnnotatedBeanClass();
+ public AnnotatedType<X> getAnnotatedSessionBeanClass();
public String getEjbName();
Modified: core/trunk/impl/src/main/java/org/jboss/weld/BeanManagerImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/BeanManagerImpl.java 2009-10-09 13:42:39
UTC (rev 3908)
+++ core/trunk/impl/src/main/java/org/jboss/weld/BeanManagerImpl.java 2009-10-09 13:47:55
UTC (rev 3909)
@@ -1271,7 +1271,7 @@
public <T> InjectionTarget<T> createInjectionTarget(EjbDescriptor<T>
descriptor)
{
- return getBean(descriptor);
+ return getBean(descriptor).getInjectionTarget();
}
public <X> Bean<? extends X> getMostSpecializedBean(Bean<X> bean)
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractBean.java 2009-10-09
13:42:39 UTC (rev 3908)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractBean.java 2009-10-09
13:47:55 UTC (rev 3909)
@@ -331,7 +331,7 @@
*
* @return The annotated item
*/
- protected abstract WeldAnnotated<T, E> getAnnotatedItem();
+ public abstract WeldAnnotated<T, E> getAnnotatedItem();
/**
* Gets the binding types
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java 2009-10-09
13:42:39 UTC (rev 3908)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java 2009-10-09
13:47:55 UTC (rev 3909)
@@ -25,6 +25,9 @@
import java.util.List;
import java.util.Set;
+import javassist.util.proxy.ProxyFactory;
+import javassist.util.proxy.ProxyObject;
+
import javax.enterprise.context.Dependent;
import javax.enterprise.context.NormalScope;
import javax.enterprise.context.spi.CreationalContext;
@@ -53,9 +56,6 @@
import org.jboss.weld.util.Proxies;
import org.jboss.weld.util.Strings;
-import javassist.util.proxy.ProxyFactory;
-import javassist.util.proxy.ProxyObject;
-
/**
* An abstract bean representation common for class-based beans
*
@@ -64,7 +64,7 @@
* @param <T>
* @param <E>
*/
-public abstract class AbstractClassBean<T> extends AbstractBean<T,
Class<T>> implements InjectionTarget<T>
+public abstract class AbstractClassBean<T> extends AbstractBean<T,
Class<T>>
{
// Logger
private static final LogProvider log =
Logging.getLogProvider(AbstractClassBean.class);
@@ -83,6 +83,8 @@
private final ThreadLocal<Integer> decoratorStackPosition;
private WeldMethod<?, ?> postConstruct;
private WeldMethod<?, ?> preDestroy;
+
+ private InjectionTarget<T> injectionTarget;
/**
* Constructor
@@ -209,12 +211,6 @@
{
return Collections.unmodifiableList(decorators);
}
-
- public void dispose(T instance)
- {
- // No-op for class beans
- }
-
/**
* Initializes the bean type
@@ -348,39 +344,7 @@
return dependencies;
}
- public void postConstruct(T instance)
- {
- WeldMethod<?, ?> postConstruct = getPostConstruct();
- if (postConstruct != null)
- {
- try
- {
- postConstruct.invoke(instance);
- }
- catch (Exception e)
- {
- throw new RuntimeException("Unable to invoke " + postConstruct +
" on " + instance, e);
- }
- }
- }
- public void preDestroy(T instance)
- {
- WeldMethod<?, ?> preDestroy = getPreDestroy();
- if (preDestroy != null)
- {
- try
- {
- // note: RI supports injection into @PreDestroy
- preDestroy.invoke(instance);
- }
- catch (Exception e)
- {
- throw new RuntimeException("Unable to invoke " + preDestroy +
" on " + instance, e);
- }
- }
- }
-
/**
* Initializes the post-construct method
*/
@@ -466,4 +430,54 @@
manager.getBoundInterceptorsRegistry().registerInterceptionModel(getType(),
builder.build());
}
}
+
+ public void setInjectionTarget(InjectionTarget<T> injectionTarget)
+ {
+ this.injectionTarget = injectionTarget;
+ }
+
+ public InjectionTarget<T> getInjectionTarget()
+ {
+ return injectionTarget;
+ }
+
+ @Override
+ public Set<InjectionPoint> getInjectionPoints()
+ {
+ return getInjectionTarget().getInjectionPoints();
+ }
+
+ protected void defaultPreDestroy(T instance)
+ {
+ WeldMethod<?, ?> preDestroy = getPreDestroy();
+ if (preDestroy != null)
+ {
+ try
+ {
+ // note: RI supports injection into @PreDestroy
+ preDestroy.invoke(instance);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unable to invoke " + preDestroy +
" on " + instance, e);
+ }
+ }
+ }
+
+ protected void defaultPostConstruct(T instance)
+ {
+ WeldMethod<?, ?> postConstruct = getPostConstruct();
+ if (postConstruct != null)
+ {
+ try
+ {
+ postConstruct.invoke(instance);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unable to invoke " + postConstruct +
" on " + instance, e);
+ }
+ }
+ }
+
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractProducerBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractProducerBean.java 2009-10-09
13:42:39 UTC (rev 3908)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractProducerBean.java 2009-10-09
13:47:55 UTC (rev 3909)
@@ -56,9 +56,11 @@
* @param <T>
* @param <S>
*/
-public abstract class AbstractProducerBean<X, T, S extends Member> extends
AbstractReceiverBean<X, T, S> implements Producer<T>
+public abstract class AbstractProducerBean<X, T, S extends Member> extends
AbstractReceiverBean<X, T, S>
{
private static final LogProvider log =
Logging.getLogProvider(AbstractProducerBean.class);
+
+ private Producer<T> producer;
/**
* Constructor
@@ -154,6 +156,12 @@
super.initialize(environment);
checkProducerReturnType();
}
+
+ @Override
+ public Set<InjectionPoint> getInjectionPoints()
+ {
+ return getProducer().getInjectionPoints();
+ }
/**
* Validates the return value
@@ -244,6 +252,21 @@
{
return true;
}
+
+ /**
+ * This operation is *not* threadsafe, and should not be called outside bootstrap
+ *
+ * @param producer
+ */
+ public void setProducer(Producer<T> producer)
+ {
+ this.producer = producer;
+ }
+
+ public Producer<T> getProducer()
+ {
+ return producer;
+ }
/**
* Creates an instance of the bean
@@ -254,7 +277,7 @@
{
try
{
- T instance = produce(creationalContext);
+ T instance = getProducer().produce(creationalContext);
checkReturnValue(instance);
return instance;
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractReceiverBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractReceiverBean.java 2009-10-09
13:42:39 UTC (rev 3908)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractReceiverBean.java 2009-10-09
13:47:55 UTC (rev 3909)
@@ -119,6 +119,6 @@
}
@Override
- protected abstract WeldMember<T, ?, S> getAnnotatedItem();
+ public abstract WeldMember<T, ?, S> getAnnotatedItem();
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/InterceptorImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/InterceptorImpl.java 2009-10-09
13:42:39 UTC (rev 3908)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/InterceptorImpl.java 2009-10-09
13:47:55 UTC (rev 3909)
@@ -17,20 +17,19 @@
package org.jboss.weld.bean;
+import java.lang.annotation.Annotation;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.InterceptionType;
+import javax.enterprise.inject.spi.Interceptor;
+import javax.interceptor.InvocationContext;
+
import org.jboss.interceptor.model.InterceptorClassMetadata;
+import org.jboss.interceptor.proxy.DirectClassInterceptionHandler;
import org.jboss.interceptor.registry.InterceptorClassMetadataRegistry;
-import org.jboss.interceptor.proxy.DirectClassInterceptionHandler;
import org.jboss.weld.BeanManagerImpl;
import org.jboss.weld.introspector.WeldClass;
-import org.jboss.weld.metadata.cache.MetaAnnotationStore;
-import javax.enterprise.inject.spi.InterceptionType;
-import javax.enterprise.inject.spi.Interceptor;
-import javax.interceptor.InvocationContext;
-import java.lang.annotation.Annotation;
-import java.util.HashSet;
-import java.util.Set;
-
/**
* @author Marius Bogoevici
*/
@@ -74,14 +73,15 @@
}
@Override
- public void postConstruct(T instance)
+ protected void defaultPostConstruct(T instance)
{
- // do nothing on PostConstruct
+ // Lifecycle callbacks not supported
}
-
+
@Override
- public void preDestroy(T instance)
+ protected void defaultPreDestroy(T instance)
{
- // do nothing on PreDestroy
+ // Lifecycle callbacks not supported
}
+
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java 2009-10-09 13:42:39
UTC (rev 3908)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java 2009-10-09 13:47:55
UTC (rev 3909)
@@ -16,23 +16,24 @@
*/
package org.jboss.weld.bean;
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Set;
-import java.util.List;
-import java.util.ArrayList;
-import java.lang.annotation.Annotation;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.Decorator;
import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.InjectionTarget;
+import org.jboss.interceptor.model.InterceptionModelBuilder;
+import org.jboss.interceptor.proxy.InterceptionHandlerFactory;
import org.jboss.interceptor.proxy.InterceptorProxyCreatorImpl;
-import org.jboss.interceptor.proxy.InterceptionHandlerFactory;
+import org.jboss.interceptor.registry.InterceptorRegistry;
import org.jboss.interceptor.util.InterceptionUtils;
-import org.jboss.interceptor.model.InterceptionModelBuilder;
-import org.jboss.interceptor.registry.InterceptorRegistry;
import org.jboss.weld.BeanManagerImpl;
import org.jboss.weld.DefinitionException;
import org.jboss.weld.DeploymentException;
@@ -113,8 +114,8 @@
{
originalInjectionPoint = attachCorrectInjectionPoint();
}
- T instance = produce(creationalContext);
- inject(instance, creationalContext);
+ T instance = getInjectionTarget().produce(creationalContext);
+ getInjectionTarget().inject(instance, creationalContext);
if (hasDecorators())
{
instance = applyDecorators(instance, creationalContext,
originalInjectionPoint);
@@ -123,40 +124,14 @@
{
instance = applyInterceptors(instance, creationalContext);
InterceptionUtils.executePostConstruct(instance);
- } else
+ }
+ else
{
- postConstruct(instance);
+ getInjectionTarget().postConstruct(instance);
}
return instance;
}
- public T produce(CreationalContext<T> ctx)
- {
- T instance = constructor.newInstance(manager, ctx);
- if (!hasDecorators())
- {
- // This should be safe, but needs verification PLM
- // Without this, the chaining of decorators will fail as the incomplete instance
will be resolved
- ctx.push(instance);
- }
- return instance;
- }
-
- public void inject(final T instance, final CreationalContext<T> ctx)
- {
- new InjectionContextImpl<T>(getManager(), this, instance)
- {
-
- public void proceed()
- {
- Beans.injectEEFields(instance, getManager(), ejbInjectionPoints,
persistenceContextInjectionPoints, persistenceUnitInjectionPoints,
resourceInjectionPoints);
- Beans.injectFieldsAndInitializers(instance, ctx, getManager(),
getInjectableFields(), getInitializerMethods());
- }
-
- }.run();
-
- }
-
protected InjectionPoint attachCorrectInjectionPoint()
{
Decorator<?> decorator = getDecorators().get(getDecorators().size() - 1);
@@ -181,7 +156,9 @@
try
{
if (!isInterceptionCandidate() || !hasBoundInterceptors())
- preDestroy(instance);
+ {
+ getInjectionTarget().preDestroy(instance);
+ }
else
{
InterceptionUtils.executePredestroy(instance);
@@ -209,7 +186,58 @@
initPreDestroy();
initEEInjectionPoints();
if (isInterceptionCandidate())
+ {
initDeclaredInterceptors();
+ }
+ setInjectionTarget(new InjectionTarget<T>()
+ {
+
+ public void inject(final T instance, final CreationalContext<T> ctx)
+ {
+ new InjectionContextImpl<T>(getManager(), this, instance)
+ {
+
+ public void proceed()
+ {
+ Beans.injectEEFields(instance, getManager(), ejbInjectionPoints,
persistenceContextInjectionPoints, persistenceUnitInjectionPoints,
resourceInjectionPoints);
+ Beans.injectFieldsAndInitializers(instance, ctx, getManager(),
getInjectableFields(), getInitializerMethods());
+ }
+
+ }.run();
+ }
+
+ public void postConstruct(T instance)
+ {
+ defaultPostConstruct(instance);
+ }
+
+ public void preDestroy(T instance)
+ {
+ defaultPreDestroy(instance);
+ }
+
+ public void dispose(T instance)
+ {
+ // No-op
+ }
+
+ public Set<InjectionPoint> getInjectionPoints()
+ {
+ return (Set) getAnnotatedInjectionPoints();
+ }
+
+ public T produce(CreationalContext<T> ctx)
+ {
+ T instance = constructor.newInstance(manager, ctx);
+ if (!hasDecorators())
+ {
+ // This should be safe, but needs verification PLM
+ // Without this, the chaining of decorators will fail as the incomplete
instance will be resolved
+ ctx.push(instance);
+ }
+ return instance;
+ }
+ });
}
}
@@ -379,6 +407,7 @@
return specializedBean;
}
+ @Override
protected boolean isInterceptionCandidate()
{
return !Beans.isInterceptor(getAnnotatedItem()) &&
!Beans.isDecorator(getAnnotatedItem());
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerField.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerField.java 2009-10-09
13:42:39 UTC (rev 3908)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerField.java 2009-10-09
13:47:55 UTC (rev 3909)
@@ -22,6 +22,8 @@
import java.util.Set;
import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.Producer;
import org.jboss.weld.BeanManagerImpl;
import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
@@ -79,25 +81,38 @@
if (!isInitialized())
{
super.initialize(environment);
+ setProducer(new Producer<T>()
+ {
+
+ public void dispose(T instance)
+ {
+ defaultDispose(instance);
+ }
+
+ public Set<InjectionPoint> getInjectionPoints()
+ {
+ return (Set) getAnnotatedInjectionPoints();
+ }
+
+ public T produce(CreationalContext<T> creationalContext)
+ {
+ return field.get(getReceiver(creationalContext));
+ }
+
+ });
}
}
-
- public void destroy(T instance, CreationalContext<T> creationalContext)
+
+ protected void defaultDispose(T instance)
{
- dispose(instance);
+ // No disposal by default
}
- public void dispose(T instance)
+ public void destroy(T instance, CreationalContext<T> creationalContext)
{
- // No clean up required
+ getProducer().dispose(instance);
}
- public T produce(CreationalContext<T> ctx)
- {
- return field.get(getReceiver(ctx));
- }
-
-
/**
* Gets the annotated item representing the field
*
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java 2009-10-09
13:42:39 UTC (rev 3908)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java 2009-10-09
13:47:55 UTC (rev 3909)
@@ -26,6 +26,8 @@
import javax.enterprise.event.Observes;
import javax.enterprise.inject.CreationException;
import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.Producer;
import org.jboss.weld.BeanManagerImpl;
import org.jboss.weld.DefinitionException;
@@ -79,19 +81,6 @@
initPolicy();
}
- public T produce(CreationalContext<T> creationalContext)
- {
- Object receiver = getReceiver(creationalContext);
- if (receiver != null)
- {
- return method.invokeOnInstance(receiver, manager, creationalContext,
CreationException.class);
- }
- else
- {
- return method.invoke(receiver, manager, creationalContext,
CreationException.class);
- }
- }
-
/**
* Initializes the bean and its metadata
*/
@@ -104,6 +93,38 @@
super.initialize(environment);
checkProducerMethod();
initDisposalMethod(environment);
+ setProducer(new Producer<T>()
+ {
+
+ public void dispose(T instance)
+ {
+ if (disposalMethodBean != null)
+ {
+ disposalMethodBean.invokeDisposeMethod(instance);
+ }
+ }
+
+ public Set<InjectionPoint> getInjectionPoints()
+ {
+ return (Set) getAnnotatedInjectionPoints();
+ }
+
+ public T produce(CreationalContext<T> creationalContext)
+ {
+ Object receiver = getReceiver(creationalContext);
+ if (receiver != null)
+ {
+ return method.invokeOnInstance(receiver, manager, creationalContext,
CreationException.class);
+ }
+ else
+ {
+ return method.invoke(receiver, manager, creationalContext,
CreationException.class);
+ }
+ }
+
+
+
+ });
}
}
@@ -180,7 +201,7 @@
{
try
{
- dispose(instance);
+ getProducer().dispose(instance);
}
finally
{
@@ -190,14 +211,6 @@
}
}
}
-
- public void dispose(T instance)
- {
- if (disposalMethodBean != null)
- {
- disposalMethodBean.invokeDisposeMethod(instance);
- }
- }
/**
* Gets the annotated item representing the method
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/SessionBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/SessionBean.java 2009-10-09 13:42:39
UTC (rev 3908)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/SessionBean.java 2009-10-09 13:47:55
UTC (rev 3909)
@@ -33,8 +33,11 @@
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.CreationException;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.InjectionTarget;
import javax.interceptor.Interceptor;
+import org.jboss.interceptor.model.InterceptionModel;
import org.jboss.weld.BeanManagerImpl;
import org.jboss.weld.DefinitionException;
import org.jboss.weld.bean.interceptor.InterceptorBindingsAdapter;
@@ -54,7 +57,6 @@
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.util.Beans;
import org.jboss.weld.util.Proxies;
-import org.jboss.interceptor.model.InterceptionModel;
/**
* An enterprise bean representation
@@ -118,6 +120,67 @@
checkObserverMethods();
checkScopeAllowed();
registerInterceptors();
+ setInjectionTarget(new InjectionTarget<T>()
+ {
+
+ public void inject(final T instance, final CreationalContext<T> ctx)
+ {
+ new InjectionContextImpl<T>(getManager(), this, instance)
+ {
+
+ public void proceed()
+ {
+ Beans.injectFieldsAndInitializers(instance, ctx, getManager(),
getInjectableFields(), getInitializerMethods());
+ }
+
+ }.run();
+ }
+
+ public void postConstruct(T instance)
+ {
+ defaultPostConstruct(instance);
+ }
+
+ public void preDestroy(T instance)
+ {
+
+ }
+
+ public void dispose(T instance)
+ {
+ // No-op
+ }
+
+ public Set<InjectionPoint> getInjectionPoints()
+ {
+ return (Set) getAnnotatedInjectionPoints();
+ }
+
+ public T produce(CreationalContext<T> ctx)
+ {
+ try
+ {
+ T instance = proxyClass.newInstance();
+ ctx.push(instance);
+ ((ProxyObject) instance).setHandler(new
EnterpriseBeanProxyMethodHandler<T>(SessionBean.this, ctx));
+ log.trace("Enterprise bean instance created for bean {0}",
this);
+ return instance;
+ }
+ catch (InstantiationException e)
+ {
+ throw new RuntimeException("Could not instantiate enterprise proxy
for " + toString(), e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new RuntimeException("Could not access bean correctly when
creating enterprise proxy for " + toString(), e);
+ }
+ catch (Exception e)
+ {
+ throw new CreationException("could not find the EJB in JNDI "
+ proxyClass, e);
+ }
+ }
+
+ });
}
}
@@ -216,52 +279,14 @@
*/
public T create(final CreationalContext<T> creationalContext)
{
- T instance = produce(creationalContext);
+ T instance = getInjectionTarget().produce(creationalContext);
if (hasDecorators())
{
instance = applyDecorators(instance, creationalContext, null);
}
return instance;
}
-
- public void inject(final T instance, final CreationalContext<T> ctx)
- {
- new InjectionContextImpl<T>(getManager(), this, instance)
- {
-
- public void proceed()
- {
- Beans.injectFieldsAndInitializers(instance, ctx, getManager(),
getInjectableFields(), getInitializerMethods());
- }
-
- }.run();
-
- }
- public T produce(CreationalContext<T> ctx)
- {
- try
- {
- T instance = proxyClass.newInstance();
- ctx.push(instance);
- ((ProxyObject) instance).setHandler(new
EnterpriseBeanProxyMethodHandler<T>(this, ctx));
- log.trace("Enterprise bean instance created for bean {0}", this);
- return instance;
- }
- catch (InstantiationException e)
- {
- throw new RuntimeException("Could not instantiate enterprise proxy for
" + toString(), e);
- }
- catch (IllegalAccessException e)
- {
- throw new RuntimeException("Could not access bean correctly when creating
enterprise proxy for " + toString(), e);
- }
- catch (Exception e)
- {
- throw new CreationException("could not find the EJB in JNDI " +
proxyClass, e);
- }
- }
-
public void destroy(T instance, CreationalContext<T> creationalContext)
{
if (instance == null)
@@ -311,11 +336,6 @@
buffer.append("API types " + getTypes() + ", binding types " +
getQualifiers());
return buffer.toString();
}
-
- public void preDestroy(CreationalContext<T> creationalContext)
- {
- creationalContext.release();
- }
@Override
protected void initSerializable()
@@ -393,6 +413,7 @@
return Collections.emptySet();
}
+ @Override
protected boolean isInterceptionCandidate()
{
return true;
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/ee/PersistenceContextProducerField.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/bean/ee/PersistenceContextProducerField.java 2009-10-09
13:42:39 UTC (rev 3908)
+++
core/trunk/impl/src/main/java/org/jboss/weld/bean/ee/PersistenceContextProducerField.java 2009-10-09
13:47:55 UTC (rev 3909)
@@ -53,7 +53,7 @@
}
@Override
- public void dispose(T instance)
+ protected void defaultDispose(T instance)
{
instance.close();
}
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/AbstractBeanDeployer.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/AbstractBeanDeployer.java 2009-10-09
13:42:39 UTC (rev 3908)
+++
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/AbstractBeanDeployer.java 2009-10-09
13:47:55 UTC (rev 3909)
@@ -16,16 +16,18 @@
*/
package org.jboss.weld.bootstrap;
-import java.util.Set;
import java.lang.reflect.Member;
import java.lang.reflect.Type;
+import java.util.Set;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.ProcessInjectionTarget;
+import javax.enterprise.inject.spi.ProcessManagedBean;
import javax.enterprise.inject.spi.ProcessObserverMethod;
import javax.enterprise.inject.spi.ProcessProducer;
-import javax.enterprise.inject.spi.Interceptor;
+import javax.enterprise.inject.spi.ProcessSessionBean;
import javax.inject.Inject;
import org.jboss.weld.BeanManagerImpl;
@@ -36,6 +38,7 @@
import org.jboss.weld.bean.DisposalMethod;
import org.jboss.weld.bean.InterceptorImpl;
import org.jboss.weld.bean.ManagedBean;
+import org.jboss.weld.bean.NewBean;
import org.jboss.weld.bean.NewManagedBean;
import org.jboss.weld.bean.NewSessionBean;
import org.jboss.weld.bean.ProducerField;
@@ -44,11 +47,13 @@
import org.jboss.weld.bean.SessionBean;
import org.jboss.weld.bean.ee.EEResourceProducerField;
import org.jboss.weld.bean.ee.PersistenceContextProducerField;
+import org.jboss.weld.bootstrap.events.ProcessInjectionTargetImpl;
+import org.jboss.weld.bootstrap.events.ProcessManagedBeanImpl;
import org.jboss.weld.bootstrap.events.ProcessObserverMethodImpl;
import org.jboss.weld.bootstrap.events.ProcessProducerImpl;
+import org.jboss.weld.bootstrap.events.ProcessSessionBeanImpl;
import org.jboss.weld.ejb.EJBApiAbstraction;
import org.jboss.weld.ejb.InternalEjbDescriptor;
-import org.jboss.weld.ejb.spi.EjbServices;
import org.jboss.weld.event.ObserverFactory;
import org.jboss.weld.event.ObserverMethodImpl;
import org.jboss.weld.introspector.WeldClass;
@@ -62,7 +67,6 @@
import org.jboss.weld.util.Reflections;
import org.jboss.weld.util.reflection.ParameterizedTypeImpl;
import org.jboss.weld.ws.WSApiAbstraction;
-import org.jboss.interceptor.model.InterceptionModel;
public class AbstractBeanDeployer<E extends BeanDeployerEnvironment>
{
@@ -103,10 +107,24 @@
for (RIBean<?> bean : beans)
{
bean.initialize(getEnvironment());
- if (bean instanceof AbstractProducerBean<?, ?, ?>)
+ if (!(bean instanceof NewBean))
{
- AbstractProducerBean<?, ?, Member> producer =
(AbstractProducerBean<?, ?, Member>) bean;
- createAndFireProcessProducerEvent(producer);
+ if (bean instanceof AbstractProducerBean<?, ?, ?>)
+ {
+ fireProcessProducerEvent((AbstractProducerBean<?, ?, Member>)
bean);
+ }
+ if (bean instanceof AbstractClassBean<?>)
+ {
+ fireProcessInjectionTargetEvent((AbstractClassBean<?>) bean);
+ }
+ if (bean instanceof ManagedBean<?>)
+ {
+ fireProcessManagedBeanEvent((ManagedBean<?>) bean);
+ }
+ if (bean instanceof SessionBean<?>)
+ {
+ fireProcessSessionBeanEvent((SessionBean<Object>) bean);
+ }
}
manager.addBean(bean);
log.debug("Bean: " + bean);
@@ -183,7 +201,7 @@
getEnvironment().addBean(bean);
}
- private <X, T> void createAndFireProcessProducerEvent(AbstractProducerBean<X,
T, Member> producer)
+ private <X, T> void fireProcessProducerEvent(AbstractProducerBean<X, T,
Member> producer)
{
ProcessProducerImpl<X, T> payload = new ProcessProducerImpl<X,
T>(producer.getAnnotatedItem(), producer) {};
fireEvent(payload, ProcessProducer.class,
producer.getAnnotatedItem().getDeclaringType().getBaseType(),
producer.getAnnotatedItem().getBaseType());
@@ -194,6 +212,39 @@
}
}
+ private <X> void fireProcessInjectionTargetEvent(AbstractClassBean<X>
classBean)
+ {
+ ProcessInjectionTargetImpl<X> payload = new
ProcessInjectionTargetImpl<X>(classBean.getAnnotatedItem(), classBean) {};
+ fireEvent(payload, ProcessInjectionTarget.class,
classBean.getAnnotatedItem().getBaseType());
+ if (!payload.getDefinitionErrors().isEmpty())
+ {
+ // FIXME communicate all the captured definition errors in this exception
+ throw new DefinitionException(payload.getDefinitionErrors().get(0));
+ }
+ }
+
+ private <X> void fireProcessManagedBeanEvent(ManagedBean<X> bean)
+ {
+ ProcessManagedBeanImpl<X> payload = new ProcessManagedBeanImpl<X>(bean)
{};
+ fireEvent(payload, ProcessManagedBean.class,
bean.getAnnotatedItem().getBaseType());
+ if (!payload.getDefinitionErrors().isEmpty())
+ {
+ // FIXME communicate all the captured definition errors in this exception
+ throw new DefinitionException(payload.getDefinitionErrors().get(0));
+ }
+ }
+
+ private <X> void fireProcessSessionBeanEvent(SessionBean<Object> bean)
+ {
+ ProcessSessionBeanImpl<X> payload = new ProcessSessionBeanImpl<X>(bean)
{};
+ fireEvent(payload, ProcessSessionBean.class,
bean.getAnnotatedItem().getBaseType());
+ if (!payload.getDefinitionErrors().isEmpty())
+ {
+ // FIXME communicate all the captured definition errors in this exception
+ throw new DefinitionException(payload.getDefinitionErrors().get(0));
+ }
+ }
+
private void fireEvent(Object payload, Type rawType, Type... actualTypeArguments)
{
Type eventType = new ParameterizedTypeImpl(rawType, actualTypeArguments, null);
Added:
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/AbstractProcessBean.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/AbstractProcessBean.java
(rev 0)
+++
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/AbstractProcessBean.java 2009-10-09
13:47:55 UTC (rev 3909)
@@ -0,0 +1,40 @@
+package org.jboss.weld.bootstrap.events;
+
+import java.util.List;
+
+import javax.enterprise.inject.spi.Annotated;
+import javax.enterprise.inject.spi.ProcessBean;
+
+import org.jboss.weld.bean.AbstractBean;
+
+public abstract class AbstractProcessBean<X, B extends AbstractBean<X, ?>>
extends AbstractContainerEvent implements ProcessBean<X>
+{
+
+ private final B bean;
+
+ public AbstractProcessBean(B bean)
+ {
+ this.bean = bean;
+ }
+
+ public void addDefinitionError(Throwable t)
+ {
+ getErrors().add(t);
+ }
+
+ public List<Throwable> getDefinitionErrors()
+ {
+ return super.getErrors();
+ }
+
+ public Annotated getAnnotated()
+ {
+ return bean.getAnnotatedItem();
+ }
+
+ public B getBean()
+ {
+ return bean;
+ }
+
+}
Property changes on:
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/AbstractProcessBean.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added:
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessInjectionTargetImpl.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessInjectionTargetImpl.java
(rev 0)
+++
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessInjectionTargetImpl.java 2009-10-09
13:47:55 UTC (rev 3909)
@@ -0,0 +1,49 @@
+package org.jboss.weld.bootstrap.events;
+
+import java.util.List;
+
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.InjectionTarget;
+import javax.enterprise.inject.spi.ProcessInjectionTarget;
+
+import org.jboss.weld.bean.AbstractClassBean;
+
+
+public class ProcessInjectionTargetImpl<T> extends AbstractContainerEvent
implements ProcessInjectionTarget<T>
+{
+
+ private final AnnotatedType<T> annotatedType;
+ private AbstractClassBean<T> classBean;
+
+ public ProcessInjectionTargetImpl(AnnotatedType<T> annotatedType,
AbstractClassBean<T> classBean)
+ {
+ this.classBean = classBean;
+ this.annotatedType = annotatedType;
+ }
+
+ public void addDefinitionError(Throwable t)
+ {
+ getErrors().add(t);
+ }
+
+ public List<Throwable> getDefinitionErrors()
+ {
+ return super.getErrors();
+ }
+
+ public AnnotatedType<T> getAnnotatedType()
+ {
+ return annotatedType;
+ }
+
+ public InjectionTarget<T> getInjectionTarget()
+ {
+ return classBean.getInjectionTarget();
+ }
+
+ public void setInjectionTarget(InjectionTarget<T> injectionTarget)
+ {
+ classBean.setInjectionTarget(injectionTarget);
+ }
+
+}
Property changes on:
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessInjectionTargetImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added:
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessManagedBeanImpl.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessManagedBeanImpl.java
(rev 0)
+++
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessManagedBeanImpl.java 2009-10-09
13:47:55 UTC (rev 3909)
@@ -0,0 +1,21 @@
+package org.jboss.weld.bootstrap.events;
+
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.ProcessManagedBean;
+
+import org.jboss.weld.bean.ManagedBean;
+
+public class ProcessManagedBeanImpl<X> extends AbstractProcessBean<X,
ManagedBean<X>> implements ProcessManagedBean<X>
+{
+
+ public ProcessManagedBeanImpl(ManagedBean<X> bean)
+ {
+ super(bean);
+ }
+
+ public AnnotatedType<X> getAnnotatedBeanClass()
+ {
+ return getBean().getAnnotatedItem();
+ }
+
+}
Property changes on:
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessManagedBeanImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessProducerImpl.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessProducerImpl.java 2009-10-09
13:42:39 UTC (rev 3908)
+++
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessProducerImpl.java 2009-10-09
13:47:55 UTC (rev 3909)
@@ -6,16 +6,18 @@
import javax.enterprise.inject.spi.ProcessProducer;
import javax.enterprise.inject.spi.Producer;
+import org.jboss.weld.bean.AbstractProducerBean;
+
public class ProcessProducerImpl<X, T> extends AbstractContainerEvent implements
ProcessProducer<X, T>
{
private final AnnotatedMember<X> annotatedMember;
- private Producer<T> producer;
+ private AbstractProducerBean<X, T, ?> bean;
- public ProcessProducerImpl(AnnotatedMember<X> annotatedMember, Producer<T>
producer)
+ public ProcessProducerImpl(AnnotatedMember<X> annotatedMember,
AbstractProducerBean<X, T, ?> bean)
{
- this.producer = producer;
+ this.bean = bean;
this.annotatedMember = annotatedMember;
}
@@ -36,12 +38,12 @@
public Producer<T> getProducer()
{
- return producer;
+ return bean.getProducer();
}
public void setProducer(Producer<T> producer)
{
- throw new UnsupportedOperationException();
+ this.bean.setProducer(producer);
}
}
Added:
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessSessionBeanImpl.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessSessionBeanImpl.java
(rev 0)
+++
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessSessionBeanImpl.java 2009-10-09
13:47:55 UTC (rev 3909)
@@ -0,0 +1,52 @@
+package org.jboss.weld.bootstrap.events;
+
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.ProcessSessionBean;
+import javax.enterprise.inject.spi.SessionBeanType;
+
+import org.jboss.weld.bean.SessionBean;
+
+public class ProcessSessionBeanImpl<X> extends AbstractProcessBean<Object,
SessionBean<Object>> implements ProcessSessionBean<X>
+{
+
+ public ProcessSessionBeanImpl(SessionBean<Object> bean)
+ {
+ super(bean);
+ }
+
+ public AnnotatedType<X> getAnnotatedSessionBeanClass()
+ {
+ return (AnnotatedType<X>) getBean().getAnnotatedItem();
+ }
+
+ public String getEjbName()
+ {
+ return getBean().getEjbDescriptor().getEjbName();
+ }
+
+ public SessionBeanType getSessionBeanType()
+ {
+ if (getBean().getEjbDescriptor().isStateless())
+ {
+ return SessionBeanType.STATELESS;
+ }
+ else if (getBean().getEjbDescriptor().isStateful())
+ {
+ return SessionBeanType.STATEFUL;
+ }
+ else if (getBean().getEjbDescriptor().isSingleton())
+ {
+ return SessionBeanType.SINGLETON;
+ }
+ else
+ {
+ throw new IllegalStateException("Bean type is not STATELESS, STATEFUL or
SINGELTON " + getBean());
+ }
+ }
+
+ public AnnotatedType<Object> getAnnotatedBeanClass()
+ {
+ return getBean().getAnnotatedItem();
+ }
+
+}
Property changes on:
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessSessionBeanImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified:
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/manager/EjbDescriptorLookupTest.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/manager/EjbDescriptorLookupTest.java 2009-10-09
13:42:39 UTC (rev 3908)
+++
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/manager/EjbDescriptorLookupTest.java 2009-10-09
13:47:55 UTC (rev 3909)
@@ -48,8 +48,8 @@
assert bean.getBeanClass().equals(Cat.class);
InjectionTarget<CatLocal> it =
getCurrentManager().createInjectionTarget(descriptor);
assert it != null;
- assert it instanceof SessionBean;
- assert it == bean;
+ assert it.getInjectionPoints().equals(bean.getInjectionPoints());
+ assert it.produce(getCurrentManager().createCreationalContext(bean)) instanceof
CatLocal;
}
}