|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object SK.gnome.dwarf.utils.StringProperties
Provides a persistent set of read-only properties.
This class mimics the java.util.Properties with two main differences - it does not allow modifying of properties and it supports loading properties either from an URL or from a string.
To load properties from an URL, the string argument provided to the constructor must be a regular URL, preceded by the '@' character:
// load properties from an URL String s = "@file:conf/main.xml"; StringProperties props = new StringProperties(s);Please remember that a valid URL must start with the protocol identifier, like "file:", "jar:", "ftp:", and so on.
To load properties from a string, the string argument must contain text in the format supported by the java.util.Properties class:
// load properties from a string String s = "name1=value1\n"; s += "name2=value2\n"; s += "name3=value3"; StringProperties props = new StringProperties(s);
If you need to use a property name starting with the '@' character, precede it with the backslash:
// load properties from a string String s = "\@name1=value1\n"; // first property named "@name1" s += "name2=value2\n"; s += "name3=value3"; StringProperties props = new StringProperties(s);
In contrast to java.util.Properties, this class is unsynchronized, therefore it can be used where the performance is crucial and the properties don't need to be modified after they have been initialized.
It can be used in cooperation with the XMLConfiguration
class, where a fixed small set of properties may be specified directly in the XML element,
while a larger set of properties may be stored to an external location and referenced in the
XML document by an URL pointing to it. This scheme may be also extended to support a runtime
reloading of the externally stored properties.
Constructor Summary | |
StringProperties(java.lang.String s)
Creates new StringProperties. |
Method Summary | |
java.lang.String |
getProperty(java.lang.String key)
Returns property value by its name. |
java.net.URL |
getURL()
Returns URL from which the properties were loaded. |
java.util.Enumeration |
propertyNames()
Returns all property names. |
void |
reload()
Reloads properties loaded from an URL. |
java.lang.String |
toString()
Returns string representation of the properties. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public StringProperties(java.lang.String s)
If the string starts with the '@' character, the rest of it is taken as an URL from which the properties will be loaded. Rememeber, that each URL must start with a protocol identification, like "file:", for example.
If the string does not start with the '@' character, it must contain the properties themselves as supported by the java.io.Properties class, i.e. a list of name/value pairs, separated by the line terminator. If the name of the first property starts with the '@' character, it must be preceded with a backslash.
s
- either an URL or the properties themselvesMethod Detail |
public java.lang.String getProperty(java.lang.String key)
key
- the property name
public java.util.Enumeration propertyNames()
public void reload() throws java.io.IOException
It returns silently if the properties were specified as a string containing "name=value" pairs instead of an URL.
java.io.IOException
- if an I/O error occuredpublic java.net.URL getURL()
It returns null if the properties were specified as a string containing the list of "name=value" pairs instead of an URL.
public java.lang.String toString()
It returns URL if the properties were loaded from an URL, otherwise returns a list of contained properties.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |