uk.ac.ic.doc.automed.xml
Class XMLReader

java.lang.Object
  extended by org.xml.sax.HandlerBase
      extended by uk.ac.ic.doc.automed.xml.XMLReader
All Implemented Interfaces:
org.xml.sax.DocumentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, XMLifyConstants

public class XMLReader
extends org.xml.sax.HandlerBase
implements XMLifyConstants


Nested Class Summary
 
Nested classes/interfaces inherited from interface uk.ac.ic.doc.automed.xml.XMLifyConstants
XMLifyConstants.IgnoreNextElementException
 
Field Summary
private  int bufferSize
           
private  boolean debug
           
private static int defBufferSize
           
private  java.util.LinkedList errors
           
private  boolean finished
           
private  org.xml.sax.Locator locator
           
private  java.lang.Thread parserThread
           
private  boolean separateErrors
           
private static javax.xml.parsers.SAXParserFactory spf
           
private  java.util.Set supressedTokenTypes
           
private  boolean supressIgnorableWhitespace
           
private  boolean throwErrors
           
private  java.util.LinkedList tokens
           
 
Fields inherited from interface uk.ac.ic.doc.automed.xml.XMLifyConstants
CHARACTERS, CHILDREN, DEFINITIVE, DEFINITIVE_CHILDREN, DEFINITIVE_CHILDREN_RECURSE, DEFINITIVE_MEMBER, DEFINITIVE_MEMBER_AND_CHILDREN, DEFINITIVE_MEMBER_RECURSE, END_DOCUMENT, END_ELEMENT, ERROR, EXCLUDE, EXCLUDE_MEMBER, FATAL_ERROR, FIRSTPASS, IGNORABLE_WHITESPACE, MEMBER, NOTATION_DECL, OBJECT, OBJECT_CHILDREN, OBJECT_CHILDREN_RECURSE, OBJECT_MEMBER, OBJECT_MEMBER_AND_CHILDREN, OBJECT_MEMBER_RECURSE, ONEPASS, PRIMITIVE, PRIMITIVE_CHILDREN, PRIMITIVE_CHILDREN_RECURSE, PRIMITIVE_MEMBER, PRIMITIVE_MEMBER_AND_CHILDREN, PRIMITIVE_MEMBER_RECURSE, PROCESSING_INSTRUCTION, RECURSE, REFERENCE, REFERENCE_CHILDREN, REFERENCE_CHILDREN_RECURSE, REFERENCE_MEMBER, REFERENCE_MEMBER_AND_CHILDREN, REFERENCE_MEMBER_RECURSE, SAX_ERROR, SECONDPASS, START_DOCUMENT, START_ELEMENT, UNPARSED_ENTITY_DECL, WARNING
 
Constructor Summary
XMLReader()
           
XMLReader(int bufferSize)
           
 
Method Summary
 void addSupressedTokenType(int type)
           
 void addSupressedTokenTypes(int[] types)
           
private  void addToken(int type, java.lang.String name, java.lang.Object datum)
           
 void characters(char[] ch, int start, int length)
           
 void close()
          call this if you intend to stop reading tokens and haven't read an END_DOCUMENT or SAX_ERROR token this will not return until the parser thread completes or it times out at which point it throws an XMLReaderException.
 void close(int milliseconds)
           
 void endDocument()
           
 void endElement(java.lang.String name)
           
 void error(org.xml.sax.SAXParseException exception)
           
 void fatalError(org.xml.sax.SAXParseException exception)
           
 int getBufferSize()
           
 boolean getDebug()
           
private  java.lang.String getLocation()
           
private  java.lang.String getLocationPad()
           
 boolean getSeparateErrors()
          by default, errors are reported through the token stream, for parsing this may not be convenient you can have errors reported through getErrors() instead by setting separateErrors to true
 int[] getSupressedTokenTypes()
           
 boolean getSupressIgnorableWhitespace()
          The supressIgnorableWhitespace property and supressTokenTypes list are different in knid.
 boolean getThrowErrors()
          all errors are reported through the token stream or through the error stream, by setting throwErrors you can have nextToken and peekToken throw an exception if the next token is an error.
