org.apache.avalon.util.defaults
Class Defaults

java.lang.Object
  extended byjava.util.Dictionary
      extended byjava.util.Hashtable
          extended byjava.util.Properties
              extended byorg.apache.avalon.util.defaults.Defaults
All Implemented Interfaces:
Cloneable, Map, Serializable

public class Defaults
extends Properties

Gets a set of default property values based on a sequence of default value search components or finders.

Version:
$Revision: 1.2 $
Author:
Alex Karasulu, $Author: mcconnell $
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
Defaults(String[] a_singles, String[] a_enumerated, DefaultsFinder[] a_finders)
          Creates and populates a set of properties
 
Method Summary
static void discover(Defaults a_defaults, Properties[] a_sources, boolean a_haltOnDiscovery)
          Merges a set of properties from source Properties into a Defaults instance.
static String discover(String l_key, Properties[] a_sources, boolean a_haltOnDiscovery)
          Discovers a value within a set of Properties either halting on the first time the property is discovered or continuing on to take the last value found for the property key.
 boolean getBoolean(String a_key)
          Utility method that gets a key's value and returns a boolean value to represent it.
 String[] getEnumerated()
          Gets the base names of enumerated multi-valued keys.
 String[] getEnumerated(String a_base)
          Gets the default values for an enumerated key.
 DefaultsFinder[] getFinders()
          Gets the linear set of finders composing the search policy.
 String[] getSingles()
          Gets the names of all the single valued properties.
static Properties getStaticProperties(Class ref, String path)
          Read in a static properties resource relative to a supplied class and path.
static void macroExpand(Properties a_expanded, Properties[] a_optionals)
          Expands out a set of property key macros in the following format ${foo.bar} where foo.bar is a property key, by dereferencing the value of the key using the original source Properties and other optional Properties.
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, load, propertyNames, save, setProperty, store
 
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
 

Constructor Detail

Defaults

public Defaults(String[] a_singles,
                String[] a_enumerated,
                DefaultsFinder[] a_finders)
Creates and populates a set of properties

Parameters:
a_singles - single valued key names
a_enumerated - multi-valued key names
a_finders - search components used for staged discovery of defaults
Method Detail

getEnumerated

public String[] getEnumerated()
Gets the base names of enumerated multi-valued keys. Such keys are enumerated to have multiple values by appending an index onto a key base like so: [base.key].1,[base.key].2,[base.key].3 ... [base.key].N. The returned keys are just the base key names of multi-valued properties and do not include the appended index.

Returns:
the base key names for multi-valued properties

getFinders

public DefaultsFinder[] getFinders()
Gets the linear set of finders composing the search policy.

Returns:
the finders used to discover property defaults

getSingles

public String[] getSingles()
Gets the names of all the single valued properties.

Returns:
single valued property key names

getEnumerated

public String[] getEnumerated(String a_base)
Gets the default values for an enumerated key.

Parameters:
a_base - the base of the enumerated key
Returns:
the values of the multi-valued property

getBoolean

public boolean getBoolean(String a_key)
Utility method that gets a key's value and returns a boolean value to represent it.

Parameters:
a_key - the boolean property key
Returns:
true if the property is 1, true, yes or on, and false otherwise

discover

public static void discover(Defaults a_defaults,
                            Properties[] a_sources,
                            boolean a_haltOnDiscovery)
Merges a set of properties from source Properties into a Defaults instance. Does not allow null overrides.

Parameters:
a_defaults - the defaults to populate on discovery
a_sources - the sources to search
a_haltOnDiscovery - true to halt on first find or false to continue to last find

discover

public static String discover(String l_key,
                              Properties[] a_sources,
                              boolean a_haltOnDiscovery)
Discovers a value within a set of Properties either halting on the first time the property is discovered or continuing on to take the last value found for the property key.

Parameters:
l_key - a property key
a_sources - a set of source Properties
a_haltOnDiscovery - true if we stop on finding a value, false otherwise
Returns:
the value found or null

macroExpand

public static void macroExpand(Properties a_expanded,
                               Properties[] a_optionals)
Expands out a set of property key macros in the following format ${foo.bar} where foo.bar is a property key, by dereferencing the value of the key using the original source Properties and other optional Properties. If the original expanded Properties contain the value for the macro key foo.bar then dereferencing stops by using the value in the expanded Properties: the other optional Properties are NOT used at all. If the original expanded Properties do NOT contain the value for the macro key, then the optional Properties are used in order. The first of the optionals to contain the value for the macro key (foo.bar) shorts the search. Hence the first optional Properties in the array to contain a value for the macro key (foo.bar) is used to set the expanded value. If a macro cannot be expanded because it's key was not defined within the expanded Properties or one of the optional Properties then it is left as is.

Parameters:
a_expanded - the Properties to perform the macro expansion upon
a_optionals - null or an optional set of Properties to use for dereferencing macro keys (foo.bar)

getStaticProperties

public static Properties getStaticProperties(Class ref,
                                             String path)
                                      throws IOException
Read in a static properties resource relative to a supplied class and path.

Parameters:
ref - a class used to establish a classloader and anchors relative path references
path - the resoruce address
Returns:
the static properties
Throws:
IllegalStateException - if the path is unresolvable
IOException


Copyright © Apache Software Foundation. All Rights Reserved.