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

saxparse.TestMain Class Reference

List of all members.

Detailed Description

TestMain Aug 14, 2004.

A test driver for SAX Parsing. The main method is passed a file name and an optional flag that defines whether the parser should be validating or not.

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


Static Public Member Functions

void main (String[] args)

Private Member Functions

void usage ()
boolean parseValidateFlag (String validateFlag)
 Parse the validate flag.
void printList (ArrayList msgList)
 Print the trade engine messages to standard output.
void printSAXError (SAXParseException e, String xmlFileName)
void test (String[] args)
 Use the SAX parser to parse trade engine messages read from a file.


Member Function Documentation

void saxparse.TestMain.main String[]  args  )  [static]
 

00161 { 00162 TestMain t = new TestMain(); 00163 t.test( args ); 00164 }

boolean saxparse.TestMain.parseValidateFlag String  validateFlag  )  [private]
 

Parse the validate flag.

The flag will be either

               validate=false
               validate=true

If the flag has some other value the method will print a message and return true (since the value for the validate flag is true by default).

00060 { 00061 boolean validate = true; 00062 boolean flagOK = false; 00063 validateFlag = validateFlag.trim(); 00064 00065 if (validateFlag.startsWith("validate")) { 00066 int eqIx = validateFlag.indexOf("="); 00067 if (eqIx > 0) { 00068 String boolStr = validateFlag.substring( eqIx + 1 ); 00069 boolStr = boolStr.trim(); 00070 if (boolStr.equals("true") || boolStr.equals("false")) { 00071 flagOK = true; 00072 if (boolStr.equals("false")) { 00073 validate = false; 00074 } 00075 } 00076 } 00077 } 00078 00079 if (! flagOK) { 00080 String name = getClass().getName(); 00081 System.out.println("validate flag usage: \"validate=false\" or \"validate=true\""); 00082 } 00083 return validate; 00084 } // parseValidateFlag

void saxparse.TestMain.printList ArrayList  msgList  )  [private]
 

Print the trade engine messages to standard output.

00091 { 00092 int len = msgList.size(); 00093 for (int i = 0; i < len; i++) { 00094 Object obj = msgList.get( i ); 00095 if (obj instanceof AimOrder) { 00096 AimOrder t = (AimOrder)obj; 00097 System.out.println("Aim Order:"); 00098 System.out.println( t ); 00099 } 00100 else if (obj instanceof Control) { 00101 Control t = (Control)obj; 00102 System.out.println("Control:"); 00103 System.out.println( t ); 00104 } 00105 else { 00106 System.out.println("Unexpected object in msgList:" + 00107 obj.getClass().getName()); 00108 } 00109 } 00110 } // printList

void saxparse.TestMain.printSAXError SAXParseException  e,
String  xmlFileName
[private]
 

00114 { 00115 int lineNum = e.getLineNumber(); 00116 int columnNumber = e.getColumnNumber(); 00117 String exceptionMsg = e.getMessage(); 00118 String msg = xmlFileName + "(" + lineNum + ", " + columnNumber + "): " + exceptionMsg; 00119 System.out.println(msg); 00120 } // printSAXError

void saxparse.TestMain.test String[]  args  )  [private]
 

Use the SAX parser to parse trade engine messages read from a file.

00127 { 00128 if (args.length >= 1 && args.length <= 2) { 00129 String xmlFileName = null; 00130 boolean validate = true; 00131 for (int i = 0; i < args.length; i++) { 00132 switch (i) { 00133 case 0: 00134 xmlFileName = args[0]; 00135 break; 00136 case 1: 00137 String validateFlag = args[1]; 00138 validate = parseValidateFlag( validateFlag ); 00139 break; 00140 } // switch; 00141 } // for 00142 InputStream in = null; 00143 try { 00144 in = new FileInputStream( xmlFileName ); 00145 ArrayList msgList = new ArrayList(); 00146 MessageProcessor msgHandler = new MessageProcessor( msgList ); 00147 ParseMessage msgParser = new ParseMessage(); 00148 msgParser.parse( in, msgHandler, validate ); 00149 printList( msgList ); 00150 } catch (FileNotFoundException e) { 00151 System.out.println("Error opening file " + xmlFileName + " = " + e); 00152 } catch (SAXException e1) { 00153 printSAXError( (SAXParseException)e1, xmlFileName ); 00154 } 00155 } 00156 else { 00157 usage(); 00158 } 00159 } // test

void saxparse.TestMain.usage  )  [private]
 

00038 { 00039 String name = getClass().getName(); 00040 System.out.println("usage: " + name + "<XML fileName> [validate=true/false]"); 00041 System.out.println(" Where the <XML fileName> is the file name of an XML document"); 00042 System.out.println(" The default for validate is \"true\""); 00043 }


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