org.das2.dasml
Class DasMLValidator

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by org.das2.dasml.DasMLValidator
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

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

A validator for the dasML language developed for the University of Iowa Space Plasma Wave Group. This class is used as a pre-processor to (hopefully) provide clear and helpful error messages. Warning: This class is not thread-safe. Unexpected results can occur if multiple threads use an instance of this class concurrently.


Field Summary
static java.util.regex.Pattern FLOAT_PATTERN
           
static java.util.regex.Pattern INTEGER_PATTERN
           
static java.util.regex.Pattern WINDOW_POSITION_PATTERN
           
 
Constructor Summary
DasMLValidator()
          Creates a new instance of DasMLValidator
 
Method Summary
 void endDocument()
          Receive notification of the end of the document.
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
           
 void error(org.xml.sax.SAXParseException e)
          Receive notification of a recoverable parser error.
 void fatalError(org.xml.sax.SAXParseException e)
          Report a fatal XML parsing error.
 org.xml.sax.SAXException getLastError()
          Returns the last error encountered by this validator or null if no error has been found.
static void main(java.lang.String[] args)
           
 void setDocumentLocator(org.xml.sax.Locator locator)
          Receive a Locator object for document events.
 void startDocument()
          Receive notification of the beginning of the document.
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes)
          Receive notification of the start of an element.
 boolean validate(org.xml.sax.InputSource source, org.xml.sax.ErrorHandler errorHandler)
          Parses and validates a dasML document.
 void warning(org.xml.sax.SAXParseException e)
          Receive notification of a parser warning.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
characters, endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, skippedEntity, startPrefixMapping, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INTEGER_PATTERN

public static java.util.regex.Pattern INTEGER_PATTERN

WINDOW_POSITION_PATTERN

public static java.util.regex.Pattern WINDOW_POSITION_PATTERN

FLOAT_PATTERN

public static java.util.regex.Pattern FLOAT_PATTERN
Constructor Detail

DasMLValidator

public DasMLValidator()
               throws javax.xml.parsers.ParserConfigurationException,
                      org.xml.sax.SAXException
Creates a new instance of DasMLValidator

Throws:
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
Method Detail

validate

public boolean validate(org.xml.sax.InputSource source,
                        org.xml.sax.ErrorHandler errorHandler)
                 throws java.io.IOException
Parses and validates a dasML document. All errors are passed to the ErrorHandler instance specified. SAXExceptions thrown by the underlying parser are caught and suppressed by this method. If an application needs access to the errors, an ErrorHandler must be provided.

Parameters:
source - The source of the XML document
errorHandler - The ErrorHandler instance that will receive error messages from the parser. This can be null
Returns:
true if the document is a valid dasML document.
Throws:
IOException - if the there is an error while reading the document.

getLastError

public org.xml.sax.SAXException getLastError()
Returns the last error encountered by this validator or null if no error has been found. This method will only return an error if the last call to validate(InputSource, ErrorHandler) returned false. If an application wishes to have access to warnings and non-fatal errors then an ErrorHandler must be provided.


fatalError

public void fatalError(org.xml.sax.SAXParseException e)
                throws org.xml.sax.SAXException
Report a fatal XML parsing error.

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

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator locator)
Receive a Locator object for document events.

Specified by:
setDocumentLocator in interface org.xml.sax.ContentHandler
Overrides:
setDocumentLocator in class org.xml.sax.helpers.DefaultHandler
Parameters:
locator - A locator for all SAX document events.
See Also:
ContentHandler.setDocumentLocator(org.xml.sax.Locator), Locator

error

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

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

warning

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

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

startDocument

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

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:
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 start of an element.

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Parameters:
qName - The element type name.
attributes - The specified or defaulted attributes.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)

endDocument

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

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:
ContentHandler.endDocument()

main

public static void main(java.lang.String[] args)

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String qName)
                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