Access Castor mapping file in a different jar
main file CastorConversion.java uses the other 3 files(CustList.java,Customer.java and mapping.xml) to convert a java object
to XML.This is working fine when all these files are in the same jar file.But what should be done to generate an output xml
if all the 3 java files are in a separate jar and the mapping xml file is in a different jar.What will be the corresponding changes in the code
CastorConversion.java
public class CastorConversion
{
public static void main(String args[])
{
Customer cust1 = new Customer();
CustList custlist = new CustList();
cust1.setName("Tarun Arora");
cust1.setSex("Male");
cust1.setAge("25");
custlist.addCustomer(cust1);
try{
Mapping xmlMap = new Mapping();
xmlMap.loadMapping("mapping1.xml");
Marshaller marshaller = new Marshaller(new FileWriter("customer1.xml"));
marshaller.setMapping(xmlMap);
marshaller.marshal(custlist);
}
catch(Exception e)
{
System.out.println("Exception: "+e.getMessage());
}
}
}
CustList.java
public class CustList
{
private List customer = new ArrayList();
public void addCustomer(Customer cust)
{
customer.add(cust);
}
public List getCustomer()
{
return customer;
}
}
Customer.java
public class Customer
{
private String name;
private String sex;
private String age;
public String getAge()
{
return age;
}
public void setAge(String age)
{
this.age = age;
}
and get set methods of the other attributes.
}
mapping.xml
<?xml version="1.0"?>
<mapping>
<class name= "CustList">
<field name="customer" type="Customer" collection="arraylist">
<bind-xml name="CUSTOMER"/>
</field>
</class>
<class name="Customer">
<field name="name" type="string">
<bind-xml name="NAME" node="element" />
</field>
<field name="sex" type="string">
<bind-xml name="SEX" node="element" />
</field>
<field name="age" type="string">
<bind-xml name="AGE" node="element" />
</field>
</class>
</mapping>

