Search in sources :

Example 16 with IBindingFactory

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

the class TestConfigurationService method testMarshallAndUnmarshall.

public void testMarshallAndUnmarshall() throws Exception {
    String basedir = System.getProperty("basedir");
    ConfigurationUnmarshaller unmarshaller = new ConfigurationUnmarshaller();
    URL url = TestConfigurationService.class.getResource("../../../../configuration.xml");
    Object obj = unmarshaller.unmarshall(url);
    IBindingFactory bfact = BindingDirectory.getFactory(Configuration.class);
    IMarshallingContext mctx = bfact.createMarshallingContext();
    mctx.setIndent(2);
    mctx.marshalDocument(obj, "UTF-8", null, new FileOutputStream(basedir + "/target/configuration.xml"));
}
Also used : IMarshallingContext(org.jibx.runtime.IMarshallingContext) IBindingFactory(org.jibx.runtime.IBindingFactory) FileOutputStream(java.io.FileOutputStream) URL(java.net.URL)

Example 17 with IBindingFactory

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

the class TestConfigurationXML method testSystemPropertyResolving.

public void testSystemPropertyResolving() throws Exception {
    System.setProperty("c_value", "c_external_value");
    System.setProperty("d_value", "d_external_value");
    System.setProperty("false_value", "false");
    System.setProperty("true_value", "true");
    System.setProperty("FALSE_value", "FALSE");
    System.setProperty("TRUE_value", "TRUE");
    System.setProperty("integer_value", "5");
    System.setProperty("long_value", "41");
    System.setProperty("double_value", "172.5");
    // 
    IBindingFactory bfact = BindingDirectory.getFactory(XMLObject.class);
    IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
    URL url = TestConfigurationXML.class.getResource("../../../../test-resolved-property.xml");
    Configuration conf = (Configuration) uctx.unmarshalDocument(url.openStream(), null);
    assertNotNull(conf);
    // 
    Component component = conf.getComponent("component");
    assertNotNull(component);
    // 
    assertValueParam("a_value", component, "a");
    assertValueParam("${b_value}", component, "b");
    assertValueParam("c_external_value", component, "c");
    assertValueParam("_d_external_value_", component, "d");
    // 
    assertPropertyParam("a_value", component, "e", "e_a");
    assertPropertyParam("${b_value}", component, "e", "e_b");
    assertPropertyParam("c_external_value", component, "e", "e_c");
    assertPropertyParam("_d_external_value_", component, "e", "e_d");
    // 
    ObjectParameter o = component.getInitParams().getObjectParam("f");
    assertNotNull(o);
    Person p = (Person) o.getObject();
    assertNotNull(p);
    assertEquals("a_value", p.address_a);
    assertEquals("${b_value}", p.address_b);
    assertEquals("c_external_value", p.address_c);
    assertEquals("_d_external_value_", p.address_d);
    assertEquals(true, p.male_a);
    assertEquals(false, p.male_b);
    assertEquals(true, p.male_c);
    assertEquals(false, p.male_d);
    assertEquals(true, p.male_e);
    assertEquals(false, p.male_f);
    assertEquals(4, p.age_a);
    assertEquals(5, p.age_b);
    assertEquals(40, p.weight_a);
    assertEquals(41, p.weight_b);
    assertEquals(172.4D, p.size_a);
    assertEquals(172.5D, p.size_b);
}
Also used : IUnmarshallingContext(org.jibx.runtime.IUnmarshallingContext) Configuration(org.exoplatform.container.xml.Configuration) IBindingFactory(org.jibx.runtime.IBindingFactory) ObjectParameter(org.exoplatform.container.xml.ObjectParameter) Component(org.exoplatform.container.xml.Component) URL(java.net.URL)

Example 18 with IBindingFactory

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

the class TestDataXML method testMarshallAndUnmarshall.

public void testMarshallAndUnmarshall() throws Exception {
    String projectdir = System.getProperty("basedir");
    IBindingFactory bfact = BindingDirectory.getFactory(XMLObject.class);
    IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
    URL url = TestDataXML.class.getResource("../../../../object.xml");
    Object obj = uctx.unmarshalDocument(url.openStream(), null);
    IMarshallingContext mctx = bfact.createMarshallingContext();
    mctx.setIndent(2);
    mctx.marshalDocument(obj, "UTF-8", null, new FileOutputStream(projectdir + "/target/object.xml"));
}
Also used : IUnmarshallingContext(org.jibx.runtime.IUnmarshallingContext) IMarshallingContext(org.jibx.runtime.IMarshallingContext) IBindingFactory(org.jibx.runtime.IBindingFactory) FileOutputStream(java.io.FileOutputStream) XMLObject(org.exoplatform.xml.object.XMLObject) URL(java.net.URL)

Aggregations

IBindingFactory (org.jibx.runtime.IBindingFactory)18 IUnmarshallingContext (org.jibx.runtime.IUnmarshallingContext)10 IMarshallingContext (org.jibx.runtime.IMarshallingContext)9 FileWriter (java.io.FileWriter)3 Writer (java.io.Writer)3 URL (java.net.URL)3 Configuration (org.exoplatform.container.xml.Configuration)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Component (org.exoplatform.container.xml.Component)2 ObjectParameter (org.exoplatform.container.xml.ObjectParameter)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 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1