[Home] [By Thread] [By Date] [Recent Entries]

  • To: xml-dev@l...
  • Subject: Dynamically generating Java 'wrapper' class for XML
  • From: Oswald Campesato <ocampesato@y...>
  • Date: Tue, 15 Feb 2005 16:57:51 -0800 (PST)
  • Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
  • Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; b=hvh6H834ENdFaaI51dwSA+jvnepf4mMTJWDejnSJ60n0+98MpuIBeej7PdMaVVAVVU1qwbbzRfEAuEM1b5YvI1KEOTFhJFN61DcWXqiUKhahTVB7ssV8XXRt7oBkaYx3bD/0vkb6NwHS7D1dyI6kEsywzYwFNfmUtyrgVzaGwHM= ;

Hello, everyone:

I need to dynamically generate a Java class that
will expose a methods for each element of a given
XML document. 

For example, suppose I have this XML document:
---------------------
<quote>
  <name>Oracle</name>
  <loc>RWS</loc>
  <asset>
     <name>ST</name>
     <loc>400</loc>
  </asset>
  <asset>
     <name>CRM</name>
     <location>600</location>
  </asset>
....
</quote>
---------------------

I need to generate a Java class with the following:

public String getQuoteName() 
{ 
   quote.getName(); 
}

public String getAssetName() 
{ 
   quote.getAsset().getName(); 
}

public String getAssetLoc()  
{ 
   quote.getAsset().getLoc(); 
}
....

where 'quote' is a JAXB-based instance of a 
Java class corresponds to an unmarshalled 
instance of the preceding XML document.

The Java wrapper class needs to be generated 
each time an XSD is modified, and it will be
invoked by a third-party product in order to 
modify the contents of an XML document.

I was thinking of using JAXB 2.0 to generate the
Java binding classes associated with an XSD, and
then use introspection to determine the existing
methods, and then iterate over those methods to
generate the Java wrapper class.

Does this seem like a good approach, or is there
a more 'elegant' approach?  Hopefully this makes
sense:)

Regards,

Oswald



Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member