Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1)

E13403-04

oracle.jdeveloper.audit.service
Class Localizer

java.lang.Object
  extended by oracle.jdeveloper.audit.service.Localizer

public class Localizer
extends java.lang.Object

A supplier of localized display strings for Audit objects. A localizer retrieves template strings from a resource bundle and instantiates it using the object as a source of values. Template strings refer to property values of the object by naming them within a pair of curly braces. See instantiate(java.lang.String, java.lang.Object) and getValue(java.lang.String, int, int, java.lang.Object) for details.

The typical pattern of usage of a localizer for an object which has user-visible strings is for the object to be created with a localizer instance and for it to define a method which delegates to the localizer for each kind of string associated with the object. For example, a Catgory has a label and a description, and so has label() and description() methods that delegate to the localizer with keys of constructed from the non-localized category name: "category." + name() + ".label" and "category." + name() + ".label", respectively. The creator of a category named "assists", then, has to supply a localizer whose resource bundle supplies strings for "category.assists.label" and "category.assists.description". A class which uses a localizer should document the keys that it constructs and uses. This class is designed to be subclassable, though clients which use resource bundles in typical fashion should not need to do so.


Constructor Summary
protected Localizer(java.lang.String bundleName, java.lang.ClassLoader loader)
          Creates a localizer.
 
Method Summary
 java.util.ResourceBundle getBundle()
          Gets the resource bundle for this localizer.
protected  java.util.ResourceBundle getBundle(java.lang.String bundleName, java.lang.ClassLoader loader)
          Gets a resource bundle.
 java.lang.String getBundleName()
          Gets the name of the resource bundle for this localizer.
protected static java.lang.Object getValue(java.lang.String string, int first, int last, java.lang.Object bean)
          Gets the value of a property of an object.
static Localizer instance(java.lang.Class bundleClass)
          Gets a localizer by class.
static Localizer instance(java.lang.String bundleName)
          Gets a localizer by name.
static Localizer instance(java.lang.String bundleName, java.lang.ClassLoader loader)
          Gets a localizer by name, using the given Class Loader.
static java.lang.String instantiate(java.lang.String message, java.lang.Object bean)
          Instantiate a localized string from a template string and an object.
static java.lang.String instantiate(java.lang.String message, java.lang.Object bean, boolean erase)
          Instantiate a localized string from a template string and an object.
 java.lang.String localize(java.lang.String key, java.lang.Object object)
          Creates a localized string based on a key and an object.
 java.lang.String localize(java.lang.String key1, java.lang.String key2, java.lang.Object object)
          Creates a localized string based on a key, a fallback key, and an object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Localizer

protected Localizer(java.lang.String bundleName,
                    java.lang.ClassLoader loader)
Creates a localizer. Uses getBundle() to get the bundle using the bundle name and the given Class Loader.

Parameters:
bundleName - The name of the resource bundle used by this localizer.
loader - The ClassLoader from which to load the resource bundle.
Method Detail

instance

public static Localizer instance(java.lang.String bundleName)
Gets a localizer by name.

Parameters:
bundleName - The name of the resource bundle to use.

instance

public static Localizer instance(java.lang.String bundleName,
                                 java.lang.ClassLoader loader)
Gets a localizer by name, using the given Class Loader.

Parameters:
bundleName - The name of the resource bundle to use.
loader - The ClassLoader from which to attempt to load the resource bundle.

instance

public static Localizer instance(java.lang.Class bundleClass)
Gets a localizer by class.

Unless the type is a subclass of ResourceBundle, the bundle name will be the type name with "Bundle" appended.

Parameters:
bundleClass - The class of the resource bundle to use.

getBundleName

public java.lang.String getBundleName()
Gets the name of the resource bundle for this localizer.


getBundle

public java.util.ResourceBundle getBundle()
Gets the resource bundle for this localizer.

Returns:
the ResourceBundle for this localizer.

localize

public java.lang.String localize(java.lang.String key,
                                 java.lang.Object object)
Creates a localized string based on a key and an object. The localized string is constructed by getting the template string named by the key from the resource bundle and instantiating it by replacing property names enclosed in braces with the values of the corresponding properties in the object (see instantiate(java.lang.String, java.lang.Object)).

Parameters:
key - The name of a template string in the resource bundle.
object - An object supplying properties named in the template string.
Returns:
A localized, instantiated string.

localize

public java.lang.String localize(java.lang.String key1,
                                 java.lang.String key2,
                                 java.lang.Object object)
Creates a localized string based on a key, a fallback key, and an object. The localized string is constructed by getting the template string named by the key, or by the fallback key if necessary, from the resource bundle and instantiating it by replacing property names enclosed in braces with the values of the corresponding properties in the object (see instantiate(java.lang.String, java.lang.Object)).

Parameters:
key1 - The name of a template string in the resource bundle.
key2 - The fallback name of a template string in the resource bundle.
object - An object supplying properties named in the template strings.
Returns:
A localized, instantiated string.

getBundle

protected java.util.ResourceBundle getBundle(java.lang.String bundleName,
                                             java.lang.ClassLoader loader)
                                      throws java.util.MissingResourceException
Gets a resource bundle. The Localizer implementation calls ResourceBundle.getBundle(bundleName) to get the bundle.

Parameters:
bundleName - The name of the resource bundle.
loader - The class loader from which to load the resource bundle.
Returns:
A ResourceBundle.
Throws:
java.util.MissingResourceException

instantiate

public static java.lang.String instantiate(java.lang.String message,
                                           java.lang.Object bean)
Instantiate a localized string from a template string and an object. The template string is copied to the instantiated string except for property names enclosed in braces, which are replaced in the instantiated string by the result of invoking getValue(java.lang.String, int, int, java.lang.Object) with the property name and the object.


instantiate

public static java.lang.String instantiate(java.lang.String message,
                                           java.lang.Object bean,
                                           boolean erase)
Instantiate a localized string from a template string and an object. The template string is copied to the instantiated string except for property names enclosed in braces, which are replaced in the instantiated string by the result of invoking getValue(java.lang.String, int, int, java.lang.Object) with the property name and the object.

If erase is true and getValue returns null, immediately surrounding pairs of single or double quotes are erased and extra spaces are collapsed. This behavior in many cases allows a template string to instantiate acceptably both when properties are available and when they are not.


getValue

protected static java.lang.Object getValue(java.lang.String string,
                                           int first,
                                           int last,
                                           java.lang.Object bean)
Gets the value of a property of an object.

Parameters:
string - A string containing the property name.
first - The index of the first character of the property name.
last - The index of the first character following the property name.
bean - The object from which to get property values.

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1)

E13403-04

Copyright © 1997, 2010, Oracle. All rights reserved.