public class ExtResourceBundle
extends java.util.ResourceBundle
This is a partial rewrite of ResourceBundle to implement a type of resourcebundle next to List and Properties to take advantage of a database connection.
It does this by implicitly using properties to create a connection to a database and then lazily retrieving the information into a Hashtable.
For reasons of expedience there will be sought first for a regular ResourceBundle and only then for a database bundle. This to allow for using the faster ListResourceBundle for default Locales and a slower database connection for more uncommen Locales.
The expected table can be any table, but by default is called LOCALIZED_RESOURCE. It has a fields for the bundleName or Domain, Key, Value, Country and Language. You can overwrite getSQL to use your own table.Please make sure that the SQL statement has as first column the key and as second the value. There are no other restrictions that I'm aware of.
Due to the finalizing of the getBundle() methods it was not possible to implement it without creating new static methods getExtBundle() Needless to say the getBundle() methods will not retrieve any bundles from the database.
| Modifier and Type | Field and Description |
|---|---|
protected static java.sql.Connection |
m_con |
protected java.util.HashMap |
m_contents |
protected java.lang.String |
m_domain |
protected java.util.Locale |
m_locale |
| Constructor and Description |
|---|
ExtResourceBundle(java.lang.String baseName,
java.util.Locale locale)
Constructor for DatabaseBundle.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
clear()
clear cache
|
boolean |
containsKey(java.lang.String key) |
java.util.Map |
getAllContents() |
java.lang.String |
getBaseName()
get the base name of this resource bundle
|
protected static java.util.ResourceBundle |
getBundleImpl(ExtResourceBundle res)
Method getBundleImpl.
|
protected java.sql.Connection |
getConnection()
get the connection to the database from which to collect the resources
|
protected java.util.HashMap |
getContents()
get the content of this resource bundle as a hashtable
|
static java.util.ResourceBundle |
getExtBundle(java.lang.String baseName)
Method getExtBundle.
|
static java.util.ResourceBundle |
getExtBundle(java.lang.String baseName,
java.util.Locale locale)
Method getExtBundle.
|
static java.util.ResourceBundle |
getExtBundle(java.lang.String baseName,
java.util.Locale locale,
java.sql.Connection con)
Method getExtBundle.
|
java.util.Enumeration |
getKeys() |
java.util.Locale |
getLocale()
get the locale with which this resource bundle was created
|
protected java.util.ResourceBundle |
getParent()
get the parent of this resource bundle.
|
java.lang.String |
getSQL()
Method getSQL.
|
protected java.lang.Object |
handleGetObject(java.lang.String key) |
java.util.Set<java.lang.String> |
keySet() |
protected void |
makeConnection()
Make a connection to the database
|
protected java.util.HashMap m_contents
protected java.lang.String m_domain
protected java.util.Locale m_locale
protected static java.sql.Connection m_con
public ExtResourceBundle(java.lang.String baseName,
java.util.Locale locale)
public static java.util.ResourceBundle getExtBundle(java.lang.String baseName)
baseName - String, the Name of the Bundle/Domainpublic static java.util.ResourceBundle getExtBundle(java.lang.String baseName,
java.util.Locale locale)
baseName - locale - public static java.util.ResourceBundle getExtBundle(java.lang.String baseName,
java.util.Locale locale,
java.sql.Connection con)
baseName - locale - protected static java.util.ResourceBundle getBundleImpl(ExtResourceBundle res)
res - ExtResourceBundleprotected java.util.ResourceBundle getParent()
A parent of a resource bundle can be defined
as a less Locale specific resource bundle: en
is the parent of en_GB and has the empy locale
as its owner parent.
protected java.lang.Object handleGetObject(java.lang.String key)
handleGetObject in class java.util.ResourceBundleResourceBundle.handleGetObject(String)public java.util.Enumeration getKeys()
getKeys in class java.util.ResourceBundleResourceBundle.getKeys()protected void makeConnection()
throws java.sql.SQLException
The connection is default made using either:
or a properties.file in the root of the application named connection.properties in which the four above properties are defined.
Overwrite if you want to use another way of getting a connection
SQLException, - in the event a connection could not be establishedjava.sql.SQLExceptionpublic java.lang.String getSQL()
Composes the default query for getting values from a LOCALIZED_RESOURCE table. The query should be defined to get all values from a given base/domain, language and country at once
The lengths are not specified, so you can use your own create scripts are however provided for this table in the projects package
Overwrite if you want to use another table
protected java.util.HashMap getContents()
public java.util.Map getAllContents()
protected java.sql.Connection getConnection()
throws java.sql.SQLException
java.sql.SQLException, - thrown if the connection to the database
failsjava.sql.SQLExceptionmakeConnection()public java.lang.String getBaseName()
public java.util.Locale getLocale()
This implementation is contrary to ResourceBundle.getLocale() which
returns the Locale of the resource bundle which was actually
used and could return the
getLocale in class java.util.ResourceBundleResourceBundle.getLocale()public static void clear()
public boolean containsKey(java.lang.String key)
containsKey in class java.util.ResourceBundlepublic java.util.Set<java.lang.String> keySet()
keySet in class java.util.ResourceBundle