Top Description Fields Constructors Methods
com.sun.msv.reader

public abstract Class State

extends Object
implements ContentHandler
Class Inheritance
All Implemented Interfaces
org.xml.sax.ContentHandler
Known Direct Subclasses
com.sun.msv.relaxns.reader.NamespaceState, com.sun.msv.reader.IgnoreState, com.sun.msv.reader.SimpleState
Imports
org.xml.sax.ContentHandler, .Locator, .SAXException, org.xml.sax.helpers.LocatorImpl, com.sun.msv.grammar.Expression, com.sun.msv.util.StartTagInfo

base interface of 'parsing state'. parsing of XML representation of a grammar is done by using various states.

Each State-derived class is responsible for a particular type of declaration of the grammar. For example, SequenceState is responsible for parsing <sequence> element of RELAX module.

State objects interact each other. There are two ways of interaction.

The first type of communication occurs only when a child state object is created. The last type of communication occurs usually (but not limited to) when a child state sees its end tag.

In this level of inheritance, contract is somewhat abstract.

  1. When a State object is created, its init method is called and various information is set. Particularly, start tag information (if any) and the parent state is set. This process should only be initiated by GrammarReader.
  2. After that, startSelf method is called. Usually, this is the place to do something useful.
  3. State object is registered as a ContentHandler, and therefore will receive SAX events from now on.
  4. Derived classes are expected to do something useful by receiving SAX events.
  5. When a State object finishes its own part, it should call GrammarReader.popState method. It will remove the current State object and registers the parent state as a ContentHandler again.
Of course some derived classes introduce more restricted contract. See SimpleState.

this class also provides:

Author
Kohsuke KAWAGUCHI

Field Summary

Modifier and TypeField and Description
protected String
baseURI

base URI for this state.

protected Locator
location

Location of the start tag.

protected State
parentState

parent state of this state.

public GrammarReader
reader

reader object who is the owner of this object.

protected StartTagInfo
startTag

information of the start tag.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
_assert(boolean b)

protected final Expression
public void
characters(char[]
the characters from the XML document
buffer
,
int
the start position in the array
from
,
int
the number of characters to read from the array
len
)

Implements org.xml.sax.ContentHandler.characters.

Receive notification of character data.
public void
endPrefixMapping(String
the prefix that was being mapped. This is the empty string when a default mapping scope ends.
prefix
)

Implements org.xml.sax.ContentHandler.endPrefixMapping.

End the scope of a prefix-URI mapping.
public String
public Locator
public final State
public StartTagInfo
public void
ignorableWhitespace(char[]
the characters from the XML document
buffer
,
int
the start position in the array
from
,
int
the number of characters to read from the array
len
)

Implements org.xml.sax.ContentHandler.ignorableWhitespace.

Receive notification of ignorable whitespace in element content.
protected final void
init(GrammarReader reader, State parentState, StartTagInfo startTag)

public void
processingInstruction(String
the processing instruction target
target
,
String
the processing instruction data, or null if none was supplied. The data does not include any whitespace separating it from the target
data
)

Implements org.xml.sax.ContentHandler.processingInstruction.

Receive notification of a processing instruction.
public void
setDocumentLocator(Locator
an object that can return the location of any SAX document event
loc
)

Implements org.xml.sax.ContentHandler.setDocumentLocator.

Receive an object for locating the origin of SAX document events.
public void
skippedEntity(String
the name of the skipped entity. If it is a parameter entity, the name will begin with '%', and if it is the external DTD subset, it will be the string "[dtd]"
name
)

Implements org.xml.sax.ContentHandler.skippedEntity.

Receive notification of a skipped entity.
public final void
startDocument()

Implements org.xml.sax.ContentHandler.startDocument.

Receive notification of the beginning of a document.
public void
startPrefixMapping(String
the Namespace prefix being declared. An empty string is used for the default element namespace, which has no prefix.
prefix
,
String
the Namespace URI the prefix is mapped to
uri
)

Implements org.xml.sax.ContentHandler.startPrefixMapping.

