Main Page | Packages | Class Hierarchy | Class List | File List | Class Members

saxparse.MessageProcessor Class Reference

Collaboration diagram for saxparse.MessageProcessor:

Collaboration graph
[legend]
List of all members.

Detailed Description

MessageProcessor Aug 10, 2004.

The SAX "call back" handler for the trade engine message processor classes.

The methods in this class are called when the SAX parser recognizes the components of an XML document. The MessageProcessor class handles the document start (the message envelope) and recognizes the start of each message type. The MessageProcessor class allocates the appropriate message processor (derived from MessageBaseMessage base class) for each message. Calls the element, endElement and characters methods in the message processor to process the start tag, characters region and end tag. Note that the state machine below skips the first tag that starts a message (e.g., aim_order).

The MessageProcessor is passed a reference to an ArrayList. After each message is processed it is added to the ArrayList.

Trade engine messages are packaged within a tradeEngine XML envelope. This allows multiple sub-messages to be included in one tradeEngine message.

Author:
Ian Kaplan, www.bearcave.com, iank@bearcave.com


Public Member Functions

 MessageProcessor (ArrayList msgList)
void warning (SAXParseException e)
void error (SAXParseException e) throws SAXParseException
void fatalError (SAXParseException e) throws SAXParseException
void startDocument ()
void endDocument ()
void characters (char[] charSeq, int start, int len)
 The characters method is called to process character sequences that occur between tags.
void startElement (String uri, String localName, String qualName, Attributes attributes)
void endElement (String uri, String localName, String qualName)

Private Attributes

States mCurrentState = States.BAD_STATE
MessageInterface mMessage = null
ArrayList mMsgList = null


Constructor & Destructor Documentation

saxparse.MessageProcessor.MessageProcessor ArrayList  msgList  ) 
 

00080 { 00081 super(); 00082 mMsgList = msgList; 00083 }


Member Function Documentation

void saxparse.MessageProcessor.characters char[]  charSeq,
int  start,
int  len
 

The characters method is called to process character sequences that occur between tags.

For example:

            <TAG>This is a String</TAG>

This also includes white space that may be used in formatting the XML.

The SAX parser passes a reference to the input character array for the entire XML document. The start parameter is the offset in this array to the character region and the len parameter is its length.

Here I'm not interested in white space, so if the character region is nothing but white space, the method just returns.

00135 { 00136 String str = new String( charSeq, start, len ); 00137 str = str.trim(); 00138 if (str.length() > 0) { 00139 if (mMessage != null && mCurrentState == States.PROCESSING ) { 00140 mMessage.characters( str ); 00141 } 00142 } 00143 } // characters

void saxparse.MessageProcessor.endDocument  ) 
 

00109 { 00110 }

void saxparse.MessageProcessor.endElement String  uri,
String  localName,
String  qualName
 

00178 { 00179 if (!localName.equals("tradeEngine")) { 00180 if (localName.equals("aim_order") || 00181 localName.equals("control")) { 00182 mCurrentState = States.DONE; 00183 if (mMessage != null) { 00184 MessageBase m = mMessage.getMessage(); 00185 mMsgList.add( m ); 00186 } 00187 else { 00188 System.out.println("MessageProcessor::endElement: mMessage == null"); 00189 } 00190 } 00191 else { 00192 if (mMessage != null && mCurrentState == States.PROCESSING ) { 00193 mMessage.endElement( localName ); 00194 } 00195 } 00196 } 00197 } // endElement

void saxparse.MessageProcessor.error SAXParseException  e  )  throws SAXParseException
 

00093 { 00094 throw e; 00095 } // error

void saxparse.MessageProcessor.fatalError SAXParseException  e  )  throws SAXParseException
 

00099 { 00100 throw e; 00101 } // fatalError

void saxparse.MessageProcessor.startDocument  ) 
 

00104 { 00105 mCurrentState = States.STATE_ZERO; 00106 }

void saxparse.MessageProcessor.startElement String  uri,
String  localName,
String  qualName,
Attributes  attributes
 

00151 { 00152 if (mCurrentState == States.START_MSG) { 00153 mCurrentState = States.PROCESSING; 00154 } 00155 else { 00156 if (localName.equals("tradeEngine")) { 00157 mCurrentState = States.ENVELOPE; 00158 } 00159 else if (localName.equals("aim_order")) { 00160 mMessage = new AimOrderMessage(); 00161 mCurrentState = States.START_MSG; 00162 } 00163 else if (localName.equals("control")) { 00164 mMessage = new ControlMessage(); 00165 mCurrentState = States.START_MSG; 00166 } 00167 } 00168 00169 if (mMessage != null && mCurrentState == States.PROCESSING ) { 00170 mMessage.element( localName, attributes ); 00171 } 00172 } // startElement

void saxparse.MessageProcessor.warning SAXParseException  e  ) 
 

00087 { 00088 System.out.println("MessageProcessor: SAXWarning = " + e ); 00089 } // warning


Member Data Documentation

States saxparse.MessageProcessor.mCurrentState = States.BAD_STATE [private]
 

MessageInterface saxparse.MessageProcessor.mMessage = null [private]
 

ArrayList saxparse.MessageProcessor.mMsgList = null [private]
 


The documentation for this class was generated from the following file:
Generated on Sat Aug 28 13:50:04 2004 for SaxParse by doxygen 1.3.8