Class Element
- java.lang.Object
-
- org.pentaho.reporting.engine.classic.core.Element
-
- All Implemented Interfaces:
Serializable
,Cloneable
,DataTarget
,ReportElement
- Direct Known Subclasses:
CrosstabTableCell
,Section
public class Element extends Object implements DataTarget, ReportElement
Base class for all report elements (displays items that can appear within a report band). Elements can either be Bands (which are container classes that group elements) or content-elements. All elements can have a name and have a private style sheet defined. The style sheet is used to store and access all element properties that can be used to control the layout of the element or affect the elements appearance in the generated content. Elements can inherit all style information from its parent. A style value is inherited whenever the element's stylesheet does not define an own value for the corresponding key. Some style-keys cannot be inherited at all, in that case the default-style-sheets value is used as fall-back value. In addition to the bands stylesheet, elements may also inherit from stylesheets assigned to the current report definition's StyleSheetCollection. Foreign stylesheet will be lost after the local cloning is complete. All Style-computation is done outside of the element using one of the style-resolver implementations.- Author:
- David Gilbert, Thomas Morgner
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
ANONYMOUS_ELEMENT_PREFIX
The internal constant to mark anonymous element names.
-
Constructor Summary
Constructors Modifier Constructor Description Element()
Constructs an element.protected
Element(InstanceID id)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Element
clone()
Clones this Element, the datasource and the private stylesheet of this Element.void
copyAttributes(ReportAttributeMap<Object> attributes)
void
copyInto(Element target)
Element
derive()
Element
derive(boolean preserveElementInstanceIds)
Creates a deep copy of this element and regenerates all instance-ids.Object
getAttribute(String namespace, String name)
Expression
getAttributeExpression(String namespace, String name)
Returns the attribute expression for the given attribute identified by its namespace and attribute name.String[]
getAttributeExpressionNames(String name)
Returns the names of all attributes for the given namespace that have attribute-expressions assigned.String[]
getAttributeExpressionNamespaces()
Returns the namespaces of all attributes that have attribute-expressions assigned.ReportAttributeMap<Expression>
getAttributeExpressions()
String[]
getAttributeNames(String namespace)
String[]
getAttributeNamespaces()
ReportAttributeMap<Object>
getAttributes()
Returns the attributes of the element as unmodifable collection.<TS> TS
getAttributeTyped(String namespace, String attribute, Class<TS> filter)
long
getChangeTracker()
Returns the element's change-tracker.ReportElement
getChildElementByType(ElementType type)
ReportElement[]
getChildElementsByName(String name)
ReportElement[]
getChildElementsByType(ElementType type)
SimpleStyleSheet
getComputedStyle()
org.pentaho.reporting.libraries.resourceloader.ResourceKey
getContentBase()
DataSource
getDataSource()
Deprecated.Whereever possible use ElementType implementations instead.ElementStyleSheet
getDefaultStyleSheet()
Creates the global stylesheet for this element type.org.pentaho.reporting.libraries.resourceloader.ResourceKey
getDefinitionSource()
Returns the resource-key of the file that defined this element.<T> T
getElementContext(Class<T> contextType)
ElementType
getElementType()
String
getElementTypeName()
Object
getFirstAttribute(String localName)
String
getHRefTarget()
Returns the currently set link target for this element.String
getId()
Returns the Xml-ID of this element.ReportDefinition
getMasterReport()
Returns the master-report element.ElementMetaData
getMetaData()
String
getName()
Returns the name of the Element.InstanceID
getObjectID()
Returns a unique identifier for the given instance.Band
getParent()
Return the parent of the Element.Section
getParentSection()
ReportDefinition
getReportDefinition()
Returns the currently assigned report definition.ElementStyleSheet
getStyle()
Returns this elements private stylesheet.Expression
getStyleExpression(StyleKey property)
Returns the expressions for the report.Map<StyleKey,Expression>
getStyleExpressions()
Returns a map of all style expressions attached to this element.Object
getTreeLock()
Returns the tree lock object for the self tree.boolean
isDynamicContent()
Checks whether the layout of this element is dynamic and adjusts to the element's printable content.boolean
isVisible()
Defines whether this Element should be painted.protected void
notifyElement()
void
notifyNodeChildAdded(Object o)
Notifies the element and any parent element that a child node has been added.void
notifyNodeChildRemoved(Object o)
Notifies the element and any parent element that a child node has been removed.void
notifyNodePropertiesChanged()
Notifies the element and any parent element that a property of this element has changed.void
notifyNodePropertiesChanged(Object parameter)
void
notifyNodeStructureChanged()
Notifies the element and any parent element that the structure of this element has changed in some undisclosed way.void
setAttribute(String namespace, String name, Object value)
Defines a attribute's static value.void
setAttribute(String namespace, String name, Object value, boolean notifyChange)
void
setAttributeExpression(String namespace, String name, Expression value)
Assigns a new attribute expression for the given attribute.protected void
setChangeTracker(long changeTracker)
This method is intended for subreport handling inside the process state.void
setComputedStyle(SimpleStyleSheet computedStyle)
void
setDataSource(DataSource ds)
Deprecated.The data-source should not be used anymore.void
setDynamicContent(boolean dynamicContent)
Defines the stylesheet property for the dynamic attribute.void
setElementType(ElementType elementType)
void
setHRefTarget(String target)
Redefines the link target for this element.void
setId(String id)
Defines the Xml-ID of this element.void
setName(String name)
Defines the name for this Element.protected void
setParent(Section parent)
Defines the parent of the Element.void
setStyleExpression(StyleKey property, Expression function)
Adds a function to the report's collection of expressions.void
setVisible(boolean b)
Defines, whether this Element should be visible in the output.String
toString()
Returns a string representation of the band, useful mainly for debugging purposes.protected void
updateChangedFlagInternal(ReportElement element, int type, Object parameter)
Updates the change flag and notifies the parent, if this element has a parent.protected void
updateInternalChangeFlag()
Updates the internal change flag without notifying the parent.
-
-
-
Field Detail
-
ANONYMOUS_ELEMENT_PREFIX
public static final String ANONYMOUS_ELEMENT_PREFIX
The internal constant to mark anonymous element names.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Element
public Element()
Constructs an element. The element inherits the element's defined default ElementStyleSheet to provide reasonable default values for common stylekeys. When the element is added to the band, the bands stylesheet is set as parent to the element's stylesheet. A datasource is assigned with this element is set to a default source, which always returns null.
-
Element
protected Element(InstanceID id)
-
-
Method Detail
-
getComputedStyle
public SimpleStyleSheet getComputedStyle()
- Specified by:
getComputedStyle
in interfaceReportElement
-
setComputedStyle
public void setComputedStyle(SimpleStyleSheet computedStyle)
- Specified by:
setComputedStyle
in interfaceReportElement
-
setAttributeExpression
public void setAttributeExpression(String namespace, String name, Expression value)
Description copied from interface:ReportElement
Assigns a new attribute expression for the given attribute. Attributes are identified by the namespace and name. Each attribute can have only one expression assigned. Setting the expression tonull
clears the expression and will preserve the attribute's static value. Functions cannot be used as attribute-expressions as attribute- and style-expressions do not receive events and are not guaranteed to be executed unless the element is processed.- Specified by:
setAttributeExpression
in interfaceReportElement
- Parameters:
namespace
- the attribute's namespace.name
- the attribute's name.value
- the expression.
-
getAttributeExpression
public Expression getAttributeExpression(String namespace, String name)
Description copied from interface:ReportElement
Returns the attribute expression for the given attribute identified by its namespace and attribute name.- Specified by:
getAttributeExpression
in interfaceReportElement
- Parameters:
namespace
- the attribute's namespace.name
- the attribute's name.- Returns:
- the assigned expression or
null
if the attribute has no expression assigned.
-
getAttributeExpressionNamespaces
public String[] getAttributeExpressionNamespaces()
Description copied from interface:ReportElement
Returns the namespaces of all attributes that have attribute-expressions assigned.- Specified by:
getAttributeExpressionNamespaces
in interfaceReportElement
- Returns:
- the attribute-namespaces as array.
-
getAttributeExpressionNames
public String[] getAttributeExpressionNames(String name)
Description copied from interface:ReportElement
Returns the names of all attributes for the given namespace that have attribute-expressions assigned.- Specified by:
getAttributeExpressionNames
in interfaceReportElement
- Parameters:
name
- the namespace for which the attribute-names should be returned, never null.- Returns:
- the known attribute names as array.
-
getAttributeExpressions
public ReportAttributeMap<Expression> getAttributeExpressions()
-
setAttribute
public void setAttribute(String namespace, String name, Object value)
Description copied from interface:ReportElement
Defines a attribute's static value. Attributes are identified by the attribute's namespace and the attribute name. Setting a attribute value tonull
removes the attribute. Attribute values are not checked for type safety.- Specified by:
setAttribute
in interfaceReportElement
- Parameters:
namespace
- the attribute's namespace.name
- the attribute name.value
- the attribute value, or null to remove the attribute.
-
setAttribute
public void setAttribute(String namespace, String name, Object value, boolean notifyChange)
- Specified by:
setAttribute
in interfaceReportElement
-
getAttribute
public Object getAttribute(String namespace, String name)
- Specified by:
getAttribute
in interfaceReportElement
-
getFirstAttribute
public Object getFirstAttribute(String localName)
- Specified by:
getFirstAttribute
in interfaceReportElement
-
getAttributeNamespaces
public String[] getAttributeNamespaces()
- Specified by:
getAttributeNamespaces
in interfaceReportElement
-
getAttributeNames
public String[] getAttributeNames(String namespace)
- Specified by:
getAttributeNames
in interfaceReportElement
-
getAttributes
public ReportAttributeMap<Object> getAttributes()
Returns the attributes of the element as unmodifable collection. The collection can be safely stored as it is guaranteed to never change. (However, no assumptions are made about the contents inside the collection.)- Specified by:
getAttributes
in interfaceReportElement
- Returns:
- the unmodifiable attribute collection
-
getAttributeTyped
public <TS> TS getAttributeTyped(String namespace, String attribute, Class<TS> filter)
- Specified by:
getAttributeTyped
in interfaceReportElement
-
setElementType
public void setElementType(ElementType elementType)
-
getElementType
public ElementType getElementType()
- Specified by:
getElementType
in interfaceReportElement
-
getElementTypeName
public String getElementTypeName()
-
getMetaData
public final ElementMetaData getMetaData()
- Specified by:
getMetaData
in interfaceReportElement
-
getParent
public final Band getParent()
Return the parent of the Element. You can use this to explore the component tree.- Returns:
- the parent of this element.
-
getParentSection
public final Section getParentSection()
- Specified by:
getParentSection
in interfaceReportElement
-
setParent
protected final void setParent(Section parent)
Defines the parent of the Element. This method is public as a implementation side effect. Only a band or section implementation should call this method. Calling this method manually will create a huge disaster.- Parameters:
parent
- (null allowed).
-
notifyElement
protected void notifyElement()
-
setName
public void setName(String name)
Defines the name for this Element. The name must not be empty, or a NullPointerException is thrown. Names can be used to lookup an element within a band. There is no requirement for element names to be unique.- Parameters:
name
- the name of this element
-
getName
public String getName()
Returns the name of the Element. The name of the Element is never null.- Specified by:
getName
in interfaceReportElement
- Returns:
- the name.
-
getDataSource
public final DataSource getDataSource()
Deprecated.Whereever possible use ElementType implementations instead. This method only exists to let old reports run.Returns the datasource for this Element. You cannot override this function as the Element needs always to be the last consumer in the chain of filters. This function must never return null.- Specified by:
getDataSource
in interfaceDataTarget
- Returns:
- the assigned legacy datasource.
-
setDataSource
public void setDataSource(DataSource ds)
Deprecated.The data-source should not be used anymore. Use ElementType implementations instead. This method only exists to let old reports run.Sets the data source for this Element. The data source is used to produce or query the element's display value.- Specified by:
setDataSource
in interfaceDataTarget
- Parameters:
ds
- the datasource (null
not permitted).- Throws:
NullPointerException
- if the given data source is null.
-
isVisible
public boolean isVisible()
Defines whether this Element should be painted. The detailed implementation is up to the outputtarget.- Returns:
- the current visiblity state.
-
setVisible
public void setVisible(boolean b)
Defines, whether this Element should be visible in the output. The interpretation of this flag is up to the content processor.- Parameters:
b
- the new visibility state
-
clone
public Element clone()
Clones this Element, the datasource and the private stylesheet of this Element. The clone does no longer have a parent, as the old parent would not recognize that new object anymore.- Specified by:
clone
in interfaceDataTarget
- Overrides:
clone
in classObject
- Returns:
- a clone of this Element.
-
derive
public final Element derive()
-
derive
public Element derive(boolean preserveElementInstanceIds)
Creates a deep copy of this element and regenerates all instance-ids.- Parameters:
preserveElementInstanceIds
- defines whether this call generates new instance-ids for the derived elements. Instance-IDs are used by the report processor to recognize reoccurring elements and must not changed within the report run. Outside of the report processors new instance ids should be generated at all times to separate instances and to make them uniquely identifiable.- Returns:
- the copy of the element.
-
getStyle
public ElementStyleSheet getStyle()
Returns this elements private stylesheet. This sheet can be used to override the default values set in one of the parent-stylesheets.- Specified by:
getStyle
in interfaceReportElement
- Returns:
- the Element's stylesheet
-
getTreeLock
public final Object getTreeLock()
Returns the tree lock object for the self tree. If the element is part of a content hierarchy, the parent's tree lock is returned.- Specified by:
getTreeLock
in interfaceReportElement
- Returns:
- the treelock object.
-
getId
public String getId()
Returns the Xml-ID of this element. This ID is unique within the report-definition, but is not a internal object-instance ID but a user-defined string.- Specified by:
getId
in interfaceReportElement
- Returns:
- the element id.
-
setId
public void setId(String id)
Defines the Xml-ID of this element. This ID is unique within the report-definition, but is not a internal object-instance ID but a user-defined string.- Parameters:
id
- the element id.
-
getObjectID
public final InstanceID getObjectID()
Returns a unique identifier for the given instance. The identifier can be used to recognize cloned instance which have the same anchestor. The identifier is unique as long as the element remains in the JVM, it does not guarantee uniqueness or the ability to recognize clones, after the element has been serialized.- Specified by:
getObjectID
in interfaceReportElement
- Returns:
- the object identifier.
-
isDynamicContent
public boolean isDynamicContent()
Checks whether the layout of this element is dynamic and adjusts to the element's printable content. If set to false, the element's minimum-size will be also used as maximum size.- Returns:
- true, if the Element's layout is dynamic, false otherwise.
-
setDynamicContent
public void setDynamicContent(boolean dynamicContent)
Defines the stylesheet property for the dynamic attribute. Calling this function with either parameter will override any previously defined value for the dynamic attribute. The value can no longer be inherited from parent stylesheets.- Parameters:
dynamicContent
- the new state of the dynamic flag.
-
getReportDefinition
public ReportDefinition getReportDefinition()
Returns the currently assigned report definition.- Specified by:
getReportDefinition
in interfaceReportElement
- Returns:
- the report definition or null, if no report has been assigned.
-
getMasterReport
public ReportDefinition getMasterReport()
Returns the master-report element. This will be a MasterReport while outside of the report processing. Inside the report processing (when called from a report-definition contained in a report-state), this will be a ReportDefinitionImpl.- Returns:
- the master report.
-
setHRefTarget
public void setHRefTarget(String target)
Redefines the link target for this element.- Parameters:
target
- the target
-
getHRefTarget
public String getHRefTarget()
Returns the currently set link target for this element.- Returns:
- the link target.
-
getDefaultStyleSheet
public ElementStyleSheet getDefaultStyleSheet()
Creates the global stylesheet for this element type. The global stylesheet is an immutable stylesheet that provides reasonable default values for some of the style keys. The global default stylesheet is always the last stylesheet that will be queried for values.- Specified by:
getDefaultStyleSheet
in interfaceReportElement
- Returns:
- the global stylesheet.
-
setStyleExpression
public void setStyleExpression(StyleKey property, Expression function)
Adds a function to the report's collection of expressions.- Specified by:
setStyleExpression
in interfaceReportElement
- Parameters:
property
- the stylekey that will be modified by this element.function
- the function.
-
getStyleExpression
public Expression getStyleExpression(StyleKey property)
Returns the expressions for the report.- Specified by:
getStyleExpression
in interfaceReportElement
- Parameters:
property
- the stylekey for which an style-expression is returned.- Returns:
- the expressions.
-
getStyleExpressions
public Map<StyleKey,Expression> getStyleExpressions()
Returns a map of all style expressions attached to this element. The map is keyed by an StyleKey and contains Expression instances.- Specified by:
getStyleExpressions
in interfaceReportElement
- Returns:
- the expression.
-
getDefinitionSource
public org.pentaho.reporting.libraries.resourceloader.ResourceKey getDefinitionSource()
Returns the resource-key of the file that defined this element. This method may return null if the whole report was created in memory.- Returns:
- the the definition source.
-
getContentBase
public org.pentaho.reporting.libraries.resourceloader.ResourceKey getContentBase()
-
getChangeTracker
public long getChangeTracker()
Returns the element's change-tracker. The changetracker is a version indicator that tracks the number of changes that have been made to an element and makes it easier to implement caching on top of elements or bands. Any change will increase the change-tracker.- Specified by:
getChangeTracker
in interfaceReportElement
- Returns:
- the element's change tracking number.
- See Also:
notifyNodePropertiesChanged()
,notifyNodeStructureChanged()
-
notifyNodePropertiesChanged
public void notifyNodePropertiesChanged()
Notifies the element and any parent element that a property of this element has changed. This notification updates the change tracker.
-
notifyNodePropertiesChanged
public void notifyNodePropertiesChanged(Object parameter)
-
notifyNodeChildAdded
public void notifyNodeChildAdded(Object o)
Notifies the element and any parent element that a child node has been added. This notification updates the change tracker.- Parameters:
o
- the node that has been added.
-
notifyNodeChildRemoved
public void notifyNodeChildRemoved(Object o)
Notifies the element and any parent element that a child node has been removed. This notification updates the change tracker.- Parameters:
o
- the node that has been removed.
-
notifyNodeStructureChanged
public void notifyNodeStructureChanged()
Notifies the element and any parent element that the structure of this element has changed in some undisclosed way. This notification updates the change tracker.
-
updateChangedFlagInternal
protected void updateChangedFlagInternal(ReportElement element, int type, Object parameter)
Updates the change flag and notifies the parent, if this element has a parent.- Parameters:
element
- the element that caused the notification.type
- the notification type.parameter
- the optional parameter further describing the event.
-
updateInternalChangeFlag
protected final void updateInternalChangeFlag()
Updates the internal change flag without notifying the parent. This is a internal method and unless you are calling this method from a report-definition, you are probably doing something wrong.
-
setChangeTracker
protected final void setChangeTracker(long changeTracker)
This method is intended for subreport handling inside the process state. Messing with the change tracker in any other way will break reports. You have been warned. This method is internal and may change or be renamed at any time.- Parameters:
changeTracker
- the new change tracker value
-
toString
public String toString()
Returns a string representation of the band, useful mainly for debugging purposes.
-
getChildElementsByType
public ReportElement[] getChildElementsByType(ElementType type)
- Specified by:
getChildElementsByType
in interfaceReportElement
-
getChildElementByType
public ReportElement getChildElementByType(ElementType type)
- Specified by:
getChildElementByType
in interfaceReportElement
-
getChildElementsByName
public ReportElement[] getChildElementsByName(String name)
- Specified by:
getChildElementsByName
in interfaceReportElement
-
copyInto
public void copyInto(Element target)
-
getElementContext
public <T> T getElementContext(Class<T> contextType)
- Specified by:
getElementContext
in interfaceReportElement
-
copyAttributes
public void copyAttributes(ReportAttributeMap<Object> attributes)
-
-