Index: pom.xml
===================================================================
--- pom.xml (revision 27881)
+++ pom.xml (working copy)
@@ -9,7 +9,7 @@
Write the JBI descriptor XML into an output stream.
+ *Note: The output stream is not close by this method.
+ * + * @param jbiDescriptorClass + * The JBI Descriptor root class + * @param jbiDescrOutputStream + * The output stream where the JBI descriptor will be written + * @throws JBIDescriptorException + * The exception raised during the marshaller creation or the + * exception raised during the build of the XML string. + */ + public static void writeJBIdescriptor(final Jbi jbiDescriptorClass, final OutputStream jbiDescrOutputStream) + throws JBIDescriptorException { + + try { + // The default Xerces marshaller is not thread safe + synchronized (marshallerSync) { + getMarshaller().marshal(jbiDescriptorClass, jbiDescrOutputStream); + } + } catch (JAXBException e) { + throw new JBIDescriptorException( + "Failed to build XML binding from JBI descriptor Java classes", e); + } + } /** * Get the unmarshaller instance. Index: src/test/java/org/ow2/petals/jbi/descriptor/original/JBIDescriptorBuilderTestCase.java =================================================================== --- src/test/java/org/ow2/petals/jbi/descriptor/original/JBIDescriptorBuilderTestCase.java (revision 0) +++ src/test/java/org/ow2/petals/jbi/descriptor/original/JBIDescriptorBuilderTestCase.java (revision 0) @@ -0,0 +1,83 @@ +package org.ow2.petals.jbi.descriptor.original; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import junit.framework.TestCase; + +import org.ow2.petals.jbi.descriptor.JBIDescriptorException; +import org.ow2.petals.jbi.descriptor.original.generated.Component; +import org.ow2.petals.jbi.descriptor.original.generated.Identification; +import org.ow2.petals.jbi.descriptor.original.generated.Jbi; + +public class JBIDescriptorBuilderTestCase extends TestCase { + + private final static String BCSOAP_JBI_DESC = "bcsoap.jbi.xml"; + + /** + * Read a valid JBI descriptor, next save it, and finally read the saved + * version. + * + * @throws JBIDescriptorException + * @throws IOException + */ + public void testBuildXmlStringJBIDescriptor_000() throws JBIDescriptorException, IOException { + + // 1 - Read the original JBI descriptor + final InputStream jbiDescriptorStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(BCSOAP_JBI_DESC); + final Jbi bcSoapJbiDesc = JBIDescriptorBuilder.buildJavaJBIDescriptor(jbiDescriptorStream); + + // 2 - Temporary saved an instance of the read JBI descriptor + final String strJbiDescr = JBIDescriptorBuilder.buildXmlStringJBIdescriptor(bcSoapJbiDesc); + final File tempJbiDescr = File.createTempFile("bcsoap", "jbi.xml"); + final OutputStream os = new FileOutputStream(tempJbiDescr); + os.write(strJbiDescr.getBytes()); + os.close(); + + // 3 - Read the temporary JBI descriptor + final InputStream is = new FileInputStream(tempJbiDescr); + final Jbi tempJbiDesc = JBIDescriptorBuilder.buildJavaJBIDescriptor(is); + + assertNotNull(tempJbiDesc); + + } + + /** + * Read a valid JBI descriptor, update it with characters with accent, next save it, and finally read the saved + * version. + * + * @throws JBIDescriptorException + * @throws IOException + */ + public void testBuildXmlStringJBIDescriptor_001() throws JBIDescriptorException, IOException { + + // 1 - Read the original JBI descriptor + final InputStream jbiDescriptorStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(BCSOAP_JBI_DESC); + final Jbi bcSoapJbiDesc = JBIDescriptorBuilder.buildJavaJBIDescriptor(jbiDescriptorStream); + + // 2 - Update the read JBI descriptor with special character (with french accent) + final Component comp = bcSoapJbiDesc.getComponent(); + assertNotNull(comp); + final Identification ident = comp.getIdentification(); + assertNotNull(ident); + ident.setDescription("My french characters: [éèçàù€ïîê]"); + + // 3 - Temporary saved an instance of the read JBI descriptor + final File tempJbiDescr = File.createTempFile("bcsoap", "jbi.xml"); + final OutputStream os = new FileOutputStream(tempJbiDescr); + JBIDescriptorBuilder.writeJBIdescriptor(bcSoapJbiDesc, os); + os.close(); + + // 4 - Read the temporary JBI descriptor + final InputStream is = new FileInputStream(tempJbiDescr); + final Jbi tempJbiDesc = JBIDescriptorBuilder.buildJavaJBIDescriptor(is); + + assertNotNull(tempJbiDesc); + + } + +} Index: src/test/resources/bcsoap.jbi.xml =================================================================== --- src/test/resources/bcsoap.jbi.xml (revision 0) +++ src/test/resources/bcsoap.jbi.xml (revision 0) @@ -0,0 +1,35 @@ + +