Package gov.usgs.util
Class Config
- java.lang.Object
-
- java.util.Dictionary<K,V>
-
- java.util.Hashtable<java.lang.Object,java.lang.Object>
-
- java.util.Properties
-
- gov.usgs.util.Ini
-
- gov.usgs.util.Config
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.util.Map<java.lang.Object,java.lang.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");
orClassname obj = (Classname) new Config(Config.getConfig().getSection( "objectName")).getObject();
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.Map<java.lang.String,java.lang.String>
OBJECT_TYPE_MAP
Map from short configuration types to fully qualified class names.static java.lang.String
OBJECT_TYPE_PROPERTY
Property name that specifies the object type.-
Fields inherited from class gov.usgs.util.Ini
ALTERNATE_COMMENT_START, COMMENT_START, PROPERTY_DELIMITER, SECTION_END, SECTION_START
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Config
getConfig()
Get the global configuration object.java.lang.Object
getObject()
Load a configured object.java.lang.Object
getObject(java.lang.String name)
Get a section as a Config object.static void
setConfig(Config config)
Set the global configuration object.-
Methods inherited from class gov.usgs.util.Ini
getSectionProperty, getSections, list, list, load, save, setSectionProperty, store, write
-
Methods inherited from class java.util.Properties
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, getProperty, getProperty, hashCode, isEmpty, keys, keySet, load, loadFromXML, merge, propertyNames, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, save, setProperty, size, store, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values
-
-
-
-
Field Detail
-
OBJECT_TYPE_PROPERTY
public static final java.lang.String OBJECT_TYPE_PROPERTY
Property name that specifies the object type.- See Also:
- Constant Field Values
-
OBJECT_TYPE_MAP
public static final java.util.Map<java.lang.String,java.lang.String> OBJECT_TYPE_MAP
Map from short configuration types to fully qualified class names.
-
-
Method Detail
-
getObject
public java.lang.Object getObject() throws java.lang.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:
java.lang.Exception
- if any errors occur.
-
getObject
public java.lang.Object getObject(java.lang.String name) throws java.lang.Exception
Get a section as a Config object.- Parameters:
name
- name of config section.- Returns:
- section properties as a Config object.
- Throws:
java.lang.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.
-
-