Search in sources :

Example 1 with MetaAnnotationStore

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;
}
Also used : MetaAnnotationStore(org.jboss.weld.metadata.cache.MetaAnnotationStore) Annotation(java.lang.annotation.Annotation)

Example 2 with MetaAnnotationStore

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);
    }
}
Also used : MetaAnnotationStore(org.jboss.weld.metadata.cache.MetaAnnotationStore) Annotation(java.lang.annotation.Annotation)

Example 3 with MetaAnnotationStore

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;
}
Also used : Repeatable(java.lang.annotation.Repeatable) MetaAnnotationStore(org.jboss.weld.metadata.cache.MetaAnnotationStore) Annotation(java.lang.annotation.Annotation) HashSet(java.util.HashSet)

Example 4 with MetaAnnotationStore

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;
}
Also used : Repeatable(java.lang.annotation.Repeatable) MetaAnnotationStore(org.jboss.weld.metadata.cache.MetaAnnotationStore) DeploymentException(org.jboss.weld.exceptions.DeploymentException) Annotation(java.lang.annotation.Annotation)

Example 5 with MetaAnnotationStore

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;
}
Also used : BeanAttributesConfigurator(javax.enterprise.inject.spi.configurator.BeanAttributesConfigurator) MetaAnnotationStore(org.jboss.weld.metadata.cache.MetaAnnotationStore) Dependent(javax.enterprise.context.Dependent) Annotation(java.lang.annotation.Annotation) HashSet(java.util.HashSet)

Aggregations

MetaAnnotationStore (org.jboss.weld.metadata.cache.MetaAnnotationStore)7 Annotation (java.lang.annotation.Annotation)5 Repeatable (java.lang.annotation.Repeatable)2 HashSet (java.util.HashSet)2 WeldConfiguration (org.jboss.weld.config.WeldConfiguration)2 GlobalObserverNotifierService (org.jboss.weld.event.GlobalObserverNotifierService)2 ResourceInjectionFactory (org.jboss.weld.injection.ResourceInjectionFactory)2 ClassTransformer (org.jboss.weld.resources.ClassTransformer)2 BeanIdentifierIndex (org.jboss.weld.serialization.BeanIdentifierIndex)2 ContextualStoreImpl (org.jboss.weld.serialization.ContextualStoreImpl)2 Dependent (javax.enterprise.context.Dependent)1 BeanAttributesConfigurator (javax.enterprise.inject.spi.configurator.BeanAttributesConfigurator)1 SlimAnnotatedTypeStoreImpl (org.jboss.weld.annotated.slim.SlimAnnotatedTypeStoreImpl)1 ProtectionDomainCache (org.jboss.weld.bean.proxy.ProtectionDomainCache)1 SpecializationAndEnablementRegistry (org.jboss.weld.bootstrap.SpecializationAndEnablementRegistry)1 SimpleServiceRegistry (org.jboss.weld.bootstrap.api.helpers.SimpleServiceRegistry)1 GlobalEnablementBuilder (org.jboss.weld.bootstrap.enablement.GlobalEnablementBuilder)1 ContainerLifecycleEventPreloader (org.jboss.weld.bootstrap.events.ContainerLifecycleEventPreloader)1 ContainerLifecycleEvents (org.jboss.weld.bootstrap.events.ContainerLifecycleEvents)1 RequiredAnnotationDiscovery (org.jboss.weld.bootstrap.events.RequiredAnnotationDiscovery)1