You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Ron Blaschke <ma...@rblasch.org> on 2004/01/19 23:07:58 UTC

new project proposal: Type Conversion Library

I am posting this here because I think commons would be the
right place to put such a library.  Please tell me if it's not.

The idea is to allow conversion for (almost?) any object into another.
I'd like to see code such as this working:

Object a = new Integer(10);
Object b = "120";

assertEquals(new Integer(10),
             TypeConverter.convert(a, Integer.class));
assertEquals(new Integer(120),
             TypeConverter.convert(b, Integer.class));

Of course, it should be extensible, and maybe allow for transitive
conversions, eg

class Seconds extends Time {}
TypeConverter.registerConverter(Integer.class, Seconds.class, /* some
converter object here */);

assertEquals(new Seconds(25), TypeConverter.convert("25",
Seconds.class); /* done via String -> Integer -> Seconds conversion */

Or add some constraint checking:
System.out.println(new Integer(128).byteValue()); /* prints -128; is
that what you wanted? */

Currently, I have only my ideas to donate (ie, no code yet), and have
not previously contributed to jakarta, so any guidance is appreciated.

Thanks,
Ron
--


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re[2]: new project proposal: Type Conversion Library

Posted by Henri Yandell <ba...@generationjava.com>.
Check out [convert] for these complaints Ron.

The lookup structure is changed so that the From and the To are specified
[though it defaults to a From of String to help the beanutils guys].

I thought I made a stab at the smart completion, ie) If asked for A->C and
only have A-B and B-C, then it does it, but I may have just commented it
as a TODO.

Will attempt to check when I get a night free from work.

Hen

On Tue, 20 Jan 2004, Ron Blaschke wrote:

> Monday, January 19, 2004, 11:34:36 PM, you wrote:
> SK> On Tue, 2004-01-20 at 11:07, Ron Blaschke wrote:
> >> I am posting this here because I think commons would be the
> >> right place to put such a library.  Please tell me if it's not.
> >>
> >> The idea is to allow conversion for (almost?) any object into another.
> >> I'd like to see code such as this working:
>
> SK> Have you looked at ConvertUtils in the BeanUtils library yet?
>
> SK> http://jakarta.apache.org/commons/beanutils/api/index.html
>
> SK> It does pretty much what you describe here. You may wish to look at
> SK> that, then send a mail describing how your ideas differ from what is
> SK> already there..
>
> In ConvertUtils, the conversion relies a lot on JDK implementations,
> which is quite "relaxed."  Eg, Integer(128) -| Byte(-128),
> Double(1.3d) -| Integer(1), etc.  I'd like to see a more configurable
> approach, for example:
> strict: "1.23" -| Integer   ... not possible, raise Exception
> relaxed: "1.23" -| Integer(1)   ... seems ok
>
> or:
> strict: Integer(128) -| Byte    ... no way! raise Exception
> relaxed: Integer(128) -| Byte(127) ... close enough
>
> The converter should enable transitive conversions, that is if one
> converter knows about A to B conversion, and another from B to C, both
> together should know about A to C.  In the Seconds example, it would
> suffice for the user supplied Seconds converter to know about
> Integers to allow conversion from String via Integer to Second.
> In ConvertUtil, the converter must know about all possible conversions
> (well, most of it is handed off to Java, which is ok, but I'd rather
> not go down that lane.)
>
> That's all that is on top of my head.  For more, I'd have to dig a day
> or so. :-)
>
> Ron
> --
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re[2]: new project proposal: Type Conversion Library

Posted by Ron Blaschke <ma...@rblasch.org>.
Monday, January 19, 2004, 11:34:36 PM, you wrote:
SK> On Tue, 2004-01-20 at 11:07, Ron Blaschke wrote:
>> I am posting this here because I think commons would be the
>> right place to put such a library.  Please tell me if it's not.
>> 
>> The idea is to allow conversion for (almost?) any object into another.
>> I'd like to see code such as this working:

SK> Have you looked at ConvertUtils in the BeanUtils library yet?

SK> http://jakarta.apache.org/commons/beanutils/api/index.html

SK> It does pretty much what you describe here. You may wish to look at
SK> that, then send a mail describing how your ideas differ from what is
SK> already there..

