Package org.apache.tuscany.sca.common.xml.stax

Examples of org.apache.tuscany.sca.common.xml.stax.StAXHelper


    /**
     * Helper method to get the XML string for a model object.
     */
    public static String modelToXML(Base model, boolean pretty, ExtensionPointRegistry extensionPointRegistry) {
        try {
            StAXHelper stAXHelper = StAXHelper.getInstance(extensionPointRegistry);
            StAXArtifactProcessorExtensionPoint staxProcessors = extensionPointRegistry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
            ExtensibleStAXArtifactProcessor staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, null, stAXHelper.getOutputFactory());
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            staxProcessor.write(model, bos, new ProcessorContext(extensionPointRegistry));
            bos.close();

            if (!pretty) {
View Full Code Here


        StringBuffer xml = new StringBuffer();
        xml.append("<").append(bindingType.getLocalPart()).append(" xmlns:b=\"").append(bindingType.getNamespaceURI())
            .append("\"/>");

        StAXHelper staxHelper = StAXHelper.getInstance(registry);
        XMLStreamReader reader = staxHelper.createXMLStreamReader(new StringReader(xml.toString()));
        reader.nextTag();
        Binding binding = (Binding)processor.read(reader, new ProcessorContext(registry));

        return binding;
    }
View Full Code Here

        return null;
    }

    protected Composite readComposite(String compositeXML) {
        try {
            StAXHelper stAXHelper = StAXHelper.getInstance(registry);
            StAXArtifactProcessorExtensionPoint staxProcessors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
            ExtensibleStAXArtifactProcessor staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, stAXHelper.getInputFactory(), null);
            XMLStreamReader reader = stAXHelper.createXMLStreamReader(compositeXML);
            Composite composite = (Composite)staxProcessor.read(reader, new ProcessorContext(registry));
            return composite;
        } catch (XMLStreamException e) {
            throw new RuntimeException(e);
        } catch (ContributionReadException e) {
View Full Code Here

        }
    }

    protected String writeComposite(Composite composite) {
        try {
            StAXHelper stAXHelper = StAXHelper.getInstance(registry);
            StAXArtifactProcessorExtensionPoint staxProcessors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
            ExtensibleStAXArtifactProcessor staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, null, stAXHelper.getOutputFactory());
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            staxProcessor.write(composite, bos, new ProcessorContext(registry));
            bos.close();
            return bos.toString();
        } catch (ContributionWriteException e) {
View Full Code Here

        // This is a hack to create an instance of the binding using the XML QName
        StringBuffer xml = new StringBuffer();
        xml.append("<").append(mappedBinding.getLocalPart()).append(" xmlns:b=\"").append(mappedBinding
            .getNamespaceURI()).append("\"/>");

        StAXHelper staxHelper = StAXHelper.getInstance(registry);
        XMLStreamReader reader = staxHelper.createXMLStreamReader(new StringReader(xml.toString()));
        reader.nextTag();
        Binding binding = (Binding)processor.read(reader, new ProcessorContext(registry));
        return binding;
    }
View Full Code Here

        StringBuffer xml = new StringBuffer();
        xml.append("<").append(bindingType.getLocalPart()).append(" xmlns:b=\"").append(bindingType.getNamespaceURI())
            .append("\"/>");

        StAXHelper staxHelper = StAXHelper.getInstance(registry);
        XMLStreamReader reader = staxHelper.createXMLStreamReader(new StringReader(xml.toString()));
        reader.nextTag();
        Binding binding = (Binding)processor.read(reader, new ProcessorContext(registry));

        return binding;
    }
View Full Code Here

        return null;
    }

    protected Composite readComposite(String compositeXML) {
        try {
            StAXHelper stAXHelper = StAXHelper.getInstance(registry);
            StAXArtifactProcessorExtensionPoint staxProcessors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
            ExtensibleStAXArtifactProcessor staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, stAXHelper.getInputFactory(), null);
            XMLStreamReader reader = stAXHelper.createXMLStreamReader(compositeXML);
            Composite composite = (Composite)staxProcessor.read(reader, new ProcessorContext(registry));
            return composite;
        } catch (XMLStreamException e) {
            throw new RuntimeException(e);
        } catch (ContributionReadException e) {
View Full Code Here

        }
    }

    protected String writeComposite(Composite composite) {
        try {
            StAXHelper stAXHelper = StAXHelper.getInstance(registry);
            StAXArtifactProcessorExtensionPoint staxProcessors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
            ExtensibleStAXArtifactProcessor staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, null, stAXHelper.getOutputFactory());
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            staxProcessor.write(composite, bos, new ProcessorContext(registry));
            bos.close();
            return bos.toString();
        } catch (ContributionWriteException e) {
View Full Code Here

        "{\"xsl:root\":{\"@xmlns\":{\"xsl\":\"http://foo.com\"},\"data\":{\"$\":\"my json string\"}}}";

    @Test
    public void testXML2JSON() throws Exception {
        ExtensionPointRegistry extensionPointRegistry = new DefaultExtensionPointRegistry();
        StAXHelper staxHelper = StAXHelper.getInstance(extensionPointRegistry);

        XMLStreamReader reader = staxHelper.createXMLStreamReader(new StringReader(IPO_XML));
        XMLStreamReader2JSON t1 = new XMLStreamReader2JSON(extensionPointRegistry);
        JSONObject json = (JSONObject)t1.transform(reader, null);
        Assert.assertNotNull(json);

        // Cannot round-trip as we hit a bug in Jettison: http://jira.codehaus.org/browse/JETTISON-93
View Full Code Here

    }

    @Test
    public void testJSON2XML() throws Exception {
        ExtensionPointRegistry extensionPointRegistry = new DefaultExtensionPointRegistry();
        StAXHelper helper = StAXHelper.getInstance(extensionPointRegistry);

        JSON2XMLStreamReader t2 = new JSON2XMLStreamReader();
        XMLStreamReader reader2 = t2.transform(new JSONObject(JSON_STR), null);
        StringWriter sw = new StringWriter();
        XMLStreamWriter streamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(sw);
        helper.save(reader2, streamWriter);
        Assert.assertTrue(sw.toString()
            .contains("<xsl:root xmlns:xsl=\"http://foo.com\"><data>my json string</data></xsl:root>"));
    }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.common.xml.stax.StAXHelper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.