Skip to content

Commit

Permalink
Better fix for null injection points
Browse files Browse the repository at this point in the history
Some more @New bootstrap tests

git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@803 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
nickarls committed Jan 7, 2009
1 parent b0accab commit 8d517a9
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 41 deletions.
Expand Up @@ -120,6 +120,7 @@ public AbstractBean(ManagerImpl manager)
{
super(manager);
this.manager = manager;
injectionPoints = new HashSet<AnnotatedItem<?, ?>>();
}

/**
Expand Down Expand Up @@ -210,14 +211,6 @@ protected void initDeploymentType()
*/
protected abstract Class<? extends Annotation> getDefaultDeploymentType();

/**
* Initializes the injection points
*/
protected void initInjectionPoints()
{
injectionPoints = new HashSet<AnnotatedItem<?, ?>>();
}

/**
* Initializes the name
*/
Expand Down
Expand Up @@ -153,10 +153,8 @@ public Set<AnnotatedMethod<Object>> getObserverMethods()
/**
* Initializes the injection points
*/
@Override
protected void initInjectionPoints()
{
super.initInjectionPoints();
injectableFields = new HashSet<AnnotatedField<Object>>();
for (AnnotatedField<Object> annotatedField : annotatedItem.getMetaAnnotatedFields(BindingType.class))
{
Expand Down
Expand Up @@ -61,11 +61,6 @@ protected void init()
{
validateInjectionPoint();
super.init();
// TODO: A better place to do this? Event beans also pass through the @New bean
// parsing in bootstrap so the injectionpoints should not be null. This is usually
// done in AbstractClassBean, but it's not in the EventBeans inheritance hierarchy.
// Perhaps just init the injectionPoints to an empty set in AbstractBean...
super.initInjectionPoints();
checkAnnotatedItem();
}

Expand Down
Expand Up @@ -93,10 +93,8 @@ protected void init()
/**
* Initializes the injection points
*/
@Override
protected void initInjectionPoints()
{
super.initInjectionPoints();
for (AnnotatedParameter<Object> parameter : method.getParameters())
{
injectionPoints.add(parameter);
Expand Down
Expand Up @@ -28,6 +28,7 @@
import java.util.HashSet;
import java.util.Set;

import javax.webbeans.BindingType;
import javax.webbeans.DefinitionException;
import javax.webbeans.Fires;
import javax.webbeans.Initializer;
Expand Down Expand Up @@ -130,9 +131,12 @@ protected void registerBeans(Iterable<Class<?>> classes)
{
Set<AbstractBean<?, ?>> beans = createBeans(classes);
beans.addAll(createStandardBeans());
// TODO: Is there any better way to do this? Currently, producer method parameters aren't
// listed in the containing beans injection points since they will be separated into
// producer beans of their own so we'll have to make a second pass to make sure we hit the
// TODO: Is there any better way to do this? Currently, producer method
// parameters aren't
// listed in the containing beans injection points since they will be
// separated into
// producer beans of their own so we'll have to make a second pass to make
// sure we hit the
// created producer beans also.
registerNewBeans(beans);
getManager().setBeans(beans);
Expand All @@ -146,6 +150,10 @@ private void registerNewBeans(Set<AbstractBean<?, ?>> beans)
for (AnnotatedItem<?, ?> injectionPoint : bean.getInjectionPoints())
if (injectionPoint.isAnnotationPresent(New.class))
{
if (injectionPoint.getMetaAnnotations(BindingType.class).size() > 1)
{
throw new DefinitionException("@New cannot be used in conjunction with other binding types");
}
if (manager.getEjbDescriptorCache().containsKey(injectionPoint.getType()))
{

Expand Down
Expand Up @@ -16,6 +16,7 @@
import org.jboss.webbeans.test.SpecAssertion;
import org.jboss.webbeans.test.SpecVersion;
import org.jboss.webbeans.test.mock.MockWebBeanDiscovery;
import org.jboss.webbeans.test.newbean.invalid.NewAndOtherBindingType;
import org.jboss.webbeans.test.newbean.valid.AnnotatedConstructorParameter;
import org.jboss.webbeans.test.newbean.valid.AnnotatedField;
import org.jboss.webbeans.test.newbean.valid.AnnotatedInitializerParameter;
Expand Down Expand Up @@ -336,7 +337,7 @@ public void testNewBeanHasNoDecorators()
* requirements of a simple Web Bean implementation class or enterprise Web
* Bean implementation class.
*/
@Test(groups = { "stub", "new" })
@Test(groups = { "new" })
@SpecAssertion(section = "3.9")
public void testNewAnnotationMayBeAppliedToField()
{
Expand All @@ -353,7 +354,7 @@ public void testNewAnnotationMayBeAppliedToField()
* requirements of a simple Web Bean implementation class or enterprise Web
* Bean implementation class.
*/
@Test(groups = { "stub", "new" })
@Test(groups = { "new" })
@SpecAssertion(section = "3.9")
public void testNewAnnotationMayBeAppliedToProducerMethodParameter()
{
Expand All @@ -370,7 +371,7 @@ public void testNewAnnotationMayBeAppliedToProducerMethodParameter()
* requirements of a simple Web Bean implementation class or enterprise Web
* Bean implementation class.
*/
@Test(groups = { "stub", "new" })
@Test(groups = { "new" })
@SpecAssertion(section = "3.9")
public void testNewAnnotationMayBeAppliedToInitializerMethodParameter()
{
Expand All @@ -387,7 +388,7 @@ public void testNewAnnotationMayBeAppliedToInitializerMethodParameter()
* requirements of a simple Web Bean implementation class or enterprise Web
* Bean implementation class.
*/
@Test(groups = { "stub", "new" })
@Test(groups = { "new" })
@SpecAssertion(section = "3.9")
public void testNewAnnotationMayBeAppliedToConstructorMethodParameter()
{
Expand All @@ -403,11 +404,12 @@ public void testNewAnnotationMayBeAppliedToConstructorMethodParameter()
* enterprise Web Bean implementation class, a DefinitionException is thrown
* by the container at deployment time.
*/
@Test(groups = { "stub", "new" })
@Test(groups = { "new" }, expectedExceptions = DefinitionException.class)
@SpecAssertion(section = "3.9")
public void testNewAnnotationCannotAppearInConjunctionWithOtherBindingType()
{
assert false;
webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(NewAndOtherBindingType.class));
webBeansBootstrap.boot();
}

/**
Expand Down
@@ -0,0 +1,11 @@
package org.jboss.webbeans.test.newbean.invalid;

import javax.webbeans.Current;
import javax.webbeans.New;

import org.jboss.webbeans.test.newbean.valid.WrappedBean;

public class NewAndOtherBindingType
{
public @New @Current WrappedBean violation;
}
Expand Up @@ -2,27 +2,12 @@

import javax.webbeans.Initializer;
import javax.webbeans.New;
import javax.webbeans.Produces;


public class AnnotatedConstructorParameter
{
@New
WrappedBean reference;

@Initializer
public AnnotatedConstructorParameter(@New WrappedBean reference)
{
}

@Initializer
public void init(@New WrappedBean reference)
{
}

@Produces
Object produce(@New WrappedBean reference)
{
return new Object();
}
}

0 comments on commit 8d517a9

Please sign in to comment.