Codehaus XFire

Documentation

Quicklinks

Developers

Sponsors

JAXB 2.0

If you are on Java 5, you might want to consider using the JAXB 2.0 support in XFire. It also allows you to customize your classes via annotations, but it also supports a march larger set of XML schema than these annotations.



Working in Java 5

Everything mentioned above will still work in Java 5.0 but you will get several additional features:

  1. Support for Generics and Collections
  2. Enum Support
  3. Ability to use Attributes to control naming
  4. Nice integration with XFire's JSR 181 support

Of the above generics and enums should work out of the box. Just declare and use.

Aegis Annotations

Lets say we would like to control the naming of our elements again. Via annotations it would look like so:

import org.codehaus.xfire.aegis.type.java5.XmlElement;

@XmlType(namespace="urn:north-pole:operations")
public class Employee
{
  private String name;
  private String title;

  @XmlElement(name="Name", namespace="urn:north-pole:operations")
  public String getName() { return name; }
  public void setName(String name) { this.name = name; }

  @XmlElement(name="Title", namespace="urn:north-pole:operations")
  public String getTitle() { return title; }
  public void setTitle(String title) { this.title = title; }
}


Notice, annotations are declared on the read method of a property.

Voila, this should serialize as:

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


You could of course use the XmlAttribute type as well:

import org.codehaus.xfire.aegis.type.java5.XmlElement;
...
public class Employee
{
  private String name;
  private String title;

  @XmlAttribute(name="Name", namespace="urn:north-pole:operations")
  public String getName() { return name; }
  public void setName(String name) { this.name = name; }

....
}


This would serialize as:

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


You can also prevent a property from appearing in the WSDL by using the IgnoreProperty:
import org.codehaus.xfire.aegis.type.java5.IgnoreProperty;
..
public class Employee
{
  private String password;

  @IgnoreProperty
  public String getPassword() {return password;}

  ...
}