|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.kuali.rice.kns.util.properties.PropertyTree
public class PropertyTree
This class is a Recursive container for single- and multi-level key,value pairs. It relies on the assumption that the consumer (presumably a JSP) will (implicitly) call toString at the end of the chain, which will return the String value of the chain's endpoint. It implements Map because that's how we fool jstl into converting "a.b.c" into get("a").get("b").get("c") instead of getA().getB().getC() Uses LinkedHashMap and LinkedHashSet because iteration order is now important.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface java.util.Map |
|---|
Map.Entry<K,V> |
| Field Summary | |
|---|---|
(package private) Map |
children
|
(package private) String |
directValue
|
(package private) boolean |
flat
|
private static org.apache.log4j.Logger |
LOG
|
(package private) PropertyTree |
parent
|
| Constructor Summary | |
|---|---|
|
PropertyTree()
Creates an empty instance with no parent |
|
PropertyTree(boolean flat)
Creates an empty instance with no parent. |
|
PropertyTree(Properties properties)
Creates an instance pre-loaded with the given Properties |
private |
PropertyTree(PropertyTree parent)
Creates an empty instance with the given parent. |
| Method Summary | |
|---|---|
void |
clear()
Unsupported, since you can't change the contents of a PropertyTree once it has been initialized. |
private Map |
collectEntries(String prefix,
boolean flattenEntries)
Builds a HashMap containing all of the key,value pairs stored in this PropertyTree |
boolean |
containsKey(Object key)
|
boolean |
containsValue(Object value)
|
Set |
entrySet()
Returns an unmodifiable Set containing all key,value pairs in this PropertyTree and its children. |
Object |
get(Object key)
Traverses the tree structure until it finds the PropertyTree pointed to by the given key, and returns that PropertyTree instance. |
private PropertyTree |
getChild(String key)
Returns the PropertyTree associated with the given key. |
Map |
getDirectChildren()
|
private String |
getDirectValue()
|
String |
getProperty(String key)
|
private PropertyTree |
getSubtree(String key)
Returns the PropertyTree object with the given key, or null if there is none. |
private boolean |
hasChildren()
|
private boolean |
hasDirectValue()
|
boolean |
isEmpty()
|
Set |
keySet()
Returns an unmodifiable Set containing the keys of all of the entries of this PropertyTree. |
Object |
put(Object key,
Object value)
Unsupported, since you can't change the contents of a PropertyTree once it has been initialized. |
void |
putAll(Map t)
Unsupported, since you can't change the contents of a PropertyTree once it has been initialized. |
Object |
remove(Object key)
Unsupported, since you can't change the contents of a PropertyTree once it has been initialized. |
private void |
setDirectValue(String value)
Sets the directValue of this PropertyTree to the given value. |
void |
setProperties(Properties properties)
Inserts all properties from the given Properties instance into this PropertyTree. |
void |
setProperty(String key,
String value)
Associates the given key with the given value. |
int |
size()
|
String |
toString()
Returns the directValue of this PropertyTree, or null if there is none. |
private void |
validateKey(Object key)
|
private void |
validateValue(Object value)
|
Collection |
values()
Returns an unmodifiable Collection containing the values of all of the entries of this PropertyTree. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Map |
|---|
equals, hashCode |
| Field Detail |
|---|
private static org.apache.log4j.Logger LOG
final boolean flat
final PropertyTree parent
String directValue
Map children
| Constructor Detail |
|---|
public PropertyTree()
public PropertyTree(boolean flat)
private PropertyTree(PropertyTree parent)
public PropertyTree(Properties properties)
properties - | Method Detail |
|---|
public void setProperty(String key,
String value)
PropertyTree tree = new PropertyTree();
tree.set( "a.b.c", "something" );
the following statements are
equivalent ways to retrieve the value:
Object one = tree.get( "a.b.c" );
Object two = tree.get( "a" ).get( "b" ).get( "c" );
key - value -
IllegalArgumentException - if the key is null
IllegalArgumentException - if the value is nullpublic void setProperties(Properties properties)
properties -
IllegalArgumentException - if the Properties object is null
IllegalArgumentException - if a property's key is null
IllegalArgumentException - if a property's value is nullprivate PropertyTree getSubtree(String key)
key -
IllegalArgumentException - if the key is nullpublic String getProperty(String key)
key -
public Map getDirectChildren()
public String toString()
This is the hack that makes it possible for jstl to get what it needs when trying to retrive the value of a simple key or of a complex (multi-part) key.
toString in class Objectprivate void setDirectValue(String value)
value - private String getDirectValue()
private boolean hasDirectValue()
private boolean hasChildren()
private PropertyTree getChild(String key)
key -
IllegalArgumentException - if the given key is nullprivate void validateKey(Object key)
key -
IllegalArgumentException - if the given key is not a String, or is nullprivate void validateValue(Object value)
value -
IllegalArgumentException - if the given value is not a String, or is nullpublic Set entrySet()
entrySet in interface MapMap.entrySet()
private Map collectEntries(String prefix,
boolean flattenEntries)
public int size()
size in interface Mappublic boolean isEmpty()
isEmpty in interface MapMap.isEmpty()public Collection values()
values in interface MapMap.values()public Set keySet()
keySet in interface MapMap.keySet()public boolean containsKey(Object key)
containsKey in interface MapMap.containsKey(java.lang.Object)public boolean containsValue(Object value)
containsValue in interface MapMap.containsValue(java.lang.Object)public Object get(Object key)
Only returns PropertyTree instances; if you want the String value pointed to by a given key, you must call toString() on the returned PropertyTree (after verifying that it isn't null, of course).
get in interface MapMap.get(java.lang.Object)public void clear()
clear in interface Mappublic void putAll(Map t)
putAll in interface Mappublic Object remove(Object key)
remove in interface Map
public Object put(Object key,
Object value)
put in interface Map
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||