Hello everyone, this is something I wrote a couple months back. It is used as a universal class/object loader from an XML file. For the handling of XML I use the JDOM library. The story basically goes like this: I have a load of classes in a game I'm working on, going from enemies to items to zones, you name it. That data is written in xml files.
Instead of writing a different method for every class and every constructor, what these methods do is: you start with for instance loadItems(File aFile), which takes the xml file for Items as an argument. Using JDOM, the root of the document is found, and the method iterates over all the children, which would be all my seperate objects. The jdom.Element is given together with the class the returned object has to have as an argument to loadData. Using the parseData function I parse the strings of every child of the given Element, to identify it as an int, a double, int array, whatever. The types of all these variables get identified, and according to the class you have to the method, it looks up the right constructor, and returns you the desired object.
I now just have loadItems, loadEnemies, loadTowns, etc, methods of less than 10 lines, that all use the loadData method to store my objects in the database.