Package org.glassfish.flashlight.xml
Class StaxParser
- java.lang.Object
-
- org.glassfish.flashlight.xml.StaxParser
-
- Direct Known Subclasses:
ProbeProviderStaxParser
public abstract class StaxParser extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
StaxParser.EndDocumentException
-
Field Summary
Fields Modifier and Type Field Description protected XMLStreamReader
parser
-
Constructor Summary
Constructors Constructor Description StaxParser(File f)
StaxParser(InputStream is)
StaxParser(String resource, ClassLoader cl)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
close()
protected int
next()
The same as calling XmlStreamReader.next() except that we throw a special Exception if the end of the document was reachedprotected void
nextStart()
Skip to the next START_ELEMENTprotected Map<String,String>
parseAttributes()
The cursor must be pointing at a START_ELEMENT.protected abstract void
read()
protected void
skipPast(String name)
Skip to the first START_ELEMENT after the given START_ELEMENT name This is useful for skipping past the root elementprotected void
skipTo(String name)
The cursor will be pointing at the START_ELEMENT of name when it returns.
-
-
-
Field Detail
-
parser
protected XMLStreamReader parser
-
-
Constructor Detail
-
StaxParser
public StaxParser(File f) throws XMLStreamException
- Throws:
XMLStreamException
-
StaxParser
public StaxParser(String resource, ClassLoader cl) throws XMLStreamException
- Throws:
XMLStreamException
-
StaxParser
public StaxParser(InputStream is) throws XMLStreamException
- Throws:
XMLStreamException
-
-
Method Detail
-
read
protected abstract void read() throws XMLStreamException, StaxParser.EndDocumentException
-
next
protected int next() throws XMLStreamException, StaxParser.EndDocumentException
The same as calling XmlStreamReader.next() except that we throw a special Exception if the end of the document was reached- Returns:
- Throws:
XMLStreamException
xml.StaxParser.EndDocumentException
- if the end of the document is hereStaxParser.EndDocumentException
-
skipTo
protected void skipTo(String name) throws XMLStreamException, StaxParser.EndDocumentException
The cursor will be pointing at the START_ELEMENT of name when it returns. note that skipTree must be called. Otherwise we could be fooled by a sub-element with the same name as an outer element- Parameters:
name
- the Element to skip to- Throws:
XMLStreamException
StaxParser.EndDocumentException
-
parseAttributes
protected Map<String,String> parseAttributes()
The cursor must be pointing at a START_ELEMENT. Returns all attributes in a Map- Returns:
- Map
of all attributes - Throws:
IllegalStateException
- if the cursor is not pointing at a START_ELEMENT
-
skipPast
protected void skipPast(String name) throws XMLStreamException, StaxParser.EndDocumentException
Skip to the first START_ELEMENT after the given START_ELEMENT name This is useful for skipping past the root element- Parameters:
name
- The START_ELEMENT to skip past- Throws:
XMLStreamException
- if any errorsxml.StaxParser.EndDocumentException
- if end of document reached firstStaxParser.EndDocumentException
-
nextStart
protected void nextStart() throws XMLStreamException, StaxParser.EndDocumentException
Skip to the next START_ELEMENT- Throws:
XMLStreamException
xml.StaxParser.EndDocumentException
StaxParser.EndDocumentException
-
close
protected void close()
-
-