commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robert burrell donkin <robertburrelldon...@blueyonder.co.uk>
Subject Re: [betwixt] object<->string conversion .betwixt file
Date Sun, 30 Jan 2005 09:56:55 GMT
hi matt

this kind of scenario was intended to be supported by the flavour
parameter passed into the converter. the idea was that the flavour is an
arbitrary string which could be set either in a betwixt file or by some
course grained strategy. if the converter understood the flavour then it
could perform the appropriate conversion. 

my main development machine recently blew up on me and i'm still in the
process of configuring my secondary machine for apache development. so
i'm not really in a position to do much development right now. there's a
chance that support for flavours in dot betwixt files has already been
added. if not, then perhaps you'd like to replace your workaround with
an implementation that allows the flavour of the conversion to be set by
an attribute in the betwixt file. i'd be very happy to review any such
contribute if you'd like to donate it to apache. (the best way is by
submitting a patch through bugzilla). please consider adding unit tests
and documentation.

i do agree that it would be cool to be able to interrogate the options
for the current element within the converter. perhaps it would be
possible to add this information to the context (perhaps through a magic
variable) or just by adding an extra signature to the
ObjectStringConverter. that would allow a default implementation to
instantiate a converter to delegate to based on a magic option (just as
you had it). i like this solution but suspect that it would probably
require a little more effort that adding flavour support. 

i'd probably support both mechanisms and be willing to review
contributed patchs.

on a more general note, i'm now wondering whether it might be a good
idea to allow the binding configuration to be specified within a betwixt
file (possibly by use of a factory class). comments welcomed :)

- robert

On Fri, 2005-01-28 at 19:35, Matt Goodwin wrote:
> I have been able to be able to write out a bean with a date to a format 
> other than the default by specifying an options parameter and doing a 
> quick hack
> to the betwixt source.  Here is the .betwixt file.
> <?xml version='1.0' ?>
> <info>
>   <element name='ActivitySummary'>
>       <element name='CommissionsYTD' property='commissionsYTD'/>
>       <element name='LastCommissionAmt' property='lastCommissionAmt'/>
>       <element name='LastCommissionDate' property='lastCommissionDate'>
>           <option>
>               
> <name>org.apache.commons.betwixt.object-string-converter</name>
>               
> <value>com.equitrust.util.betwixt.strategy.SegDateObjectStringConverter</value>
>           </option>
>       </element>
>       <element name='PremiumYTD' property='premiumYTD'/>
>   </element>
> </info>
> 
> I modded the source in the AbstractBeanWriter in the convertToString 
> method by just simply checking of the existence of the option for 
> object-string-converter and then instantiating the converter specified.  
> Real ugly hack, but it works.  However, this does not work for string to
> object conversion because digester just uses the objectStringConverter 
> on the BindingConfiguration.  I've been trying to trace through and see 
> where
> the objectStringConverter is set on the BindingConfiguration and see 
> what ways I can override this with the .betwixt file.  Does anyone see a 
> way I can do this?  I'd like to be able to specify everything in the 
> .betwixt file so I don't have to specify my converter in code, and also 
> in case I need to use a different format for a different element (it 
> appears that the converter when registering it will convert all elements 
> of the type - in my case date - using the same converter).  Open to any 
> ideas.
> 
> Thanks,
> 
> Matt
> p.s. If you see a better way to do the ObjectToString conversion besides 
> my hack, please input that as well


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


Mime
View raw message