com.jrefinery.report.function
Class LevelledExpressionList

java.lang.Object
  |
  +--com.jrefinery.report.function.LevelledExpressionList
All Implemented Interfaces:
java.lang.Cloneable, java.util.EventListener, LayoutListener, PageEventListener, ReportListener

public class LevelledExpressionList
extends java.lang.Object
implements ReportListener, java.lang.Cloneable, LayoutListener, PageEventListener

A list of expressions/functions and associated levels. This class listens for report events, then passes these events on to the expressions and functions in *descending* level order.

Author:
Thomas Morgner

Constructor Summary
LevelledExpressionList(ExpressionCollection ec, ExpressionCollection fc)
          Creates a new list.
 
Method Summary
protected  void addError(java.lang.Exception e)
          Adds the error to the current list of errors.
protected  void clearError()
          Clears the error list.
 java.lang.Object clone()
          Creates and returns a copy of this object.
 void connectDataRow(DataRow dr)
          Connects the given datarow to the expression collection and all expressions contained in this collection.
 void disconnectDataRow(DataRow dr)
          Disconnects the datarow from the expression.
 void firePrepareEvent(ReportEvent event)
          Fires a prepare event.
protected  void firePrepareEventLayoutListener(ReportEvent event)
          Fires a prepare event layout listeners.
 java.util.List getErrors()
          Returns the list of errors, that occured during the last event handling.
 Expression getExpression(int index)
          Returns an expression.
 int getLevel()
          Gets the current level.
 java.util.Iterator getLevelsAscending()
          Returns an iterator that provides access to the levels in ascending order.
 java.util.Iterator getLevelsDescending()
          Returns an iterator that provides access to the levels in descending order.
 java.lang.Object getValue(int index)
          Returns the values of an expression.
 void groupFinished(ReportEvent event)
          Receives notification that a group is finished.
 void groupStarted(ReportEvent event)
          Receives notification that a new group has started.
 boolean hasErrors()
          Returns true, if this list has detected at least one error in the last operation.
 void itemsAdvanced(ReportEvent event)
          Receives notification that a new row has been read.
 void itemsFinished(ReportEvent event)
          Receives notification that a group of item bands has been completed.
 void itemsStarted(ReportEvent event)
          Receives notification that a group of item bands is about to be processed.
 void layoutComplete(LayoutEvent event)
          Receives notification that the band layouting has completed.
 void pageCanceled(ReportEvent event)
          Receives notification that a new page is being started.
 void pageFinished(ReportEvent event)
          Receives notification that a page is completed.
 void pageStarted(ReportEvent event)
          Receives notification that a new page is being started.
 void reportDone(ReportEvent event)
          Receives notification that report generation has completed, the report footer was printed, no more output is done.
 void reportFinished(ReportEvent event)
          Receives notification that report generation has finished (the last record is read and all groups are closed).
 void reportInitialized(ReportEvent event)
          Receives notification that report generation has started.
 void reportStarted(ReportEvent event)
          Receives notification that report generation has started.
 void setLevel(int level)
          Sets the level.
 int size()
          Size does not change, so it is cached.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LevelledExpressionList

public LevelledExpressionList(ExpressionCollection ec,
                              ExpressionCollection fc)
Creates a new list.

Parameters:
ec - the expressions.
fc - the functions.
Method Detail

reportStarted

public void reportStarted(ReportEvent event)
Receives notification that report generation has started.

The event carries a ReportState.Started state. Use this to prepare the report header.

Specified by:
reportStarted in interface ReportListener
Parameters:
event - the event.

reportInitialized

public void reportInitialized(ReportEvent event)
Receives notification that report generation has started.

The event carries a ReportState.Started state. Use this to initialize the report.

Specified by:
reportInitialized in interface ReportListener
Parameters:
event - the event.

reportFinished

public void reportFinished(ReportEvent event)
Receives notification that report generation has finished (the last record is read and all groups are closed).

Specified by:
reportFinished in interface ReportListener
Parameters:
event - the event.

pageStarted

public void pageStarted(ReportEvent event)
Receives notification that a new page is being started.

Specified by:
pageStarted in interface ReportListener
Parameters:
event - the event.

pageCanceled

public void pageCanceled(ReportEvent event)
Receives notification that a new page is being started.

Specified by:
pageCanceled in interface PageEventListener
Parameters:
event - the event.

pageFinished

public void pageFinished(ReportEvent event)
Receives notification that a page is completed.

Specified by:
pageFinished in interface ReportListener
Parameters:
event - the event.

groupStarted

public void groupStarted(ReportEvent event)
Receives notification that a new group has started.

The group can be determined by the report state's getCurrentGroup() function.

Specified by:
groupStarted in interface ReportListener
Parameters:
event - the event.

groupFinished

public void groupFinished(ReportEvent event)
Receives notification that a group is finished.

