com.sun.msv.reader
Class State

java.lang.Object
  extended by com.sun.msv.reader.State
All Implemented Interfaces:
ContentHandler
Direct Known Subclasses:
IgnoreState, NamespaceState, SimpleState

public abstract class State
extends Object
implements ContentHandler

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
protected  String baseURI
          base URI for this state.
protected  Locator location
          Location of the start tag.
protected  State parentState
          parent state of this state.
 GrammarReader reader
          reader object who is the owner of this object.
protected  StartTagInfo startTag
          information of the start tag.
 
Constructor Summary
State()
           
 
Method Summary
static void _assert(boolean b)
           
protected  Expression callInterceptExpression(Expression exp)
           
 void characters(char[] buffer, int from, int len)
           
 void endPrefixMapping(String prefix)
           
 String getBaseURI()
           
 Locator getLocation()
           
 State getParentState()
           
 StartTagInfo getStartTag()
           
 void ignorableWhitespace(char[] buffer, int from, int len)
           
protected  void init(GrammarReader reader, State parentState, StartTagInfo startTag)
           
 void processingInstruction(String target, String data)
           
 void setDocumentLocator(Locator loc)
           
 void skippedEntity(String name)
           
 void startDocument()
           
 void startPrefixMapping(String prefix, String uri)
           
protected  void startSelf()
          performs a task that should be done before reading any child elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.xml.sax.ContentHandler
endDocument, endElement, startElement
 

Field Detail

parentState

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.


reader

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


startTag

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


location

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


baseURI

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

Constructor Detail

State

public State()
Method Detail

getParentState

public final State getParentState()

getStartTag

public StartTagInfo getStartTag()

getLocation

public Locator getLocation()

getBaseURI

public String getBaseURI()

init

protected final void init(GrammarReader reader,
                          State parentState,
                          StartTagInfo startTag)

startSelf

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.


_assert

public static void _assert(boolean b)

characters

public void characters(char[] buffer,
                       int from,
                       int len)
                throws SAXException
Specified by:
characters in interface ContentHandler
Throws:
SAXException

callInterceptExpression

protected final Expression callInterceptExpression(Expression exp)

processingInstruction

public void processingInstruction(String target,
                                  String data)
                           throws SAXException
Specified by:
processingInstruction in interface ContentHandler
Throws:
SAXException

ignorableWhitespace

public void ignorableWhitespace(char[] buffer,
                                int from,
                                int len)
                         throws SAXException
Specified by:
ignorableWhitespace in interface ContentHandler
Throws:
SAXException

skippedEntity

public void skippedEntity(String name)
                   throws SAXException
Specified by:
skippedEntity in interface ContentHandler
Throws:
SAXException

startDocument

public final void startDocument()
                         throws SAXException
Specified by:
startDocument in interface ContentHandler
Throws:
SAXException

setDocumentLocator

public void setDocumentLocator(Locator loc)
Specified by:
setDocumentLocator in interface ContentHandler

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
                        throws SAXException
Specified by:
startPrefixMapping in interface ContentHandler
Throws:
SAXException

endPrefixMapping

public void endPrefixMapping(String prefix)
                      throws SAXException
Specified by:
endPrefixMapping in interface ContentHandler
Throws:
SAXException


MSV