Package gov.usgs.util
Class Config
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<Object,
Object>
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 Summary
FieldsModifier and TypeFieldDescriptionMap from short configuration types to fully qualified class names.static final String
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
Fields inherited from class java.util.Properties
defaults
-
Constructor Summary
ConstructorsConstructorDescriptionConfig()
Create an empty Config object.Config
(Properties properties) Create a Config object using properties for defaults. -
Method Summary
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 Details
-
OBJECT_TYPE_PROPERTY
Property name that specifies the object type.- See Also:
-
OBJECT_TYPE_MAP
Map from short configuration types to fully qualified class names.
-
-
Constructor Details
-
Config
public Config()Create an empty Config object. -
Config
Create a Config object using properties for defaults.- Parameters:
properties
- the default properties.
-
-
Method Details
-
getObject
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
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
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
Set the global configuration object.- Parameters:
config
- the new global configuration object.
-