Aegis Databinding has been edited by Benson Margulies (Sep 10, 2007).

(View changes)


Why Aegis?

Aegis is a fast StAX based data-binding that makes developing code first services as simply as possible. It is able to handle most classes and create intelligent schemas for them.

Features include:

  • No annotations are needed to expose classes
  • Support for interfaces
  • Support for collections including Maps
  • Support for a wide variety of datatypes

Using Aegis

To configure your Server or Client to use the Aegis databinding, you'll need to configure your ServerFactoryBean and ClientFactoryBeans to use the Aegis databinding.

Spring Configuration

<bean id="aegisBean" class="org.apache.cxf.aegis.databinding.AegisDatabinding"/> 
 <bean id='jaxws-and-aegis-service-factory' class=""> 
        <property name="dataBinding" ref="aegisBean"/>
                 <property name="serviceConfigurations">
                       <bean class=""/>
                       <bean class="org.apache.cxf.aegis.databinding.AegisServiceConfiguration"/>
                       <bean class="org.apache.cxf.service.factory.DefaultServiceConfiguration"/> 

 <jaxws:endpoint id="my_service_endpoint" implementor="#my-service" address="/MyIndex">
   <ref bean='jaxws-and-aegis-service-factory' />

Java configuration

import org.apache.cxf.aegis.databinding.AegisDatabinding;
import org.apache.cxf.frontend.ServerFactoryBean;

ServerFactoryBean sf = new ServerFactoryBean();
sf.getServiceFactory().setDataBinding(new AegisDatabinding());

Similarly, you'll need to set up the client side:

import org.apache.cxf.aegis.databinding.AegisDatabinding;
import org.apache.cxf.frontend.ClientProxyFactoryBean;

ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
factory.getServiceFactory().setDataBinding(new AegisDatabinding());
MyService client = (MyService) factory.create();

XFire Compatability

If you need to ensure that your service is backward compatabile with XFire, you'll want to add one other line:

import org.apache.cxf.aegis.databinding.AegisServiceConfiguration;

sf.getServiceFactory().getServiceConfigurations().add(0, new AegisServiceConfiguration());

This will the change the namespaces that CXF generates by default so that they are the same as XFire would generate.

Class <-> XML 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 "" with the local name "Employee"

Fore example, the java class:

public class Employee
  private String name;
  private String title;

  public String getName() { return name; }
  public void setName(String name) { = name; }

  public String getTitle() { return title; }
  public void setTitle(String title) { this.title = title; }

In XML this translates to:

<Employee xmlns="">
  <name>Santa Claus</name>
  <title>Chief Present Officer (CPO)</title>

In XML Schema this would become a complex type:

<xsd:complexType name="Employee">
    <xsd:element name="name" type="xsd:string" minOccurs="0" maxOccurs="1/>
    <xsd:element name="title" type="xsd:string" minOccurs="0" maxOccurs="1/>
Validate your mapping!

You can find an XML Schema for Aegis mapping files here.
This version of the XML schema has comments to explain the bits and pieces.

Supported Types

  • Basic types: int, double, float, long, byte[], short, String, BigDecimal
  • Arrays
  • Collections - including Maps
  • 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.)

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.

ServerFactoryBean sf = new ServerFactoryBean();
AegisDatabinding db = new AegisDatabinding();

DefaultTypeMappingRegistry tmr = (DefaultTypeMappingRegistry)db.getTypeMappingRegistry();
// here we disuade XFire from its rather annoying tendency to assume that, just because
// anything in Java can be null, that we want to advertise all that nullity all over.
Configuration configuration = tmr.getConfiguration();


More Information....

This section is under construction. For more information about how the Aegis databinding works, please check out the Aegis documentation at the XFire site.

Powered by Atlassian Confluence (Version: 2.2.9 Build:#527 Sep 07, 2006) - Bug/feature request

Unsubscribe or edit your notifications preferences