Class Config

java.lang.Object
net.messagevortex.Config
Direct Known Subclasses:
MessageVortexConfig

public class Config extends Object
  • Constructor Details

    • Config

      public Config(String ressourceFile) throws IOException
      *

      Creates an config object following the spec given in the resource file.

      Parameters:
      ressourceFile - filename of the resource file
      Throws:
      IOException - if an error happens while reading the file
  • Method Details

    • getResouceFilename

      public String getResouceFilename()
    • getDefault

      public static Config getDefault() throws IOException
      Throws:
      IOException
    • copy

      public Config copy()
      *

      Returns a deep copy of this config store.

      Returns:
      the copy
    • clear

      public void clear()
      *

      Reverts config store to all default values.

    • createBooleanConfigValue

      public void createBooleanConfigValue(String id, String description, boolean dval)
      *

      Creates a new boolean config value in the store.

      Parameters:
      id - the name (id) of the new value
      description - the description for the value
      dval - the default value
    • setBooleanValue

      public boolean setBooleanValue(String section, String id, boolean value, int lineNumber)
      *

      Sets a boolean value in the application config.

      Parameters:
      section - the section of the config to be affected (null for default section)
      id - key which should be set
      value - Value to be set in key
      lineNumber - the line number of the respective file (for error messages)
      Returns:
      old value before setting to new value
      Throws:
      NullPointerException - if key does not exist in configData
      ClassCastException - if key is not of type boolean
    • getBooleanValue

      public boolean getBooleanValue(String section, String id)
      *

      Gets a boolean value from the application config.

      Parameters:
      section - the section of the config to be affected (null for default section)
      id - key which should be set
      Returns:
      current value of the specified key
      Throws:
      NullPointerException - if key does not exist in configData
      ClassCastException - if key is not of type boolean
    • createNumericConfigValue

      public void createNumericConfigValue(String id, String description, int dval)
      *

      Creates a new numeric config value in the store.

      Parameters:
      id - the name (id) of the new value
      description - the description for the value
      dval - the default value
    • createSectionConfigValue

      public void createSectionConfigValue(String id, String description, String dval)
      *

      Creates a new section config value in the store.

      Parameters:
      id - the name (id) of the new value
      description - the description for the value
      dval - the default value
    • setNumericValue

      public int setNumericValue(String section, String id, int value, int lineNumber)
      *

      Sets a numeric value in the application config.

      Parameters:
      section - section from which the value should be taken. null defaults to default section
      id - key which should be set
      value - Value to be set in key
      lineNumber - the line number of the respective file (for error messages)
      Returns:
      old value before setting to new value
      Throws:
      NullPointerException - if key does not exist in configData
      ClassCastException - if key is not of type boolean
    • getNumericValue

      public int getNumericValue(String section, String id)
      *

      Gets a numeric value from the application config.

      Parameters:
      section - section from which the value should be taken. null defaults to default section
      id - key which should be set
      Returns:
      current value of the specified key
      Throws:
      NullPointerException - if key does not exist in configData
      ClassCastException - if key is not of type boolean
    • createSectionListConfigValue

      public boolean createSectionListConfigValue(String id, String description, String dval)
      *

      Creates a section_list config item.

      Creates a config item with a case insensitive identifier. The content of the item may not be null.

      Parameters:
      id - Name of config item (case insensitive)
      description - Description of value to be written
      dval - Default content if not set
      Returns:
      True if item did not exist and was successfully created
    • setSectionListValue

      public String setSectionListValue(String section, String id, String value, int lineNumber)
      *

      Set a section_list value to a config parameter.

      Parameters:
      section - section from which the value should be taken. null defaults to default section
      id - key which should be set
      value - Value to be set in key
      lineNumber - the line number of the respective file (for error messages)
      Returns:
      the previously set value
      Throws:
      NullPointerException - when id is unknown or value is null
      ClassCastException - when id is not a String setting
    • getSectionListValue

      public String[] getSectionListValue(String section, String id)
      *

      Sets the value of a section_list type.

      Parameters:
      section - section from which the value should be taken. 'Null' defaults to default section
      id - the id of the value to be retrieved
      Returns:
      a list of sections
      Throws:
      NullPointerException - when id is unknown
      ClassCastException - when id is not a String setting
    • setSectionValue

      public String setSectionValue(String section, String id, String value, int lineNumber)
      *

      Set a section value to a config parameter.

      Parameters:
      section - section from which the value should be taken. Use "null" to get the default section
      id - key which should be set
      value - Value to be set in key
      lineNumber - the line number of the respective file (for error messages)
      Returns:
      the previously set value
      Throws:
      NullPointerException - when id is unknown or value is null
      ClassCastException - when id is not a String setting
    • getSectionValue

      public String getSectionValue(String section, String id)
      *

      Gets the value of a section type.

      Parameters:
      section - section from which the value should be taken. 'Null' defaults to default section
      id - the id of the value to be retrieved
      Returns:
      a section name
      Throws:
      NullPointerException - when id is unknown
      ClassCastException - when id is not a String setting
    • createStringConfigValue

      public boolean createStringConfigValue(String id, String description, String dval)
      *

      Creates a String config item.

      Creates a config item with a case insensitive identifier. The content of the item may not be null.

      Parameters:
      id - Name of config item (case insensitive)
      description - Description of value to be written
      dval - Default content if not set
      Returns:
      True if item did not exist and was successfully created
    • removeConfigValue

      public boolean removeConfigValue(String id)
      *

      Removes a config value declaration from the config container.

      Parameters:
      id - the id of the value to be removed
      Returns:
      true if the id did exist
    • setStringValue

      public String setStringValue(String section, String id, String value, int lineNumber)
      *

      Set a String value to a config parameter.

      Parameters:
      section - section from which the value should be taken. 'null' defaults to default section
      id - Name of config item (case insensitive)
      value - Value to be set in key
      lineNumber - the line number of the respective file (for error messages)
      Returns:
      the previously set value
      Throws:
      NullPointerException - when id is unknown or value is null
      ClassCastException - when id is not a String setting
    • getStringValue

      public String getStringValue(String section, String id)
      *

      Sets the value of a string type.

      Parameters:
      section - section from which the value should be taken. 'null' defaults to default section
      id - the id of the value to be retrieved
      Returns:
      the previously set value
      Throws:
      NullPointerException - when id is unknown
      ClassCastException - when id is not a String setting
    • isDefaultValue

      public boolean isDefaultValue(String section, String id)

      Checks if a specific key is returning default values only.

      Parameters:
      section - the section to be querried
      id - the id of the key to be queried
      Returns:
      true if there is a specific value set.
    • getMap

      public Map<String,net.messagevortex.Config.ConfigElement> getMap()
    • load

      public void load(String filename) throws IOException
      *

      Loads a config file and validates input.

      Loads and parses a file according to the resources configuration

      Parameters:
      filename - name of the property file to be read
      Throws:
      IOException - if the file is not parsed properly
    • store

      public String store() throws IOException
      *

      Writes config to a string.

      Writes a commented file according to the configuration

      Returns:
      The configuration as string
      Throws:
      IOException - if error writing file
    • store

      public void store(String filename) throws IOException
      *

      Writes a config file.

      Writes a commented file according to the configuration

      Parameters:
      filename - name of the property file to be written
      Throws:
      IOException - if error writing to file
    • getDescription

      public String getDescription(String id)
      Get the descriptive text of the named configuration item.
      Parameters:
      id - identification of the configuration item
      Returns:
      the configuration item description
    • getDefaultValue

      public String getDefaultValue(String id)
      Gets the default value of the named configuration item.
      Parameters:
      id - identification of the configuration item
      Returns:
      the configuration items' default value