In ConvertUtils, the conversion relies a lot on JDK implementations,
which is quite "relaxed."  Eg, Integer(128) -| Byte(-128),
Double(1.3d) -| Integer(1), etc.  I'd like to see a more configurable
approach, for example:
strict: "1.23" -| Integer   ... not possible, raise Exception
relaxed: "1.23" -| Integer(1)   ... seems ok

or:
strict: Integer(128) -| Byte    ... no way! raise Exception
relaxed: Integer(128) -| Byte(127) ... close enough

The converter should enable transitive conversions, that is if one
converter knows about A to B conversion, and another from B to C, both
together should know about A to C.  In the Seconds example, it would
suffice for the user supplied Seconds converter to know about
Integers to allow conversion from String via Integer to Second.
In ConvertUtil, the converter must know about all possible conversions
(well, most of it is handed off to Java, which is ok, but I'd rather
not go down that lane.)

That's all that is on top of my head.  For more, I'd have to dig a day
or so. :-)

Ron
-- 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: new project proposal: Type Conversion Library

Posted by Simon Kitching <si...@ecnetwork.co.nz>.
On Tue, 2004-01-20 at 11:07, Ron Blaschke wrote:
> I am posting this here because I think commons would be the
> right place to put such a library.  Please tell me if it's not.
> 
> The idea is to allow conversion for (almost?) any object into another.
> I'd like to see code such as this working:

Have you looked at ConvertUtils in the BeanUtils library yet?

http://jakarta.apache.org/commons/beanutils/api/index.html

It does pretty much what you describe here. You may wish to look at
that, then send a mail describing how your ideas differ from what is
already there..

Regards,

Simon



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: Re[2]: new project proposal: Type Conversion Library

Posted by Paul Libbrecht <pa...@activemath.org>.
Robert,

It sounds indeed to match what I understood (remember, James was mostly 
the father of it all). How about an example to make things more precise 
?

paul


On 22-Jan-04, at 11:49 Uhr, robert burrell donkin wrote:

> On 22 Jan 2004, at 10:21, Paul Libbrecht wrote:
>
>> I'm sorry I'm coming so late on this but I wanted to point out one 
>> interest into this library: Jelly is currently using BeanUtils with a 
>> few registred additional converters (for example Jelly-Swing with 
>> Dimensions, Rectangles, Colors, Fonts, ...). However the way these 
>> converters are registred is not easy to be "meta-thought-about" which 
>> makes the generation of the tag-documentation for such libraries 
>> currently impossible.
>>
>> If there was an abstract way of specifying type-converters, then 
>> jellydoc could probably use it at the instatiation of the 
>> tag-libraries.
>
> hi paul
>
> (just to explain the beanutils sort-of-road-map)
>
> the route we've been traveling down (slowly) is beanification - 
> replacing the old booch utilities with proper objects and backing the 
> old interfaces with pseudo-singletons (per context classloader). using 
> proper objects has many advantages including better isolation.
>
> we'll probably also move towards great use of strategy plugins.
>
> in terms of registration, one improvement which i've been planning to 
> make (but have never really felt the itch badly enough) is factor out 
> a register for the conversion types. if this happened then it'd be 
> possible to create a register implementation which could be configured 
> using meta-data and then plugged into the convertutilsbean instance to 
> be used in the next part of the script.
>
> if this kind of functionality is needed by jelly, i'd probably be more 
> motivated to implement it. of course, the problem for jelly with this 
> is that it'd mean moving onto CVS HEAD for beanutils and without a 
> realistic chance of a release for some time.
>
> (that's not to say that the conversion system in beanutils is any way 
> sufficient for many purposes but then one of the long term aims for 
> both project - for me at least - would  be to be able to plug convert 
> into a beanutils.)
>
> - robert
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: Re[2]: new project proposal: Type Conversion Library

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
On 22 Jan 2004, at 10:21, Paul Libbrecht wrote:

> I'm sorry I'm coming so late on this but I wanted to point out one 
> interest into this library: Jelly is currently using BeanUtils with a 
> few registred additional converters (for example Jelly-Swing with 
> Dimensions, Rectangles, Colors, Fonts, ...). However the way these 
> converters are registred is not easy to be "meta-thought-about" which 
> makes the generation of the tag-documentation for such libraries 
> currently impossible.
>
> If there was an abstract way of specifying type-converters, then 
> jellydoc could probably use it at the instatiation of the 
> tag-libraries.

