A
Ajay Singh Tomar
Hello,
I couldn't locate how to invoke get and set methods from the Java code with
Binding Definition for JIBX as given below.
<binding>
<mapping name="customer" class="Customer">
<structure name="person" field="person">
<value name="cust-num" get-method="getNumber" set-method="setNumber" />
<value name="first-name" field="firstName" />
<value name="last-name" field="lastName" />
</structure>
<value name="street" field="street" />
<value name="city" field="city" />
<value name="state" field="state" />
<value name="zip" field="zip" />
<value name="phone" field="phone" />
</mapping>
</binding>
This is the Java file for calling the methods. Please tell me what needs to
be modified here.
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.jibx.runtime.BindingDirectory;
import org.jibx.runtime.IBindingFactory;
import org.jibx.runtime.IMarshallingContext;
import org.jibx.runtime.IUnmarshallingContext;
public class Customer
{
public Customer()
{
try
{
IBindingFactory bfact = BindingDirectory.getFactory(Customer.class);
IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
Object obj = uctx.unmarshalDocument(new FileInputStream("input.xml"), null);
Customer cst = new Customer ();
cst.setNumber(4);
IMarshallingContext mctx = bfact.createMarshallingContext();
mctx.setIndent(4);
mctx.marshalDocument(obj, "UTF-8", null,new FileOutputStream("output.xml"));
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
public static void main(String[] args)
{
Customer test1 = new Customer ();
}
}
Please help.
Regards,
Ajay
I couldn't locate how to invoke get and set methods from the Java code with
Binding Definition for JIBX as given below.
<binding>
<mapping name="customer" class="Customer">
<structure name="person" field="person">
<value name="cust-num" get-method="getNumber" set-method="setNumber" />
<value name="first-name" field="firstName" />
<value name="last-name" field="lastName" />
</structure>
<value name="street" field="street" />
<value name="city" field="city" />
<value name="state" field="state" />
<value name="zip" field="zip" />
<value name="phone" field="phone" />
</mapping>
</binding>
This is the Java file for calling the methods. Please tell me what needs to
be modified here.
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.jibx.runtime.BindingDirectory;
import org.jibx.runtime.IBindingFactory;
import org.jibx.runtime.IMarshallingContext;
import org.jibx.runtime.IUnmarshallingContext;
public class Customer
{
public Customer()
{
try
{
IBindingFactory bfact = BindingDirectory.getFactory(Customer.class);
IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
Object obj = uctx.unmarshalDocument(new FileInputStream("input.xml"), null);
Customer cst = new Customer ();
cst.setNumber(4);
IMarshallingContext mctx = bfact.createMarshallingContext();
mctx.setIndent(4);
mctx.marshalDocument(obj, "UTF-8", null,new FileOutputStream("output.xml"));
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
public static void main(String[] args)
{
Customer test1 = new Customer ();
}
}
Please help.
Regards,
Ajay