private  java.lang.String getTokenList(int[] list)
           
 void ignorableWhitespace(char[] ch, int start, int length)
           
 boolean isNamespaceAware()
           
 boolean isTokenTypeSupressed(int type)
           
 boolean isValidating()
           
 XMLToken nextError()
          If separateErrors is set to true and nextToken() or peekToken() have (or would on next call) returned return null then getNextError will keep returning errors until the list is exhausted at which point it will return null otherwise it will just return null
private  XMLToken nextSingleToken()
           
 XMLToken nextToken()
           
 XMLToken nextToken(int type)
           
 XMLToken nextToken(int[] types)
           
 XMLToken nextToken(int[] types, java.lang.String[] names)
           
 XMLToken nextToken(int type, java.lang.String name)
          throws an XMLReaderException if the next element or its name is not of the expected type
 void notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
           
 XMLToken peekError()
           
private  XMLToken peekSingleToken()
           
 XMLToken peekToken()
           
 void processingInstruction(java.lang.String target, java.lang.String data)
           
 void removeSupressedTokenType(int type)
           
 void removeSupressedTokenTypes(int[] types)
           
 org.xml.sax.InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId)
           
 void setDebug(boolean b)
           
 void setDocumentLocator(org.xml.sax.Locator locator)
           
 void setNamespaceAware(boolean b)
           
 void setSeparateErrors(boolean b)
           
 void setSupressedTokenTypes(int[] types)
           
 void setSupressIgnorableWhitespace(boolean b)
           
 void setThrowErrors(boolean b)
           
 void setValidating(boolean b)
           
 void skipTokens(int type)
           
 void skipTokens(int[] types)
           
 XMLToken skipToNextToken(int type)
           
 XMLToken skipToNextToken(int[] types)
           
 void start(org.xml.sax.InputSource is)
           
 void start(java.lang.String filename)
           
 void startDocument()
           
 void startElement(java.lang.String name, org.xml.sax.AttributeList atts)
           
 void unparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName)
           
 void warning(org.xml.sax.SAXParseException exception)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

spf

private static javax.xml.parsers.SAXParserFactory spf

tokens

private java.util.LinkedList tokens

errors

private java.util.LinkedList errors

debug

private boolean debug

defBufferSize

private static int defBufferSize

bufferSize

private final int bufferSize

locator

private org.xml.sax.Locator locator

finished

private boolean finished

parserThread

private java.lang.Thread parserThread

separateErrors

private boolean separateErrors

throwErrors

private boolean throwErrors

supressIgnorableWhitespace

private boolean supressIgnorableWhitespace

supressedTokenTypes

private java.util.Set supressedTokenTypes
Constructor Detail

XMLReader

public XMLReader()

XMLReader

public XMLReader(int bufferSize)
Method Detail

getBufferSize

public int getBufferSize()

getDebug

public boolean getDebug()

setDebug

public void setDebug(boolean b)

getSeparateErrors

public boolean getSeparateErrors()
by default, errors are reported through the token stream, for parsing this may not be convenient you can have errors reported through getErrors() instead by setting separateErrors to true


setSeparateErrors

public void setSeparateErrors(boolean b)

getThrowErrors

public boolean getThrowErrors()
all errors are reported through the token stream or through the error stream, by setting throwErrors you can have nextToken and peekToken throw an exception if the next token is an error. If you specify separateErrors and throwErrors, the SAXException following a fatal error will get thrown, all warnings, errors and the actual fatal error will then be available through nextError() as would warnings and errors if there were no fatal error


setThrowErrors

public void setThrowErrors(boolean b)

getSupressIgnorableWhitespace

