use of org.jboss.weld.metadata.cache.MetaAnnotationStore in project core by weld.
the class Interceptors method flattenInterceptorBindings.
/**
* Extracts a flat set of interception bindings from a given set of interceptor bindings.
*
* @param addTopLevelInterceptorBindings add top level interceptor bindings to the result set.
* @param addInheritedInterceptorBindings add inherited level interceptor bindings to the result set.
* @return
*/
public static Set<Annotation> flattenInterceptorBindings(EnhancedAnnotatedType<?> clazz, BeanManagerImpl beanManager, Collection<Annotation> annotations, boolean addTopLevelInterceptorBindings, boolean addInheritedInterceptorBindings) {
Set<Annotation> flattenInterceptorBindings = new InterceptorBindingSet(beanManager);
MetaAnnotationStore metaAnnotationStore = beanManager.getServices().get(MetaAnnotationStore.class);
if (addTopLevelInterceptorBindings) {
addInterceptorBindings(clazz, annotations, flattenInterceptorBindings, metaAnnotationStore);
}
if (addInheritedInterceptorBindings) {
for (Annotation annotation : annotations) {
addInheritedInterceptorBindings(clazz, annotation.annotationType(), metaAnnotationStore, flattenInterceptorBindings);
}
}
return flattenInterceptorBindings;
}
use of org.jboss.weld.metadata.cache.MetaAnnotationStore in project core by weld.
the class InterceptorBindingSet method contains.
public boolean contains(Object o) {
if (o instanceof Annotation) {
Annotation annotation = (Annotation) o;
MetaAnnotationStore metaAnnotationStore = beanManager.getServices().get(MetaAnnotationStore.class);
InterceptorBindingModel<? extends Annotation> interceptorBindingModel = metaAnnotationStore.getInterceptorBindingModel(annotation.annotationType());
for (Annotation containedAnnotation : set) {
if (interceptorBindingModel.isEqual(annotation, containedAnnotation)) {
return true;
}
}
return false;
} else {
return super.contains(o);
}
}
use of org.jboss.weld.metadata.cache.MetaAnnotationStore in project core by weld.
the class Beans method mergeInQualifiers.
public static Set<Annotation> mergeInQualifiers(BeanManagerImpl manager, Collection<Annotation> qualifiers, Annotation[] newQualifiers) {
Set<Annotation> result = new HashSet<Annotation>();
if (qualifiers != null && !(qualifiers.isEmpty())) {
result.addAll(qualifiers);
}
if (newQualifiers != null && newQualifiers.length > 0) {
final MetaAnnotationStore store = manager.getServices().get(MetaAnnotationStore.class);
Set<Annotation> checkedNewQualifiers = new HashSet<Annotation>();
for (Annotation qualifier : newQualifiers) {
if (!store.getBindingTypeModel(qualifier.annotationType()).isValid()) {
throw UtilLogger.LOG.annotationNotQualifier(qualifier);
}
Class<? extends Annotation> annotationType = qualifier.annotationType();
if (!annotationType.isAnnotationPresent(Repeatable.class)) {
for (Annotation annotation : checkedNewQualifiers) {
if (annotationType.equals(annotation.annotationType())) {
throw UtilLogger.LOG.redundantQualifier(qualifier, Arrays.toString(newQualifiers));
}
}
}
checkedNewQualifiers.add(qualifier);
}
result.addAll(checkedNewQualifiers);
}
return result;
}
use of org.jboss.weld.metadata.cache.MetaAnnotationStore in project core by weld.
the class Interceptors method mergeBeanInterceptorBindings.
/**
* Merge class-level interceptor bindings with interceptor bindings inherited from interceptor bindings and stereotypes.
*/
public static Multimap<Class<? extends Annotation>, Annotation> mergeBeanInterceptorBindings(BeanManagerImpl beanManager, AnnotatedType<?> clazz, Collection<Annotation> classBindingAnnotations, Collection<Annotation> inheritedBindingAnnotations) {
SetMultimap<Class<? extends Annotation>, Annotation> mergedBeanBindings = SetMultimap.newSetMultimap();
SetMultimap<Class<? extends Annotation>, Annotation> acceptedInheritedBindings = SetMultimap.newSetMultimap();
MetaAnnotationStore metaAnnotationStore = beanManager.getServices().get(MetaAnnotationStore.class);
// add all class-level interceptor bindings (these have precedence)
for (Annotation binding : classBindingAnnotations) {
Class<? extends Annotation> annotationType = binding.annotationType();
if (!annotationType.isAnnotationPresent(Repeatable.class)) {
// Detec conflicts for non repeating bindings
for (Annotation mergedBinding : mergedBeanBindings.get(annotationType)) {
if (!metaAnnotationStore.getInterceptorBindingModel(annotationType).isEqual(binding, mergedBinding, false)) {
throw new DeploymentException(BeanLogger.LOG.conflictingInterceptorBindings(clazz.getJavaClass()));
}
}
}
mergedBeanBindings.put(binding.annotationType(), binding);
}
// add inherited interceptor bindings
for (Annotation binding : inheritedBindingAnnotations) {
Class<? extends Annotation> annotationType = binding.annotationType();
if (!mergedBeanBindings.containsKey(annotationType) || annotationType.isAnnotationPresent(Repeatable.class)) {
mergedBeanBindings.put(annotationType, binding);
acceptedInheritedBindings.put(annotationType, binding);
} else {
Set<Annotation> inheritedBindings = acceptedInheritedBindings.get(annotationType);
for (Annotation inheritedBinding : inheritedBindings) {
if (!metaAnnotationStore.getInterceptorBindingModel(annotationType).isEqual(binding, inheritedBinding, false)) {
throw new DeploymentException(BeanLogger.LOG.conflictingInterceptorBindings(clazz.getJavaClass()));
}
}
}
}
return mergedBeanBindings;
}
use of org.jboss.weld.metadata.cache.MetaAnnotationStore in project core by weld.
the class BeanAttributesConfiguratorImpl method initScope.
private Class<? extends Annotation> initScope() {
if (scope != null) {
return scope;
}
if (!stereotypes.isEmpty()) {
MetaAnnotationStore metaAnnotationStore = beanManager.getServices().get(MetaAnnotationStore.class);
Set<Annotation> possibleScopeTypes = new HashSet<>();
for (Class<? extends Annotation> stereotype : stereotypes) {
StereotypeModel<? extends Annotation> model = metaAnnotationStore.getStereotype(stereotype);
if (model.isValid()) {
possibleScopeTypes.add(model.getDefaultScopeType());
} else {
throw BeanManagerLogger.LOG.notStereotype(stereotype);
}
}
if (possibleScopeTypes.size() == 1) {
return possibleScopeTypes.iterator().next().annotationType();
} else {
throw BeanLogger.LOG.multipleScopesFoundFromStereotypes(BeanAttributesConfigurator.class.getSimpleName(), Formats.formatTypes(stereotypes, false), possibleScopeTypes, "");
}
}
return Dependent.class;
}
Aggregations