Search in sources :

Example 1 with IMarshallingContext

use of org.jibx.runtime.IMarshallingContext in project camel by apache.

the class JibxDataFormat method marshal.

public void marshal(Exchange exchange, Object body, OutputStream stream) throws Exception {
    IBindingFactory bindingFactory = createBindingFactory(body.getClass(), bindingName);
    IMarshallingContext marshallingContext = bindingFactory.createMarshallingContext();
    marshallingContext.marshalDocument(body, null, null, stream);
    if (contentTypeHeader) {
        if (exchange.hasOut()) {
            exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "application/xml");
        } else {
            exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/xml");
        }
    }
}
Also used : IMarshallingContext(org.jibx.runtime.IMarshallingContext) IBindingFactory(org.jibx.runtime.IBindingFactory)

Example 2 with IMarshallingContext

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

the class JibxMarshaller method createMarshallingContext.

/**
	 * Create a new {@code IMarshallingContext}, configured with the correct indentation.
	 * @return the created marshalling context
	 * @throws JiBXException in case of errors
	 */
protected IMarshallingContext createMarshallingContext() throws JiBXException {
    IMarshallingContext marshallingContext = this.bindingFactory.createMarshallingContext();
    marshallingContext.setIndent(this.indent);
    return marshallingContext;
}
Also used : IMarshallingContext(org.jibx.runtime.IMarshallingContext)

Example 3 with IMarshallingContext

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

the class JiBXUtils method marshallController.

/**
    * Static method for marshalling a controller.
    * 
    * @param controller the controller to be marshalled.
    * @param file the file the controller has to be marshalled to.
    * @throws JiBXException if JiBX fails.
    * @throws IOException if an input- or output-exception occurs.
    */
public static void marshallController(final Controller controller, final File file) throws JiBXException, IOException {
    final Writer writer = new FileWriter(file);
    final IBindingFactory factory = BindingDirectory.getFactory(Controller.class);
    final IMarshallingContext context = factory.createMarshallingContext();
    context.setIndent(INDENT);
    context.setOutput(writer);
    context.marshalDocument(controller, 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 4 with IMarshallingContext

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

the class JiBXUtils method marshallService.

/**
    * Static method for marshalling a service.
    * 
    * @param service the service to be marshalled.
    * @param file the file the service has to be marshalled to.
    * @throws JiBXException if JiBX fails.
    * @throws IOException if an input- or output-exception occurs.
    */
public static void marshallService(final Service service, final File file) throws JiBXException, IOException {
    final Writer writer = new FileWriter(file);
    final IBindingFactory factory = BindingDirectory.getFactory(Service.class);
    final IMarshallingContext context = factory.createMarshallingContext();
    context.setIndent(INDENT);
    context.setOutput(writer);
    context.marshalDocument(service, 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 5 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)

Aggregations

IMarshallingContext (org.jibx.runtime.IMarshallingContext)7 IBindingFactory (org.jibx.runtime.IBindingFactory)4 FileWriter (java.io.FileWriter)3 Writer (java.io.Writer)3 JiBXException (org.jibx.runtime.JiBXException)2