Package net.sf.jasperreports.engine.util
Class JRSingletonCache<T>
- java.lang.Object
-
- net.sf.jasperreports.engine.util.JRSingletonCache<T>
-
public class JRSingletonCache<T> extends java.lang.ObjectUtility 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 java.lang.StringEXCEPTION_MESSAGE_KEY_CLASS_NOT_COMPATIBLEstatic java.lang.StringEXCEPTION_MESSAGE_KEY_CLASS_NOT_FOUNDstatic java.lang.StringEXCEPTION_MESSAGE_KEY_INSTANCE_ERROR
-
Constructor Summary
Constructors Constructor Description JRSingletonCache(java.lang.Class<T> itf)Creates a cache of singleton instances.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected TcreateInstance(java.lang.String className)TgetCachedInstance(java.lang.String className)Returns the singleton instance corresponding to a class.protected java.util.Map<java.lang.String,T>getContextInstanceCache()protected java.lang.ObjectgetContextKey()
-
-
-
Field Detail
-
EXCEPTION_MESSAGE_KEY_CLASS_NOT_COMPATIBLE
public static final java.lang.String EXCEPTION_MESSAGE_KEY_CLASS_NOT_COMPATIBLE
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_CLASS_NOT_FOUND
public static final java.lang.String EXCEPTION_MESSAGE_KEY_CLASS_NOT_FOUND
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_INSTANCE_ERROR
public static final java.lang.String EXCEPTION_MESSAGE_KEY_INSTANCE_ERROR
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JRSingletonCache
public JRSingletonCache(java.lang.Class<T> itf)
Creates a cache of singleton instances.- Parameters:
itf- a interface or class that should be implemented by all classes cached by this object
-
-
Method Detail
-
getCachedInstance
public T getCachedInstance(java.lang.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(java.lang.String className) throws JRException
- Throws:
JRException
-
getContextInstanceCache
protected java.util.Map<java.lang.String,T> getContextInstanceCache()
-
getContextKey
protected java.lang.Object getContextKey()
-
-