com.ccg.util
Class LookupProperties

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable<Object,Object>
          extended by java.util.Properties
              extended by com.ccg.util.LookupProperties
All Implemented Interfaces:
Lookup, LookupKeyed, Serializable, Cloneable, Map<Object,Object>

public class LookupProperties
extends Properties
implements LookupKeyed

Version of Properties which implements a keyed lookup table. This standard Properties class is pretty dang handy thing. This class enhances it with the following capabilities:

Since:
1.0
Version:
$Revision: 1.1.1.1 $
Author:
$Author: pkb $
See Also:
LookupKeyed, Serialized Form

Field Summary
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
LookupProperties()
          Create a empty lookup table.
LookupProperties(URL baseURL, String path)
          Construct and load a LookupProperties object.
 
Method Summary
 void addFromCommaString(String s)
          Parse a comma separated string containing KEY=VALUE pairs.
 Enumeration getKeys()
          Get enumeration of all of the keys in the lookup table.
 String getString(Object key)
          Fetch a String "value" associated with a "key".
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, load, loadFromXML, propertyNames, save, setProperty, store, storeToXML, storeToXML
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.ccg.util.LookupKeyed
get
 

Constructor Detail

LookupProperties

public LookupProperties()
Create a empty lookup table. This allows one to create a empty property table. You can use the standard Properties.load(java.io.InputStream) or Hashtable.put(K, V) methods to add values to the property table after you create it in this manner.

Since:
1.0
See Also:
LookupProperties(URL,String)

LookupProperties

public LookupProperties(URL baseURL,
                        String path)
Construct and load a LookupProperties object. This constructor attempts to load the properties file based upon two parameters which are passed. This constructor doesn't throw any exceptions. If there were any problems encountered in loading the specified property file, then all you can do is check via the Hashtable.isEmpty() method. This means that you won't be able to distinguish the condition when a property file is missing as to a property file being empty.

The contents of the property file should be in the standard form supported by Properties.load(java.io.InputStream).

The property file is searched for in the following manner:

Parameters:
base - Your "anchor" point to use if the "path" specified is relative or omits protocol type information from the URL. If you pass null, then an attempt will be made to load the properties directly from the value specified in "path".
path - The string that specifies the property file you want to load (in a form recognized by Utility.getInputStream(java.lang.String)). If you pass null, then the property file will be loaded from the URL specified by the "base" parameter.
Since:
1.0
See Also:
Hashtable.isEmpty(), Utility.convertRelativeURL(java.net.URL, java.lang.String), Utility.getInputStream(java.lang.String)
Method Detail

getString

public String getString(Object key)
Fetch a String "value" associated with a "key". Try to lookup the String object which is associated with the key. This method should never throw an exception and is required so that class can be used as a standard Lookup object.

Specified by:
getString in interface Lookup
Specified by:
getString in interface LookupKeyed
Parameters:
key - Key to use to look up object with (if you pass null, you will get null back).
Returns:
Object found (if exists) returned as a String or null if not found.
Since:
1.0
See Also:
Lookup

getKeys

public Enumeration getKeys()
Get enumeration of all of the keys in the lookup table.

Specified by:
getKeys in interface LookupKeyed
Returns:
Enumeration list of all keys in the Lookup table.
Since:
1.0

addFromCommaString

public void addFromCommaString(String s)
Parse a comma separated string containing KEY=VALUE pairs. This method will parse a comma separated string of "KEY=VALUE" pairs. The form of the string looks something like:
 ENTRY[,ENTRY[,ENTRY...]
 

Each "ENTRY" must have one of the following forms to be accepted:

 KEY[=VALUE]
 

The "KEY" field must ALWAYS be present. The values entered into the Lookup table will be as follows:

KEY
If the "equal" sign is absent, then the key will be added to the table as a boolean true (like a flag setting).
KEY=
If the "equal" sign is present, but no value is included, then the zero length string "" will be used for the value.
KEY=VALUE
Finally if both the KEY and VALUE are present, the VALUE will be entered for the KEY into the Lookup table as a string.

As an example, consider the URL recognized by the URLConnection class:

 "tcp:/localhost:5555/sendBufferSize=5000,tcpNoDelay,soLinger=3"
 

If you were to pass the file name portion of the above string to this method, it would add three new key/value pairs to the lookup table: "sendBufferSize" would return "5000", "tcpNoDelay" would return Boolean.TRUE and "soLinger" would return "3".

Parameters:
values - List key=value pairs separated only by commas
Since:
1.0
See Also:
URLConnection


Copyright 1998-1998-2006 null. All Rights Reserved.