/** * Find out if a given class is explicitly bound to a scope. * * @param clazz class * @param manager bean manager * @return <code>true</code> if a given class is annotated with a scope * annotation or with a stereotype which (transitively) declares a * scope */ private static boolean isScopeDefined(Class<?> clazz, BeanManager manager) { for (Annotation annotation : clazz.getAnnotations()) { if (manager.isScope(annotation.annotationType())) { return true; } if (manager.isStereotype(annotation.annotationType())) { if (isScopeDefined(annotation.annotationType(), manager)) { return true; } } } return false; } }
/** * Find out if a given annotated type is explicitly bound to a scope. * * @param annotatedType annotated type * @param manager bean manager * @return true if and only if a given annotated type is annotated with a scope * annotation or with a stereotype which (transitively) declares a * scope */ public static boolean isScopeDefined(AnnotatedType<?> annotatedType, BeanManager manager) { for (Annotation annotation : annotatedType.getAnnotations()) { if (manager.isScope(annotation.annotationType())) { return true; } if (manager.isStereotype(annotation.annotationType())) { if (isScopeDefined(annotation.annotationType(), manager)) { return true; } } } return false; }
@Override public boolean isStereotype(Class<? extends Annotation> annotationType) { return delegate().isStereotype(annotationType); }
private static boolean isAnnotationPresentOnStereotype(Collection<Annotation> annotations, Class<? extends Annotation> annotationType, BeanManager beanManager) { for (Annotation candidate : annotations) { if (beanManager.isStereotype(candidate.annotationType())) { for (Annotation stereotyped : beanManager.getStereotypeDefinition(candidate.annotationType())) { if (stereotyped.annotationType().equals(annotationType)) { return true; } } } } return false; }
protected boolean isBeanDefiningAnnotation(Annotation annotation) { Class<? extends Annotation> annotationType = annotation.annotationType(); boolean isBeanAnnotation = beanManager.isScope(annotationType); isBeanAnnotation = isBeanAnnotation || beanManager.isStereotype(annotationType); return isBeanAnnotation; }
private static boolean isAnnotationPresentOnStereotype(Collection<Annotation> annotations, Class<? extends Annotation> annotationType, BeanManager beanManager) { for (Annotation candidate : annotations) { if (beanManager.isStereotype(candidate.annotationType())) { for (Annotation stereotyped : beanManager.getStereotypeDefinition(candidate.annotationType())) { if (stereotyped.annotationType().equals(annotationType)) { return true; } } } } return false; }
@Override public boolean isStereotype(Class<? extends Annotation> annotationType) { return delegate().isStereotype(annotationType); }
@Override public boolean isStereotype(Class<? extends Annotation> annotationType) { return delegate().isStereotype(annotationType); }
@Override public boolean isStereotype(Class<? extends Annotation> annotationType) { return delegate().isStereotype(annotationType); }
private static <A extends Annotation> A getAnnotationFromStereotype(Collection<Annotation> annotations, Class<A> annotationType, BeanManager beanManager) { for (Annotation candidate : annotations) { if (beanManager.isStereotype(candidate.annotationType())) { for (Annotation stereotyped : beanManager.getStereotypeDefinition(candidate.annotationType())) { if (stereotyped.annotationType().equals(annotationType)) { return annotationType.cast(stereotyped); } } } } return null; } }
@Override public boolean isStereotype(Class<? extends Annotation> annotationType) { return delegate().isStereotype(annotationType); }
private static <A extends Annotation> A getAnnotationFromStereotype(Collection<Annotation> annotations, Class<A> annotationType, BeanManager beanManager) { for (Annotation candidate : annotations) { if (beanManager.isStereotype(candidate.annotationType())) { for (Annotation stereotyped : beanManager.getStereotypeDefinition(candidate.annotationType())) { if (stereotyped.annotationType().equals(annotationType)) { return annotationType.cast(stereotyped); } } } } return null; } }
@Test @SpecAssertion(section = BM_DETERMINING_ANNOTATION, id = "ac") public void testDetermineStereotype() { assertTrue(getCurrentManager().isStereotype(AnimalStereotype.class)); assertFalse(getCurrentManager().isStereotype(Tame.class)); assertFalse(getCurrentManager().isStereotype(ApplicationScoped.class)); assertFalse(getCurrentManager().isStereotype(Transactional.class)); }
@Test(groups="rewrite") @SpecAssertion(section = "11.3.13", id = "ac") // Should also check a custom stereotype public void testDetermineStereotype() { assert getCurrentManager().isStereotype(AnimalStereotype.class); assert !getCurrentManager().isStereotype(Tame.class); assert !getCurrentManager().isStereotype(ApplicationScoped.class); assert !getCurrentManager().isStereotype(Transactional.class); }
public static void validateStereotypes(BeanAttributes<?> attributes, BeanManager manager) { if(attributes.getStereotypes() == null) { throw MetadataLogger.LOG.stereotypesNull(attributes); } for (Class<? extends Annotation> annotation : attributes.getStereotypes()) { if (!manager.isStereotype(annotation)) { throw MetadataLogger.LOG.notAStereotype(annotation, attributes); } } }
public static void validateStereotypes(BeanAttributes<?> attributes, BeanManager manager) { if(attributes.getStereotypes() == null) { throw MetadataLogger.LOG.stereotypesNull(attributes); } for (Class<? extends Annotation> annotation : attributes.getStereotypes()) { if (!manager.isStereotype(annotation)) { throw MetadataLogger.LOG.notAStereotype(annotation, attributes); } } }
public static void validateStereotypes(BeanAttributes<?> attributes, BeanManager manager) { if(attributes.getStereotypes() == null) { throw MetadataLogger.LOG.stereotypesNull(attributes); } for (Class<? extends Annotation> annotation : attributes.getStereotypes()) { if (!manager.isStereotype(annotation)) { throw MetadataLogger.LOG.notAStereotype(annotation, attributes); } } }
public static void validateStereotypes(BeanAttributes<?> attributes, BeanManager manager) { if(attributes.getStereotypes() == null) { throw MetadataLogger.LOG.stereotypesNull(attributes); } for (Class<? extends Annotation> annotation : attributes.getStereotypes()) { if (!manager.isStereotype(annotation)) { throw MetadataLogger.LOG.notAStereotype(annotation, attributes); } } }
public static void validateStereotypes(BeanAttributes<?> attributes, BeanManager manager) { if(attributes.getStereotypes() == null) { throw MetadataLogger.LOG.stereotypesNull(attributes); } for (Class<? extends Annotation> annotation : attributes.getStereotypes()) { if (!manager.isStereotype(annotation)) { throw MetadataLogger.LOG.notAStereotype(annotation, attributes); } } }
public static void validateStereotypes(BeanAttributes<?> attributes, BeanManager manager) { if(attributes.getStereotypes() == null) { throw MetadataLogger.LOG.stereotypesNull(attributes); } for (Class<? extends Annotation> annotation : attributes.getStereotypes()) { if (!manager.isStereotype(annotation)) { throw MetadataLogger.LOG.notAStereotype(annotation, attributes); } } }