Skip to content

Commit

Permalink
A lightweight annotated class for resolving
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@1605 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Feb 19, 2009
1 parent 3672860 commit f24ae4a
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 21 deletions.
11 changes: 6 additions & 5 deletions webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
Expand Up @@ -64,6 +64,7 @@
import org.jboss.webbeans.ejb.spi.EjbResolver;
import org.jboss.webbeans.event.EventManager;
import org.jboss.webbeans.event.ObserverImpl;
import org.jboss.webbeans.injection.ResolvableAnnotatedClass;
import org.jboss.webbeans.injection.Resolver;
import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.introspector.AnnotatedItem;
Expand Down Expand Up @@ -288,7 +289,7 @@ public void setEnabledDeploymentTypes(List<Class<? extends Annotation>> enabledD
*/
public <T> Set<Bean<T>> resolveByType(Class<T> type, Annotation... bindings)
{
return resolveByType(AnnotatedClassImpl.of(type, bindings), bindings);
return resolveByType(ResolvableAnnotatedClass.of(type, bindings), bindings);
}

/**
Expand All @@ -303,7 +304,7 @@ public <T> Set<Bean<T>> resolveByType(Class<T> type, Annotation... bindings)
*/
public <T> Set<Bean<T>> resolveByType(TypeLiteral<T> type, Annotation... bindings)
{
return resolveByType(AnnotatedClassImpl.of(type, bindings), bindings);
return resolveByType(ResolvableAnnotatedClass.of(type, bindings), bindings);
}

/**
Expand Down Expand Up @@ -622,7 +623,7 @@ public <T> T getInstanceToInject(InjectionPoint injectionPoint, CreationalContex
{
currentInjectionPoint.set(injectionPoint);
}
AnnotatedItem<T, ?> element = AnnotatedClassImpl.of((Class<T>) injectionPoint.getType(), injectionPoint.getBindings().toArray(new Annotation[0]));
AnnotatedItem<T, ?> element = ResolvableAnnotatedClass.of((Class<T>) injectionPoint.getType(), injectionPoint.getBindings().toArray(new Annotation[0]));
Bean<T> bean = getBeanByType(element, element.getBindingsAsArray());
if (creationalContext instanceof CreationalContextImpl)
{
Expand Down Expand Up @@ -689,7 +690,7 @@ else if (beans.size() > 1)
*/
public <T> T getInstanceByType(Class<T> type, Annotation... bindings)
{
return getInstanceByType(AnnotatedClassImpl.of(type, bindings), bindings);
return getInstanceByType(ResolvableAnnotatedClass.of(type, bindings), bindings);
}


Expand All @@ -705,7 +706,7 @@ public <T> T getInstanceByType(Class<T> type, Annotation... bindings)
*/
public <T> T getInstanceByType(TypeLiteral<T> type, Annotation... bindings)
{
return getInstanceByType(AnnotatedClassImpl.of(type, bindings), bindings);
return getInstanceByType(ResolvableAnnotatedClass.of(type, bindings), bindings);
}

/**
Expand Down
@@ -0,0 +1,94 @@
package org.jboss.webbeans.injection;

import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Arrays;

import javax.inject.TypeLiteral;

import org.jboss.webbeans.introspector.AnnotationStore;
import org.jboss.webbeans.introspector.jlr.AbstractAnnotatedItem;

/**
* Extension of an element which bases equality not only on type, but also on
* binding type
*/
public class ResolvableAnnotatedClass<T> extends AbstractAnnotatedItem<T, Class<T>>
{

private static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0];
private final Class<T> rawType;
private final Type[] actualTypeArguments;

private final String _string;

public static <T> ResolvableAnnotatedClass<T> of(TypeLiteral<T> typeLiteral, Annotation[] annotations)
{
return new ResolvableAnnotatedClass<T>(typeLiteral.getRawType(), typeLiteral.getType(), annotations);
}

public static <T> ResolvableAnnotatedClass<T> of(Class<T> clazz, Annotation[] annotations)
{
return new ResolvableAnnotatedClass<T>(clazz, clazz, annotations);
}

private ResolvableAnnotatedClass(Class<T> rawType, Type type, Annotation[] annotations)
{
super(AnnotationStore.of(annotations, EMPTY_ANNOTATION_ARRAY));
this.rawType = rawType;
if (type instanceof ParameterizedType)
{
this.actualTypeArguments = ((ParameterizedType) type).getActualTypeArguments();
this._string = rawType.toString() + "<" + Arrays.asList(actualTypeArguments).toString() + ">";
}
else
{
this.actualTypeArguments = new Type[0];
this._string = rawType.toString();
}
}

@Override
public String toString()
{
return _string;
}

@Override
public Class<T> getDelegate()
{
return rawType;
}

public Type[] getActualTypeArguments()
{
return actualTypeArguments;
}

public String getName()
{
throw new UnsupportedOperationException();
}

public Class<T> getType()
{
return rawType;
}

public boolean isFinal()
{
throw new UnsupportedOperationException();
}

public boolean isPublic()
{
throw new UnsupportedOperationException();
}

public boolean isStatic()
{
throw new UnsupportedOperationException();
}

}
Expand Up @@ -31,8 +31,6 @@
import java.util.Map;
import java.util.Set;

import javax.inject.TypeLiteral;

import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.introspector.AnnotatedConstructor;
import org.jboss.webbeans.introspector.AnnotatedField;
Expand Down Expand Up @@ -265,20 +263,6 @@ public static <T> AnnotatedClass<T> of(Class<T> clazz)
{
return new AnnotatedClassImpl<T>(clazz, clazz, clazz.getAnnotations(), clazz.getDeclaredAnnotations());
}

// TODO Introduce a lightweight implementation for resolution
@Deprecated
public static <T> AnnotatedClassImpl<T> of(TypeLiteral<T> typeLiteral, Annotation[] annotations)
{
return new AnnotatedClassImpl<T>(typeLiteral.getRawType(), typeLiteral.getType(), annotations, annotations);
}

// TODO Introduce a lightweight implementation for resolution
@Deprecated
public static <T> AnnotatedClassImpl<T> of(Class<T> clazz, Annotation[] annotations)
{
return new AnnotatedClassImpl<T>(clazz, clazz, annotations, annotations);
}

private AnnotatedClassImpl(Class<T> rawType, Type type, Annotation[] annotations, Annotation[] declaredAnnotations)
{
Expand Down

0 comments on commit f24ae4a

Please sign in to comment.