• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic