Class ApplicationPropertiesSugar

java.lang.Object
org.refcodes.properties.PropertiesSugar
org.refcodes.properties.ext.application.ApplicationPropertiesSugar

public class ApplicationPropertiesSugar extends org.refcodes.properties.PropertiesSugar
Declarative syntactic sugar which may be statically imported in order to allow declarative definitions for the construction of ApplicationProperties (and the like).
  • Method Details

    • fromApplicationProperties

      public static ApplicationProperties fromApplicationProperties()
      Factory method to conveniently create a preconfigured ApplicationProperties instance. Constructs a ApplicationProperties instance with no Condition for parsing command line arguments. As no syntax notation is required by the constructor (no root Condition), no syntax validation is done. Therefore the properties are heuristically determined from the provided command line arguments when invoking withArgs(String[]).
      Returns:
      The accordingly constructed ApplicationProperties instance.
    • withArgs

      public static ApplicationProperties withArgs(String[] aArgs)
      Factory method to conveniently create a preconfigured ApplicationProperties instance. Constructs a ApplicationProperties instance with no Condition for parsing command line arguments: As no syntax notation is required by the constructor (no root Condition), no syntax validation is done. Therefore the properties are heuristically determined from the provided command line arguments.
      Parameters:
      aArgs - The command line arguments to be evaluated.
      Returns:
      The accordingly constructed ApplicationProperties instance.
    • withRootArgsSyntax

      public static ApplicationProperties withRootArgsSyntax(org.refcodes.cli.Condition aRootArgsSyntax)
      Factory method to conveniently create a preconfigured ApplicationProperties instance. Constructs a ApplicationProperties instance with the given Condition representing the syntax to be used to parse command line arguments. Provide command line arguments via ApplicationProperties.evalArgs(String[]) (and the like methods).
      Parameters:
      aRootArgsSyntax - The root condition being the node from which parsing the command line arguments starts. Parse the command line arguments via ApplicationProperties.evalArgs(String[]).
      Returns:
      The accordingly constructed ApplicationProperties instance.
    • withRootOption

      public static ApplicationProperties withRootOption(org.refcodes.cli.Option<?> aRootOption)
      Factory method to conveniently create a preconfigured ApplicationProperties instance. Constructs a ApplicationProperties instance with the given Option representing the syntax to be used to parse command line arguments. Provide command line arguments via ApplicationProperties.evalArgs(String[]) (and the like methods).
      Parameters:
      aRootOption - The root option being the node from which parsing the command line arguments starts. Parse the command line arguments via ApplicationProperties.evalArgs(String[]).
      Returns:
      The accordingly constructed ApplicationProperties instance.
    • withObfuscationMode

      public static ApplicationProperties withObfuscationMode(org.refcodes.runtime.SystemContext aMode)
      Factory method to conveniently create a preconfigured ApplicationProperties instance. Constructs the ApplicationProperties with the given obfuscation mode
      Parameters:
      aMode - The SystemContext specifies which level of obfuscation is to be used when encountering upon obfuscated properties: E.g. obfuscation may be bound to the host, the "secret" used for obfuscation being the same for all applications on the same host or obfuscation may be bound to the application, being different for different applications on the same host.
      Returns:
      The accordingly constructed ApplicationProperties instance.
    • withSecret

      public static ApplicationProperties withSecret(String aSecret)
      Factory method to conveniently create a preconfigured ApplicationProperties instance. Constructs a ApplicationProperties instance with a custom secret for obfuscation.
      Parameters:
      aSecret - The secret to be used when encountering upon obfuscated properties.
      Returns:
      The accordingly constructed ApplicationProperties instance.
    • withFile

      public static ApplicationProperties withFile(File aFile) throws IOException, ParseException
      Factory method to conveniently create a preconfigured ApplicationProperties instance. Loads a properties file from the file directly or (if not found) from first folder containing such a file as of the specification for the method ConfigLocator.getFolders().
      Parameters:
      aFile - The file of the properties to load.
      Returns:
      The ApplicationProperties instance as of the builder pattern for chained method calls.
      Throws:
      IOException - thrown in case accessing or processing the properties file failed.
      ParseException - Signals that an error has been reached unexpectedly while parsing the data to be loaded.
    • withInputStream

      public static ApplicationProperties withInputStream(InputStream aInputStream) throws IOException, ParseException
      Factory method to conveniently create a preconfigured ApplicationProperties instance. Reads the properties from the given InputStream.
      Parameters:
      aInputStream - The InputStream from which to read the properties.
      Returns:
      The ApplicationProperties instance as of the builder pattern for chained method calls.
      Throws:
      IOException - thrown in case accessing or processing the properties file failed.
      ParseException - Signals that an error has been reached unexpectedly while parsing the data to be loaded.
    • withResourceClass

      public static ApplicationProperties withResourceClass(String aFilePath) throws IOException, ParseException
      Factory method to conveniently create a preconfigured ApplicationProperties instance. Loads a properties file from the file directly or (if not found) from first folder containing such a file as of the specification for the method ConfigLocator.getFolders().
      Parameters:
      aFilePath - The file of the properties file to load.
      Returns:
      The ApplicationProperties instance as of the builder pattern for chained method calls.
      Throws:
      IOException - thrown in case accessing or processing the properties file failed.
      ParseException - Signals that an error has been reached unexpectedly while parsing the data to be loaded.
    • withUrl

      public static ApplicationProperties withUrl(URL aUrl) throws IOException, ParseException
      Factory method to conveniently create a preconfigured ApplicationProperties instance. Loads the properties from the given URL.
      Parameters:
      aUrl - The URL from which to read the properties.
      Returns:
      The ApplicationProperties instance as of the builder pattern for chained method calls.
      Throws:
      IOException - thrown in case accessing or processing the properties file failed.
      ParseException - Signals that an error has been reached unexpectedly while parsing the data to be loaded.
    • withParseArgs

      public static ApplicationProperties withParseArgs(String[] aArgs) throws org.refcodes.cli.ArgsSyntaxException
      Factory method to conveniently create a preconfigured ApplicationProperties instance. Evaluates the provided command line arguments and adds them with their according properties representation
      Parameters:
      aArgs - The command line arguments to be evaluated.
      Returns:
      The ApplicationProperties instance of the builder pattern to chain further method calls.
      Throws:
      org.refcodes.cli.ArgsSyntaxException - thrown in case of a command line arguments mismatch regarding provided and expected args.
    • withProperties

      public static ApplicationProperties withProperties(org.refcodes.properties.Properties aProperties)
      Factory method to conveniently create a preconfigured ApplicationProperties instance. A hook for you to provide Properties programmatically. The later you add Properties, the lower their precedence.
      Parameters:
      aProperties - The Properties to be added.
      Returns:
      The ApplicationProperties instance of the builder pattern to chain further method calls.