Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Generating classes

 
Ranch Hand
Posts: 271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can I accomplish the following task using reflection?
I have an xml file , part of which is shown below
<tag tagid="TAG001">
<attrib>Tag Id</attrib>
<attrib>SCV Entity</attrib>
<attrib>SCV Action</attrib>
<attrib>Change Time</attrib>
</tag>
I wanna generate classes dynamically with the elements i.e <attrib> under <tag> being the String variables and the class name being "TAG001" .The reason I say dynamically is that the xml is bound to change and have more <attrib> elements in it.I know if the xml was constant , I would use Digester.Any ideas?
jeff
 
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you might be using the wrong term, but let's see.
You can instantiate an object (or implement a class) with reflection. However, that would require an already created class definition. I don't think that's what you want.
You can generate a class definition dynamically with byte code engineering. I think this is what you want. It means, you have no such "TAG001" class existing and you want to dynamically create/compile the class and load it into the JVM. This isn't easy, but you can use BCEL to do this:
http://jakarta.apache.org/bcel
[ January 27, 2004: Message edited by: Robert Paris ]
 
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may also want to take a look at CGLIB for an easier way to do this.
 
jeff mutonho
Ranch Hand
Posts: 271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found XJR which seems to be what I'm looking for , but the documentation sux!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic