deegree 2.1 (2007/11/08 09:57 build-328-official)

org.deegree.model.csct.resources
Class ResourceBundle

java.lang.Object
  extended by java.util.ResourceBundle
      extended by org.deegree.model.csct.resources.ResourceBundle
Direct Known Subclasses:
Resources, Resources

public class ResourceBundle
extends ResourceBundle

{link java.util.ResourceBundle} implementation using integers instead of strings for resource keys. Because it doesn't use strings, this implementation avoid adding all those string constants to .class files and runtime images. Developpers still have meaningful labels in their code (e.g. DIMENSION_MISMATCH) through a set of constants defined in interfaces. This approach furthermore give the benefict of compile-time safety. Because integer constants are inlined right into class files at compile time, the declarative interface is never loaded at run time.

This class also provides facilities for string formatting using MessageFormat.

Version:
1.0
Author:
Martin Desruisseaux

Field Summary
protected  String[] values
          The array of resources.
 
Fields inherited from class java.util.ResourceBundle
parent
 
Constructor Summary
protected ResourceBundle(String filename)
          Construct a new resource bundle.
 
Method Summary
 Enumeration<String> getKeys()
          Returns an enumeration of the keys.
 String getLabel(int keyID)
          Gets a string for the given key and append ": " to it.
protected  String getLoggerName()
          Returns the name of the logger to use.
 String getMenuLabel(int keyID)
          Gets a string for the given key and append "..." to it.
 String getString(int keyID)
          Gets a string for the given key from this resource bundle or one of its parents.
 String getString(int keyID, Object arg0)
          Gets a string for the given key and format it with the specified argument.
 String getString(int keyID, Object arg0, Object arg1)
          Gets a string for the given key are replace all occurence of "{0}", "{1}", with values of arg0, arg1, etc.
 String getString(int keyID, Object arg0, Object arg1, Object arg2)
          Gets a string for the given key are replace all occurence of "{0}", "{1}", with values of arg0, arg1, etc.
 String getString(int keyID, Object arg0, Object arg1, Object arg2, Object arg3)
          Gets a string for the given key are replace all occurence of "{0}", "{1}", with values of arg0, arg1, etc.
 String getString(int keyID, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4)
          Gets a string for the given key are replace all occurence of "{0}", "{1}", with values of arg0, arg1, etc.
protected  Object handleGetObject(String key)
          Gets an object for the given key from this resource bundle.
 void list(Writer out)
          List resources to the specified stream.
 String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.util.ResourceBundle
getBundle, getBundle, getBundle, getLocale, getObject, getString, getStringArray, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

values

protected String[] values
The array of resources. Keys are array index. For example the value for key "14" is values[14]. This array will be loaded only when first needed. We should not load it at construction time, because some ResourceBundle objects will never ask for values. This is case especially for ancestor classes of Resources_fr_CA, Resources_en, Resources_de, etc., which will be used only if a key has not been found in the subclasse.

Constructor Detail

ResourceBundle

protected ResourceBundle(String filename)
Construct a new resource bundle.

Parameters:
filename - The resource name containing resources. It is usually a filename, but may also be an entry in a JAR file.
Method Detail

getLoggerName

protected String getLoggerName()
Returns the name of the logger to use. Default implementation returns the package name.


list

public final void list(Writer out)
                throws IOException
List resources to the specified stream. If a resource has more than one line, only the first line will be written. This method is used mostly for debugging purpose.

Parameters:
out - The destination stream.
Throws:
IOException - if an output operation failed.

getKeys

public final Enumeration<String> getKeys()
Returns an enumeration of the keys.

Specified by:
getKeys in class ResourceBundle
Returns:
enumeration of the keys

handleGetObject

protected final Object handleGetObject(String key)
Gets an object for the given key from this resource bundle. Returns null if this resource bundle does not contain an object for the given key.

Specified by:
handleGetObject in class ResourceBundle
Parameters:
key - the key for the desired object
Returns:
the object for the given key, or null
Throws:
NullPointerException - if key is null

getMenuLabel

public final String getMenuLabel(int keyID)
                          throws MissingResourceException
Gets a string for the given key and append "..." to it. This is method is typically used for creating menu label.

Parameters:
keyID - The key for the desired string.
Returns:
The string for the given key.
Throws:
MissingResourceException - If no object for the given key can be found.

getLabel

public final String getLabel(int keyID)
                      throws MissingResourceException
Gets a string for the given key and append ": " to it. This is method is typically used for creating menu label.

Parameters:
keyID - The key for the desired string.
Returns:
The string for the given key.
Throws:
MissingResourceException - If no object for the given key can be found.

getString

public final String getString(int keyID)
                       throws MissingResourceException
Gets a string for the given key from this resource bundle or one of its parents.

Parameters:
keyID - The key for the desired string.
Returns:
The string for the given key.
Throws:
MissingResourceException - If no object for the given key can be found.

getString

public final String getString(int keyID,
                              Object arg0)
                       throws MissingResourceException
Gets a string for the given key and format it with the specified argument. The message if formatted using MessageFormat. Calling his method is approximatively equivalent to calling:
     String pattern = getString(key);
     Format f = new MessageFormat(pattern);
     return f.format(arg0);
 
If arg0 is not already an array, it will be wrapped into an array of length 1. Using MessageFormat, all occurence of "{0}", "{1}", "{2}" in the resource string will be replaced by arg0[0], arg0[1], arg0[2], etc.

Parameters:
keyID - The key for the desired string.
arg0 - A single object or an array of objects to be formatted and substituted.
Returns:
The string for the given key.
Throws:
MissingResourceException - If no object for the given key can be found.
See Also:
MessageFormat

getString

public final String getString(int keyID,
                              Object arg0,
                              Object arg1)
                       throws MissingResourceException
Gets a string for the given key are replace all occurence of "{0}", "{1}", with values of arg0, arg1, etc.

Parameters:
keyID - The key for the desired string.
arg0 - Value to substitute to "{0}".
arg1 - Value to substitute to "{1}".
Returns:
The formatted string for the given key.
Throws:
MissingResourceException - If no object for the given key can be found.

getString

public final String getString(int keyID,
                              Object arg0,
                              Object arg1,
                              Object arg2)
                       throws MissingResourceException
Gets a string for the given key are replace all occurence of "{0}", "{1}", with values of arg0, arg1, etc.

Parameters:
keyID - The key for the desired string.
arg0 - Value to substitute to "{0}".
arg1 - Value to substitute to "{1}".
arg2 - Value to substitute to "{2}".
Returns:
The formatted string for the given key.
Throws:
MissingResourceException - If no object for the given key can be found.

getString

public final String getString(int keyID,
                              Object arg0,
                              Object arg1,
                              Object arg2,
                              Object arg3)
                       throws MissingResourceException
Gets a string for the given key are replace all occurence of "{0}", "{1}", with values of arg0, arg1, etc.

Parameters:
keyID - The key for the desired string.
arg0 - Value to substitute to "{0}".
arg1 - Value to substitute to "{1}".
arg2 - Value to substitute to "{2}".
arg3 - Value to substitute to "{3}".
Returns:
The formatted string for the given key.
Throws:
MissingResourceException - If no object for the given key can be found.

getString

public final String getString(int keyID,
                              Object arg0,
                              Object arg1,
                              Object arg2,
                              Object arg3,
                              Object arg4)
                       throws MissingResourceException
Gets a string for the given key are replace all occurence of "{0}", "{1}", with values of arg0, arg1, etc.

Parameters:
keyID - The key for the desired string.
arg0 - Value to substitute to "{0}".
arg1 - Value to substitute to "{1}".
arg2 - Value to substitute to "{2}".
arg3 - Value to substitute to "{3}".
arg4 - Value to substitute to "{4}".
Returns:
The formatted string for the given key.
Throws:
MissingResourceException - If no object for the given key can be found.

toString

public String toString()
Returns a string representation of this object. This method is for debugging purpose only.

Overrides:
toString in class Object

deegree 2.1 (2007/11/08 09:57 build-328-official)

an open source project founded by lat/lon, Bonn, Germany.
For more information visit: http://deegree.sourceforge.net