Package net.sf.jasperreports.engine.util
Class JRSingletonCache<T>
- java.lang.Object
-
- net.sf.jasperreports.engine.util.JRSingletonCache<T>
-
public class JRSingletonCache<T> extends Object
Utility to use as a soft cache of singleton instances.- Author:
- Lucian Chirita (lucianc@users.sourceforge.net)
-
-
Field Summary
Fields Modifier and Type Field Description static String
EXCEPTION_MESSAGE_KEY_CLASS_NOT_COMPATIBLE
static String
EXCEPTION_MESSAGE_KEY_CLASS_NOT_FOUND
static String
EXCEPTION_MESSAGE_KEY_INSTANCE_ERROR
-
Constructor Summary
Constructors Constructor Description JRSingletonCache(Class<T> itf)
Creates a cache of singleton instances.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected T
createInstance(String className)
T
getCachedInstance(String className)
Returns the singleton instance corresponding to a class.protected Map<String,T>
getContextInstanceCache()
protected Object
getContextKey()
-
-
-
Field Detail
-
EXCEPTION_MESSAGE_KEY_CLASS_NOT_COMPATIBLE
public static final String EXCEPTION_MESSAGE_KEY_CLASS_NOT_COMPATIBLE
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_CLASS_NOT_FOUND
public static final String EXCEPTION_MESSAGE_KEY_CLASS_NOT_FOUND
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_INSTANCE_ERROR
public static final String EXCEPTION_MESSAGE_KEY_INSTANCE_ERROR
- See Also:
- Constant Field Values
-
-
Method Detail
-
getCachedInstance
public T getCachedInstance(String className) throws JRException
Returns the singleton instance corresponding to a class.The instance is first searched into the cache and created if not found.
The class is expected to have a no-argument constructor.
- Parameters:
className
-- Returns:
- the singleton instance corresponding to a class
- Throws:
JRException
-
createInstance
protected T createInstance(String className) throws JRException
- Throws:
JRException
-
getContextKey
protected Object getContextKey()
-
-