com.davisor.graphics.chart
Class ChartXMLDataBuffer

java.lang.Object
  extended bycom.davisor.data.VoidData
      extended bycom.davisor.data.stream.JoinedDataBuffer
          extended bycom.davisor.graphics.chart.ChartXMLDataBuffer
All Implemented Interfaces:
org.xml.sax.ContentHandler, Data, DataBuffer, DataSource, org.xml.sax.DocumentHandler

public class ChartXMLDataBuffer
extends JoinedDataBuffer
implements org.xml.sax.ContentHandler, org.xml.sax.DocumentHandler

ChartXMLDataBuffer implements a SAX document handler that can read and combine chart data from a XML document and an external data source. In particular, if an external non-XML data source is supplied, it provides the data for data columns that are only declared in the XML document.

The XML syntax this handler accepts is described in a separate Chart XML reference document. The XML attributes this handler manipulates are further described in a separate attribute reference document.

ChartXMLDataBuffer will pack the read data into a number of DataBuffer objects that will hold channel attribute information in addition to the actual data.

External data sources

The following external data sources are supported:

External data sources are consumed and buffered at construction time. The source SQL result set, in particular, may then be disposed, while its data now can be read and re-read as many times as necessary.

The pairing of external data source columns and XML document columns is based on their identities. The identity of JDBC database columns is given by their column names, dug out from JDBC metadata. The identity of DataStream columns is defined by their TupleType member identities. Both of these identities are matched against the id attributes in XML groups and columns. If a match is found, the data in the external data source replaces entirely any data given in the XML document for that column. The column XML attributes and data type are however still applied to the data.

Column identity uniqueness

Chart tools rely on that the data columns they access all have mutually unique identities. Normally this is the case anyway, but it is also possible to feed in XML data that violates this principle. This makes it neccessary to validate column identities after XML data has been read in.

Column identities are validated in endDocument() method. The validation process will generate an unique identity for any column that either does not already have one, or that has an identity that conflicts with another column.

Chart attributes may assosiate channel attributes to data channels at chart generation time. The assosiation is based on channel identities. Such channel attribute identity references to columns that had conflicting identity will not therefore obviously work.

Since:
JDK1.1
See Also:
startElement(String,AttributeList), ChannelAttributes, ChartData

Field Summary
static int COLUMN
           
static int DATA
           
static int DATAFORMAT
           
static int DATATYPE
           
static boolean DEBUG
           
static int ELEMENT
           
static int ELEMENT_SHORT
           
static int FORMAT
           
static int GROUP
           
static int ID
           
static com.davisor.core.Index INDEXES
           
protected  java.util.List M_columnIDs
          Column ids during parsing.
protected  java.util.List M_columns
          Column list during parsing.
protected  java.net.URL M_context
          Context URL for textures and images.
protected  java.util.Map M_databaseColumns
          Supplemental database columns (if given).
protected  java.lang.String[] M_databaseNames
          Database column names (if given).
protected  java.util.Map M_jspAttributesMap
          Map containing attributes from the jsp page context
static int META
           
static int NAME
           
static int SEPARATOR
           
static int SQLCOLUMNINDEX
           
static int SQLCOLUMNNAME
           
protected static java.lang.String[] TAGS
           
static int TYPE
           
static int VALUE
           
static int VALUES
           
static java.lang.String XMLDATABUFFER_METADATA
          Needed to pass information from data source to lazylistdatabuffer
 
Fields inherited from class com.davisor.data.stream.JoinedDataBuffer
bufferMetaData, M_buffers, M_size
 
Fields inherited from class com.davisor.data.VoidData
M_type
 
Constructor Summary
ChartXMLDataBuffer(java.net.URL context)
          Creates a new chart data buffer that can be initialized from the XML document by using ChartXMLDocumentHandler.
ChartXMLDataBuffer(java.net.URL context, java.util.Map attributes)
          Creates a new chart data buffer that can be initialized from the XML document by using ChartXMLDocumentHandler.
 