public boolean getSupressIgnorableWhitespace()
The supressIgnorableWhitespace property and supressTokenTypes list are different in knid. supressIgnorableWhitespace is implemented in the stream so no IGNORABLE_WHIYESPACE tokens ever get added to the token buffer. The supressedTokenTypes list is used by all variants of nextToken, peekToken and skipTokens to transparently skip these tokens. supressedTokenTypes can be changed dynamically while parsing in a context sensitive manner but due to there being a separate thread to fill the token buffer, the supressIgnorableWhitespace should not be changed once parsing commences (the effect of doing so would be delayed by the size of the buffer). setting supressIgnorableWhitespace only has an effect if a dtd is declared in the xml and a validating parser is used, otherwise the SAX parser cannot know what is ignorable and all white space is reported as CHARACTERS. If all ignorable whitespace is to be ignored, it is more effecient to use supressIgnorableWhitespace than to add IGNORABLE_WHITESPACE to the supressTokenTypes list.


setSupressIgnorableWhitespace

public void setSupressIgnorableWhitespace(boolean b)

isTokenTypeSupressed

public boolean isTokenTypeSupressed(int type)

getSupressedTokenTypes

public int[] getSupressedTokenTypes()

setSupressedTokenTypes

public void setSupressedTokenTypes(int[] types)

addSupressedTokenType

public void addSupressedTokenType(int type)

addSupressedTokenTypes

public void addSupressedTokenTypes(int[] types)

removeSupressedTokenType

public void removeSupressedTokenType(int type)

removeSupressedTokenTypes

public void removeSupressedTokenTypes(int[] types)

isNamespaceAware

public boolean isNamespaceAware()

setNamespaceAware

public void setNamespaceAware(boolean b)

isValidating

public boolean isValidating()

setValidating

public void setValidating(boolean b)

start

public void start(java.lang.String filename)
           throws javax.xml.parsers.ParserConfigurationException,
                  org.xml.sax.SAXException,
                  java.io.IOException,
                  java.lang.IllegalArgumentException
Throws:
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException
java.lang.IllegalArgumentException

start

public void start(org.xml.sax.InputSource is)
           throws javax.xml.parsers.ParserConfigurationException,
                  org.xml.sax.SAXException,
                  java.io.IOException,
                  java.lang.IllegalArgumentException
Throws:
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException
java.lang.IllegalArgumentException

nextError

public XMLToken nextError()
                   throws java.lang.Exception
If separateErrors is set to true and nextToken() or peekToken() have (or would on next call) returned return null then getNextError will keep returning errors until the list is exhausted at which point it will return null otherwise it will just return null

Throws:
java.lang.Exception

peekError

public XMLToken peekError()
                   throws java.lang.Exception
Throws:
java.lang.Exception

skipTokens

public void skipTokens(int type)
                throws java.lang.Exception
Throws:
java.lang.Exception

skipTokens

public void skipTokens(int[] types)
                throws java.lang.Exception
Throws:
java.lang.Exception

skipToNextToken

public XMLToken skipToNextToken(int type)
                         throws java.lang.Exception
Throws:
java.lang.Exception

skipToNextToken

public XMLToken skipToNextToken(int[] types)
                         throws java.lang.Exception
Throws:
java.lang.Exception

nextToken

public XMLToken nextToken(int type,
                          java.lang.String name)
                   throws java.lang.Exception
throws an XMLReaderException if the next element or its name is not of the expected type

Throws:
java.lang.Exception

nextToken

public XMLToken nextToken(int[] types,
                          java.lang.String[] names)
                   throws java.lang.Exception
Throws:
java.lang.Exception

nextToken

public XMLToken nextToken(int type)
                   throws java.lang.Exception
Throws:
java.lang.Exception

nextToken

public XMLToken nextToken(int[] types)
                   throws java.lang.Exception
Throws:
java.lang.Exception

getTokenList

private java.lang.String getTokenList(int[] list)

nextToken

public XMLToken nextToken()
                   throws java.lang.Exception
Throws:
java.lang.Exception

nextSingleToken

private XMLToken nextSingleToken()
                          throws java.lang.Exception
Throws:
java.lang.Exception

peekToken

public XMLToken peekToken()
                   throws java.lang.Exception
Throws:
java.lang.Exception

peekSingleToken

private XMLToken peekSingleToken()
                          throws java.lang.Exception
Throws:
java.lang.Exception

close

public void close()
           throws XMLReaderException
