com.cri.xcat.api.examples
Class NonBlockingHandler

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

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


Constructor Summary
NonBlockingHandler(java.util.Observer observer)
           
 
Method Summary
 void characters(char[] buf, int offset, int len)
           
 void endDocument()
           
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String name)
           
 void handleError(java.lang.Exception e)
          This method is called when an error has occurred while attempting to submit a request (send a command) to the xCAT daemon.
 void handleXmlResponse(java.io.InputStream inputStream)
          This method takes the InputStream from the SSL socket connection and parses it.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
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
 

Constructor Detail

NonBlockingHandler

public NonBlockingHandler(java.util.Observer observer)
Method Detail

handleXmlResponse

public void handleXmlResponse(java.io.InputStream inputStream)
Description copied from interface: IResponseHandler
This method takes the InputStream from the SSL socket connection and parses it. The InputStream is the response from xcatd after a request is made to the daemon.

The response is in a XML format with the root XML tag of xcatresponse. According to the xCAT documentation, a valid XML response can be in various formats. There are 3 specifically mentioned in the documentation that are listed below:

 1.     <xcatresponse>
       <data>...</data>
       <data>...</data>
                   ...
       <data>...</data>
      </xcatresponse>
 

In this format, there can be multiple data tags.

 2.     <xcatresponse>
         <data>
        <desc>desc1</desc>
        <contents>contents1</contents>
       </data>
       <data>
        <desc>desc2</desc>
        <contents>contents2</contents>
       </data>
      </xcatresponse>
 

NOTE: In this format, only the data array can have more than one element. All other arrays are assumed to be a single element.

 3.     <xcatresponse>
       <node>
        <name>node1</name>
          <data>
         <desc>node 1 desc</desc>
         <contents>node 1 contents</contents>
        </data>
       </node>
       <node>
        <name>node2</name>
          <data>
         <desc>node 2 desc</desc>
         <contents>node 2 contents</contents>
        </data>
       </node>
      </xcatresponse>
 

NOTE: Only the node array can have more than one element. All other arrays are assumed to be a single element.

The response from xcatd may also contain an error. The error will be specified in the XML response and in which case the client should recognize this error and respond accordingly. NOTE: The handleError method is not automatically called when xcatd responds with valid XML containing an error message. This is up to the client.

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

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

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

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

handleError

public void handleError(java.lang.Exception e)
Description copied from interface: IResponseHandler
This method is called when an error has occurred while attempting to submit a request (send a command) to the xCAT daemon. It can be called at any time during the communication process, even while the client is handling the XML response from the server.

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