Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically.
Carlos Martins Getting Started with Juffrou-XML-SpringJuffrou-XML-Spring is the implementation of springframework's (spring-oxm) Marshaller and Unmarshaller interfaces using Juffrou-XML.
To start using Juffrou-XML in your maven project just add the following dependency:
<dependency> <groupId>net.sf.juffrou</groupId> <artifactId>juffrou-xml-spring</artifactId> <version></version> </dependency>
Download the file juffrou--bundle.zip from the website and extract it's contents to a temporary directory.
Add juffrou-reflect-.jar, juffrou-xml-.jar and juffrou-xml-spring-.jar to the classpath of your project and you are good to go.
In a spring application context, Juffrou-XML is a bean and can be configured like any other bean in spring.
<bean id="marshaller" class="net.sf.juffrou.xml.JuffrouXmlSpring"> <property name="mappingLocations"> <list> <value>classpath:/net/sf/juffrou/**/*-xml-mapping.xml</value> <value>file:${CONFIG_LOCATION}/juffrou-xml/**/*-xml-mapping.xml</value> </list> </property> </bean>
In the above example spring tells juffrou-xml to load its configuration from several mapping files.
Serializers may be used to convert between the text in an XML element and a complex type. With juffrou-xml-spring you can define your serializers as java beans and thus take advantage of spring's dependency injection mechanism.
For example purposes lets consider the SimpleDateSerializer from the spring-xml reference. First we would define the serializer bean:
<bean id="mySimpleDateSerializerBean" class="net.sf.juffrou.xml.test.dom.SimpleDateSerializer"> <bean id="marshaller" class="net.sf.juffrou.xml.JuffrouMarshaller"> <property name="mappingLocations"> <list> <value>classpath:/net/sf/juffrou/**/*-xml-mapping.xml</value> <value>file:${CONFIG_LOCATION}/juffrou-xml/**/*-xml-mapping.xml</value> </list> </property> </bean>
To use this serializer bean in juffrou-xml you would configure the configuration mapping like the following example:
<?xml version="1.0" encoding="UTF-8"?> <mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://juffrou.sourceforge.net/juffrou-xml" xsi:schemaLocation="http://juffrou.sourceforge.net/juffrou-xml http://juffrou.sourceforge.net/juffrou-xml/schemas/juffrou-xml.xsd"> <root-element xml="Person" type="net.sf.juffrou.xml.test.dom.Person"> <attribute property="firstName" xml="name" /> <element property="lastName" xml="Surname" /> <element property="birthDay" xml="birthday"> <serializer bean="mySimpleDateSerializerBean"/> </element> </root-element> </mapping>