Method Summary
protected  java.util.Map attributeListToMap(org.xml.sax.AttributeList atts)
          Converts SAX1 AttributeList to Map object
 void characters(char[] ch, int start, int length)
          Appends a bundle of characters into current text accumulation buffer.
protected  void endColumn()
          Handles the end of a column.
 void endDocument()
          Handles the end of a XML document.
protected  void endElement()
          Handles the end of a data element.
 void endElement(java.lang.String name)
          Handles the end of a XML element.
 void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qualifiedName)
          Handles the end of a XML element in SAX2 compliant way.
protected  void endGroup()
          Handles the end of a column group.
 void endPrefixMapping(java.lang.String prefix)
          End the scope of a prefix-URI mapping in SAX2 compliant way.
 java.net.URL getContext()
          Returns the context for textures and images.
 void ignorableWhitespace(char[] ch, int start, int length)
          Handles ignorable white space (which is ignored).
 void processingInstruction(java.lang.String target, java.lang.String data)
          Handles processing instructions (which are ignored).
 void setContext(java.net.URL context)
          Sets the context for textures and images for the given context.
 void setDocumentLocator(org.xml.sax.Locator locator)
          Sets the custom document locator (ignored).
 void skippedEntity(java.lang.String name)
          Receive notification of a skipped entity in SAX2 compliant way.
protected  void startColumn(org.xml.sax.AttributeList atts)
          Handles the start of a column.
 void startDocument()
          Handles the start of a XML document.
protected  void startElement(org.xml.sax.AttributeList atts)
          Handles the start of a data element.
 void startElement(java.lang.String name, org.xml.sax.AttributeList atts)
          Handles the start of a XML element.
 void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qualifiedName, org.xml.sax.Attributes atts)
          Handles the end of a XML element in SAX2 compliant way.
protected  void startGroup(org.xml.sax.AttributeList atts)
          Handles the start of a column group.
protected  void startMeta(org.xml.sax.AttributeList atts)
          Handles the start of a meta data.
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
          Begin the scope of a prefix-URI Namespace mapping in SAX2 compliant way.
 
Methods inherited from class com.davisor.data.stream.JoinedDataBuffer
assosiateListsWithTypes, close, getBuffers, getData, getSize, getStream, getStream, init, resolveSizeAndType, toString, toString
 
Methods inherited from class com.davisor.data.VoidData
equals, getDataValue, getType, hashCode, setType
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.davisor.data.Data
getType
 

Field Detail

COLUMN

public static final int COLUMN
See Also:
Constant Field Values

GROUP

public static final int GROUP
See Also:
Constant Field Values

ELEMENT

public static final int ELEMENT
See Also:
Constant Field Values

ELEMENT_SHORT

public static final int ELEMENT_SHORT
See Also:
Constant Field Values

TYPE

public static final int TYPE
See Also:
Constant Field Values

ID

public static final int ID
See Also:
Constant Field Values

SQLCOLUMNNAME

public static final int SQLCOLUMNNAME
See Also:
Constant Field Values

SQLCOLUMNINDEX

public static final int SQLCOLUMNINDEX
See Also:
Constant Field Values

NAME

public static final int NAME
See Also:
Constant Field Values

DATAFORMAT

public static final int DATAFORMAT
See Also:
Constant Field Values

DATATYPE

public static final int DATATYPE
See Also:
Constant Field Values

VALUES

public static final int VALUES
See Also:
Constant Field Values

SEPARATOR

public static final int SEPARATOR
See Also:
Constant Field Values

DATA

public static final int DATA
See Also:
Constant Field Values

FORMAT

public static final int FORMAT
See Also:
Constant Field Values

META

public static final int META
See Also:
Constant Field Values

VALUE

public static final int VALUE
See Also:
Constant Field Values

TAGS

protected static final java.lang.String[] TAGS

INDEXES

public static final com.davisor.core.Index INDEXES

M_context

