Class JRVirtualizationContext

java.lang.Object
net.sf.jasperreports.engine.fill.JRVirtualizationContext
All Implemented Interfaces:
Serializable, VirtualizationListener<VirtualElementsData>

public class JRVirtualizationContext extends Object implements Serializable, VirtualizationListener<VirtualElementsData>
Context used to store data shared by virtualized objects resulted from a report fill process.
Author:
Lucian Chirita (lucianc@users.sourceforge.net)
See Also:
  • Field Details

    • EXCEPTION_MESSAGE_KEY_LOCKING_INTERRUPTED

      public static final String EXCEPTION_MESSAGE_KEY_LOCKING_INTERRUPTED
      See Also:
    • EXCEPTION_MESSAGE_KEY_RENDERER_NOT_FOUND_IN_CONTEXT

      public static final String EXCEPTION_MESSAGE_KEY_RENDERER_NOT_FOUND_IN_CONTEXT
      See Also:
    • EXCEPTION_MESSAGE_KEY_TEMPLATE_NOT_FOUND_IN_CONTEXT

      public static final String EXCEPTION_MESSAGE_KEY_TEMPLATE_NOT_FOUND_IN_CONTEXT
      See Also:
  • Constructor Details

    • JRVirtualizationContext

      public JRVirtualizationContext(JasperReportsContext jasperReportsContext)
      Constructs a context.
    • JRVirtualizationContext

      protected JRVirtualizationContext(JRVirtualizationContext parentContext)
  • Method Details

    • addListener

      public void addListener(VirtualizationListener<VirtualElementsData> listener)
      Adds a virtualization listener.
      Parameters:
      listener -
    • removeListener

      public void removeListener(VirtualizationListener<VirtualElementsData> listener)
      Remove a virtualization listener.
      Parameters:
      listener -
    • beforeExternalization

      public void beforeExternalization(JRVirtualizable<VirtualElementsData> object)
      Description copied from interface: VirtualizationListener
      Called before an object's data is externalized.
      Specified by:
      beforeExternalization in interface VirtualizationListener<VirtualElementsData>
      Parameters:
      object -
      See Also:
    • afterExternalization

      public void afterExternalization(JRVirtualizable<VirtualElementsData> object)
    • afterInternalization

      public void afterInternalization(JRVirtualizable<VirtualElementsData> object)
      Description copied from interface: VirtualizationListener
      Called after an object's data was made available to the object.
      Specified by:
      afterInternalization in interface VirtualizationListener<VirtualElementsData>
      Parameters:
      object -
      See Also:
    • cacheRenderer

      public void cacheRenderer(Renderable renderer)
      Caches an image renderer.
      Parameters:
      renderer - the image whose renderer should be cached
    • getCachedRenderer

      public Renderable getCachedRenderer(String id)
      Retrieves a cached image renderer based on an ID.
      Parameters:
      id - the ID
      Returns:
      the cached image renderer for the ID
    • hasCachedRenderer

      public boolean hasCachedRenderer(String id)
      Determines whether a cached image renderer for a specified ID exists.
      Parameters:
      id - the ID
      Returns:
      true if and only if the context contains a cached renderer with the specified ID
    • hasCachedTemplate

      public boolean hasCachedTemplate(String id)
      Determines whether a cached template with a specified ID exists.
      Parameters:
      id - the template ID
      Returns:
      true if and only if the context contains a cached template with the specified ID
    • cacheTemplate

      public void cacheTemplate(JRTemplateElement template)
      Caches an element template.
      Parameters:
      template - the template to cache
    • getCachedTemplate

      public JRTemplateElement getCachedTemplate(String templateId)
      Retrieves a cached template.
      Parameters:
      templateId - the template ID
      Returns:
      the cached template having the given ID
    • cacheTemplate

      public void cacheTemplate(JRPrintElement element)
      Caches the template of an element.
      Parameters:
      element - the element whose template to cache
    • isReadOnly

      public boolean isReadOnly()
      Determines whether this context has been marked as read-only.
      Returns:
      whether this context has been marked as read-only
      See Also:
    • setReadOnly

      public void setReadOnly(boolean readOnly)
      Sets the read-only flag for this context.

      When in read-only mode, all the virtualizable objects belonging to this context are assumed final by the virtualizer and any change in a virtualizable object's data would be discarded on virtualization.

      Parameters:
      readOnly - the read-only flag
    • register

      public static void register(JRVirtualizationContext context, JasperPrint print)
      Registers a virtualization context for JasperPrint object.
      Parameters:
      context - the virtualization context
      print - the print object
    • getRegistered

      public static JRVirtualizationContext getRegistered(JasperPrint print)
      Returns the virtualization context registered for a print object.

      When the engine fills a report using a virtualizer, it registers the virtualization context with the generated JasperPrint object so that the caller would be able to retrieve the context based on the returned print object.

      Parameters:
      print - a print object
      Returns:
      the virtualization context registered for the print object, or null if no context has been registered
    • getPageElementSize

      public int getPageElementSize()
      Returns the virtual page size used by the report.
      Returns:
      the virtual page size used by the report
      See Also:
    • setPageElementSize

      public void setPageElementSize(int pageElementSize)
      Set the virtual page size used by the report.
      Parameters:
      pageElementSize - the virtual page size
      See Also:
    • getVirtualizer

      public JRVirtualizer getVirtualizer()
      Returns the virtualizer used by this context.
    • setVirtualizer

      public void setVirtualizer(JRVirtualizer virtualizer)
    • traverseDeepElements

      protected void traverseDeepElements(PrintElementVisitor<Void> visitor, Collection<? extends JRPrintElement> elements)
      Traverses all the elements on the page, including the ones placed inside frames.
      Parameters:
      visitor - element visitor
    • replaceSerializedObject

      public Object replaceSerializedObject(Object obj)
    • resolveSerializedObject

      public Object resolveSerializedObject(Object obj)
    • lock

      public void lock()
      Acquires a lock on this context.
    • tryLock

      public boolean tryLock()
      Attempts to acquire a lock on this context.
      Returns:
      true iff the lock was acquired on the context
    • unlock

      public void unlock()
      Releases the lock previously acquired on this context.
    • dispose

      public void dispose()
      Marks this context as disposed in order to instruct the virtualizer that pages owned by this context are no longer used.
    • isDisposed

      public boolean isDisposed()
      Determines if this context is marked as disposed.
      Returns:
      whether this context has been marked as disposed
    • getMasterContext

      public JRVirtualizationContext getMasterContext()
    • getCachedRenderers

      public Map<String,Renderable> getCachedRenderers()
    • getCachedTemplates

      public Map<String,JRTemplateElement> getCachedTemplates()
    • getFramesContext

      public JRVirtualizationContext getFramesContext()
    • getVirtualizableLists

      public Map<PrintElementId,VirtualizableElementList> getVirtualizableLists()
    • cacheVirtualizableList

      public void cacheVirtualizableList(PrintElementId id, VirtualizableElementList virtualizableList)
    • getVirtualizableList

      public VirtualizableElementList getVirtualizableList(PrintElementId id)
    • updateParent

      public void updateParent(JRVirtualizationContext destinationContext)
    • getJasperReportsContext

      public JasperReportsContext getJasperReportsContext()