Aegis is the default XFire binding which maps XML to POJOs. It supports code first development only at this point - i.e. you write your service in POJOs and it will generate the XML schema/wsdl for you.
XML and Annotation Mapping Overview
Aegis has a flexible mapping system so you can control how your beans are controlled. By default your POJOs are serialized based on their name and namespaces. If you have a class in the "org.codehaus.xfire" package named "Employee" it would be serialized in namespace "http://xfire.codehaus.org" with the local name "Employee"
Fore example, the java class:
In XML this translates to:
In XML Schema this would become a complex type:
- Basic types: int, double, float, long, byte, short, String, BigDecimal
- Dates: java.util.Date, java.util.Calendar, java.sql.Timestamp, java.sql.Date, java.sql.Time
- XML: org.w3c.dom.Docmument, org.jdom.Element, XMLStreamReader, Source
- Complex types which are aggregations of the above
If you have constructors defined in your Java beans, make sure a default constructor (i.e. no arguments) is also declared. (Aegis needs a no-argument contstructor to instantiate client Java classes.)
Controlling Mappings with XML
Its easy to control how your service and its beans are mapped to xml. If you are using Java 5.0 skip straight down to that section otherwise read on to learn how to configure serialization via mapping files.
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:
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.
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:
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:
If you don't want to serialize a certain property it is easy to ignore it:
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.
Using the Aegis basic types
In order to make use of the various types that Aegis provides in the "org.codehaus.xfire.aegis.type.basic" package, follow this example which allows the wsdl to use the "xsd:date" instead of the "xsd:dateTime".
Setting Default minOccurs and nillable Parameters from Java
If you have many properties, and you want most, or all of them, to have a minOccurs other than 0 or a nillable other than false, you can change the defaults for Aegis from Java code (amongst other places).
Here is an example: it extracts the binding provider from the service factory, and changes the configuration parameters.