Class YamlProperties

  • All Implemented Interfaces:
    Properties, ResourceProperties, org.refcodes.mixin.DelimiterAccessor, org.refcodes.mixin.Dumpable, org.refcodes.mixin.TypeAccessor<java.lang.String>, org.refcodes.structure.CanonicalMap, org.refcodes.structure.Containable, org.refcodes.structure.Dictionary<java.lang.String,java.lang.String>, org.refcodes.structure.Keys<java.lang.String,java.lang.String>, org.refcodes.structure.PathMap<java.lang.String>, org.refcodes.structure.PropertiesAccessorMixin

    public class YamlProperties
    extends AbstractResourceProperties
    implements ResourceProperties
    Implementation of the ResourceProperties interface with support of so called "YAML properties". For YAML properties, see "https://en.wikipedia.org/wiki/YAML"
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  YamlProperties.YamlPropertiesFactory
      • Nested classes/interfaces inherited from interface org.refcodes.structure.CanonicalMap

        org.refcodes.structure.CanonicalMap.CanonicalMapBuilder, org.refcodes.structure.CanonicalMap.MutableCanonicalMap
      • Nested classes/interfaces inherited from interface org.refcodes.mixin.DelimiterAccessor

        org.refcodes.mixin.DelimiterAccessor.DelimiterBuilder<B extends org.refcodes.mixin.DelimiterAccessor.DelimiterBuilder<B>>, org.refcodes.mixin.DelimiterAccessor.DelimiterMutator, org.refcodes.mixin.DelimiterAccessor.DelimiterProperty
      • Nested classes/interfaces inherited from interface org.refcodes.structure.Dictionary

        org.refcodes.structure.Dictionary.MutableDictionary<K extends java.lang.Object,V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface org.refcodes.structure.Keys

        org.refcodes.structure.Keys.MutableKeys<K extends java.lang.Object,V extends java.lang.Object>, org.refcodes.structure.Keys.MutableValues<K extends java.lang.Object,V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface org.refcodes.structure.PathMap

        org.refcodes.structure.PathMap.MutablePathMap<T extends java.lang.Object>, org.refcodes.structure.PathMap.PathMapBuilder<T extends java.lang.Object>
      • Nested classes/interfaces inherited from interface org.refcodes.structure.PropertiesAccessorMixin

        org.refcodes.structure.PropertiesAccessorMixin.PropertiesBuilderMixin<T extends java.lang.Object>, org.refcodes.structure.PropertiesAccessorMixin.PropertiesMixin, org.refcodes.structure.PropertiesAccessorMixin.PropertiesMutatorMixin
      • Nested classes/interfaces inherited from interface org.refcodes.mixin.TypeAccessor

        org.refcodes.mixin.TypeAccessor.TypeMutator<T extends java.lang.Object>, org.refcodes.mixin.TypeAccessor.TypeProperty<T extends java.lang.Object>
    • Constructor Summary

      Constructors 
      Constructor Description
      YamlProperties​(java.io.File aFile)
      Loads the YAML Properties from the given File.
      YamlProperties​(java.io.File aFile, char... aDelimiters)
      Loads the YAML Properties from the given File.
      YamlProperties​(java.io.File aFile, org.refcodes.runtime.ConfigLocator aConfigLocator)
      Loads or seeks the YAML Properties from the given File.
      YamlProperties​(java.io.File aFile, org.refcodes.runtime.ConfigLocator aConfigLocator, char... aDelimiters)
      Loads or seeks the YAML Properties from the given File.
      YamlProperties​(java.io.InputStream aInputStream)
      Reads the YAML Properties from the given InputStream.
      YamlProperties​(java.io.InputStream aInputStream, char... aDelimiters)
      Reads the YAML Properties from the given InputStream.
      YamlProperties​(java.lang.Class<?> aResourceClass, java.lang.String aFilePath)
      Loads the YAML Properties from the given file's path.
      YamlProperties​(java.lang.Class<?> aResourceClass, java.lang.String aFilePath, char... aDelimiters)
      Loads the YAML Properties from the given file's path.
      YamlProperties​(java.lang.Class<?> aResourceClass, java.lang.String aFilePath, org.refcodes.runtime.ConfigLocator aConfigLocator)
      Loads the YAML Properties from the given file's path.
      YamlProperties​(java.lang.Class<?> aResourceClass, java.lang.String aFilePath, org.refcodes.runtime.ConfigLocator aConfigLocator, char... aDelimiters)
      Loads the YAML Properties from the given file's path.
      YamlProperties​(java.lang.Object aObj)
      Create a YamlProperties instance containing the elements as of PathMap.MutablePathMap.insert(Object) using the default path delimiter "/" (Delimiter.PATH) for the path declarations: "Inspects the given object and adds all elements found in the given object.
      YamlProperties​(java.lang.String aFilePath)
      Loads the YAML Properties from the given file's path.
      YamlProperties​(java.lang.String aFilePath, char... aDelimiters)
      Loads the YAML Properties from the given file's path.
      YamlProperties​(java.lang.String aFilePath, org.refcodes.runtime.ConfigLocator aConfigLocator)
      Loads the YAML Properties from the given file's path.
      YamlProperties​(java.lang.String aFilePath, org.refcodes.runtime.ConfigLocator aConfigLocator, char... aDelimiters)
      Loads the YAML Properties from the given file's path.
      YamlProperties​(java.net.URL aUrl)
      Loads the YAML Properties from the given URL.
      YamlProperties​(java.net.URL aUrl, char... aDelimiters)
      Loads the YAML Properties from the given URL.
      YamlProperties​(java.util.Map<?,?> aProperties)
      Create a YamlProperties instance containing the elements of the provided Map instance using the default path delimiter "/" (Delimiter.PATH) for the path declarations
      YamlProperties​(Properties aProperties)
      Create a YamlProperties instance containing the elements of the provided Properties instance using the default path delimiter "/" (Delimiter.PATH) for the path declarations
      YamlProperties​(Properties.PropertiesBuilder aProperties)
      Create a YamlProperties instance containing the elements of the provided Properties.PropertiesBuilder instance using the default path delimiter "/" (Delimiter.PATH) for the path declarations
    • Constructor Detail

      • YamlProperties

        public YamlProperties​(java.lang.Object aObj)
        Create a YamlProperties instance containing the elements as of PathMap.MutablePathMap.insert(Object) using the default path delimiter "/" (Delimiter.PATH) for the path declarations: "Inspects the given object and adds all elements found in the given object. Elements of type Map, Collection and arrays are identified and handled as of their type: The path for each value in a Map is appended with its according key. The path for each value in a Collection or array is appended with its according index of occurrence (in case of a List or an array, its actual index). In case of reflection, the path for each member is appended with its according mamber's name. All elements (e.g. the members and values) are inspected recursively which results in the according paths of the terminating values."
        Parameters:
        aObj - The object from which the elements are to be added.
      • YamlProperties

        public YamlProperties​(Properties aProperties)
        Create a YamlProperties instance containing the elements of the provided Properties instance using the default path delimiter "/" (Delimiter.PATH) for the path declarations
        Parameters:
        aProperties - the properties to be added.
      • YamlProperties

        public YamlProperties​(java.util.Map<?,?> aProperties)
        Create a YamlProperties instance containing the elements of the provided Map instance using the default path delimiter "/" (Delimiter.PATH) for the path declarations
        Parameters:
        aProperties - the properties to be added.
      • YamlProperties

        public YamlProperties​(java.io.File aFile)
                       throws java.io.IOException,
                              java.text.ParseException
        Loads the YAML Properties from the given File.
        Parameters:
        aFile - The File from which to load the properties.
        Throws:
        java.io.IOException - thrown in case accessing or processing the properties file failed.
        java.text.ParseException - Signals that an error has been reached unexpectedly while parsing the data to be loaded.
      • YamlProperties

        public YamlProperties​(java.io.File aFile,
                              char... aDelimiters)
                       throws java.io.IOException,
                              java.text.ParseException
        Loads the YAML Properties from the given File.
        Parameters:
        aFile - The File from which to load the properties.
        aDelimiters - The path delimiters to be used when parsing the source's properties.
        Throws:
        java.io.IOException - thrown in case accessing or processing the properties file failed.
        java.text.ParseException - Signals that an error has been reached unexpectedly while parsing the data to be loaded.
      • YamlProperties

        public YamlProperties​(java.io.File aFile,
                              org.refcodes.runtime.ConfigLocator aConfigLocator)
                       throws java.io.IOException,
                              java.text.ParseException
        Loads or seeks the YAML Properties from the given File. A provided ConfigLocator describes the locations to additional crawl for the desired file.
        Parameters:
        aFile - The File from which to load the properties.
        aConfigLocator - The ConfigLocator describes the locations to additional crawl for the desired file.
        Throws:
        java.io.IOException - thrown in case accessing or processing the properties file failed.
        java.text.ParseException - Signals that an error has been reached unexpectedly while parsing the data to be loaded.
      • YamlProperties

        public YamlProperties​(java.io.File aFile,
                              org.refcodes.runtime.ConfigLocator aConfigLocator,
                              char... aDelimiters)
                       throws java.io.IOException,
                              java.text.ParseException
        Loads or seeks the YAML Properties from the given File. A provided ConfigLocator describes the locations to additional crawl for the desired file.
        Parameters:
        aFile - The File from which to load the properties.
        aConfigLocator - The ConfigLocator describes the locations to additional crawl for the desired file.
        aDelimiters - The path delimiters to be used when parsing the source's properties.
        Throws:
        java.io.IOException - thrown in case accessing or processing the properties file failed.
        java.text.ParseException - Signals that an error has been reached unexpectedly while parsing the data to be loaded.
      • YamlProperties

        public YamlProperties​(java.lang.String aFilePath)
                       throws java.io.IOException,
                              java.text.ParseException
        Loads the YAML Properties from the given file's path.
        Parameters:
        aFilePath - The path to the file from which to load the properties.
        Throws:
        java.io.IOException - thrown in case accessing or processing the properties file failed.
        java.text.ParseException - Signals that an error has been reached unexpectedly while parsing the data to be loaded.
      • YamlProperties

        public YamlProperties​(java.lang.String aFilePath,
                              char... aDelimiters)
                       throws java.io.IOException,
                              java.text.ParseException
        Loads the YAML Properties from the given file's path.
        Parameters:
        aFilePath - The path to the file from which to load the properties.
        aDelimiters - The path delimiters to be used when parsing the source's properties.
        Throws:
        java.io.IOException - thrown in case accessing or processing the properties file failed.
        java.text.ParseException - Signals that an error has been reached unexpectedly while parsing the data to be loaded.
      • YamlProperties

        public YamlProperties​(java.lang.Class<?> aResourceClass,
                              java.lang.String aFilePath)
                       throws java.io.IOException,
                              java.text.ParseException
        Loads the YAML Properties from the given file's path.
        Parameters:
        aResourceClass - The class which's class loader is to take care of loading the properties (from inside a JAR).
        aFilePath - The file path of the class's resources from which to load the properties.
        Throws:
        java.io.IOException - thrown in case accessing or processing the properties file failed.
        java.text.ParseException - Signals that an error has been reached unexpectedly while parsing the data to be loaded.
      • YamlProperties

        public YamlProperties​(java.lang.Class<?> aResourceClass,
                              java.lang.String aFilePath,
                              char... aDelimiters)
                       throws java.io.IOException,
                              java.text.ParseException
        Loads the YAML Properties from the given file's path.
        Parameters:
        aResourceClass - The class which's class loader is to take care of loading the properties (from inside a JAR).
        aFilePath - The file path of the class's resources from which to load the properties.
        aDelimiters - The path delimiters to be used when parsing the source's properties.
        Throws:
        java.io.IOException - thrown in case accessing or processing the properties file failed.
        java.text.ParseException - Signals that an error has been reached unexpectedly while parsing the data to be loaded.
      • YamlProperties

        public YamlProperties​(java.lang.String aFilePath,
                              org.refcodes.runtime.ConfigLocator aConfigLocator)
                       throws java.io.IOException,
                              java.text.ParseException
        Loads the YAML Properties from the given file's path. A provided ConfigLocator describes the locations to additional crawl for the desired file.
        Parameters:
        aFilePath - The path to the file from which to load the properties.
        aConfigLocator - The ConfigLocator describes the locations to additional crawl for the desired file.
        Throws:
        java.io.IOException - thrown in case accessing or processing the properties file failed.
        java.text.ParseException - Signals that an error has been reached unexpectedly while parsing the data to be loaded.
      • YamlProperties

        public YamlProperties​(java.lang.String aFilePath,
                              org.refcodes.runtime.ConfigLocator aConfigLocator,
                              char... aDelimiters)
                       throws java.io.IOException,
                              java.text.ParseException
        Loads the YAML Properties from the given file's path. A provided ConfigLocator describes the locations to additional crawl for the desired file.
        Parameters:
        aFilePath - The path to the file from which to load the properties.
        aConfigLocator - The ConfigLocator describes the locations to additional crawl for the desired file.
        aDelimiters - The path delimiters to be used when parsing the source's properties.
        Throws:
        java.io.IOException - thrown in case accessing or processing the properties file failed.
        java.text.ParseException - Signals that an error has been reached unexpectedly while parsing the data to be loaded.
      • YamlProperties

        public YamlProperties​(java.lang.Class<?> aResourceClass,
                              java.lang.String aFilePath,
                              org.refcodes.runtime.ConfigLocator aConfigLocator)
                       throws java.io.IOException,
                              java.text.ParseException
        Loads the YAML Properties from the given file's path. A provided ConfigLocator describes the locations to additional crawl for the desired file. Finally (if nothing else succeeds) the properties are loaded by the provided class's class loader which takes care of loading the properties (in case the file path is a relative path, also the absolute path with a prefixed path delimiter "/" is probed).
        Parameters:
        aResourceClass - The class which's class loader is to take care of loading the properties (from inside a JAR).
        aFilePath - The file path of the class's resources from which to load the properties.
        aConfigLocator - The ConfigLocator describes the locations to additional crawl for the desired file.
        Throws:
        java.io.IOException - thrown in case accessing or processing the properties file failed.
        java.text.ParseException - Signals that an error has been reached unexpectedly while parsing the data to be loaded.
      • YamlProperties

        public YamlProperties​(java.lang.Class<?> aResourceClass,
                              java.lang.String aFilePath,
                              org.refcodes.runtime.ConfigLocator aConfigLocator,
                              char... aDelimiters)
                       throws java.io.IOException,
                              java.text.ParseException
        Loads the YAML Properties from the given file's path. A provided ConfigLocator describes the locations to additional crawl for the desired file. Finally (if nothing else succeeds) the properties are loaded by the provided class's class loader which takes care of loading the properties (in case the file path is a relative path, also the absolute path with a prefixed path delimiter "/" is probed).
        Parameters:
        aResourceClass - The class which's class loader is to take care of loading the properties (from inside a JAR).
        aFilePath - The file path of the class's resources from which to load the properties.
        aConfigLocator - The ConfigLocator describes the locations to additional crawl for the desired file.
        aDelimiters - The path delimiters to be used when parsing the source's properties.
        Throws:
        java.io.IOException - thrown in case accessing or processing the properties file failed.
        java.text.ParseException - Signals that an error has been reached unexpectedly while parsing the data to be loaded.
      • YamlProperties

        public YamlProperties​(java.net.URL aUrl)
                       throws java.io.IOException,
                              java.text.ParseException
        Loads the YAML Properties from the given URL.
        Parameters:
        aUrl - The URL from which to read the properties.
        Throws:
        java.io.IOException - thrown in case accessing or processing the properties file failed.
        java.text.ParseException - Signals that an error has been reached unexpectedly while parsing the data to be loaded.
      • YamlProperties

        public YamlProperties​(java.net.URL aUrl,
                              char... aDelimiters)
                       throws java.io.IOException,
                              java.text.ParseException
        Loads the YAML Properties from the given URL.
        Parameters:
        aUrl - The URL from which to read the properties.
        aDelimiters - The path delimiters to be used when parsing the source's properties.
        Throws:
        java.io.IOException - thrown in case accessing or processing the properties file failed.
        java.text.ParseException - Signals that an error has been reached unexpectedly while parsing the data to be loaded.
      • YamlProperties

        public YamlProperties​(java.io.InputStream aInputStream)
                       throws java.io.IOException,
                              java.text.ParseException
        Reads the YAML Properties from the given InputStream.
        Parameters:
        aInputStream - The InputStream from which to read the properties.
        Throws:
        java.io.IOException - thrown in case accessing or processing the properties file failed.
        java.text.ParseException - Signals that an error has been reached unexpectedly while parsing the data to be loaded.
      • YamlProperties

        public YamlProperties​(java.io.InputStream aInputStream,
                              char... aDelimiters)
                       throws java.io.IOException,
                              java.text.ParseException
        Reads the YAML Properties from the given InputStream.
        Parameters:
        aInputStream - The InputStream from which to read the properties.
        aDelimiters - The path delimiters to be used when parsing the source's properties.
        Throws:
        java.io.IOException - thrown in case accessing or processing the properties file failed.
        java.text.ParseException - Signals that an error has been reached unexpectedly while parsing the data to be loaded.
    • Method Detail

      • containsKey

        public boolean containsKey​(java.lang.Object aKey)
        Specified by:
        containsKey in interface org.refcodes.structure.Keys<java.lang.String,java.lang.String>
      • get

        public java.lang.String get​(java.lang.Object aKey)
        Specified by:
        get in interface org.refcodes.structure.Keys<java.lang.String,java.lang.String>
      • keySet

        public java.util.Set<java.lang.String> keySet()
        Specified by:
        keySet in interface org.refcodes.structure.Keys<java.lang.String,java.lang.String>
      • values

        public java.util.Collection<java.lang.String> values()
        Specified by:
        values in interface org.refcodes.structure.Keys<java.lang.String,java.lang.String>
      • size

        public int size()
        Specified by:
        size in interface org.refcodes.structure.Containable
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface org.refcodes.structure.Containable
      • retrieveFrom

        public Properties retrieveFrom​(java.lang.String aFromPath)
        Specified by:
        retrieveFrom in interface org.refcodes.structure.CanonicalMap
        Specified by:
        retrieveFrom in interface org.refcodes.structure.PathMap<java.lang.String>
        Specified by:
        retrieveFrom in interface Properties
      • retrieveTo

        public Properties retrieveTo​(java.lang.String aToPath)
        Specified by:
        retrieveTo in interface org.refcodes.structure.CanonicalMap
        Specified by:
        retrieveTo in interface org.refcodes.structure.PathMap<java.lang.String>
        Specified by:
        retrieveTo in interface Properties
      • childrenOf

        public Properties childrenOf​(java.lang.String aParentPath)
        Specified by:
        childrenOf in interface org.refcodes.structure.CanonicalMap
        Specified by:
        childrenOf in interface org.refcodes.structure.PathMap<java.lang.String>
        Specified by:
        childrenOf in interface Properties
      • getDelimiter

        public char getDelimiter()
        Returns the default path delimiter as of Delimiter.PATH.
        Specified by:
        getDelimiter in interface org.refcodes.mixin.DelimiterAccessor
        Specified by:
        getDelimiter in interface Properties
      • getType

        public java.lang.Class<java.lang.String> getType()
        Specified by:
        getType in interface Properties
        Specified by:
        getType in interface org.refcodes.mixin.TypeAccessor<java.lang.String>
      • toDataStructure

        public java.lang.Object toDataStructure​(java.lang.String aFromPath)
        Specified by:
        toDataStructure in interface org.refcodes.structure.PathMap<java.lang.String>
      • reload

        public Properties reload​(ReloadMode aReloadMode)
                          throws java.io.IOException,
                                 java.lang.IllegalStateException,
                                 java.text.ParseException
        Reloads the ResourceProperties from the resource to which the ResourceProperties are attached to (such as a File as of ResourceProperties.MutableResoureProperties.loadFrom(File) or ResourceProperties.MutableResoureProperties.saveTo(File)). In case the resource (such as an InputStream) does not support reloading, then an IllegalStateException is thrown. Properties existing in the attached resource as well in the Properties itself are replaced. When "orphan removal" is set to false, then properties existing in the attached resource but not(!) in the Properties itself are not(!) removed. When "orphan removal" is set to true, then properties existing in the attached resource but not(!) in the Properties itself are(!) removed.
        Specified by:
        reload in interface ResourceProperties
        Parameters:
        aReloadMode - when set to ReloadMode.ORPHAN_REMOVAL, then properties existing in the attached resource but not(!) in the Properties itself are(!) removed. Else properties not existing in the attached resource are kept.
        Returns:
        The Properties as loaded from the resource and applied to this instance.
        Throws:
        java.io.IOException - thrown in case accessing the resource encountered an I/O problem.
        java.lang.IllegalStateException - in case the attached resource does not support reloading.
        java.text.ParseException - Signals that an error has been reached unexpectedly while parsing the data to be loaded.