Search in sources :

Example 1 with BeansXmlImpl

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);
}
Also used : StartElement(javax.xml.stream.events.StartElement) XMLStreamException(javax.xml.stream.XMLStreamException) InputStream(java.io.InputStream) BeansXmlImpl(org.jboss.weld.metadata.BeansXmlImpl) XMLEvent(javax.xml.stream.events.XMLEvent) XMLEventReader(javax.xml.stream.XMLEventReader) ScanningImpl(org.jboss.weld.metadata.ScanningImpl) IOException(java.io.IOException) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 2 with BeansXmlImpl

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);
}
Also used : BeansXmlImpl(org.jboss.weld.metadata.BeansXmlImpl) Metadata(org.jboss.weld.bootstrap.spi.Metadata) ArrayList(java.util.ArrayList) BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) ScanningImpl(org.jboss.weld.metadata.ScanningImpl) URL(java.net.URL)

Example 3 with BeansXmlImpl

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

Aggregations

BeansXmlImpl (org.jboss.weld.metadata.BeansXmlImpl)3 ScanningImpl (org.jboss.weld.metadata.ScanningImpl)3 ArrayList (java.util.ArrayList)2 Metadata (org.jboss.weld.bootstrap.spi.Metadata)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 XMLEventReader (javax.xml.stream.XMLEventReader)1 XMLInputFactory (javax.xml.stream.XMLInputFactory)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 StartElement (javax.xml.stream.events.StartElement)1 XMLEvent (javax.xml.stream.events.XMLEvent)1 BeansXml (org.jboss.weld.bootstrap.spi.BeansXml)1 Filter (org.jboss.weld.bootstrap.spi.Filter)1 MetadataImpl (org.jboss.weld.bootstrap.spi.helpers.MetadataImpl)1