org.apache.commons.configuration.interpol

Class ConfigurationInterpolator

    • Field Summary

      Fields 
      Modifier and Type Field and Description
      private org.apache.commons.lang.text.StrLookup defaultLookup
      Stores the default lookup object.
      private static java.util.Map globalLookups
      A map with the globally registered lookup objects.
      private java.util.Map localLookups
      A map with the locally registered lookup objects.
      static java.lang.String PREFIX_CONSTANTS
      Constant for the prefix of the standard lookup object for resolving constant values.
      private static char PREFIX_SEPARATOR
      Constant for the prefix separator.
      static java.lang.String PREFIX_SYSPROPERTIES
      Constant for the prefix of the standard lookup object for resolving system properties.
    • Constructor Summary

      Constructors 
      Constructor and Description
      ConfigurationInterpolator()
      Creates a new instance of ConfigurationInterpolator.
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      static boolean deregisterGlobalLookup(java.lang.String prefix)
      Deregisters the global lookup object for the specified prefix.
      boolean deregisterLookup(java.lang.String prefix)
      Deregisters the lookup object for the specified prefix at this instance.
      protected org.apache.commons.lang.text.StrLookup fetchLookupForPrefix(java.lang.String prefix)
      Obtains the lookup object for the specified prefix.
      protected org.apache.commons.lang.text.StrLookup fetchNoPrefixLookup()
      Returns the lookup object to be used for variables without a prefix.
      org.apache.commons.lang.text.StrLookup getDefaultLookup()
      Returns the default lookup object.
      java.lang.String lookup(java.lang.String var)
      Resolves the specified variable.
      java.util.Set prefixSet()
      Returns a set with the prefixes, for which lookup objects are registered at this instance.
      static void registerGlobalLookup(java.lang.String prefix, org.apache.commons.lang.text.StrLookup lookup)
      Registers the given lookup object for the specified prefix globally.
      void registerLookup(java.lang.String prefix, org.apache.commons.lang.text.StrLookup lookup)
      Registers the given lookup object for the specified prefix at this instance.
      void setDefaultLookup(org.apache.commons.lang.text.StrLookup defaultLookup)
      Sets the default lookup object.
      • Methods inherited from class org.apache.commons.lang.text.StrLookup

        mapLookup, noneLookup, systemPropertiesLookup
      • Methods inherited from class java.lang.Object

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

      • PREFIX_SYSPROPERTIES

        public static final java.lang.String PREFIX_SYSPROPERTIES
        Constant for the prefix of the standard lookup object for resolving system properties.
        See Also:
        Constant Field Values
      • PREFIX_CONSTANTS

        public static final java.lang.String PREFIX_CONSTANTS
        Constant for the prefix of the standard lookup object for resolving constant values.
        See Also:
        Constant Field Values
      • PREFIX_SEPARATOR

        private static final char PREFIX_SEPARATOR
        Constant for the prefix separator.
        See Also:
        Constant Field Values
      • globalLookups

        private static java.util.Map globalLookups
        A map with the globally registered lookup objects.
      • localLookups

        private java.util.Map localLookups
        A map with the locally registered lookup objects.
      • defaultLookup

        private org.apache.commons.lang.text.StrLookup defaultLookup
        Stores the default lookup object.
    • Constructor Detail

      • ConfigurationInterpolator

        public ConfigurationInterpolator()
        Creates a new instance of ConfigurationInterpolator.
    • Method Detail

      • registerGlobalLookup

        public static void registerGlobalLookup(java.lang.String prefix,
                                org.apache.commons.lang.text.StrLookup lookup)
        Registers the given lookup object for the specified prefix globally. This means that all instances that are created later will use this lookup object for this prefix. If for this prefix a lookup object is already registered, the new lookup object will replace the old one. Note that the lookup objects registered here will be shared between multiple clients. So they should be thread-safe.
        Parameters:
        prefix - the variable prefix (must not be null)
        lookup - the lookup object to be used for this prefix (must not be null)
      • deregisterGlobalLookup

        public static boolean deregisterGlobalLookup(java.lang.String prefix)
        Deregisters the global lookup object for the specified prefix. This means that this lookup object won't be available for later created instances any more. For already existing instances this operation does not have any impact.
        Parameters:
        prefix - the variable prefix
        Returns:
        a flag whether for this prefix a lookup object had been registered
      • registerLookup

        public void registerLookup(java.lang.String prefix,
                          org.apache.commons.lang.text.StrLookup lookup)
        Registers the given lookup object for the specified prefix at this instance. From now on this lookup object will be used for variables that have the specified prefix.
        Parameters:
        prefix - the variable prefix (must not be null)
        lookup - the lookup object to be used for this prefix (must not be null)
      • deregisterLookup

        public boolean deregisterLookup(java.lang.String prefix)
        Deregisters the lookup object for the specified prefix at this instance. It will be removed from this instance.
        Parameters:
        prefix - the variable prefix
        Returns:
        a flag whether for this prefix a lookup object had been registered
      • prefixSet

        public java.util.Set prefixSet()
        Returns a set with the prefixes, for which lookup objects are registered at this instance. This means that variables with these prefixes can be processed.
        Returns:
        a set with the registered variable prefixes
      • getDefaultLookup

        public org.apache.commons.lang.text.StrLookup getDefaultLookup()
        Returns the default lookup object.
        Returns:
        the default lookup object
      • setDefaultLookup

        public void setDefaultLookup(org.apache.commons.lang.text.StrLookup defaultLookup)
        Sets the default lookup object. This lookup object will be used for all variables without a special prefix. If it is set to null, such variables won't be processed.
        Parameters:
        defaultLookup - the new default lookup object
      • lookup

        public java.lang.String lookup(java.lang.String var)
        Resolves the specified variable. This implementation will try to extract a variable prefix from the given variable name (the first colon (':') is used as prefix separator). It then passes the name of the variable with the prefix stripped to the lookup object registered for this prefix. If no prefix can be found, the default lookup object will be used.
        Specified by:
        lookup in class org.apache.commons.lang.text.StrLookup
        Parameters:
        var - the name of the variable whose value is to be looked up
        Returns:
        the value of this variable or null if it cannot be resolved
      • fetchNoPrefixLookup

        protected org.apache.commons.lang.text.StrLookup fetchNoPrefixLookup()
        Returns the lookup object to be used for variables without a prefix. This implementation will check whether a default lookup object was set. If this is the case, it will be returned. Otherwise a null lookup object will be returned.
        Returns:
        the lookup object to be used for variables without a prefix
      • fetchLookupForPrefix

        protected org.apache.commons.lang.text.StrLookup fetchLookupForPrefix(java.lang.String prefix)
        Obtains the lookup object for the specified prefix. This method is called by the lookup() method. This implementation will check whether a lookup object is registered for the given prefix. If not, a null lookup object will be returned.
        Parameters:
        prefix - the prefix
        Returns:
        the lookup object to be used for this prefix