Uploaded image for project: 'Commons Configuration'
  1. Commons Configuration
  2. CONFIGURATION-192

[configuration] Enhancement of interpolation features

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.4
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: other
      Platform: Other

    • Bugzilla Id:
      35116

      Description

      At the moment interpolation is only supported by the getString() and
      getStringArray() methods. This proposal suggests adding interpolation support
      for other getter methods, too, and at the same time making it more customizable
      (including the ability to disable it at all).

      A first step in achieving this could be to refactor the interpolation
      functionality out of AbstractConfiguration and into a new Interpolator class.
      This class would provide a main interpolation method and would also maintain an
      arbitrary number of objects that know how to resolve variables of certain types.
      Each Configuration object would be assigned an Interpolator instance, to which
      it would delegate interpolation tasks.

      Customization of the interpolation features could be done by assigning an
      Interpolator object to a configuration that has been initialized with a custom
      set of variable resolver objects. If no Interpolator is assigned, no
      interpolation will be performed.

      Variable resolver objects are very simple: They define a method which takes a
      variable's name and return its value. The variable resolver to use for a
      concrete variable is determined by a prefix that can be set for each variable.
      So a variable like ${sys:user.home} e.g. might refer to the system properties
      resolver. Variables without a prefix are handled by a default resolver, which is
      implemented by the Configuration object itself, so that the Configuration's
      properties are used as variable values (which is backwards compatible to the
      current functionality).

      It should be possible to define a default Interpolator (or at least a default
      set of variable resolvers) that is to be used by each Configuration object as
      long as no special Interpolator is set. This could be done through a static
      field in AbstractConfiguration.

      Useful specific variable resolver classes could be:

      • The already mentioned system properties resolver, which would make system
        properties accessable in each configuration.
      • A resolver that would read constant values from specified classes.
      • A resolver that would evaluate expressions in an expression language like EL.

        Attachments

        1. ASF.LICENSE.NOT.GRANTED--Interpolator.java
          13 kB
          Oliver Heger
        2. ASF.LICENSE.NOT.GRANTED--VariableResolver.java
          2 kB
          Oliver Heger
        3. ASF.LICENSE.NOT.GRANTED--TestInterpolator.java
          6 kB
          Oliver Heger
        4. ASF.LICENSE.NOT.GRANTED--Interpolator.java
          14 kB
          Oliver Heger
        5. ASF.LICENSE.NOT.GRANTED--TestInterpolator.java
          7 kB
          Oliver Heger
        6. ASF.LICENSE.NOT.GRANTED--interpolation.diff
          14 kB
          Oliver Heger

          Issue Links

            Activity

              People

              • Assignee:
                oheger Oliver Heger
                Reporter:
                oheger Oliver Heger
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: