Class AbstractYAMLBasedConfiguration
- java.lang.Object
-
- org.apache.commons.configuration2.event.BaseEventSource
-
- org.apache.commons.configuration2.AbstractConfiguration
-
- org.apache.commons.configuration2.AbstractHierarchicalConfiguration<ImmutableNode>
-
- org.apache.commons.configuration2.BaseHierarchicalConfiguration
-
- org.apache.commons.configuration2.AbstractYAMLBasedConfiguration
-
- All Implemented Interfaces:
java.lang.Cloneable
,Configuration
,EventSource
,HierarchicalConfiguration<ImmutableNode>
,ImmutableConfiguration
,ImmutableHierarchicalConfiguration
,SynchronizerSupport
,InMemoryNodeModelSupport
,NodeKeyResolver<ImmutableNode>
,NodeModelSupport<ImmutableNode>
- Direct Known Subclasses:
JSONConfiguration
public class AbstractYAMLBasedConfiguration extends BaseHierarchicalConfiguration
A base class for configuration implementations based on YAML structures.
This base class offers functionality related to YAML-like data structures based on maps. Such a map has strings as keys and arbitrary objects as values. The class offers methods to transform such a map into a hierarchy of
ImmutableNode
objects and vice versa.- Since:
- 2.2
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.commons.configuration2.BaseHierarchicalConfiguration
BaseHierarchicalConfiguration.BuilderVisitor
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractYAMLBasedConfiguration()
Creates a new instance ofAbstractYAMLBasedConfiguration
.protected
AbstractYAMLBasedConfiguration(HierarchicalConfiguration<ImmutableNode> c)
Creates a new instance ofAbstractYAMLBasedConfiguration
as a copy of the specified configuration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
addEntry(java.util.Map<java.lang.String,java.lang.Object> map, java.lang.String key, java.lang.Object value)
Adds a key value pair to a map, taking list structures into account.private static java.util.List<ImmutableNode>
constructHierarchy(java.lang.String key, java.lang.Object elem)
Creates a part of the hierarchical nodes structure of the resulting configuration.protected java.util.Map<java.lang.String,java.lang.Object>
constructMap(ImmutableNode node)
Constructs a YAML map, i.e.protected void
load(java.util.Map<java.lang.String,java.lang.Object> map)
Loads this configuration from the content of the specified map.private static java.util.List<ImmutableNode>
parseCollection(java.util.Collection<java.lang.Object> col, java.lang.String key)
Parses a collection structure.private static java.util.List<ImmutableNode>
parseMap(java.util.Map<java.lang.String,java.lang.Object> map, java.lang.String key)
Parses a map structure.(package private) static void
rethrowException(java.lang.Exception e)
Internal helper method to wrap an exception in aConfigurationException
.-
Methods inherited from class org.apache.commons.configuration2.BaseHierarchicalConfiguration
childConfigurationsAt, childConfigurationsAt, cloneNodeModel, configurationAt, configurationAt, configurationsAt, configurationsAt, createSubConfigurationForTrackedNode, getNodeModel, getSubConfigurationNodeSelector, getSubConfigurationParentModel, immutableChildConfigurationsAt, immutableConfigurationAt, immutableConfigurationAt, immutableConfigurationsAt, initSubConfigurationForThisParent, interpolatedConfiguration, subnodeConfigurationChanged, subset
-
Methods inherited from class org.apache.commons.configuration2.AbstractHierarchicalConfiguration
addNodes, addNodesInternal, addPropertyDirect, addPropertyInternal, clearInternal, clearPropertyDirect, clearTree, clearTreeInternal, clone, containsKeyInternal, containsValueInternal, fetchNodeList, getExpressionEngine, getKeysInternal, getKeysInternal, getMaxIndex, getMaxIndexInternal, getModel, getPropertyInternal, getRootElementName, getRootElementNameInternal, isEmptyInternal, nodeDefined, nodeKey, resolveAddKey, resolveKey, resolveNodeKey, resolveUpdateKey, setExpressionEngine, setPropertyInternal, sizeInternal, toString
-
Methods inherited from class org.apache.commons.configuration2.AbstractConfiguration
addErrorLogListener, addProperty, append, beginRead, beginWrite, clear, clearProperty, cloneInterpolator, contains, containsKey, containsValue, copy, endRead, endWrite, get, get, getArray, getArray, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getCollection, getCollection, getConfigurationDecoder, getConversionHandler, getDouble, getDouble, getDouble, getDuration, getDuration, getEncodedString, getEncodedString, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getInterpolator, getKeys, getKeys, getKeys, getKeysInternal, getList, getList, getList, getList, getListDelimiterHandler, getLogger, getLong, getLong, getLong, getProperties, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, getSynchronizer, immutableSubset, initLogger, installInterpolator, interpolate, interpolate, isEmpty, isScalarValue, isThrowExceptionOnMissing, lock, setConfigurationDecoder, setConversionHandler, setDefaultLookups, setInterpolator, setListDelimiterHandler, setLogger, setParentInterpolator, setPrefixLookups, setProperty, setSynchronizer, setThrowExceptionOnMissing, size, unlock
-
Methods inherited from class org.apache.commons.configuration2.event.BaseEventSource
addEventListener, clearErrorListeners, clearEventListeners, copyEventListeners, createErrorEvent, createEvent, fireError, fireEvent, getEventListenerRegistrations, getEventListeners, isDetailEvents, removeEventListener, setDetailEvents
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.commons.configuration2.Configuration
addProperty, clear, clearProperty, getInterpolator, installInterpolator, setInterpolator, setProperty
-
Methods inherited from interface org.apache.commons.configuration2.ImmutableConfiguration
containsKey, containsValue, get, get, getArray, getArray, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getCollection, getCollection, getDouble, getDouble, getDouble, getDuration, getDuration, getEncodedString, getEncodedString, getEnum, getEnum, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getKeys, getKeys, getKeys, getList, getList, getList, getList, getLong, getLong, getLong, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, immutableSubset, isEmpty, size
-
Methods inherited from interface org.apache.commons.configuration2.sync.SynchronizerSupport
getSynchronizer, lock, setSynchronizer, unlock
-
-
-
-
Constructor Detail
-
AbstractYAMLBasedConfiguration
protected AbstractYAMLBasedConfiguration()
Creates a new instance ofAbstractYAMLBasedConfiguration
.
-
AbstractYAMLBasedConfiguration
protected AbstractYAMLBasedConfiguration(HierarchicalConfiguration<ImmutableNode> c)
Creates a new instance ofAbstractYAMLBasedConfiguration
as a copy of the specified configuration.- Parameters:
c
- the configuration to be copied
-
-
Method Detail
-
addEntry
private static void addEntry(java.util.Map<java.lang.String,java.lang.Object> map, java.lang.String key, java.lang.Object value)
Adds a key value pair to a map, taking list structures into account. If a key is added which is already present in the map, this method ensures that a list is created.- Parameters:
map
- the mapkey
- the keyvalue
- the value
-
constructHierarchy
private static java.util.List<ImmutableNode> constructHierarchy(java.lang.String key, java.lang.Object elem)
Creates a part of the hierarchical nodes structure of the resulting configuration. The passed in element is converted into one or multiple configuration nodes. (If list structures are involved, multiple nodes are returned.)- Parameters:
key
- the key of the new node(s)elem
- the element to be processed- Returns:
- a list with configuration nodes representing the element
-
parseCollection
private static java.util.List<ImmutableNode> parseCollection(java.util.Collection<java.lang.Object> col, java.lang.String key)
Parses a collection structure. The elements of the collection are processed recursively.- Parameters:
col
- the collection to be processedkey
- the key under which this collection is to be stored- Returns:
- a node representing this collection
-
parseMap
private static java.util.List<ImmutableNode> parseMap(java.util.Map<java.lang.String,java.lang.Object> map, java.lang.String key)
Parses a map structure. The single keys of the map are processed recursively.- Parameters:
map
- the map to be processedkey
- the key under which this map is to be stored- Returns:
- a node representing this map
-
rethrowException
static void rethrowException(java.lang.Exception e) throws ConfigurationException
Internal helper method to wrap an exception in aConfigurationException
.- Parameters:
e
- the exception to be wrapped- Throws:
ConfigurationException
- the resulting exception
-
constructMap
protected java.util.Map<java.lang.String,java.lang.Object> constructMap(ImmutableNode node)
Constructs a YAML map, i.e. String -> Object from a given configuration node.- Parameters:
node
- The configuration node to create a map from.- Returns:
- A Map that contains the configuration node information.
-
load
protected void load(java.util.Map<java.lang.String,java.lang.Object> map)
Loads this configuration from the content of the specified map. The data in the map is transformed into a hierarchy ofImmutableNode
objects.- Parameters:
map
- the map to be processed
-
-