October 18th 2003 oXerp Documentation SourceForge.net Logo
Introduction Installation Create a company Create a partner Create a product Create an order Create an invoice Customize invoice Customize payment conditions Import-export Close a period Marshalling java-xml Understand config files Add extra info to an object
Marshalling java-xml
Principles

Oxerp uses a custom marshaller/unmarshaller. The classes of this marshaller are under packages org.oxerp.xml.*.

Mapping file

The marshaller needs a mapping file to work. This format of the mapping file is compatible with Castor project (org.exolab.xml). As a consequence you can use the XDoclet castor tags to generate this file. A section of the mapping file looks like :

<class name='org.oxerp.xml.test.ClassTest'> <map-to xml='product' /> <field name='categ' type='java.lang.String' direct='true'> <bind-xml name='category' node='attribute' /> </field> <field name='lib' type='string' direct='true'> <bind-xml name='libelle' /> </field> <field name='d' type='date'> <bind-xml name='date' node='attribute' /> </field> <field name='examples' type='string' collection="collection"> <bind-xml name='col-ex' node='element' /> </field> <field name="inner" type="org.oxerp.xml.test.ClassTestInner"> <bind-xml name="inner" /> </field> <field name='inners' type="org.oxerp.xml.test.ClassTestInner" collection="collection"> <bind-xml name='inners' node='element' /> </field> <field name='paymentConditions' type="org.oxerp.xml.test.ClassTestAbstract"> <bind-xml name='payment-conditions' node='element' /> </field> <field name='examplesSet' type='string' collection="set"> <bind-xml name='col-ex-set' node='element' /> </field> </class>

Custom simple types

You can plugin your own simple type. To do that, you add a sub class of org.oxerp.xml.SimpleType, defining format, parse and getClassType methods. Then, you add a "simple-type" section in mapping file (not compatible with Castor mapping file) ; the attribute 'name' defines the virtual simple type ; use it in the 'field' tag for a 'class' element. See org.oxerp.xml.test.SimpleTypeDecimal with oxerp_mapping.xml in oxerp-marshaller.jar (in the client zip for instance)

<simple-type name="decimal" class="org.oxerp.xml.test.SimpleTypeDecimal"/>

API calls

Mapping m = new Mapping(); try { m.loadMapping("oxerp_mapping.xml"); unmarshaller = new Unmarshaller(); unmarshaller.setMapping(m); Reader reader = new BufferedReader(new FileReader(file)); Object o = unmarshaller.unmarshal(reader, ClassTest.class); ClassTest ct = (ClassTest)o; Marshaller marshaller = new Marshaller(); marshaller.setMapping(m); Writer w = new BufferedWriter(new FileWriter(file)); marshaller.marshal(o, w); w.close();