Class 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 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
    • Constructor Detail

      • JRSingletonCache

        public JRSingletonCache​(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​(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
      • getContextInstanceCache

        protected Map<String,​T> getContextInstanceCache()
      • getContextKey

        protected Object getContextKey()