Skip to content

Commit

Permalink
WBRI-75
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@771 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Jan 5, 2009
1 parent 86ef62b commit c45a986
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 32 deletions.
3 changes: 2 additions & 1 deletion webbeans-api/src/main/java/javax/webbeans/manager/Bean.java
Expand Up @@ -18,6 +18,7 @@
package javax.webbeans.manager;

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Set;

/**
Expand Down Expand Up @@ -47,7 +48,7 @@ protected Manager getManager()

public abstract void destroy(T instance);

public abstract Set<Class<?>> getTypes();
public abstract Set<Type> getTypes();

public abstract Set<Annotation> getBindingTypes();

Expand Down
Expand Up @@ -102,7 +102,7 @@ public static Class<? extends Annotation> getDeploymentType(List<Class<? extends
// The type
protected Class<T> type;
// The API types
protected Set<Class<?>> apiTypes;
protected Set<Type> types;
// The injection points
protected Set<AnnotatedItem<?, ?>> injectionPoints;
// If the type a primitive?
Expand Down Expand Up @@ -137,15 +137,16 @@ protected void init()
initDeploymentType();
checkDeploymentType();
initScopeType();
initApiTypes();
initTypes();
}

/**
* Initializes the API types
*/
protected void initApiTypes()
protected void initTypes()
{
apiTypes = Reflections.getTypeHierachy(getType());
types = new HashSet<Type>();
Reflections.getTypeHierachy(getType(), types);
}

/**
Expand Down Expand Up @@ -501,9 +502,9 @@ public Class<T> getType()
* @see javax.webbeans.manager.Bean#getTypes()
*/
@Override
public Set<Class<?>> getTypes()
public Set<Type> getTypes()
{
return apiTypes;
return types;
}

/**
Expand Down
Expand Up @@ -21,18 +21,13 @@
import java.lang.reflect.Type;
import java.util.HashSet;

import javax.webbeans.BindingType;
import javax.webbeans.DefinitionException;
import javax.webbeans.Dependent;
import javax.webbeans.IllegalProductException;
import javax.webbeans.UnserializableDependencyException;
import javax.webbeans.manager.Bean;

import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.MetaDataCache;
import org.jboss.webbeans.context.DependentContext;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.jlr.AbstractAnnotatedMember;
import org.jboss.webbeans.util.Names;
import org.jboss.webbeans.util.Reflections;

Expand Down Expand Up @@ -76,22 +71,22 @@ protected Class<? extends Annotation> getDefaultDeploymentType()
* Initializes the API types
*/
@Override
protected void initApiTypes()
protected void initTypes()
{
if (getType().isArray() || getType().isPrimitive())
{
apiTypes = new HashSet<Class<?>>();
apiTypes.add(getType());
apiTypes.add(Object.class);
types = new HashSet<Type>();
types.add(getType());
types.add(Object.class);
}
else if (getType().isInterface())
{
super.initApiTypes();
apiTypes.add(Object.class);
super.initTypes();
types.add(Object.class);
}
else
{
super.initApiTypes();
super.initTypes();
}
}

Expand Down
Expand Up @@ -18,6 +18,7 @@
package org.jboss.webbeans.bean;

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Set;

import javax.webbeans.manager.Bean;
Expand Down Expand Up @@ -115,7 +116,7 @@ public Class<? extends Annotation> getScopeType()
* @return The API types
*/
@Override
public Set<Class<?>> getTypes()
public Set<Type> getTypes()
{
return delegate().getTypes();
}
Expand Down
Expand Up @@ -18,6 +18,7 @@
package org.jboss.webbeans.bean.proxy;

import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Callable;
Expand Down Expand Up @@ -76,7 +77,7 @@ private static <T> T createClientProxy(Bean<T> bean, int beanIndex) throws Runti
try
{
SimpleBeanProxyMethodHandler proxyMethodHandler = new SimpleBeanProxyMethodHandler(bean, beanIndex);
Set<Class<?>> classes = new HashSet<Class<?>>(bean.getTypes());
Set<Type> classes = new HashSet<Type>(bean.getTypes());
classes.add(Serializable.class);
ProxyFactory proxyFactory = Proxies.getProxyFactory(classes);
proxyFactory.setHandler(proxyMethodHandler);
Expand Down
Expand Up @@ -127,7 +127,7 @@ public interface AnnotatedItem<T, S>
* @param types The set of types to match
* @return True if assignable, false otherwise.
*/
public boolean isAssignableFrom(Set<Class<?>> types);
public boolean isAssignableFrom(Set<Type> types);

/**
* Gets the actual type arguments for any parameterized types that this
Expand Down
Expand Up @@ -123,7 +123,7 @@ public boolean isAssignableFrom(AnnotatedItem<?, ?> that)
/**
* @see org.jboss.webbeans.introspector.AnnotatedItem
*/
public boolean isAssignableFrom(Set<Class<?>> types)
public boolean isAssignableFrom(Set<Type> types)
{
return delegate().isAssignableFrom(types);
}
Expand Down
Expand Up @@ -390,13 +390,21 @@ public boolean isAssignableFrom(AnnotatedItem<?, ?> that)
*
* @see org.jboss.webbeans.introspector.AnnotatedItem#isAssignableFrom(Set)
*/
public boolean isAssignableFrom(Set<Class<?>> types)
public boolean isAssignableFrom(Set<Type> types)
{
for (Class<?> type : types)
for (Type type : types)
{
if (isAssignableFrom(type, Reflections.getActualTypeArguments(type)))
if (type instanceof Class)
{
return true;
Class<?> clazz = (Class<?>) type;
if (isAssignableFrom(clazz, Reflections.getActualTypeArguments(clazz)))
{
return true;
}
}
else
{

}
}
return false;
Expand Down
Expand Up @@ -104,9 +104,9 @@ public static TypeInfo ofClasses(Set<Class<?>> classes)
* @param classes Additional interfaces the proxy should implement
* @return the proxy factory
*/
public static ProxyFactory getProxyFactory(Set<Class<?>> types)
public static ProxyFactory getProxyFactory(Set<Type> types)
{
return TypeInfo.ofClasses(types).createProxyFactory();
return TypeInfo.ofTypes(types).createProxyFactory();
}

}
19 changes: 16 additions & 3 deletions webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
Expand Up @@ -593,20 +593,33 @@ public static boolean isProxy(Object instance)
*
* @param clazz The class to examine
* @return The set of classes and interfaces in the hierarchy
* @see #getTypeHierachy(Class, Set)
*/
public static Set<Class<?>> getTypeHierachy(Class<?> clazz)
{
Set<Class<?>> classes = new HashSet<Class<?>>();
getTypeHierachy(clazz, classes);
return classes;
}

/**
* Gets the flattened type hierarchy for a class, including all super classes
* and the entire interface type hierarchy
*
* @param clazz the class to examine
* @param classes the set of types
*/
public static void getTypeHierachy(Class<?> clazz, Set<? super Class<?>> classes)
{
if (clazz != null)
{
classes.add(clazz);
classes.addAll(getTypeHierachy(clazz.getSuperclass()));
getTypeHierachy(clazz.getSuperclass(), classes);
for (Class<?> c : clazz.getInterfaces())
{
classes.addAll(getTypeHierachy(c));
getTypeHierachy(c, classes);
}
}
return classes;
}

/**
Expand Down
Expand Up @@ -17,6 +17,7 @@

package org.jboss.webbeans.util;


/**
* Utility class for Types
*
Expand Down

0 comments on commit c45a986

Please sign in to comment.