File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Generating classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Generating classes" Watch "Generating classes" New topic
Author

Generating classes

jeff mutonho
Ranch Hand

Joined: Apr 30, 2003
Posts: 271
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
Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
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 ]
Ken Krebs
Ranch Hand

Joined: Nov 27, 2002
Posts: 451
You may also want to take a look at CGLIB for an easier way to do this.


kktec<br />SCJP, SCWCD, SCJD<br />"What we observe is not nature itself, but nature exposed to our method of questioning." - Werner Heisenberg
jeff mutonho
Ranch Hand

Joined: Apr 30, 2003
Posts: 271
I found XJR which seems to be what I'm looking for , but the documentation sux!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Generating classes
 
Similar Threads
Inherited parameter classes in method invocation (reflection API)
Inhertiting complex type in XML Schema
Rendering XML
Free text in XML
problem encountered while using jsp:getProperty tag