hi paul

(just to explain the beanutils sort-of-road-map)

the route we've been traveling down (slowly) is beanification - 
replacing the old booch utilities with proper objects and backing the 
old interfaces with pseudo-singletons (per context classloader). using 
proper objects has many advantages including better isolation.

we'll probably also move towards great use of strategy plugins.

in terms of registration, one improvement which i've been planning to 
make (but have never really felt the itch badly enough) is factor out a 
register for the conversion types. if this happened then it'd be 
possible to create a register implementation which could be configured 
using meta-data and then plugged into the convertutilsbean instance to 
be used in the next part of the script.

if this kind of functionality is needed by jelly, i'd probably be more 
motivated to implement it. of course, the problem for jelly with this 
is that it'd mean moving onto CVS HEAD for beanutils and without a 
realistic chance of a release for some time.

(that's not to say that the conversion system in beanutils is any way 
sufficient for many purposes but then one of the long term aims for 
both project - for me at least - would  be to be able to plug convert 
into a beanutils.)

- robert


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: Re[2]: new project proposal: Type Conversion Library

Posted by Paul Libbrecht <pa...@activemath.org>.
I'm sorry I'm coming so late on this but I wanted to point out one 
interest into this library: Jelly is currently using BeanUtils with a 
few registred additional converters (for example Jelly-Swing with 
Dimensions, Rectangles, Colors, Fonts, ...). However the way these 
converters are registred is not easy to be "meta-thought-about" which 
makes the generation of the tag-documentation for such libraries 
currently impossible.

If there was an abstract way of specifying type-converters, then 
jellydoc could probably use it at the instatiation of the 
tag-libraries.

Thanks.

paul


On 22-Jan-04, at 10:20 Uhr, Stephen Colebourne wrote:

> From: "Ron Blaschke" <ma...@rblasch.org>
>> Thanks a lot for the pointers to convert and how to get involved.  I
>> glanced over convert and it seems the right place to start.
>
> I am also willing to help push forward the [convert] project and am 
> willing
> to apply patches etc.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: Re[2]: new project proposal: Type Conversion Library

Posted by Stephen Colebourne <sc...@btopenworld.com>.
From: "Ron Blaschke" <ma...@rblasch.org>
> Thanks a lot for the pointers to convert and how to get involved.  I
> glanced over convert and it seems the right place to start.

I am also willing to help push forward the [convert] project and am willing
to apply patches etc.

Stephen


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re[2]: new project proposal: Type Conversion Library

Posted by Ron Blaschke <ma...@rblasch.org>.
Tuesday, January 20, 2004, 12:17:04 AM, you wrote:
HY> Yep, [convert] exists in the sandbox and I've been moving forward with it
HY> in my usual way, which means I find a way to use it in some non-apache
HY> project of mine and just see how it goes. I've got it attached to two
HY> projects, but it's not being used in anger in them yet.

HY> The code is based on the beanutils code, with a new lookup mechanism. I'm
HY> happy to mentor any further work on it, so you won't get abandoned without
HY> the ability to add patches etc.

HY> On Mon, 19 Jan 2004, robert burrell donkin wrote:
>> here are some urls:
>>
>> http://jakarta.apache.org/commons/volunteering.html
>> http://jakarta.apache.org/commons/patches.html
>> http://jakarta.apache.org/site/getinvolved.html
>>
>> but there's quite a lot else on the web site and the wiki if you're
>> willing to look hard enough.

Thanks a lot for the pointers to convert and how to get involved.  I
glanced over convert and it seems the right place to start.



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: new project proposal: Type Conversion Library

Posted by Henri Yandell <ba...@generationjava.com>.
Yep, [convert] exists in the sandbox and I've been moving forward with it
in my usual way, which means I find a way to use it in some non-apache
project of mine and just see how it goes. I've got it attached to two
projects, but it's not being used in anger in them yet.

The code is based on the beanutils code, with a new lookup mechanism. I'm
happy to mentor any further work on it, so you won't get abandoned without
the ability to add patches etc.

Hen

On Mon, 19 Jan 2004, robert burrell donkin wrote:

