link
Avalon
Merlin Runtime
Home PlanetProductsCentral
Defaults
Overview

A simple default property value discovery API that makes it very easy to define a policy for searching for and merging property values.

The Defaults class is a Properties subclass that holds the default property values discovered. It contains special methods to access multi-valued properties using a property name based enumeration scheme. Other nice features include a macro expansion facility and prepackaged finders for locating defaults in other default property sources.

Below in order is an the environment listing, the contents of a properties file, and the code used to discover and print out the default values discovered. The last item is the output. The defaults are searched for in the defaults.properties file, the shell environment and the system properties:

akarasulu@franklin ~
$ env
...
MERLIN_HOME=f:/apache/avalon/merlin
...
        
# defaults.properties
targets.0=./conf/webserver.xml
targets.1=./conf/eve.xml
targets.2=./conf/ftpserver.xml
targets.3=${mailserver}
...
        
// Load defaults.properties
Properties props = new Properties() ;
props.load(new FileReader( "defaults.properties" ) ) ;
props.setProperty( "mailserver", "./conf/james.xml" ) ;

// Perpare to discover defaults of interest in sources
DefaultFinders [] finders = {
    new SystemDefaultsFinder(),
    new SimpleDefaultsFinder( env ),
    new SimpleDefaultsFinder( props )
    };
String singles = { MERLIN_HOME, mailserver } ;
String enumerated = { targets } ;    
Defaults defaults = Defaults( singles, enumerated, finders ) ;

// Access and print
String home = defaults.getProperty( "MERLIN_HOME" ) ;
System.out.println( "MERLIN_HOME = " + home ) ;
String [] targets = defaults.getEnumerated( "targets" ) ;
printout( targets ) ;
        
MERLIN_HOME=f:/apache/avalon/merlin
[ ./conf/webserver.xml, ./conf/eve.xml, ./conf/ftpserver.xml, ./conf/james.xml ]