Search in sources :

Example 21 with IBindingFactory

use of org.jibx.runtime.IBindingFactory in project tutorials by eugenp.

the class CustomerIntegrationTest method WhenUnmarshal_ThenMappingInherited.

@Test
public void WhenUnmarshal_ThenMappingInherited() throws JiBXException, FileNotFoundException {
    IBindingFactory bfact = BindingDirectory.getFactory(Customer.class);
    IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    InputStream inputStream = classLoader.getResourceAsStream("Customer1.xml");
    Customer customer = (Customer) uctx.unmarshalDocument(inputStream, null);
    assertEquals(12345, customer.getPerson().getCustomerId());
}
Also used : IUnmarshallingContext(org.jibx.runtime.IUnmarshallingContext) IBindingFactory(org.jibx.runtime.IBindingFactory) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 22 with IBindingFactory

use of org.jibx.runtime.IBindingFactory in project alfresco-repository by Alfresco.

the class SystemInfo method toXML.

/**
 * Create XML representation of System Info
 *
 * @param xml  xml representation of system info
 */
public void toXML(OutputStream xml) {
    try {
        IBindingFactory factory = BindingDirectory.getFactory(SystemInfo.class);
        IMarshallingContext context = factory.createMarshallingContext();
        context.setIndent(4);
        context.marshalDocument(this, "UTF-8", null, xml);
    } catch (JiBXException e) {
        throw new DictionaryException("Failed to create System Info", e);
    }
}
Also used : IMarshallingContext(org.jibx.runtime.IMarshallingContext) IBindingFactory(org.jibx.runtime.IBindingFactory) JiBXException(org.jibx.runtime.JiBXException) DictionaryException(org.alfresco.service.cmr.dictionary.DictionaryException)

Example 23 with IBindingFactory

use of org.jibx.runtime.IBindingFactory in project alfresco-repository by Alfresco.

the class SystemInfo method createSystemInfo.

/**
 * Create System Info from XML representation
 *
 * @param xml  xml representation of system info
 * @return  the System Info
 */
public static SystemInfo createSystemInfo(InputStream xml) {
    try {
        IBindingFactory factory = BindingDirectory.getFactory(SystemInfo.class);
        IUnmarshallingContext context = factory.createUnmarshallingContext();
        Object obj = context.unmarshalDocument(xml, null);
        return (SystemInfo) obj;
    } catch (JiBXException e) {
        throw new DictionaryException("Failed to parse System Info", e);
    }
}
Also used : IUnmarshallingContext(org.jibx.runtime.IUnmarshallingContext) IBindingFactory(org.jibx.runtime.IBindingFactory) JiBXException(org.jibx.runtime.JiBXException) DictionaryException(org.alfresco.service.cmr.dictionary.DictionaryException)

Aggregations

IBindingFactory (org.jibx.runtime.IBindingFactory)23 IUnmarshallingContext (org.jibx.runtime.IUnmarshallingContext)14 IMarshallingContext (org.jibx.runtime.IMarshallingContext)10 InputStream (java.io.InputStream)5 FileWriter (java.io.FileWriter)3 Writer (java.io.Writer)3 URL (java.net.URL)3 Configuration (org.exoplatform.container.xml.Configuration)3 Test (org.junit.Test)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 DictionaryException (org.alfresco.service.cmr.dictionary.DictionaryException)2 Component (org.exoplatform.container.xml.Component)2 ObjectParameter (org.exoplatform.container.xml.ObjectParameter)2 JiBXException (org.jibx.runtime.JiBXException)2 Controller (com.iggroup.oss.restdoclet.doclet.type.Controller)1 Service (com.iggroup.oss.restdoclet.doclet.type.Service)1 Services (com.iggroup.oss.restdoclet.doclet.type.Services)1 FileInputStream (java.io.FileInputStream)1