dev@jax-ws.java.net

Proposal: resource constant

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Mon, 27 Mar 2006 10:44:56 -0800

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:

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.



-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com