Controlling Mappings with XML

Its easy to control how your service and its beans are mapped to xml. Mapping files provide a way to do this without modifying your code at all. But, most of this can be done through Java generics or annotations as well. (Most of this was developed for XFire users originally on Java 1.4)

Mapping files must exist in the same package as your bean or service class on the class path. In the above example the mapping file would be named "/org/codehaus/xfire/Employee.aegis.xml", with the following format:

<mappings>
  <mapping uri="" name="">
    <method name="methodName">
      <return-type mappedName="" componentType=""/>
      <parameter index="" mappedName=""/>
    </method>
    <property name="" mappedName="" style="attribute|element" componentType=""/>
  </mapping>
</mappings>

When you are creating ClassName.aegis.xml files to control type mapping, you will have only one mapping element, and you don't need any attributes on the mapping element. You use property elements to specify how to map your properties. You must supply name= to select the property. There are more examples of specific cases below.

Note that <method> is used to configure methods on your service and <property> is used to configure properties on your javabeans.
The above example highlights many of the possible elements, most are optional and the format encourages minimally specified mappings.

Controlling Naming

Lets pretend that in the above example you would like the elements names to be capatilized and in the namespace "urn:north-pole:operations". You could achieve this through a mapping file like so:

<mappings xmlns:np="urn:north-pole:operations">
  <mapping name="np:Employee">
    <property name="name" mappedName="Name"/>
    <property name="title" mappedName="Title"/>
  </mapping>
</mappings>

Notice that the namespace was declared on the mappings element and then the prefix was used to specify the element QNames for the name/title properties.

This will result in a mapping like so:

<np:Employee xmlns:np="urn:north-pole:operations">
  <np:Name>Santa Claus</np:Name>
  <np:Title>Chief Present Officer (CPO)</np:Title>
</np:Employee>

Ignoring properties

If you don't want to serialize a certain property it is easy to ignore it:

<mappings>
  <mapping>
    <property name="propertyName" ignore="true"/>
  </mapping>
</mappings>

Controlling minOccurs and nillable

The default Aegis mapping is to assume that, since any Java object can be null, that the corresponding schema elements should have minOccurs of 0 and nillable of true. There are properties on the mappings for to control this.

<mappings>
  <mapping>
    <property name='everpresentProperty' minOccurs='1' nillable='false'/>
 </mapping>
<mappings>

Using the Aegis basic types

In order to make use of the various types that Aegis provides in the "org.apache.cxf.aegis.type.basic" package, follow this example which allows the wsdl to use the "xsd:date" instead of the "xsd:dateTime".

<mappings xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<mapping>
		<property name="birthDate" 
			type="org.codehaus.xfire.aegis.type.basic.DateType" 
			typeName="xsd:date"
			/>
	</mapping>
</mappings>