Class StreamingParser
- java.lang.Object
-
- com.sun.xml.rpc.sp.StreamingParser
-
- Direct Known Subclasses:
StreamingParserImpl
public abstract class StreamingParser extends Object
A simple demand-driven XML parser interface.There are no public constructors for this class. New instances are created by first creating and configuring, if necessary, an instance of the
StreamingParserFactoryclass.After each invocation of the
parsemethod an instance of this class will be in one of the following states. In each state thename,value, anduriStringmethods may be invoked to return the data specified in the following table. If no data is specified for a given method and state then invoking that method in that state will cause anIllegalStateExceptionto be thrown.
If a start tag has any attributes then thestate description name()value()uriString()START Start tag Element name Element namespace END End tag Element name Element namespace ATTR Attribute Name Value Attribute namespace CHARS Character data Data IWS Ignorable whitespace Whitespace PI Processing instruction Target name Content STARTstate for that tag will immediately be followed by a sequence ofATTRstates, one per attribute. The attributes are parsed in the order in which they appear in the document.An empty tag, that is, a tag of the form <foo/>, will yield a
STARTstate and then anENDstate, possibly with someATTRstates in between.If the parser is namespace-aware then the
uriStringmethod may be invoked in theSTART,END, andATTRstates to return the namespace in which the element or attribute is defined. Otherwise, theuriStringmethod just returns null at those states.Note that because detecting ignorable whitespace requires a DTD, the
IWSstate will be entered only when validation is being performed.There is otherwise no restriction on the allowable state transitions other than those induced by the structure of the XML document being parsed.
- Author:
- Mark Reinhold, JAX-RPC RI Development Team
-
-
Field Summary
Fields Modifier and Type Field Description static intATTRState value indicating that an attribute has been parsed.static intCHARSState value indicating that character data has been parsed.static intENDState value indicating that an end tag has been parsed.static intIWSState value indicating that ignorable whitespace has been parsed.static intPIState value indicating that a processing instruction has been parsed.static intSTARTState value indicating that a start tag has been parsed.
-
Constructor Summary
Constructors Modifier Constructor Description protectedStreamingParser()Construct a new StreamingParser.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract intcolumn()Returns the column number of the current component, or -1 if the column number is not known.abstract Stringdescribe(boolean articleNeeded)Constructs a string describing the current state of this parser, suitable for use in an error message or an exception detail string.static Stringdescribe(int state, String name, String value, boolean articleNeeded)Constructs a string describing the given parser state, suitable for use in an error message or an exception detail string.abstract booleanisCoalescing()Returns the coalescing property of this parser.abstract booleanisNamespaceAware()Returns the namespaceAware property of this parser.abstract booleanisValidating()Returns the validating property of this parser.abstract intline()Returns the line number of the current component, or -1 if the line number is not known.abstract Stringname()Returns a name string whose meaning depends upon the current state.abstract intparse()Parses the next component of the document being parsed.abstract StringpublicId()Returns the public identifer of the document being parsed, or null if it has none.abstract intstate()Returns the current state of the parser.abstract StringsystemId()Returns the system identifer of the document being parsed, or null if it has none.StringtoString()abstract StringuriString()Returns the URI string of the current component.abstract Stringvalue()Returns a value string whose meaning depends upon the current state.
-
-
-
Field Detail
-
START
public static final int START
State value indicating that a start tag has been parsed. Thename()method will return the name of the element just started.- See Also:
- Constant Field Values
-
END
public static final int END
State value indicating that an end tag has been parsed. Thename()method will return the name of the element just ended.- See Also:
- Constant Field Values
-
ATTR
public static final int ATTR
State value indicating that an attribute has been parsed. Thename()method will return the name of the attribute, while thevalue()method will return its value.- See Also:
- Constant Field Values
-
CHARS
public static final int CHARS
State value indicating that character data has been parsed. Thevalue()method will return the parsed characters.- See Also:
- Constant Field Values
-
IWS
public static final int IWS
State value indicating that ignorable whitespace has been parsed. Thevalue()method will return the whitespace.- See Also:
- Constant Field Values
-
PI
public static final int PI
State value indicating that a processing instruction has been parsed. Thename()method will return the target of the instruction, while thevalue()method will return its content.- See Also:
- Constant Field Values
-
-
Method Detail
-
parse
public abstract int parse() throws ParseException, IOExceptionParses the next component of the document being parsed.- Returns:
- The parser's current state, one of
START,END,ATTR,CHARS,IWS, orPI, or -1 if the end of the document has been reached - Throws:
ParseException- If an XML parsing error occursIOException- If an I/O error occurs
-
state
public abstract int state()
Returns the current state of the parser.
-
name
public abstract String name()
Returns a name string whose meaning depends upon the current state.- Throws:
IllegalStateException- If there is no name data for the current parser state
-
value
public abstract String value()
Returns a value string whose meaning depends upon the current state.- Throws:
IllegalStateException- If there is no value data for the current parser state
-
uriString
public abstract String uriString()
Returns the URI string of the current component.- Throws:
IllegalStateException- If there is no URI for the current component
-
line
public abstract int line()
Returns the line number of the current component, or -1 if the line number is not known.
-
column
public abstract int column()
Returns the column number of the current component, or -1 if the column number is not known.
-
publicId
public abstract String publicId()
Returns the public identifer of the document being parsed, or null if it has none.
-
systemId
public abstract String systemId()
Returns the system identifer of the document being parsed, or null if it has none.
-
isValidating
public abstract boolean isValidating()
Returns the validating property of this parser.- Returns:
- true if, and only if, this parser will perform validation
-
isCoalescing
public abstract boolean isCoalescing()
Returns the coalescing property of this parser.- Returns:
- true if, and only if, this parser will coalesce adjacent runs of character data
-
isNamespaceAware
public abstract boolean isNamespaceAware()
Returns the namespaceAware property of this parser.- Returns:
- true if, and only if, this parser will support namespace
-
describe
public static String describe(int state, String name, String value, boolean articleNeeded)
Constructs a string describing the given parser state, suitable for use in an error message or an exception detail string.- Parameters:
state- A parser state, one ofSTART,END,ATTR,CHARS,IWS, orPI, or -1 if the end of the document has been reachedname- The name data for the parser state, or null if there is nonevalue- The value data for the parser state, or null if there is nonearticleNeeded- Whether an appropriate article ("a", "an", "some", or "the") is to be prepended to the description string- Returns:
- A string describing the given parser state.
-
describe
public abstract String describe(boolean articleNeeded)
Constructs a string describing the current state of this parser, suitable for use in an error message or an exception detail string.- Parameters:
articleNeeded- Whether an appropriate article ("a", "an", "some", or "the") is to be prepended to the description string- Returns:
- A string describing the given parser state.
-
-