 |
 |
 |
 |
| Programming & Packaging A place to discuss programming and packaging. |

21st June 2006, 08:30 PM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 3,855

|
|
|
How to instantiate Java class from XML file?
I'm looking at some code (copyrighted, or else I would post it) written in Java that reads an XML file that describes a class and uses the features of java.lang.reflect to create an instance of that class. Does anyone know of some simple examples of this technique or a technical name for it?
__________________
"Never let the task you are trying to accomplish distract you from the study of computers."
|

22nd June 2006, 05:12 AM
|
|
Registered User
|
|
Join Date: Mar 2004
Location: Minnesota, USA
Age: 27
Posts: 7,909

|
|
Reflection.
This stuff appears interesting, I'm hoping to study it further.
|

22nd June 2006, 02:38 PM
|
|
Registered User
|
|
Join Date: May 2005
Posts: 23

|
|
Quote:
|
Originally Posted by tashirosgt
I'm looking at some code (copyrighted, or else I would post it) written in Java that reads an XML file that describes a class and uses the features of java.lang.reflect to create an instance of that class. Does anyone know of some simple examples of this technique or a technical name for it?
|
The class must have definition in order to create instance from it with reflection.
Reflection cannot be used for generating class definitions.
You need something like this:
BCEL
Did I miss the point?
|

23rd June 2006, 04:10 AM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 3,855

|
|
|
I think all the classes in this software are defined. The data for various instances of them is in XML files. What would be nice is some utility that would show me a graph of which classes and packages in this mess depend on which others.
__________________
"Never let the task you are trying to accomplish distract you from the study of computers."
|

23rd June 2006, 04:32 AM
|
|
Registered User
|
|
Join Date: Mar 2004
Location: Minnesota, USA
Age: 27
Posts: 7,909

|
|
Quote:
|
Originally Posted by tashirosgt
I think all the classes in this software are defined. The data for various instances of them is in XML files. What would be nice is some utility that would show me a graph of which classes and packages in this mess depend on which others.
|
Like this?
Have any idea what doctype or format the XML data is in? I would think there are tools that do this.
|

23rd June 2006, 04:48 AM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 3,855

|
|
|
Thanks, I'll try that. I just installed Eclipse.
Most of the XML files have an associated *.xsd file, which is "Schema" isn't it?
The program (called OneSAF) looks to be what is known as "composable" architecture. There are over 11,000 XML files in the data directory alone. I think there is a set of "services" and many different programs are "composed" from these services by a general purpose routine that can read an XML file for what services are needed and instantiate them. But that's only my guess.
__________________
"Never let the task you are trying to accomplish distract you from the study of computers."
|

23rd June 2006, 07:40 PM
|
|
Registered User
|
|
Join Date: May 2005
Posts: 23

|
|
You could try also Castor
|

27th June 2006, 04:09 PM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 3,855

|
|
|
Castor might be a fine product but the Castor pages are a good example of how to write fancy jargon without really explaining anything. This seems to be typical of anything associated with XML!
The metrics plugin for Eclipse looks promising. But Eclipse itself is my current problem. It seems to me that mine is a very common situation - namely you have a bunch of Java files and you want to understand how they fit together. Yet I don't see any features in Eclipse that let me import all the files in a given directory and its subdirectories into a new project. Would I have to do select them one by one? The program has a build file that are useable by Ant, but when I try the option to create a new project based on an existing Ant build file, Eclipse tells me that the build file can't be used because it contains no javac statement.
__________________
"Never let the task you are trying to accomplish distract you from the study of computers."
|

28th June 2006, 02:12 AM
|
|
Registered User
|
|
Join Date: Mar 2004
Location: Minnesota, USA
Age: 27
Posts: 7,909

|
|
Quote:
|
Originally Posted by tashirosgt
It seems to me that mine is a very common situation - namely you have a bunch of Java files and you want to understand how they fit together. Yet I don't see any features in Eclipse that let me import all the files in a given directory and its subdirectories into a new project. Would I have to do select them one by one? The program has a build file that are useable by Ant, but when I try the option to create a new project based on an existing Ant build file, Eclipse tells me that the build file can't be used because it contains no javac statement.
|
Not for new projects that are not already Eclipse projects. You can however create a new project and import your directory structure, then apply some Ant.
|

29th June 2006, 02:52 PM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 3,855

|
|
|
Can you "import your directory structure" in a few mouse clicks in Eclipse? I looked at the code with Netbeans and was pleased to find that when I examined one file it automatically began "scanning" and put some other files into the tree of classes it displays. But Netbeans on my work machine (RHEL 4) has the problem that it expects double clicks to select files and you must double click very fast. If work at my normal speed, the file selection is never made.
__________________
"Never let the task you are trying to accomplish distract you from the study of computers."
|

30th June 2006, 06:55 PM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 4

|
|
You could try http://xmlbeans.apache.org/ since you have the xsd. I just had a pure XML file and used the xsd app from Visual Studio (don't ask) to make the xsd. Then I used the stuff from xmlbeans (scomp) to make the java mapping libs.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Current GMT-time: 02:00 (Sunday, 26-05-2013)
|
|
 |
 |
 |
 |
|
|