Error Messages, Parameters and Other Resources In InfoGrid

InfoGrid internally configures all parameters and messages via resource files. This makes internationalization much easier, and gives application developers a way of changing internal parameters if so desired. InfoGrid includes an override mechanism allows developers to use different values than InfoGrid’s default values without having to change InfoGrid’s property files.

Let’s take an example. Class org.infogrid.httpd.HttpServer implements a very simple HTTP server that’s been quite useful for automated testing, for example. Its default listening port should not be hard-coded, but instead is configured via a resource. In the code, it looks as follows:

private static final ResourceHelper theResourceHelper
        = ResourceHelper.getInstance( HttpServer.class );

protected static final int DEFAULT_ACCEPT_PORT
        = theResourceHelper.getResourceIntegerOrDefault(
                8081 );

Class org.infogrid.util.ResourceHelper is basically a wrapper around the Java resource facilities, but with some additional facilities, such as the ability to parse integers and use defaults as can be seen from this code fragment. When this code runs, InfoGrid looks for an override first (more about this below), then for a property file called org/infogrid/httpd/ In that file, it looks for a line that looks like this:


If found, DEFAULT_ACCEPT_PORT will be assigned that value. If not found (as in the current InfoGrid version, as the line is commented out), it will use the default specified in the code, here 8081.

If a developer wishes to override the property in that file, they could of course change that property file, but that would effectively create an InfoGrid branch, which is undesirable. Instead, an override mechanism can be used:

The ResourceHelper can be initialized with an “application resource bundle”, which essentially is just another property file specific to the application. Resources specified in that file override all others. An application developer could specify, in that file:


and DEFAULT_ACCEPT_PORT will become 80. It is necessary to qualify the name of the resource with the fully-qualified name of the ResourceHelper so no naming collisions occur across modules or developers, hence the prefix separated by the !.

The application resource bundle for an application can be set manually, by invoking ResourceHelper.setApplicationResourceBundle( ResourceBundle ) in the application’s startup code, or, preferably when using the InfoGrid Module Framework, in the application’s module advertisement as a parameter like this:

<parameter name="org.infogrid.util.ResourceHelper.ApplicationResourceBundle"
        value="com/example/ExampleApp" />

This identifies file com/example/ as the application resource file.

Comments are closed.