Search in sources :

Example 16 with XMLStreamWriter

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

the class InitContextExample method initContext.

@Override
public void initContext(ContextEnricher contextEnricher) {
    final Map<String, String> customParameters = contextEnricher.getBlueprintConfiguration().getCustomParameters();
    for (final String param : customParameters.keySet()) {
        if (param.startsWith("example.")) {
            final String key = param.split("\\.")[1];
            contextEnricher.addBlueprintContentWriter("enrichContextWithExample-" + key, new XmlWriter() {

                @Override
                public void write(XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
                    xmlStreamWriter.writeEmptyElement("example");
                    xmlStreamWriter.writeDefaultNamespace("http://exampleNamespace");
                    xmlStreamWriter.writeAttribute("id", key);
                    xmlStreamWriter.writeAttribute("value", customParameters.get(param));
                }
            });
        }
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) XmlWriter(org.apache.aries.blueprint.plugin.spi.XmlWriter)

Example 17 with XMLStreamWriter

use of javax.xml.stream.XMLStreamWriter 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 18 with XMLStreamWriter

use of javax.xml.stream.XMLStreamWriter 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 19 with XMLStreamWriter

use of javax.xml.stream.XMLStreamWriter 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)

Example 20 with XMLStreamWriter

use of javax.xml.stream.XMLStreamWriter in project spring-framework by spring-projects.

the class AbstractMarshallerTests method marshalStaxResultStreamWriter.

@Test
public void marshalStaxResultStreamWriter() throws Exception {
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
    StringWriter writer = new StringWriter();
    XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
    Result result = StaxUtils.createStaxResult(streamWriter);
    marshaller.marshal(flights, result);
    assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING));
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) StringWriter(java.io.StringWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result) StAXResult(javax.xml.transform.stax.StAXResult) DOMResult(javax.xml.transform.dom.DOMResult) Test(org.junit.Test)

Aggregations

XMLStreamWriter (javax.xml.stream.XMLStreamWriter)209 XMLStreamException (javax.xml.stream.XMLStreamException)84 StringWriter (java.io.StringWriter)47 Test (org.junit.Test)47 ByteArrayOutputStream (java.io.ByteArrayOutputStream)40 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)40 XMLStreamReader (javax.xml.stream.XMLStreamReader)32 QName (javax.xml.namespace.QName)26 Document (org.w3c.dom.Document)26 Fault (org.apache.cxf.interceptor.Fault)25 IOException (java.io.IOException)23 OutputStream (java.io.OutputStream)21 ByteArrayInputStream (java.io.ByteArrayInputStream)17 StreamSource (javax.xml.transform.stream.StreamSource)17 StringReader (java.io.StringReader)16 JAXBException (javax.xml.bind.JAXBException)14 DOMSource (javax.xml.transform.dom.DOMSource)14 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)14 Message (org.apache.cxf.message.Message)13 Element (org.w3c.dom.Element)11