de.zeigermann.xpa.tokenParser
Class Parser2XMLTokenStreamAdapter

java.lang.Object
  |
  +--de.zeigermann.xpa.tokenParser.Parser2XMLTokenStreamAdapter
All Implemented Interfaces:
TokenStream
Direct Known Subclasses:
SAXDrivenTokenStream, XMLFragmentDrivenTokenStream

public abstract class Parser2XMLTokenStreamAdapter
extends Object
implements TokenStream

This abstract class provides base functionality to adapt XML parsers to a token stream needed by ANTLR genrated (token) parsers.

While the task of actually parsing something is delegated to its subclasses this class is capable of creating XML tokens from XML parsing data. Subclasses should call tellWhiteSpace(java.lang.String), tellPCDATA(java.lang.String), tellStartElement(java.lang.String, org.xml.sax.helpers.AttributesImpl), and tellEndDocument() to deliver this XML information.


Field Summary
protected  XMLTokenTypeManager tokenManager
           
 
Constructor Summary
Parser2XMLTokenStreamAdapter(XMLTokenTypeManager tokenManager)
          Creates a new adapter using tokenManager.
 
Method Summary
protected abstract  void applyLocatorInfo(Token token)
          Depending on implementation set line and column number of token if available.
 boolean getIgnoreAllWhiteSpace()
          Gets property described in setIgnoreAllWhiteSpace(boolean).
 boolean getTreatValidWhiteSpaceAsIgnorable()
          Gets property described in setTreatValidWhiteSpaceAsIgnorable(boolean).
abstract  Token nextToken()
          Gets the next token.
 void setIgnoreAllWhiteSpace(boolean ignoreAllWhiteSpace)
          Sets if all whitespace is ignored.
protected abstract  void setNextToken(Token token)
          Sets next token generated by adapter methods.
 void setTreatValidWhiteSpaceAsIgnorable(boolean treatValidWhiteSpaceAsIgnorable)
          Sets if valid whitespace is treated like ignoreable whitespace.
protected  void tellEndDocument()
          Tells this adapter that the XML document has now ended no no more call back will occur.
protected  void tellEndElement(String tag)
          Tells this adapter to make an XMLEndToken out of an end tag.
protected  void tellPCDATA(String pcdata)
          Tells this adapter to make an XMLToken out of parseable character data.
protected  void tellStartElement(String tag, AttributesImpl attributes)
          Tells this adapter to make an XMLStartToken out of a start tag.
protected  void tellWhiteSpace(String cdata)
          Tells this adapter to make an XMLToken out of whitespace.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tokenManager

protected XMLTokenTypeManager tokenManager
Constructor Detail

Parser2XMLTokenStreamAdapter

public Parser2XMLTokenStreamAdapter(XMLTokenTypeManager tokenManager)
Creates a new adapter using tokenManager.

Parameters:
tokenManager - the token manager to determine token types for token generation
Method Detail

nextToken

public abstract Token nextToken()
                         throws TokenStreamException
Gets the next token. Usually called by ANTLR generated parser.

Specified by:
nextToken in interface TokenStream
Returns:
token generated by parser that feeds this adapter
TokenStreamException
See Also:
setNextToken(antlr.Token)

applyLocatorInfo

protected abstract void applyLocatorInfo(Token token)
Depending on implementation set line and column number of token if available.


setNextToken

protected abstract void setNextToken(Token token)
Sets next token generated by adapter methods. It is in the responsibility of the subclassing parser to deliver tokens using nextToken() in exatcly the same order as set here. This contract is important if a queueing mechanism is used.

See Also:
nextToken()

setIgnoreAllWhiteSpace

public void setIgnoreAllWhiteSpace(boolean ignoreAllWhiteSpace)
Sets if all whitespace is ignored.
Default is false

See Also:
tellWhiteSpace(java.lang.String)

getIgnoreAllWhiteSpace

public boolean getIgnoreAllWhiteSpace()
Gets property described in setIgnoreAllWhiteSpace(boolean).


setTreatValidWhiteSpaceAsIgnorable

public void setTreatValidWhiteSpaceAsIgnorable(boolean treatValidWhiteSpaceAsIgnorable)
Sets if valid whitespace is treated like ignoreable whitespace.
Default is true

See Also:
tellPCDATA(java.lang.String)

getTreatValidWhiteSpaceAsIgnorable

public boolean getTreatValidWhiteSpaceAsIgnorable()
Gets property described in setTreatValidWhiteSpaceAsIgnorable(boolean).


tellWhiteSpace

protected void tellWhiteSpace(String cdata)
Tells this adapter to make an XMLToken out of whitespace. In fact this adapter will only make a token out of it if not forbidden by setIgnoreAllWhiteSpace(boolean). Also, if the underlying token manager has no type for whitespace, no token will be created.

Parameters:
cdata - the whitespace this adapter is notified of
See Also:
setIgnoreAllWhiteSpace(boolean)

tellPCDATA

protected void tellPCDATA(String pcdata)
Tells this adapter to make an XMLToken out of parseable character data. If valid whitespace is treated like ignoreable whitespace as defined by setTreatValidWhiteSpaceAsIgnorable(boolean) whitespace reported by this method will be forwarded to tellWhiteSpace(java.lang.String).

Parameters:
pcdata - the parseable character data this adapter is notified of
See Also:
setTreatValidWhiteSpaceAsIgnorable(boolean)

tellStartElement

protected void tellStartElement(String tag,
                                AttributesImpl attributes)
Tells this adapter to make an XMLStartToken out of a start tag.

Parameters:
tag - name of this start tag
attributes - attributes associated to this start tag

tellEndElement

protected void tellEndElement(String tag)
Tells this adapter to make an XMLEndToken out of an end tag.

Parameters:
tag - name of this end tag

tellEndDocument

protected void tellEndDocument()
Tells this adapter that the XML document has now ended no no more call back will occur. This method generates an XMLToken for EOF as ANTLR generated (token) parsers expect it.



Copyright © 1999-2003 Oliver Zeigermann. All Rights Reserved.