[Hippo-cms7-user] Re: [Hippo-hst-dev] HstComponent development

Ard Schrijvers a.schrijvers at onehippo.com
Thu Apr 14 13:19:39 CEST 2011


On Thu, Apr 14, 2011 at 12:40 PM, Mickaël Tricot <m.tricot at onehippo.com> wrote:
> Hi,
>
> I like the idea of using annotations to inject the parameter values. I
> haven't tried it yet, but an idea comes to my mind.
>
> Wouldn't it be nice to have a mechanism for transforming the value into any
> Object type we would need into the component? See this quick code snippet,

It would be very nice, and hence, this is already how it works. Only,
not the way described below. It works automatically by the return type
of the interface method. If your return type for example is 'int', we
try to return the default value or the parameter value from
configuration as an integer. This is all taking care of by the proxy
around the interface with parameterized getters: Great job by Woonsan.

Just try it out, you'll see how nice this already works. Also see the
documentation page, that we get an instance of the interface, and just
say getPageSize and get an integer.

Regards Ard


> for a Class parameter:
>
> @Parameter(name = "fooClass", defaultValue="java.lang.String",
> transformer=ParameterClassTransformer.class)
> Class getFooClass();
>
> The transformer could look like:
>
> interface Transformer<T> {
>   T transform(String parameterValue, String defaultValue);
> }
>
> class ParameterClassTransformer implements Transformer<Class> {
>  Class transform(String parameterValue, String defaultValue) {
>    try {
>      return Class.forName(parameterValue);
>    } catch(Exception e){}
>    return defaultValue;
>  }
> }
>
> ... or like (returns the default value in case of exception during the
> transformation):
>
> interface Transformer<T>  {
>  T transform(String parameterValue) throws IllegalArgumentException;
> }
>
> class ParameterClassTransformer implements Transformer<Class>  {
>  Class transform(String parameterValue) {
>    try {
>      return Class.forName(parameterValue);
>    } catch(Exception e){
>      throw new IllegalArgumentException(e);
>    }
>  }
> }
>
>
> What do you think?
> Regards,
>
> Mickaël
> _______________________________________________
> Hippo-hst-dev mailing list and forums
> http://www.onehippo.org/site-toolkit
>



-- 
Hippo
Europe  •  Amsterdam  Oosteinde 11  •  1017 WT Amsterdam  •  +31 (0)20 522 4466
USA  • San Francisco 755 Baywood Drive, Second Floor •  Petaluma, CA.
94954 •  +1 877 414 4776 (toll free)
Canada    •   Montréal  5369 Boulevard St-Laurent #430 •  Montréal QC
H2T 1S5  •  +1 (514) 316 8966
www.onehippo.com  •  www.onehippo.org  •  info at onehippo.com
________________________________________________________________
This e-mail may be privileged and/or confidential, and the sender does
not waive any related rights and obligations. Any distribution, use or
copying of this e-mail or the information it contains by other than an
intended recipient is unauthorized. If you received this e-mail in
error, please advise me (by return e-mail or otherwise) immediately.



More information about the Hippo-cms7-user mailing list