473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Extracting class data from a jar

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.

Tony
Oct 22 '06 #1
3 4222
Tony Burrows <to**@tonyburrows.comwrote in
news:pa****************************@tonyburrows.co m:
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.

Tony
I will have to make some assumptions here, because you:
Didn't describe what this tree represents.
Didn't describe what the parent/child relationship is in the tree.
Didn't describe what is in the jar file.
Didn't describe what "relevant data" means to you.

Assuming that:
The jar file contains .class (or .cla) files.
"Relevant data" means classes, their methods and their fields.

Then java reflection may be the answer to your question.
A jar file can be accessed (doesn't need reflection) to reveal the files
within.
Java reflection allows the classes to be loaded and examined for
information about their methods, fields, etc.

If you need more information, I suggest:

"Java Reflection in Action" (In Action series) by Ira R. Forman and Nate
Forman

I am not associated with the authors or the publisher, just a satisfied
reader.

If I guessed wrong (likely), then please write back with more information.

Good Luck!
--
Ian Shef 805/F6 * These are my personal opinions
Raytheon Company * and not those of my employer.
PO Box 11337 *
Tucson, AZ 85734-1337 *
Oct 23 '06 #2
Tony Burrows <to**@tonyburrows.comwrote:
>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.
How do you decide which classes can be dragged, and what can be a parent?
>All the relevant classes are in a jar file (j3dcore.jar) as well as
other abstract classes and there is standard generated documentation.
Typically, a combination of requiring the jar to have a specific config file
or manifest in the jar, and use of reflection on classes listed in that config
does the trick.
>Any idea how I could extract the relevant data? Hand coding it would be
just too much.
How would we know what data is relevant? You can use the
java.util.jar.JarFile class to read contents of a jar (including files and
Manifest entries), and java.lang.Class (either from your classloader via
Class.forName(className) or from a URLClassLoader under your control via
loadClass(classBinaryName).

If this tree is known at build-time for the jar, it's really going to be
easiest to put the relevant data into manifest entries or into a specific XML
file in META-INF that you can read and use, rather than guessing based on
looking at every class in the jar.
--
Mark Rafn da***@dagon.net <http://www.dagon.net/>
Oct 23 '06 #3
On Mon, 23 Oct 2006 20:01:10 +0000, Ian Shef wrote:
Tony Burrows <to**@tonyburrows.comwrote in
news:pa****************************@tonyburrows.co m:
>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.

Tony

I will have to make some assumptions here, because you:
Didn't describe what this tree represents.
Didn't describe what the parent/child relationship is in the tree.
Didn't describe what is in the jar file.
Didn't describe what "relevant data" means to you.
Thanks for that, though I finally got as far as using the JarFile class
yesterday.

I was trying to keep things as simple as possible in my query, wrongly.

The actual classes are Java3D ones to build a representation of a J3D
scenegraph, which is a tree (later I'll generate the matching code). The
main classes are all in j3dcore.jar, plus a couple of utility classes.
Other do exist but can't be connected to the scenegraph.

In fact, the classes descend from one of four parents, Group, Leaf,
NodeComponent or unspecified. Leaf nodes can be added to Group nodes so
once I extract the two types I can control what can be dropped where.
NodeComponent nodes can only be dropped on leaf nodes, with 1 exception,
but not all node components on all leaf nodes! The unspecified are
similar. What I've managed is to extract the nodes, but then manually had
to adjust which node components and unspecified objects can be added to
the other nodes, and the numbers allowed (that varies too).

I was trying to avoid the labour of hand coding it all, since the API is
still evolving, but I think it will have to be a blend of the two.

Tony
Oct 24 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ovid | last post by:
Hi, I'm trying to determine the cleanest way to override class data in a subclass. class Universe { public String name; private static double PI = 3.1415; Universe(String name) {
5
by: Michael Hill | last post by:
Hi, folks. I am writing a Javascript program that accepts (x, y) data pairs from a text box and then analyzes that data in various ways. This is my first time using text area boxes; in the past,...
9
by: cryptic_blade | last post by:
I am working on the design for a new application and want to make the program fully object oriented. I have built and used C++ classes before, but never with a database driven application. Should...
3
by: Grant Harmeyer | last post by:
Ok: I have done small level Xml stuff and am just now starting to understand some of the plumbing involved. I've done a lot of .NET programming for SQL Server, but little for Xml data stores. ...
1
by: sgraber | last post by:
I have encountered a class data alignment issue in Microsoft Visual Studio .Net 2003 (C++, 7.1). The issue only appears in certain configurations. My class is a simple class with no inheritance....
12
by: arenium | last post by:
Hi, I'll cut to the chase. I have a class named Foo(). I create an instance of this class named bar, and I set bar.data to a large list of tuples. Within Foo() there is a method which...
4
by: John Speth | last post by:
Hi group- I have what is a simple understanding problem with c++. I just can't see a way to reference the base class data properly in my code. Here's my simple code that is written in MFC: ...
12
by: WaterWalk | last post by:
Hello. I am rather confused by the type of a pointer to class data member. Many c++ texts say that pointer to data member has a special syntax. For example the following class: class MyClass {...
2
by: WaterWalk | last post by:
(Sorry if I duplicated this post. My previous post somehow disappeared.) Hello. I am rather confused about pointers to class data members. Take the following class as an example: class MyClass...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.