Skip to content

Commit

Permalink
WELD-305
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Dec 3, 2009
1 parent f8b3b2b commit b39d4ac
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 9 deletions.
2 changes: 1 addition & 1 deletion impl/src/main/java/org/jboss/weld/bean/AbstractBean.java
Expand Up @@ -199,7 +199,7 @@ protected void initTypes()
}
else
{
this.types = getAnnotatedItem().getTypeClosure();
this.types = new HashSet<Type>(getAnnotatedItem().getTypeClosure());
if (getType().isInterface())
{
this.types.add(Object.class);
Expand Down
4 changes: 3 additions & 1 deletion impl/src/main/java/org/jboss/weld/bean/SessionBean.java
Expand Up @@ -73,6 +73,7 @@
import org.jboss.weld.util.Beans;
import org.jboss.weld.util.Proxies;
import org.jboss.weld.util.Proxies.TypeInfo;
import org.jboss.weld.util.Reflections.HierarchyDiscovery;

/**
* An enterprise bean representation
Expand Down Expand Up @@ -206,9 +207,10 @@ public T produce(CreationalContext<T> ctx)
protected void initTypes()
{
Map<Class<?>, Type> types = new LinkedHashMap<Class<?>, Type>();

for (BusinessInterfaceDescriptor<?> businessInterfaceDescriptor : ejbDescriptor.getLocalBusinessInterfaces())
{
types.put(businessInterfaceDescriptor.getInterface(), businessInterfaceDescriptor.getInterface());
types.putAll(new HierarchyDiscovery(businessInterfaceDescriptor.getInterface()).getTypeMap());
}
if (getAnnotatedItem().isAnnotationPresent(Typed.class))
{
Expand Down
23 changes: 17 additions & 6 deletions impl/src/main/java/org/jboss/weld/util/Reflections.java
Expand Up @@ -42,7 +42,6 @@
import java.security.AccessControlException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

Expand All @@ -58,6 +57,9 @@

import ch.qos.cal10n.IMessageConveyor;

import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;

/**
* Utility class for static reflection-type operations
*
Expand All @@ -82,7 +84,7 @@ public static class HierarchyDiscovery

private final Type type;

private Set<Type> typeSet;
private BiMap<Type, Class<?>> types;

public HierarchyDiscovery(Type type)
{
Expand All @@ -91,21 +93,30 @@ public HierarchyDiscovery(Type type)

protected void add(Class<?> clazz, Type type)
{
typeSet.add(type);
types.forcePut(type, clazz);
}

public Set<Type> getTypeClosure()
{
if (typeSet == null)
if (types == null)
{
init();
}
return types.keySet();
}

public Map<Class<?>, Type> getTypeMap()
{
if (types == null)
{
init();
}
return typeSet;
return types.inverse();
}

private void init()
{
this.typeSet = new HashSet<Type>();
this.types = HashBiMap.create();
discoverTypes(type);
}

Expand Down
6 changes: 6 additions & 0 deletions tests/src/main/java/org/jboss/weld/test/AbstractWeldTest.java
Expand Up @@ -90,6 +90,12 @@ public boolean annotationSetMatches(Set<? extends Annotation> annotations, Class
}
return annotationTypeList.size() == 0;
}

public boolean typeSetMatches(Set<Type> types, Type... requiredTypes)
{
List<Type> typeList = Arrays.asList(requiredTypes);
return requiredTypes.length == types.size() && types.containsAll(typeList);
}

protected Iterable<URL> getResources(String name)
{
Expand Down
@@ -0,0 +1,6 @@
package org.jboss.weld.tests.enterprise;

public interface Animal
{

}
9 changes: 9 additions & 0 deletions tests/src/test/java/org/jboss/weld/tests/enterprise/Dog.java
@@ -0,0 +1,9 @@
package org.jboss.weld.tests.enterprise;

import javax.ejb.Local;

@Local
public interface Dog extends Animal
{

}
10 changes: 10 additions & 0 deletions tests/src/test/java/org/jboss/weld/tests/enterprise/DogBean.java
@@ -0,0 +1,10 @@
package org.jboss.weld.tests.enterprise;

import javax.ejb.Stateless;


@Stateless
public class DogBean implements Dog
{

}
@@ -0,0 +1,23 @@
package org.jboss.weld.tests.enterprise;

import javax.enterprise.inject.spi.Bean;

import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.Packaging;
import org.jboss.testharness.impl.packaging.PackagingType;
import org.jboss.weld.test.AbstractWeldTest;
import org.testng.annotations.Test;

@Artifact
@Packaging(PackagingType.EAR)
public class EnterpriseBeanDefinitionTest extends AbstractWeldTest
{

@Test(description="WELD-305")
public void testSuperInterfacesAreBeanTypes()
{
Bean<?> bean = getBean(Dog.class);
assert typeSetMatches(bean.getTypes(), Object.class, Dog.class, Animal.class);
}

}
Expand Up @@ -36,5 +36,4 @@ public void testSLSBBusinessMethodThrowsRuntimeException()
assert false : "Expected a BowlerHatException to be in the cause stack";
}


}

0 comments on commit b39d4ac

Please sign in to comment.