Class PropertyLoader

All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>
Direct Known Subclasses:
AppConstants, CredentialConstants

public class PropertyLoader extends Properties
See Also:
  • Constructor Details

    • PropertyLoader

      public PropertyLoader(String propertiesFile)
    • PropertyLoader

      public PropertyLoader(ClassLoader classLoader, String propertiesFile)
  • Method Details

    • get

      public String get(Object key)
      Specified by:
      get in interface Map<Object,Object>
      Overrides:
      get in class Properties
    • getProperty

      public String getProperty(String key)
      Overrides:
      getProperty in class Properties
    • getUnresolvedProperty

      public String getUnresolvedProperty(String key)
    • getResolvedProperty

      protected final String getResolvedProperty(String key)
      the method is like the Properties.getProperty, but provides functionality to resolve ${variable} Syntaxes. It uses the property values and system values to resolve the variables, and does so recursively.
      See Also:
    • getOrDefault

      @Nonnull public <T extends Enum<T>> T getOrDefault(@Nonnull String key, @Nonnull T dfault)
    • getListProperty

      @Nonnull public List<String> getListProperty(@Nonnull String key)
      Retrieves a list property value associated with the specified key. The method first resolves the property value using the getResolvedProperty(String) method. If the resolved property value is null, an empty list is returned.
      Parameters:
      key - the key of the property value to retrieve
      Returns:
      a list of string values associated with the specified key, or an empty list if the resolved property is null
    • getListProperty

      @Nonnull public List<String> getListProperty(@Nonnull String key, @Nullable String defaults)
      Retrieves a list property value associated with the specified key. The method first resolves the property value using the getResolvedProperty(String) method. If the resolved property value is null, it returns the list of string values provided as "defaults".
      Parameters:
      key - the key of the property value to retrieve
      defaults - the default list of string values to return if the resolved property is null
      Returns:
      a list of string values associated with the specified key, or the default list if the resolved property is null. If the defaults is also null, then returns an empty list.
    • put

      @Deprecated public Object put(Object key, Object value)
      Deprecated.
      Add property only in the local PropertyLoader! Do not use this method and use Properties.setProperty(String, String) if you want to set the property globally!

      This method is used by Properties.load(InputStream) to add all properties found (in a file/stream) to the underlying Hashtable.

      Specified by:
      put in interface Map<Object,Object>
      Overrides:
      put in class Properties
    • load

      protected void load(ClassLoader classLoader, String filename)
      Load the contents of a properties file.

      Optionally, this may be a comma-separated list of files to load, e.g. log4j2.properties,DeploymentSpecifics.properties which will cause both files to be loaded in the listed order.

    • getString

      public String getString(String key, String dfault)
      Gets a String value Uses the getResolvedProperty(String) method.
      Parameters:
      key - the Key
      dfault - the default value
      Returns:
      String
    • getBoolean

      public boolean getBoolean(String key, boolean dfault)
      Gets a boolean value Returns "true" if the retrieved value is "true", otherwise "false" Uses the getResolvedProperty(String) method.
      Parameters:
      key - the Key
      dfault - the default value
      Returns:
      double
    • getInt

      public int getInt(String key, int dfault)
      Gets an int value Uses the getResolvedProperty(String) method.
      Parameters:
      key - the Key
      dfault - the default value
      Returns:
      int
    • getLong

      public long getLong(String key, long dfault)
      Gets a long value Uses the getResolvedProperty(String) method.
      Parameters:
      key - the Key
      dfault - the default value
      Returns:
      long
    • getDouble

      public double getDouble(String key, double dfault)
      Gets a double value Uses the getResolvedProperty(String) method.
      Parameters:
      key - the Key
      dfault - the default value
      Returns:
      double