Package net.sf.jasperreports.engine.fill
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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
EXCEPTION_MESSAGE_KEY_LOCKING_INTERRUPTED
static String
EXCEPTION_MESSAGE_KEY_RENDERER_NOT_FOUND_IN_CONTEXT
static String
EXCEPTION_MESSAGE_KEY_TEMPLATE_NOT_FOUND_IN_CONTEXT
-
Constructor Summary
Constructors Modifier Constructor Description protected
JRVirtualizationContext(JRVirtualizationContext parentContext)
JRVirtualizationContext(JasperReportsContext jasperReportsContext)
Constructs a context.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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(Renderable renderer)
Caches an image renderer.void
cacheTemplate(JRTemplateElement template)
Caches an element template.void
cacheTemplate(JRPrintElement element)
Caches the template of an element.void
cacheVirtualizableList(PrintElementId id, VirtualizableElementList virtualizableList)
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(String id)
Retrieves a cached image renderer based on an ID.Map<String,Renderable>
getCachedRenderers()
JRTemplateElement
getCachedTemplate(String templateId)
Retrieves a cached template.Map<String,JRTemplateElement>
getCachedTemplates()
JRVirtualizationContext
getFramesContext()
JasperReportsContext
getJasperReportsContext()
JRVirtualizationContext
getMasterContext()
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.VirtualizableElementList
getVirtualizableList(PrintElementId id)
Map<PrintElementId,VirtualizableElementList>
getVirtualizableLists()
JRVirtualizer
getVirtualizer()
Returns the virtualizer used by this context.boolean
hasCachedRenderer(String id)
Determines whether a cached image renderer for a specified ID exists.boolean
hasCachedTemplate(String id)
Determines whether a cachedtemplate
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 forJasperPrint
object.void
removeListener(VirtualizationListener<VirtualElementsData> listener)
Remove a virtualization listener.Object
replaceSerializedObject(Object obj)
Object
resolveSerializedObject(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.void
setVirtualizer(JRVirtualizer virtualizer)
protected void
traverseDeepElements(PrintElementVisitor<Void> visitor, Collection<? extends JRPrintElement> elements)
Traverses all the elements on the page, including the ones placed insideframes
.boolean
tryLock()
Attempts to acquire a lock on this context.void
unlock()
Releases the lock previously acquired on this context.void
updateParent(JRVirtualizationContext destinationContext)
-
-
-
Field Detail
-
EXCEPTION_MESSAGE_KEY_LOCKING_INTERRUPTED
public static final String EXCEPTION_MESSAGE_KEY_LOCKING_INTERRUPTED
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_RENDERER_NOT_FOUND_IN_CONTEXT
public static final String EXCEPTION_MESSAGE_KEY_RENDERER_NOT_FOUND_IN_CONTEXT
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_TEMPLATE_NOT_FOUND_IN_CONTEXT
public static final String EXCEPTION_MESSAGE_KEY_TEMPLATE_NOT_FOUND_IN_CONTEXT
- See Also:
- Constant Field Values
-
-
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 interfaceVirtualizationListener<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 interfaceVirtualizationListener<VirtualElementsData>
- See Also:
JRVirtualizable.afterInternalization()
-
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 cachedtemplate
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(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 forJasperPrint
object.- Parameters:
context
- the virtualization contextprint
- 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 generatedJasperPrint
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
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 insideframes
.- Parameters:
visitor
- element visitor
-
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()
-
-