Skip to content

Commit

Permalink
Start to fix producer tests
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@258 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Nov 6, 2008
1 parent 1ba7ae8 commit 49fc69d
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 69 deletions.
@@ -1,22 +1,23 @@
package org.jboss.webbeans.bean;

import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.model.bean.BeanModel;
import org.jboss.webbeans.model.bean.ProducerMethodBeanModel;

public class ProducerBean<T> extends AbstractBean<T>
{

private ProducerMethodBeanModel<T> model;

public ProducerBean(ManagerImpl manager)
public ProducerBean(ProducerMethodBeanModel<T> model, ManagerImpl manager)
{
super(manager);
// TODO Auto-generated constructor stub
this.model = model;
}

@Override
public BeanModel<T, ?> getModel()
public ProducerMethodBeanModel<T> getModel()
{
// TODO Auto-generated method stub
return null;
return model;
}

@Override
Expand Down
Expand Up @@ -41,7 +41,7 @@ public abstract class AbstractBeanModel<T, E> implements BeanModel<T, E>
protected Class<? extends Annotation> deploymentType;
protected Class<T> type;
protected InjectableMethod<?> removeMethod;
private Set<Class<?>> apiTypes;
protected Set<Class<?>> apiTypes;
protected Set<Injectable<?, ?>> injectionPoints;
private boolean primitive;
protected ManagerImpl manager;
Expand Down
Expand Up @@ -4,10 +4,13 @@
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.HashSet;
import java.util.Set;

import javax.webbeans.DefinitionException;
import javax.webbeans.Dependent;
import javax.webbeans.Destructor;
import javax.webbeans.Disposes;
import javax.webbeans.Observes;

import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.injectable.InjectableMethod;
Expand All @@ -22,7 +25,7 @@ public class ProducerMethodBeanModel<T> extends AbstractBeanModel<T, Method>

private MethodConstructor<T> constructor;

private AnnotatedItem<T, Method> xmlAnnotatedItem = null /*new SimpleAnnotatedItem<T, Method>(new HashMap<Class<? extends Annotation>, Annotation>())*/;
private AnnotatedItem<T, Method> xmlAnnotatedItem;
private AnnotatedMethod<T> annotatedMethod;

private BeanModel<?, ?> declaringBean;
Expand All @@ -31,10 +34,11 @@ public class ProducerMethodBeanModel<T> extends AbstractBeanModel<T, Method>
private String location;
private Type declaredBeanType;

public ProducerMethodBeanModel(AnnotatedMethod<T> annotatedMethod, ManagerImpl container)
public ProducerMethodBeanModel(AnnotatedMethod<T> annotatedMethod, AnnotatedMethod<T> xmlAnnotatedMethod, ManagerImpl manager)
{
this.annotatedMethod = annotatedMethod;
init(container);
this.xmlAnnotatedItem = xmlAnnotatedMethod;
init(manager);
}

@Override
Expand Down Expand Up @@ -80,7 +84,6 @@ protected void initDeploymentType()

protected void initDeclaringBean(ManagerImpl container)
{
// TODO replace
declaringBean = container.getModelManager().getBeanModel(getAnnotatedItem().getDelegate().getDeclaringClass());
}

Expand All @@ -95,10 +98,17 @@ protected void checkProducerMethod()
{
throw new DefinitionException("Producer method cannot be static " + annotatedMethod);
}
// TODO Check if declaring class is a WB bean
if (!getScopeType().equals(Dependent.class) && getAnnotatedItem().isFinal())
else if (getAnnotatedItem().isAnnotationPresent(Destructor.class))
{
throw new RuntimeException("Final producer method must have @Dependent scope " + annotatedMethod);
throw new DefinitionException("Producer method cannot be annotated @Destructor");
}
else if (getAnnotatedItem().getAnnotatedParameters(Observes.class).size() > 0)
{
throw new DefinitionException("Producer method cannot have parameter annotated @Observes");
}
else if (getAnnotatedItem().getAnnotatedParameters(Disposes.class).size() > 0)
{
throw new DefinitionException("Producer method cannot have parameter annotated @Disposes");
}
}

Expand Down Expand Up @@ -165,6 +175,26 @@ protected void initType()
}
}

@Override
protected void initApiTypes()
{
if (getType().isArray() || getType().isPrimitive())
{
super.apiTypes = new HashSet<Class<?>>();
super.apiTypes.add(getType());
super.apiTypes.add(Object.class);
}
else if (getType().isInterface())
{
super.initApiTypes();
super.apiTypes.add(Object.class);
}
else
{
super.initApiTypes();
}
}

private Type getDeclaredBeanType()
{
if (declaredBeanType == null)
Expand Down
@@ -1,5 +1,6 @@
package org.jboss.webbeans.test;

import static org.jboss.webbeans.test.util.Util.createProducerModel;
import static org.jboss.webbeans.test.util.Util.createSimpleModel;

import java.lang.reflect.Method;
Expand All @@ -10,7 +11,6 @@

import org.jboss.webbeans.contexts.AbstractContext;
import org.jboss.webbeans.contexts.RequestContext;
import org.jboss.webbeans.introspector.impl.SimpleAnnotatedMethod;
import org.jboss.webbeans.model.bean.ProducerMethodBeanModel;
import org.jboss.webbeans.model.bean.SimpleBeanModel;
import org.jboss.webbeans.test.beans.SpiderProducer;
Expand Down Expand Up @@ -70,7 +70,7 @@ public void testProducerMethodReturningNullOK() throws SecurityException, NoSuch
SimpleBeanModel<SpiderProducer> producer = createSimpleModel(SpiderProducer.class, manager);
manager.getModelManager().addBeanModel(producer);
Method nullProducer = SpiderProducer.class.getMethod("produceShelob");
ProducerMethodBeanModel<Tarantula> producerModel = new ProducerMethodBeanModel<Tarantula>(new SimpleAnnotatedMethod<Tarantula>(nullProducer), manager);
ProducerMethodBeanModel<Tarantula> producerModel = createProducerModel(Tarantula.class, nullProducer, manager);
//Bean<Tarantula> shelobBean = new ProducerBeanImpl<Tarantula>(producerModel, manager);
//assert context.get(shelobBean, true) == null;
}
Expand Down

0 comments on commit 49fc69d

Please sign in to comment.