Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Getting class data from a jar file (or otherwise)

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
TonyLB
LXF regular


Joined: Tue Apr 12, 2005 8:08 pm
Posts: 112
Location: Wirral, UK

PostPosted: Sun Oct 22, 2006 3:39 pm    Post subject: Getting class data from a jar file (or otherwise) Reply with quote

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
Back to top
View user's profile Send private message
chan_0x0c



Joined: Wed Nov 15, 2006 10:11 am
Posts: 3

PostPosted: Sat Dec 02, 2006 6:06 am    Post subject: Since nobody's responding, i'll pickup the slack. Reply with quote

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
Back to top
View user's profile Send private message
TonyLB
LXF regular


Joined: Tue Apr 12, 2005 8:08 pm
Posts: 112
Location: Wirral, UK

PostPosted: Sun Dec 03, 2006 9:51 pm    Post subject: RE: Since nobody Reply with quote

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)
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast