Package gov.usgs.util

Class Config

All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>

public class Config extends Ini
The configuration object used for distribution. This object holds a singleton reference to the global configuration. Users should use the static method getConfig() to retrieve the loaded configuration. Objects are loaded from Config objects using the property "type". The value of the property "type" should be a fully qualified class name. This can be used for Any type of object that has a constructor with no arguments. If the loaded object implements the Configurable interface, its "configure" method is called using the Config object.
 [objectName]
 type = fully.qualified.Classname
 ... other object properties

 [anotherObject]
 ...
 
Some objects refer to other named configured objects. These named objects correspond to sections in the global configuration object. These objects are loaded using the getObject() method:
 Classname obj = (Classname) Config.getConfig().getObject("objectName");
 
or
 Classname obj = (Classname) new Config(Config.getConfig().getSection("objectName")).getObject();
 
See Also:
  • Field Details

    • OBJECT_TYPE_PROPERTY

      public static final String OBJECT_TYPE_PROPERTY
      Property name that specifies the object type.
      See Also:
    • OBJECT_TYPE_MAP

      public static final Map<String,String> OBJECT_TYPE_MAP
      Map from short configuration types to fully qualified class names.
  • Constructor Details

    • Config

      public Config()
      Create an empty Config object.
    • Config

      public Config(Properties properties)
      Create a Config object using properties for defaults.
      Parameters:
      properties - the default properties.
  • Method Details

    • getObject

      public Object getObject() throws Exception
      Load a configured object. Uses the property "type" to determine which type of object to load. If the loaded object implements the Configurable interface, its configure method is called before returning.
      Returns:
      the loaded object
      Throws:
      Exception - if any errors occur.
    • getObject

      public Object getObject(String name) throws Exception
      Get a section as a Config object.
      Parameters:
      name - name of config section.
      Returns:
      section properties as a Config object.
      Throws:
      Exception - if any errors occur.
    • getConfig

      public static Config getConfig()
      Get the global configuration object. Users are encouraged to not maintain a reference to the returned object, in case it is updated.
      Returns:
      the global configuration object.
    • setConfig

      public static void setConfig(Config config)
      Set the global configuration object.
      Parameters:
      config - the new global configuration object.