org.optimizationservices.oscommon.representationparser
Class FMLHandler

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by org.optimizationservices.oscommon.representationparser.FMLHandler
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class FMLHandler
extends org.xml.sax.helpers.DefaultHandler

The FMLHandler class is derived from the SAX DefaultHandler class. When the SAX parser encounter the start and end of elements, methods in FMLHandler are called. These methods return values for the element attributes and text content. These data are then used in the arguments for methods such as onConstraints in the class FMLReader.

Since:
OS 1.0
Version:
1.0, 03/14/2004
Author:
Robert Fourer, Jun Ma, Kipp Martin
See Also:
FMLReader, DefaultHandler

Constructor Summary
FMLHandler(FMLReader fmlParser)
          constructor of FMLHandler.
 
Method Summary
 void characters(char[] ch, int start, int length)
          Receive notification of character data.
 void endDocument()
          Receive notification of the end of a document.
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
          Receive notification of the end of an element.
 void error(org.xml.sax.SAXParseException e)
          Receive notification of a recoverable error.
 void fatalError(org.xml.sax.SAXParseException e)
          Receive notification of a non-recoverable error.
 void ignorableWhitespace(char[] ch, int start, int length)
          Receive notification of ignorable whitespace in element content.
static void main(java.lang.String[] argv)
          main for test purposes.
 void processingInstruction(java.lang.String target, java.lang.String data)
          Receive notification of a processing instruction.
 void startDocument()
          Receive notification of the beginning of a document.
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes)
          Receive notification of the beginning of an element.
 void warning(org.xml.sax.SAXParseException e)
          Receive notification of a warning.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, notationDecl, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FMLHandler

public FMLHandler(FMLReader fmlParser)
constructor of FMLHandler. FMLHandler is aware of the parser that registers it.

Parameters:
fmlParser - The FML Parser that registers this handler.
Method Detail

warning

public void warning(org.xml.sax.SAXParseException e)
             throws org.xml.sax.SAXException
Receive notification of a warning.

SAX parsers will use this method to report conditions that are not errors or fatal errors as defined by the XML 1.0 recommendation. The implemented behavior is to print the xml style warning message and set the warning flag true.

The SAX parser will continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end.

Specified by:
warning in interface org.xml.sax.ErrorHandler
Overrides:
warning in class org.xml.sax.helpers.DefaultHandler
Parameters:
e - The warning information encapsulated in a SAX parse exception.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
SAXParseException, ErrorHandler.warning(org.xml.sax.SAXParseException)

error

public void error(org.xml.sax.SAXParseException e)
           throws org.xml.sax.SAXException
Receive notification of a recoverable error.

This corresponds to the definition of "error" in section 1.2 of the W3C XML 1.0 Recommendation such as a validity constraint. The implemented behavior is to print the xml style error message and set the error flag true.

The SAX parser will continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end. If the application cannot do so, then the parser will report a fatal error.

Specified by:
error in interface org.xml.sax.ErrorHandler
Overrides:
error in class org.xml.sax.helpers.DefaultHandler
Parameters:
exception - The error information encapsulated in a SAX parse exception.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
SAXParseException, ErrorHandler.error(org.xml.sax.SAXParseException)

fatalError

public void fatalError(org.xml.sax.SAXParseException e)
                throws org.xml.sax.SAXException
Receive notification of a non-recoverable error.

This corresponds to the definition of "fatal error" in section 1.2 of the W3C XML 1.0 Recommendation, such as a well-formedness constraint.The implemented behavior is to print the xml style error message and set the fatalError flag true.

The application will assume that the document is unusable after the parser has invoked this method, and will continue (if at all) only for the sake of collecting addition error messages: in fact, SAX parsers are free to stop reporting any other events once this method has been invoked.

Specified by:
fatalError in interface org.xml.sax.ErrorHandler
Overrides:
fatalError in class org.xml.sax.helpers.DefaultHandler
Parameters:
exception - The error information encapsulated in a SAX parse exception.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
SAXParseException, ErrorHandler.fatalError(org.xml.sax.SAXParseException)

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws org.xml.sax.SAXException
Receive notification of a processing instruction.

The Parser will invoke this method once for each processing instruction found: note that processing instructions may occur before or after the main document element.

The implemented method uses the default behavior from the super class DefaultHandler

Specified by:
processingInstruction in interface org.xml.sax.ContentHandler
Overrides:
processingInstruction in class org.xml.sax.helpers.DefaultHandler
Parameters:
target - The processing instruction target.
data - The processing instruction data, or null if none was supplied. The data does not include any whitespace separating it from the target.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.processingInstruction(java.lang.String, java.lang.String)

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws org.xml.sax.SAXException
Receive notification of ignorable whitespace in element content.

The implemented method uses the default behavior from the super class DefaultHandler

Specified by:
ignorableWhitespace in interface org.xml.sax.ContentHandler
Overrides:
ignorableWhitespace in class org.xml.sax.helpers.DefaultHandler
Parameters:
ch - The characters from the XML document.
start - The start position in the array.
length - The number of characters to read from the array.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
characters(char[], int, int), ContentHandler.ignorableWhitespace(char[], int, int)

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Receive notification of character data.

The method stores the current characters in a string corresponding to each of the following element, to be processed later.

  1. <el>
  2. <maxOrMin>
  3. <numberRows>
  4. <numberVars>
  5. <objConstant>
  6. <source>
  7. <status>
  8. <optimalValue>
  9. <solverMessage>

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler
Parameters:
ch - The characters from the XML document.
start - The start position in the array.
length - The number of characters to read from the array.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ignorableWhitespace(char[], int, int), Locator, ContentHandler.characters(char[], int, int)

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Receive notification of the beginning of a document.

The SAX parser will invoke this method only once, before any other methods in this interface or in DTDHandler (except for setDocumentLocator).

The implemented method uses the default behavior from the super class DefaultHandler

Specified by:
startDocument in interface org.xml.sax.ContentHandler
Overrides:
startDocument in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
endDocument(), ContentHandler.startDocument()

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes attributes)
                  throws org.xml.sax.SAXException
Receive notification of the beginning of an element. The implemented method assumes valid FML, detects elements defined by the schema, and stores necessary information to be later used by the method endElement.

The Parser will invoke this method at the beginning of every element in the XML document; there will be a corresponding endElement event for every startElement event (even when the element is empty). All of the element's content will be reported, in order, before the corresponding endElement event.

This event allows up to three name components for each element:

  1. the Namespace URI;
  2. the local name; and
  3. the qualified (prefixed) name.

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The qualified name (with prefix), or the empty string if qualified names are not available.
atts - The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
endElement(java.lang.String, java.lang.String, java.lang.String), Attributes, ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
Receive notification of the end of an element.

The SAX parser will invoke this method at the end of every element in the XML document; there will be a corresponding startElement event for every endElement event (even when the element is empty).

For information on the names, see startElement.

Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The qualified XML 1.0 name (with prefix), or the empty string if qualified names are not available.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes), ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
Receive notification of the end of a document.

The SAX parser will invoke this method only once, and it will be the last method invoked during the parse. The parser will not invoke this method until it has either abandoned parsing (because of an unrecoverable error) or reached the end of input.

The implemented method uses the default behavior from the super class DefaultHandler

Specified by:
endDocument in interface org.xml.sax.ContentHandler
Overrides:
endDocument in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
startDocument(), ContentHandler.endDocument()

main

public static void main(java.lang.String[] argv)
main for test purposes.

Parameters:
argv - command line arguments.