Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

jbreport.core
Class AbstractReportElement  view AbstractReportElement download AbstractReportElement.java

java.lang.Object
  extended byjbreport.core.AbstractReportElement
All Implemented Interfaces:
java.lang.Cloneable, jbreport.ReportElement, Traversable, XMLAware
Direct Known Subclasses:
Fragment, Include, NullReportStylesheet, QueryBoundResult, ReportCompositeImpl, ReportSectionImpl, SectionBreak, TableRow

public abstract class AbstractReportElement
extends java.lang.Object
implements java.lang.Cloneable, jbreport.ReportElement, Traversable, XMLAware

This provides default implementations of all the interfaces that are implemented by most elements that exist as part of the report framework.

Version:
$Revision: 1.1 $

Field Summary
protected  java.lang.String attrType
          The type declared as an attribute with the declaration of the xml element.
protected  java.lang.String cdata
          The character data that existed as part of the element definition
protected  java.lang.String className
          The declared style class - can be null
protected  java.lang.String elementType
          The type of xml *element* that this instance represents.
(package private)  jbreport.ReportElementFactory factory
          The factory that defined this report element instance.
protected  java.lang.String name
          The name of this report element
private  jbreport.ReportElement parent
          The parent of this instance
(package private)  XMLHandler xmlHandler
          The xml handler instance that was responsible for causing this element to be created.
 
Fields inherited from interface jbreport.ReportElement
DEEP, SHALLOW
 
Constructor Summary
AbstractReportElement()
           
 
Method Summary
 void accept(ReportVisitor visitor, ReportVisitorState state)
          This defines the operation that the Traversable instance must perform at each node in the traversal.
protected static void assert(boolean condition, java.lang.String msg)
          Assert that the given statement is not false, throw an error if it is false.
protected static void assertNotNull(java.lang.Object obj, java.lang.String objName)
          Assert that the given object instance is not null.
 java.util.Iterator boundParameters()
          Returns an iterator of all the bound parameters that exist within this section
 void breakEventNotify(jbreport.util.ReportBreak source, java.lang.Object type)
          This will notify the element that a break event has happened, and will give the element a chance to do some work.
protected  java.lang.Object clone()
          Enable cloning of this instance so that the copy() methods can be implemented.
 jbreport.ReportElement copy()
          This is the same as calling copy(SHALLOW);
 jbreport.ReportElement copy(boolean deep)
          This will copy (clone) the current element, returning the copied element.
 java.lang.String getBoundParamValue(java.lang.String paramName)
          Returns the value of the bound parameter, null if no parameter of that name was found
 jbreport.ReportElement getElement(java.lang.String property)
          Returns the ReportElement that exists as part of this element.
 jbreport.ReportElementFactory getFactory()
          Returns the ElementFactory that created this instance.
 java.util.List getList(java.lang.String property)
          Returns the List instance for the given property name.
 java.lang.String getName()
          Returns the name of this report element if it has one.
 jbreport.ReportElement getParent()
          Returns the parent of this element.
 jbreport.Repository getRepository()
          Returns the repository in which this instance is defined.
 java.lang.String getString(java.lang.String property, java.lang.String defaultValue)
          Returns the string value for the requested property.
 jbreport.ReportStylesheet getStylesheet()
          This will return the stylesheet instance for this ReportElement instance.
 java.lang.String getType()
          Returns the type of this report element.
 java.util.Iterator inOrderIterator()
          Returns an iterator suitable for an inOrder iteration over the hierarchy.
 void inOrderTraverse(ReportVisitor visitor)
          Traverse the tree using an in-order iterator, and call the accept method on each element in the traversal.
 void loadData()
          This will initiate the loading of the data into the report.
 java.util.Iterator postOrderIterator()
          Returns an iterator suitable for a postOrder iteration over the hierarchy.
 void postOrderTraverse(ReportVisitor visitor)
          Traverse the tree using a post-order iterator, and call the accept method on each element in the traversal.
 void preLoadData()
          This method is called prior to the data actually being loaded into the report.
 java.util.Iterator preOrderIterator()
          Returns an iterator suitable for a preOrder iteration over the hierarchy.
 void preOrderTraverse(ReportVisitor visitor)
          Traverse the tree using a pre-order iterator, and call the accept method on each element in the traversal.
 void setParent(jbreport.ReportElement parent)
          This will set the parent of this element to that given.
 void setString(java.lang.String property, java.lang.String value)
          Sets the value of the given property to that given.
 void updateData(jbreport.data.QueryResult queryResult)
          This is called for every successful next() method call on the QueryResult contained by a group.
 void xmlEnd(java.lang.String cdata)
          This should mark the end of the element definition using xml.
 void xmlEndChild(jbreport.ReportElement elem)
          This method is called for every child element that is defined during xml tree traversal.
 void xmlInitialize(java.lang.String localName, org.xml.sax.Attributes attributes)
          This should initialize the instance with data obtained during the traversal of an xml tree.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

