Re: [picocontainer-dev] ConfigParameterTestCase / ConfigParameter
Jörg Schaible <[email protected]>
| Newsgroups | gmane.comp.java.picocontainer.devel |
|---|---|
| Message-ID | <[email protected]> |
Paul Hammant wrote:
[snip]
> I'd love to stop using the XSteam converters, and just use the miriad
> of built in converters in the JDK ...
>
> Currency.getInstance(paramValue)
> Float.valueOf(paramValue)
Hmmm. Remember XStream's ToStringConverter that was contributed by you?
Since Pico is now Java 5 it should be quite easy to provide some generic
parameter factories (Pico only needs 'em oneway only). Some pseudo-code:
interface ParameterFactory<T> {
bool provides(Class<U> type);
T fromString(String s);
}
abstract class AbstractParameterFactory<T> implements PF<T> {
bool provides(Class<U> type) {
return T.class == U.class;
}
}
class StringConstructorParameterFactory<T> extends APF<T> {
T fromString(String s) {
return new T(s);
}
}
class NewInstanceParameterFactory<T> extends APF<T> {
T fromString(String s) {
return T.newInstance(s);
}
}
class ValueOfParameterFactory<T> extends APF<T> {
T fromString(String s) {
return T.valueOf(s);
}
}
class EnumParameterFactory<T> extends APF<T> {
T fromString(String s) {
return Enum.valueOf(T.class, s));
}
}
...
> This would allow a massive simplification of the implementation, and
> meet the my need, Konstantin's original need, and the needs in the
> lastest thread.
The only missing part is now to have a factory for the
ParameterFactories ;-)
However, all that is necessary is a (enhanceable ?) list of class types for
each ParameterFactory.
WDYAT ?
- Jörg
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email