call this if you intend to stop reading tokens and haven't read an END_DOCUMENT or SAX_ERROR token this will not return until the parser thread completes or it times out at which point it throws an XMLReaderException. Default timeout period is 1 minute All subsequent warnings and errors will still be added to the error list if separateErrors has been set

Throws:
XMLReaderException

close

public void close(int milliseconds)
           throws XMLReaderException
Throws:
XMLReaderException

resolveEntity

public org.xml.sax.InputSource resolveEntity(java.lang.String publicId,
                                             java.lang.String systemId)
                                      throws org.xml.sax.SAXException
Specified by:
resolveEntity in interface org.xml.sax.EntityResolver
Overrides:
resolveEntity in class org.xml.sax.HandlerBase
Throws:
org.xml.sax.SAXException

notationDecl

public void notationDecl(java.lang.String name,
                         java.lang.String publicId,
                         java.lang.String systemId)
Specified by:
notationDecl in interface org.xml.sax.DTDHandler
Overrides:
notationDecl in class org.xml.sax.HandlerBase

unparsedEntityDecl

public void unparsedEntityDecl(java.lang.String name,
                               java.lang.String publicId,
                               java.lang.String systemId,
                               java.lang.String notationName)
Specified by:
unparsedEntityDecl in interface org.xml.sax.DTDHandler
Overrides:
unparsedEntityDecl in class org.xml.sax.HandlerBase

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator locator)
Specified by:
setDocumentLocator in interface org.xml.sax.DocumentHandler
Overrides:
setDocumentLocator in class org.xml.sax.HandlerBase

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Specified by:
startDocument in interface org.xml.sax.DocumentHandler
Overrides:
startDocument in class org.xml.sax.HandlerBase
Throws:
org.xml.sax.SAXException

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
Specified by:
endDocument in interface org.xml.sax.DocumentHandler
Overrides:
endDocument in class org.xml.sax.HandlerBase
Throws:
org.xml.sax.SAXException

startElement

public void startElement(java.lang.String name,
                         org.xml.sax.AttributeList atts)
                  throws org.xml.sax.SAXException
Specified by:
startElement in interface org.xml.sax.DocumentHandler
Overrides:
startElement in class org.xml.sax.HandlerBase
Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String name)
                throws org.xml.sax.SAXException
Specified by:
endElement in interface org.xml.sax.DocumentHandler
Overrides:
endElement in class org.xml.sax.HandlerBase
Throws:
org.xml.sax.SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Specified by:
characters in interface org.xml.sax.DocumentHandler
Overrides:
characters in class org.xml.sax.HandlerBase
Throws:
org.xml.sax.SAXException

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws org.xml.sax.SAXException
Specified by:
ignorableWhitespace in interface org.xml.sax.DocumentHandler
Overrides:
ignorableWhitespace in class org.xml.sax.HandlerBase
Throws:
org.xml.sax.SAXException

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws org.xml.sax.SAXException
Specified by:
processingInstruction in interface org.xml.sax.DocumentHandler
Overrides:
processingInstruction in class org.xml.sax.HandlerBase
Throws:
org.xml.sax.SAXException

warning

public void warning(org.xml.sax.SAXParseException exception)
             throws org.xml.sax.SAXException
Specified by:
warning in interface org.xml.sax.ErrorHandler
Overrides:
warning in class org.xml.sax.HandlerBase
Throws:
org.xml.sax.SAXException

error

public void error(org.xml.sax.SAXParseException exception)
           throws org.xml.sax.SAXException
Specified by:
error in interface org.xml.sax.ErrorHandler
Overrides:
error in class org.xml.sax.HandlerBase
Throws:
org.xml.sax.SAXException

fatalError

public void fatalError(org.xml.sax.SAXParseException exception)
                throws org.xml.sax.SAXException
Specified by:
fatalError in interface org.xml.sax.ErrorHandler
Overrides:
fatalError in class org.xml.sax.HandlerBase
Throws:
org.xml.sax.SAXException

addToken

private void addToken(int type,
                      java.lang.String name,
                      java.lang.Object datum)
               throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

getLocation

private java.lang.String getLocation()

getLocationPad

private java.lang.String getLocationPad()