protected java.lang.String name
The name of this report element


elementType

protected java.lang.String elementType
The type of xml *element* that this instance represents. This is normally used by external packages while traversing the tree.


attrType

protected java.lang.String attrType
The type declared as an attribute with the declaration of the xml element. Thus for , elementType is query, and attrType is jdbc.


cdata

protected java.lang.String cdata
The character data that existed as part of the element definition


className

protected java.lang.String className
The declared style class - can be null


factory

jbreport.ReportElementFactory factory
The factory that defined this report element instance.


xmlHandler

XMLHandler xmlHandler
The xml handler instance that was responsible for causing this element to be created. Note that this is not necessarily always set, so the onus is on the programmer to check for null.


parent

private jbreport.ReportElement parent
The parent of this instance

Constructor Detail

AbstractReportElement

public AbstractReportElement()
Method Detail

getName

public java.lang.String getName()
Description copied from interface: jbreport.ReportElement
Returns the name of this report element if it has one. If it is not named null is returned.

Specified by:
getName in interface jbreport.ReportElement

getRepository

public jbreport.Repository getRepository()
Description copied from interface: jbreport.ReportElement
Returns the repository in which this instance is defined. In the case of the repository, return itself. ie. This method should never return null.

Specified by:
getRepository in interface jbreport.ReportElement

assert

protected static void assert(boolean condition,
                             java.lang.String msg)
Assert that the given statement is not false, throw an error if it is false.


assertNotNull

protected static void assertNotNull(java.lang.Object obj,
                                    java.lang.String objName)
Assert that the given object instance is not null. This is normally used to check arguments passed into a method, and will throw a different exception to that thrown by the assert method.


breakEventNotify

public void breakEventNotify(jbreport.util.ReportBreak source,
                             java.lang.Object type)
                      throws jbreport.ReportException
This will notify the element that a break event has happened, and will give the element a chance to do some work.


clone

protected java.lang.Object clone()
Enable cloning of this instance so that the copy() methods can be implemented. This is made protected, as we need to encourage the use of the copy methods for the actual work.


copy

public jbreport.ReportElement copy()
Description copied from interface: jbreport.ReportElement
This is the same as calling copy(SHALLOW);

Specified by:
copy in interface jbreport.ReportElement

copy

public jbreport.ReportElement copy(boolean deep)
Description copied from interface: jbreport.ReportElement
This will copy (clone) the current element, returning the copied element.

Should the deep parameter be set, the children of this element are cloned as well, otherwise, the references are copied. This is not strictly true, as there might be classes of elements where a clone does not make sense.

Specified by:
copy in interface jbreport.ReportElement

getElement

public jbreport.ReportElement getElement(java.lang.String property)
Description copied from interface: jbreport.ReportElement
Returns the ReportElement that exists as part of this element. This is used in to fetch parts of elements that don't have a specific interface defined for them.

Specified by:
getElement in interface jbreport.ReportElement

getString

public java.lang.String getString(java.lang.String property,
                                  java.lang.String defaultValue)
                           throws jbreport.ReportException
Description copied from interface: jbreport.ReportElement
Returns the string value for the requested property.

Specified by:
getString in interface jbreport.ReportElement

getStylesheet

public jbreport.ReportStylesheet getStylesheet()
                                        throws jbreport.ReportException
Description copied from interface: jbreport.ReportElement
This will return the stylesheet instance for this ReportElement instance. Should the document to which the element belongs not be declared as having a stylesheet, return an instance from which all requests for styles will return null.

We don't provide a method to to fetch an actual style value, as this would imply either a stylesheet lookup for every value, or storing the reference in the concrete implementation. Both of these would be relatively expensive.

Specified by:
getStylesheet in interface jbreport.ReportElement

boundParameters

public java.util.Iterator boundParameters()
                                   throws jbreport.ReportException
Description copied from interface: jbreport.ReportElement
Returns an iterator of all the bound parameters that exist within this section

Specified by:
boundParameters in interface jbreport.ReportElement

getBoundParamValue

public java.lang.String getBoundParamValue(java.lang.String paramName)
Description copied from interface: jbreport.ReportElement
Returns the value of the bound parameter, null if no parameter of that name was found

Specified by:
getBoundParamValue in interface jbreport.ReportElement

setString

public void setString(java.lang.String property,
                      java.lang.String value)
               throws jbreport.ReportException
Description copied from interface: jbreport.ReportElement
Sets the value of the given property to that given.

Specified by:
setString in interface jbreport.ReportElement

getList

public java.util.List getList(java.lang.String property)
Description copied from interface: jbreport.ReportElement
Returns the List instance for the given property name.

Specified by:
getList in interface jbreport.ReportElement

getType

