users@jaxb.java.net

Generating Code...Factories? Interfaces?

From: Eric DeFazio <mdefazio_at_AMENTRA.COM>
Date: Sun, 23 Mar 2003 22:41:10 -0700

Good evening, I recently downloaded the WSDP and tested out JAXB as a replacement for XML DataBinding that we currently "Home - Cooked" on a project...

I did not throughly try everything that JAXB has to offer, but from what I have seen, I did have a few questions/comments.

Rather than discribe my misgivings, I'd like to rather propose my ideal solution, and then maybe someone can give me some direction on how I may get there...

What I would like would be to have an XML binding framework which could accept an XML Schema, and Generate a Factory which would know how to produce/validate objects which implement the generated interface.

i.e. (forgive my incorrect XML Schema, but, for effect):

<PRE>
<xml>
<xsd:complexType>
  <xsd:element name="Name" type="xsd:string" length="10"/>
</xsd:complexType>
</PRE>

would produce:

public interface Generated
{
   public static final BindingFactory = GeneratedFactory.getInstance();
   public String getName();
   public void setName();
}

AND

public class GeneratedFactory
    implements BindingFactory
{
   //this would be a singleton with a getInstance method

   public Document getXMLForObject(Generated lInstance)
          throws XMLBindException
   {
         //..code to create a DOM from the instance
   }
   public Generated createObjectFromXML(Document)
          throws XMLBindException
   {
        //..code to create an Instance from XML
   }
   //there could be other methods as well, like a validate, etc. etc.
}

...The generator (similar to the xjc ANT task and underlying classes) could also create "Clean" JavaBean ValueObjects which implemented all the getter/setter methods, but the big difference is that they don't contain all the extra serialization code and Validation Code (All that code is in the Factories).

This way, I can do more with JaxB, (i.e. intergrate it with my existing Systems without having to hassle to much with the code...) I could just have my value objects implement the appropriate interfaces, and the Factory will do all the ugly work.

In addition to the value add of allowing better usability I think overall it's better design than generating these JavaBeans which have all these methods which are only used in Serialization/Deserialization.

Anyways, that is what I am shooting for, anyone have any ideas of how to get there... the only thing I can see at this point would be to modify the JAXB code to do this...

Thanks,
Eric