Skip to content

Commit

Permalink
A bit more clean up
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@2302 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Apr 5, 2009
1 parent 69a9961 commit 53bb958
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 120 deletions.
6 changes: 3 additions & 3 deletions impl/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
Expand Up @@ -22,6 +22,7 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Named;
Expand All @@ -42,7 +43,6 @@
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedParameter;
import org.jboss.webbeans.introspector.AnnotationStore.AnnotationMap;
import org.jboss.webbeans.literal.CurrentLiteral;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
Expand Down Expand Up @@ -79,7 +79,7 @@ public abstract class AbstractBean<T, E> extends RIBean<T>
* @param possibleDeploymentTypes The possible deployment types
* @return The deployment type
*/
public static Class<? extends Annotation> getDeploymentType(List<Class<? extends Annotation>> enabledDeploymentTypes, AnnotationMap possibleDeploymentTypes)
public static Class<? extends Annotation> getDeploymentType(List<Class<? extends Annotation>> enabledDeploymentTypes, Map<Class<? extends Annotation>, Annotation> possibleDeploymentTypes)
{
for (int i = (enabledDeploymentTypes.size() - 1); i > 0; i--)
{
Expand Down Expand Up @@ -199,7 +199,7 @@ protected void initDefaultBindings()

protected void initDeploymentTypeFromStereotype()
{
AnnotationMap possibleDeploymentTypes = getMergedStereotypes().getPossibleDeploymentTypes();
Map<Class<? extends Annotation>, Annotation> possibleDeploymentTypes = getMergedStereotypes().getPossibleDeploymentTypes();
if (possibleDeploymentTypes.size() > 0)
{
this.deploymentType = getDeploymentType(manager.getEnabledDeploymentTypes(), possibleDeploymentTypes);
Expand Down
130 changes: 17 additions & 113 deletions impl/src/main/java/org/jboss/webbeans/introspector/AnnotationStore.java
Expand Up @@ -14,8 +14,8 @@
import javax.inject.BindingType;

import org.jboss.webbeans.literal.CurrentLiteral;
import org.jboss.webbeans.util.Strings;
import org.jboss.webbeans.util.collections.ForwardingMap;
import org.jboss.webbeans.util.collections.multi.SetHashMultiMap;
import org.jboss.webbeans.util.collections.multi.SetMultiMap;

public class AnnotationStore
{
Expand All @@ -26,112 +26,16 @@ public class AnnotationStore
private static final Set<Annotation> DEFAULT_BINDING = new HashSet<Annotation>(Arrays.asList(DEFAULT_BINDING_ARRAY));

private static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0];

/**
* Represents a mapping from a annotation type to an annotation
* implementation
*/
public static class AnnotationMap extends ForwardingMap<Class<? extends Annotation>, Annotation>
{
private final 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;
}

/**
* Gets a string representation of the map
*
* @return A string representation
*/
@Override
public String toString()
{
return Strings.mapToString("AnnotationMap (annotation type -> annotation): ", delegate);
}

}

/**
* Represents a mapping from a annotation (meta-annotation) to a set of
* annotations
*
*/
private static class MetaAnnotationMap extends ForwardingMap<Class<? extends Annotation>, Set<Annotation>>
{
private final 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;
}

/**
* Gets the set of annotations matching the given annotation type
*
* @param key The meta-annotation to match
* @returns The set of matching annotations containing this
* meta-annotation
*/
@Override
public Set<Annotation> get(Object key)
{
Set<Annotation> annotations = super.get(key);
return annotations != null ? annotations : new HashSet<Annotation>();
}

/**
* Adds an annotation under the meta-annotation type key
*
* @param key The meta-annotation type
* @param value The annotation
*/
public void put(Class<? extends Annotation> key, Annotation value)
{
Set<Annotation> annotations = super.get(key);
if (annotations == null)
{
annotations = new HashSet<Annotation>();
super.put(key, annotations);
}
annotations.add(value);
}

/**
* Gets a string representation of the map
*
* @return A string representation
*/
@Override
public String toString()
{
return Strings.mapToString("MetaAnnotationMap (annotation type -> annotation set: ", delegate);
}

}

/**
* Builds the annotation map (annotation type -> annotation)
*
* @param annotations The array of annotations to map
* @return The annotation map
*/
protected static AnnotationMap buildAnnotationMap(Annotation[] annotations)
protected static Map<Class<? extends Annotation>, Annotation> buildAnnotationMap(Annotation[] annotations)
{
AnnotationMap annotationMap = new AnnotationMap();
Map<Class<? extends Annotation>, Annotation> annotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
for (Annotation annotation : annotations)
{
annotationMap.put(annotation.annotationType(), annotation);
Expand All @@ -145,9 +49,9 @@ protected static AnnotationMap buildAnnotationMap(Annotation[] annotations)
* @param annotations The array of annotations to map
* @return The annotation map
*/
protected static AnnotationMap buildAnnotationMap(Iterable<Annotation> annotations)
protected static Map<Class<? extends Annotation>, Annotation> buildAnnotationMap(Iterable<Annotation> annotations)
{
AnnotationMap annotationMap = new AnnotationMap();
Map<Class<? extends Annotation>, Annotation> annotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
for (Annotation annotation : annotations)
{
annotationMap.put(annotation.annotationType(), annotation);
Expand All @@ -173,30 +77,30 @@ public static AnnotationStore of(Annotation[] annotations, Annotation[] declared

public static AnnotationStore wrap(AnnotationStore annotationStore, Set<Annotation> annotations, Set<Annotation> declaredAnnotations)
{
AnnotationMap annotationMap = new AnnotationMap();
Map<Class<? extends Annotation>, Annotation> annotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
annotationMap.putAll(buildAnnotationMap(annotations));
annotationMap.putAll(annotationStore.getAnnotationMap());

AnnotationMap declaredAnnotationMap = new AnnotationMap();
Map<Class<? extends Annotation>, Annotation> declaredAnnotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
declaredAnnotationMap.putAll(buildAnnotationMap(declaredAnnotations));
declaredAnnotationMap.putAll(annotationStore.getDeclaredAnnotationMap());

return new AnnotationStore(annotationMap, declaredAnnotationMap);
}

// The annotation map (annotation type -> annotation) of the item
private final AnnotationMap annotationMap;
private final Map<Class<? extends Annotation>, Annotation> annotationMap;
// The meta-annotation map (annotation type -> set of annotations containing
// meta-annotation) of the item
private final MetaAnnotationMap metaAnnotationMap;
private final SetMultiMap<Class<? extends Annotation>, Annotation> metaAnnotationMap;
// The set of all annotations on the item
private final Set<Annotation> annotationSet;

// The annotation map (annotation type -> annotation) of the item
private final AnnotationMap declaredAnnotationMap;
private final Map<Class<? extends Annotation>, Annotation> declaredAnnotationMap;
// The meta-annotation map (annotation type -> set of annotations containing
// meta-annotation) of the item
private final MetaAnnotationMap declaredMetaAnnotationMap;
private final SetMultiMap<Class<? extends Annotation>, Annotation> declaredMetaAnnotationMap;
// The set of all annotations on the item
private final Set<Annotation> declaredAnnotationSet;

Expand All @@ -209,15 +113,15 @@ public static AnnotationStore wrap(AnnotationStore annotationStore, Set<Annotati
* @param annotationMap A map of annotation to register
*
*/
protected AnnotationStore(AnnotationMap annotationMap, AnnotationMap declaredAnnotationMap)
protected AnnotationStore(Map<Class<? extends Annotation>, Annotation> annotationMap, Map<Class<? extends Annotation>, Annotation> declaredAnnotationMap)
{
if (annotationMap == null)
{
throw new NullPointerException("annotationMap cannot be null");
}
this.annotationMap = annotationMap;
this.annotationSet = new HashSet<Annotation>();
this.metaAnnotationMap = new MetaAnnotationMap();
this.metaAnnotationMap = new SetHashMultiMap<Class<? extends Annotation>, Annotation>();
for (Annotation annotation : annotationMap.values())
{
for (Annotation metaAnnotation : annotation.annotationType().getAnnotations())
Expand All @@ -237,7 +141,7 @@ protected AnnotationStore(AnnotationMap annotationMap, AnnotationMap declaredAnn
}
this.declaredAnnotationMap = declaredAnnotationMap;
this.declaredAnnotationSet = new HashSet<Annotation>();
this.declaredMetaAnnotationMap = new MetaAnnotationMap();
this.declaredMetaAnnotationMap = new SetHashMultiMap<Class<? extends Annotation>, Annotation>();
for (Annotation annotation : declaredAnnotationMap.values())
{
for (Annotation metaAnnotation : annotation.annotationType().getAnnotations())
Expand Down Expand Up @@ -306,12 +210,12 @@ public boolean isDeclaredAnnotationPresent(Class<? extends Annotation> annotatio
return declaredAnnotationMap.containsKey(annotationType);
}

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

AnnotationMap getDeclaredAnnotationMap()
Map<Class<? extends Annotation>, Annotation> getDeclaredAnnotationMap()
{
return declaredAnnotationMap;
}
Expand Down
Expand Up @@ -18,11 +18,12 @@
package org.jboss.webbeans.metadata;

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

import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.introspector.AnnotationStore.AnnotationMap;

/**
* Meta model for the merged stereotype for a bean
Expand All @@ -32,7 +33,7 @@
public class MergedStereotypes<T, E>
{
// The possible deployment types
private final AnnotationMap possibleDeploymentTypes;
private final Map<Class<? extends Annotation>, Annotation> possibleDeploymentTypes;
// The possible scope types
private final Set<Annotation> possibleScopeTypes;
// Is the bean name defaulted?
Expand All @@ -51,7 +52,7 @@ public class MergedStereotypes<T, E>
*/
public MergedStereotypes(Set<Annotation> stereotypeAnnotations, ManagerImpl manager)
{
this.possibleDeploymentTypes = new AnnotationMap();
this.possibleDeploymentTypes = new HashMap<Class<? extends Annotation>, Annotation>();
this.possibleScopeTypes = new HashSet<Annotation>();
this.requiredTypes = new HashSet<Class<?>>();
this.supportedScopes = new HashSet<Class<? extends Annotation>>();
Expand Down Expand Up @@ -96,7 +97,7 @@ protected void merge(Set<Annotation> stereotypeAnnotations)
*
* @return The deployment types
*/
public AnnotationMap getPossibleDeploymentTypes()
public Map<Class<? extends Annotation>, Annotation> getPossibleDeploymentTypes()
{
return possibleDeploymentTypes;
}
Expand Down

0 comments on commit 53bb958

Please sign in to comment.