xml.cart
Class CartDocumentHandler

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by xml.cart.CartDocumentHandler
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

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

The CartDocumentHandler gets notification in the form of a call-back method. These call-backs are like the Listener model used for event handling. When a new element is encountered, for example, that creates a call-back. The call-backs are handled in the DocumentHandler:


Constructor Summary
CartDocumentHandler()
           
 
Method Summary
 void addProduct()
          addProduct will make an instance of a Product class and add it to the Cart instance.
 void characters(char[] buf, int offset, int len)
          when characters are found, we add them to the string vector for latter use.
 void endDocument()
           
 void endElement(java.lang.String URI, java.lang.String localName, java.lang.String qName)
          When we get the tag, then we want to invoke addProduct otherwise, just return:
 Cart getCart()
           
 void ignorableWhitespace(char[] buf, int offset, int len)
           
 void processingInstruction(java.lang.String target, java.lang.String data)
          The processingInstruction is called back when a non XML declaration is made.
 void setDocumentLocator(org.xml.sax.Locator l)
          The Locator instance must be used locally to identify the origin of a SAX event.
 void startDocument()
           
 void startElement()
          The AttributeList is not going to have any attributes in it for our example (i.e.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, notationDecl, resolveEntity, skippedEntity, startElement, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CartDocumentHandler

public CartDocumentHandler()
Method Detail

getCart

public Cart getCart()

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator l)
The Locator instance must be used locally to identify the origin of a SAX event.

Specified by:
setDocumentLocator in interface org.xml.sax.ContentHandler
Overrides:
setDocumentLocator in class org.xml.sax.helpers.DefaultHandler

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()
The AttributeList is not going to have any attributes in it for our example (i.e. provides an attribute of isbn whose value is 10).


endElement

public void endElement(java.lang.String URI,
                       java.lang.String localName,
                       java.lang.String qName)
When we get the tag, then we want to invoke addProduct otherwise, just return:

Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler

addProduct

public void addProduct()
addProduct will make an instance of a Product class and add it to the Cart instance. It is added by parsing the last three strings that have been pushed into the StringVector.


characters

public void characters(char[] buf,
                       int offset,
                       int len)
when characters are found, we add them to the string vector for latter use.

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler

ignorableWhitespace

public void ignorableWhitespace(char[] buf,
                                int offset,
                                int len)
Specified by:
ignorableWhitespace in interface org.xml.sax.ContentHandler
Overrides:
ignorableWhitespace in class org.xml.sax.helpers.DefaultHandler

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
The processingInstruction is called back when a non XML declaration is made.

Specified by:
processingInstruction in interface org.xml.sax.ContentHandler
Overrides:
processingInstruction in class org.xml.sax.helpers.DefaultHandler