Package org.gjt.xpp.impl.pullnode
Class PullNode
- java.lang.Object
-
- org.gjt.xpp.impl.tag.Tag
-
- org.gjt.xpp.impl.tag.StartTag
-
- org.gjt.xpp.impl.node.Node
-
- org.gjt.xpp.impl.pullnode.PullNode
-
- All Implemented Interfaces:
XmlNode
,XmlPullNode
,XmlStartTag
,XmlTag
public class PullNode extends Node implements XmlPullNode
Allows node tree to be constructed on demand. When PullNode is constructed and method setPullPasrser() is executed (or constructor with PullParser arg is called) node is assumend to be incomplete and children will be retrieved on demand (pulled) including automatic creation of sub pull nodes. If no pull parser is associated (it is null) this class must work like regular XmlNode...- Author:
- Aleksander Slominski
-
-
Field Summary
Fields Modifier and Type Field Description protected int
depth
protected XmlPullParser
pp
-
Fields inherited from class org.gjt.xpp.impl.node.Node
children, childrenCount, declaredNs, declaredNsEnd, declaredPrefixes, defaultNamespaceUri, EMPTY_ENUMERATION, oneChild, parent, prefix2Ns
-
-
Constructor Summary
Constructors Constructor Description PullNode(XmlPullParser pp)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
appendChild(java.lang.Object child)
java.util.Enumeration
children()
This is not recommened method to pull children when node is not finished (use readNextChild() instead) as Enumeration interface does not allow to throw XmlPullParserException so any parsing exeption is wrapped into RuntimeException making code more messy...java.lang.Object
getChildAt(int pos)
int
getChildrenCount()
it will reconsruct whole subtree to get count ...int
getChildrenCountSoFar()
if unfinished it returns actual number of children...XmlPullParser
getPullParser()
Get parser that is use to build this node tree and this pull node becomes finished - the caller is responsibile to move pull parser state to the end tag of this node (or parent pull node will be left in unconsistent state!!!!).void
insertChildAt(int pos, java.lang.Object child)
boolean
isFinished()
Is pull parsing of node finished.XmlNode
newNode()
context sensitive factory method to create the same type of nodeXmlPullNode
newPullNode(XmlPullParser pp)
protected void
printFields(java.lang.StringBuffer buf)
Print this class state into StringBuffer element namevoid
readChildren()
Read all reminaing children up to end tag.java.lang.Object
readNextChild()
This is preferred method to pull children (children() requires .wrapping object Enumeration).void
removeChildAt(int pos)
void
removeChildren()
Removes all children - every child that was implementing XmlNode will have set parent to null.void
replaceChildAt(int pos, java.lang.Object child)
void
resetPullNode()
PullNode stays in finished state.void
setPullParser(XmlPullParser pp)
Reset pull node to use pull parser.void
skipChildren()
java.lang.String
toString()
Return string representation of start tag including name and list of attributes.-
Methods inherited from class org.gjt.xpp.impl.node.Node
addDeclaredNamespaces, addNamespaceDeclaration, ensureChildrenCapacity, ensureDeclaredNamespacesCapacity, equals, getDeclaredNamespaceLength, getDefaultNamespaceUri, getParentNode, getQNameLocal, getQNameUri, namespace2Prefix, newNode, prefix2Namespace, readDeclaredNamespaceUris, readDeclaredPrefixes, removeDeclaredNamespaces, resetNode, setDefaultNamespaceUri, setParentNode
-
Methods inherited from class org.gjt.xpp.impl.tag.StartTag
addAttribute, addAttribute, ensureAttributesCapacity, getAttributeCount, getAttributeLocalName, getAttributeNamespaceUri, getAttributePrefix, getAttributeRawName, getAttributeValue, getAttributeValueFromName, getAttributeValueFromRawName, isAttributeNamespaceDeclaration, removeAttributeByName, removeAttributeByRawName, removeAttributes, resetStartTag
-
Methods inherited from class org.gjt.xpp.impl.tag.Tag
getLocalName, getNamespaceUri, getPrefix, getRawName, hashCode, modifyTag, resetTag
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.gjt.xpp.XmlNode
addDeclaredNamespaces, addNamespaceDeclaration, ensureChildrenCapacity, ensureDeclaredNamespacesCapacity, getDeclaredNamespaceLength, getDefaultNamespaceUri, getParentNode, getQNameLocal, getQNameUri, namespace2Prefix, newNode, prefix2Namespace, readDeclaredNamespaceUris, readDeclaredPrefixes, removeDeclaredNamespaces, resetNode, setDefaultNamespaceUri, setParentNode
-
Methods inherited from interface org.gjt.xpp.XmlStartTag
addAttribute, addAttribute, ensureAttributesCapacity, getAttributeCount, getAttributeLocalName, getAttributeNamespaceUri, getAttributePrefix, getAttributeRawName, getAttributeValue, getAttributeValueFromName, getAttributeValueFromRawName, isAttributeNamespaceDeclaration, removeAttributeByName, removeAttributeByRawName, removeAttributes, resetStartTag
-
Methods inherited from interface org.gjt.xpp.XmlTag
getLocalName, getNamespaceUri, getPrefix, getRawName, modifyTag, resetTag
-
-
-
-
Field Detail
-
depth
protected int depth
-
pp
protected XmlPullParser pp
-
-
Constructor Detail
-
PullNode
public PullNode(XmlPullParser pp) throws XmlPullParserException
- Throws:
XmlPullParserException
-
-
Method Detail
-
newNode
public XmlNode newNode() throws XmlPullParserException
Description copied from class:Node
context sensitive factory method to create the same type of node- Specified by:
newNode
in interfaceXmlNode
- Specified by:
newNode
in interfaceXmlPullNode
- Overrides:
newNode
in classNode
- Throws:
XmlPullParserException
-
newPullNode
public XmlPullNode newPullNode(XmlPullParser pp) throws XmlPullParserException
- Specified by:
newPullNode
in interfaceXmlPullNode
- Throws:
XmlPullParserException
-
resetPullNode
public void resetPullNode()
PullNode stays in finished state.- Specified by:
resetPullNode
in interfaceXmlPullNode
-
isFinished
public boolean isFinished()
Description copied from interface:XmlPullNode
Is pull parsing of node finished.- Specified by:
isFinished
in interfaceXmlPullNode
-
getPullParser
public XmlPullParser getPullParser() throws java.io.IOException, XmlPullParserException
Description copied from interface:XmlPullNode
Get parser that is use to build this node tree and this pull node becomes finished - the caller is responsibile to move pull parser state to the end tag of this node (or parent pull node will be left in unconsistent state!!!!). The returned pull parser position will be before start tag of next child or before final end tag and the caller should use next() to move parser to start reading children. The node state becomes finished and subsequent call to this method will throw exception until setPullParser() is called. The final effect should be equivalen to calling skipNode()!NOTE: this pull node must be in unfinished state or exception will be thrown
- Specified by:
getPullParser
in interfaceXmlPullNode
- Throws:
java.io.IOException
XmlPullParserException
-
setPullParser
public void setPullParser(XmlPullParser pp) throws XmlPullParserException
Reset pull node to use pull parser. Pull Parser must be on START_TAG- Specified by:
setPullParser
in interfaceXmlPullNode
- Throws:
XmlPullParserException
-
children
public java.util.Enumeration children()
Description copied from interface:XmlPullNode
This is not recommened method to pull children when node is not finished (use readNextChild() instead) as Enumeration interface does not allow to throw XmlPullParserException so any parsing exeption is wrapped into RuntimeException making code more messy...- Specified by:
children
in interfaceXmlNode
- Specified by:
children
in interfaceXmlPullNode
- Overrides:
children
in classNode
- See Also:
XmlPullNode.readNextChild()
-
readNextChild
public java.lang.Object readNextChild() throws XmlPullParserException, java.io.IOException
Description copied from interface:XmlPullNode
This is preferred method to pull children (children() requires .wrapping object Enumeration).- Specified by:
readNextChild
in interfaceXmlPullNode
- Returns:
- next child (which is String or XmlPullNode) or null if there is no re children
- Throws:
XmlPullParserException
java.io.IOException
- See Also:
XmlPullNode.children()
-
readChildren
public void readChildren() throws XmlPullParserException, java.io.IOException
Read all reminaing children up to end tag.- Specified by:
readChildren
in interfaceXmlPullNode
- Throws:
XmlPullParserException
java.io.IOException
-
skipChildren
public void skipChildren() throws XmlPullParserException, java.io.IOException
- Specified by:
skipChildren
in interfaceXmlPullNode
- Throws:
XmlPullParserException
java.io.IOException
-
getChildrenCountSoFar
public int getChildrenCountSoFar()
if unfinished it returns actual number of children...- Specified by:
getChildrenCountSoFar
in interfaceXmlPullNode
-
getChildrenCount
public int getChildrenCount()
it will reconsruct whole subtree to get count ...- Specified by:
getChildrenCount
in interfaceXmlNode
- Overrides:
getChildrenCount
in classNode
-
getChildAt
public java.lang.Object getChildAt(int pos)
- Specified by:
getChildAt
in interfaceXmlNode
- Overrides:
getChildAt
in classNode
-
appendChild
public void appendChild(java.lang.Object child) throws XmlPullParserException
- Specified by:
appendChild
in interfaceXmlNode
- Overrides:
appendChild
in classNode
- Throws:
XmlPullParserException
-
insertChildAt
public void insertChildAt(int pos, java.lang.Object child) throws XmlPullParserException
- Specified by:
insertChildAt
in interfaceXmlNode
- Overrides:
insertChildAt
in classNode
- Throws:
XmlPullParserException
-
removeChildAt
public void removeChildAt(int pos) throws XmlPullParserException
- Specified by:
removeChildAt
in interfaceXmlNode
- Overrides:
removeChildAt
in classNode
- Throws:
XmlPullParserException
-
replaceChildAt
public void replaceChildAt(int pos, java.lang.Object child) throws XmlPullParserException
- Specified by:
replaceChildAt
in interfaceXmlNode
- Overrides:
replaceChildAt
in classNode
- Throws:
XmlPullParserException
-
removeChildren
public void removeChildren() throws XmlPullParserException
Description copied from interface:XmlNode
Removes all children - every child that was implementing XmlNode will have set parent to null.- Specified by:
removeChildren
in interfaceXmlNode
- Overrides:
removeChildren
in classNode
- Throws:
XmlPullParserException
-
printFields
protected void printFields(java.lang.StringBuffer buf)
Print this class state into StringBuffer element name- Overrides:
printFields
in classNode
-
-