Skip to content

Commit

Permalink
WBRI-364, and fix annotation literal to support array member values
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@3517 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Aug 16, 2009
1 parent 263ccc3 commit ccda5d4
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 22 deletions.
18 changes: 16 additions & 2 deletions impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
Expand Up @@ -1304,12 +1304,26 @@ public Bean<?> getPassivationCapableBean(String id)

public ScopeType getScopeDefinition(Class<? extends Annotation> scopeType)
{
throw new UnsupportedOperationException("Not yet implemented");
if (isScopeType(scopeType))
{
return getServices().get(MetaAnnotationStore.class).getScopeModel(scopeType).getMetaAnnnotation();
}
else
{
throw new IllegalArgumentException("Not a scope type " + scopeType);
}
}

public Set<Annotation> getStereotypeDefinition(Class<? extends Annotation> stereotype)
{
throw new UnsupportedOperationException("Not yet implemented");
if (getServices().get(MetaAnnotationStore.class).getStereotype(stereotype).isValid())
{
return getServices().get(MetaAnnotationStore.class).getStereotype(stereotype).getMetaAnnotations();
}
else
{
throw new IllegalArgumentException("Not a stereotype " + stereotype);
}
}

public boolean isBindingType(Class<? extends Annotation> annotationType)
Expand Down
7 changes: 1 addition & 6 deletions impl/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
Expand Up @@ -492,12 +492,7 @@ public boolean isSpecializing()

public Set<Class<? extends Annotation>> getStereotypes()
{
Set<Class<? extends Annotation>> stereotypes = new HashSet<Class<? extends Annotation>>();
for (Annotation stereotypeAnnotation : getAnnotatedItem().getMetaAnnotations(Stereotype.class))
{
stereotypes.add(stereotypeAnnotation.annotationType());
}
return stereotypes;
return mergedStereotypes.getStereotypes();
}

}
Expand Up @@ -67,7 +67,7 @@ protected void initType()
{
if (!Annotation.class.isAssignableFrom(getRawType()))
{
throw new DefinitionException(getMetaAnnotation().toString() + " can only be applied to an annotation, it was applied to " + getRawType());
throw new DefinitionException(getMetaAnnotationType().toString() + " can only be applied to an annotation, it was applied to " + getRawType());
}
}

