commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <>
Subject [configuration]Single and multiple properties
Date Tue, 17 May 2005 18:22:01 GMT
Each property stored in a Configuration object can have multiple values. 
We have methods for accessing a single value of a property (e.g. 
getProperty(), getString(), getInt() etc.) and methods for retrieving 
all values (e.g. getList()). In the implementations of these methods 
typically checks have to be performed whether the property has a single 
or multiple values and eventually conversions need to be done. This 
happens at different places in the code, e.g. in AbstractConfiguration 
in resolveContainerStore(), getList(), or getStringArray(), or in 
multile methods of DataConfiguration.

When we enhance the interpolation features to support other data types 
than String, we will also have to distinguish between single and 
multiple property values.

I would like to remove duplicate code and place the logic that deals 
with these problems at a central location. So I suggest introducing a 
new interface PropertyValue, which could look as follows:

public interface PropertyValue
    // number of values of this property
    int size();
    // Is this a null property?
    boolean isDefined();

    // accessors for property values
    Object asObject();
    List asList();
    Object[] asArray();

    // Helpers for interpolation, to be fully defined later
    void interpolateScalar();
    void interpolateAll();

The main purpose of this interface would be to simplify our current 
implementation, but it would be useful for configuration clients, too. 
So a method PropertyValue getPropertyValue() could be added to the 
Configuration interface.

There can be a default implementation DefaultPropertyValue, which 
supports property values as single objects, collections, and arrays and 
knows how to convert to each other. Then all check and conversion logic 
would be placed in this class. AbstractConfiguration can provide a 
default implementation of the getPropertyValue() method that returns 
such a DefaultPropertyValue object.


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

View raw message