The Preferences approach looks interesting, but seems to be geared ever so slightly more toward client-side applications.
My interest in this
thread was to overcome the Hashtable behavior of the Properties class with minimal re-work to my existing applications that use the current Properties class.
Primarily, I did not like the way that the ordering of the Enumeration from propertyNames() method is dictated by the hashing function.
While it would be an easy thing to sort the keys alphabetically, I wanted to get the keys in their order of appearance in the properties file.
To this end, I have re-implemented the Properties class, based on the java.util.LinkedHashMap data structure. It is a work in progress, though, so I haven't yet implemented all of the methods, rules and behavior found in the original java.util.Properties class. For instance, I haven't yet implemented any capability for reading values that span multiple lines using continuation characters.
Among the liberties I am taking:
OrderedProperties contains a data structure, instead of extending one.Property values must be Strings. This is enforced throughout.I used the java.util.regex classes to parse the key/value lines.I might implement an Iterator, which is preferred over Enumerations. Given the greater flexibility that XML-based configuration files can afford, I will probably cut development of this class short. It is more of a coding exersize for me anyway, but it does meet a current need as well.
For the curious, here is the code. Of course, this is limited to
Java 1.4 platforms, but that is not a problem for me. I have tested this code, and so far it works just as expected.
PCS
[ November 07, 2002: Message edited by: Philip Shanks ]