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.PropertiesAPropertiesListinstance is intended to be an element of a doubly linked list consisting of otherPropertiesListinstances. EachPropertiesListinstance "wraps" aDictionaryobject. APropertiesListis a subclass ofPropertiesand therefore provides the same API, including the methods and fields ofDictionaryandHashtable. ThePropertiesListclass overrides all methods of thePropertiesAPI and delegates the method evaluation to the wrappedPropertiesobject.The linked list of
PropertiesListobjects is constructed byRequestfor each incoming request. That is, there is a uniquePropertiesListlinked list for each request. The head of the initial list constructed byrequestisRequest.propsand the tail of the two element list isRequest.serverProps. The former wraps an emptyPropertiesobject, while the latter wrapsServer.props. OtherPropertiesListobjects can be added, and removed, from this initial list as required.Given a reference to a
PropertiesListobject on the linked list (e.g.request.props), one typically "looks up" the value associated with a name using thegetPropertymethod, which delegates to the wrappedProperties.getPropertymethod. If the result isnull, meaning the name/value pair is not stored in the wrappedPropertiesobject, 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 (andnullis 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 thegetPropertyrequest is forwarded to the next object in the list rather than delegated to the wrappedPropertiesobject. If the result of the forwarded request isnull, the request is then passed to the wrappedPropertiesobject 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 booleandebugSettrueto turn on debug output.
-
Constructor Summary
Constructors Constructor Description PropertiesList()Constructs a newPropertiesListobject that wraps an empty newPropertiesobject.PropertiesList(java.util.Dictionary dict)Constructs a newPropertiesListobject that wraps the inputDictionary.PropertiesList(java.util.Dictionary dict, boolean searchNextFirst)Constructs a newPropertiesListobject that wraps the inputDictionary.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAfter(PropertiesList cursor)Adds thisPropertiesListobject into a linked list following the object referenced by thecursorparameter.voidaddBefore(PropertiesList cursor)Adds thisPropertiesListobject into a linked list preceding the object referenced by thecursorparameter.voidclear()Invokes the same method on the wrappedHashtableobject.java.lang.Objectclone()Invokes the same method on the wrappedHashtableobject.booleancontains(java.lang.Object value)Invokes the same method on the wrappedHashtableobject.booleancontainsKey(java.lang.Object key)Invokes the same method on the wrappedHashtableobject.voiddump(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.Enumerationelements()Invokes the same method on the wrappedDictionaryobject.java.util.SetentrySet()Invokes the same method on the wrappedHashtableobject.booleanequals(java.lang.Object o)Invokes the same method on the wrappedHashtableobject.java.lang.Objectget(java.lang.Object key)Invokes the same method on the wrappedDictionaryobject.PropertiesListgetHead()Returns thePropertiesListobject that is the first object on the list of which this object is a member.PropertiesListgetNext()Returns thePropertiesListobject that succedes this object on the list of which this object is a member.PropertiesListgetPrior()Returns thePropertiesListobject that precedes this object on the list of which this object is a member.java.lang.StringgetProperty(java.lang.String key)Looks upkeyin the wrapped object.java.lang.StringgetProperty(java.lang.String key, java.lang.String defaultValue)UsesgetProperty(String)to look up the value associated with the key.java.util.DictionarygetWrapped()Returns theDictionaryobject wrapped by thisPropertiesList.inthashCode()Invokes the same method on the wrappedHashtableobject.booleanisEmpty()Invokes the same method on the wrappedDictionaryobject.booleanisTransient()Sub-classes of PropertiesList can override this to mark themselves "transient", in which caseaddAfterwill skip this list.java.util.Enumerationkeys()Invokes the same method on the wrappedDictionaryobject.java.util.SetkeySet()Invokes the same method on the wrappedHashtableobject.voidlist(java.io.PrintStream out)Invokes the same method on the wrappedPropertiesobject.voidlist(java.io.PrintWriter out)Invokes the same method on the wrappedPropertiesobject.voidload(java.io.InputStream in)Invokes the same method on the wrappedPropertiesobject.java.util.EnumerationpropertyNames()Invokes the same method on the wrappedPropertiesobject.java.util.EnumerationpropertyNames(java.lang.String pattern)Returns anEnumerationof property names that match aglobpattern.java.lang.Objectput(java.lang.Object key, java.lang.Object value)Invokes the same method on the wrappedDictionaryobject.voidputAll(java.util.Map t)Invokes the same method on the wrappedHashtableobject.booleanremove()Remove this object from the list in which it's a member.java.lang.Objectremove(java.lang.Object key)Invokes the same method on the wrappedDictionaryobject.booleanremoveProperty(java.lang.String key)Remove the key and its associated value from the first properties object in the chain that contains this key.booleanremoveProperty(java.lang.String key, boolean all)Remove a property from a a chain of properties lists.voidsave(java.io.OutputStream out, java.lang.String header)Invokes the same method on the wrappedPropertiesobject.java.lang.ObjectsetProperty(java.lang.String key, java.lang.String value)Invokes the same method on the wrappedPropertiesobject if it exists.intsize()Invokes the same method on the wrappedDictionaryobject.voidstore(java.io.OutputStream out, java.lang.String header)Invokes the same method on the wrappedPropertiesobject.java.lang.StringtoString()Returns aStringcontaining theSystem.identityHashCodes of this object, the wrapped object, and the preceding and succeding objects on the list of which this object is a member.java.util.Collectionvalues()Invokes the same method on the wrappedHashtableobject.PropertiesListwraps(java.util.Dictionary d)Find the firstPropertiesListobject on the list of which this object is a member that wraps theDictionaryparameter.
-
-
-
Constructor Detail
-
PropertiesList
public PropertiesList()
Constructs a newPropertiesListobject that wraps an empty newPropertiesobject.
-
PropertiesList
public PropertiesList(java.util.Dictionary dict)
Constructs a newPropertiesListobject that wraps the inputDictionary.- Parameters:
dict- TheDictionaryobject wrapped by thisPropertiesList.
-
PropertiesList
public PropertiesList(java.util.Dictionary dict, boolean searchNextFirst)Constructs a newPropertiesListobject that wraps the inputDictionary. If the boolean parameter is settrue, the wrappedDictionaryis searched after subsequentPropertiesListobjects in the linked list are searched, and only if the result of that search wasnull.- Parameters:
dict- TheDictionaryobject wrapped by thisPropertiesList.searchNextFirst- Iftrueall the following objects in the list are searched before this one.
-
-
Method Detail
-
getWrapped
public java.util.Dictionary getWrapped()
Returns theDictionaryobject wrapped by thisPropertiesList.
-
addAfter
public void addAfter(PropertiesList cursor)
Adds thisPropertiesListobject into a linked list following the object referenced by thecursorparameter. 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 thisPropertiesListobject into a linked list preceding the object referenced by thecursorparameter. 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 thePropertiesListobject that succedes this object on the list of which this object is a member.- Returns:
- A
PropertiesListobject ornull.
-
getPrior
public PropertiesList getPrior()
Returns thePropertiesListobject that precedes this object on the list of which this object is a member.- Returns:
- A
PropertiesListobject ornull.
-
getHead
public PropertiesList getHead()
Returns thePropertiesListobject 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
PropertiesListobject.
-
wraps
public PropertiesList wraps(java.util.Dictionary d)
Find the firstPropertiesListobject on the list of which this object is a member that wraps theDictionaryparameter.- Parameters:
d- TheDictionarythat is compared with the wrappedDictionary's for a match.- Returns:
PropertiesListobject 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- Iftruealso print the contents of the wrappedDictionaryobject.msg- If notnull, add this message to the header line.
-
elements
public java.util.Enumeration elements()
Invokes the same method on the wrappedDictionaryobject.- Overrides:
elementsin classjava.util.Properties
-
get
public java.lang.Object get(java.lang.Object key)
Invokes the same method on the wrappedDictionaryobject.- Specified by:
getin interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
getin classjava.util.Properties
-
isEmpty
public boolean isEmpty()
Invokes the same method on the wrappedDictionaryobject.- Specified by:
isEmptyin interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
isEmptyin classjava.util.Properties
-
keys
public java.util.Enumeration keys()
Invokes the same method on the wrappedDictionaryobject.- Overrides:
keysin classjava.util.Properties
-
put
public java.lang.Object put(java.lang.Object key, java.lang.Object value)Invokes the same method on the wrappedDictionaryobject.- Specified by:
putin interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
putin classjava.util.Properties
-
remove
public java.lang.Object remove(java.lang.Object key)
Invokes the same method on the wrappedDictionaryobject.- Specified by:
removein interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
removein classjava.util.Properties
-
size
public int size()
Invokes the same method on the wrappedDictionaryobject.- Specified by:
sizein interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
sizein classjava.util.Properties
-
clear
public void clear()
Invokes the same method on the wrappedHashtableobject.- Specified by:
clearin interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
clearin classjava.util.Properties
-
clone
public java.lang.Object clone()
Invokes the same method on the wrappedHashtableobject.- Overrides:
clonein classjava.util.Properties
-
contains
public boolean contains(java.lang.Object value)
Invokes the same method on the wrappedHashtableobject.- Overrides:
containsin classjava.util.Properties
-
containsKey
public boolean containsKey(java.lang.Object key)
Invokes the same method on the wrappedHashtableobject.- Specified by:
containsKeyin interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
containsKeyin classjava.util.Properties
-
entrySet
public java.util.Set entrySet()
Invokes the same method on the wrappedHashtableobject.- Specified by:
entrySetin interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
entrySetin classjava.util.Properties
-
equals
public boolean equals(java.lang.Object o)
Invokes the same method on the wrappedHashtableobject.- Specified by:
equalsin interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
equalsin classjava.util.Properties
-
hashCode
public int hashCode()
Invokes the same method on the wrappedHashtableobject.- Specified by:
hashCodein interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
hashCodein classjava.util.Properties
-
keySet
public java.util.Set keySet()
Invokes the same method on the wrappedHashtableobject.- Specified by:
keySetin interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
keySetin classjava.util.Properties
-
putAll
public void putAll(java.util.Map t)
Invokes the same method on the wrappedHashtableobject.- Specified by:
putAllin interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
putAllin classjava.util.Properties
-
values
public java.util.Collection values()
Invokes the same method on the wrappedHashtableobject.- Specified by:
valuesin interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
valuesin classjava.util.Properties
-
toString
public java.lang.String toString()
Returns aStringcontaining theSystem.identityHashCodes of this object, the wrapped object, and the preceding and succeding objects on the list of which this object is a member. Additionally, ifdebugistrue, the result of invokingtoStringon the wrappedDictionaryis appended.- Overrides:
toStringin classjava.util.Properties- Returns:
Stringrepresentation of this object.
-
getProperty
public java.lang.String getProperty(java.lang.String key)
Looks upkeyin the wrapped object. If the result isnullthe 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, thekeyis looked up in the wrappedPropertiesobject.- Overrides:
getPropertyin 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:
getPropertyin 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 wrappedPropertiesobject.- Overrides:
listin classjava.util.Properties
-
list
public void list(java.io.PrintWriter out)
Invokes the same method on the wrappedPropertiesobject.- Overrides:
listin classjava.util.Properties
-
load
public void load(java.io.InputStream in) throws java.io.IOExceptionInvokes the same method on the wrappedPropertiesobject.- Overrides:
loadin classjava.util.Properties- Throws:
java.io.IOException
-
propertyNames
public java.util.Enumeration propertyNames()
Invokes the same method on the wrappedPropertiesobject.- Overrides:
propertyNamesin classjava.util.Properties
-
save
public void save(java.io.OutputStream out, java.lang.String header)Invokes the same method on the wrappedPropertiesobject.- Overrides:
savein classjava.util.Properties
-
setProperty
public java.lang.Object setProperty(java.lang.String key, java.lang.String value)Invokes the same method on the wrappedPropertiesobject if it exists. Otherwise invokesputon the wrappedDictionaryobject.- Overrides:
setPropertyin classjava.util.Properties
-
store
public void store(java.io.OutputStream out, java.lang.String header) throws java.io.IOExceptionInvokes the same method on the wrappedPropertiesobject.- Overrides:
storein classjava.util.Properties- Throws:
java.io.IOException
-
propertyNames
public java.util.Enumeration propertyNames(java.lang.String pattern)
Returns anEnumerationof property names that match aglobpattern.- Parameters:
pattern- Theglobpattern to match.- Returns:
- An
Enumerationcontaining matching property names, if any.
-
isTransient
public boolean isTransient()
Sub-classes of PropertiesList can override this to mark themselves "transient", in which caseaddAfterwill skip this list.
-
-