net.sf.jasperreports.engine.fill
Class JRVirtualizationContext

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

public class JRVirtualizationContext
extends java.lang.Object
implements java.io.Serializable, VirtualizationListener<VirtualElementsData>

Context used to store data shared by virtualized objects resulted from a report fill process.

Version:
$Id: JRVirtualizationContext.java 5180 2012-03-29 13:23:12Z teodord $
Author:
Lucian Chirita (lucianc@users.sourceforge.net)
See Also:
Serialized Form

Constructor Summary
  JRVirtualizationContext(JasperReportsContext jasperReportsContext)
          Constructs a context.
protected JRVirtualizationContext(JRVirtualizationContext parentContext)
           
 
Method Summary
 void addListener(VirtualizationListener<VirtualElementsData> listener)
          Adds a virtualization listener.
 void afterExternalization(JRVirtualizable<VirtualElementsData> object)
           
 void afterInternalization(JRVirtualizable<VirtualElementsData> object)
          Called after an object's data was made available to the object.
 void beforeExternalization(JRVirtualizable<VirtualElementsData> object)
          Called before an object's data is externalized.
 void cacheRenderer(JRPrintImage image)
          Caches an image renderer.
 void cacheTemplate(JRPrintElement element)
          Caches the template of an element.
 void cacheTemplate(JRTemplateElement template)
          Caches an element template.
 void dispose()
          Marks this context as disposed in order to instruct the virtualizer that pages owned by this context are no longer used.
 Renderable getCachedRenderer(java.lang.String id)
          Retrieves a cached image renderer based on an ID.
 JRTemplateElement getCachedTemplate(java.lang.String templateId)
          Retrieves a cached template.
 int getPageElementSize()
          Returns the virtual page size used by the report.
static JRVirtualizationContext getRegistered(JasperPrint print)
          Returns the virtualization context registered for a print object.
 JRVirtualizer getVirtualizer()
          Returns the virtualizer used by this context.
 boolean hasCachedRenderer(java.lang.String id)
          Determines whether a cached image renderer for a specified ID exists.
 boolean hasCachedTemplate(java.lang.String id)
          Determines whether a cached template with a specified ID exists.
 boolean isDisposed()
          Determines if this context is marked as disposed.
 boolean isReadOnly()
          Determines whether this context has been marked as read-only.
 void lock()
          Acquires a lock on this context.
static void register(JRVirtualizationContext context, JasperPrint print)
          Registers a virtualization context for JasperPrint object.
 void removeListener(VirtualizationListener<VirtualElementsData> listener)
          Remove a virtualization listener.
 java.lang.Object replaceSerializedObject(java.lang.Object obj)
           
 java.lang.Object resolveSerializedObject(java.lang.Object obj)
           
 void setPageElementSize(int pageElementSize)
          Set the virtual page size used by the report.
 void setReadOnly(boolean readOnly)
          Sets the read-only flag for this context.
protected  void setVirtualizer(JRVirtualizer virtualizer)
           
protected  void traverseDeepElements(PrintElementVisitor<java.lang.Void> visitor, java.util.Collection<? extends JRPrintElement> elements)
          Traverses all the elements on the page, including the ones placed inside frames.
 boolean tryLock()
          Attempts to acquire a lock on this context.
 void unlock()
          Releases the lock previously acquired on this context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JRVirtualizationContext

public JRVirtualizationContext(JasperReportsContext jasperReportsContext)
Constructs a context.


JRVirtualizationContext

protected JRVirtualizationContext(JRVirtualizationContext parentContext)
Method Detail

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>
See Also:
JRVirtualizable.beforeExternalization()

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>
See Also:
JRVirtualizable.afterInternalization()

cacheRenderer

public void cacheRenderer(JRPrintImage image)
Caches an image renderer.

Parameters:
image - the image whose renderer should be cached

getCachedRenderer

public Renderable getCachedRenderer(java.lang.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(java.lang.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(java.lang.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(java.lang.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(boolean)

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:
JRVirtualPrintPage.PROPERTY_VIRTUAL_PAGE_ELEMENT_SIZE

setPageElementSize

public void setPageElementSize(int pageElementSize)
Set the virtual page size used by the report.

Parameters:
pageElementSize - the virtual page size
See Also:
JRVirtualPrintPage.PROPERTY_VIRTUAL_PAGE_ELEMENT_SIZE

getVirtualizer

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


setVirtualizer

protected void setVirtualizer(JRVirtualizer virtualizer)

traverseDeepElements

protected void traverseDeepElements(PrintElementVisitor<java.lang.Void> visitor,
                                    java.util.Collection<? extends JRPrintElement> elements)
Traverses all the elements on the page, including the ones placed inside frames.

Parameters:
visitor - element visitor

replaceSerializedObject

public java.lang.Object replaceSerializedObject(java.lang.Object obj)

resolveSerializedObject

public java.lang.Object resolveSerializedObject(java.lang.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


© 2001-2010 Jaspersoft Corporation www.jaspersoft.com