You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by Adrian Crum <ad...@hlmksw.com> on 2007/06/26 22:53:11 UTC

RFC: Data converter interface/classes

I noticed the recent work being done with OAGIS support. At the same time I'm looking at adding iCal 
support to my calendar application. Both efforts require converting external data types to/from 
OFBiz data types.

I'm thinking that it would make sense to have a GenericDataConverter interface created that we could 
derive implementations from for these and future conversions. Initially, the interface would just 
convert from OFBiz data types to properly formatted strings and the reverse - strings to OFBiz data 
types. In other words, each OFBiz data type would have two methods: fromXxxx and toXxxx.

So, the OAGIS component would have an implementation of the data converter interface called, say, 
OagisDataConverter, and instead of the code:

DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSS'Z'Z");
Date date = new Date();
String sentDate = null;
sentDate = dateFormat.format(date);

you would have this:

String sentDate = OagisDataConverter.fromDate(new Date());

To get OFBiz data from an OAGIS data source, you would use the complimentary method:

Date sentDate = OagisDataConverter.toDate(oagisDateString);

In my calendar app I would have an iCal implementation of the interface:

String eventDate = iCalDataConverter.fromDate(new Date());
Date eventDate = iCalDataConverter.toDate(iCalDateString);

What do you think?

-Adrian

Re: RFC: Data converter interface/classes

Posted by Adrian Crum <ad...@hlmksw.com>.
I was thinking that the GenericDataConverter interface could be coupled with a concrete GenericValue 
decorator class to provide a GenericValue that auto-converts between data formats.

Example:

GenericDataConverter oagisConverter = new OagisDataConverter();
GenericValue someEntity = delegator.findByPrimaryKey(...);
GenericValue convertedEntity = new GenericConverterValue(someEntity, oagisConverter);
// use convertedEntity as you would a GenericEntity - get() and put() return/accept OAGIS data types
convertedEntity.put("sentDate", oagisSentDate);
convertedEntity.store();


Adrian Crum wrote:

> I noticed the recent work being done with OAGIS support. At the same 
> time I'm looking at adding iCal support to my calendar application. Both 
> efforts require converting external data types to/from OFBiz data types.
> 
> I'm thinking that it would make sense to have a GenericDataConverter 
> interface created that we could derive implementations from for these 
> and future conversions. Initially, the interface would just convert from 
> OFBiz data types to properly formatted strings and the reverse - strings 
> to OFBiz data types. In other words, each OFBiz data type would have two 
> methods: fromXxxx and toXxxx.
> 
> So, the OAGIS component would have an implementation of the data 
> converter interface called, say, OagisDataConverter, and instead of the 
> code:
> 
> DateFormat dateFormat = new 
> SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSS'Z'Z");
> Date date = new Date();
> String sentDate = null;
> sentDate = dateFormat.format(date);
> 
> you would have this:
> 
> String sentDate = OagisDataConverter.fromDate(new Date());
> 
> To get OFBiz data from an OAGIS data source, you would use the 
> complimentary method:
> 
> Date sentDate = OagisDataConverter.toDate(oagisDateString);
> 
> In my calendar app I would have an iCal implementation of the interface:
> 
> String eventDate = iCalDataConverter.fromDate(new Date());
> Date eventDate = iCalDataConverter.toDate(iCalDateString);
> 
> What do you think?
> 
> -Adrian
>