|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.ResourceBundle org.brains2b.resx.ExtResourceBundle
public class ExtResourceBundle
ResourceBundle that reads Bundles and domains from a database connection.
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.
Field Summary | |
---|---|
protected static java.sql.Connection |
m_con
|
protected java.lang.String |
m_domain
|
protected java.util.Locale |
m_locale
|
Fields inherited from class java.util.ResourceBundle |
---|
parent |
Constructor Summary | |
---|---|
ExtResourceBundle(java.lang.String baseName,
java.util.Locale locale)
Constructor for DatabaseBundle. |
Method Summary | |
---|---|
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. |
java.util.Enumeration |
getKeys()
|
java.util.Locale |
getLocale()
get the locale with which this resource bundle was created This implementation is contrary to ResourceBundle.getLocale() which returns the Locale of the resource bundle which was actually
used and could return the |
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)
|
protected void |
makeConnection()
Make a connection to the database The connection is default made using either: System.properties sql.driver the full classpath name of the driver sql.url the url to connect to the database sql.user the username with which to connect to the database sql.password the password to connect to the database or a properties.file in the root of the application named connection.properties in which the four above properties are defined. |
Methods inherited from class java.util.ResourceBundle |
---|
getBundle, getBundle, getBundle, getObject, getString, getStringArray, setParent |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.lang.String m_domain
protected java.util.Locale m_locale
protected static java.sql.Connection m_con
Constructor Detail |
---|
public ExtResourceBundle(java.lang.String baseName, java.util.Locale locale)
Method Detail |
---|
public static java.util.ResourceBundle getExtBundle(java.lang.String baseName)
baseName
- String, the Name of the Bundle/Domain
public static java.util.ResourceBundle getExtBundle(java.lang.String baseName, java.util.Locale locale)
baseName
- locale
-
protected static java.util.ResourceBundle getBundleImpl(ExtResourceBundle res)
res
- ExtResourceBundle
protected 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.ResourceBundle
ResourceBundle.handleGetObject(String)
public java.util.Enumeration getKeys()
getKeys
in class java.util.ResourceBundle
ResourceBundle.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 established
java.sql.SQLException
public 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()
protected java.sql.Connection getConnection() throws java.sql.SQLException
java.sql.SQLException,
- thrown if the connection to the database
fails
java.sql.SQLException
makeConnection()
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.ResourceBundle
ResourceBundle.getLocale()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |