jcifs.util
Class PropertiesTree
java.lang.Object
|
+--java.util.Dictionary
|
+--java.util.Hashtable
|
+--java.util.Properties
|
+--jcifs.util.PropertiesTree
- public class PropertiesTree
- extends Properties
This class is backwords compatible with Properties
however another dimension is added by using the customary dot '.' as
an operator to alternativly represent properties as trees. In essance
it gives meaning to the '.' used in keys of properties whereas with
traditional properties usage of the dot '.' was mearly a convention. This
allows applications to organize there data in new ways. The following
is an example of the "tagged" output from a PropertiesTree along with
traditional output from the same PropertiesTree to it's right. PropertiesTree can load and store
both formats at runtime(e.g. load traditional and then store tagged).
#Feed Processor Config
#Sun Dec 31 00:48:23 EST 2000
proxy=192.168.1.15
<net>
username=joe
<smb>
host=doc-storage
username=kelly
</smb>
<ftp>
host=feed10.research.com
</ftp>
</net>
|
#Feed Processor Config
#Sun Dec 31 00:59:31 EST 2000
proxy=192.168.1.15
net.username=joe
net.smb.host=doc-storage
net.smb.username=kelly
net.ftp.host=feed10.research.com
|
In the above example, if getProperty( "net.ftp.username" )
was called "joe" would be returned. The get
method walks
up the tree searching for the first match. So the following:
net.ftp.username
net.username
username
are basically equivalent and thus backwords compatible with
java.util.Properties. The plus is that a child property can mask a parent
property. This is true of the net.smb.username
property.
It might also be thought of as overloading net.username
with net.smb.username
but only for the smb branch.
- See Also:
- Serialized Form
Constructor Summary |
PropertiesTree()
Construct an empty properties tree with no values. |
Method Summary |
Object |
get(Object key)
Retrieved the property specified by the key parameter, seraching parent
nodes if necessary. |
String |
getProperty(String key)
Retrieve a property from the tree by searching parent nodes
if necessary and return the value as a String. |
String |
getProperty(String key,
String defaultValue)
Retrieve a property from the tree by searching parent nodes if necessary
and return the value as a String. |
void |
list(PrintStream out)
List all properties in the traditional output format and truncated to
ensure the contents fit within the display. |
void |
load(InputStream in)
Load all properties from the provided InputStream. |
Object |
put(Object key,
Object value)
Put a key and value into the tree. |
void |
save(OutputStream out,
String header)
Save this properties tree to the specified OutputStream. |
void |
save(OutputStream out,
String header,
boolean tagged)
Save this properties tree to the specified OutputStream. |
Methods inherited from class java.util.Hashtable |
clear,
clone,
contains,
containsKey,
containsValue,
elements,
entrySet,
equals,
hashCode,
isEmpty,
keys,
keySet,
putAll,
rehash,
remove,
size,
toString,
values |
PropertiesTree
public PropertiesTree()
- Construct an empty properties tree with no values.
put
public Object put(Object key,
Object value)
- Put a key and value into the tree. If the key contains a dot
'.', new tree nodes will be automatically created to accomodate.
- Overrides:
- put in class Hashtable
get
public Object get(Object key)
- Retrieved the property specified by the key parameter, seraching parent
nodes if necessary.
- Overrides:
- get in class Hashtable
getProperty
public String getProperty(String key)
- Retrieve a property from the tree by searching parent nodes
if necessary and return the value as a String.
- Overrides:
- getProperty in class Properties
getProperty
public String getProperty(String key,
String defaultValue)
- Retrieve a property from the tree by searching parent nodes if necessary
and return the value as a String. If the keys value is not found, the
default parameter will be returned.
- Overrides:
- getProperty in class Properties
list
public void list(PrintStream out)
- List all properties in the traditional output format and truncated to
ensure the contents fit within the display.
- Overrides:
- list in class Properties
save
public void save(OutputStream out,
String header)
- Save this properties tree to the specified OutputStream. The header
parameter will be printed at the top as a comment.
- Overrides:
- save in class Properties
save
public void save(OutputStream out,
String header,
boolean tagged)
- Save this properties tree to the specified OutputStream. The header
parameter will be printed at the top as a comment. If the boolean
parameter is true the output will be stored in tagged format as shown
in the example at the top of this page.
load
public void load(InputStream in)
throws IOException
- Load all properties from the provided InputStream. The text read may be
either tagged format, traditional format, or a mixture of both.
- Overrides:
- load in class Properties