OZONE Asylum
Forums
OZONE
Java: Instantiate classes by name from a file
This page's ID:
28631
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
Okay, I don't even know if this is possible, I'm just hoping it is. I have a program I'm writing. It's got a few different configuration files that it loads and parses. I want one of these to be a modules file. See, the program provides a framework, then the modules file lists input commands, and the class that runs them. Allows me to interactively add/remove modules without ever having to restart the program. The modules all implement the interface Module, which has a single method: public static void process(String message). Since all modules share this interface, it allows me to create a TreeMap based on them. public TreeMap<String,Module> modules = new TreeMap<String,Module>(); Upon loading, the modules file will be read line-by-line. The last entry on the line will be the class that handles the commands, and everything leading up to it will be a command that will be fed (as part of String message) to the class' process() method. This is all well and good so far, but I'm wondering this: If I load up a set of strings from this file, is there any way I can tell Java "create an instance of the class named in StringA"? [url=http://sunday.yarinareth.net][img]http://members.ii.net/~skaarjj/tempus.gif[/img][/url] Justice 4 [url=http://www.justice4pat.com]Pat Richard[/url]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »