/** * Creates an observer * * @param method The observer method abstraction * @param declaringBean The declaring bean * @param manager The Bean manager * @return An observer implementation built from the method abstraction */ public static <T, X> ObserverMethodImpl<T, X> create(EnhancedAnnotatedMethod<T, ? super X> method, RIBean<X> declaringBean, BeanManagerImpl manager, boolean isAsync) { if (declaringBean instanceof ExtensionBean) { return new ExtensionObserverMethodImpl<T, X>(method, declaringBean, manager, isAsync); } return new ObserverMethodImpl<T, X>(method, declaringBean, manager, isAsync); }
@Override protected Object getReceiver(CreationalContext<X> ctx) { return getDeclaringBean().create(null); }
private static boolean isUnrestrictedProcessAnnotatedTypeObserver(ObserverMethodImpl<?, ?> observerMethod) { if (observerMethod instanceof ExtensionObserverMethodImpl) { ExtensionObserverMethodImpl<?, ?> extensionObserverMethod = (ExtensionObserverMethodImpl<?, ?>) observerMethod; Class<?> rawObserverType = Reflections.getRawType(extensionObserverMethod.getObservedType()); if ((rawObserverType.equals(ProcessAnnotatedType.class) || rawObserverType.equals(ProcessSyntheticAnnotatedType.class)) && extensionObserverMethod.getRequiredAnnotations().isEmpty()) { Type eventType = extensionObserverMethod.getObservedType(); Type[] typeArguments; if (eventType instanceof ParameterizedType) { typeArguments = ((ParameterizedType) eventType).getActualTypeArguments(); } else { typeArguments = Arrays2.EMPTY_TYPE_ARRAY; } if (typeArguments.length == 0 || Reflections.isUnboundedWildcard(typeArguments[0]) || Reflections.isUnboundedTypeVariable(typeArguments[0])) { return true; } } } return false; }
protected ExtensionObserverMethodImpl(EnhancedAnnotatedMethod<T, ? super X> observer, RIBean<X> declaringBean, BeanManagerImpl manager, boolean isAsync) { super(observer, declaringBean, manager, isAsync); this.containerLifecycleEventDeliveryLock = Container.instance(manager); this.requiredTypeAnnotations = initRequiredTypeAnnotations(observer); }
@Override protected void checkRequiredTypeAnnotations(EnhancedAnnotatedParameter<?, ?> eventParameter) { Class<?> rawObserverType = Reflections.getRawType(getObservedType()); boolean isProcessAnnotatedType = rawObserverType.equals(ProcessAnnotatedType.class) || rawObserverType.equals(ProcessSyntheticAnnotatedType.class); if (!isProcessAnnotatedType && !requiredTypeAnnotations.isEmpty()) { throw EventLogger.LOG .invalidWithAnnotations(this, Formats.formatAsStackTraceElement(eventParameter.getDeclaringEnhancedCallable().getJavaMember())); } if (isProcessAnnotatedType && requiredTypeAnnotations.isEmpty()) { Type[] typeArguments = eventParameter.getActualTypeArguments(); if (typeArguments.length == 0 || Reflections.isUnboundedWildcard(typeArguments[0]) || Reflections.isUnboundedTypeVariable(typeArguments[0])) { EventLogger.LOG.unrestrictedProcessAnnotatedTypes(this); } } }
private boolean checkScopeInheritanceRules(SlimAnnotatedType<?> type, ExtensionObserverMethodImpl<?, ?> observer) { Collection<Class<? extends Annotation>> scopes = observer.getRequiredScopeAnnotations(); if (!scopes.isEmpty() && scopes.size() == observer.getRequiredScopeAnnotations().size()) { // this check only works if only scope annotations are listed within @WithAnnotations // performing a complete check would be way too expensive - eliminating the benefit of ClassFileServices for (Class<? extends Annotation> annotation : scopes) { if (type.isAnnotationPresent(annotation)) { return true; } } return false; } return true; }
protected Set<Class<? extends Annotation>> initRequiredTypeAnnotations(EnhancedAnnotatedMethod<T, ? super X> observer) { EnhancedAnnotatedParameter<?, ? super X> eventParameter = getEventParameter(observer); WithAnnotations annotation = eventParameter.getAnnotation(WithAnnotations.class); if (annotation != null) { return ImmutableSet.<Class<? extends Annotation>>of(annotation.value()); } return Collections.emptySet(); }
private boolean containsRequiredAnnotation(ClassFileInfo classInfo, ExtensionObserverMethodImpl<?, ?> observer) { if (observer.getRequiredAnnotations().isEmpty()) { return true; } for (Class<? extends Annotation> annotation : observer.getRequiredAnnotations()) { if (classInfo.containsAnnotation(annotation)) { return true; } } return false; }
protected ExtensionObserverMethodImpl(EnhancedAnnotatedMethod<T, ? super X> observer, RIBean<X> declaringBean, BeanManagerImpl manager, boolean isAsync) { super(observer, declaringBean, manager, isAsync); this.containerLifecycleEventDeliveryLock = Container.instance(manager); this.requiredTypeAnnotations = initRequiredTypeAnnotations(observer); }
@Override protected void checkRequiredTypeAnnotations(EnhancedAnnotatedParameter<?, ?> eventParameter) { Class<?> rawObserverType = Reflections.getRawType(getObservedType()); boolean isProcessAnnotatedType = rawObserverType.equals(ProcessAnnotatedType.class) || rawObserverType.equals(ProcessSyntheticAnnotatedType.class); if (!isProcessAnnotatedType && !requiredTypeAnnotations.isEmpty()) { throw EventLogger.LOG .invalidWithAnnotations(this, Formats.formatAsStackTraceElement(eventParameter.getDeclaringEnhancedCallable().getJavaMember())); } if (isProcessAnnotatedType && requiredTypeAnnotations.isEmpty()) { Type[] typeArguments = eventParameter.getActualTypeArguments(); if (typeArguments.length == 0 || Reflections.isUnboundedWildcard(typeArguments[0]) || Reflections.isUnboundedTypeVariable(typeArguments[0])) { EventLogger.LOG.unrestrictedProcessAnnotatedTypes(this); } } }
private boolean checkScopeInheritanceRules(SlimAnnotatedType<?> type, ContainerLifecycleEventObserverMethod<?> observer, BeanManagerImpl beanManager) { Collection<Class<? extends Annotation>> scopes; if (observer instanceof ExtensionObserverMethodImpl) { ExtensionObserverMethodImpl<?, ?> extensionObserver = (ExtensionObserverMethodImpl<?, ?>) observer; scopes = extensionObserver.getRequiredScopeAnnotations(); } else { scopes = observer.getRequiredAnnotations().stream().filter((a) -> beanManager.isScope(a)).collect(Collectors.toSet()); } if (!scopes.isEmpty() && scopes.size() == observer.getRequiredAnnotations().size()) { // this check only works if only scope annotations are listed within @WithAnnotations // performing a complete check would be way too expensive - eliminating the benefit of ClassFileServices for (Class<? extends Annotation> annotation : scopes) { if (type.isAnnotationPresent(annotation)) { return true; } } return false; } return true; }
protected Set<Class<? extends Annotation>> initRequiredTypeAnnotations(EnhancedAnnotatedMethod<T, ? super X> observer) { EnhancedAnnotatedParameter<?, ? super X> eventParameter = getEventParameter(observer); WithAnnotations annotation = eventParameter.getAnnotation(WithAnnotations.class); if (annotation != null) { return ImmutableSet.<Class<? extends Annotation>>of(annotation.value()); } return Collections.emptySet(); }
@Override protected boolean matches(Resolvable resolvable, ObserverMethod<?> observer) { if (!rules.matches(observer.getObservedType(), resolvable.getTypes())) { return false; } if (!Beans.containsAllQualifiers(QualifierInstance.of(observer.getObservedQualifiers(), metaAnnotationStore), resolvable.getQualifiers())) { return false; } if (observer instanceof ExtensionObserverMethodImpl<?, ?>) { ExtensionObserverMethodImpl<?, ?> extensionObserver = (ExtensionObserverMethodImpl<?, ?>) observer; if (resolvable instanceof ProcessAnnotatedTypeEventResolvable && !extensionObserver.getRequiredAnnotations().isEmpty()) { // this is a ProcessAnnotatedType observer method with @WithAnnotations and a resolvable for ProcessAnnotatedType ProcessAnnotatedTypeEventResolvable patResolvable = (ProcessAnnotatedTypeEventResolvable) resolvable; return patResolvable.containsRequiredAnnotations(extensionObserver.getRequiredAnnotations()); } } else { return !isContainerLifecycleEvent(resolvable); // container lifecycle events are only delivered to extensions } return true; }
protected ExtensionObserverMethodImpl(EnhancedAnnotatedMethod<T, ? super X> observer, RIBean<X> declaringBean, BeanManagerImpl manager, boolean isAsync) { super(observer, declaringBean, manager, isAsync); this.containerLifecycleEventDeliveryLock = Container.instance(manager); this.requiredTypeAnnotations = initRequiredTypeAnnotations(observer); }
@Override protected Object getReceiver(CreationalContext<X> ctx) { return getDeclaringBean().create(null); }
/** * Creates an observer * * @param method The observer method abstraction * @param declaringBean The declaring bean * @param manager The Bean manager * @return An observer implementation built from the method abstraction */ public static <T, X> ObserverMethodImpl<T, X> create(EnhancedAnnotatedMethod<T, ? super X> method, RIBean<X> declaringBean, BeanManagerImpl manager, boolean isAsync) { if (declaringBean instanceof ExtensionBean) { return new ExtensionObserverMethodImpl<T, X>(method, declaringBean, manager, isAsync); } return new ObserverMethodImpl<T, X>(method, declaringBean, manager, isAsync); }
@Override protected void checkRequiredTypeAnnotations(EnhancedAnnotatedParameter<?, ?> eventParameter) { Class<?> rawObserverType = Reflections.getRawType(getObservedType()); boolean isProcessAnnotatedType = rawObserverType.equals(ProcessAnnotatedType.class) || rawObserverType.equals(ProcessSyntheticAnnotatedType.class); if (!isProcessAnnotatedType && !requiredTypeAnnotations.isEmpty()) { throw EventLogger.LOG .invalidWithAnnotations(this, Formats.formatAsStackTraceElement(eventParameter.getDeclaringEnhancedCallable().getJavaMember())); } if (isProcessAnnotatedType && requiredTypeAnnotations.isEmpty()) { Type[] typeArguments = eventParameter.getActualTypeArguments(); if (typeArguments.length == 0 || Reflections.isUnboundedWildcard(typeArguments[0]) || Reflections.isUnboundedTypeVariable(typeArguments[0])) { EventLogger.LOG.unrestrictedProcessAnnotatedTypes(this); } } }
private boolean checkScopeInheritanceRules(SlimAnnotatedType<?> type, ContainerLifecycleEventObserverMethod<?> observer, BeanManagerImpl beanManager) { Collection<Class<? extends Annotation>> scopes; if (observer instanceof ExtensionObserverMethodImpl) { ExtensionObserverMethodImpl<?, ?> extensionObserver = (ExtensionObserverMethodImpl<?, ?>) observer; scopes = extensionObserver.getRequiredScopeAnnotations(); } else { scopes = observer.getRequiredAnnotations().stream().filter((a) -> beanManager.isScope(a)).collect(Collectors.toSet()); } if (!scopes.isEmpty() && scopes.size() == observer.getRequiredAnnotations().size()) { // this check only works if only scope annotations are listed within @WithAnnotations // performing a complete check would be way too expensive - eliminating the benefit of ClassFileServices for (Class<? extends Annotation> annotation : scopes) { if (type.isAnnotationPresent(annotation)) { return true; } } return false; } return true; }
protected Set<Class<? extends Annotation>> initRequiredTypeAnnotations(EnhancedAnnotatedMethod<T, ? super X> observer) { EnhancedAnnotatedParameter<?, ? super X> eventParameter = getEventParameter(observer); WithAnnotations annotation = eventParameter.getAnnotation(WithAnnotations.class); if (annotation != null) { return ImmutableSet.<Class<? extends Annotation>>of(annotation.value()); } return Collections.emptySet(); }
protected ExtensionObserverMethodImpl(EnhancedAnnotatedMethod<T, ? super X> observer, RIBean<X> declaringBean, BeanManagerImpl manager) { super(observer, declaringBean, manager); this.containerLifecycleEventDeliveryLock = Container.instance(manager); this.requiredTypeAnnotations = initRequiredTypeAnnotations(observer); }