Getting class data from a jar file (or otherwise)

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

Getting class data from a jar file (or otherwise)

Postby TonyLB » Sun Oct 22, 2006 2:39 pm

I'm building an app which lets users drag and drop classes into a tree,
followed by code generation. For this, I need to have (a) a list of all
the classes which can be dragged and (b) for each class, which of the
others can be a parent in the tree.

All the relevant classes are in a jar file (j3dcore.jar) as well as
other abstract classes and there is standard generated documentation.

Any idea how I could extract the relevant data? Hand coding it would be
just too much?

The only idea I've had so far is to use Python to strip all the documentation and extract what I need from that.

Tony
TonyLB
LXF regular
 
Posts: 112
Joined: Tue Apr 12, 2005 7:08 pm
Location: Wirral, UK

Since nobody's responding, i'll pickup the slack.

Postby chan_0x0c » Sat Dec 02, 2006 6:06 am

Sounds like you want to automate the extraction of infomoation of classss.

I won't give you a step-by-step instruction, but following the tradition
of beg, borrow, steal, then write, there's a guy who's done half of your work.
Ian F Darwin For Java CookBook 2ndEd, Ch25.7.
code: http://javacook.darwinsys.com/

introspection/CrossRef.java

The idea follows like this.

For the jar file you want to inspect, extract the jar file, by unzipping it.
now we have a bunch of class, so for each class, we use the
java.lsng.Class, and java.lang.reflect
and hack out the infomation.

They allow you to obtain what the class contains, what method thay have,
what parent they are from, and anything else that the Java doc contains,
you will be able to obtain the infomation.

In a nutshell, the javadoc IS made from using these, so there isn't any suprise here.

The good thing about these, is that the code could be made for classes that are not
even existing yet. Also it it good to note, (or ovious from reading the javadoc) that
you can dianmically construct classes, and inveoke methods on the fly, and such if
the desire to do so ever arises.


The reflection class is probably what you will need.

I don't quite follow waat you mean by 'class that you can drag', but
here's my (or Ian's) $0.02 worth of note.


happy hacking

chan_0x0c

p.s. javadoc is your friend.
cat * | w3m -dump -T text/html |grep does wonders
chan_0x0c
 
Posts: 3
Joined: Wed Nov 15, 2006 10:11 am

RE: Since nobody

Postby TonyLB » Sun Dec 03, 2006 9:51 pm

Thanks Chan.

I'd got as far as extracting the class names from the jar files and dumping anything that was abstract or an interface, but hadn't thought of pulling the methods out.

What I'm doing it building an IDE which lets you drag Java3D objects into a tree structure which represents the Java3D scenegraph. There have to be controls on what is allowed to be added to a particular node since it is only what a particular class will allow (eg a Leaf can be a child of a Group node, but not vv). Once the tree has been built is can then be converted into java source code.

It's getting there slowly.

Tony
In the beginning was nothing, which exploded! (Lords and Ladies, Terry Pratchett)
TonyLB
LXF regular
 
Posts: 112
Joined: Tue Apr 12, 2005 7:08 pm
Location: Wirral, UK


Return to Programming

Who is online

Users browsing this forum: No registered users and 2 guests