de.zeigermann.xpa.treeParser
Class Parser2XMLASTAdapter

java.lang.Object
  |
  +--de.zeigermann.xpa.treeParser.Parser2XMLASTAdapter
Direct Known Subclasses:
SAXDrivenASTParser, XMLFragmentDrivenASTParser

public abstract class Parser2XMLASTAdapter
extends Object

This abstract class is the superclass of all parser classes that generate XMLASTs that are useable by XPA.

While the task of actually parsing something is delegated to its subclasses this class is capable of creating a correctly structured and correctly typed XMLAST. Subclasses call tellStartDocument(), tellPCDATA(java.lang.String), tellStartElement(java.lang.String, org.xml.sax.Attributes) and tellEndElement(java.lang.String) to tell this class what XMLAST to construct.


Field Summary
protected  XMLTokenTypeManager tokenManager
           
protected  XMLAST tree
          Tree construction pointer
protected  Stack treeStack
          Keep track of document structure
 
Constructor Summary
Parser2XMLASTAdapter(XMLTokenTypeManager tokenManager)
          Creates a new adapter using tokenManager.
 
Method Summary
 XMLAST getAST()
          Gets the XMLAST created by this adapter.
 boolean getIgnoreAllWhiteSpace()
          Gets property described in setIgnoreAllWhiteSpace(boolean).
 boolean getTreatValidWhiteSpaceAsIgnorable()
          Gets property described in setTreatValidWhiteSpaceAsIgnorable(boolean).
abstract  void parse(InputStream in)
          Parses a XML from an input stream
abstract  void parse(Reader in)
          Parses a XML from a reader.
 void parse(String in)
          Parses a XML from a string.
 void setIgnoreAllWhiteSpace(boolean ignoreAllWhiteSpace)
          Sets if all whitespace is ignored.
 void setTreatValidWhiteSpaceAsIgnorable(boolean treatValidWhiteSpaceAsIgnorable)
          Sets if valid whitespace is treated like ignoreable whitespace.
protected  void tellEndElement(String name)
          Tells this adapter to that the current element now closes.
protected  void tellPCDATA(String pcdata)
          Tells this adapter to create an XMLAST out of parseable character data and link it to the tree returned by getAST().
protected  void tellStartDocument()
          Tells this adapter that the XML document has started.
protected  void tellStartElement(String name, Attributes attributes)
          Tells this adapter to created and link an XMLStartAST out of a start tag.
protected  void tellWhiteSpace(String pcdata)
          Tells this adapter to create an XMLAST out of this whitespace and link it to the tree returned by getAST().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tree

protected XMLAST tree
Tree construction pointer


treeStack

protected Stack treeStack
Keep track of document structure


tokenManager

protected XMLTokenTypeManager tokenManager
Constructor Detail

Parser2XMLASTAdapter

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

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

parse

public abstract void parse(Reader in)
                    throws XPAParseException
Parses a XML from a reader.

Parameters:
in - the reader to parse from
XPAParseException

parse

public abstract void parse(InputStream in)
                    throws XPAParseException
Parses a XML from an input stream

Parameters:
in - the input stream to parse from
XPAParseException

parse

public void parse(String in)
           throws XPAParseException
Parses a XML from a string.

Parameters:
in - the string to parse
XPAParseException

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


getAST

public XMLAST getAST()
Gets the XMLAST created by this adapter.


tellPCDATA

protected void tellPCDATA(String pcdata)
Tells this adapter to create an XMLAST out of parseable character data and link it to the tree returned by getAST(). 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), getAST()

tellWhiteSpace

protected void tellWhiteSpace(String pcdata)
Tells this adapter to create an XMLAST out of this whitespace and link it to the tree returned by getAST(). In fact this adapter will only create and link an an XMLAST out of it if not forbidden by setIgnoreAllWhiteSpace(boolean). Also, if the underlying token manager has no type for whitespace, no XMLAST will be added.

See Also:
setIgnoreAllWhiteSpace(boolean), getAST()

tellStartDocument

protected void tellStartDocument()
Tells this adapter that the XML document has started. This method must be called before any other call back methods, to allow this adapter to initialize.


tellStartElement

protected void tellStartElement(String name,
                                Attributes attributes)
Tells this adapter to created and link an XMLStartAST out of a start tag.

Parameters:
name - name of this start tag
attributes - attributes associated to this start tag
See Also:
getAST()

tellEndElement

protected void tellEndElement(String name)
Tells this adapter to that the current element now closes. There in no need to create an AST for this, as ends of elements are implied by the structure of the generated XMLAST.

Parameters:
name - name of this end tag


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