Author: pete.muir(a)jboss.org
Date: 2009-10-18 20:12:42 -0400 (Sun, 18 Oct 2009)
New Revision: 4187
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Bestiary.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Dragon.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Griffin.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Hippogriff.java
Modified:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/NewSimpleBeanTest.java
cdi-tck/trunk/impl/src/main/resources/tck-audit-cdi.xml
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/DisposalMethod.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/NewManagedBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/NewSessionBean.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/builtin/DefaultValidatorBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/AbstractBeanDeployer.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployer.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployerEnvironment.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployment.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/ExtensionBeanDeployer.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/ExtensionBeanDeployerEnvironment.java
core/trunk/impl/src/main/java/org/jboss/weld/ejb/EjbDescriptors.java
core/trunk/impl/src/main/java/org/jboss/weld/event/ObserverMethodImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/AbstractWeldAnnotated.java
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/resources/ClassTransformer.java
core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java
core/trunk/inject-tck-runner/src/test/java/org/jboss/weld/atinject/tck/Producers.java
core/trunk/tests/src/main/java/org/jboss/weld/mock/MockValidationServices.java
Log:
support @New injecting classes from outside BDAs
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Bestiary.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Bestiary.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Bestiary.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -0,0 +1,47 @@
+package org.jboss.jsr299.tck.tests.implementation.simple.newSimpleBean;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.Set;
+import java.util.TreeSet;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.New;
+import javax.enterprise.inject.Produces;
+
+@RequestScoped
+public class Bestiary
+{
+
+ private Set<String> possibleNames;
+ private Set<String> knightsWhichKilledTheDragons;
+
+ @Produces Collection<Dragon> getDragons(@New ArrayList<Dragon> dragons)
+ {
+ return dragons;
+ }
+
+ public void observeBirth(@Observes Griffin griffin, @New TreeSet<String>
possibleNames)
+ {
+ this.possibleNames = possibleNames;
+ }
+
+ public void destroyDragons(@Disposes Collection<Dragon> dragons, @New
LinkedHashSet<String> knights)
+ {
+ this.knightsWhichKilledTheDragons = knights;
+ }
+
+ public Set<String> getPossibleNames()
+ {
+ return possibleNames;
+ }
+
+ public Set<String> getKnightsWhichKilledTheDragons()
+ {
+ return knightsWhichKilledTheDragons;
+ }
+
+}
Property changes on:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Bestiary.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/implementation/simple/newSimpleBean/Dragon.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Dragon.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Dragon.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -0,0 +1,25 @@
+package org.jboss.jsr299.tck.tests.implementation.simple.newSimpleBean;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.inject.New;
+import javax.inject.Inject;
+
+public class Dragon
+{
+
+ private Set<String> children;
+
+ @Inject
+ public void initialize(@New HashSet<String> children)
+ {
+ this.children = children;
+ }
+
+ public Set<String> getChildren()
+ {
+ return children;
+ }
+
+}
Property changes on:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Dragon.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/implementation/simple/newSimpleBean/Griffin.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Griffin.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Griffin.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -0,0 +1,19 @@
+package org.jboss.jsr299.tck.tests.implementation.simple.newSimpleBean;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.enterprise.inject.New;
+import javax.inject.Inject;
+
+public class Griffin
+{
+
+ @Inject @New ArrayList<String> list;
+
+ public List<String> getList()
+ {
+ return list;
+ }
+
+}
Property changes on:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Griffin.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/implementation/simple/newSimpleBean/Hippogriff.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Hippogriff.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Hippogriff.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -0,0 +1,25 @@
+package org.jboss.jsr299.tck.tests.implementation.simple.newSimpleBean;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.enterprise.inject.New;
+import javax.inject.Inject;
+
+public class Hippogriff
+{
+
+ private Map<String, String> homes;
+
+ @Inject
+ public Hippogriff(@New HashMap<String, String> homes)
+ {
+ this.homes = homes;
+ }
+
+ public Map<String, String> getHomes()
+ {
+ return homes;
+ }
+
+}
Property changes on:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Hippogriff.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/implementation/simple/newSimpleBean/NewSimpleBeanTest.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/NewSimpleBeanTest.java 2009-10-19
00:08:13 UTC (rev 4186)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/NewSimpleBeanTest.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -1,13 +1,20 @@
package org.jboss.jsr299.tck.tests.implementation.simple.newSimpleBean;
import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.Set;
+import java.util.TreeSet;
import javax.enterprise.context.Dependent;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.AnnotationLiteral;
import javax.enterprise.inject.New;
+import javax.enterprise.inject.TypeLiteral;
import javax.enterprise.inject.spi.Bean;
import org.jboss.jsr299.tck.AbstractJSR299Test;
@@ -27,7 +34,66 @@
private static final Annotation TAME_LITERAL = new AnnotationLiteral<Tame>()
{
};
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "3.12", id = "ya")
+ })
+ public void testNewBeanCreatedForFieldInjectionPoint()
+ {
+ assert getInstanceByType(Griffin.class).getList() instanceof ArrayList<?>;
+ }
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "3.12", id = "yc")
+ })
+ public void testNewBeanCreatedForInitializerInjectionPoint()
+ {
+ assert getInstanceByType(Dragon.class).getChildren() instanceof HashSet<?>;
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "3.12", id = "ye")
+ })
+ public void testNewBeanCreatedForConstructorInjectioAnPoint()
+ {
+ assert getInstanceByType(Hippogriff.class).getHomes() instanceof HashMap<?,
?>;
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "3.12", id = "yg")
+ })
+ public void testNewBeanCreatedForProducerMethod()
+ {
+ assert getInstanceByType(new TypeLiteral<Collection<Dragon>>() {})
instanceof ArrayList<?>;
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "3.12", id = "yi")
+ })
+ public void testNewBeanCreatedForObserverMethod()
+ {
+ getCurrentManager().fireEvent(new Griffin());
+ assert getInstanceByType(Bestiary.class).getPossibleNames() instanceof
TreeSet<?>;
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "3.12", id = "yk")
+ })
+ public void testNewBeanCreatedForDisposerMethod()
+ {
+ Bean<Collection<Dragon>> bean = getUniqueBean(new
TypeLiteral<Collection<Dragon>>() {});
+ CreationalContext<Collection<Dragon>> ctx =
getCurrentManager().createCreationalContext(bean);
+ Collection<Dragon> dragons = bean.create(ctx);
+ bean.destroy(dragons, ctx);
+ assert getInstanceByType(Bestiary.class).getKnightsWhichKilledTheDragons()
instanceof LinkedHashSet<?>;
+ }
+
@Test(groups = { "new" })
@SpecAssertions({
@SpecAssertion(section = "3.12", id = "p")
Modified: cdi-tck/trunk/impl/src/main/resources/tck-audit-cdi.xml
===================================================================
--- cdi-tck/trunk/impl/src/main/resources/tck-audit-cdi.xml 2009-10-19 00:08:13 UTC (rev
4186)
+++ cdi-tck/trunk/impl/src/main/resources/tck-audit-cdi.xml 2009-10-19 00:12:42 UTC (rev
4187)
@@ -1565,11 +1565,41 @@
<group>
<text>Note that this second bean exists, is enabled, and is available for
injection whenever the bean class is in the application classpath, even if the first bean
is disabled, as defined by Section 5.2.2, “Enabled and disabled beans” or is deployed out-
side of a bean deployment archive, as defined in Section 12.1, “Bean deployment archives”,
and is therefore not discovered during the bean discovery process defined in Chapter 12,
Packaging and deployment.</text>
<assertion id="ya">
- <text>Check that @New on a class outside the BDA, but in the classpath
causes a bean with qualifier @New and the given type to be created</text>
+ <text>Check that @New on a field injection point outside the BDA, but in
the classpath causes a bean with qualifier @New and the given type to be
created</text>
</assertion>
<assertion id="yb">
- <text>Check that @New on a class (which is a session bean class) outside
the BDA, but in the classpath causes a session bean with qualifier @New and the given type
to be created</text>
+ <text>Check that @New on a field injection point (which is a session bean
class) outside the BDA, but in the classpath causes a session bean with qualifier @New and
the given type to be created</text>
</assertion>
+ <assertion id="yc">
+ <text>Check that @New on a initializer method injection point outside the
BDA, but in the classpath causes a bean with qualifier @New and the given type to be
created</text>
+ </assertion>
+ <assertion id="yd">
+ <text>Check that @New on a initializer method injection point (which is a
session bean class) outside the BDA, but in the classpath causes a session bean with
qualifier @New and the given type to be created</text>
+ </assertion>
+ <assertion id="ye">
+ <text>Check that @New on a constructor injection point outside the BDA, but
in the classpath causes a bean with qualifier @New and the given type to be
created</text>
+ </assertion>
+ <assertion id="yf">
+ <text>Check that @New on a constructor injection point (which is a session
bean class) outside the BDA, but in the classpath causes a session bean with qualifier
@New and the given type to be created</text>
+ </assertion>
+ <assertion id="yg">
+ <text>Check that @New on a producer method injection point outside the BDA,
but in the classpath causes a bean with qualifier @New and the given type to be
created</text>
+ </assertion>
+ <assertion id="yh">
+ <text>Check that @New on a producer method injection point (which is a
session bean class) outside the BDA, but in the classpath causes a session bean with
qualifier @New and the given type to be created</text>
+ </assertion>
+ <assertion id="yi">
+ <text>Check that @New on a observer method injection point outside the BDA,
but in the classpath causes a bean with qualifier @New and the given type to be
created</text>
+ </assertion>
+ <assertion id="yj">
+ <text>Check that @New on a observer method injection point (which is a
session bean class) outside the BDA, but in the classpath causes a session bean with
qualifier @New and the given type to be created</text>
+ </assertion>
+ <assertion id="yk">
+ <text>Check that @New on a disposer method injection point outside the BDA,
but in the classpath causes a bean with qualifier @New and the given type to be
created</text>
+ </assertion>
+ <assertion id="yl">
+ <text>Check that @New on a disposer method injection point (which is a
session bean class) outside the BDA, but in the classpath causes a session bean with
qualifier @New and the given type to be created</text>
+ </assertion>
</group>
<assertion id="z">
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-19
00:08:13 UTC (rev 4186)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractBean.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -25,6 +25,7 @@
import javax.decorator.Decorates;
import javax.enterprise.context.Dependent;
import javax.enterprise.inject.Alternative;
+import javax.enterprise.inject.New;
import javax.enterprise.inject.Specializes;
import javax.enterprise.inject.Typed;
import javax.enterprise.inject.spi.Bean;
@@ -83,6 +84,10 @@
// The injection points
private Set<WeldInjectionPoint<?, ?>> injectionPoints;
private Set<WeldInjectionPoint<?, ?>> delegateInjectionPoints;
+
+ // The @New injection points
+ private Set<WeldInjectionPoint<?, ?>> newInjectionPoints;
+
// If the type a primitive?
private boolean primitive;
// The Bean manager
@@ -110,6 +115,7 @@
this.manager = manager;
this.injectionPoints = new HashSet<WeldInjectionPoint<?, ?>>();
this.delegateInjectionPoints = new HashSet<WeldInjectionPoint<?,?>>();
+ this.newInjectionPoints = new HashSet<WeldInjectionPoint<?,?>>();
}
/**
@@ -153,6 +159,10 @@
{
this.delegateInjectionPoints.add(injectionPoint);
}
+ if (injectionPoint.isAnnotationPresent(New.class))
+ {
+ this.newInjectionPoints.add(injectionPoint);
+ }
injectionPoints.add(injectionPoint);
}
@@ -390,6 +400,11 @@
{
return injectionPoints;
}
+
+ public Set<WeldInjectionPoint<?, ?>> getNewInjectionPoints()
+ {
+ return newInjectionPoints;
+ }
/**
* Gets the merged stereotypes of the bean
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-19
00:08:13 UTC (rev 4186)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -45,8 +45,8 @@
import org.jboss.weld.DeploymentException;
import org.jboss.weld.bean.proxy.DecoratorProxyMethodHandler;
import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
-import org.jboss.weld.context.SerializableContextualInstance;
import org.jboss.weld.context.SerializableContextual;
+import org.jboss.weld.context.SerializableContextualInstance;
import org.jboss.weld.injection.FieldInjectionPoint;
import org.jboss.weld.injection.MethodInjectionPoint;
import org.jboss.weld.introspector.WeldClass;
@@ -76,7 +76,6 @@
private List<Set<FieldInjectionPoint<?, ?>>> injectableFields;
// The initializer methods of each type in the type hierarchy, with the actual type at
the bottom
private List<Set<MethodInjectionPoint<?, ?>>> initializerMethods;
- private Set<String> dependencies;
private List<Decorator<?>> decorators;
@@ -110,6 +109,8 @@
};
initStereotypes();
initPolicy();
+ initInitializerMethods();
+ initInjectableFields();
}
/**
@@ -118,8 +119,6 @@
@Override
public void initialize(BeanDeployerEnvironment environment)
{
- initInitializerMethods();
- initInjectableFields();
super.initialize(environment);
checkBeanImplementation();
initDecorators();
@@ -221,11 +220,6 @@
{
log.trace("Bean type specified in Java");
this.type = getAnnotatedItem().getJavaClass();
- this.dependencies = new HashSet<String>();
- for (Class<?> clazz = type.getSuperclass(); clazz != Object.class; clazz =
clazz.getSuperclass())
- {
- dependencies.add(clazz.getName());
- }
}
/**
@@ -339,12 +333,6 @@
// TODO Make immutable
return injectableFields;
}
-
- // TODO maybe a better way to expose this?
- public Set<String> getSuperclasses()
- {
- return dependencies;
- }
/**
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/DisposalMethod.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/DisposalMethod.java 2009-10-19
00:08:13 UTC (rev 4186)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/DisposalMethod.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -35,6 +35,7 @@
import org.jboss.weld.injection.MethodInjectionPoint;
import org.jboss.weld.introspector.WeldMethod;
import org.jboss.weld.introspector.WeldParameter;
+import org.jboss.weld.util.Beans;
public class DisposalMethod<X, T> extends AbstractReceiverBean<X, T, Method>
{
@@ -52,6 +53,7 @@
initTypes();
initStereotypes();
initPolicy();
+ addInjectionPoints(Beans.getParameterInjectionPoints(this,
disposalMethodInjectionPoint));
}
private void initDisposesParameter()
@@ -67,7 +69,6 @@
@Override
public void initialize(BeanDeployerEnvironment environment)
{
- addInjectionPoint(disposalMethodInjectionPoint);
super.initialize(environment);
checkDisposalMethod();
initDisposesParameter();
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-19 00:08:13
UTC (rev 4186)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java 2009-10-19 00:12:42
UTC (rev 4187)
@@ -89,8 +89,13 @@
*/
public static <T> ManagedBean<T> of(WeldClass<T> clazz,
BeanManagerImpl manager)
{
- return new ManagedBean<T>(clazz, new
StringBuilder().append(ManagedBean.class.getSimpleName()).append(BEAN_ID_SEPARATOR).append(clazz.getName()).toString(),
manager);
+ return new ManagedBean<T>(clazz, createId(ManagedBean.class.getSimpleName(),
clazz), manager);
}
+
+ protected static String createId(String beanType, WeldClass<?> clazz)
+ {
+ return new
StringBuilder().append(beanType).append(BEAN_ID_SEPARATOR).append(clazz.getBaseType()).toString();
+ }
/**
* Constructor
@@ -104,6 +109,7 @@
initType();
initTypes();
initBindings();
+ initConstructor();
}
/**
@@ -173,7 +179,6 @@
{
if (!isInitialized())
{
- initConstructor();
checkConstructor();
super.initialize(environment);
initPostConstruct();
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/NewManagedBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/NewManagedBean.java 2009-10-19
00:08:13 UTC (rev 4186)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/NewManagedBean.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -43,7 +43,7 @@
*/
public static <T> NewManagedBean<T> of(WeldClass<T> clazz,
BeanManagerImpl manager)
{
- return new NewManagedBean<T>(clazz, new
StringBuilder().append(NewManagedBean.class.getSimpleName()).append(BEAN_ID_SEPARATOR).append(clazz.getName()).toString(),
manager);
+ return new NewManagedBean<T>(clazz,
createId(NewManagedBean.class.getSimpleName(), clazz), manager);
}
private Set<Annotation> bindings;
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/NewSessionBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/NewSessionBean.java 2009-10-19
00:08:13 UTC (rev 4186)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/NewSessionBean.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -46,7 +46,7 @@
public static <T> NewSessionBean<T> of(InternalEjbDescriptor<T>
ejbDescriptor, BeanManagerImpl manager)
{
WeldClass<T> type =
manager.getServices().get(ClassTransformer.class).loadClass(ejbDescriptor.getBeanClass());
- return new NewSessionBean<T>(type, ejbDescriptor, new
StringBuilder().append(NewSessionBean.class.getSimpleName()).append(BEAN_ID_SEPARATOR).append(ejbDescriptor.getEjbName()).toString(),
manager);
+ return new NewSessionBean<T>(type, ejbDescriptor,
createId(NewSessionBean.class.getSimpleName(), ejbDescriptor), manager);
}
private Set<Annotation> bindings;
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-19
00:08:13 UTC (rev 4186)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -79,6 +79,7 @@
this.id = new
StringBuilder().append(BEAN_ID_PREFIX).append(getClass().getSimpleName()).append(BEAN_ID_SEPARATOR).append(declaringBean.getAnnotatedItem().getName()).append(getAnnotatedItem().getSignature().toString()).toString();
initStereotypes();
initPolicy();
+ initProducerMethodInjectableParameters();
}
/**
@@ -89,7 +90,6 @@
{
if (!isInitialized())
{
- initProducerMethodInjectableParameters();
super.initialize(environment);
checkProducerMethod();
initDisposalMethod(environment);
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-19 00:08:13
UTC (rev 4186)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/SessionBean.java 2009-10-19 00:12:42
UTC (rev 4187)
@@ -92,9 +92,14 @@
public static <T> SessionBean<T> of(InternalEjbDescriptor<T>
ejbDescriptor, BeanManagerImpl manager)
{
WeldClass<T> type =
manager.getServices().get(ClassTransformer.class).loadClass(ejbDescriptor.getBeanClass());
- return new SessionBean<T>(type, ejbDescriptor, new
StringBuilder().append(SessionBean.class.getSimpleName()).append(BEAN_ID_SEPARATOR).append(ejbDescriptor.getEjbName()).toString(),
manager);
+ return new SessionBean<T>(type, ejbDescriptor,
createId(SessionBean.class.getSimpleName(), ejbDescriptor) , manager);
}
+ protected static String createId(String beanType, InternalEjbDescriptor<?>
ejbDescriptor)
+ {
+ return new
StringBuilder().append(beanType).append(BEAN_ID_SEPARATOR).append(ejbDescriptor.getEjbName()).toString();
+ }
+
/**
* Constructor
*
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/DefaultValidatorBean.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/DefaultValidatorBean.java 2009-10-19
00:08:13 UTC (rev 4186)
+++
core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/DefaultValidatorBean.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -23,6 +23,7 @@
import javax.validation.Validator;
import org.jboss.weld.BeanManagerImpl;
+import org.jboss.weld.Container;
import org.jboss.weld.util.collections.Arrays2;
import org.jboss.weld.validation.spi.ValidationServices;
@@ -55,7 +56,7 @@
{
if (getManager().getServices().contains(ValidationServices.class))
{
- return
getManager().getServices().get(ValidationServices.class).getDefaultValidatorFactory().getValidator();
+ return
Container.instance().deploymentServices().get(ValidationServices.class).getDefaultValidatorFactory().getValidator();
}
else
{
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java 2009-10-19
00:08:13 UTC (rev 4186)
+++
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -102,6 +102,11 @@
// getting lazy created
return null;
}
+ if (proxiedInstance == null)
+ {
+ // TODO not sure if this right PLM
+ return null;
+ }
if (proxiedMethod.getName().equals("equals") &&
proxiedMethod.getParameterTypes().length == 1 &&
proxiedMethod.getParameterTypes()[0] == Object.class && args[0] == self)
{
return true;
@@ -109,7 +114,7 @@
try
{
Object returnValue = Reflections.lookupMethod(proxiedMethod,
proxiedInstance).invoke(proxiedInstance, args);
- log.trace("Executed method " + proxiedMethod + " on " +
proxiedInstance + " with parameters " + Arrays.toString(args) + " and got
return value " + returnValue);
+ log.trace("Executed method " + proxiedMethod + " on " +
proxiedInstance + " with parameters " + Arrays.toString(args) + " and got
return value " + returnValue == null ? null : returnValue);
return returnValue;
}
catch (InvocationTargetException e)
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-19
00:08:13 UTC (rev 4186)
+++
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/AbstractBeanDeployer.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -23,7 +23,6 @@
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
-import javax.interceptor.Interceptor;
import org.jboss.weld.BeanManagerImpl;
import org.jboss.weld.bean.AbstractClassBean;
@@ -155,7 +154,7 @@
* The class bean
*
*/
- protected <T> void createSubBeans(AbstractClassBean<T> bean)
+ protected <T> void createObserversProducersDisposers(AbstractClassBean<T>
bean)
{
createProducerMethods(bean, bean.getAnnotatedItem());
createProducerFields(bean, bean.getAnnotatedItem());
@@ -181,14 +180,14 @@
{
DisposalMethod<X, ?> disposalBean = DisposalMethod.of(manager, method,
declaringBean);
disposalBean.initialize(getEnvironment());
- getEnvironment().addBean(disposalBean);
+ getEnvironment().addDisposesMethod(disposalBean);
}
}
protected <X, T> void createProducerMethod(AbstractClassBean<X>
declaringBean, WeldMethod<T, X> annotatedMethod)
{
ProducerMethod<X, T> bean = ProducerMethod.of(annotatedMethod, declaringBean,
manager);
- getEnvironment().addBean(bean);
+ getEnvironment().addProducerMethod(bean);
}
protected <X, T> void createProducerField(AbstractClassBean<X>
declaringBean, WeldField<T, X> field)
@@ -206,7 +205,7 @@
{
bean = ProducerField.of(field, declaringBean, manager);
}
- getEnvironment().addBean(bean);
+ getEnvironment().addProducerField(bean);
}
protected <X> void createProducerFields(AbstractClassBean<X>
declaringBean, WeldClass<X> annotatedClass)
@@ -228,38 +227,48 @@
protected <X, T> void createObserverMethod(RIBean<X> declaringBean,
WeldMethod<T, X> method)
{
ObserverMethodImpl<X, T> observer = ObserverFactory.create(method,
declaringBean, manager);
- getEnvironment().addObserver(observer);
+ getEnvironment().addObserverMethod(observer);
}
- protected <T> void createSimpleBean(WeldClass<T> annotatedClass)
+ protected <T> ManagedBean<T> createManagedBean(WeldClass<T>
annotatedClass)
{
ManagedBean<T> bean = ManagedBean.of(annotatedClass, manager);
- getEnvironment().addBean(bean);
- createSubBeans(bean);
- getEnvironment().addBean(NewManagedBean.of(annotatedClass, manager));
+ getEnvironment().addManagedBean(bean);
+ createObserversProducersDisposers(bean);
+ return bean;
}
+ protected <T> void createNewManagedBean(WeldClass<T> annotatedClass)
+ {
+ getEnvironment().addManagedBean(NewManagedBean.of(annotatedClass, manager));
+ }
+
protected <T> void createDecorator(WeldClass<T> annotatedClass)
{
DecoratorImpl<T> bean = DecoratorImpl.of(annotatedClass, manager);
- getEnvironment().addBean(bean);
+ getEnvironment().addDecorator(bean);
}
protected <T> void createInterceptor(WeldClass<T> annotatedClass)
{
InterceptorImpl<T> bean = InterceptorImpl.of(annotatedClass, manager);
- getEnvironment().addBean(bean);
+ getEnvironment().addInterceptor(bean);
}
- protected <T> void createEnterpriseBean(InternalEjbDescriptor<T>
ejbDescriptor)
+ protected <T> SessionBean<T>
createSessionBean(InternalEjbDescriptor<T> ejbDescriptor)
{
// TODO Don't create enterprise bean if it has no local interfaces!
SessionBean<T> bean = SessionBean.of(ejbDescriptor, manager);
- getEnvironment().addBean(bean);
- createSubBeans(bean);
- getEnvironment().addBean(NewSessionBean.of(ejbDescriptor, manager));
+ getEnvironment().addSessionBean(bean);
+ createObserversProducersDisposers(bean);
+ return bean;
}
+ protected <T> void createNewSessionBean(InternalEjbDescriptor<T>
ejbDescriptor)
+ {
+ getEnvironment().addSessionBean(NewSessionBean.of(ejbDescriptor, manager));
+ }
+
/**
* Indicates if the type is a simple Web Bean
*
@@ -267,7 +276,7 @@
* The type to inspect
* @return True if simple Web Bean, false otherwise
*/
- protected boolean isTypeManagedBeanOrDecorator(WeldClass<?> clazz)
+ protected boolean isTypeManagedBeanOrDecoratorOrInterceptor(WeldClass<?> clazz)
{
Class<?> javaClass = clazz.getJavaClass();
EJBApiAbstraction ejbApiAbstraction =
manager.getServices().get(EJBApiAbstraction.class);
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployer.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployer.java 2009-10-19
00:08:13 UTC (rev 4186)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployer.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -40,7 +40,6 @@
{
private final BeanManagerImpl deploymentManager;
-
private final Set<WeldClass<?>> classes;
/**
@@ -97,7 +96,7 @@
{
for (WeldClass<?> clazz : classes)
{
- boolean managedBeanOrDecorator =
!getEnvironment().getEjbDescriptors().contains(clazz.getJavaClass()) &&
isTypeManagedBeanOrDecorator(clazz);
+ boolean managedBeanOrDecorator =
!getEnvironment().getEjbDescriptors().contains(clazz.getJavaClass()) &&
isTypeManagedBeanOrDecoratorOrInterceptor(clazz);
if (managedBeanOrDecorator &&
clazz.isAnnotationPresent(Decorator.class))
{
validateDecorator(clazz);
@@ -110,14 +109,24 @@
}
else if (managedBeanOrDecorator && !clazz.isAbstract())
{
- createSimpleBean(clazz);
+ createManagedBean(clazz);
}
}
- // TODO Iterate over newClasses and add a new bean for each
for (InternalEjbDescriptor<?> ejbDescriptor :
getEnvironment().getEjbDescriptors())
{
- createEnterpriseBean(ejbDescriptor);
+ createSessionBean(ejbDescriptor);
}
+
+ // Now create the new beans
+ for (WeldClass<?> clazz : getEnvironment().getNewManagedBeanClasses())
+ {
+ createNewManagedBean(clazz);
+ }
+ for (InternalEjbDescriptor<?> descriptor :
getEnvironment().getNewSessionBeanDescriptors())
+ {
+ createNewSessionBean(descriptor);
+ }
+
return this;
}
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployerEnvironment.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployerEnvironment.java 2009-10-19
00:08:13 UTC (rev 4186)
+++
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployerEnvironment.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -27,22 +27,30 @@
import java.util.Set;
import org.jboss.weld.BeanManagerImpl;
+import org.jboss.weld.bean.AbstractBean;
import org.jboss.weld.bean.AbstractClassBean;
import org.jboss.weld.bean.DecoratorImpl;
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;
import org.jboss.weld.bean.ProducerMethod;
import org.jboss.weld.bean.RIBean;
+import org.jboss.weld.bean.SessionBean;
import org.jboss.weld.bean.builtin.AbstractBuiltInBean;
import org.jboss.weld.bean.builtin.ExtensionBean;
import org.jboss.weld.ejb.EjbDescriptors;
+import org.jboss.weld.ejb.InternalEjbDescriptor;
import org.jboss.weld.event.ObserverMethodImpl;
+import org.jboss.weld.injection.WeldInjectionPoint;
import org.jboss.weld.introspector.WeldClass;
import org.jboss.weld.introspector.WeldMethod;
import org.jboss.weld.resolution.ResolvableFactory;
import org.jboss.weld.resolution.TypeSafeDisposerResolver;
+import org.jboss.weld.resources.ClassTransformer;
public class BeanDeployerEnvironment
{
@@ -57,6 +65,9 @@
private final Set<InterceptorImpl<?>> interceptors;
private final EjbDescriptors ejbDescriptors;
private final TypeSafeDisposerResolver disposalMethodResolver;
+ private final ClassTransformer classTransformer;
+ private final Set<WeldClass<?>> newManagedBeanClasses;
+ private final Set<InternalEjbDescriptor<?>> newSessionBeanDescriptors;
public BeanDeployerEnvironment(EjbDescriptors ejbDescriptors, BeanManagerImpl
manager)
{
@@ -70,7 +81,20 @@
this.observers = new HashSet<ObserverMethodImpl<?, ?>>();
this.ejbDescriptors = ejbDescriptors;
this.disposalMethodResolver = new TypeSafeDisposerResolver(manager,
allDisposalBeans);
+ this.classTransformer = manager.getServices().get(ClassTransformer.class);
+ this.newManagedBeanClasses = new HashSet<WeldClass<?>>();
+ this.newSessionBeanDescriptors = new
HashSet<InternalEjbDescriptor<?>>();
}
+
+ public Set<WeldClass<?>> getNewManagedBeanClasses()
+ {
+ return newManagedBeanClasses;
+ }
+
+ public Set<InternalEjbDescriptor<?>> getNewSessionBeanDescriptors()
+ {
+ return newSessionBeanDescriptors;
+ }
public <X, T> ProducerMethod<X, T> getProducerMethod(WeldMethod<X,
T> method)
{
@@ -100,55 +124,106 @@
}
}
- public void addBean(ProducerMethod<?, ?> bean)
+ public void addProducerMethod(ProducerMethod<?, ?> bean)
{
producerMethodBeanMap.put(bean.getAnnotatedItem(), bean);
- beans.add(bean);
+ addAbstractBean(bean);
}
- public void addBean(ProducerField<?, ?> bean)
+ public void addProducerField(ProducerField<?, ?> bean)
{
- beans.add(bean);
+ addAbstractBean(bean);
}
- public void addBean(ExtensionBean bean)
+ public void addExtension(ExtensionBean bean)
{
beans.add(bean);
}
- public void addBean(AbstractBuiltInBean<?> bean)
+ public void addBuiltInBean(AbstractBuiltInBean<?> bean)
{
beans.add(bean);
}
- public void addBean(AbstractClassBean<?> bean)
+ protected void addAbstractClassBean(AbstractClassBean<?> bean)
{
if (!(bean instanceof NewBean))
{
classBeanMap.put(bean.getAnnotatedItem(), bean);
}
+ addAbstractBean(bean);
+ }
+
+ public void addManagedBean(ManagedBean<?> bean)
+ {
+ newManagedBeanClasses.add(bean.getAnnotatedItem());
+ addAbstractClassBean(bean);
+ }
+
+ public void addSessionBean(SessionBean<?> bean)
+ {
+ newSessionBeanDescriptors.add(bean.getEjbDescriptor());
+ addAbstractClassBean(bean);
+ }
+
+ public void addNewManagedBean(NewManagedBean<?> bean)
+ {
beans.add(bean);
}
+
+ public void addNewSessionBean(NewSessionBean<?> bean)
+ {
+ beans.add(bean);
+ }
+
+ protected void addAbstractBean(AbstractBean<?, ?> bean)
+ {
+ addNewBeansFromInjectionPoints(bean);
+ beans.add(bean);
+ }
- public void addBean(DecoratorImpl<?> bean)
+ public void addDecorator(DecoratorImpl<?> bean)
{
decorators.add(bean);
}
- public void addBean(InterceptorImpl<?> bean)
+ public void addInterceptor(InterceptorImpl<?> bean)
{
interceptors.add(bean);
}
- public void addBean(DisposalMethod<?, ?> bean)
+ public void addDisposesMethod(DisposalMethod<?, ?> bean)
{
allDisposalBeans.add(bean);
+ addNewBeansFromInjectionPoints(bean);
}
- public void addObserver(ObserverMethodImpl<?, ?> observer)
+ public void addObserverMethod(ObserverMethodImpl<?, ?> observer)
{
this.observers.add(observer);
+ addNewBeansFromInjectionPoints(observer.getNewInjectionPoints());
}
+
+
+ private void addNewBeansFromInjectionPoints(AbstractBean<?, ?> bean)
+ {
+ addNewBeansFromInjectionPoints(bean.getNewInjectionPoints());
+ }
+
+ private void addNewBeansFromInjectionPoints(Set<WeldInjectionPoint<?, ?>>
newInjectionPoints)
+ {
+ for (WeldInjectionPoint<?, ?> injectionPoint : newInjectionPoints)
+ {
+ if (getEjbDescriptors().contains(injectionPoint.getJavaClass()))
+ {
+
newSessionBeanDescriptors.add(getEjbDescriptors().getUnique(injectionPoint.getJavaClass()));
+ }
+ else
+ {
+
newManagedBeanClasses.add(classTransformer.loadClass(injectionPoint.getJavaClass(),
injectionPoint.getBaseType()));
+ }
+ }
+ }
public Set<? extends RIBean<?>> getBeans()
{
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployment.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployment.java 2009-10-19
00:08:13 UTC (rev 4186)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployment.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -152,10 +152,10 @@
}
}
beanDeployer.addClasses(beanDeploymentArchive.getBeanClasses());
- beanDeployer.getEnvironment().addBean(new ManagerBean(beanManager));
- beanDeployer.getEnvironment().addBean(new InjectionPointBean(beanManager));
- beanDeployer.getEnvironment().addBean(new EventBean(beanManager));
- beanDeployer.getEnvironment().addBean(new InstanceBean(beanManager));
+ beanDeployer.getEnvironment().addBuiltInBean(new ManagerBean(beanManager));
+ beanDeployer.getEnvironment().addBuiltInBean(new InjectionPointBean(beanManager));
+ beanDeployer.getEnvironment().addBuiltInBean(new EventBean(beanManager));
+ beanDeployer.getEnvironment().addBuiltInBean(new InstanceBean(beanManager));
if (!environment.equals(Environments.SE))
{
beanDeployer.addClass(ConversationImpl.class);
@@ -166,16 +166,16 @@
}
if (beanManager.getServices().contains(TransactionServices.class))
{
- beanDeployer.getEnvironment().addBean(new UserTransactionBean(beanManager));
+ beanDeployer.getEnvironment().addBuiltInBean(new
UserTransactionBean(beanManager));
}
if (beanManager.getServices().contains(SecurityServices.class))
{
- beanDeployer.getEnvironment().addBean(new PrincipalBean(beanManager));
+ beanDeployer.getEnvironment().addBuiltInBean(new PrincipalBean(beanManager));
}
if (beanManager.getServices().contains(ValidationServices.class))
{
- beanDeployer.getEnvironment().addBean(new DefaultValidatorBean(beanManager));
- beanDeployer.getEnvironment().addBean(new
DefaultValidatorFactoryBean(beanManager));
+ beanDeployer.getEnvironment().addBuiltInBean(new
DefaultValidatorBean(beanManager));
+ beanDeployer.getEnvironment().addBuiltInBean(new
DefaultValidatorFactoryBean(beanManager));
}
beanDeployer.createBeans().deploy();
}
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/ExtensionBeanDeployer.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/ExtensionBeanDeployer.java 2009-10-19
00:08:13 UTC (rev 4186)
+++
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/ExtensionBeanDeployer.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -53,7 +53,7 @@
ExtensionBean bean = new ExtensionBean(getManager(), clazz, extension);
this.
- getEnvironment().addBean(bean);
+ getEnvironment().addExtension(bean);
createObserverMethods(bean, clazz);
}
return this;
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/ExtensionBeanDeployerEnvironment.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/ExtensionBeanDeployerEnvironment.java 2009-10-19
00:08:13 UTC (rev 4186)
+++
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/ExtensionBeanDeployerEnvironment.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -26,7 +26,7 @@
}
@Override
- public void addBean(ExtensionBean bean)
+ public void addExtension(ExtensionBean bean)
{
extensionBeans.add(bean);
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/ejb/EjbDescriptors.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/ejb/EjbDescriptors.java 2009-10-19
00:08:13 UTC (rev 4186)
+++ core/trunk/impl/src/main/java/org/jboss/weld/ejb/EjbDescriptors.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -21,10 +21,15 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
import org.jboss.weld.bootstrap.api.Service;
import org.jboss.weld.ejb.spi.EjbDescriptor;
+import com.google.common.base.Supplier;
+import com.google.common.collect.Multimaps;
+import com.google.common.collect.SetMultimap;
+
/**
* EJB descriptors by EJB implementation class or name
*
@@ -34,9 +39,9 @@
public class EjbDescriptors implements Service,
Iterable<InternalEjbDescriptor<?>>
{
// EJB name -> EJB descriptors map
- private final Map<String, InternalEjbDescriptor<?>> ejbs;
+ private final Map<String, InternalEjbDescriptor<?>> ejbByName;
- private final Collection<Class<?>> ejbClasses;
+ private final SetMultimap<Class<?>, String> ejbByClass;
public static final EjbDescriptors EMPTY = new EjbDescriptors()
{
@@ -72,8 +77,16 @@
*/
public EjbDescriptors()
{
- this.ejbs = new HashMap<String, InternalEjbDescriptor<?>>();
- this.ejbClasses = new HashSet<Class<?>>();
+ this.ejbByName = new HashMap<String, InternalEjbDescriptor<?>>();
+ this.ejbByClass = Multimaps.newSetMultimap(new HashMap<Class<?>,
Collection<String>>(), new Supplier<Set<String>>()
+ {
+
+ public Set<String> get()
+ {
+ return new HashSet<String>();
+ }
+
+ });
}
/**
@@ -85,7 +98,7 @@
@SuppressWarnings("unchecked")
public <T> InternalEjbDescriptor<T> get(String beanName)
{
- return (InternalEjbDescriptor<T>) ejbs.get(beanName);
+ return (InternalEjbDescriptor<T>) ejbByName.get(beanName);
}
/**
@@ -96,8 +109,8 @@
public <T> void add(EjbDescriptor<T> ejbDescriptor)
{
InternalEjbDescriptor<T> internalEjbDescriptor = new
InternalEjbDescriptor<T>(ejbDescriptor);
- ejbs.put(ejbDescriptor.getEjbName(), internalEjbDescriptor);
- ejbClasses.add(ejbDescriptor.getBeanClass());
+ ejbByName.put(ejbDescriptor.getEjbName(), internalEjbDescriptor);
+ ejbByClass.put(ejbDescriptor.getBeanClass(), internalEjbDescriptor.getEjbName());
}
/**
@@ -109,7 +122,7 @@
*/
public boolean contains(String beanName)
{
- return ejbs.containsKey(beanName);
+ return ejbByName.containsKey(beanName);
}
/**
@@ -121,9 +134,26 @@
*/
public boolean contains(Class<?> beanClass)
{
- return ejbClasses.contains(beanClass);
+ return ejbByClass.containsKey(beanClass);
}
-
+
+ public InternalEjbDescriptor<?> getUnique(Class<?> beanClass)
+ {
+ Set<String> ejbs = ejbByClass.get(beanClass);
+ if (ejbs.size() > 0)
+ {
+ throw new IllegalStateException("Unable to determine EJB for " +
beanClass + ", multiple EJBs with that class " + ejbs);
+ }
+ else if (ejbs.size() == 0)
+ {
+ return null;
+ }
+ else
+ {
+ return get(ejbs.iterator().next());
+ }
+ }
+
/**
* Adds all EJB descriptors to the maps
*
@@ -142,18 +172,18 @@
*/
public void clear()
{
- ejbs.clear();
+ ejbByName.clear();
}
public Iterator<InternalEjbDescriptor<?>> iterator()
{
- return ejbs.values().iterator();
+ return ejbByName.values().iterator();
}
public void cleanup()
{
- this.ejbClasses.clear();
- this.ejbs.clear();
+ this.ejbByClass.clear();
+ this.ejbByName.clear();
}
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/event/ObserverMethodImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/event/ObserverMethodImpl.java 2009-10-19
00:08:13 UTC (rev 4186)
+++ core/trunk/impl/src/main/java/org/jboss/weld/event/ObserverMethodImpl.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -31,6 +31,7 @@
import javax.enterprise.event.Observes;
import javax.enterprise.event.TransactionPhase;
import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.New;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.ObserverMethod;
@@ -41,16 +42,19 @@
import org.jboss.weld.DefinitionException;
import org.jboss.weld.bean.RIBean;
import org.jboss.weld.injection.MethodInjectionPoint;
+import org.jboss.weld.injection.WeldInjectionPoint;
import org.jboss.weld.introspector.WeldMethod;
import org.jboss.weld.introspector.WeldParameter;
import org.jboss.weld.manager.api.ExecutorServices;
+import org.jboss.weld.util.Beans;
/**
* <p>
- * Reference implementation for the ObserverMethod interface, which represents an
- * observer method. Each observer method has an event type which is the class of
- * the event object being observed, and event binding types that are annotations
- * applied to the event parameter to narrow the event notifications delivered.
+ * Reference implementation for the ObserverMethod interface, which represents
+ * an observer method. Each observer method has an event type which is the class
+ * of the event object being observed, and event binding types that are
+ * annotations applied to the event parameter to narrow the event notifications
+ * delivered.
* </p>
*
* @author David Allen
@@ -67,6 +71,8 @@
protected final MethodInjectionPoint<T, X> observerMethod;
protected TransactionPhase transactionPhase;
+ private final Set<WeldInjectionPoint<?, ?>> newInjectionPoints;
+
/**
* Creates an Observer which describes and encapsulates an observer method
* (8.5).
@@ -86,8 +92,21 @@
Observes observesAnnotation =
observerMethod.getAnnotatedParameters(Observes.class).get(0).getAnnotation(Observes.class);
this.notifyType = observesAnnotation.notifyObserver();
transactionPhase = TransactionPhase.IN_PROGRESS;
+ this.newInjectionPoints = new HashSet<WeldInjectionPoint<?, ?>>();
+ for (WeldInjectionPoint<?, ?> injectionPoint :
Beans.getParameterInjectionPoints(null, observerMethod))
+ {
+ if (injectionPoint.isAnnotationPresent(New.class))
+ {
+ this.newInjectionPoints.add(injectionPoint);
+ }
+ }
}
+ public Set<WeldInjectionPoint<?, ?>> getNewInjectionPoints()
+ {
+ return newInjectionPoints;
+ }
+
/**
* Performs validation of the observer method for compliance with the
* specifications.
@@ -117,10 +136,12 @@
{
throw new DefinitionException("Cannot use a type variable " +
type + " in an parameterized type " + toString());
}
-// else if (type instanceof WildcardType)
-// {
-// throw new DefinitionException("Cannot use a wildcard variable
" + type + " in an parameterized type " + toString());
-// }
+ // else if (type instanceof WildcardType)
+ // {
+ // throw new
+ // DefinitionException("Cannot use a wildcard variable " + type
+
+ // " in an parameterized type " + toString());
+ // }
}
}
}
@@ -173,7 +194,7 @@
{
return transactionPhase;
}
-
+
/**
* @return the observerMethod
*/
@@ -217,7 +238,8 @@
{
return;
}
- // As we are working with the contextual instance, we may not have the actual
object, but a container proxy (e.g. EJB)
+ // As we are working with the contextual instance, we may not have the
+ // actual object, but a container proxy (e.g. EJB)
observerMethod.invokeOnInstanceWithSpecialValue(instance, Observes.class, event,
manager, creationalContext, ObserverException.class);
}
finally
@@ -231,6 +253,7 @@
/**
* Queues the event for later execution
+ *
* @param event
*/
protected void sendEventAsynchronously(final T event)
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/AbstractWeldAnnotated.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/AbstractWeldAnnotated.java 2009-10-19
00:08:13 UTC (rev 4186)
+++
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/AbstractWeldAnnotated.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -19,6 +19,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
@@ -166,10 +167,10 @@
@Override
public boolean equals(Object other)
{
- if (other instanceof WeldAnnotated)
+ if (other instanceof WeldAnnotated<?, ?>)
{
WeldAnnotated<?, ?> that = (WeldAnnotated<?, ?>) other;
- return this.getAnnotations().equals(that.getAnnotations()) &&
this.getJavaClass().equals(that.getJavaClass());
+ return this.getAnnotations().equals(that.getAnnotations()) &&
this.getJavaClass().equals(that.getJavaClass()) &&
this.getActualTypeArguments().length == that.getActualTypeArguments().length &&
Arrays.equals(this.getActualTypeArguments(), that.getActualTypeArguments());
}
return false;
}
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java 2009-10-19
00:08:13 UTC (rev 4186)
+++
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -136,6 +136,12 @@
AnnotationStore annotationStore =
AnnotationStore.of(annotatedType.getAnnotations(), annotatedType.getAnnotations(),
classTransformer.getTypeStore());
return new WeldClassImpl<T>(annotatedType.getJavaClass(),
annotatedType.getBaseType(), annotatedType, annotationStore, classTransformer);
}
+
+ public static <T> WeldClass<T> of(Class<T> rawType, Type type,
ClassTransformer classTransformer)
+ {
+ AnnotationStore annotationStore = AnnotationStore.of(rawType.getAnnotations(),
rawType.getDeclaredAnnotations(), classTransformer.getTypeStore());
+ return new WeldClassImpl<T>(rawType, type, null, annotationStore,
classTransformer);
+ }
protected WeldClassImpl(Class<T> rawType, Type type, AnnotatedType<T>
annotatedType, AnnotationStore annotationStore, ClassTransformer classTransformer)
{
Modified: core/trunk/impl/src/main/java/org/jboss/weld/resources/ClassTransformer.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/resources/ClassTransformer.java 2009-10-19
00:08:13 UTC (rev 4186)
+++
core/trunk/impl/src/main/java/org/jboss/weld/resources/ClassTransformer.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -17,6 +17,7 @@
package org.jboss.weld.resources;
import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
import java.util.concurrent.Callable;
import javax.enterprise.inject.spi.AnnotatedType;
@@ -32,7 +33,7 @@
public class ClassTransformer implements Service
{
- private final ConcurrentCache<Class<?>, WeldClass<?>> classes;
+ private final ConcurrentCache<Type, WeldClass<?>> classes;
private final ConcurrentCache<AnnotatedType<?>, WeldClass<?>>
annotatedTypes;
private final ConcurrentCache<Class<?>, WeldAnnotation<?>>
annotations;
private final TypeStore typeStore;
@@ -42,21 +43,33 @@
*/
public ClassTransformer(TypeStore typeStore)
{
- classes = new ConcurrentCache<Class<?>, WeldClass<?>>();
+ classes = new ConcurrentCache<Type, WeldClass<?>>();
this.annotatedTypes = new ConcurrentCache<AnnotatedType<?>,
WeldClass<?>>();
annotations = new ConcurrentCache<Class<?>,
WeldAnnotation<?>>();
this.typeStore = typeStore;
}
+ public <T> WeldClass<T> loadClass(final Class<T> rawType, final Type
baseType)
+ {
+ return classes.putIfAbsent(baseType, new Callable<WeldClass<T>>()
+ {
+
+ public WeldClass<T> call() throws Exception
+ {
+ return WeldClassImpl.of(rawType, baseType, ClassTransformer.this);
+ }
+
+ });
+ }
+
public <T> WeldClass<T> loadClass(final Class<T> clazz)
{
- final ClassTransformer transformer = this;
return classes.putIfAbsent(clazz, new Callable<WeldClass<T>>()
{
public WeldClass<T> call() throws Exception
{
- return WeldClassImpl.of(clazz, transformer);
+ return WeldClassImpl.of(clazz, ClassTransformer.this);
}
});
@@ -64,13 +77,12 @@
public <T> WeldClass<T> loadClass(final AnnotatedType<T> clazz)
{
- final ClassTransformer transformer = this;
return annotatedTypes.putIfAbsent(clazz, new Callable<WeldClass<T>>()
{
public WeldClass<T> call() throws Exception
{
- return WeldClassImpl.of(clazz, transformer);
+ return WeldClassImpl.of(clazz, ClassTransformer.this);
}
});
@@ -78,13 +90,12 @@
public <T extends Annotation> WeldAnnotation<T> loadAnnotation(final
Class<T> clazz)
{
- final ClassTransformer transformer = this;
return annotations.putIfAbsent(clazz, new
Callable<WeldAnnotation<T>>()
{
public WeldAnnotation<T> call() throws Exception
{
- return WeldAnnotationImpl.of(clazz, transformer);
+ return WeldAnnotationImpl.of(clazz, ClassTransformer.this);
}
});
Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java 2009-10-19 00:08:13 UTC
(rev 4186)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java 2009-10-19 00:12:42 UTC
(rev 4187)
@@ -17,7 +17,6 @@
package org.jboss.weld.util;
import java.lang.annotation.Annotation;
-import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
@@ -398,6 +397,16 @@
return injectionPoints;
}
+ public static Set<ParameterInjectionPoint<?, ?>>
getParameterInjectionPoints(Bean<?> declaringBean, MethodInjectionPoint<?, ?>
method)
+ {
+ Set<ParameterInjectionPoint<?,?>> injectionPoints = new
HashSet<ParameterInjectionPoint<?,?>>();
+ for (WeldParameter<?, ?> parameter : method.getWBParameters())
+ {
+ injectionPoints.add(ParameterInjectionPoint.of(declaringBean, parameter));
+ }
+ return injectionPoints;
+ }
+
public static Set<ParameterInjectionPoint<?, ?>>
getParameterInjectionPoints(Bean<?> declaringBean,
List<Set<MethodInjectionPoint<?, ?>>> methodInjectionPoints)
{
Set<ParameterInjectionPoint<?, ?>> injectionPoints = new
HashSet<ParameterInjectionPoint<?,?>>();
Modified:
core/trunk/inject-tck-runner/src/test/java/org/jboss/weld/atinject/tck/Producers.java
===================================================================
---
core/trunk/inject-tck-runner/src/test/java/org/jboss/weld/atinject/tck/Producers.java 2009-10-19
00:08:13 UTC (rev 4186)
+++
core/trunk/inject-tck-runner/src/test/java/org/jboss/weld/atinject/tck/Producers.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -10,10 +10,9 @@
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
+import javax.enterprise.inject.New;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.Typed;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Qualifier;
@@ -22,7 +21,6 @@
import org.atinject.tck.auto.Seat;
import org.atinject.tck.auto.Tire;
import org.atinject.tck.auto.accessories.SpareTire;
-import org.jboss.weld.atinject.tck.util.NonContextual;
/**
* Producer methods for the @Inject TCK beans we need greater control over
@@ -32,16 +30,6 @@
*/
public class Producers
{
-
- private final NonContextual<SpareTire> spareTire;
- private final NonContextual<DriversSeat> driversSeat;
-
- @Inject
- public Producers(BeanManager beanManager)
- {
- this.spareTire = new NonContextual<SpareTire>(beanManager, SpareTire.class);
- this.driversSeat = new NonContextual<DriversSeat>(beanManager,
DriversSeat.class);
- }
/**
* Producer method for a bean with qualifier @Drivers and types Seat, Object
@@ -49,9 +37,9 @@
* @return
*/
@Produces @Drivers
- public Seat produceAtDriversSeat()
+ public Seat produceAtDriversSeat(@New DriversSeat driversSeat)
{
- return driversSeat.newInstance().produce().inject().get();
+ return driversSeat;
}
/**
@@ -60,9 +48,9 @@
* @return
*/
@Produces @Typed(DriversSeat.class)
- public DriversSeat produceDriversSeat()
+ public DriversSeat produceDriversSeat(@New DriversSeat driversSeat)
{
- return driversSeat.newInstance().produce().inject().get();
+ return driversSeat;
}
@Qualifier
@@ -81,18 +69,18 @@
*
*/
@Produces @Named("spare") @Spare
- public Tire produceAtNamedSpareTire()
+ public Tire produceAtNamedSpareTire(@New SpareTire spareTire)
{
- return spareTire.newInstance().produce().inject().get();
+ return spareTire;
}
/**
* Producer method for bean with default qualifiers and type SpareTire only
*/
@Produces @Typed(SpareTire.class)
- public SpareTire produceSpareTire()
+ public SpareTire produceSpareTire(@New SpareTire spareTire)
{
- return spareTire.newInstance().produce().inject().get();
+ return spareTire;
}
}
Modified: core/trunk/tests/src/main/java/org/jboss/weld/mock/MockValidationServices.java
===================================================================
---
core/trunk/tests/src/main/java/org/jboss/weld/mock/MockValidationServices.java 2009-10-19
00:08:13 UTC (rev 4186)
+++
core/trunk/tests/src/main/java/org/jboss/weld/mock/MockValidationServices.java 2009-10-19
00:12:42 UTC (rev 4187)
@@ -16,6 +16,11 @@
*/
package org.jboss.weld.mock;
+import javax.validation.ConstraintValidatorFactory;
+import javax.validation.MessageInterpolator;
+import javax.validation.TraversableResolver;
+import javax.validation.Validator;
+import javax.validation.ValidatorContext;
import javax.validation.ValidatorFactory;
import org.jboss.weld.validation.spi.ValidationServices;
@@ -29,7 +34,45 @@
public ValidatorFactory getDefaultValidatorFactory()
{
- return null;
+ return new ValidatorFactory()
+ {
+
+ public ValidatorContext usingContext()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public <T> T unwrap(Class<T> type)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Validator getValidator()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public TraversableResolver getTraversableResolver()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public MessageInterpolator getMessageInterpolator()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ConstraintValidatorFactory getConstraintValidatorFactory()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
}
public void cleanup() {}