Search in sources :

Example 1 with Filter

use of org.jboss.weld.bootstrap.spi.Filter in project core by weld.

the class BeansXmlStreamParser method handleFilter.

private void handleFilter(StartElement filterElement, XMLEventReader reader, Consumer<XmlMetadata<Filter>> consumer) throws XMLStreamException {
    String name = getAttribute(filterElement, NAME_ATTRIBUTE_NAME);
    String pattern = name != null ? null : getAttribute(filterElement, PATTERN_ATTRIBUTE_NAME);
    if (name != null || pattern != null) {
        List<Metadata<SystemPropertyActivation>> systemPropertyActivations = new LinkedList<>();
        List<Metadata<ClassAvailableActivation>> classAvailableActivations = new LinkedList<>();
        while (reader.hasNext()) {
            XMLEvent event = reader.nextEvent();
            if (isEnd(event, EXCLUDE, SCANNING_URIS) || isEnd(event, INCLUDE, SCANNING_URIS)) {
                Filter filter;
                if (filterElement.getName().getNamespaceURI().equals(WELD_URI)) {
                    filter = new WeldFilterImpl(name, systemPropertyActivations, classAvailableActivations, pattern);
                } else {
                    filter = new FilterImpl(name, systemPropertyActivations, classAvailableActivations);
                }
                consumer.accept(new XmlMetadata<Filter>(filterElement.getName().toString(), filter, beansXml, filterElement.getLocation().getLineNumber()));
                return;
            } else if (event.isStartElement()) {
                StartElement element = (StartElement) event;
                if (isStartElement(element, IF_CLASS_AVAILABLE, SCANNING_URIS)) {
                    classAvailable(element, classAvailableActivations::add, false);
                } else if (isStartElement(element, IF_CLASS_NOT_AVAILABLE, SCANNING_URIS)) {
                    classAvailable(element, classAvailableActivations::add, true);
                } else if (isStartElement(element, IF_SYSTEM_PROPERTY, SCANNING_URIS)) {
                    systemProperty(element, systemPropertyActivations::add);
                }
            }
        }
    }
}
Also used : StartElement(javax.xml.stream.events.StartElement) WeldFilterImpl(org.jboss.weld.metadata.WeldFilterImpl) FilterImpl(org.jboss.weld.metadata.FilterImpl) Filter(org.jboss.weld.bootstrap.spi.Filter) Metadata(org.jboss.weld.bootstrap.spi.Metadata) XMLEvent(javax.xml.stream.events.XMLEvent) WeldFilterImpl(org.jboss.weld.metadata.WeldFilterImpl) LinkedList(java.util.LinkedList)

Example 2 with Filter

use of org.jboss.weld.bootstrap.spi.Filter in project core by weld.

the class BeansXmlParsingTest method testExclusionFilters2.

@Test(expectedExceptions = Exception.class)
public void testExclusionFilters2() {
    BeansXml xml = getBeansXml("cdi11-exclude-beans2.xml");
    Collection<Metadata<Filter>> filters = xml.getScanning().getExcludes();
    assertEquals(filters.size(), 1);
    for (Metadata<Filter> filter : filters) {
        new FilterPredicate(filter, DefaultResourceLoader.INSTANCE);
    }
}
Also used : Filter(org.jboss.weld.bootstrap.spi.Filter) BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) Metadata(org.jboss.weld.bootstrap.spi.Metadata) FilterPredicate(org.jboss.weld.metadata.FilterPredicate) Test(org.testng.annotations.Test)

Example 3 with Filter

use of org.jboss.weld.bootstrap.spi.Filter in project core by weld.

the class BeansXmlMergeTest method createBeansXmlTestInstance.

