com.cri.xcat.api.helpers
Class DefaultResponseHandler

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by com.cri.xcat.api.helpers.DefaultResponseHandler
All Implemented Interfaces:
IResponseHandler, org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class DefaultResponseHandler
extends org.xml.sax.helpers.DefaultHandler
implements IResponseHandler

This class is the default handler for a xCAT response from the xCAT daemon. It prints out the contents of the XML response to the console using SAX parsing techniques.

This class manages error handling by logging and printing the error to the console.

Author:
Scott Brown

Field Summary
protected  java.util.Map<java.lang.String,java.util.List<java.lang.String>> responseData
           
protected  boolean serverDone
           
 
Constructor Summary
DefaultResponseHandler()
           
 
Method Summary
 void characters(char[] buf, int offset, int len)
           
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String name)
           
 java.util.Map<java.lang.String,java.util.List<java.lang.String>> getResponseData()
          Returns a map that contains the information contained in the XML.
 void handleError(java.lang.Exception e)
          Logs the error that occurred and prints the error to the console.
 void handleXmlResponse(java.io.InputStream inputStream)
          Saves the XML response to the an internal responseData Map.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startElement, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

responseData

protected java.util.Map<java.lang.String,java.util.List<java.lang.String>> responseData

serverDone

protected boolean serverDone
Constructor Detail

DefaultResponseHandler

public DefaultResponseHandler()
Method Detail

handleError

public void handleError(java.lang.Exception e)
Logs the error that occurred and prints the error to the console.

Specified by:
handleError in interface IResponseHandler
Parameters:
e - The error that occurred.

handleXmlResponse

public void handleXmlResponse(java.io.InputStream inputStream)
Saves the XML response to the an internal responseData Map. The map can be retrived using the getResponseData method.

Assumes each non-parent XML tag has text content which is assumed to be the value of the xml node.

Continues to read xCAT responses until the serverdone tag is met.

Specified by:
handleXmlResponse in interface IResponseHandler
Parameters:
inputStream - the input stream from the xCAT daemon to this client.

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String name)
                throws org.xml.sax.SAXException
Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

characters

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

getResponseData

public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getResponseData()
Returns a map that contains the information contained in the XML. The Map that is returned has a key equal to the tag name and a value equal to the XML tag and a value equal to the data inside the tag. If there was only 1 XML tag of any name, the corresponding value in the map would be a List consisting of just 1 item (the text inside the XML tag).

Returns:
a map that contains the information contained in the XML