> hi ron
>
> IIRC there is a proto-project in the sandbox along these lines called
> convert. convertutils (in beanutils) is ok but is handicapped by
> backwards compatibility. it's been lacking momentum for some while but
> it's might be easier to revive that project that create a new one.
>
> it's probably good that you don't have much code (just - hopefully -
> enthusiasm) since that avoids any thorny questions of importing
> external code. i'd suggest that you take a look at the convert project
> and about ways to take it forward. then next phase would be writing
> some patches and submitting them. (it might be wise to see whether they
> are any committers willing to act as mentors for convert before putting
> too much work in.)
>
> here are some urls:
>
> http://jakarta.apache.org/commons/volunteering.html
> http://jakarta.apache.org/commons/patches.html
> http://jakarta.apache.org/site/getinvolved.html
>
> but there's quite a lot else on the web site and the wiki if you're
> willing to look hard enough.
>
> - robert
>
> On 19 Jan 2004, at 22:07, Ron Blaschke wrote:
>
> > I am posting this here because I think commons would be the
> > right place to put such a library.  Please tell me if it's not.
> >
> > The idea is to allow conversion for (almost?) any object into another.
> > I'd like to see code such as this working:
> >
> > Object a = new Integer(10);
> > Object b = "120";
> >
> > assertEquals(new Integer(10),
> >              TypeConverter.convert(a, Integer.class));
> > assertEquals(new Integer(120),
> >              TypeConverter.convert(b, Integer.class));
> >
> > Of course, it should be extensible, and maybe allow for transitive
> > conversions, eg
> >
> > class Seconds extends Time {}
> > TypeConverter.registerConverter(Integer.class, Seconds.class, /* some
> > converter object here */);
> >
> > assertEquals(new Seconds(25), TypeConverter.convert("25",
> > Seconds.class); /* done via String -> Integer -> Seconds conversion */
> >
> > Or add some constraint checking:
> > System.out.println(new Integer(128).byteValue()); /* prints -128; is
> > that what you wanted? */
> >
> > Currently, I have only my ideas to donate (ie, no code yet), and have
> > not previously contributed to jakarta, so any guidance is appreciated.
> >
> > Thanks,
> > Ron
> > --
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: new project proposal: Type Conversion Library

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
hi ron

IIRC there is a proto-project in the sandbox along these lines called 
convert. convertutils (in beanutils) is ok but is handicapped by 
backwards compatibility. it's been lacking momentum for some while but 
it's might be easier to revive that project that create a new one.

it's probably good that you don't have much code (just - hopefully - 
enthusiasm) since that avoids any thorny questions of importing 
external code. i'd suggest that you take a look at the convert project 
and about ways to take it forward. then next phase would be writing 
some patches and submitting them. (it might be wise to see whether they 
are any committers willing to act as mentors for convert before putting 
too much work in.)

here are some urls:

http://jakarta.apache.org/commons/volunteering.html
http://jakarta.apache.org/commons/patches.html
http://jakarta.apache.org/site/getinvolved.html

but there's quite a lot else on the web site and the wiki if you're 
willing to look hard enough.

- robert

On 19 Jan 2004, at 22:07, Ron Blaschke wrote:

> I am posting this here because I think commons would be the
> right place to put such a library.  Please tell me if it's not.
>
> The idea is to allow conversion for (almost?) any object into another.
> I'd like to see code such as this working:
>
> Object a = new Integer(10);
> Object b = "120";
>
> assertEquals(new Integer(10),
>              TypeConverter.convert(a, Integer.class));
> assertEquals(new Integer(120),
>              TypeConverter.convert(b, Integer.class));
>
> Of course, it should be extensible, and maybe allow for transitive
> conversions, eg
>
> class Seconds extends Time {}
> TypeConverter.registerConverter(Integer.class, Seconds.class, /* some
> converter object here */);
>
> assertEquals(new Seconds(25), TypeConverter.convert("25",
> Seconds.class); /* done via String -> Integer -> Seconds conversion */
>
> Or add some constraint checking:
> System.out.println(new Integer(128).byteValue()); /* prints -128; is
> that what you wanted? */
>
> Currently, I have only my ideas to donate (ie, no code yet), and have
> not previously contributed to jakarta, so any guidance is appreciated.
>
> Thanks,
> Ron
> --
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org