org.apache.avalon.util.defaults
Class DefaultsBuilder

java.lang.Object
  extended byorg.apache.avalon.util.defaults.DefaultsBuilder

public class DefaultsBuilder
extends Object

A utility class that provides support for the establishment of a set of installation properties.

Version:
$Revision: 1.6 $
Author:
Avalon Development Team

Constructor Summary
DefaultsBuilder(String key, File work)
           
 
Method Summary
 Properties getConsolidatedProperties(Properties defaults, String[] keys)
          Return a consolidated set of properties.
 Properties getConsolidatedProperties(Properties defaults, String[] keys, String[] sequence)
          Return a consolidated set of properties.
 Properties getDirProperties()
          Return the application specific properties from the current working directory.
 File getHomeDirectory()
          Return the application home directory.
static File getHomeDirectory(String key)
          Return a home directory taking into account a supplied env symbol, a property key and a fallback directory.
 Properties getHomeProperties()
          Return the application properties.
static Properties getHomeProperties(File home, String key, boolean flag)
          Create a installation properties object.
static Properties getProperties(ClassLoader classloader, String path)
           
static Properties getProperties(File file)
          Create a properties object from the supplied file.
static Properties getProperties(File dir, String key)
          Create a dir properties object.
 Properties getUserProperties()
          Return the application specific properties from the users home directory.
static Properties getUserProperties(String key)
          Create a user properties object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultsBuilder

public DefaultsBuilder(String key,
                       File work)
                throws IOException
Method Detail

getHomeDirectory

public static File getHomeDirectory(String key)
                             throws IOException
Return a home directory taking into account a supplied env symbol, a property key and a fallback directory. If the supplied key references a known system property value of '[key].home' then that value will be used to establish the home directory. Otherwise, if the supplied env symbol cannot be resolved to a value, a directory corresponding to ${user.home}/.[key] will be returned.

Parameters:
key - an application key such as 'merlin'
Returns:
the derived directory
Throws:
IOException

getHomeProperties

public static Properties getHomeProperties(File home,
                                           String key,
                                           boolean flag)
                                    throws IOException
Create a installation properties object. The implementation will create a new properties object and read in a properties file if it exists relative to the filename [home]/[key].properties. Before returning the properties object the home directory will be assigned as the value of a property name [key].home if the supplied flag argument is TRUE.

Parameters:
home - the home directory
key - the application key
flag - if TRUE set the property '[key].home' to the home directory
Returns:
the application properties object
Throws:
IOException

getUserProperties

public static Properties getUserProperties(String key)
                                    throws IOException
Create a user properties object. The implementation will create a new properties object and read in a properties file if it exists relative to the filename ${user.home}/[key].properties.

Parameters:
key - the application key
Returns:
the user properties object
Throws:
IOException

getProperties

public static Properties getProperties(File dir,
                                       String key)
                                throws IOException
Create a dir properties object. The implementation will create a new properties object and read in a properties file if it exists relative to [dir]/[key].properties.

Parameters:
dir - the base directory
key - the application key
Returns:
the user properties object
Throws:
IOException

getProperties

public static Properties getProperties(File file)
                                throws IOException
Create a properties object from the supplied file. If the file does not exists an empty property object will be returned.

Parameters:
file - the properties file
Returns:
the properties object
Throws:
IOException

getProperties

public static Properties getProperties(ClassLoader classloader,
                                       String path)
                                throws IOException
Throws:
IOException

getHomeDirectory

public File getHomeDirectory()
Return the application home directory.

Returns:
the home directory

getHomeProperties

public Properties getHomeProperties()
Return the application properties. Properties returned are resolved relative to a properties file named [key].properties in the application home directory.

Returns:
the home directory

getUserProperties

public Properties getUserProperties()
Return the application specific properties from the users home directory.

Returns:
the user's application properties

getDirProperties

public Properties getDirProperties()
Return the application specific properties from the current working directory.

Returns:
the working application properties

getConsolidatedProperties

public Properties getConsolidatedProperties(Properties defaults,
                                            String[] keys)
                                     throws IOException
Return a consolidated set of properties.

Parameters:
defaults - the source properties
keys - the simple property keys
Returns:
the consolidated properties
Throws:
IOException

getConsolidatedProperties

public Properties getConsolidatedProperties(Properties defaults,
                                            String[] keys,
                                            String[] sequence)
                                     throws IOException
Return a consolidated set of properties.

Parameters:
defaults - the source properties
keys - the simple property keys
sequence - the sequence property keys
Returns:
the consolidated properties
Throws:
IOException


Copyright © The Apache Software Foundation. All Rights Reserved.