Search in sources :

Example 1 with ImmutableList

use of org.jboss.weld.util.collections.ImmutableList in project core by weld.

the class GlobalEnablementBuilder method createModuleEnablement.

public ModuleEnablement createModuleEnablement(BeanDeployment deployment) {
    ClassLoader loader = new ClassLoader(deployment.getBeanManager().getServices().get(ResourceLoader.class));
    BeansXml beansXml = deployment.getBeanDeploymentArchive().getBeansXml();
    Set<Class<?>> alternativeClasses = null;
    Set<Class<? extends Annotation>> alternativeStereotypes = null;
    List<Class<?>> globallyEnabledInterceptors = getInterceptorList(null);
    List<Class<?>> globallyEnabledDecorators = getDecoratorList(null);
    ImmutableList.Builder<Class<?>> moduleInterceptorsBuilder = ImmutableList.<Class<?>>builder();
    moduleInterceptorsBuilder.addAll(globallyEnabledInterceptors);
    ImmutableList.Builder<Class<?>> moduleDecoratorsBuilder = ImmutableList.<Class<?>>builder();
    moduleDecoratorsBuilder.addAll(globallyEnabledDecorators);
    if (beansXml != null) {
        checkForDuplicates(beansXml.getEnabledInterceptors(), ValidatorLogger.INTERCEPTOR_SPECIFIED_TWICE);
        checkForDuplicates(beansXml.getEnabledDecorators(), ValidatorLogger.DECORATOR_SPECIFIED_TWICE);
        checkForDuplicates(beansXml.getEnabledAlternativeClasses(), ValidatorLogger.ALTERNATIVE_CLASS_SPECIFIED_MULTIPLE_TIMES);
        checkForDuplicates(beansXml.getEnabledAlternativeStereotypes(), ValidatorLogger.ALTERNATIVE_STEREOTYPE_SPECIFIED_MULTIPLE_TIMES);
        List<Class<?>> interceptorClasses = beansXml.getEnabledInterceptors().stream().map(loader).collect(Collectors.toList());
        moduleInterceptorsBuilder.addAll(filter(interceptorClasses, globallyEnabledInterceptors, ValidatorLogger.INTERCEPTOR_ENABLED_FOR_APP_AND_ARCHIVE, deployment));
        List<Class<?>> decoratorClasses = beansXml.getEnabledDecorators().stream().map(loader).collect(Collectors.toList());
        moduleDecoratorsBuilder.addAll(filter(decoratorClasses, globallyEnabledDecorators, ValidatorLogger.DECORATOR_ENABLED_FOR_APP_AND_ARCHIVE, deployment));
        alternativeClasses = beansXml.getEnabledAlternativeClasses().stream().map(loader).collect(ImmutableSet.collector());
        alternativeStereotypes = cast(beansXml.getEnabledAlternativeStereotypes().stream().map(loader).collect(ImmutableSet.collector()));
    } else {
        alternativeClasses = Collections.emptySet();
        alternativeStereotypes = Collections.emptySet();
    }
    Map<Class<?>, Integer> globalAlternatives = getGlobalAlternativeMap();
    // We suppose that enablements are always created all at once
    dirty = false;
    return new ModuleEnablement(moduleInterceptorsBuilder.build(), moduleDecoratorsBuilder.build(), globalAlternatives, alternativeClasses, alternativeStereotypes);
}
Also used : ResourceLoader(org.jboss.weld.resources.spi.ResourceLoader) ImmutableList(org.jboss.weld.util.collections.ImmutableList) Annotation(java.lang.annotation.Annotation) BigInteger(java.math.BigInteger) BeansXml(org.jboss.weld.bootstrap.spi.BeansXml)

Aggregations

Annotation (java.lang.annotation.Annotation)1 BigInteger (java.math.BigInteger)1 BeansXml (org.jboss.weld.bootstrap.spi.BeansXml)1 ResourceLoader (org.jboss.weld.resources.spi.ResourceLoader)1 ImmutableList (org.jboss.weld.util.collections.ImmutableList)1