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);
}
}
}
}
}
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);
}
}
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);
}
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));
}
}
}
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);
}
}
Aggregations