Hello everyone, For the last 3 days I'm struggling with a problem which, at first, didn't seem like a problem at all. I hope someone here can help me. I'll try to be as clear as possible, but if there's any question, just let me know. What I'm trying to do is create some kind of dynamic property reading class. The idea is as follows:
This method getProperty() should work in the following way that it should return a Map (or a Map in a Map in a Map, as I will show later). The Map can be of different depths, depending on the way you call the method. If you call the method with a string like this:
It should give you a map such that the following code should work:
The idea is that this will enable me to get all the controller settings is necessary (with getProperty("controller")) or to get all internationalization settings (getProperty("controller.i18n")) or, as above, to get all handlers associated with the controller logger (getProperty("controller.logger.handler");
Now it might look like I'm going for an easy anwer and don't do the thinking myself. Well, that's not the case. I can post all my possible solution here I created so far (Which all don't work!), but that will make quite as mess. If you are interested though, I won't mind posting them here too.
Maybe I'm looking in a very wrong direction, but I someone can give me a push into a better direction, please let me know!
This sounds like an ok direction. I once built a resource manager that read all the properties files in a directory. It made a PropertyResourceBundle for each file and stuck them in a hashmap keyed by filename.
The manager never gives any client a direct reference to a resource bundle, so the mgr can throw bundles away and reload them from disk during the day, and of course to completely change the implementation. Any of those ideas help?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Hello Stan, Thanks for your reply. I wish property reading was as 'easy' as in your example, but I have already have something like that, with filelisteners, PropertyChangeEvents, etc. But what I really one is to have a sort of tree structure, like this
which can enable me to get all the properties belonging to the controller, or only the ones refering to the handler, etc. Thanks again for your help, but this was not exactly what I was looking for! Greetings, Erik [ June 17, 2003: Message edited by: Erik Pragt ]
Here is some sample code I just created. I works for demonstration purposed, which means it has some bugs in it, but you might get the idea of what I want to do. The missing part in this is the createStructure, which should use the properties instead of the dummy structure I'm using now. Any help still appreciated!
Why dont you take a look at the Log4J source code? I'm not terribly familiar with it, but I know it accomplishes this sort of thing, and may even use some open source libraries from the Commons project that you'd find useful. You could start by looking at the source for org.apache.log4j.PropertyConfigurator (again, I'm not sure of these names). http://www.apache.org
public abstract class Preferences extends Object A node in a hierarchical collection of preference data. This class allows applications to store and retrieve user and system preference and configuration data. This data is stored persistently in an implementation-dependent backing store. Typical implementations include flat files, OS-specific registries, directory servers and SQL databases. The user of this class needn't be concerned with details of the backing store.
Hello Dana, thanks for the tip! I'm downloading the log4j source files now! Don, also thanks for your help! However, I'm not very familier with the preferences API, so I will go for Dana's tip first. If I don't succeed (and maybe also when I do succeed!), I will look at the preferences API. both, thanks for your help! Greetings, Erik
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop