org.jurvis.util
Class JvPropertyLocator

java.lang.Object
  extended by org.jurvis.util.JvPropertyLocator

public class JvPropertyLocator
extends Object

A class used to locate a property within a set of property sources. Property sources are registered with JvPropertyLocator using the addSource method. Properties and ResourceBundles may be used as property sources.

Author:
Neil W. Weber

Constructor Summary
JvPropertyLocator()
          Construct a JvPropertyLocator.
 
Method Summary
protected  boolean addSource(Object source)
          Register a property source with this JvPropertyLocator.
 void addSource(Properties source)
          Register a property source with this JvPropertyLocator.
 void addSource(ResourceBundle source)
          Register a property source with this JvPropertyLocator.
 void addSource(String bundleName)
          Register a property source with this JvPropertyLocator.
 PropertyEditor getEditor(Class valueType, String valueName)
          Return the PropertyEditor for a property named valueName with type valueType.
 PropertyEditor getEditor(PropertyDescriptor pd)
          Return the PropertyEditor for the described property.
 Object getObject(Component parent, Component component, String key, Class valueType)
          Retrieve the property object with the given key within the context of a particular named Component and its parent.
 String getString(Component parent, Component component, String key)
          Retrieve the property with the given key within the context of a particular named Component and its parent.
 String getString(Component component, String key)
          Retrieve the property with the given key within the context of a particular named Component.
 String getString(String key)
          Retrieve the property with the given key.
protected  boolean hasBaseKey(String key)
          Determine if within the sources there is even a key that shares the base key of the specified key.
protected  void recordBaseKeys(Enumeration e)
          Iterate through the keys in the given enumeration and record all the base keys.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JvPropertyLocator

public JvPropertyLocator()
Construct a JvPropertyLocator.

Method Detail

addSource

public void addSource(ResourceBundle source)
Register a property source with this JvPropertyLocator.

Parameters:
source - the new property source

addSource

public void addSource(Properties source)
Register a property source with this JvPropertyLocator.

Parameters:
source - the new property source

addSource

public void addSource(String bundleName)
Register a property source with this JvPropertyLocator.

Parameters:
bundleName - the name of the ResourceBundle to register

addSource

protected boolean addSource(Object source)
Register a property source with this JvPropertyLocator.

If you call this method directly, be sure to also perform a recordBaseKeys on your source otherwise any unusual properties will not be found in your source.

Parameters:
source - the new property source
Returns:
true if the source was added

recordBaseKeys

protected void recordBaseKeys(Enumeration e)
Iterate through the keys in the given enumeration and record all the base keys. This record will later be used to speed up searching for keys via getString and getObject.

Parameters:
e - an Enumeration through a sources' keys

hasBaseKey

protected final boolean hasBaseKey(String key)
Determine if within the sources there is even a key that shares the base key of the specified key.

Parameters:
key - the key whose base key is being looked for
Returns:
true if the base key of key is found in the sources

getString

public String getString(String key)
Retrieve the property with the given key.

Parameters:
key - the key of the property to return
Returns:
the property if found; null otherwise

getString

public String getString(Component component,
                        String key)
Retrieve the property with the given key within the context of a particular named Component. In other words, look for a property keyed as "name.key" where name is the Component's name obtained via getName.

Parameters:
component - the component providing context
key - the key of the property to return
Returns:
the property if found; null otherwise

getString

public String getString(Component parent,
                        Component component,
                        String key)
Retrieve the property with the given key within the context of a particular named Component and its parent. In other words, look for a property keyed as "parent.name.key" where parent is the name of the parent obtained via getName and name is the Component's name.

If no matching property is found, the property is searched for without using the parent context. In other words, look for a property keyed as "name.key."

Parameters:
parent - the parent of the component providing additional context
component - the component providing context
key - the key of the property to return
Returns:
the property if found; null otherwise

getObject

public Object getObject(Component parent,
                        Component component,
                        String key,
                        Class valueType)
Retrieve the property object with the given key within the context of a particular named Component and its parent. This method uses getString(Component, Component, String) to locate the property and then uses the PropertyEditor for the valueType to convert the property string into an object.

Parameters:
parent - the parent of the component providing additional context
component - the component providing context
key - the key of the property to return
valueType - the class of the property object
Returns:
the property object if found; null otherwise
See Also:
getString(Component, Component, String), PropertyEditor

getEditor

public PropertyEditor getEditor(Class valueType,
                                String valueName)
Return the PropertyEditor for a property named valueName with type valueType.

Parameters:
valueType - the Class of the desired value
valueName - the name of the desired value
Returns:
the value's PropertyEditor

getEditor

public PropertyEditor getEditor(PropertyDescriptor pd)
Return the PropertyEditor for the described property.

Parameters:
pd - the property descriptor


Copyright © 1999-2004 Neil W. Weber. All Rights Reserved.