protected java.net.URL M_context
Context URL for textures and images.


M_jspAttributesMap

protected java.util.Map M_jspAttributesMap
Map containing attributes from the jsp page context


M_databaseColumns

protected java.util.Map M_databaseColumns
Supplemental database columns (if given).


M_databaseNames

protected java.lang.String[] M_databaseNames
Database column names (if given).


M_columns

protected java.util.List M_columns
Column list during parsing.


M_columnIDs

protected java.util.List M_columnIDs
Column ids during parsing.


XMLDATABUFFER_METADATA

public static final java.lang.String XMLDATABUFFER_METADATA
Needed to pass information from data source to lazylistdatabuffer

See Also:
Constant Field Values

DEBUG

public static final boolean DEBUG
See Also:
Constant Field Values
Constructor Detail

ChartXMLDataBuffer

public ChartXMLDataBuffer(java.net.URL context)
Creates a new chart data buffer that can be initialized from the XML document by using ChartXMLDocumentHandler.

Parameters:
context - an URL context for textures and images (may be null)

ChartXMLDataBuffer

public ChartXMLDataBuffer(java.net.URL context,
                          java.util.Map attributes)
Creates a new chart data buffer that can be initialized from the XML document by using ChartXMLDocumentHandler.

Parameters:
context - an URL context for textures and images (may be null)
attributes - map originating from outside (may be null)
Method Detail

endElement

public void endElement(java.lang.String namespaceURI,
                       java.lang.String localName,
                       java.lang.String qualifiedName)
                throws org.xml.sax.SAXException
Handles the end of a XML element in SAX2 compliant way. Uses localName if both namespaceURI and localName are not null nor empty, qualifiedName otherwise. All other elements are silently ignored.

Specified by:
endElement in interface org.xml.sax.ContentHandler
Parameters:
namespaceURI - element namespace identifier (may be empty)
localName - element local name (may be empty)
qualifiedName - element qualified name (may be empty)
Throws:
org.xml.sax.SAXException
See Also:
endElement(String)

endPrefixMapping

public void endPrefixMapping(java.lang.String prefix)
                      throws org.xml.sax.SAXException
End the scope of a prefix-URI mapping in SAX2 compliant way. This implementation does nothing.

Specified by:
endPrefixMapping in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

skippedEntity

public void skippedEntity(java.lang.String name)
                   throws org.xml.sax.SAXException
Receive notification of a skipped entity in SAX2 compliant way. This implementation does nothing.

Specified by:
skippedEntity in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

startElement

public void startElement(java.lang.String namespaceURI,
                         java.lang.String localName,
                         java.lang.String qualifiedName,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
Handles the end of a XML element in SAX2 compliant way. Uses localName if both namespaceURI and localName are not null nor empty, qualifiedName otherwise. The following elements are recognized: All other elements are silently ignored.

Specified by:
startElement in interface org.xml.sax.ContentHandler
Parameters:
namespaceURI - element namespace identifier (may be empty)
localName - element local name (may be empty)
qualifiedName - element qualified name (may be empty)
atts - element attributes (may be empty)
Throws:
org.xml.sax.SAXException
See Also:
startElement(String,AttributeList)

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
                        throws org.xml.sax.SAXException
Begin the scope of a prefix-URI Namespace mapping in SAX2 compliant way. This implementation does nothin.

Specified by:
startPrefixMapping in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Appends a bundle of characters into current text accumulation buffer.

Specified by:
characters in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
Handles the end of a XML document. Data column identities are checked and their uniqueness is enforced.

Specified by:
endDocument in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException
See Also:
JoinedDataBuffer.init(java.lang.String, java.util.List, java.util.List, boolean)

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws org.xml.sax.SAXException
Handles ignorable white space (which is ignored).

Specified by:
ignorableWhitespace in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws org.xml.sax.SAXException
Handles processing instructions (which are ignored).

Specified by:
processingInstruction in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator locator)
Sets the custom document locator (ignored).

