Class 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 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.

    • Method Detail

      • 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 to null 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 interface ReportElement
        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 interface ReportElement
        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 interface ReportElement
        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 interface ReportElement
        Parameters:
        name - the namespace for which the attribute-names should be returned, never null.
        Returns:
        the known attribute names as array.
      • 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 to null removes the attribute. Attribute values are not checked for type safety.
        Specified by:
        setAttribute in interface ReportElement
        Parameters:
        namespace - the attribute's namespace.
        name - the attribute name.
        value - the attribute value, or null to remove the attribute.
      • 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 interface ReportElement
        Returns:
        the unmodifiable attribute collection
      • setElementType

        public void setElementType​(ElementType elementType)
      • getElementTypeName

        public String getElementTypeName()
      • 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.
      • 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 interface ReportElement
        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 interface DataTarget
        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 interface DataTarget
        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 interface DataTarget
        Overrides:
        clone in class Object
        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 interface ReportElement
        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 interface ReportElement
        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 interface ReportElement
        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 interface ReportElement
        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 interface ReportElement
        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 interface ReportElement
        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 interface ReportElement
        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 interface ReportElement
        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 interface ReportElement
        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 interface ReportElement
        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.
        Overrides:
        toString in class Object
        Returns:
        a string representation of this band.
      • copyInto

        public void copyInto​(Element target)