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

[configuration] Provide support for declaring and creating objects

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • None
    • None
    • None
    • Operating System: All
      Platform: All

    • 34353

    Description

      A useful enhancement for the configuration API could be a way to create and
      initialize objects whose class and initialization parameters are defined in a
      configuration file.

      The idea is that both the class name and initialization parameters for an object
      are defined in a standard format. A createObject(String key) method (which might
      fit best in DataConfiguration?) would extract the class name from the specified
      property, create the object using reflection and then populate properties via
      [beanutils].

      For the concrete format for declaring objects in a configuration file there are
      many possibilities. We have to define a format which is easy to use, but
      although suports complex initialization parameters. A possible object
      declaration could look as follows (here in XML flavour, but other configuration
      sources are of course possible, too):

      <myobject>
      <class>package.ClassName</class>
      <args>
      <arg1>value1</arg1>
      <arg2>value2></arg2>
      ...
      </args>
      </myobject>

      We could even go a step further and define an interface
      public interface Configurable
      {
      void initialize(Configuration config);
      }

      If the newly created object implements this interface, its initialize() method
      will be called and a sub configuration will be passed that contains the content
      of the <args> section. This would allow for arbitrary complex and also
      hierarchical initialization parameters. It's a bit similar to what IoC
      frameworks do.

      Side note: If we add more features to the configuration definition files
      processed by ConfigurationFactory (e.g locators or declarations for reloading
      strategies) and use a XMLConfiguration to load these files, the proposed object
      creation facility may come in handy.

      Attachments

        Activity

          People

            Unassigned Unassigned
            oheger Oliver Heger
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: