de.zeigermann.xpa.treeParser
Class XMLAST

java.lang.Object
  |
  +--antlr.BaseAST
        |
        +--antlr.CommonAST
              |
              +--de.zeigermann.xpa.treeParser.XMLAST
All Implemented Interfaces:
AST, Serializable
Direct Known Subclasses:
XMLStartAST

public class XMLAST
extends CommonAST

The XMLAST class is the basic class to represent AST for XML data. This class is used to represent XML nodes that contain PCDATA and to provide a set of convenience methods to transform ASTs low level.

Even though it is an AST node this class does not expect to have any children, as it is text only. XMLStartAST is the class to contain children.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class antlr.BaseAST
down, right
 
Constructor Summary
XMLAST()
          Create a new new empty XMLAST.
XMLAST(int type, String text)
          Creates a new XMLAST.
XMLAST(Token t)
          Creates a new XMLAST.
XMLAST(XMLAST b)
          Copy ctor.
 
Method Summary
 XMLAST addSibling(XMLAST sibling)
          Adds a new sibling to this element.
 XMLAST getLastChild()
          Adds a new sibling to this element.
 XMLAST getLastSibling()
          Gets the last sibling of this element, if there is one, otherwise null.
 XMLAST getPreviousSiblingFlat(XMLAST inTree)
          Gets the sibling left to me or null if there is none.
 XMLAST noRoot()
          Chops off root of tree, leaving only first child.
 XMLAST reverseFlat()
          Destructive method that reverses a flat tree.
 String toString()
          Gets a simple string representation of this token.
 void updateTokenTypes(XMLTokenTypeManager tokenManager)
          Resets the type of XMLTokenTypeManager.PCDATA for this XMLAST.
 void write(XMLWriter writer)
          Writes itself to XML writer.
 
Methods inherited from class antlr.CommonAST
getText, getType, initialize, initialize, initialize, setText, setType
 
Methods inherited from class antlr.BaseAST
addChild, decode, encode, equals, equalsList, equalsListPartial, equalsTree, equalsTreePartial, findAll, findAllPartial, getFirstChild, getNextSibling, getNumberOfChildren, removeChildren, setFirstChild, setNextSibling, setVerboseStringConversion, toStringList, toStringTree, xmlSerialize, xmlSerializeNode, xmlSerializeRootClose, xmlSerializeRootOpen
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XMLAST

public XMLAST()
Create a new new empty XMLAST.


XMLAST

public XMLAST(int type,
              String text)
Creates a new XMLAST.

Parameters:
type - the type of the AST, usually the type of XMLTokenTypeManager.PCDATA.
text - the text of the AST

XMLAST

public XMLAST(Token t)
Creates a new XMLAST.

Parameters:
t - the token to get type and text from

XMLAST

public XMLAST(XMLAST b)
Copy ctor.

Method Detail

toString

public String toString()
Gets a simple string representation of this token. Not intended for writing back to XML.

Specified by:
toString in interface AST
Overrides:
toString in class BaseAST
See Also:
write(de.zeigermann.xml.XMLWriter)

write

public void write(XMLWriter writer)
           throws IOException
Writes itself to XML writer. This method is intended to write back XMLASTs to XML documents.

IOException

updateTokenTypes

public void updateTokenTypes(XMLTokenTypeManager tokenManager)
Resets the type of XMLTokenTypeManager.PCDATA for this XMLAST. This is needed when we want to change the token types of an existing XMLAST.


noRoot

public XMLAST noRoot()
Chops off root of tree, leaving only first child.


addSibling

public XMLAST addSibling(XMLAST sibling)
Adds a new sibling to this element.


getLastChild

public XMLAST getLastChild()
Adds a new sibling to this element.


getLastSibling

public XMLAST getLastSibling()
Gets the last sibling of this element, if there is one, otherwise null.


reverseFlat

public XMLAST reverseFlat()
Destructive method that reverses a flat tree.
Flat tree "( 1 2 3 4 )" will be transformed like that:


this right this right
1 -> 2 4 -> 3
2 -> 3 ---> 3 -> 2
3 -> 4 ---> 2 -> 1
4 -> NULL 1 -> NULL

This means:
  1. swap left with right
  2. make last first


getPreviousSiblingFlat

public XMLAST getPreviousSiblingFlat(XMLAST inTree)
Gets the sibling left to me or null if there is none. Can be compared to BaseAST.getNextSibling() which gets the sibling right to me.

Parameters:
inTree - the root AST of this AST


Copyright 1999-2003 Oliver Zeigermann. All Rights Reserved.