Module de.carne
Package de.carne.util

Class PropertyResolver


  • public final class PropertyResolver
    extends java.lang.Object
    Utility class providing dynamic property resolution support.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String expand​(java.lang.String s)
      Expands the given string by resolving all embedded property keys.
      @Nullable java.lang.String resolve​(java.lang.String key)
      Resolves the given key by searching the sources selected during instance creation.
      java.lang.String resolve​(java.lang.String key, java.lang.String defaultValue)
      Resolves the given key by searching the sources selected during instance creation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PropertyResolver

        public PropertyResolver​(java.util.Map<?,​?> properties)
        Constructs a new PropertyResolver instance.
        Parameters:
        properties - the custom properties to consider while resolving.
        See Also:
        resolve(String)
      • PropertyResolver

        public PropertyResolver​(boolean useSystemProperties,
                                boolean useEnvironemnt)
        Constructs a new PropertyResolver instance.
        Parameters:
        useSystemProperties - whether to consider system properties while resolving.
        useEnvironemnt - whether to consider environment variables while resolving.
        See Also:
        resolve(String)
      • PropertyResolver

        public PropertyResolver​(java.util.Map<?,​?> properties,
                                boolean useSystemProperties,
                                boolean useEnvironemnt)
        Constructs a new PropertyResolver instance.
        Parameters:
        properties - the custom properties to consider while resolving.
        useSystemProperties - whether to consider system properties while resolving.
        useEnvironemnt - whether to consider environment variables while resolving.
        See Also:
        resolve(String)
    • Method Detail

      • resolve

        public @Nullable java.lang.String resolve​(java.lang.String key)
        Resolves the given key by searching the sources selected during instance creation.

        The sources are searched in the following order:

        1. Custom properties
        2. System properties
        3. Environment variables
        For Custom and system properties the key is used unchanged. For environment variables the key is converted to upper case and any period character ('.') is replaced by an underscore ('_').
        Parameters:
        key - the key to resolve.
        Returns:
        the resolved value or null if the key is undefined.
      • resolve

        public java.lang.String resolve​(java.lang.String key,
                                        java.lang.String defaultValue)
        Resolves the given key by searching the sources selected during instance creation.
        Parameters:
        key - the key to resolve.
        defaultValue - the value to return in case the key is undefined.
        Returns:
        the resolved value or defaultValue if the key is undefined.
        See Also:
        resolve(String)
      • expand

        public java.lang.String expand​(java.lang.String s)
                                throws java.text.ParseException
        Expands the given string by resolving all embedded property keys.
        Parameters:
        s - the string to expand.
        Returns:
        the expanded string.
        Throws:
        java.text.ParseException - if a parse or resolve error occurs during expansion.