Annotation[] annotations = proxyType.getDeclaredAnnotations(); for(Annotation annotation : annotations) { if(beanManager.isScope(annotation.annotationType())) { possibleScopes.add(annotation);
protected Class< ? extends ScopedAssociation> getBroadestActiveContext() { for (Class< ? extends ScopedAssociation> scopeType : getAvailableScopedAssociationClasses()) { Annotation scopeAnnotation = scopeType.getAnnotations().length > 0 ? scopeType.getAnnotations()[0] : null; if (scopeAnnotation == null || !beanManager.isScope(scopeAnnotation.annotationType())) { throw new ProcessEngineException("ScopedAssociation must carry exactly one annotation and it must be a @Scope annotation"); } try { beanManager.getContext(scopeAnnotation.annotationType()); return scopeType; } catch (ContextNotActiveException e) { log.finest("Context " + scopeAnnotation.annotationType() + " not active."); } } throw new ProcessEngineException("Could not determine an active context to associate the current process instance / task instance with."); }
/** * 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; }
protected boolean isBeanDefiningAnnotation(Annotation annotation) { Class<? extends Annotation> annotationType = annotation.annotationType(); boolean isBeanAnnotation = beanManager.isScope(annotationType); isBeanAnnotation = isBeanAnnotation || beanManager.isStereotype(annotationType); return isBeanAnnotation; }
@Override public boolean isScope(Class<? extends Annotation> annotationType) { return delegate().isScope(annotationType); }
@Override public boolean isScope(Class<? extends Annotation> annotationType) { return delegate().isScope(annotationType); }
@Override public boolean isScope(Class<? extends Annotation> annotationType) { return delegate().isScope(annotationType); }
@Override public boolean isScope(Class<? extends Annotation> annotationType) { return delegate().isScope(annotationType); }
@Override public boolean isScope(Class<? extends Annotation> annotationType) { return delegate().isScope(annotationType); }
@Test @SpecAssertion(section = BM_DETERMINING_ANNOTATION, id = "ab") public void testDetermineScope() { assertTrue(getCurrentManager().isScope(ApplicationScoped.class)); assertTrue(getCurrentManager().isScope(DummyScoped.class)); assertFalse(getCurrentManager().isScope(Tame.class)); assertFalse(getCurrentManager().isScope(AnimalStereotype.class)); assertFalse(getCurrentManager().isScope(Transactional.class)); }
@Test(groups="rewrite") // Should also check a custom scope @SpecAssertion(section = "11.3.13", id = "ab") public void testDetermineScopeType() { assert getCurrentManager().isScope(ApplicationScoped.class); assert !getCurrentManager().isScope(Tame.class); assert !getCurrentManager().isScope(AnimalStereotype.class); assert !getCurrentManager().isScope(Transactional.class); }
<T> void rewriteTestClassScope(@Observes ProcessAnnotatedType<T> pat, BeanManager beanManager) { AnnotatedType<T> annotatedType = pat.getAnnotatedType(); if (annotatedType.getJavaClass().equals(testClass)) { // Replace any test class's scope with @Singleton Set<Annotation> annotations = annotatedType.getAnnotations().stream() .filter(annotation -> beanManager.isScope(annotation.annotationType())) .collect(Collectors.toSet()); annotations.add(SINGLETON_LITERAL); pat.setAnnotatedType(new AnnotationRewritingAnnotatedType<>(annotatedType, annotations)); } }
<T> void rewriteTestClassScope(@Observes ProcessAnnotatedType<T> pat, BeanManager beanManager) { AnnotatedType<T> annotatedType = pat.getAnnotatedType(); if (annotatedType.getJavaClass().equals(testClass)) { // Replace any test class's scope with @Singleton Set<Annotation> annotations = annotatedType.getAnnotations().stream() .filter(annotation -> beanManager.isScope(annotation.annotationType())) .collect(Collectors.toSet()); annotations.add(SINGLETON_LITERAL); pat.setAnnotatedType(new AnnotationRewritingAnnotatedType<>(annotatedType, annotations)); } }
public static void validateScope(BeanAttributes<?> attributes, BeanManager manager) { if(attributes.getScope() == null) { throw MetadataLogger.LOG.scopeNull(attributes); } if (!manager.isScope(attributes.getScope())) { throw MetadataLogger.LOG.notAScope(attributes.getScope(), attributes); } }
public static void validateScope(BeanAttributes<?> attributes, BeanManager manager) { if(attributes.getScope() == null) { throw MetadataLogger.LOG.scopeNull(attributes); } if (!manager.isScope(attributes.getScope())) { throw MetadataLogger.LOG.notAScope(attributes.getScope(), attributes); } }
public static void validateScope(BeanAttributes<?> attributes, BeanManager manager) { if(attributes.getScope() == null) { throw MetadataLogger.LOG.scopeNull(attributes); } if (!manager.isScope(attributes.getScope())) { throw MetadataLogger.LOG.notAScope(attributes.getScope(), attributes); } }
public static void validateScope(BeanAttributes<?> attributes, BeanManager manager) { if(attributes.getScope() == null) { throw MetadataLogger.LOG.scopeNull(attributes); } if (!manager.isScope(attributes.getScope())) { throw MetadataLogger.LOG.notAScope(attributes.getScope(), attributes); } }
public static void validateScope(BeanAttributes<?> attributes, BeanManager manager) { if(attributes.getScope() == null) { throw MetadataLogger.LOG.scopeNull(attributes); } if (!manager.isScope(attributes.getScope())) { throw MetadataLogger.LOG.notAScope(attributes.getScope(), attributes); } }
public static void validateScope(BeanAttributes<?> attributes, BeanManager manager) { if(attributes.getScope() == null) { throw MetadataLogger.LOG.scopeNull(attributes); } if (!manager.isScope(attributes.getScope())) { throw MetadataLogger.LOG.notAScope(attributes.getScope(), attributes); } }