Class YamlConfiguration

  • All Implemented Interfaces:
    Cloneable, org.apache.commons.configuration2.Configuration, org.apache.commons.configuration2.event.EventSource, org.apache.commons.configuration2.FileBasedConfiguration, org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode>, org.apache.commons.configuration2.ImmutableConfiguration, org.apache.commons.configuration2.ImmutableHierarchicalConfiguration, org.apache.commons.configuration2.io.FileBased, org.apache.commons.configuration2.io.InputStreamSupport, org.apache.commons.configuration2.sync.SynchronizerSupport, org.apache.commons.configuration2.tree.InMemoryNodeModelSupport, org.apache.commons.configuration2.tree.NodeKeyResolver<org.apache.commons.configuration2.tree.ImmutableNode>, org.apache.commons.configuration2.tree.NodeModelSupport<org.apache.commons.configuration2.tree.ImmutableNode>

    public class YamlConfiguration
    extends org.apache.commons.configuration2.BaseHierarchicalConfiguration
    implements org.apache.commons.configuration2.FileBasedConfiguration, org.apache.commons.configuration2.io.InputStreamSupport

    Implementation of Apache Commons HierarchicalConfiguration that parses a YAML configuration file and loads the configuration in memory for easy access.

    Example configuration file:

     server:
          hostname: localhost
          port: 8080
     mimeTypes:
          - application/pdf
          - application/msword
     

    How to read and access the configuration

     YamlConfiguration config = new YamlConfiguration();
     config.read(new FileReader("config.yaml"));
    
     String serverHostname = config.getString("server.hostname");
     String serverPort = config.getInt("server.port");
     String pdfMimeType = config.getString("mimeTypes(0)");
     String mswordMimeType = config.getString("mimeTypes(1)");
     
    Author:
    avasquez
    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.apache.commons.configuration2.BaseHierarchicalConfiguration

        org.apache.commons.configuration2.BaseHierarchicalConfiguration.BuilderVisitor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void buildConfig​(Map<String,​Object> yamlObj)  
      protected void buildConfigFromCollection​(String name, Collection<Object> collection, org.apache.commons.configuration2.tree.ImmutableNode.Builder parent)  
      protected void buildConfigFromKeyValuePair​(String name, Object value, org.apache.commons.configuration2.tree.ImmutableNode.Builder parent)  
      protected void buildConfigFromMap​(Map<String,​Object> map, org.apache.commons.configuration2.tree.ImmutableNode.Builder parent)  
      protected void load​(Reader in)  
      void read​(InputStream in)  
      void read​(Reader in)  
      void write​(Writer out)  
      • 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, 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, containsKey, 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, 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 interface org.apache.commons.configuration2.Configuration

        addProperty, clear, clearProperty, getInterpolator, installInterpolator, setInterpolator, setProperty, subset
      • Methods inherited from interface org.apache.commons.configuration2.ImmutableConfiguration

        containsKey, 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, 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

      • YamlConfiguration

        public YamlConfiguration()
    • Method Detail

      • read

        public void read​(Reader in)
                  throws org.apache.commons.configuration2.ex.ConfigurationException,
                         IOException
        Specified by:
        read in interface org.apache.commons.configuration2.io.FileBased
        Throws:
        org.apache.commons.configuration2.ex.ConfigurationException
        IOException
      • read

        public void read​(InputStream in)
                  throws org.apache.commons.configuration2.ex.ConfigurationException,
                         IOException
        Specified by:
        read in interface org.apache.commons.configuration2.io.InputStreamSupport
        Throws:
        org.apache.commons.configuration2.ex.ConfigurationException
        IOException
      • write

        public void write​(Writer out)
                   throws org.apache.commons.configuration2.ex.ConfigurationException,
                          IOException
        Specified by:
        write in interface org.apache.commons.configuration2.io.FileBased
        Throws:
        org.apache.commons.configuration2.ex.ConfigurationException
        IOException
      • load

        protected void load​(Reader in)
                     throws org.apache.commons.configuration2.ex.ConfigurationException
        Throws:
        org.apache.commons.configuration2.ex.ConfigurationException
      • buildConfig

        protected void buildConfig​(Map<String,​Object> yamlObj)
      • buildConfigFromKeyValuePair

        protected void buildConfigFromKeyValuePair​(String name,
                                                   Object value,
                                                   org.apache.commons.configuration2.tree.ImmutableNode.Builder parent)
      • buildConfigFromMap

        protected void buildConfigFromMap​(Map<String,​Object> map,
                                          org.apache.commons.configuration2.tree.ImmutableNode.Builder parent)
      • buildConfigFromCollection

        protected void buildConfigFromCollection​(String name,
                                                 Collection<Object> collection,
                                                 org.apache.commons.configuration2.tree.ImmutableNode.Builder parent)