javax.enterprise.inject.Stereotype Java Examples

The following examples show how to use javax.enterprise.inject.Stereotype. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CDIBeanInfo.java    From smallrye-metrics with Apache License 2.0 6 votes vote down vote up
@Override
public <T extends Annotation> AnnotationInfo getAnnotation(Class<T> metric) {
    T annotation = input.getAnnotation(metric);
    if (annotation != null) {
        return new CDIAnnotationInfoAdapter().convert(annotation);
    } else {
        // the metric annotation can also be applied via a stereotype, so look for stereotype annotations
        for (Annotation stereotypeCandidate : ((AnnotatedElement) input).getAnnotations()) {
            if (stereotypeCandidate.annotationType().isAnnotationPresent(Stereotype.class) &&
                    stereotypeCandidate.annotationType().isAnnotationPresent(metric)) {
                return new CDIAnnotationInfoAdapter().convert(stereotypeCandidate.annotationType().getAnnotation(metric));
            }
        }
        return null;
    }
}
 
Example #2
Source File: DefaultViewConfigInheritanceStrategy.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
protected void addViewMetaData(Annotation currentAnnotation, List<Annotation> metaDataList)
{
    Class<? extends Annotation> annotationClass = currentAnnotation.annotationType();

    if (annotationClass.isAnnotationPresent(ViewMetaData.class))
    {
        metaDataList.add(currentAnnotation);
    }

    if (annotationClass.isAnnotationPresent(Stereotype.class))
    {
        for (Annotation inheritedViaStereotype : annotationClass.getAnnotations())
        {
            if (inheritedViaStereotype.annotationType().isAnnotationPresent(ViewMetaData.class))
            {
                metaDataList.add(inheritedViaStereotype);
            }
        }
    }
}
 
Example #3
Source File: CDIBeanInfo.java    From smallrye-metrics with Apache License 2.0 5 votes vote down vote up
@Override
public <T extends Annotation> boolean isAnnotationPresent(Class<T> metric) {
    if (input.isAnnotationPresent(metric)) {
        return true;
    } else {
        // the metric annotation can also be applied via a stereotype, so look for stereotype annotations
        for (Annotation stereotypeCandidate : ((AnnotatedElement) input).getAnnotations()) {
            if (stereotypeCandidate.annotationType().isAnnotationPresent(Stereotype.class) &&
                    stereotypeCandidate.annotationType().isAnnotationPresent(metric)) {
                return true;
            }
        }
        return false;
    }
}
 
Example #4
Source File: MockBean.java    From weld-junit with Apache License 2.0 5 votes vote down vote up
private static Set<Annotation> getStereotypes(AnnotatedElement element) {
    Set<Annotation> stereotypes = new HashSet<>();
    for (Annotation annotation : element.getAnnotations()) {
        if (annotation.annotationType().isAnnotationPresent(Stereotype.class)) {
            stereotypes.add(annotation);
            stereotypes.addAll(getStereotypes(annotation.annotationType()));
        }
    }
    return stereotypes;
}
 
Example #5
Source File: SecurityUtils.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
public static Annotation resolveSecurityBindingType(Annotation annotation)
{
    List<Annotation> result = getAllAnnotations(annotation.annotationType().getAnnotations(),
        new HashSet<Integer>());

    for (Annotation foundAnnotation : result)
    {
        if (foundAnnotation.annotationType().isAnnotationPresent(SecurityBindingType.class))
        {
            return foundAnnotation;
        }
    }
    throw new IllegalStateException(annotation.annotationType().getName() + " is a " + Stereotype.class.getName() +
            " but it isn't annotated with " + SecurityBindingType.class.getName());
}
 
Example #6
Source File: DefaultConfigNodeConverter.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
private List<Annotation> mergeMetaData(Set<Annotation> metaData, List<Annotation> inheritedMetaData)
{
    //TODO add qualifier support
    List<Annotation> nodeViewMetaData = new ArrayList<Annotation>();
    List<Annotation> viewMetaDataFromStereotype = new ArrayList<Annotation>();

    for (Annotation annotation : metaData)
    {
        if (annotation.annotationType().isAnnotationPresent(ViewMetaData.class))
        {
            nodeViewMetaData.add(annotation);
        }

        //TODO move to stereotype-util, improve it and merge it with DefaultViewConfigInheritanceStrategy
        if (annotation.annotationType().isAnnotationPresent(Stereotype.class))
        {
            for (Annotation metaAnnotation : annotation.annotationType().getAnnotations())
            {
                if (metaAnnotation.annotationType().isAnnotationPresent(ViewMetaData.class))
                {
                    viewMetaDataFromStereotype.add(metaAnnotation);
                }
            }
        }
    }

    //merge meta-data of same level
    List<Annotation> result = mergeAnnotationInstances(viewMetaDataFromStereotype, nodeViewMetaData);

    if (inheritedMetaData != null && !inheritedMetaData.isEmpty())
    {
        //merge meta-data with levels above
        result = mergeAnnotationInstances(inheritedMetaData, result);
    }

    return result;
}
 
Example #7
Source File: MethodInfo.java    From smallrye-graphql with Apache License 2.0 4 votes vote down vote up
private static <A extends Annotation> Stream<A> resolveStereotypes(Annotation[] annotations, Class<A> type) {
    return Stream.of(annotations)
            .map(Annotation::annotationType)
            .filter(annotation -> annotation.isAnnotationPresent(Stereotype.class))
            .flatMap(a -> resolveAnnotations(a, type));
}
 
Example #8
Source File: ClassScanning.java    From weld-junit with Apache License 2.0 4 votes vote down vote up
private static boolean hasBeanDefiningAnnotation(Class<?> clazz) {
    return isAnnotated(clazz, NormalScope.class) || isAnnotated(clazz, Dependent.class) ||
            isAnnotated(clazz, Interceptor.class) || isAnnotated(clazz, Decorator.class) ||
            isAnnotated(clazz, Stereotype.class);
}