org.apache.aries.util.nls
Class MessageUtil

java.lang.Object
  extended by org.apache.aries.util.nls.MessageUtil

public final class MessageUtil
extends Object

This is a helper class for loading messages for logging and exception messages. It supports translating the message into the default Locale. It works out the calling Bundle and uses it to load any resources. If the resource bundle is of type java.properties then it tries to find the bundle first via the bundle getResources method, then via the getEntry method. If it is of type java.class then it'll use the bundle to load the class.


Method Summary
static MessageUtil createMessageUtil(Bundle b, String baseName)
          This method loads the resource bundle backing the MessageUtil from the provided Bundle.
static MessageUtil createMessageUtil(Class<?> context, String baseName)
          Loads the MessageUtil using the given context.
static MessageUtil createMessageUtil(String baseName)
          This method uses the Bundle associated with the caller of this method.
 String getMessage(String key, Object... inserts)
          This method translates the message and puts the inserts into the message before returning it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getMessage

public String getMessage(String key,
                         Object... inserts)
This method translates the message and puts the inserts into the message before returning it. If the message key does not exist then the key itself is returned.

Parameters:
key - the message key.
inserts - the inserts into the resolved message.
Returns:
the message in the correct language, or the key if the message does not exist.

createMessageUtil

public static MessageUtil createMessageUtil(Class<?> context,
                                            String baseName)
Loads the MessageUtil using the given context. It resolves the Class to an OSGi bundle.

Parameters:
context - the bundle this class is in will be used to resolve the base name.
baseName - the resource bundle base name
Returns:
the message util instance.
Throws:
MissingResourceException - If the resource bundle cannot be located

createMessageUtil

public static MessageUtil createMessageUtil(String baseName)
This method uses the Bundle associated with the caller of this method.

Parameters:
baseName - the resource bundle base name
Returns:
the message util instance.
Throws:
MissingResourceException - If the resource bundle cannot be located

createMessageUtil

public static MessageUtil createMessageUtil(Bundle b,
                                            String baseName)
This method loads the resource bundle backing the MessageUtil from the provided Bundle.

Parameters:
b - the bundle to load the resource bundle from
baseName - the resource bundle base name
Returns:
the message util instance.
Throws:
MissingResourceException - If the resource bundle cannot be located


Copyright © 2009-2011 The Apache Software Foundation. All Rights Reserved.