Skip to content

Commit

Permalink
Code and TCK tests for the ProcessAnnotatedType container lifecycle e…
Browse files Browse the repository at this point in the history
…vents.

git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@3556 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
drallen committed Aug 19, 2009
1 parent 270aa89 commit bcbe3b6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
14 changes: 7 additions & 7 deletions impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
Expand Up @@ -584,13 +584,13 @@ else if (resolvedType instanceof ParameterizedType)
{
throw new IllegalArgumentException("Event type " + resolvedType + " is not allowed");
}
for (Type type : types)
{
if (type instanceof TypeVariable)
{
throw new IllegalArgumentException("Cannot provide an event type parameterized with a type parameter " + resolvedType);
}
}
// for (Type type : types)
// {
// if (type instanceof TypeVariable)
// {
// throw new IllegalArgumentException("Cannot provide an event type parameterized with a type parameter " + resolvedType);
// }
// }
}

/**
Expand Down
Expand Up @@ -79,7 +79,7 @@ public AbstractBeanDeployer addClasses(Iterable<Class<?>> classes)

public AbstractBeanDeployer addClasses(Collection<WBClass<?>> classes)
{
classes.addAll(classes);
this.classes.addAll(classes);
return this;
}

Expand Down
Expand Up @@ -20,14 +20,19 @@
import javax.enterprise.inject.spi.ProcessAnnotatedType;

/**
* Container lifecycle event for each Java class or interface discovered by
* the container.
*
* @author pmuir
* @author David Allen
*
*/
public class ProcessAnnotatedTypeImpl<X> implements ProcessAnnotatedType<X>
{

private AnnotatedType<X> annotatedType;
private boolean veto;
private boolean annotatedTypeReplaced = false;

public ProcessAnnotatedTypeImpl(AnnotatedType<X> annotatedType)
{
Expand All @@ -46,6 +51,7 @@ public void setAnnotatedType(AnnotatedType<X> type)
throw new IllegalArgumentException("Cannot set the type to null (if you want to stop the type being used, call veto()) " + this);
}
this.annotatedType = type;
this.annotatedTypeReplaced = true;
}

public void veto()
Expand All @@ -57,5 +63,10 @@ public boolean isVeto()
{
return veto;
}

public boolean isAnnotatedTypeReplaced()
{
return annotatedTypeReplaced;
}

}
Expand Up @@ -19,7 +19,9 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;

import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.BeforeShutdown;
import javax.enterprise.inject.spi.Extension;

Expand Down Expand Up @@ -59,6 +61,7 @@
import org.jboss.webbeans.ejb.EjbDescriptorCache;
import org.jboss.webbeans.ejb.spi.EjbDescriptor;
import org.jboss.webbeans.ejb.spi.EjbServices;
import org.jboss.webbeans.introspector.WBClass;
import org.jboss.webbeans.jsf.JsfApiAbstraction;
import org.jboss.webbeans.log.Log;
import org.jboss.webbeans.log.Logging;
Expand Down Expand Up @@ -268,7 +271,7 @@ public Bootstrap deployBeans()
{
synchronized (this)
{
beanDeployer.addClasses(deploymentVisitor.getBeanClasses());
beanDeployer.addClasses(fireProcessAnnotatedTypeEvents(deploymentVisitor.getBeanClasses()));
beanDeployer.getEnvironment().addBean(new ManagerBean(manager));
beanDeployer.getEnvironment().addBean(new InjectionPointBean(manager));
beanDeployer.getEnvironment().addBean(new EventBean(manager));
Expand Down Expand Up @@ -411,6 +414,32 @@ private void fireAfterDeploymentValidationEvent()
}
}

private Collection<WBClass<?>> fireProcessAnnotatedTypeEvents(Iterable<Class<?>> classes)
{
ClassTransformer classTransformer = getManager().getServices().get(ClassTransformer.class);
HashSet<WBClass<?>> finalClassSet = new HashSet<WBClass<?>>();
for (Class<?> clazz : classes)
{
WBClass<?> annotatedType = classTransformer.loadClass(clazz);
ProcessAnnotatedTypeImpl<?> event = createProcessAnnotatedTypeEvent(annotatedType);
getManager().fireEvent(event);
if (!event.isVeto())
{
if (event.isAnnotatedTypeReplaced())
{
//TODO Create another WBClass<?> that uses this annotated type
}
finalClassSet.add(annotatedType);
}
}
return finalClassSet;
}

private <X> ProcessAnnotatedTypeImpl<X> createProcessAnnotatedTypeEvent(AnnotatedType<X> annotatedType)
{
return new ProcessAnnotatedTypeImpl<X>(annotatedType);
}

/**
* Gets version information
*
Expand Down

0 comments on commit bcbe3b6

Please sign in to comment.