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 Details

    • EXCEPTION_MESSAGE_KEY_CLASS_NOT_COMPATIBLE

      public static final String EXCEPTION_MESSAGE_KEY_CLASS_NOT_COMPATIBLE
      See Also:
    • EXCEPTION_MESSAGE_KEY_CLASS_NOT_FOUND

      public static final String EXCEPTION_MESSAGE_KEY_CLASS_NOT_FOUND
      See Also:
    • EXCEPTION_MESSAGE_KEY_INSTANCE_ERROR

      public static final String EXCEPTION_MESSAGE_KEY_INSTANCE_ERROR
      See Also:
  • Constructor Details

    • 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 Details

    • 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
    • getContextInstanceCache

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

      protected Object getContextKey()