-----
Aegis Binding
-----
XFire User's Guide
-----
Aegis Binding
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 "YourBean."
Fore example, the java class:
+---------------------------------------------------------------------------------------------------------------------+
public class Employee
{
private String name;
private String title;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getTitle() { return title; }
public void setTitle(String title) { this.title = title; }
}
+---------------------------------------------------------------------------------------------------------------------+
In XML this translates to:
+---------------------------------------------------------------------------------------------------------------------+
Santa Claus
Chief Present Officer (CPO)
+---------------------------------------------------------------------------------------------------------------------+
In XML Schema this would become a complex type:
+---------------------------------------------------------------------------------------------------------------------+
+---------------------------------------------------------------------------------------------------------------------+
Note that <<< >>> is used to configure methods on your service and 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:
+---------------------------------------------------------------------------------------------------------------------+
+---------------------------------------------------------------------------------------------------------------------+
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:
+---------------------------------------------------------------------------------------------------------------------+
Santa Claus
Chief Present Officer (CPO)
+---------------------------------------------------------------------------------------------------------------------+
* Ignoring properties
If you don't want to serialize a certain property it is easy to ignore it:
+---------------------------------------------------------------------------------------------------------------------+
+---------------------------------------------------------------------------------------------------------------------+
* Handling Collections
You undoubtedly use Collections in your code. Pre Java 5 it is impossible to determine the "component type" of a
Collection by introspection. So you need to give Aegis some hints. For a service which returned a Collection of
employees like so:
+---------------------------------------------------------------------------------------------------------------------+
public class EmployeeService
{
Collection getEmployees(String id) { ... }
}
+---------------------------------------------------------------------------------------------------------------------+
You would need to supply metadata which gave the component type in a mapping file like this one:
+---------------------------------------------------------------------------------------------------------------------+
+---------------------------------------------------------------------------------------------------------------------+
* Handling Maps
Java Maps don't map well to XML Schema (no pun intended) because there is no Map concept in XML Schema so your
clients. Maps are transformed to a collection of {key, value} tuples instead. In addition to providing the type of
the value, you must also provide Aegis with the type of the key:
+---------------------------------------------------------------------------------------------------------------------+
public class GiftService
{
Map getGiftList() { /* returns a map of NiceChild => Present */ }
}
+---------------------------------------------------------------------------------------------------------------------+
The mapping file should look like this:
+---------------------------------------------------------------------------------------------------------------------+
+---------------------------------------------------------------------------------------------------------------------+
This will generate the following type:
+---------------------------------------------------------------------------------------------------------------------+
+---------------------------------------------------------------------------------------------------------------------+
Interfaces and Aegis
The Aegis binding will automatically create proxies for your interfaces when reading XML. So if you have an interface
like this:
+---------------------------------------------------------------------------------------------------------------------+
public interface User {
public String getUsername();
public String getPasswrod();
}
+---------------------------------------------------------------------------------------------------------------------+
It will then create its own implementation of User and provide a username and password from the XML. You can specify
your implementation class (in 1.1+) by setting a property on your service:
+---------------------------------------------------------------------------------------------------------------------+
Service service = ...;
service.setProperty("com.acme.User.implementation", "com.acme.UserImpl");
+---------------------------------------------------------------------------------------------------------------------+