eu.planets_project.ifr.core.common.conf
Class ServiceConfig

java.lang.Object
  extended by eu.planets_project.ifr.core.common.conf.ServiceConfig

public final class ServiceConfig
extends java.lang.Object

Factory for obtaining configuration parameters. Configuration files are "properties" files, stored in a common directory which is defined by the system property "eu.planets-project.config.dir" Generally, configuration is expected to be performed in a manner analogous to log4j. For example:

 public class MyClass {
     private static Configuration config = ServiceConfig.getConfiguration(MyClass.class);
     
     public MyClass() {
         String value1 = config.getString("test.name");
         int    value2 = config.getInt("test.version");
     }
 }
 
The configuration will then be loaded from a file in the directory specified (above). The name of the configuration file will be the fully qualified class name suffixed with ".properties" The method getConfiguration() can alternatively accept a String type parameter which allows the name of the configuration file to be more explicitly specified. The name of the configuration file will be the value of the parameter suffixed with ".properties" and will still be located in the directory specified above. If the property file does not exist, or cannot be parsed a ConfigurationException will be thrown. If a property is requested that cannot be found, a NoSuchElementException will be thrown.


Method Summary
static Configuration getConfiguration(java.lang.Class<?> clazz)
          Find the configuration file for a given class and return an object representing it.
static Configuration getConfiguration(java.io.File properties)
          Return a configuration based on the contents of the passed file
static Configuration getConfiguration(java.lang.String basename)
          Find a configuration file and return an object representing it.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getConfiguration

public static Configuration getConfiguration(java.lang.Class<?> clazz)
                                      throws ConfigurationException
Find the configuration file for a given class and return an object representing it.

Parameters:
clazz - Specifies the configuration file in question. The filename will be the fully qualified class name suffixed with ".properties"
Returns:
Representation of the configuration file
Throws:
ConfigurationException - If the appropriate file cannot be found or, if present, parsed correctly.

getConfiguration

public static Configuration getConfiguration(java.lang.String basename)
                                      throws ConfigurationException
Find a configuration file and return an object representing it.

Parameters:
basename - Specifies the configuration file in question. The filename will be suffixed with ".properties"
Returns:
Representation of the configuration file
Throws:
ConfigurationException - If the appropriate file cannot be found or, if present, parsed correctly.

getConfiguration

public static Configuration getConfiguration(java.io.File properties)
Return a configuration based on the contents of the passed file

Parameters:
properties - the config file
Returns:
Representation of the config file


Copyright © 2007-2010 The Planets Consortium. All Rights Reserved.