Search in sources :

Example 1 with ScanResult

use of org.jboss.weld.environment.deployment.discovery.BeanArchiveScanner.ScanResult in project core by weld.

the class AbstractDiscoveryStrategy method performDiscovery.

@Override
public Set<WeldBeanDeploymentArchive> performDiscovery() {
    if (scanner == null) {
        scanner = new DefaultBeanArchiveScanner(resourceLoader, bootstrap);
    }
    final List<BeanArchiveBuilder> beanArchiveBuilders = new ArrayList<BeanArchiveBuilder>();
    final Set<String> processedRefs = new HashSet<String>();
    List<BeanArchiveHandler> beanArchiveHandlers = initBeanArchiveHandlers();
    for (ScanResult scanResult : scanner.scan()) {
        final String ref = scanResult.getBeanArchiveRef();
        if (processedRefs.contains(ref)) {
            throw CommonLogger.LOG.invalidScanningResult(ref);
        }
        CommonLogger.LOG.processingBeanArchiveReference(ref);
        processedRefs.add(ref);
        BeanArchiveBuilder builder = null;
        for (BeanArchiveHandler handler : beanArchiveHandlers) {
            builder = handler.handle(ref);
            if (builder != null) {
                CommonLogger.LOG.beanArchiveReferenceHandled(ref, handler);
                builder.setId(scanResult.getBeanArchiveId());
                builder.setBeansXml(scanResult.getBeansXml());
                beanArchiveBuilders.add(builder);
                break;
            }
        }
        if (builder == null) {
            CommonLogger.LOG.beanArchiveReferenceCannotBeHandled(ref, beanArchiveHandlers);
        }
    }
    beforeDiscovery(beanArchiveBuilders);
    Set<WeldBeanDeploymentArchive> archives = new HashSet<WeldBeanDeploymentArchive>();
    for (Iterator<BeanArchiveBuilder> iterator = beanArchiveBuilders.iterator(); iterator.hasNext(); ) {
        BeanArchiveBuilder builder = iterator.next();
        BeansXml beansXml = builder.getBeansXml();
        if (beansXml != null) {
            switch(beansXml.getBeanDiscoveryMode()) {
                case ALL:
                    addToArchives(archives, processAllDiscovery(builder));
                    break;
                case ANNOTATED:
                    addToArchives(archives, processAnnotatedDiscovery(builder));
                    break;
                case NONE:
                    addToArchives(archives, processNoneDiscovery(builder));
                    break;
                default:
                    throw CommonLogger.LOG.undefinedBeanDiscoveryValue(beansXml.getBeanDiscoveryMode());
            }
        } else {
            // A candidate for an implicit bean archive with no beans.xml
            addToArchives(archives, processAnnotatedDiscovery(builder));
        }
    }
    for (WeldBeanDeploymentArchive archive : archives) {
        archive.getServices().add(ResourceLoader.class, resourceLoader);
    }
    afterDiscovery(archives);
    return archives;
}
Also used : ScanResult(org.jboss.weld.environment.deployment.discovery.BeanArchiveScanner.ScanResult) WeldBeanDeploymentArchive(org.jboss.weld.environment.deployment.WeldBeanDeploymentArchive) ArrayList(java.util.ArrayList) BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 BeansXml (org.jboss.weld.bootstrap.spi.BeansXml)1 WeldBeanDeploymentArchive (org.jboss.weld.environment.deployment.WeldBeanDeploymentArchive)1 ScanResult (org.jboss.weld.environment.deployment.discovery.BeanArchiveScanner.ScanResult)1