Skip to content

Commit

Permalink
Forwarding maps AnnotationMap and MetaAnnotationMap
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@363 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
nickarls committed Nov 26, 2008
1 parent a10c911 commit e1aebc8
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 50 deletions.
Expand Up @@ -23,7 +23,6 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.webbeans.BindingType;
Expand All @@ -44,6 +43,7 @@
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.AnnotatedParameter;
import org.jboss.webbeans.introspector.jlr.AbstractAnnotatedItem.AnnotationMap;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
import org.jboss.webbeans.util.Reflections;
Expand Down Expand Up @@ -73,7 +73,7 @@ public abstract class AbstractBean<T, E> extends Bean<T>
* @param possibleDeploymentTypes The possible deployment types
* @return The deployment type
*/
public static Class<? extends Annotation> getDeploymentType(List<Class<? extends Annotation>> enabledDeploymentTypes, Map<Class<? extends Annotation>, Annotation> possibleDeploymentTypes)
public static Class<? extends Annotation> getDeploymentType(List<Class<? extends Annotation>> enabledDeploymentTypes, AnnotationMap possibleDeploymentTypes)
{
for (int i = (enabledDeploymentTypes.size() - 1); i > 0; i--)
{
Expand Down
Expand Up @@ -18,13 +18,12 @@
package org.jboss.webbeans.bean;

import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.introspector.jlr.AbstractAnnotatedItem.AnnotationMap;
import org.jboss.webbeans.model.StereotypeModel;

/**
Expand All @@ -35,7 +34,7 @@
*/
public class MergedStereotypes<T, E>
{
private Map<Class<? extends Annotation>, Annotation> possibleDeploymentTypes;
private AnnotationMap possibleDeploymentTypes;
private Set<Annotation> possibleScopeTypes;
private boolean beanNameDefaulted;
private Set<Class<?>> requiredTypes;
Expand All @@ -49,7 +48,7 @@ public class MergedStereotypes<T, E>
*/
public MergedStereotypes(Set<Annotation> stereotypeAnnotations, ManagerImpl manager)
{
possibleDeploymentTypes = new HashMap<Class<? extends Annotation>, Annotation>();
possibleDeploymentTypes = new AnnotationMap();
possibleScopeTypes = new HashSet<Annotation>();
requiredTypes = new HashSet<Class<?>>();
supportedScopes = new HashSet<Class<? extends Annotation>>();
Expand Down Expand Up @@ -94,7 +93,7 @@ protected void merge(Set<Annotation> stereotypeAnnotations, ManagerImpl manager)
*
* @return The deployment types
*/
public Map<Class<? extends Annotation>, Annotation> getPossibleDeploymentTypes()
public AnnotationMap getPossibleDeploymentTypes()
{
return possibleDeploymentTypes;
}
Expand Down
Expand Up @@ -30,7 +30,6 @@
*/
public interface AnnotatedItem<T, S>
{

/**
* Gets all annotations on the item
*
Expand Down
Expand Up @@ -21,61 +21,98 @@
import org.jboss.webbeans.util.Reflections;
import org.jboss.webbeans.util.Types;

import com.google.common.collect.ForwardingMap;

public abstract class AbstractAnnotatedItem<T, S> implements AnnotatedItem<T, S>
{

private static final Annotation[] DEFAULT_BINDING_ARRAY = {new CurrentAnnotationLiteral()};
public static class AnnotationMap extends ForwardingMap<Class<? extends Annotation>, Annotation>
{
private Map<Class<? extends Annotation>, Annotation> delegate;

public AnnotationMap()
{
delegate = new HashMap<Class<? extends Annotation>, Annotation>();
}

@Override
protected Map<Class<? extends Annotation>, Annotation> delegate()
{
return delegate;
}

}

public static class MetaAnnotationMap extends ForwardingMap<Class<? extends Annotation>, Set<Annotation>>
{
private Map<Class<? extends Annotation>, Set<Annotation>> delegate;

public MetaAnnotationMap()
{
delegate = new HashMap<Class<? extends Annotation>, Set<Annotation>>();
}

@Override
protected Map<Class<? extends Annotation>, Set<Annotation>> delegate()
{
return delegate;
}

}

private static final Annotation[] DEFAULT_BINDING_ARRAY = { new CurrentAnnotationLiteral() };
private static final Set<Annotation> DEFAULT_BINDING = new HashSet<Annotation>(Arrays.asList(DEFAULT_BINDING_ARRAY));
private Map<Class<? extends Annotation>, Annotation> annotationMap;
private Map<Class<? extends Annotation>, Set<Annotation>> metaAnnotationMap;

private AnnotationMap annotationMap;
private MetaAnnotationMap metaAnnotationMap;
private Set<Annotation> annotationSet;
private Annotation[] annotationArray;
public AbstractAnnotatedItem(Map<Class<? extends Annotation>, Annotation> annotationMap)

public AbstractAnnotatedItem(AnnotationMap annotationMap)
{
if (annotationMap == null)
{
throw new NullPointerException("annotationMap cannot be null");
}
this.annotationMap = annotationMap;
}
protected static Map<Class<? extends Annotation>, Annotation> buildAnnotationMap(AnnotatedElement element)

protected static AnnotationMap buildAnnotationMap(AnnotatedElement element)
{
return buildAnnotationMap(element.getAnnotations());
}
protected static Map<Class<? extends Annotation>, Annotation> buildAnnotationMap(Annotation[] annotations)

protected static AnnotationMap buildAnnotationMap(Annotation[] annotations)
{
Map<Class<? extends Annotation>, Annotation> annotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
AnnotationMap annotationMap = new AnnotationMap();
for (Annotation annotation : annotations)
{
annotationMap.put(annotation.annotationType(), annotation);
}
return annotationMap;
}

protected static Set<Annotation> populateAnnotationSet(Set<Annotation> annotationSet, Map<Class<? extends Annotation>, Annotation> annotationMap)
protected static Set<Annotation> populateAnnotationSet(Set<Annotation> annotationSet, AnnotationMap annotationMap)
{
for (Entry<Class<? extends Annotation>, Annotation> entry : annotationMap.entrySet())
{
annotationSet.add(entry.getValue());
}
return annotationSet;
}

protected static Object[] getParameterValues(List<AnnotatedParameter<Object>> parameters, ManagerImpl manager)
{
Object[] parameterValues = new Object[parameters.size()];
Iterator<AnnotatedParameter<Object>> iterator = parameters.iterator();
Iterator<AnnotatedParameter<Object>> iterator = parameters.iterator();
for (int i = 0; i < parameterValues.length; i++)
{
parameterValues[i] = iterator.next().getValue(manager);
}
return parameterValues;
}

@SuppressWarnings("unchecked")
public <A extends Annotation> A getAnnotation(Class<? extends A> annotationType)
{
return (A) annotationMap.get(annotationType);
Expand All @@ -85,12 +122,12 @@ public Set<Annotation> getMetaAnnotations(Class<? extends Annotation> metaAnnota
{
if (metaAnnotationMap == null)
{
metaAnnotationMap = new HashMap<Class<? extends Annotation>, Set<Annotation>>();
metaAnnotationMap = new MetaAnnotationMap();
}
metaAnnotationMap = populateMetaAnnotationMap(metaAnnotationType, metaAnnotationMap, annotationMap);
return metaAnnotationMap.get(metaAnnotationType);
}

public Annotation[] getMetaAnnotationsAsArray(Class<? extends Annotation> metaAnnotationType)
{
if (annotationArray == null)
Expand All @@ -115,10 +152,7 @@ public boolean isAnnotationPresent(Class<? extends Annotation> annotatedType)
return annotationMap.containsKey(annotatedType);
}

protected static <A extends Annotation> Map<Class<? extends Annotation>, Set<Annotation>> populateMetaAnnotationMap(
Class<A> metaAnnotationType, Map<Class<? extends Annotation>,
Set<Annotation>> metaAnnotationMap,
Map<Class<? extends Annotation>, Annotation> annotationMap)
protected static <A extends Annotation> MetaAnnotationMap populateMetaAnnotationMap(Class<A> metaAnnotationType, MetaAnnotationMap metaAnnotationMap, AnnotationMap annotationMap)
{
if (!metaAnnotationMap.containsKey(metaAnnotationType))
{
Expand All @@ -135,11 +169,11 @@ protected static <A extends Annotation> Map<Class<? extends Annotation>, Set<Ann
return metaAnnotationMap;
}

protected Map<Class<? extends Annotation>, Annotation> getAnnotationMap()
protected AnnotationMap getAnnotationMap()
{
return annotationMap;
}

@Override
public boolean equals(Object other)
{
Expand All @@ -150,12 +184,12 @@ public boolean equals(Object other)
}
return false;
}

public boolean isAssignableFrom(AnnotatedItem<?, ?> that)
{
return isAssignableFrom(that.getType(), that.getActualTypeArguments());
}

public boolean isAssignableFrom(Set<Class<?>> types)
{
for (Class<?> type : types)
Expand All @@ -167,18 +201,18 @@ public boolean isAssignableFrom(Set<Class<?>> types)
}
return false;
}

private boolean isAssignableFrom(Class<?> type, Type[] actualTypeArguments)
{
return Types.boxedType(getType()).isAssignableFrom(Types.boxedType(type)) && Arrays.equals(getActualTypeArguments(), actualTypeArguments);
}

@Override
public int hashCode()
{
return getType().hashCode();
}

@Override
public String toString()
{
Expand All @@ -199,7 +233,7 @@ public String toString()
string += getAnnotations();
return string;
}

public Set<Annotation> getBindingTypes()
{
if (getMetaAnnotations(BindingType.class).size() > 0)
Expand All @@ -211,7 +245,7 @@ public Set<Annotation> getBindingTypes()
return DEFAULT_BINDING;
}
}

public Annotation[] getBindingTypesAsArray()
{
if (getMetaAnnotationsAsArray(BindingType.class).length > 0)
Expand All @@ -223,7 +257,7 @@ public Annotation[] getBindingTypesAsArray()
return DEFAULT_BINDING_ARRAY;
}
}

public boolean isProxyable()
{
if (Reflections.getConstructor(getType()) == null)
Expand Down
@@ -1,8 +1,6 @@
package org.jboss.webbeans.introspector.jlr;

import java.lang.annotation.Annotation;
import java.lang.reflect.Member;
import java.util.Map;

import javax.webbeans.BindingType;

Expand All @@ -14,7 +12,7 @@ public abstract class AbstractAnnotatedMember<T, S extends Member> extends Abstr

private String name;

public AbstractAnnotatedMember(Map<Class<? extends Annotation>, Annotation> annotationMap)
public AbstractAnnotatedMember(AnnotationMap annotationMap)
{
super(annotationMap);
}
Expand Down
@@ -1,8 +1,5 @@
package org.jboss.webbeans.introspector.jlr;

import java.lang.annotation.Annotation;
import java.util.Map;

import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.util.Reflections;

Expand All @@ -11,7 +8,7 @@ public abstract class AbstractAnnotatedType<T> extends AbstractAnnotatedItem<T,

private AnnotatedClass<Object> superclass;

public AbstractAnnotatedType(Map<Class<? extends Annotation>, Annotation> annotationMap)
public AbstractAnnotatedType(AnnotationMap annotationMap)
{
super(annotationMap);
}
Expand Down
Expand Up @@ -3,7 +3,6 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Map;

import javax.webbeans.TypeLiteral;

Expand All @@ -14,18 +13,18 @@ public class AnnotatedItemImpl<T, S> extends AbstractAnnotatedItem<T, S>
private Class<T> type;
private Annotation[] actualAnnotations;

private AnnotatedItemImpl(Map<Class<? extends Annotation>, Annotation> annotationMap)
private AnnotatedItemImpl(AnnotationMap annotationMap)
{
super(annotationMap);
}

private AnnotatedItemImpl(Map<Class<? extends Annotation>, Annotation> annotationMap, Class<T> type)
private AnnotatedItemImpl(AnnotationMap annotationMap, Class<T> type)
{
super(annotationMap);
this.type = type;
}

private AnnotatedItemImpl(Map<Class<? extends Annotation>, Annotation> annotationMap, TypeLiteral<T> apiType)
private AnnotatedItemImpl(AnnotationMap annotationMap, TypeLiteral<T> apiType)
{
super(annotationMap);
this.type = apiType.getRawType();
Expand All @@ -35,7 +34,7 @@ private AnnotatedItemImpl(Map<Class<? extends Annotation>, Annotation> annotatio
}
}

private AnnotatedItemImpl(Map<Class<? extends Annotation>, Annotation> annotationMap, Class<T> type, Type[] actualTypeArguments)
private AnnotatedItemImpl(AnnotationMap annotationMap, Class<T> type, Type[] actualTypeArguments)
{
this(annotationMap, type);
this.actualTypeArguments = actualTypeArguments;
Expand Down

0 comments on commit e1aebc8

Please sign in to comment.