com.unitesk.atp.text.localize
Class ConstantStringManager

java.lang.Object
  extended by com.unitesk.atp.text.localize.ConstantStringManager
All Implemented Interfaces:
StringManager
Direct Known Subclasses:
PatternStringManager

public class ConstantStringManager
extends Object
implements StringManager

The default implementation of localized strings manager. Associates object classes and bundles of localized messages. That is for all objects of some class localized strings with the same names are equal.

Version:
$Id: ConstantStringManager.java,v 1.4 2005/05/23 05:49:37 all-x Exp $
Author:
Alexey Demakov

Field Summary
protected  Map class_to_bundle
           
protected  ClassLoader classLoader
           
protected  Locale locale
           
 
Constructor Summary
ConstantStringManager()
          Creates new localized strings manager using default locale and class loader of this class.
ConstantStringManager(Locale locale)
          Creates new localized strings manager using the specified locale and class loader of this class.
ConstantStringManager(Locale locale, ClassLoader classLoader)
          Creates new localized strings manager with the specified locale and class loader.
 
Method Summary
protected  ResourceBundle getBundle(Class cls)
          Loads bundle of localized strings for the specified class.
 String getString(Class cls, String name)
          Get localized string for the specified class.
 String getString(Class cls, String name, Object obj)
          Get localized string for the specified class and customize it for the specified object.
 String getString(String name, Object obj)
          Get localized string for the specified object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

locale

protected Locale locale

classLoader

protected ClassLoader classLoader

class_to_bundle

protected Map class_to_bundle
Constructor Detail

ConstantStringManager

public ConstantStringManager()
Creates new localized strings manager using default locale and class loader of this class.


ConstantStringManager

public ConstantStringManager(Locale locale)
Creates new localized strings manager using the specified locale and class loader of this class.

Parameters:
locale - The locale to be used by this manager.

ConstantStringManager

public ConstantStringManager(Locale locale,
                             ClassLoader classLoader)
Creates new localized strings manager with the specified locale and class loader.

Parameters:
locale - The locale to be used by this manager.
classLoader - The class loader to be used by this maanger.
Method Detail

getBundle

protected ResourceBundle getBundle(Class cls)
Loads bundle of localized strings for the specified class.

This implementation uses ResourceBundle.getBundle( cls.getName(), locale, classLoader) to obtain bundle. locale and classLoader are specified in constructor of this manager.

Inheritors can override this method to change a way of bundle loading.

Parameters:
cls - The specified class.
Returns:
Bundle for the specified class or null if it is not found.

getString

public String getString(Class cls,
                        String name)
Get localized string for the specified class. The first time this method is called for the specified class it uses getBundle( cls ) to obtain resource bundle. Then gets string name from this bundle and customize it with respect to obj.

Specified by:
getString in interface StringManager
Parameters:
cls - The specified class.
name - The name of localized string for this class.
Returns:
Localized string or null if it is not found.

getString

public String getString(String name,
                        Object obj)
Get localized string for the specified object. It calls getString( obj.getClass(), name ). This string manager is called 'constant' because it returns the same string for all objects of the same class.

Specified by:
getString in interface StringManager
Parameters:
name - The name of localized string for this object.
obj - The specified object.
Returns:
Localized string or null if it is not found.

getString

public String getString(Class cls,
                        String name,
                        Object obj)
Get localized string for the specified class and customize it for the specified object. It calls getString( cls, name ). This string manager is called 'constant' because it returns the same string for all objects of the same class.

Specified by:
getString in interface StringManager
Parameters:
cls - The specified class.
name - The name of localized string for this class.
obj - Not used.
Returns:
Localized string or null if it is not found.


Copyright © 2001-2006 ISP RAS, RedVerst Group. All Rights Reserved.