Specified by:
setDocumentLocator in interface org.xml.sax.ContentHandler

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Handles the start of a XML document. All internal buffer are initialized to be ready to accept content from a new XML document.

Specified by:
startDocument in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String name)
                throws org.xml.sax.SAXException
Handles the end of a XML element. This implementation calls SAX2 compliant element end handler with an empty namespace and same qualified name as local name.

Specified by:
endElement in interface org.xml.sax.DocumentHandler
Parameters:
name - element to be ended
Throws:
org.xml.sax.SAXException
See Also:
startElement(String, AttributeList), endElement(String, String, String)

startElement

public void startElement(java.lang.String name,
                         org.xml.sax.AttributeList atts)
                  throws org.xml.sax.SAXException
Handles the start of a XML element. This implementation calls SAX2 compliant element start handler with an empty namespace and same qualified name as local name.

Specified by:
startElement in interface org.xml.sax.DocumentHandler
Parameters:
name - element to be started
atts - attributes for the element
Throws:
org.xml.sax.SAXException
See Also:
endElement(String), startElement(String, String, String, org.xml.sax.Attributes)

attributeListToMap

protected java.util.Map attributeListToMap(org.xml.sax.AttributeList atts)
Converts SAX1 AttributeList to Map object


endColumn

protected void endColumn()
Handles the end of a column. Current text accumulation buffer, if any, is trimmed, and the data in it, if any, is appended to current column.

Alternatively, if a database column with matching column identity is available, data is taken from it.

Finally, the new data column is added into current column group, if available, or among the top-level columns.

See Also:
startColumn(org.xml.sax.AttributeList)

endElement

protected void endElement()
Handles the end of a data element. A data value is formed from the entire content of the current text accumulation buffer, and that is then added at the end of current data column.

See Also:
startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)

endGroup

protected void endGroup()
Handles the end of a column group. A new group column is formed, and the group members are added to it it. The new group column is then added into it's parent group, if available, or among the top-level columns.

The new group will be stored into a JoinedDataBuffer object, that contains all columns from the current group, all their member spesific attributes, and all group attributes common to all members. In particular, all member attributes will be added as sub-channel attributes to the group attributes.

See Also:
startGroup(org.xml.sax.AttributeList), JoinedDataBuffer

startColumn

protected void startColumn(org.xml.sax.AttributeList atts)
                    throws org.xml.sax.SAXException
Handles the start of a column. The following attributes are recognized:

Throws:
org.xml.sax.SAXException
See Also:
endColumn()

startElement

protected void startElement(org.xml.sax.AttributeList atts)
Handles the start of a data element. The data element has no attributes. Instead, a data buffer is prepared to accept element body content. When data element ends, the entire accumulated body content will be added as a new data element into current data column.

If current data buffer is active and non-empty at the moment this method is called, the current content of that buffer is treated as out-of-element body content. If so, all preceding and trailing white space is first removed from the biffer. The remaining buffer content is then expected to contain a series data elements, separated by current column data separator character. If so, these element are stored into current data column now.

For example, in the following case, column separator is white space, and the elements "a", "b", and "cd" will be added to data colum, now, and " e f " later when endElement is invoked. Please note, that the whole content of element tag is treated as the element value, in contrary to out-of-element data, that first trims and then slices the content.

 
   a b cd
    e f 
 
 

See Also:
endElement()

startGroup

protected void startGroup(org.xml.sax.AttributeList atts)
Handles the start of a column group. The following attributes are recognized:


startMeta

protected void startMeta(org.xml.sax.AttributeList atts)
Handles the start of a meta data. The following attributes are recognized:


getContext

public java.net.URL getContext()
Returns the context for textures and images.

See Also:
setContext(java.net.URL)

setContext

public void setContext(java.net.URL context)
Sets the context for textures and images for the given context.

See Also:
getContext()


Copyright © 2001-2004 Davisor Oy. All Rights Reserved.