Juffrou-XML-Spring Reference Documentation This document refers to version of the Juffrou-XML-Spring.

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-Spring

Introduction

Juffrou-XML-Spring is the implementation of springframework's (spring-oxm) Marshaller and Unmarshaller interfaces using Juffrou-XML.

Installing

Maven projects

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>
This will allow you access the source code of the library as well as the javadoc files, if you have checked the options "download artifact sources" and "download atifact javadoc in your IDE."

Non maven projects

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.

Configuring Juffrou-XML though Spring

In a spring application context, Juffrou-XML is a bean and can be configured like any other bean in spring.

Juffrou-XML Spring Configuration

    <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.

Defining serializers as spring beans

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>