use of org.jboss.weld.metadata.BeansXmlImpl in project core by weld.
the class BeansXmlStreamParser method parse.
public BeansXml parse() {
if (beansXml == null) {
throw XmlLogger.LOG.loadError("unknown", null);
}
try (InputStream in = beansXml.openStream()) {
if (in.available() == 0) {
// The file is just acting as a marker file
return EMPTY_BEANS_XML;
}
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLEventReader reader = factory.createXMLEventReader(in);
StartElement element = nextStartElement(reader, BEANS, JAVAEE_URIS);
if (element != null) {
parseBeans(element);
while (reader.hasNext()) {
XMLEvent event = reader.nextEvent();
if (isEnd(event, BEANS)) {
break;
} else if (isStartElement(event, ALTERNATIVES)) {
parseAlternatives(reader, event);
} else if (isStartElement(event, INTERCEPTORS)) {
parseInterceptors(reader, event);
} else if (isStartElement(event, DECORATORS)) {
parseDecorators(reader, event);
} else if (isStartElement(event, SCAN, SCANNING_URIS)) {
parseScan(reader, event);
} else if (isStartElement(event, TRIM)) {
isTrimmed = true;
}
}
}
reader.close();
} catch (IOException e) {
throw XmlLogger.LOG.loadError(beansXml, e);
} catch (XMLStreamException e) {
throw XmlLogger.LOG.parsingError(beansXml, e);
}
return new BeansXmlImpl(orEmpty(selectedAlternatives), orEmpty(selectedAlternativeStereotypes), orEmpty(enabledDecorators), orEmpty(enabledInterceptors), new ScanningImpl(orEmpty(includes), orEmpty(excludes)), beansXml, discoveryMode, version, isTrimmed);
}
use of org.jboss.weld.metadata.BeansXmlImpl in project core by weld.
the class BeansXmlParser method merge.
// Merging utils
public static <T> BeansXml merge(Iterable<? extends T> items, Function<T, BeansXml> function, boolean removeDuplicates) {
List<Metadata<String>> alternatives = new ArrayList<>();
List<Metadata<String>> alternativeStereotypes = new ArrayList<>();
List<Metadata<String>> decorators = new ArrayList<>();
List<Metadata<String>> interceptors = new ArrayList<>();
List<Metadata<Filter>> includes = new ArrayList<>();
List<Metadata<Filter>> excludes = new ArrayList<>();
boolean isTrimmed = false;
URL beansXmlUrl = null;
for (T item : items) {
BeansXml beansXml = function.apply(item);
addTo(alternatives, beansXml.getEnabledAlternativeClasses(), removeDuplicates);
addTo(alternativeStereotypes, beansXml.getEnabledAlternativeStereotypes(), removeDuplicates);
addTo(decorators, beansXml.getEnabledDecorators(), removeDuplicates);
addTo(interceptors, beansXml.getEnabledInterceptors(), removeDuplicates);
includes.addAll(beansXml.getScanning().getIncludes());
excludes.addAll(beansXml.getScanning().getExcludes());
isTrimmed = beansXml.isTrimmed();
/*
* provided we are merging the content of multiple XML files, getBeansXml() returns an InputStream representing the last one
*/
beansXmlUrl = beansXml.getUrl();
}
return new BeansXmlImpl(alternatives, alternativeStereotypes, decorators, interceptors, new ScanningImpl(includes, excludes), beansXmlUrl, BeanDiscoveryMode.ALL, null, isTrimmed);
}
use of org.jboss.weld.metadata.BeansXmlImpl 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);
}
Aggregations