jcifs.util
Class PropertiesTree

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--java.util.Properties
                    |
                    +--jcifs.util.PropertiesTree
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable

public class PropertiesTree
extends java.util.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 benifit of using PropertiesTree as opposed to Properties is that a child property can mask a parent property resulting in sophisticated hierarchial relationships. 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 the PropertiesTree document for details.

See Also:
Serialized Form

Inner classes inherited from class java.util.Map
java.util.Map.Entry
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
PropertiesTree()
          Construct an empty properties tree with no values.
 
Method Summary
 java.lang.Object get(java.lang.Object key)
          Retrieved the property specified by the key parameter, seraching parent nodes if necessary.
 java.lang.String getProperty(java.lang.String key)
          Retrieve a property from the tree by searching parent nodes if necessary and return the value as a String.
 java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)
          Retrieve a property from the tree by searching parent nodes if necessary and return the value as a String.
 void list(java.io.PrintStream out)
          List all properties in the traditional output format and truncated to ensure the contents fit within the display.
 void load(java.io.InputStream in)
          Load all properties from the provided InputStream.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Put a key and value into the tree.
 void store(java.io.OutputStream out, java.lang.String header)
          Save this properties tree to the specified OutputStream.
 void store(java.io.OutputStream out, java.lang.String header, boolean tagged)
          Write this properties tree to the specified OutputStream.
 
Methods inherited from class java.util.Properties
list, propertyNames, save, setProperty
 
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
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PropertiesTree

public PropertiesTree()
Construct an empty properties tree with no values.
Method Detail

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.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 java.util.Hashtable

get

public java.lang.Object get(java.lang.Object key)
Retrieved the property specified by the key parameter, seraching parent nodes if necessary.
Overrides:
get in class java.util.Hashtable

getProperty

public java.lang.String getProperty(java.lang.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 java.util.Properties

getProperty

public java.lang.String getProperty(java.lang.String key,
                                    java.lang.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 java.util.Properties

list

public void list(java.io.PrintStream out)
List all properties in the traditional output format and truncated to ensure the contents fit within the display.
Overrides:
list in class java.util.Properties

store

public void store(java.io.OutputStream out,
                  java.lang.String header)
Save this properties tree to the specified OutputStream. The header parameter will be printed at the top as a comment.
Overrides:
store in class java.util.Properties

store

public void store(java.io.OutputStream out,
                  java.lang.String header,
                  boolean tagged)
Write 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(java.io.InputStream in)
          throws java.io.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 java.util.Properties