I write applications that need alot of options. These options can be handed to the application by a xml file. Theses files are quite big with some levels and a few dependancies not modelable in a schema.
So the file passes the jdom schema check. Now I want to create some config object for the application and set some variables in some classes.
I don't really see any way not hardcoding the names of the开发者_运维知识库 elements and attributes and then looping over these elements and creating new objects.
This makes a 20kLoc application have 25 classes only holding configurations for other classes.
Is there some golden hammer rule how to use xml and customize applications. It comes down to putting the information in the file into some lists, hashtables and attributes of objects.
Can that be done easier? Some awesome framework, maybe? Reflection? Beans? Beans is just a hype word for java programming, or am I missing something?
Who controls the schema of the configuration files? If you can change it, you can simplify it enough to limit the number of classes needed.
If they are imposed from the outside, you might get some traction with Apache Commons BeanUtils and Betwixt.
精彩评论