Expand All @@ -77,7 +77,7 @@ protected void initType()
protected void initValid()
{
this.valid = true;
if (!annotatedAnnotation.isAnnotationPresent(getMetaAnnotation()))
if (!annotatedAnnotation.isAnnotationPresent(getMetaAnnotationType()))
{
this.valid = false;
}
Expand All @@ -104,7 +104,7 @@ public Class<T> getRawType()
*
* @return
*/
protected abstract Class<? extends Annotation> getMetaAnnotation();
protected abstract Class<? extends Annotation> getMetaAnnotationType();

/**
* Indicates if the annotation is valid
Expand Down
Expand Up @@ -110,7 +110,7 @@ private void checkArrayAndAnnotationValuedMembers()
* @return The BindingType class
*/
@Override
protected Class<? extends Annotation> getMetaAnnotation()
protected Class<? extends Annotation> getMetaAnnotationType()
{
return BindingType.class;
}
Expand Down
Expand Up @@ -36,6 +36,8 @@ public class MergedStereotypes<T, E>
// Are any of the sterotypes policies
private boolean policy;

private Set<Class<? extends Annotation>> stereotypes;

private final BeanManagerImpl manager;

/**
Expand All @@ -46,6 +48,7 @@ public class MergedStereotypes<T, E>
public MergedStereotypes(Set<Annotation> stereotypeAnnotations, BeanManagerImpl manager)
{
this.possibleScopeTypes = new HashSet<Annotation>();
this.stereotypes = new HashSet<Class<? extends Annotation>>();
this.manager = manager;
merge(stereotypeAnnotations);
}
Expand Down Expand Up @@ -77,6 +80,7 @@ protected void merge(Set<Annotation> stereotypeAnnotations)
{
beanNameDefaulted = true;
}
this.stereotypes.add(stereotypeAnnotation.annotationType());
// Merge in inherited stereotypes
merge(stereotype.getInheritedSterotypes());
}
Expand Down Expand Up @@ -106,15 +110,13 @@ public boolean isBeanNameDefaulted()
{
return beanNameDefaulted;
}

/**
* Indicates if the bean was declared in XML
*
* @return True if declared in XML, else false
* @return the stereotypes
*/
public boolean isDeclaredInXml()
public Set<Class<? extends Annotation>> getStereotypes()
{
return false;
return stereotypes;
}

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

import javax.enterprise.context.ScopeType;

import org.jboss.webbeans.literal.ScopeTypeLiteral;
import org.jboss.webbeans.log.Log;
import org.jboss.webbeans.log.Logging;
import org.jboss.webbeans.resources.ClassTransformer;
Expand All @@ -41,6 +42,10 @@ public class ScopeModel<T extends Annotation> extends AnnotationModel<T>
{
private static final Log log = Logging.getLog(ScopeModel.class);

private final ScopeType metaAnnotation;
private final boolean normal;
private final boolean passivating;

/**
* Constrctor
*
Expand All @@ -49,6 +54,18 @@ public class ScopeModel<T extends Annotation> extends AnnotationModel<T>
public ScopeModel(Class<T> scope, ClassTransformer classTransformer)
{
super(scope, classTransformer);
if (isValid())
{
this.normal = getAnnotatedAnnotation().getAnnotation(ScopeType.class).normal();
this.passivating = getAnnotatedAnnotation().getAnnotation(ScopeType.class).passivating();
this.metaAnnotation = new ScopeTypeLiteral(normal, passivating);
}
else
{
this.normal = false;
this.passivating = false;
this.metaAnnotation = null;
}
}

@Override
Expand All @@ -74,7 +91,7 @@ else if (!Arrays2.unorderedEquals(getAnnotatedAnnotation().getAnnotation(Target.
*/
public boolean isNormal()
{
return getAnnotatedAnnotation().getAnnotation(ScopeType.class).normal();
return normal;
}

/**
Expand All @@ -84,7 +101,7 @@ public boolean isNormal()
*/
public boolean isPassivating()
{
return getAnnotatedAnnotation().getAnnotation(ScopeType.class).passivating();
return passivating;
}

/**
Expand All @@ -93,10 +110,15 @@ public boolean isPassivating()
* @return The ScopeType class
*/
@Override
protected Class<? extends Annotation> getMetaAnnotation()
protected Class<? extends Annotation> getMetaAnnotationType()
{
return ScopeType.class;
}

public ScopeType getMetaAnnnotation()
{
return metaAnnotation;
}

/**
* Gets a string representation of the scope model
Expand Down
Expand Up @@ -58,6 +58,8 @@ public class StereotypeModel<T extends Annotation> extends AnnotationModel<T>
private Set<Annotation> interceptorBindings;

private Set<Annotation> inheritedSterotypes;

private Set<Annotation> metaAnnotations;

/**
* Constructor
Expand All @@ -73,6 +75,7 @@ public StereotypeModel(Class<T> sterotype, ClassTransformer transformer)
initInterceptorBindings();
initInheritedStereotypes();
checkBindings();
this.metaAnnotations = getAnnotatedAnnotation().getAnnotations();
}

/**
Expand Down Expand Up @@ -202,7 +205,7 @@ public boolean isBeanNameDefaulted()
* @return The Stereotype class
*/
@Override
protected Class<? extends Annotation> getMetaAnnotation()
protected Class<? extends Annotation> getMetaAnnotationType()
{
return Stereotype.class;
}
Expand All @@ -219,5 +222,13 @@ public Set<Annotation> getInheritedSterotypes()
{
return inheritedSterotypes;
}

/**
* @return the metaAnnotations
*/
public Set<Annotation> getMetaAnnotations()
{
return metaAnnotations;
}

}

0 comments on commit ccda5d4

Please sign in to comment.