The group can be determined by the report state's getCurrentGroup() function.

Specified by:
groupFinished in interface ReportListener
Parameters:
event - the event.

itemsStarted

public void itemsStarted(ReportEvent event)
Receives notification that a group of item bands is about to be processed.

The next events will be itemsAdvanced events until the itemsFinished event is raised.

Specified by:
itemsStarted in interface ReportListener
Parameters:
event - the event.

itemsFinished

public void itemsFinished(ReportEvent event)
Receives notification that a group of item bands has been completed.

The itemBand is finished, the report starts to close open groups.

Specified by:
itemsFinished in interface ReportListener
Parameters:
event - the event.

itemsAdvanced

public void itemsAdvanced(ReportEvent event)
Receives notification that a new row has been read.

This event is raised before an ItemBand is printed.

Specified by:
itemsAdvanced in interface ReportListener
Parameters:
event - the event.

layoutComplete

public void layoutComplete(LayoutEvent event)
Receives notification that the band layouting has completed.

The event carries the current report state.

Specified by:
layoutComplete in interface LayoutListener
Parameters:
event - The event.

reportDone

public void reportDone(ReportEvent event)
Receives notification that report generation has completed, the report footer was printed, no more output is done. This is a helper event to shut down the output service.

Specified by:
reportDone in interface ReportListener
Parameters:
event - The event.

connectDataRow

public void connectDataRow(DataRow dr)
Connects the given datarow to the expression collection and all expressions contained in this collection.

Parameters:
dr - the datarow to be connected (null not permitted).
Throws:
java.lang.IllegalStateException - if there is a datarow already connected.
java.lang.NullPointerException - if the given datarow is null.

disconnectDataRow

public void disconnectDataRow(DataRow dr)
Disconnects the datarow from the expression.

Parameters:
dr - the datarow to be connected.
Throws:
java.lang.NullPointerException - if the given datarow is null.

size

public int size()
Size does not change, so it is cached.

Returns:
the size.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:
 x.clone() != x
will be true, and that the expression:
 x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
 x.clone().equals(x)
will be true, this is not an absolute requirement. Copying an object will typically entail creating a new instance of its class, but it also may require copying of internal data structures as well. No constructors are called.

The method clone for class Object performs a specific cloning operation. First, if the class of this object does not implement the interface Cloneable, then a CloneNotSupportedException is thrown. Note that all arrays are considered to implement the interface Cloneable. Otherwise, this method creates a new instance of the class of this object and initializes all its fields with exactly the contents of the corresponding fields of this object, as if by assignment; the contents of the fields are not themselves cloned. Thus, this method performs a "shallow copy" of this object, not a "deep copy" operation.

The class Object does not itself implement the interface Cloneable, so calling the clone method on an object whose class is Object will result in throwing an exception at run time. The clone method is implemented by the class Object as a convenient, general utility for subclasses that implement the interface Cloneable, possibly also overriding the clone method, in which case the overriding definition can refer to this utility definition by the call:

 super.clone()

Overrides:
clone in class java.lang.Object
Returns:
a clone of this instance.
Throws:
java.lang.CloneNotSupportedException - if the object's class does not support the Cloneable interface. Subclasses that override the clone method can also throw this exception to indicate that an instance cannot be cloned.
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
Cloneable

setLevel

public void setLevel(int level)
Sets the level.

Parameters:
level - the level.

getLevel

public int getLevel()
Gets the current level.

Returns:
the current level.

getLevelsDescending

public java.util.Iterator getLevelsDescending()
Returns an iterator that provides access to the levels in descending order.

Returns:
the iterator.

getLevelsAscending

public java.util.Iterator getLevelsAscending()
Returns an iterator that provides access to the levels in ascending order.

Returns:
the iterator.

getValue

public java.lang.Object getValue(int index)
Returns the values of an expression.

Parameters:
index - the function/expression index.
Returns:
the value.

getExpression

public Expression getExpression(int index)
Returns an expression.

Parameters:
index - the function/expression index.
Returns:
the function/expression.

getErrors

public java.util.List getErrors()
Returns the list of errors, that occured during the last event handling.

Returns:
the list of errors.

hasErrors

public boolean hasErrors()
Returns true, if this list has detected at least one error in the last operation.

Returns:
true, if there were errors, false otherwise.

addError

protected void addError(java.lang.Exception e)
Adds the error to the current list of errors.

Parameters:
e - the new exception that occured during the event dispatching.

clearError

protected void clearError()
Clears the error list.


firePrepareEvent

public void firePrepareEvent(ReportEvent event)
Fires a prepare event.

Parameters:
event - the event.

firePrepareEventLayoutListener

protected void firePrepareEventLayoutListener(ReportEvent event)
Fires a prepare event layout listeners.

Parameters:
event - the event.