Begin the scope of a prefix-URI Namespace mapping.
protected void
startSelf()

performs a task that should be done before reading any child elements.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

baseURIback to summary
protected String baseURI

base URI for this state. This information is avaiable after init method is called.

locationback to summary
protected Locator location

Location of the start tag. This information is avaiable after init method is called.

parentStateback to summary
protected State parentState

parent state of this state. In other words, the parent state is a state who is responsible for the parent element of the current element. For states responsible for the document element, the parent state is a state who is responsible for the entire document. For states responsible for the entire document, the parent state is always null.

readerback to summary
public GrammarReader reader

reader object who is the owner of this object. This information is avaiable after init method is called.

startTagback to summary
protected StartTagInfo startTag

information of the start tag. This information is avaiable after init method is called.

Constructor Detail

Stateback to summary
public State()

Method Detail

_assertback to summary
public static void _assert(boolean b)
callInterceptExpressionback to summary
protected final Expression callInterceptExpression(Expression exp)
charactersback to summary
public void characters(char[] buffer, int from, int len) throws SAXException

Implements org.xml.sax.ContentHandler.characters.

Doc from org.xml.sax.ContentHandler.characters.

Receive notification of character data.

The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity so that the Locator provides useful information.

The application must not attempt to read from the array outside of the specified range.

Individual characters may consist of more than one Java char value. There are two important cases where this happens, because characters can't be represented in just sixteen bits. In one case, characters are represented in a Surrogate Pair, using two special Unicode values. Such characters are in the so-called "Astral Planes", with a code point above U+FFFF. A second case involves composite characters, such as a base character combining with one or more accent characters.

Your code should not assume that algorithms using char-at-a-time idioms will be working in character units; in some cases they will split characters. This is relevant wherever XML permits arbitrary characters, such as attribute values, processing instruction data, and comments as well as in data reported from this method. It's also generally relevant whenever Java code manipulates internationalized text; the issue isn't unique to XML.

Note that some parsers will report whitespace in element content using the ignorableWhitespace method rather than this one (validating parsers must do so).

Parameters
buffer:char[]

the characters from the XML document

from:int

the start position in the array

len:int

the number of characters to read from the array

Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
endPrefixMappingback to summary
public void endPrefixMapping(String prefix) throws SAXException

Implements org.xml.sax.ContentHandler.endPrefixMapping.

Doc from org.xml.sax.ContentHandler.endPrefixMapping.

End the scope of a prefix-URI mapping.

See startPrefixMapping for details. These events will always occur immediately after the corresponding endElement event, but the order of endPrefixMapping events is not otherwise guaranteed.

Parameters
prefix:String

the prefix that was being mapped. This is the empty string when a default mapping scope ends.

Exceptions
SAXException:
the client may throw an exception during processing
getBaseURIback to summary
public String getBaseURI()
getLocationback to summary
public Locator getLocation()
getParentStateback to summary
public final State getParentState()
getStartTagback to summary
public StartTagInfo getStartTag()
ignorableWhitespaceback to summary
public void ignorableWhitespace(char[] buffer, int from, int len) throws SAXException

Implements org.xml.sax.ContentHandler.ignorableWhitespace.

Doc from org.xml.sax.ContentHandler.ignorableWhitespace.

Receive notification of ignorable whitespace in element content.

Validating Parsers must use this method to report each chunk of whitespace in element content (see the W3C XML 1.0 recommendation, section 2.10): non-validating parsers may also use this method if they are capable of parsing and using content models.

SAX parsers may return all contiguous whitespace in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.

The application must not attempt to read from the array outside of the specified range.

Parameters
buffer:char[]

the characters from the XML document

from:int

the start position in the array

len:int

the number of characters to read from the array

Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
initback to summary
protected final void init(GrammarReader reader, State parentState, StartTagInfo startTag)
processingInstructionback to summary
public void processingInstruction(String target, String data) throws SAXException

Implements org.xml.sax.ContentHandler.processingInstruction.

Doc from org.xml.sax.ContentHandler.processingInstruction.

