Class PropertiesList
- java.lang.Object
-
- java.util.Dictionary<K,V>
-
- java.util.Hashtable<java.lang.Object,java.lang.Object>
-
- java.util.Properties
-
- sunlabs.brazil.properties.PropertiesList
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.util.Map<java.lang.Object,java.lang.Object>
public class PropertiesList extends java.util.Properties
APropertiesList
instance is intended to be an element of a doubly linked list consisting of otherPropertiesList
instances. EachPropertiesList
instance "wraps" aDictionary
object. APropertiesList
is a subclass ofProperties
and therefore provides the same API, including the methods and fields ofDictionary
andHashtable
. ThePropertiesList
class overrides all methods of theProperties
API and delegates the method evaluation to the wrappedProperties
object.The linked list of
PropertiesList
objects is constructed byRequest
for each incoming request. That is, there is a uniquePropertiesList
linked list for each request. The head of the initial list constructed byrequest
isRequest.props
and the tail of the two element list isRequest.serverProps
. The former wraps an emptyProperties
object, while the latter wrapsServer.props
. OtherPropertiesList
objects can be added, and removed, from this initial list as required.Given a reference to a
PropertiesList
object on the linked list (e.g.request.props
), one typically "looks up" the value associated with a name using thegetProperty
method, which delegates to the wrappedProperties.getProperty
method. If the result isnull
, meaning the name/value pair is not stored in the wrappedProperties
object, the request is "forwarded" to the next object on the linked list, and so on until either the name/value pair is found (and the value is returned) or the end of the list is reached (andnull
is returned).It may be desirable for the name/value lookup to be delayed until after the lookup request has been passed on to subsequent objects on the list. This can be done by using the two parameter constructor and setting the second, boolean, parameter to
true
. Then thegetProperty
request is forwarded to the next object in the list rather than delegated to the wrappedProperties
object. If the result of the forwarded request isnull
, the request is then passed to the wrappedProperties
object and it's result is returned.- Version:
- 2.8
- Author:
- Steve Drach <drach@sun.com>
- See Also:
Dictionary
,Hashtable
,Properties
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
debug
Settrue
to turn on debug output.
-
Constructor Summary
Constructors Constructor Description PropertiesList()
Constructs a newPropertiesList
object that wraps an empty newProperties
object.PropertiesList(java.util.Dictionary dict)
Constructs a newPropertiesList
object that wraps the inputDictionary
.PropertiesList(java.util.Dictionary dict, boolean searchNextFirst)
Constructs a newPropertiesList
object that wraps the inputDictionary
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAfter(PropertiesList cursor)
Adds thisPropertiesList
object into a linked list following the object referenced by thecursor
parameter.void
addBefore(PropertiesList cursor)
Adds thisPropertiesList
object into a linked list preceding the object referenced by thecursor
parameter.void
clear()
Invokes the same method on the wrappedHashtable
object.java.lang.Object
clone()
Invokes the same method on the wrappedHashtable
object.boolean
contains(java.lang.Object value)
Invokes the same method on the wrappedHashtable
object.boolean
containsKey(java.lang.Object key)
Invokes the same method on the wrappedHashtable
object.void
dump(boolean full, java.lang.String msg)
Starting with this object, print the contents of this and succeeding objects that are on the same list as this object is.java.util.Enumeration
elements()
Invokes the same method on the wrappedDictionary
object.java.util.Set
entrySet()
Invokes the same method on the wrappedHashtable
object.boolean
equals(java.lang.Object o)
Invokes the same method on the wrappedHashtable
object.java.lang.Object
get(java.lang.Object key)
Invokes the same method on the wrappedDictionary
object.PropertiesList
getHead()
Returns thePropertiesList
object that is the first object on the list of which this object is a member.PropertiesList
getNext()
Returns thePropertiesList
object that succedes this object on the list of which this object is a member.PropertiesList
getPrior()
Returns thePropertiesList
object that precedes this object on the list of which this object is a member.java.lang.String
getProperty(java.lang.String key)
Looks upkey
in the wrapped object.java.lang.String
getProperty(java.lang.String key, java.lang.String defaultValue)
UsesgetProperty(String)
to look up the value associated with the key.java.util.Dictionary
getWrapped()
Returns theDictionary
object wrapped by thisPropertiesList
.int
hashCode()
Invokes the same method on the wrappedHashtable
object.boolean
isEmpty()
Invokes the same method on the wrappedDictionary
object.boolean
isTransient()
Sub-classes of PropertiesList can override this to mark themselves "transient", in which caseaddAfter
will skip this list.java.util.Enumeration
keys()
Invokes the same method on the wrappedDictionary
object.java.util.Set
keySet()
Invokes the same method on the wrappedHashtable
object.void
list(java.io.PrintStream out)
Invokes the same method on the wrappedProperties
object.void
list(java.io.PrintWriter out)
Invokes the same method on the wrappedProperties
object.void
load(java.io.InputStream in)
Invokes the same method on the wrappedProperties
object.java.util.Enumeration
propertyNames()
Invokes the same method on the wrappedProperties
object.java.util.Enumeration
propertyNames(java.lang.String pattern)
Returns anEnumeration
of property names that match aglob
pattern.java.lang.Object
put(java.lang.Object key, java.lang.Object value)
Invokes the same method on the wrappedDictionary
object.void
putAll(java.util.Map t)
Invokes the same method on the wrappedHashtable
object.boolean
remove()
Remove this object from the list in which it's a member.java.lang.Object
remove(java.lang.Object key)
Invokes the same method on the wrappedDictionary
object.boolean
removeProperty(java.lang.String key)
Remove the key and its associated value from the first properties object in the chain that contains this key.boolean
removeProperty(java.lang.String key, boolean all)
Remove a property from a a chain of properties lists.void
save(java.io.OutputStream out, java.lang.String header)
Invokes the same method on the wrappedProperties
object.java.lang.Object
setProperty(java.lang.String key, java.lang.String value)
Invokes the same method on the wrappedProperties
object if it exists.int
size()
Invokes the same method on the wrappedDictionary
object.void
store(java.io.OutputStream out, java.lang.String header)
Invokes the same method on the wrappedProperties
object.java.lang.String
toString()
Returns aString
containing theSystem.identityHashCode
s of this object, the wrapped object, and the preceding and succeding objects on the list of which this object is a member.java.util.Collection
values()
Invokes the same method on the wrappedHashtable
object.PropertiesList
wraps(java.util.Dictionary d)
Find the firstPropertiesList
object on the list of which this object is a member that wraps theDictionary
parameter.
-
-
-
Constructor Detail
-
PropertiesList
public PropertiesList()
Constructs a newPropertiesList
object that wraps an empty newProperties
object.
-
PropertiesList
public PropertiesList(java.util.Dictionary dict)
Constructs a newPropertiesList
object that wraps the inputDictionary
.- Parameters:
dict
- TheDictionary
object wrapped by thisPropertiesList
.
-
PropertiesList
public PropertiesList(java.util.Dictionary dict, boolean searchNextFirst)
Constructs a newPropertiesList
object that wraps the inputDictionary
. If the boolean parameter is settrue
, the wrappedDictionary
is searched after subsequentPropertiesList
objects in the linked list are searched, and only if the result of that search wasnull
.- Parameters:
dict
- TheDictionary
object wrapped by thisPropertiesList
.searchNextFirst
- Iftrue
all the following objects in the list are searched before this one.
-
-
Method Detail
-
getWrapped
public java.util.Dictionary getWrapped()
Returns theDictionary
object wrapped by thisPropertiesList
.
-
addAfter
public void addAfter(PropertiesList cursor)
Adds thisPropertiesList
object into a linked list following the object referenced by thecursor
parameter. The result is a list that could look like: request.props -> cursor -> this -> serverPropsAny transient properties lists's are skipped over before this one is inserted into the list
- Parameters:
cursor
- The list object that will precede this object.
-
addBefore
public void addBefore(PropertiesList cursor)
Adds thisPropertiesList
object into a linked list preceding the object referenced by thecursor
parameter. The result is a list that could look like: request.props -> this -> cursor -> serverProps- Parameters:
cursor
- The list object that will succede this object.
-
remove
public boolean remove()
Remove this object from the list in which it's a member.- Returns:
true
.
-
getNext
public PropertiesList getNext()
Returns thePropertiesList
object that succedes this object on the list of which this object is a member.- Returns:
- A
PropertiesList
object ornull
.
-
getPrior
public PropertiesList getPrior()
Returns thePropertiesList
object that precedes this object on the list of which this object is a member.- Returns:
- A
PropertiesList
object ornull
.
-
getHead
public PropertiesList getHead()
Returns thePropertiesList
object that is the first object on the list of which this object is a member. Note that the first object may be this object.- Returns:
- A
PropertiesList
object.
-
wraps
public PropertiesList wraps(java.util.Dictionary d)
Find the firstPropertiesList
object on the list of which this object is a member that wraps theDictionary
parameter.- Parameters:
d
- TheDictionary
that is compared with the wrappedDictionary
's for a match.- Returns:
PropertiesList
object that wraps the input parameter, otherwisenull
.
-
dump
public void dump(boolean full, java.lang.String msg)
Starting with this object, print the contents of this and succeeding objects that are on the same list as this object is.- Parameters:
full
- Iftrue
also print the contents of the wrappedDictionary
object.msg
- If notnull
, add this message to the header line.
-
elements
public java.util.Enumeration elements()
Invokes the same method on the wrappedDictionary
object.- Overrides:
elements
in classjava.util.Properties
-
get
public java.lang.Object get(java.lang.Object key)
Invokes the same method on the wrappedDictionary
object.- Specified by:
get
in interfacejava.util.Map<java.lang.Object,java.lang.Object>
- Overrides:
get
in classjava.util.Properties
-
isEmpty
public boolean isEmpty()
Invokes the same method on the wrappedDictionary
object.- Specified by:
isEmpty
in interfacejava.util.Map<java.lang.Object,java.lang.Object>
- Overrides:
isEmpty
in classjava.util.Properties
-
keys
public java.util.Enumeration keys()
Invokes the same method on the wrappedDictionary
object.- Overrides:
keys
in classjava.util.Properties
-
put
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
Invokes the same method on the wrappedDictionary
object.- Specified by:
put
in interfacejava.util.Map<java.lang.Object,java.lang.Object>
- Overrides:
put
in classjava.util.Properties
-
remove
public java.lang.Object remove(java.lang.Object key)
Invokes the same method on the wrappedDictionary
object.- Specified by:
remove
in interfacejava.util.Map<java.lang.Object,java.lang.Object>
- Overrides:
remove
in classjava.util.Properties
-
size
public int size()
Invokes the same method on the wrappedDictionary
object.- Specified by:
size
in interfacejava.util.Map<java.lang.Object,java.lang.Object>
- Overrides:
size
in classjava.util.Properties
-
clear
public void clear()
Invokes the same method on the wrappedHashtable
object.- Specified by:
clear
in interfacejava.util.Map<java.lang.Object,java.lang.Object>
- Overrides:
clear
in classjava.util.Properties
-
clone
public java.lang.Object clone()
Invokes the same method on the wrappedHashtable
object.- Overrides:
clone
in classjava.util.Properties
-
contains
public boolean contains(java.lang.Object value)
Invokes the same method on the wrappedHashtable
object.- Overrides:
contains
in classjava.util.Properties
-
containsKey
public boolean containsKey(java.lang.Object key)
Invokes the same method on the wrappedHashtable
object.- Specified by:
containsKey
in interfacejava.util.Map<java.lang.Object,java.lang.Object>
- Overrides:
containsKey
in classjava.util.Properties
-
entrySet
public java.util.Set entrySet()
Invokes the same method on the wrappedHashtable
object.- Specified by:
entrySet
in interfacejava.util.Map<java.lang.Object,java.lang.Object>
- Overrides:
entrySet
in classjava.util.Properties
-
equals
public boolean equals(java.lang.Object o)
Invokes the same method on the wrappedHashtable
object.- Specified by:
equals
in interfacejava.util.Map<java.lang.Object,java.lang.Object>
- Overrides:
equals
in classjava.util.Properties
-
hashCode
public int hashCode()
Invokes the same method on the wrappedHashtable
object.- Specified by:
hashCode
in interfacejava.util.Map<java.lang.Object,java.lang.Object>
- Overrides:
hashCode
in classjava.util.Properties
-
keySet
public java.util.Set keySet()
Invokes the same method on the wrappedHashtable
object.- Specified by:
keySet
in interfacejava.util.Map<java.lang.Object,java.lang.Object>
- Overrides:
keySet
in classjava.util.Properties
-
putAll
public void putAll(java.util.Map t)
Invokes the same method on the wrappedHashtable
object.- Specified by:
putAll
in interfacejava.util.Map<java.lang.Object,java.lang.Object>
- Overrides:
putAll
in classjava.util.Properties
-
values
public java.util.Collection values()
Invokes the same method on the wrappedHashtable
object.- Specified by:
values
in interfacejava.util.Map<java.lang.Object,java.lang.Object>
- Overrides:
values
in classjava.util.Properties
-
toString
public java.lang.String toString()
Returns aString
containing theSystem.identityHashCode
s of this object, the wrapped object, and the preceding and succeding objects on the list of which this object is a member. Additionally, ifdebug
istrue
, the result of invokingtoString
on the wrappedDictionary
is appended.- Overrides:
toString
in classjava.util.Properties
- Returns:
String
representation of this object.
-
getProperty
public java.lang.String getProperty(java.lang.String key)
Looks upkey
in the wrapped object. If the result isnull
the request is forwarded to the succeeding object in the list of which this object is a member. If the search order was changed by constructing this object with the two parameter constructor, the request is first forwarded and then, if the result of the forwarded request isnull
, thekey
is looked up in the wrappedProperties
object.- Overrides:
getProperty
in classjava.util.Properties
- Parameters:
key
- The key whose value is sought.- Returns:
- The value or
null
.
-
getProperty
public java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)
UsesgetProperty(String)
to look up the value associated with the key. If the result isnull
, returns the default value.- Overrides:
getProperty
in classjava.util.Properties
- Parameters:
key
- The key whose value is sought.defaultValue
- The default value.- Returns:
- The value or
null
.
-
removeProperty
public boolean removeProperty(java.lang.String key, boolean all)
Remove a property from a a chain of properties lists. if "all" is specified, then remove all the keys and values from all property lists in the chain instead of just the first one found.- Parameters:
key
- The key whose value is to be removedall
- remove all matching keys.- Returns:
- true, if at least one key/value pair was removed.
-
removeProperty
public boolean removeProperty(java.lang.String key)
Remove the key and its associated value from the first properties object in the chain that contains this key.- Returns:
- true, if the key was removed.
-
list
public void list(java.io.PrintStream out)
Invokes the same method on the wrappedProperties
object.- Overrides:
list
in classjava.util.Properties
-
list
public void list(java.io.PrintWriter out)
Invokes the same method on the wrappedProperties
object.- Overrides:
list
in classjava.util.Properties
-
load
public void load(java.io.InputStream in) throws java.io.IOException
Invokes the same method on the wrappedProperties
object.- Overrides:
load
in classjava.util.Properties
- Throws:
java.io.IOException
-
propertyNames
public java.util.Enumeration propertyNames()
Invokes the same method on the wrappedProperties
object.- Overrides:
propertyNames
in classjava.util.Properties
-
save
public void save(java.io.OutputStream out, java.lang.String header)
Invokes the same method on the wrappedProperties
object.- Overrides:
save
in classjava.util.Properties
-
setProperty
public java.lang.Object setProperty(java.lang.String key, java.lang.String value)
Invokes the same method on the wrappedProperties
object if it exists. Otherwise invokesput
on the wrappedDictionary
object.- Overrides:
setProperty
in classjava.util.Properties
-
store
public void store(java.io.OutputStream out, java.lang.String header) throws java.io.IOException
Invokes the same method on the wrappedProperties
object.- Overrides:
store
in classjava.util.Properties
- Throws:
java.io.IOException
-
propertyNames
public java.util.Enumeration propertyNames(java.lang.String pattern)
Returns anEnumeration
of property names that match aglob
pattern.- Parameters:
pattern
- Theglob
pattern to match.- Returns:
- An
Enumeration
containing matching property names, if any.
-
isTransient
public boolean isTransient()
Sub-classes of PropertiesList can override this to mark themselves "transient", in which caseaddAfter
will skip this list.
-
-