Configuration Version 2

This one goes back to my Configuration entry. Well, it turned out, 128 lines wasn't enough. See, when I write an XML document, I like to reuse tag names (see Element over at The W3), so, my old XML document of one line per object wouldn't cut it. The system would look up an object, but it will be a different type. For instance, I would use the "attribute" tag numerous times, but each time it means something else. One time it would mean the definition of an attribute, and another time it would mean "this attribute is the one that I want to use", or essentially, in as highly a technical way as I can describe it, something would reference an attribute that was previously created. Now, that one class that was 128 lines or whatever, is now 206. Still not a ton, and I wake up and thank God for letting me wake up one more day, and I also thank Him for recursion and reflection. Those are two of God's greatest gifts to any Computer Scientist. Each a gift in their own right, but get them together and that's how babies are born. It's SEXY.

Overall, here are the files and their line numbers in the Configuration Version 2 project:

Package voodoo.xmlconfig.domain : : 7 lines
Package voodoo.xmlconfig.loader : : 104 lines : 206 lines
Package voodoo.xmlconfig.nodes : : 12 lines : 45 lines : 47 lines : 125 lines
Package voodoo.xmlconfig : : 39 lines

So there you have it. Sacrifices were made. Ideas were thrown around. XML parsing was ritually slaughtered. Never again. Woohoo.

There are some major features in this though, despite its brevity. When loading and looking up objects in a map at the same time, sometimes what you are looking up will not have been loaded into the map yet. I wrote my copy function to take care of this after the objects have been initialized and put into the map as basically blank objects. Copy then takes the actual values and loads them in. This is important because other objects already have a reference to the blank object, as opposed to the fully loaded object of the same type. This could cause problems in the future, but for my needs, it will serve the purpose. Another awesome feature is the ability to look up objects in a map in the first place! "I want to add a reference to this attribute to this object, but find it in this map under this key and this key." Sometimes, a map indexed with a key will reveal another map, so you can specify multiple keys. For my attribute, first, you look up the type, where many attributes can have the same type, then you look up the name in the resulting map of attributes with that type. This can be done infinitely.

Tune in next week. I just took my laptop out of its case for the first time in 2 weeks! I should be addicted to programming Java again in no time.

blog comments powered by Disqus