Class YamlPropertiesBuilder

  • All Implemented Interfaces:
    java.io.Flushable, java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.String,java.lang.String>, org.refcodes.component.Flushable, org.refcodes.component.Flushable.FlushBuilder<ResourceProperties.ResourcePropertiesBuilder>, Properties, Properties.MutableProperties, Properties.PropertiesBuilder, ResourceProperties, ResourceProperties.MutableResoureProperties, ResourceProperties.ResourcePropertiesBuilder, org.refcodes.mixin.DelimiterAccessor, org.refcodes.mixin.Dumpable, org.refcodes.mixin.TypeAccessor<java.lang.String>, org.refcodes.structure.CanonicalMap, org.refcodes.structure.CanonicalMap.CanonicalMapBuilder, org.refcodes.structure.CanonicalMap.MutableCanonicalMap, org.refcodes.structure.Clearable, org.refcodes.structure.Containable, org.refcodes.structure.Dictionary<java.lang.String,java.lang.String>, org.refcodes.structure.Dictionary.MutableDictionary<java.lang.String,java.lang.String>, org.refcodes.structure.Dictionary.MutableDictionary.DictionaryBuilder<java.lang.String,java.lang.String,org.refcodes.structure.PathMap.PathMapBuilder<java.lang.String>>, org.refcodes.structure.Keys<java.lang.String,java.lang.String>, org.refcodes.structure.Keys.MutableKeys<java.lang.String,java.lang.String>, org.refcodes.structure.Keys.MutableValues<java.lang.String,java.lang.String>, org.refcodes.structure.PathMap<java.lang.String>, org.refcodes.structure.PathMap.MutablePathMap<java.lang.String>, org.refcodes.structure.PathMap.PathMapBuilder<java.lang.String>, org.refcodes.structure.PropertiesAccessorMixin, org.refcodes.structure.PropertiesAccessorMixin.PropertiesBuilderMixin<org.refcodes.structure.CanonicalMap.CanonicalMapBuilder>, org.refcodes.structure.PropertiesAccessorMixin.PropertiesMixin, org.refcodes.structure.PropertiesAccessorMixin.PropertiesMutatorMixin

    public class YamlPropertiesBuilder
    extends AbstractResourcePropertiesBuilder
    implements ResourceProperties.ResourcePropertiesBuilder
    Implementation of the ResourceProperties.ResourcePropertiesBuilder interface with support of so called "YAML properties" (or just "properties"). For YAML, see "https://en.wikipedia.org/wiki/YAML".
    See Also:
    Serialized Form
    • Constructor Detail

      • YamlPropertiesBuilder

        public YamlPropertiesBuilder()
        Create an empty YamlPropertiesBuilder instance using the default path delimiter "/" (Delimiter.PATH) for the path declarations.
      • YamlPropertiesBuilder

        public YamlPropertiesBuilder​(java.lang.Object aObj)
        Create a YamlPropertiesBuilder 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.
      • YamlPropertiesBuilder

        public YamlPropertiesBuilder​(Properties aProperties)
        Create a YamlPropertiesBuilder 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.
      • YamlPropertiesBuilder

        public YamlPropertiesBuilder​(java.util.Map<?,?> aProperties)
        Create a YamlPropertiesBuilder 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.
      • YamlPropertiesBuilder

        public YamlPropertiesBuilder​(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.
      • YamlPropertiesBuilder

        public YamlPropertiesBuilder​(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.
      • YamlPropertiesBuilder

        public YamlPropertiesBuilder​(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.
      • YamlPropertiesBuilder

        public YamlPropertiesBuilder​(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.
      • YamlPropertiesBuilder

        public YamlPropertiesBuilder​(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.
      • YamlPropertiesBuilder

        public YamlPropertiesBuilder​(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.
      • YamlPropertiesBuilder

        public YamlPropertiesBuilder​(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.
      • YamlPropertiesBuilder

        public YamlPropertiesBuilder​(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.
      • YamlPropertiesBuilder

        public YamlPropertiesBuilder​(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.
      • YamlPropertiesBuilder

        public YamlPropertiesBuilder​(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.
      • YamlPropertiesBuilder

        public YamlPropertiesBuilder​(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.
      • YamlPropertiesBuilder

        public YamlPropertiesBuilder​(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.
      • YamlPropertiesBuilder

        public YamlPropertiesBuilder​(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.
      • YamlPropertiesBuilder

        public YamlPropertiesBuilder​(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.
      • YamlPropertiesBuilder

        public YamlPropertiesBuilder​(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.
      • YamlPropertiesBuilder

        public YamlPropertiesBuilder​(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

      • loadFrom

        public Properties loadFrom​(java.io.InputStream aInputStream,
                                   char... aDelimiters)
                            throws java.io.IOException,
                                   java.text.ParseException
        Loads the properties from the given InputStream. Save them using the method ResourceProperties.MutableResoureProperties.saveTo(OutputStream). This is the hook-method of the default implementation for loading the properties. In case you want to implement ResourceProperties which support other notations than the properties notation (path=value), then you overwrite this method in your implementation accordingly.
        Specified by:
        loadFrom in interface ResourceProperties.MutableResoureProperties
        Parameters:
        aInputStream - The InputStream from which to load the properties.
        aDelimiters - The path delimiters to be used when parsing the source's properties (in case the the serialized format supports / requires the such).
        Returns:
        The Properties as loaded from the resource and applied to this instance.
        Throws:
        java.io.IOException - thrown in case loading the properties failed
        java.text.ParseException - Signals that an error has been reached unexpectedly while parsing the data to be loaded.
      • saveTo

        public void saveTo​(java.io.OutputStream aOutputStream,
                           java.lang.String aComment,
                           char aDelimiter)
                    throws java.io.IOException
        The comment is ignored for the YAML format as YAML does not(!) support any comments! Saves the properties to the given OutputStream using the provided delimiter as the destination's path delimiter. Load them via ResourceProperties.MutableResoureProperties.loadFrom(InputStream, char...) This is the hook-method of the default implementation for writing (saving) the properties. In case you want to implement ResourceProperties which support other notations than the properties notation (path=value), then you overwrite this method in your implementation accordingly.
        Specified by:
        saveTo in interface ResourceProperties.MutableResoureProperties
        Parameters:
        aOutputStream - The OutputStream to which to save the properties to.
        aComment - The description for the properties file.
        aDelimiter - The path delimiter to be used when writing out the properties to the destination (in case the the serialized format supports / requires the such).
        Throws:
        java.io.IOException - thrown in case saving the properties failed