Package de.businesscode.bcdui.toolbox
Class Configuration
- java.lang.Object
-
- de.businesscode.bcdui.toolbox.Configuration
-
- All Implemented Interfaces:
ConfigurationProvider
public class Configuration extends java.lang.Object implements ConfigurationProvider
This class extends theJNDIProvider
and offers a common API to retrieve configuration parameter from JNDI context as specified by servlet spec, furthermore this class cascades the configuration viaDbProperties
allowing to manage dynamic properties from database. all API refer to "server" scope in sense ofDbProperties
scope, except ofgetClientParameters()
which provides "client" scope configuration from database.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Configuration.OPT_CLASSES
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CONFIG_DB_RELOAD_SEC
static java.lang.String
CONFIG_FILE_PATH_KEY
static java.lang.String
DEFAULT_DB_CONTEXT_ID
static java.lang.String
DISABLE_CACHE
static java.lang.String
VFS_CATALOG_KEY
-
Constructor Summary
Constructors Modifier Constructor Description protected
Configuration()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> void
addConfigurationParameter(java.lang.String id, T value)
void
closeAllConnections(boolean rollback)
static <T> T
getClassInstance(Configuration.OPT_CLASSES name, java.lang.Class<?>[] types, java.lang.Object... params)
likegetClassoption(OPT_CLASSES)
but looks for public constructor accepting given types and instantiates the class, with given params in case a class is not found this method returns null, in case a class is found but a constructor is missing, this method throws an exception.static <T> T
getClassInstance(java.lang.Class<?> clazz, java.lang.Class<?>[] types, java.lang.Object... params)
Looks for a public constructor accepting given types and instantiates the class, with given params. in case a class a constructor is missing, this method throws an exception.static java.lang.Class<?>
getClassoption(Configuration.OPT_CLASSES name)
Returns for a given token Configuration.OPT_CLASSES the 'best' class, or null if none 'Best' means the one with the highest priority according to optionalClassesPrio found in classpath Can be switched to CDI, once available on all platformsjava.util.HashMap<java.lang.String,java.lang.Object>
getClientParameters()
retrieve client propertiesjava.lang.Object
getConfigurationParameter(java.lang.String id)
retrieve a (mandatory) parameter or throw exception, also seeConfigurationProvider.getConfigurationParameterOrNull(String)
<T> T
getConfigurationParameter(java.lang.String id, T defaultValue)
getter for configuration parameter including downcastjava.lang.Object
getConfigurationParameterOrNull(java.lang.String id)
retrieve parameterstatic Configuration
getInstance()
java.sql.Connection
getManagedConnection(java.lang.String dbSourceName)
java.sql.Connection
getManagedConnection(java.lang.String dbSourceName, boolean closedByRequestLifeCycleFilter)
java.sql.Connection
getUnmanagedConnection(java.lang.String dbSourceName)
javax.sql.DataSource
getUnmanagedDataSource(java.lang.String dbSourceName)
convenience getter forgetUnmanagedDataSource(String)
static boolean
isCacheDisabled()
-
-
-
Field Detail
-
CONFIG_FILE_PATH_KEY
public static final java.lang.String CONFIG_FILE_PATH_KEY
- See Also:
- Constant Field Values
-
DISABLE_CACHE
public static final java.lang.String DISABLE_CACHE
- See Also:
- Constant Field Values
-
VFS_CATALOG_KEY
public static final java.lang.String VFS_CATALOG_KEY
- See Also:
- Constant Field Values
-
CONFIG_DB_RELOAD_SEC
public static final java.lang.String CONFIG_DB_RELOAD_SEC
- See Also:
- Constant Field Values
-
DEFAULT_DB_CONTEXT_ID
public static final java.lang.String DEFAULT_DB_CONTEXT_ID
- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static Configuration getInstance()
-
getConfigurationParameter
public java.lang.Object getConfigurationParameter(java.lang.String id)
Description copied from interface:ConfigurationProvider
retrieve a (mandatory) parameter or throw exception, also seeConfigurationProvider.getConfigurationParameterOrNull(String)
- Specified by:
getConfigurationParameter
in interfaceConfigurationProvider
- Returns:
- configuration parameter instance
-
getConfigurationParameter
public <T> T getConfigurationParameter(java.lang.String id, T defaultValue)
Description copied from interface:ConfigurationProvider
getter for configuration parameter including downcast- Specified by:
getConfigurationParameter
in interfaceConfigurationProvider
- Returns:
- configuration parameter instance or defaultValue
-
getConfigurationParameterOrNull
public java.lang.Object getConfigurationParameterOrNull(java.lang.String id)
Description copied from interface:ConfigurationProvider
retrieve parameter- Specified by:
getConfigurationParameterOrNull
in interfaceConfigurationProvider
- Returns:
- configuration parameter instance or NULL
-
getClientParameters
public java.util.HashMap<java.lang.String,java.lang.Object> getClientParameters()
retrieve client properties- Returns:
- client properties OR null in case no are specified or DbProperties is not available
-
isCacheDisabled
public static boolean isCacheDisabled()
- Returns:
-
getManagedConnection
public java.sql.Connection getManagedConnection(java.lang.String dbSourceName) throws java.lang.Exception
- Parameters:
dbSourceName
-- Returns:
- Throws:
java.lang.Exception
-
getManagedConnection
public java.sql.Connection getManagedConnection(java.lang.String dbSourceName, boolean closedByRequestLifeCycleFilter) throws java.lang.Exception
- Parameters:
dbSourceName
-- Returns:
- Throws:
java.lang.Exception
-
getUnmanagedConnection
public java.sql.Connection getUnmanagedConnection(java.lang.String dbSourceName) throws java.lang.Exception
- Parameters:
dbSourceName
-- Returns:
- Throws:
java.lang.Exception
-
addConfigurationParameter
public <T> void addConfigurationParameter(java.lang.String id, T value)
- Parameters:
id
-value
-
-
closeAllConnections
public void closeAllConnections(boolean rollback) throws java.sql.SQLException
- Parameters:
rollback
-- Throws:
java.sql.SQLException
-
getUnmanagedDataSource
public javax.sql.DataSource getUnmanagedDataSource(java.lang.String dbSourceName) throws java.lang.Exception
convenience getter forgetUnmanagedDataSource(String)
- Parameters:
dbSourceName
-- Returns:
- see
getUnmanagedDataSource(String)
- Throws:
java.lang.Exception
-
getClassoption
public static java.lang.Class<?> getClassoption(Configuration.OPT_CLASSES name)
Returns for a given token Configuration.OPT_CLASSES the 'best' class, or null if none 'Best' means the one with the highest priority according to optionalClassesPrio found in classpath Can be switched to CDI, once available on all platforms- Parameters:
name
-- Returns:
-
getClassInstance
public static <T> T getClassInstance(Configuration.OPT_CLASSES name, java.lang.Class<?>[] types, java.lang.Object... params) throws java.lang.RuntimeException
likegetClassoption(OPT_CLASSES)
but looks for public constructor accepting given types and instantiates the class, with given params in case a class is not found this method returns null, in case a class is found but a constructor is missing, this method throws an exception.- Parameters:
name
- of class bindingtypes
- to be accepted by constructorparams
- the params in exact order as types- Returns:
- the instance of matched class or null in case no such class could be found
- Throws:
java.lang.RuntimeException
- in case the class is missing a constructor accepting given parameters or if the instantiation fails
-
getClassInstance
public static <T> T getClassInstance(java.lang.Class<?> clazz, java.lang.Class<?>[] types, java.lang.Object... params) throws java.lang.RuntimeException
Looks for a public constructor accepting given types and instantiates the class, with given params. in case a class a constructor is missing, this method throws an exception.- Parameters:
clazz
- to instantiatetypes
- to be accepted by constructorparams
- the params in exact order as types- Returns:
- the instance of matched class
- Throws:
java.lang.RuntimeException
- in case the class is missing a constructor accepting given parameters or if the instantiation fails
-
-