|
JAXB v0.21 |
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object | +--javax.xml.marshal.XMLScanner
A scanner of XML input streams or data structures.
When unmarshalling XML into a content tree it is not necessary to use a full-fledged XML parser because schema-derived classes enforce all validity constraints as well as the following non-local well-formedness constraints of the XML 1.0 specification:
Element type match: The name in an element's end-tag must match the element type in its start-tag.
Unique Att Spec: No attribute name may appear more than once in the same start-tag or empty-element tag.
An XML scanner is in one of the following states:
Start: The scanner is positioned at a start tag. This state may be followed by the AttributeName, Chars, Start, or End states. An empty tag, that is, a tag of the form <foo/>, will yield the Start state followed by the End state, possibly with some intervening attribute states.
AttributeName: The scanner is positioned at an attribute name. This state may be followed only by the AttributeValue state. This state will be entered exactly once for each attribute that is read. Attributes are read in the order in which they appear in the input document.
AttributeValue: The scanner is positioned at an attribute
value. This state may be followed by the AttributeName,
Chars, Start, or End states. If the tokenizeAttributeValue method is invoked then
this state may also be followed by the AttributeValueToken state.
AttributeValueToken: The scanner is positioned at one of the tokens of a tokenized attribute value. This state may be followed by the AttributeValueToken, AttributeName, Chars, Start, or End states.
Chars: The scanner is positioned at some character content. This state may be followed by the Start or End states.
End: The scanner is positioned at an end tag. This state may be followed by the Chars, Start, End, or EndOfDocument states.
EndOfDocument: The scanner has reached the end of the input document, at which point it closes itself. The state of the scanner will not change after it reaches this state.
Methods named atFoo return a boolean value indicating whether the scanner is in the Foo state and possibly whether some other condition holds.
Methods named takeFoo check that the scanner is in
the Foo state; if so, a relevant value is returned and the scanner
is (in most cases) advanced to the next state. A InvalidContentException is thrown if the scanner is not in the
Foo state.
WS_COLLAPSE,
WS_NORMALIZE, or WS_PRESERVE, indicating how whitespace is
to be processed. Whitespace is defined here exactly as in the XML 1.0
specification: A whitespace character is one of TAB
('\u0009'), LINE FEED ('\u000A'),
CARRIAGE RETURN ('\u000D'), or
SPACE ('\u0020').
This class also defines a method for retrieving the scanner's position and factory methods for creating scanners that read byte-input streams and scanners that read DOM trees.
| Field Summary | |
static int |
WS_COLLAPSE
Constant indicating that whitespace is to be collapsed. |
static int |
WS_NORMALIZE
Constant indicating that whitespace is to be normalized. |
static int |
WS_PRESERVE
Constant indicating that whitespace is to be preserved. |
| Constructor Summary | |
XMLScanner()
|
|
| Method Summary | |
abstract boolean |
atAttribute()
Tests whether the scanner is positioned at an attribute name. |
abstract boolean |
atAttributeValue()
Tests whether the scanner is positioned at an attribute value. |
abstract boolean |
atAttributeValueToken()
Tests whether the scanner is positioned at an attribute-value token. |
abstract boolean |
atChars(int whitespace)
Tests whether the scanner is positioned at some character data. |
abstract boolean |
atEnd()
Skips whitespace, if any, and then tests whether the scanner is positioned at an end tag. |
abstract boolean |
atEnd(String name)
Skips whitespace, if any, and then tests whether the scanner is positioned at an end tag with the given name. |
abstract boolean |
atEndOfDocument()
Skips whitespace, if any, and then tests whether the scanner has reached the end of the input document. |
abstract boolean |
atStart()
Skips whitespace, if any, and then tests whether the scanner is positioned at a start tag. |
abstract boolean |
atStart(String name)
Skips whitespace, if any, and then tests whether the scanner is positioned at a start tag with the given name. |
abstract void |
close()
Closes this scanner. |
static XMLScanner |
open(org.w3c.dom.Document doc)
Creates a new scanner that scans the given DOM tree. |
static XMLScanner |
open(InputStream in)
Creates a new scanner that reads an XML document from the given input stream. |
abstract String |
peekStart()
Skips whitespace, if any, and then reads the current start tag. |
abstract ScanPosition |
position()
Returns a new scan-position object reporting the scanner's current position. |
abstract String |
takeAttributeName()
Reads the current attribute name and then advances the scanner to the next state. |
String |
takeAttributeValue()
Reads the current attribute value, collapsing whitespace, and then advances the scanner to the next state. |
abstract String |
takeAttributeValue(int whitespace)
Reads the current attribute value and then advances the scanner to the next state. |
abstract String |
takeAttributeValueToken()
Reads the current attribute-value token and then advances the scanner to the next state. |
abstract String |
takeChars(int whitespace)
Reads the current character data and then advances the scanner to the next state. |
void |
takeEmpty(String name)
Takes an empty tag. |
abstract String |
takeEnd()
Skips whitespace, if any, reads the current end tag, and then advances the scanner to the next state. |
abstract void |
takeEnd(String name)
Skips whitespace, if any, checks that the current end tag's name is equal to the given name, and then advances the scanner to the next state. |
abstract void |
takeEndOfDocument()
Skips whitespace, if any, and then checks that the scanner has reached the end of the input document. |
String |
takeLeaf(String name,
int whitespace)
Takes a simple leaf element. |
abstract String |
takeStart()
Skips whitespace, if any, reads the current start tag, and then advances the scanner to the next state. |
abstract void |
takeStart(String name)
Skips whitespace, if any, checks that the current start tag's name is equal to the given name, and then advances the scanner to the next state. |
abstract void |
tokenizeAttributeValue()
Reads the current attribute's value as a sequence of non-whitespace tokens, returning them in succeeding AttributeValueToken states. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int WS_COLLAPSE
public static final int WS_NORMALIZE
public static final int WS_PRESERVE
| Constructor Detail |
public XMLScanner()
| Method Detail |
public abstract boolean atAttribute()
public abstract boolean atAttributeValue()
public abstract boolean atAttributeValueToken()
public abstract boolean atChars(int whitespace)
throws ScanException
If the value of the whitespace parameter is WS_COLLAPSE then any initial whitespace is first skipped.
whitespace - Determines how whitespace in the character data will be handled;
must be one of WS_COLLAPSE, WS_NORMALIZE, or
WS_PRESERVEIllegalStateException - If this method has already been invoked for the current state
but with a different value for the whitespace
parameterScanException - If input that is not lexically well-formed is scanned,
or if an I/O error occurs
public abstract boolean atEnd()
throws ScanException
ScanException - If input that is not lexically well-formed is scanned,
or if an I/O error occurs
public abstract boolean atEnd(String name)
throws ScanException
name - The element name to be testedScanException - If input that is not lexically well-formed is scanned,
or if an I/O error occurs
public abstract boolean atEndOfDocument()
throws InvalidContentException,
ScanException
ScanException - If input that is not lexically well-formed is scanned,
or if an I/O error occurs
public abstract boolean atStart()
throws ScanException
ScanException - If input that is not lexically well-formed is scanned,
or if an I/O error occurs
public abstract boolean atStart(String name)
throws ScanException
name - The element name to be testedScanException - If input that is not lexically well-formed is scanned,
or if an I/O error occurs
public abstract void close()
throws ScanIOException
If this scanner was created from a byte-input stream then the input stream is closed.
ScanIOException - If an I/O error occurs
public static XMLScanner open(org.w3c.dom.Document doc)
throws ScanException
doc - The document to be scannedScanException - If input that is not lexically well-formed is scanned,
or if an I/O error occurs
public static XMLScanner open(InputStream in)
throws ScanException
in - The input stream to be scannedScanException - If input that is not lexically well-formed is scanned,
or if an I/O error occurs
public abstract String peekStart()
throws InvalidContentException,
ScanException
InvalidContentException - If, after skipping whitespace, the scanner's state is not
StartScanException - If input that is not lexically well-formed is scanned,
or if an I/O error occurspublic abstract ScanPosition position()
public abstract String takeAttributeName()
throws InvalidContentException,
ScanException
InvalidContentException - If the scanner's state is not AttributeNameScanException - If input that is not lexically well-formed is scanned,
or if an I/O error occurs
public final String takeAttributeValue()
throws InvalidContentException,
ScanException
An invocation of this method behaves in exactly the same way as an
invocation of the takeAttributeValue(int) method, passing
WS_COLLAPSE for the whitespace argument.
InvalidContentException - If the scanner's state is not AttributeValueScanException - If input that is not lexically well-formed is scanned,
or if an I/O error occurs
public abstract String takeAttributeValue(int whitespace)
throws InvalidContentException,
ScanException
whitespace - Determines how whitespace in the attribute value will be
handled; must be one of WS_COLLAPSE, WS_NORMALIZE, or WS_PRESERVEInvalidContentException - If the scanner's state is not AttributeValueScanException - If input that is not lexically well-formed is scanned,
or if an I/O error occurs
public abstract String takeAttributeValueToken()
throws InvalidContentException,
ScanException
InvalidContentException - If the scanner's state is not AttributeValueTokenScanException - If input that is not lexically well-formed is scanned,
or if an I/O error occurs
public abstract String takeChars(int whitespace)
throws InvalidContentException,
ScanException
whitespace - Determines how whitespace in the character data will be handled;
must be one of WS_COLLAPSE, WS_NORMALIZE, or
WS_PRESERVEInvalidContentException - If the scanner's state is not CharsIllegalStateException - If the atChars(int) method has already been
invoked for the current state but with a different value for
the whitespace parameterScanException - If input that is not lexically well-formed is scanned,
or if an I/O error occurs
public final void takeEmpty(String name)
throws InvalidContentException,
ScanException
This method takes a start tag with the given name and then takes an end tag with the same name.
name - The element name of the expected start and end tagsInvalidContentException - If the expected tags cannot be scannedScanException - If input that is not lexically well-formed is scanned,
or if an I/O error occurs
public abstract String takeEnd()
throws InvalidContentException,
ScanException
InvalidContentException - If, after skipping whitespace, the scanner's state is not
EndScanException - If input that is not lexically well-formed is scanned,
or if an I/O error occurs
public abstract void takeEnd(String name)
throws InvalidContentException,
ScanException
name - The element name to be scannedInvalidContentException - If, after skipping whitespace, the scanner's state is not
End and the name in the tag is not equal to
nameScanException - If input that is not lexically well-formed is scanned,
or if an I/O error occurs
public abstract void takeEndOfDocument()
throws InvalidContentException,
ScanException
InvalidContentException - If, after skipping whitespace, the scanner's state is not
EndScanException - If input that is not lexically well-formed is scanned,
or if an I/O error occurs
public final String takeLeaf(String name,
int whitespace)
throws InvalidContentException,
ScanException
This method takes start tag with the given name, takes a sequence of characters, if present, takes an end tag with the given name, and then returns the character data, if any.
name - The element name of the expected start and end tagswhitespace - Determines how whitespace in the character data will be handled;
must be one of WS_COLLAPSE, WS_NORMALIZE, or
WS_PRESERVEInvalidContentException - If the expected tags and the character data cannot be scannedScanException - If input that is not lexically well-formed is scanned,
or if an I/O error occurs
public abstract String takeStart()
throws InvalidContentException,
ScanException
InvalidContentException - If, after skipping whitespace, the scanner's state is not
StartScanException - If input that is not lexically well-formed is scanned,
or if an I/O error occurs
public abstract void takeStart(String name)
throws InvalidContentException,
ScanException
name - The element name to be scannedInvalidContentException - If, after skipping whitespace, the scanner's state is not
Start and the name in the tag is not equal to
nameScanException - If input that is not lexically well-formed is scanned,
or if an I/O error occurs
public abstract void tokenizeAttributeValue()
throws InvalidContentException,
ScanException
InvalidContentException - If the scanner's state is not AttributeValueScanException - If input that is not lexically well-formed is scanned,
or if an I/O error occurs
|
JAXB v0.21 |
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
Copyright © 2001 by Sun Microsystems, Inc., 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.