Search in sources :

Example 6 with IMarshallingContext

use of org.jibx.runtime.IMarshallingContext in project kernel by exoplatform.

the class XMLObject method toByteArray.

public byte[] toByteArray(String encoding) throws Exception {
    IBindingFactory bfact = getBindingFactoryInPriviledgedMode(XMLObject.class);
    IMarshallingContext mctx = bfact.createMarshallingContext();
    mctx.setIndent(2);
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    mctx.marshalDocument(this, encoding, null, os);
    return os.toByteArray();
}
Also used : IMarshallingContext(org.jibx.runtime.IMarshallingContext) IBindingFactory(org.jibx.runtime.IBindingFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 7 with IMarshallingContext

use of org.jibx.runtime.IMarshallingContext in project RESTdoclet by IG-Group.

the class JiBXUtils method marshallServices.

/**
    * Static method for marshalling services (list).
    * 
    * @param services the services to be marshalled.
    * @param file the file the services have to be marshalled to.
    * @throws JiBXException if JiBX fails.
    * @throws IOException if an input- or output-exception occurs.
    */
public static void marshallServices(final Services services, final File file) throws JiBXException, IOException {
    final Writer writer = new FileWriter(file);
    final IBindingFactory factory = BindingDirectory.getFactory(Services.class);
    final IMarshallingContext context = factory.createMarshallingContext();
    context.setIndent(INDENT);
    context.setOutput(writer);
    context.marshalDocument(services, ENCODING, null);
}
Also used : IMarshallingContext(org.jibx.runtime.IMarshallingContext) IBindingFactory(org.jibx.runtime.IBindingFactory) FileWriter(java.io.FileWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 8 with IMarshallingContext

use of org.jibx.runtime.IMarshallingContext in project spring-framework by spring-projects.

the class JibxMarshaller method marshalOutputStream.

// Supported marshalling
@Override
protected void marshalOutputStream(Object graph, OutputStream outputStream) throws XmlMappingException, IOException {
    try {
        IMarshallingContext marshallingContext = createMarshallingContext();
        marshallingContext.startDocument(this.encoding, this.standalone, outputStream);
        marshalDocument(marshallingContext, graph);
    } catch (JiBXException ex) {
        throw convertJibxException(ex, true);
    }
}
Also used : IMarshallingContext(org.jibx.runtime.IMarshallingContext) JiBXException(org.jibx.runtime.JiBXException)

Example 9 with IMarshallingContext

use of org.jibx.runtime.IMarshallingContext in project spring-framework by spring-projects.

the class JibxMarshaller method marshalWriter.

@Override
protected void marshalWriter(Object graph, Writer writer) throws XmlMappingException, IOException {
    try {
        IMarshallingContext marshallingContext = createMarshallingContext();
        marshallingContext.startDocument(this.encoding, this.standalone, writer);
        marshalDocument(marshallingContext, graph);
    } catch (JiBXException ex) {
        throw convertJibxException(ex, true);
    }
}
Also used : IMarshallingContext(org.jibx.runtime.IMarshallingContext) JiBXException(org.jibx.runtime.JiBXException)

Example 10 with IMarshallingContext

use of org.jibx.runtime.IMarshallingContext in project kernel by exoplatform.

the class Configuration method toXML.

/**
 * Dumps the configuration in XML format into the given {@link Writer}
 */
public void toXML(Writer w) {
    try {
        CURRENT_CONFIG_TO_SERIALIZE.set(this);
        IBindingFactory bfact = BindingDirectory.getFactory(Configuration.class);
        IMarshallingContext mctx = bfact.createMarshallingContext();
        mctx.setIndent(2);
        mctx.marshalDocument(this, "UTF-8", null, w);
    } catch (Exception e) {
        LOG.warn("Couldn't dump the runtime configuration in XML Format", e);
    } finally {
        CURRENT_CONFIG_TO_SERIALIZE.remove();
    }
}
Also used : IMarshallingContext(org.jibx.runtime.IMarshallingContext) IBindingFactory(org.jibx.runtime.IBindingFactory) IOException(java.io.IOException)

Aggregations

IMarshallingContext (org.jibx.runtime.IMarshallingContext)12 IBindingFactory (org.jibx.runtime.IBindingFactory)9 FileWriter (java.io.FileWriter)3 Writer (java.io.Writer)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 URL (java.net.URL)2 JiBXException (org.jibx.runtime.JiBXException)2 IOException (java.io.IOException)1 XMLObject (org.exoplatform.xml.object.XMLObject)1 IUnmarshallingContext (org.jibx.runtime.IUnmarshallingContext)1