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

pullparse.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 printXMLPullError (XmlPullParserException e, String xmlFileName)
void test (String[] args)
 Use the SAX parser to parse trade engine messages read from a file.


Member Function Documentation

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

00164 { 00165 TestMain t = new TestMain(); 00166 t.test( args ); 00167 }

boolean pullparse.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).

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

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

Print the trade engine messages to standard output.

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

void pullparse.TestMain.printXMLPullError XmlPullParserException  e,
String  xmlFileName
[private]
 

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

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

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

00126 { 00127 if (args.length >= 1 && args.length <= 2) { 00128 String xmlFileName = null; 00129 boolean validate = true; 00130 for (int i = 0; i < args.length; i++) { 00131 switch (i) { 00132 case 0: 00133 xmlFileName = args[0]; 00134 break; 00135 case 1: 00136 String validateFlag = args[1]; 00137 validate = parseValidateFlag( validateFlag ); 00138 break; 00139 } // switch; 00140 } // for 00141 FileReader reader = null; 00142 try { 00143 reader = new FileReader( xmlFileName ); 00144 ParseXML parse = new ParseXML( false ); 00145 ArrayList msgList = new ArrayList(); 00146 parse.parse( reader, msgList ); 00147 printList( msgList ); 00148 } catch (FileNotFoundException e) { 00149 System.out.println("Error opening file " + xmlFileName + " = " + e); 00150 } catch (IOException e1) { 00151 System.out.println(xmlFileName + ": IOException = " + e1 ); 00152 } catch (XmlPullParserException e2) { 00153 printXMLPullError( e2, xmlFileName ); 00154 } 00155 catch (ParseException e3) { 00156 System.out.println( e3 ); 00157 } 00158 } 00159 else { 00160 usage(); 00161 } 00162 } // test

void pullparse.TestMain.usage  )  [private]
 

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


The documentation for this class was generated from the following file:
Generated on Sat Aug 28 14:08:27 2004 for PullParse by doxygen 1.3.8