public java.lang.String getType()
Description copied from interface: jbreport.ReportElement
Returns the type of this report element. This is useful for debugging a report tree.

Specified by:
getType in interface jbreport.ReportElement

getFactory

public jbreport.ReportElementFactory getFactory()
Description copied from interface: jbreport.ReportElement
Returns the ElementFactory that created this instance.

Specified by:
getFactory in interface jbreport.ReportElement

getParent

public jbreport.ReportElement getParent()
Description copied from interface: jbreport.ReportElement
Returns the parent of this element. This will return null if the element does not have a parent - ie. it is at the top of the report tree

Specified by:
getParent in interface jbreport.ReportElement

setParent

public void setParent(jbreport.ReportElement parent)
Description copied from interface: jbreport.ReportElement
This will set the parent of this element to that given. If the given parent is null, it implies that this element is at the top of the tree.

Specified by:
setParent in interface jbreport.ReportElement

loadData

public void loadData()
              throws jbreport.ReportException
Description copied from interface: jbreport.ReportElement
This will initiate the loading of the data into the report.

Specified by:
loadData in interface jbreport.ReportElement

preLoadData

public void preLoadData()
                 throws jbreport.ReportException
This method is called prior to the data actually being loaded into the report. It is currently used by the Group element to create a template which is later copied on every break.


updateData

public void updateData(jbreport.data.QueryResult queryResult)
                throws jbreport.ReportException
This is called for every successful next() method call on the QueryResult contained by a group.


xmlInitialize

public void xmlInitialize(java.lang.String localName,
                          org.xml.sax.Attributes attributes)
                   throws jbreport.ReportException
Description copied from interface: jbreport.ReportElement
This should initialize the instance with data obtained during the traversal of an xml tree. The child-parent relationship is catered for with the xmlEndChild() method.

Specified by:
xmlInitialize in interface jbreport.ReportElement

xmlEnd

public void xmlEnd(java.lang.String cdata)
            throws jbreport.ReportException
Description copied from interface: jbreport.ReportElement
This should mark the end of the element definition using xml. It will return the character data that was found during parsing to the element.

Specified by:
xmlEnd in interface jbreport.ReportElement

xmlEndChild

public void xmlEndChild(jbreport.ReportElement elem)
                 throws jbreport.ReportException
Description copied from interface: jbreport.ReportElement
This method is called for every child element that is defined during xml tree traversal. In order to preserve the tree, it will only be called at the end of the child definition.

Specified by:
xmlEndChild in interface jbreport.ReportElement

preOrderIterator

public java.util.Iterator preOrderIterator()
Description copied from interface: Traversable
Returns an iterator suitable for a preOrder iteration over the hierarchy.

The order of this iterator is to visit the root, visit the left subtree, visit the right subtree.

Specified by:
preOrderIterator in interface Traversable

postOrderIterator

public java.util.Iterator postOrderIterator()
Description copied from interface: Traversable
Returns an iterator suitable for a postOrder iteration over the hierarchy.

The order of this iterator is to visit the left subtree, visit the right subtree, visit the root.

Specified by:
postOrderIterator in interface Traversable

inOrderIterator

public java.util.Iterator inOrderIterator()
Description copied from interface: Traversable
Returns an iterator suitable for an inOrder iteration over the hierarchy.

The order of this iterator is to visit the left subtree, visit the root, visit the right subtree.

Specified by:
inOrderIterator in interface Traversable

preOrderTraverse

public void preOrderTraverse(ReportVisitor visitor)
                      throws jbreport.ReportException
Description copied from interface: Traversable
Traverse the tree using a pre-order iterator, and call the accept method on each element in the traversal.

Specified by:
preOrderTraverse in interface Traversable

postOrderTraverse

public void postOrderTraverse(ReportVisitor visitor)
                       throws jbreport.ReportException
Description copied from interface: Traversable
Traverse the tree using a post-order iterator, and call the accept method on each element in the traversal.

Specified by:
postOrderTraverse in interface Traversable

inOrderTraverse

public void inOrderTraverse(ReportVisitor visitor)
                     throws jbreport.ReportException
Description copied from interface: Traversable
Traverse the tree using an in-order iterator, and call the accept method on each element in the traversal.

Specified by:
inOrderTraverse in interface Traversable

accept

public void accept(ReportVisitor visitor,
                   ReportVisitorState state)
            throws jbreport.ReportException
Description copied from interface: Traversable
This defines the operation that the Traversable instance must perform at each node in the traversal. It should be coded such that it calls an appropriate method on the ReportVisitor instance. Should an appropriate method not exist, one should be coded.

The accept method should not recurse into its children, it is the contract of the iterator to perform that function.

eg:- For node type Section the method on this node should be as follows.

   public void accept(ReportVisitor visitor, ReportVisitorState state) 
      throws ReportException {
      visitor.visitSection(this, state);
   }

Specified by:
accept in interface Traversable