Details
Description
We return a description of factory parameters in terms of an Param[] (or its superclass Parameter[]). This is a bit of a pain since it is hard to find a param entry by key; or sort out what the different utility methods do.
Often you end up writing the same for loops multiple times; or putting things in a Map<String,Param> just to make programming faster.
The attached class was combined from a bunch of uDig utility code from handling parameters and operates as a wrapper around a Param[].
class Params {
Params(DataAccessFactory)
lookup(Class<T>, String, Map<String, ?>)
lookup(Class<T>, Map<String, ?>)
getParam(String)
getParam(Class<?>)
}
An example use is:
Params params = new Params( factory ); String host = params.lookup( String.class, "host", connectionParams )
The expected type is passed in; simply to cut down on casting; if "host" is not available in the factory params it will not be blindly returned. In a similar manner the host "sample" value of localhost will be returned if the connectionParams does not contain an "host" entry. This method builds on Param.handle( connectionParams ).
Please note that the Param superclass Parameter has less helpful utility methods; it is my preference to move such things into this Params class rather then complicate the superclass.
The approach of a wrapper was taken rather then adding methods to DataUtilities.
Notes:
- Params may not be the best name for the class - even the above code example has too many things named "param". Should use a plural form since we are wrapping a set of parameters. Ideas: Parameters, ConnectionParameters
- Note this is not Andrea's long standing request for a Java Bean; however this class could become a formal DynamicProxy (if we pass the connection parameter values in) or produce a BeanInfo for working with one of the commons bean classes which present a java map as a bean.
Like, the main use case I see is people actually building the map to get back a datastore, and this one does not seem to particularly help out?
Do you have a code example of how it makes things better?