Fedora Linux Support Community & Resources Center
  #1  
Old 21st June 2006, 08:30 PM
tashirosgt Offline
Registered User
 
Join Date: Aug 2004
Posts: 3,958
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."
Reply With Quote
  #2  
Old 22nd June 2006, 05:12 AM
Jman Offline
Registered User
 
Join Date: Mar 2004
Location: Minnesota, USA
Age: 28
Posts: 7,909
Reflection.

This stuff appears interesting, I'm hoping to study it further.
Reply With Quote
  #3  
Old 22nd June 2006, 02:38 PM
drmr Offline
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?
Reply With Quote
  #4  
Old 23rd June 2006, 04:10 AM
tashirosgt Offline
Registered User
 
Join Date: Aug 2004
Posts: 3,958
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."
Reply With Quote
  #5  
Old 23rd June 2006, 04:32 AM
Jman Offline
Registered User
 
Join Date: Mar 2004
Location: Minnesota, USA
Age: 28
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.
Reply With Quote
  #6  
Old 23rd June 2006, 04:48 AM
tashirosgt Offline
Registered User
 
Join Date: Aug 2004
Posts: 3,958
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."
Reply With Quote
  #7  
Old 23rd June 2006, 07:40 PM
drmr Offline
Registered User
 
Join Date: May 2005
Posts: 23
You could try also Castor
Reply With Quote
  #8  
Old 27th June 2006, 04:09 PM
tashirosgt Offline
Registered User
 
Join Date: Aug 2004
Posts: 3,958
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."
Reply With Quote
  #9  
Old 28th June 2006, 02:12 AM
Jman Offline
Registered User
 
Join Date: Mar 2004
Location: Minnesota, USA
Age: 28
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.
Reply With Quote
  #10  
Old 29th June 2006, 02:52 PM
tashirosgt Offline
Registered User
 
Join Date: Aug 2004
Posts: 3,958
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."
Reply With Quote
  #11  
Old 30th June 2006, 06:55 PM
jsather Offline
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.
Reply With Quote
Reply

Tags
class, file, instantiate, java, xml

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding the size of a custome class type in java cola Programming & Packaging 1 17th February 2009 11:05 PM
How to set Java class path in Core 6? riff_almighty Using Fedora 9 17th September 2007 07:27 AM
import class error in java??? paladin_knight Programming & Packaging 6 21st June 2007 07:12 AM
wrong ELF class: ELFCLASS64: java swing is not running. suraj Using Fedora 0 19th September 2006 03:59 PM


Current GMT-time: 11:41 (Tuesday, 02-09-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat