Search in sources :

Example 66 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project aries by apache.

the class SpringTransactionalFactory method handleBeanAnnotation.

@Override
public void handleBeanAnnotation(AnnotatedElement annotatedElement, String id, ContextEnricher contextEnricher, BeanEnricher beanEnricher) {
    final String nsTx1 = getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), PATTERN_NS_TX1);
    if (nsTx1 != null) {
        enableAnnotationTx1(contextEnricher, nsTx1);
        final Transactional transactional = annotatedElement.getAnnotation(Transactional.class);
        final String transactionTypeName = getTransactionTypeName(transactional);
        beanEnricher.addBeanContentWriter("javax.transactional.method/" + annotatedElement + "/*/" + transactionTypeName, new XmlWriter() {

            @Override
            public void write(XMLStreamWriter writer) throws XMLStreamException {
                writer.writeEmptyElement("transaction");
                writer.writeDefaultNamespace(nsTx1);
                writer.writeAttribute("method", "*");
                writer.writeAttribute("value", transactionTypeName);
            }
        });
    }
    final String nsTx2 = getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), PATTERN_NS_TX1);
    if (nsTx2 != null) {
        insertEnableAnnotationTx2(contextEnricher, nsTx2);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) XmlWriter(org.apache.aries.blueprint.plugin.spi.XmlWriter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 67 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project aries by apache.

the class SpringTransactionalFactory method handleMethodAnnotation.

@Override
public void handleMethodAnnotation(Class<?> clazz, List<Method> methods, ContextEnricher contextEnricher, BeanEnricher beanEnricher) {
    final String nsTx1 = getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), PATTERN_NS_TX1);
    if (nsTx1 != null) {
        enableAnnotationTx1(contextEnricher, nsTx1);
        for (final Method method : methods) {
            final Transactional transactional = method.getAnnotation(Transactional.class);
            final String transactionTypeName = getTransactionTypeName(transactional);
            final String name = method.getName();
            beanEnricher.addBeanContentWriter("javax.transactional.method/" + clazz.getName() + "/" + name + "/" + transactionTypeName, new XmlWriter() {

                @Override
                public void write(XMLStreamWriter writer) throws XMLStreamException {
                    writer.writeEmptyElement("transaction");
                    writer.writeDefaultNamespace(nsTx1);
                    writer.writeAttribute("method", name);
                    writer.writeAttribute("value", transactionTypeName);
                }
            });
        }
    }
    final String nsTx2 = getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), PATTERN_NS_TX2);
    if (nsTx2 != null) {
        insertEnableAnnotationTx2(contextEnricher, nsTx2);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) Method(java.lang.reflect.Method) XmlWriter(org.apache.aries.blueprint.plugin.spi.XmlWriter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 68 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project lucene-solr by apache.

the class XMLResponseParser method readDocument.

protected SolrDocument readDocument(XMLStreamReader parser) throws XMLStreamException {
    if (XMLStreamConstants.START_ELEMENT != parser.getEventType()) {
        throw new RuntimeException("must be start element, not: " + parser.getEventType());
    }
    if (!"doc".equals(parser.getLocalName().toLowerCase(Locale.ROOT))) {
        throw new RuntimeException("must be 'lst', not: " + parser.getLocalName());
    }
    SolrDocument doc = new SolrDocument();
    StringBuilder builder = new StringBuilder();
    KnownType type = null;
    String name = null;
    // just eat up the events...
    int depth = 0;
    while (true) {
        switch(parser.next()) {
            case XMLStreamConstants.START_ELEMENT:
                depth++;
                // reset the text
                builder.setLength(0);
                type = KnownType.get(parser.getLocalName());
                if (type == null) {
                    throw new RuntimeException("this must be known type! not: " + parser.getLocalName());
                }
                name = null;
                int cnt = parser.getAttributeCount();
                for (int i = 0; i < cnt; i++) {
                    if ("name".equals(parser.getAttributeLocalName(i))) {
                        name = parser.getAttributeValue(i);
                        break;
                    }
                }
                //Nested documents
                while (type == KnownType.DOC) {
                    doc.addChildDocument(readDocument(parser));
                    int event = parser.next();
                    if (event == XMLStreamConstants.END_ELEMENT) {
                        //Doc ends
                        return doc;
                    }
                }
                if (name == null) {
                    throw new XMLStreamException("requires 'name' attribute: " + parser.getLocalName(), parser.getLocation());
                }
                // Handle multi-valued fields
                if (type == KnownType.ARR) {
                    for (Object val : readArray(parser)) {
                        doc.addField(name, val);
                    }
                    // the array reading clears out the 'endElement'
                    depth--;
                } else if (type == KnownType.LST) {
                    doc.addField(name, readNamedList(parser));
                    depth--;
                } else if (!type.isLeaf) {
                    System.out.println("nbot leaf!:" + type);
                    throw new XMLStreamException("must be value or array", parser.getLocation());
                }
                break;
            case XMLStreamConstants.END_ELEMENT:
                if (--depth < 0) {
                    return doc;
                }
                //System.out.println( "FIELD:"+type+"::"+name+"::"+builder );
                Object val = type.read(builder.toString().trim());
                if (val == null) {
                    throw new XMLStreamException("error reading value:" + type, parser.getLocation());
                }
                doc.addField(name, val);
                break;
            // TODO?  should this be trimmed? make sure it only gets one/two space?
            case XMLStreamConstants.SPACE:
            case XMLStreamConstants.CDATA:
            case XMLStreamConstants.CHARACTERS:
                builder.append(parser.getText());
                break;
        }
    }
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 69 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project karaf by apache.

the class MavenConfigService method getLocalRepositoryFromSettings.

private static String getLocalRepositoryFromSettings(File file) {
    XMLStreamReader reader = null;
    try (InputStream fin = new FileInputStream(file)) {
        reader = XMLInputFactory.newFactory().createXMLStreamReader(fin);
        int event;
        String elementName = null;
        while ((event = reader.next()) != XMLStreamConstants.END_DOCUMENT) {
            if (event == XMLStreamConstants.START_ELEMENT) {
                elementName = reader.getLocalName();
            } else if (event == XMLStreamConstants.END_ELEMENT) {
                elementName = null;
            } else if (event == XMLStreamConstants.CHARACTERS && "localRepository".equals(elementName)) {
                return reader.getText().trim();
            }
        }
    } catch (Exception e) {
        logger.error("Error retrieving maven configuration", e);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (XMLStreamException e) {
            // Ignore
            }
        }
    }
    return null;
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 70 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project logging-log4j2 by apache.

the class DefaultConfigurationBuilder method writeXmlConfiguration.

@Override
public void writeXmlConfiguration(final OutputStream output) throws IOException {
    try {
        final XMLStreamWriter xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(output);
        writeXmlConfiguration(xmlWriter);
        xmlWriter.close();
    } catch (final XMLStreamException e) {
        if (e.getNestedException() instanceof IOException) {
            throw (IOException) e.getNestedException();
        }
        Throwables.rethrow(e);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) IOException(java.io.IOException)

Aggregations

XMLStreamException (javax.xml.stream.XMLStreamException)442 XMLStreamReader (javax.xml.stream.XMLStreamReader)137 IOException (java.io.IOException)126 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)75 XMLInputFactory (javax.xml.stream.XMLInputFactory)69 InputStream (java.io.InputStream)66 Document (org.w3c.dom.Document)36 JAXBException (javax.xml.bind.JAXBException)35 Fault (org.apache.cxf.interceptor.Fault)34 Element (org.w3c.dom.Element)32 StringReader (java.io.StringReader)30 XMLEvent (javax.xml.stream.events.XMLEvent)28 DOMSource (javax.xml.transform.dom.DOMSource)27 ByteArrayInputStream (java.io.ByteArrayInputStream)25 ArrayList (java.util.ArrayList)23 QName (javax.xml.namespace.QName)23 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)23 Node (org.w3c.dom.Node)22 StringWriter (java.io.StringWriter)21 XMLEventReader (javax.xml.stream.XMLEventReader)20