Oxerp uses a custom marshaller/unmarshaller. The classes of this marshaller are under packages org.oxerp.xml.*.
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>
-
Tag class, attribute name : the class to marshal
-
Tag field, attribute name : a java attribute in the class if direct is set to true, a set/get couple method if not
-
Tag field, attribute type : string, java.lang.String, date, java.util.Date, integer, int, double, long, short, boolean, double, float are all default basic types. You can put another class described by the mapping file in the type attribute.
-
Tag field, attribute collection : if set to collection a java.util.List is expected, if set to "set", a java.util.Set is expected
-
Tag bind-xml : the xml counterpart of the field, xml attribute or xml sub-element
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"/>
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();