public BeansXml createBeansXmlTestInstance() {
    final MetadataImpl<String> alternative = new MetadataImpl<String>("some.package.SomeAlternative", "C:\temp");
    final MetadataImpl<String> stereoType = new MetadataImpl<String>("some.package.SomeStereotype", "C:\temp");
    final MetadataImpl<String> decorator = new MetadataImpl<String>("some.package.SomeDecorator", "C:\temp");
    final MetadataImpl<String> interceptor = new MetadataImpl<String>("some.package.SomeInterceptor", "C:\temp");
    final Metadata<Filter> include = new MetadataImpl<Filter>(new FilterStub(), "C:\temp");
    final Metadata<Filter> exclude = new MetadataImpl<Filter>(new FilterStub(), "C:\temp");
    final List<Metadata<String>> alternativesClasses = new ArrayList<Metadata<String>>();
    final List<Metadata<String>> alternativeStereotypes = new ArrayList<Metadata<String>>();
    final List<Metadata<String>> decorators = new ArrayList<Metadata<String>>();
    final List<Metadata<String>> interceptors = new ArrayList<Metadata<String>>();
    final List<Metadata<Filter>> includes = new ArrayList<Metadata<Filter>>();
    final List<Metadata<Filter>> excludes = new ArrayList<Metadata<Filter>>();
    alternativesClasses.add(alternative);
    alternativeStereotypes.add(stereoType);
    decorators.add(decorator);
    interceptors.add(interceptor);
    includes.add(include);
    excludes.add(exclude);
    return new BeansXmlImpl(alternativesClasses, alternativeStereotypes, decorators, interceptors, new ScanningImpl(includes, excludes), null, BeanDiscoveryMode.ALL, "1.1", false);
}
Also used : MetadataImpl(org.jboss.weld.bootstrap.spi.helpers.MetadataImpl) Filter(org.jboss.weld.bootstrap.spi.Filter) BeansXmlImpl(org.jboss.weld.metadata.BeansXmlImpl) Metadata(org.jboss.weld.bootstrap.spi.Metadata) ArrayList(java.util.ArrayList) ScanningImpl(org.jboss.weld.metadata.ScanningImpl)

Example 4 with Filter

use of org.jboss.weld.bootstrap.spi.Filter in project core by weld.

the class JsonObjects method createMetadataArrayJson.

static void createMetadataArrayJson(JsonArrayBuilder scanBuilder, Collection<Metadata<Filter>> metadata, String type) {
    if (metadata != null && !metadata.isEmpty()) {
        for (Metadata<Filter> filterMetadata : metadata) {
            Filter filter = filterMetadata.getValue();
            scanBuilder.add(createFilterJsonArray(filter, type));
        }
    }
}
Also used : Filter(org.jboss.weld.bootstrap.spi.Filter)

Example 5 with Filter

use of org.jboss.weld.bootstrap.spi.Filter in project core by weld.

the class BeansXmlParsingTest method testExclusionFilters1.

@Test
public void testExclusionFilters1() {
    BeansXml xml = getBeansXml("cdi11-exclude-beans1.xml");
    Collection<Metadata<Filter>> filters = xml.getScanning().getExcludes();
    assertEquals(filters.size(), 3);
    for (Metadata<Filter> filter : filters) {
        new FilterPredicate(filter, DefaultResourceLoader.INSTANCE);
    }
}
Also used : Filter(org.jboss.weld.bootstrap.spi.Filter) BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) Metadata(org.jboss.weld.bootstrap.spi.Metadata) FilterPredicate(org.jboss.weld.metadata.FilterPredicate) Test(org.testng.annotations.Test)

Aggregations

Filter (org.jboss.weld.bootstrap.spi.Filter)5 Metadata (org.jboss.weld.bootstrap.spi.Metadata)4 BeansXml (org.jboss.weld.bootstrap.spi.BeansXml)2 FilterPredicate (org.jboss.weld.metadata.FilterPredicate)2 Test (org.testng.annotations.Test)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 StartElement (javax.xml.stream.events.StartElement)1 XMLEvent (javax.xml.stream.events.XMLEvent)1 MetadataImpl (org.jboss.weld.bootstrap.spi.helpers.MetadataImpl)1 BeansXmlImpl (org.jboss.weld.metadata.BeansXmlImpl)1 FilterImpl (org.jboss.weld.metadata.FilterImpl)1 ScanningImpl (org.jboss.weld.metadata.ScanningImpl)1 WeldFilterImpl (org.jboss.weld.metadata.WeldFilterImpl)1