Package Summary  Overview Summary


com.sun.rowset.internal
Class XmlReaderContentHandler

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by com.sun.rowset.internal.XmlReaderContentHandler


All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class XmlReaderContentHandler
extends org.xml.sax.helpers.DefaultHandler

The document handler that receives parse events that an XML parser sends while it is parsing an XML document representing a WebRowSet object. The parser sends strings to this XmlReaderContentHandler and then uses these strings as arguments for the XmlReaderContentHandler methods it invokes. The final goal of the SAX parser working with an XmlReaderContentHandler object is to read an XML document that represents a RowSet object.

A rowset consists of its properties, metadata, and data values. An XML document representating a rowset includes the values in these three categories along with appropriate XML tags to identify them. It also includes a top-level XML tag for the rowset and three section tags identifying the three categories of values.

The tags in an XML document are hierarchical. This means that the top-level tag, RowSet, is followed by the three sections with appropriate tags, which are in turn each followed by their constituent elements. For example, the properties element will be followed by an element for each of the properties listed in in this XmlReaderContentHandler object's properties field. The content of the other two fields, colDef, which lists the rowset's metadata elements, and data, which lists the rowset's data elements, are handled similarly .

This implementation of XmlReaderContentHandler provides the means for the parser to determine which elements need to have a value set and then to set those values. The methods in this class are all called by the parser; an application programmer never calls them directly.


Constructor Summary
XmlReaderContentHandler(RowSet r)
          Constructs a new XmlReaderContentHandler object that will assist the SAX parser in reading a WebRowSet object in the format of an XML document.
 
Method Summary
 voidcharacters(char[] ch, int start, int length)
          Sets a property, metadata, or data value with the characters in the given array of characters, starting with the array element indicated by start and continuing for length number of characters.
 voidendDocument()
           
 voidendElement(java.lang.String uri, java.lang.String lName, java.lang.String qName)
          Sets the value for the given element if name is one of the array elements in the fields properties, colDef, or data and this XmlReaderContentHandler object's state is not INITIAL.
 voiderror(org.xml.sax.SAXParseException e)
          Throws the given SAXParseException object.
 voidnotationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
           
 voidstartDocument()
           
 voidstartElement(java.lang.String uri, java.lang.String lName, java.lang.String qName, org.xml.sax.Attributes attributes)
          Sets this XmlReaderContentHandler object's tag field if the given name is the key for a tag and this object's state is not INITIAL.
 voidunparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName)
           
 voidwarning(org.xml.sax.SAXParseException err)
          Prints a warning message to System.out giving the line number and uri for what caused the warning plus a message explaining the reason for the warning.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, fatalError, ignorableWhitespace, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlReaderContentHandler

public XmlReaderContentHandler(RowSet r)
Constructs a new XmlReaderContentHandler object that will assist the SAX parser in reading a WebRowSet object in the format of an XML document. In addition to setting some default values, this constructor creates three HashMap objects, one for properties, one for metadata, and one for data. These hash maps map the strings sent by the SAX parser to integer constants so that they can be compared more efficiently in switch statements.

Parameters:
r - the RowSet object in XML format that will be read

Method Detail

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Specified by:
startDocument in interface org.xml.sax.ContentHandler
Overrides:
startDocument in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
Specified by:
endDocument in interface org.xml.sax.ContentHandler
Overrides:
endDocument in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

startElement

public void startElement(java.lang.String uri,
                         java.lang.String lName,
                         java.lang.String qName,
                         org.xml.sax.Attributes attributes)
                  throws org.xml.sax.SAXException
Sets this XmlReaderContentHandler object's tag field if the given name is the key for a tag and this object's state is not INITIAL. The field is set to the constant that corresponds to the given element name. If the state is INITIAL, the state is set to the given name, which will be one of the sections PROPERTIES, METADATA, or DATA. In either case, this method puts this document handler in the proper state for calling the method endElement.

If the state is DATA and the tag is RowTag, DelTag, or InsTag, this method moves the rowset's cursor to the insert row and sets this XmlReaderContentHandler object's idx field to 0 so that it will be in the proper state when the parser calls the method endElement.

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Parameters:
lName - the name of the element; either (1) one of the array elements in the fields properties, colDef, or data or (2) one of the RowSet elements "properties", "metadata", or "data"
attributes - org.xml.sax.AttributeList objects that are attributes of the named section element; may be null if there are no attributes, which is the case for WebRowSet objects
Throws:
org.xml.sax.SAXException - if a general SAX error occurs

endElement

public void endElement(java.lang.String uri,
                       java.lang.String lName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
Sets the value for the given element if name is one of the array elements in the fields properties, colDef, or data and this XmlReaderContentHandler object's state is not INITIAL. If the state is INITIAL, this method does nothing.

If the state is METADATA and the argument supplied is "metadata", the rowset's metadata is set. If the state is PROPERTIES, the appropriate property is set using the given name to determine the appropriate value. If the state is DATA and the argument supplied is "data", this method sets the state to INITIAL and returns. If the argument supplied is one of the elements in the field data, this method makes the appropriate changes to the rowset's data.

Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Parameters:
lName - the name of the element; either (1) one of the array elements in the fields properties, colDef, or data or (2) one of the RowSet elements "properties", "metadata", or "data"
Throws:
org.xml.sax.SAXException - if a general SAX error occurs

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Sets a property, metadata, or data value with the characters in the given array of characters, starting with the array element indicated by start and continuing for length number of characters.

The SAX parser invokes this method and supplies the character array, start position, and length parameter values it got from parsing the XML document. An application programmer never invokes this method directly.

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler
Parameters:
ch - an array of characters supplied by the SAX parser, all or part of which will be used to set a value
start - the position in the given array at which to start
length - the number of consecutive characters to use
Throws:
org.xml.sax.SAXException

error

public void error(org.xml.sax.SAXParseException e)
           throws org.xml.sax.SAXParseException
Throws the given SAXParseException object. This exception was originally thrown by the SAX parser and is passed to the method error when the SAX parser invokes it.

Specified by:
error in interface org.xml.sax.ErrorHandler
Overrides:
error in class org.xml.sax.helpers.DefaultHandler
Parameters:
e - the SAXParseException object to throw
Throws:
org.xml.sax.SAXParseException

warning

public void warning(org.xml.sax.SAXParseException err)
             throws org.xml.sax.SAXParseException
Prints a warning message to System.out giving the line number and uri for what caused the warning plus a message explaining the reason for the warning. This method is invoked by the SAX parser.

Specified by:
warning in interface org.xml.sax.ErrorHandler
Overrides:
warning in class org.xml.sax.helpers.DefaultHandler
Parameters:
err - a warning generated by the SAX parser
Throws:
org.xml.sax.SAXParseException

notationDecl

public void notationDecl(java.lang.String name,
                         java.lang.String publicId,
                         java.lang.String systemId)
Specified by:
notationDecl in interface org.xml.sax.DTDHandler
Overrides:
notationDecl in class org.xml.sax.helpers.DefaultHandler

unparsedEntityDecl

public void unparsedEntityDecl(java.lang.String name,
                               java.lang.String publicId,
                               java.lang.String systemId,
                               java.lang.String notationName)
Specified by:
unparsedEntityDecl in interface org.xml.sax.DTDHandler
Overrides:
unparsedEntityDecl in class org.xml.sax.helpers.DefaultHandler


Java is a trademark or registered trademark of Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A All Rights Reserved.