Re: Setting class variables dynamically from a config file
Joel Gilmore wrote:
I envision having a user-editable config file which would be loaded at
the start, either in XML format or simply
This actually is a good case for using reflection. The only real issue
is that Java suffers an embarrassment of riches for serializing classes
to XML and back. Before rolling your own you should look at some
parsers that have already been written (and debugged).
You've already got some good advice. A Google search for "java xml
serialization" gets lots of good hits. You should browse those results
yourself to see if anything strikes you as a very good match for your
application.
Here's a couple of thoughts by me:
JAXB - Java XML Binding
Uses annotations to make the job of marshaling classes to XML and back.
<http://java.sun.com/javase/6/docs/technotes/guides/xml/jaxb/index.html>
XStream
Claims to be simple and easy, always a win in my book.
http://xstream.codehaus.org/
Simple
It looks like Simple also uses annotations but claims to be (guess!)
simpler to use than JAXB.
http://simple.sourceforge.net/
I haven't used any of these, so you might want to look around for some
articles and check the docs, see what might be the best match for you.