Search in sources :

Example 1 with QualifiedBean

use of org.apache.cxf.jaxb.fortest.QualifiedBean in project cxf by apache.

the class JAXBDataBindingTest method doNamespaceMappingTest.

void doNamespaceMappingTest(boolean internal, boolean asm) throws Exception {
    if (internal) {
        try {
            Class.forName("com.sun.xml.internal.bind.v2.ContextFactory");
        } catch (Throwable t) {
            // on a JVM (likely IBM's) that doesn't rename the ContextFactory package to include "internal"
            return;
        }
    }
    try {
        if (!asm) {
            ReflectionUtil.setAccessible(ReflectionUtil.getDeclaredField(ASMHelper.class, "badASM")).set(null, Boolean.TRUE);
        }
        JAXBDataBinding db = createJaxbContext(internal);
        DataWriter<XMLStreamWriter> writer = db.createWriter(XMLStreamWriter.class);
        XMLOutputFactory writerFactory = XMLOutputFactory.newInstance();
        StringWriter stringWriter = new StringWriter();
        XMLStreamWriter xmlWriter = writerFactory.createXMLStreamWriter(stringWriter);
        QualifiedBean bean = new QualifiedBean();
        bean.setAriadne("spider");
        writer.write(bean, xmlWriter);
        xmlWriter.flush();
        String xml = stringWriter.toString();
        assertTrue("Failed to map namespace " + xml, xml.contains("greenland=\"uri:ultima:thule"));
    } finally {
        if (!asm) {
            ReflectionUtil.setAccessible(ReflectionUtil.getDeclaredField(ASMHelper.class, "badASM")).set(null, Boolean.FALSE);
        }
    }
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) StringWriter(java.io.StringWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) QualifiedBean(org.apache.cxf.jaxb.fortest.QualifiedBean)

Aggregations

StringWriter (java.io.StringWriter)1 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 QualifiedBean (org.apache.cxf.jaxb.fortest.QualifiedBean)1