commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From (Oliver Heger)
Subject [configuration] Support for object creation
Date Wed, 01 Oct 2003 10:05:56 GMT
Hello configuration developers,

I am quite new to open source and would like to contribute something to this
project. I was working on a proprietary configuration framework and maybe I
can share some of the ideas used there with the community.

At first I'd like to suggest a simple but (as I hope) useful extension for
creating objects based on configuration information. As a use case for this
consider an application that accesses some central components (e.g. a
resource manager, a caching component or whatever) only through interfaces
and at startup instanciates objects of implementation classes defined in the
configuration. This makes it possible to alter the application's behavior by
just changing an implementation class in the configuration; it is a kind of
application of the GoF strategy pattern.

The idea is that information about a class is specified in a configuration
file as shown in the following example (for the XML flavour):

      <anotherproperty>Another value</anotherproperty>

Then a new class of the configuration package named ObjectConfigData (or
somebody comes up with a better name?) can be used to read this
configuration and create an instance of the defined class:

  Configuration config = ...
  ObjectConfigData objData = new ObjectConfigData(config,
  Object obj = objData.createInstance();

ObjectConfigData would extract the name of the class to be instantiated from
the class property below the specified configuration key and also all keys
in the content of the (optional) <args> element. It could use BeanUtils to
initialize the newly created instance with the properties defined here. So
the new instance can be parametrized.

In addition to this initialization a Configurable (or similar) interface can
be defined with a single initialize method that takes a Configuration object
as argument. ObjectConfigData could check if the new instance implemented
that interface and if so, pass the whole content of the <args> section to
this method. This allows for a more sophisticated initialization.

There are of course some details which need a further discussion (e.g.
exception handling), but I hope you get the point. (And I hope this mail is
not too long.) Your comments are welcome!


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message