org.apache.commons.resources.impl
Class JDBCResources

java.lang.Object
  extended by org.apache.commons.resources.impl.ResourcesBase
      extended by org.apache.commons.resources.impl.CollectionResourcesBase
          extended by org.apache.commons.resources.impl.JDBCResources
All Implemented Interfaces:
Serializable, Resources

public class JDBCResources
extends CollectionResourcesBase

Concrete implementation of Resources that retrieves message key value pairs using JDBC. For this specific implementation, database connection properties and Locale for which the document's messages apply are specified via property files. Resources are looked up in a hierarchy of database values in a manner identical to that performed by java.util.ResourceBundle.getBundle()..

The base URL passed to our constructor must contain the base name of a properties file that holds the JDBC datasource configuration.

The expected format of the required properties file might look like this:

 jdbc.connect.driver               = org.gjt.mm.mysql.Driver
 jdbc.connect.url                  = jdbc:mysql://localhost/resources
 jdbc.connect.login                = resourcesTest
 jdbc.connect.password             = resourcesTest
 
 jdbc.sql.db                       = resources
 jdbc.sql.table                    = resources
 jdbc.sql.locale.column            = locale
 jdbc.sql.key.column               = msgKey
 jdbc.sql.val.column               = val
 
 org.apache.commons.resource.CACHE = true
 
 

Version:
$Revision: 354539 $ $Date: 2005-12-06 20:40:16 +0000 (Tue, 06 Dec 2005) $
Author:
James Mitchell
See Also:
Serialized Form

Constructor Summary
JDBCResources(String name, String base)
          Create a new Resources instance with the specified logical name and base resource URL.
 
Method Summary
protected  Map getLocaleMap(String baseUrl, Locale locale)
          Return a Map containing the name-value mappings for the specified base URL and requested Locale, if there are any.
 
Methods inherited from class org.apache.commons.resources.impl.CollectionResourcesBase
destroy, getDefaultLocale, getKeys, getLocaleList, getLocaleMap, getLocaleSuffix, getObject, setDefaultLocale
 
Methods inherited from class org.apache.commons.resources.impl.ResourcesBase
getBufferSize, getBytes, getInputStream, getName, getReader, getString, init, isReturnNull, setBufferSize, setReturnNull
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDBCResources

public JDBCResources(String name,
                     String base)

Create a new Resources instance with the specified logical name and base resource URL.

Parameters:
name - Logical name of the new instance
base - Base URL of the JDBC configuration properties.
Method Detail

getLocaleMap

protected Map getLocaleMap(String baseUrl,
                           Locale locale)

Return a Map containing the name-value mappings for the specified base URL and requested Locale, if there are any. If there are no defined mappings for the specified Locale, return an empty Map instead.

Concrete subclasses must override this method to perform the appropriate lookup. A typical implementation will construct an absolute URL based on the specified base URL and Locale, retrieve the specified resource file (if any), and parse it into a Map structure.

Caching of previously retrieved Maps (if any) should be performed by callers of this method. Therefore, this method should always attempt to retrieve the specified resource and load it appropriately.

Specified by:
getLocaleMap in class CollectionResourcesBase
Parameters:
baseUrl - Base URL of the resource files for this Resources instance
locale - Locale for which name-value mappings are requested
Returns:
A name-value Map for the specified URL and locale.


Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.