Class AppPropertiesService


  • public final class AppPropertiesService
    extends java.lang.Object
    this class provides management services for properties files
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static java.util.List<java.lang.String> getKeys​(java.lang.String strPrefix)
      Returns a list of keys that match a given prefix.
      <T> java.util.Optional<T> getOptionalValue​(java.lang.String name, java.lang.Class<T> aClass)
      Return the resolved property value with the specified type for the specified property name from the underlying configuration sources.
      static java.util.Properties getProperties()
      Gets properties
      static java.util.Map<java.lang.String,​java.lang.String> getPropertiesAsMap()
      Gets all properties as a Map
      static java.lang.String getProperty​(java.lang.String strProperty)
      Returns the value of a variable defined in the .properties file of the application as a String
      static java.lang.String getProperty​(java.lang.String strProperty, java.lang.String strDefault)
      Returns the value of a variable defined in the .properties file of the application as a String
      static boolean getPropertyBoolean​(java.lang.String strProperty, boolean bDefault)
      Returns the value of a variable defined in the .properties file of the application as a boolean
      static int getPropertyInt​(java.lang.String strProperty, int nDefault)
      Returns the value of a variable defined in the .properties file of the application as an int
      static long getPropertyLong​(java.lang.String strProperty, long lDefault)
      Returns the value of a variable defined in the .properties file of the application as an long
      static void init​(java.lang.String strConfPath)
      Initializes the service
      static boolean isPropertyDeclared​(java.lang.String strProperty)
      Tells whether a property is declared by one of the configuration sources, whatever its value.
      static void reload​(java.lang.String strFilename)
      Deprecated.
      static void reloadAll()
      Deprecated.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • init

        public static void init​(java.lang.String strConfPath)
        Initializes the service
        Parameters:
        strConfPath - The configuration path
      • getProperty

        public static java.lang.String getProperty​(java.lang.String strProperty)
        Returns the value of a variable defined in the .properties file of the application as a String
        Parameters:
        strProperty - The variable name
        Returns:
        The variable value read in the properties file
      • getProperty

        public static java.lang.String getProperty​(java.lang.String strProperty,
                                                   java.lang.String strDefault)
        Returns the value of a variable defined in the .properties file of the application as a String
        Parameters:
        strProperty - The variable name
        strDefault - The default value which is returned if no value is found for the variable in the .properties file.
        Returns:
        The variable value read in the properties file
      • getPropertyInt

        public static int getPropertyInt​(java.lang.String strProperty,
                                         int nDefault)
        Returns the value of a variable defined in the .properties file of the application as an int
        Parameters:
        strProperty - The variable name
        nDefault - The default value which is returned if no value is found for the variable in the le downloadFile .properties. .properties file.
        Returns:
        The variable value read in the properties file
      • getPropertyLong

        public static long getPropertyLong​(java.lang.String strProperty,
                                           long lDefault)
        Returns the value of a variable defined in the .properties file of the application as an long
        Parameters:
        strProperty - The variable name
        lDefault - The default value which is returned if no value is found for the variable in the le downloadFile .properties. .properties file.
        Returns:
        The variable value read in the properties file
      • getPropertyBoolean

        public static boolean getPropertyBoolean​(java.lang.String strProperty,
                                                 boolean bDefault)
        Returns the value of a variable defined in the .properties file of the application as a boolean
        Parameters:
        strProperty - The variable name
        bDefault - The default value which is returned if no value is found for the variable in the le downloadFile .properties. .properties file.
        Returns:
        The variable value read in the properties file
      • getOptionalValue

        public <T> java.util.Optional<T> getOptionalValue​(java.lang.String name,
                                                          java.lang.Class<T> aClass)
        Return the resolved property value with the specified type for the specified property name from the underlying configuration sources.

        The configuration value is not guaranteed to be cached by the implementation, and may be expensive to compute; therefore, if the returned value is intended to be frequently used, callers should consider storing rather than recomputing it.

        If this method is used very often then consider to locally store the configured value.

        Type Parameters:
        T - The property type
        Parameters:
        propertyName - The configuration property name
        propertyType - The type into which the resolved property value should be converted
        Returns:
        The resolved property value as an Optional wrapping the requested type
        Throws:
        java.lang.IllegalArgumentException - if the property cannot be converted to the specified type
      • reloadAll

        @Deprecated
        public static void reloadAll()
        Deprecated.
        Reloads all the properties files
      • reload

        @Deprecated
        public static void reload​(java.lang.String strFilename)
        Deprecated.
        Reloads a given properties file
        Parameters:
        strFilename - The file name
      • getProperties

        public static java.util.Properties getProperties()
        Gets properties
        Returns:
        All properties
        Since:
        version 3.0
      • getPropertiesAsMap

        public static java.util.Map<java.lang.String,​java.lang.String> getPropertiesAsMap()
        Gets all properties as a Map
        Returns:
        a Map of all properties
        Since:
        version 5.0
      • getKeys

        public static java.util.List<java.lang.String> getKeys​(java.lang.String strPrefix)
        Returns a list of keys that match a given prefix.
        Parameters:
        strPrefix - the str prefix
        Returns:
        A list of keys that match the prefix
        Since:
        version 3.0
      • isPropertyDeclared

        public static boolean isPropertyDeclared​(java.lang.String strProperty)
        Tells whether a property is declared by one of the configuration sources, whatever its value. getProperty(String) resolves a property declared with an empty value to null, exactly as it resolves a property that no source declares, so the resolved value alone cannot tell the two apart. The property names known to the configuration do include the keys declared with an empty value, which makes this the only way to distinguish an empty declaration from a missing one.
        Parameters:
        strProperty - the property key
        Returns:
        true if a configuration source declares the key, false otherwise
        Since:
        version 7.1.10