Receive notification of a processing instruction.

The Parser will invoke this method once for each processing instruction found: note that processing instructions may occur before or after the main document element.

A SAX parser must never report an XML declaration (XML 1.0, section 2.8) or a text declaration (XML 1.0, section 4.3.1) using this method.

Like characters(), processing instruction data may have characters that need more than one char value.

Parameters
target:String

the processing instruction target

data:String

the processing instruction data, or null if none was supplied. The data does not include any whitespace separating it from the target

Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
setDocumentLocatorback to summary
public void setDocumentLocator(Locator loc)

Implements org.xml.sax.ContentHandler.setDocumentLocator.

Doc from org.xml.sax.ContentHandler.setDocumentLocator.

Receive an object for locating the origin of SAX document events.

SAX parsers are strongly encouraged (though not absolutely required) to supply a locator: if it does so, it must supply the locator to the application by invoking this method before invoking any of the other methods in the ContentHandler interface.

The locator allows the application to determine the end position of any document-related event, even if the parser is not reporting an error. Typically, the application will use this information for reporting its own errors (such as character content that does not match an application's business rules). The information returned by the locator is probably not sufficient for use with a search engine.

Note that the locator will return correct information only during the invocation SAX event callbacks after startDocument returns and before endDocument is called. The application should not attempt to use it at any other time.

Parameters
loc:Locator

an object that can return the location of any SAX document event

skippedEntityback to summary
public void skippedEntity(String name) throws SAXException

Implements org.xml.sax.ContentHandler.skippedEntity.

Doc from org.xml.sax.ContentHandler.skippedEntity.

Receive notification of a skipped entity. This is not called for entity references within markup constructs such as element start tags or markup declarations. (The XML recommendation requires reporting skipped external entities. SAX also reports internal entity expansion/non-expansion, except within markup constructs.)

The Parser will invoke this method each time the entity is skipped. Non-validating processors may skip entities if they have not seen the declarations (because, for example, the entity was declared in an external DTD subset). All processors may skip external entities, depending on the values of the http://xml.org/sax/features/external-general-entities and the http://xml.org/sax/features/external-parameter-entities properties.

Parameters
name:String

the name of the skipped entity. If it is a parameter entity, the name will begin with '%', and if it is the external DTD subset, it will be the string "[dtd]"

Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
startDocumentback to summary
public final void startDocument() throws SAXException

Implements org.xml.sax.ContentHandler.startDocument.

Doc from org.xml.sax.ContentHandler.startDocument.

Receive notification of the beginning of a document.

The SAX parser will invoke this method only once, before any other event callbacks (except for setDocumentLocator).

Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
startPrefixMappingback to summary
public void startPrefixMapping(String prefix, String uri) throws SAXException

Implements org.xml.sax.ContentHandler.startPrefixMapping.

Doc from org.xml.sax.ContentHandler.startPrefixMapping.

Begin the scope of a prefix-URI Namespace mapping.

The information from this event is not necessary for normal Namespace processing: the SAX XML reader will automatically replace prefixes for element and attribute names when the http://xml.org/sax/features/namespaces feature is true (the default).

There are cases, however, when applications need to use prefixes in character data or in attribute values, where they cannot safely be expanded automatically; the start/endPrefixMapping event supplies the information to the application to expand prefixes in those contexts itself, if necessary.

Note that start/endPrefixMapping events are not guaranteed to be properly nested relative to each other: all startPrefixMapping events will occur immediately before the corresponding startElement event, and all endPrefixMapping events will occur immediately after the corresponding endElement event, but their order is not otherwise guaranteed.

There should never be start/endPrefixMapping events for the "xml" prefix, since it is predeclared and immutable.

Parameters
prefix:String

the Namespace prefix being declared. An empty string is used for the default element namespace, which has no prefix.

uri:String

the Namespace URI the prefix is mapped to

Exceptions
SAXException:
the client may throw an exception during processing
startSelfback to summary
protected void startSelf()

performs a task that should be done before reading any child elements. derived-class can safely read startTag and/or parentState values.