Local Strings in GlassFish - A Proposal - Solaris Rss

This is a discussion on Local Strings in GlassFish - A Proposal - Solaris Rss ; There are 2 heavily used classes that help with obtaining localized strings at runtime. The strings themselves are maintained in one properties file per package. Usually what happens is that every class in the package will create a static string ...

Local Strings in GlassFish - A Proposal

There are 2 heavily used classes that help with obtaining localized strings at runtime. The strings themselves are maintained in one properties file per package. Usually what happens is that every class in the package will create a static string helper class instantiation. Since they are static they will last forever once the class is loaded. If the package has a lot of classes then there will be a lot of these instances. But the instances are all really the same thing. They all point at the same properties file in the package.

My proposal is to have an extremely light-weight helper class, in every package that uses localized strings. This one class has only 2 simple static methods that return strings from that package's properties file. The class is copied around to every package and, literally, only one line needs to be changed -- the package declaration.

Classes in the package need not import anything -- it is already in the package.

Everything in the class is package-private -- no public or protected.

The class is naturally thread-safe

Classes simply use it like so:

String msg = Strings.get("labelHere", "arg1", "arg2");

I have 2 goals with this proposal

Make it easier to localize strings in GlassFish code. I don't know how to make it any easier!

Avoid Code Duplication

Example Implementation. You literally copy, paste and change the package name. This implementation uses LocalStringsImpl as the workhorse. You could change things around bit to use LocalStringManagerImpl instead.

package com.sun.enterprise.util.cluster;

import com.sun.enterprise.universal.i18n.LocalStringsImpl ;

/**
* Strings -- Get your Strings here.
* One file with Strings
* So one class for messing with them!
* Nothing in here is public or protected. Only for use by this one java package.
* @author Byron Nevins
*/