users@jaxb.java.net

Re: Specifying Interfaces that generated classes extend/implement

From: Erik Ostermueller <Erik.Ostermueller_at_alltel.com>
Date: Mon, 10 Mar 2003 12:14:48 -0600

Ryan wrote:
> The team frequently discusses this topic internally, so
> please continue to send us
> your ideas and requirements so that we can explore
> adding them to the next major
> release.

Ryan,

I have brought Castor databinding into our development group.
I custom-coded support in Castor to generate implements statements
into our value objects (sure is nice to have the source code. ;-) ).
I just ran across the doc I wrote for my developers. Here it is:


It is a trivial matter to generate an implements statement for an 'empty' interface like java.io.Serializable. It does not implement any methods (see Sun's API JavaDoc). As such, when compiling the Value Object, the Java compiler is dealing with a very weak contract. It does not have to force your class (by means of compiler errors) to implement any methods. If, on the other hand, you implement an interface that does indeed contain methods, you will have some work to do to get your generated Value Objects to compile.

It makes sense to code-generate an implements statement to which your generated Value Object can adhere when compiled. The main way of making a Value Object adhere to a particular interface is by altering the XML schema from which it is generated.

Assume you want to implement an interface that looks like this:
public interface Notifiable {
public String getEmailAddress();
}
Your XML schema must look something like this:
                <xsd:complexType>
                        <xsd:sequence>
                                <xsd:element name="EmailAddress"
                                                                type="xsd:string">
The SourceGenerator adds getter and setter methods based on the names of the XSD schema data items. The SourceGenerator will find EmailAddress in the schema (as shown above) and will prefix it with the word 'get' to come up with the getEmailAddress() name for the getter.



--Erik Ostermueller