dev@jax-ws.java.net

Re: Proposal: resource constant

From: Jitendra Kotamraju <Jitendra.Kotamraju_at_Sun.COM>
Date: Mon, 27 Mar 2006 11:10:36 -0800

Kohsuke Kawaguchi wrote:

>
> I find the current resource localization code in JAX-WS to be painful
> to use. For example, a typical idiom is:
>
> private static final Localizer localizer = new Localizer();
> private static final LocalizableMessageFactory messageFactory =
> new LocalizableMessageFactory("com.sun.xml.ws.resources.wsservlet");
>
> and then do:
>
> localizer.localize(
> messageFactory.getMessage("servlet.html.notFound", message))
>
> this is not only error prone, but it's hard to use.
>
> I'd like to write a little code generator that scans resource files,
> and generate a class of the form:

Is there any code in JDK we can reuse to parse the resource files as
some properties can go on multiple lines etc.

Jitu

>
> public class WSServletMessages {
> // for each message
> public static String LISTENER_PARSING_FAILED(Object arg1) {
> // localize the message by using the default locale
> }
>
> // creates Localizable so that locale can be supplied later
> Localizable createLISTENER_PARSING_FAILED(Object arg1) { ... }
> }
>
> for each resource file.
>
> Basically, turn each resource into a method with the right number of
> arguments.
>
> This would allow our code to say:
>
> WSServletMessages.LISTENER_PARSING_FAILED(...);
>
> instead of:
>
> localizer.localize(
> messageFactory.getMessage("servlet.html.notFound", message))
>
> and you can also get auto-completion from IDE, so you save a lot of
> typing. This also allows us to check for unused resource messages,
> make sure that the # of arguments are correct.
>
> The same code would benefit Tango components, too.
>
>
>