cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruno Dumon <br...@outerthought.org>
Subject Re: [RT] Attribute Rendering and CForms Convertors
Date Tue, 16 Nov 2004 07:57:15 GMT
On Sat, 2004-11-13 at 05:50 +0100, Jonas Ekstedt wrote:
> On Wed, 2004-11-10 at 12:15 +0100, Daniel Fagerstrom wrote:
<snip/>
> 
> How about an interface like this:
> 
> public interface Convertor {
> 
>     public String getId();
>     public void setId(String id);
>     public Class getTypeClass();
>     public String convertToString(Object value, Locale locale) 
> 	throws Exception;
>     public Object convertFromString(String value, Locale locale) 
> 	throws Exception;
> 
> }
> 
> Each convertor has an id (useful for error reporting when conversion
> fails) and a typeClass (ie the class type it converts to/from). Those
> convertors that need extra configuration would implement Configurable.

So if convertFromString fails, you'd throw an exception? A user who
enters something invalid is far from an exceptional condition, that's
why currently the ConversionResult is returned which includes this
information (exceptions are rather heavy to create).

Originally, convertors returned null if conversion failed (and otherwise
the converted value), but then the ConversionResult was introduced to
allow convertors to also return an error message describing why the
conversion failed.

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


Mime
View raw message