com.sun.msv.reader

Class GrammarReader

public abstract class GrammarReader extends XMLFilterImpl implements IDContextProvider2

base implementation of grammar readers that read grammar from SAX2 stream. GrammarReader class can be used as a ContentHandler that parses a grammar. So the typical usage is

 
 GrammarReader reader = new RELAXGrammarReader(...);
 XMLReader parser = .... // create a new XMLReader here
 
 parser.setContentHandler(reader);
 parser.parse(whateverYouLike);
 return reader.grammar;  // obtain parsed grammar.
 
Or you may want to use several pre-defined static "parse" methods for ease of use.

Author: Kohsuke KAWAGUCHI

UNKNOWN: com.sun.msv.reader.relax.RELAXReader#parse com.sun.msv.reader.trex.TREXGrammarReader#parse

Nested Class Summary
static interfaceGrammarReader.BackPatch
classGrammarReader.BackwardReferenceMap
memorizes what declarations are referenced from where. this information is used to report the source of errors.
classGrammarReader.ChainPrefixResolver
static interfaceGrammarReader.PrefixResolver
namespace prefix to URI conversion map. this variable is evacuated to InclusionContext when the parser is switched.
Field Summary
GrammarReader.BackwardReferenceMapbackwardReference
keeps track of all backward references to every ReferenceExp. this map should be used to report the source of error of undefined-something.
static GrammarReader.PrefixResolverbasePrefixResolver
The namespace prefix resolver that only resolves "xml" prefix.
Controllercontroller
this object receives errors and warnings
static StringERR_BAD_ATTRIBUTE_VALUE
static StringERR_BAD_TYPE
static StringERR_CHARACTERS
static StringERR_CONFLICTING_ATTRIBUTES
static StringERR_DATATYPE_ALREADY_DEFINED
static StringERR_DISALLOWED_ATTRIBUTE
static StringERR_FRAGMENT_IDENTIFIER
static StringERR_ILLEGAL_FINAL_VALUE
static StringERR_MALPLACED_ELEMENT
static StringERR_MISSING_ATTRIBUTE
static StringERR_MISSING_ATTRIBUTE_2
static StringERR_MISSING_CHILD_EXPRESSION
static StringERR_MISSING_CHILD_TYPE
static StringERR_MISSING_TOPLEVEL
static StringERR_MORE_THAN_ONE_CHILD_EXPRESSION
static StringERR_MORE_THAN_ONE_CHILD_TYPE
static StringERR_RECURSIVE_DATATYPE
static StringERR_RECURSIVE_INCLUDE
static StringERR_RUNAWAY_EXPRESSION
static StringERR_UNDEFINED_DATATYPE
Locatorlocator
document Locator that is given by XML reader
SAXParserFactoryparserFactory
Reader may create another SAXParser from this factory
ExpressionPoolpool
this object must be used to create a new expression
GrammarReader.PrefixResolverprefixResolver
static StringWRN_DEPRECATED_TYPENAME
static StringWRN_MAYBE_WRONG_NAMESPACE
Method Summary
voidaddBackPatchJob(GrammarReader.BackPatch job)
voidaddBackPatchJob(XSDatatypeExp job)
StringcombineURI(String baseURI, String relativeURI)
converts the relative URL to the absolute one by using the specified base URL.
StringcombineURL(String baseURI, String relativeURI)
abstract StatecreateExpressionChildState(State parent, StartTagInfo tag)
this method must be implemented by the derived class to create language-default expresion state.
voiddetectUndefinedOnes(ReferenceContainer container, String errMsg)
detects undefined ReferenceExp and reports it as an error. this method is used in the final wrap-up process of parsing.
voidendPrefixMapping(String prefix)
XSDatatypegetBackwardCompatibleType(String typeName)
tries to obtain a DataType object by resolving obsolete names. this method is useful for backward compatibility purpose.
StringgetBaseUri()
StategetCurrentState()
gets current State object.
LocatorgetDeclaredLocationOf(Object o)
abstract GrammargetResultAsGrammar()
gets the parsed AGM.
booleanisNotation(String notationName)
booleanisUnparsedEntity(String entityName)
IteratoriterateInscopeNamespaces()
Iterates Map.Entry objects which has the prefix as key and the namespace URI as value.
voidonID(Datatype dt, StringToken token)
voidparse(String source)
parses a grammar from the specified source
voidparse(InputSource source)
parses a grammar from the specified source
voidpopState()
pops the previous state from the stack
voidpushState(State newState, State parentState, StartTagInfo startTag)
pushs the current state into the stack and sets new one
voidreportError(String propertyName)
voidreportError(String propertyName, Object arg1)
voidreportError(String propertyName, Object arg1, Object arg2)
voidreportError(String propertyName, Object arg1, Object arg2, Object arg3)
voidreportError(Exception nestedException, String propertyName)
voidreportError(Exception nestedException, String propertyName, Object arg1)
voidreportError(Locator[] locs, String propertyName, Object[] args)
voidreportError(String propertyName, Object[] args, Exception nestedException, Locator[] errorLocations)
reports an error to the controller
voidreportWarning(String propertyName)
voidreportWarning(String propertyName, Object arg1)
voidreportWarning(String propertyName, Object arg1, Object arg2)
voidreportWarning(String propertyName, Object[] args, Locator[] locations)
reports a warning to the controller
InputSourceresolveLocation(State sourceState, String uri)
obtains InputSource for the specified url.
StringresolveNamespacePrefix(String prefix)
voidrunBackPatchJob()
Performs all back-patchings.
voidsetDeclaredLocationOf(Object o)
voidsetDocumentLocator(Locator loc)
String[]splitQName(String qName)
Resolves a QName into a pair of (namespace URI,local name).
voidstartPrefixMapping(String prefix, String uri)
voidswitchSource(State sourceState, String url, State newState)
Switchs InputSource to the specified URL and parses it by the specified state.
voidswitchSource(InputSource source, State newState)
void_parse(Object source, Locator errorSource)
parses a grammar from the specified source

Field Detail

backwardReference

public final GrammarReader.BackwardReferenceMap backwardReference
keeps track of all backward references to every ReferenceExp. this map should be used to report the source of error of undefined-something.

basePrefixResolver

public static final GrammarReader.PrefixResolver basePrefixResolver
The namespace prefix resolver that only resolves "xml" prefix. This class should be used as the base resolver.

controller

public final Controller controller
this object receives errors and warnings

ERR_BAD_ATTRIBUTE_VALUE

public static final String ERR_BAD_ATTRIBUTE_VALUE

ERR_BAD_TYPE

public static final String ERR_BAD_TYPE

ERR_CHARACTERS

public static final String ERR_CHARACTERS

ERR_CONFLICTING_ATTRIBUTES

public static final String ERR_CONFLICTING_ATTRIBUTES

ERR_DATATYPE_ALREADY_DEFINED

public static final String ERR_DATATYPE_ALREADY_DEFINED

ERR_DISALLOWED_ATTRIBUTE

public static final String ERR_DISALLOWED_ATTRIBUTE

ERR_FRAGMENT_IDENTIFIER

public static final String ERR_FRAGMENT_IDENTIFIER

ERR_ILLEGAL_FINAL_VALUE

public static final String ERR_ILLEGAL_FINAL_VALUE

ERR_MALPLACED_ELEMENT

public static final String ERR_MALPLACED_ELEMENT

ERR_MISSING_ATTRIBUTE

public static final String ERR_MISSING_ATTRIBUTE

ERR_MISSING_ATTRIBUTE_2

public static final String ERR_MISSING_ATTRIBUTE_2

ERR_MISSING_CHILD_EXPRESSION

public static final String ERR_MISSING_CHILD_EXPRESSION

ERR_MISSING_CHILD_TYPE

public static final String ERR_MISSING_CHILD_TYPE

ERR_MISSING_TOPLEVEL

public static final String ERR_MISSING_TOPLEVEL

ERR_MORE_THAN_ONE_CHILD_EXPRESSION

public static final String ERR_MORE_THAN_ONE_CHILD_EXPRESSION

ERR_MORE_THAN_ONE_CHILD_TYPE

public static final String ERR_MORE_THAN_ONE_CHILD_TYPE

ERR_RECURSIVE_DATATYPE

public static final String ERR_RECURSIVE_DATATYPE

ERR_RECURSIVE_INCLUDE

public static final String ERR_RECURSIVE_INCLUDE

ERR_RUNAWAY_EXPRESSION

public static final String ERR_RUNAWAY_EXPRESSION

ERR_UNDEFINED_DATATYPE

public static final String ERR_UNDEFINED_DATATYPE

locator

public Locator locator
document Locator that is given by XML reader

parserFactory

public final SAXParserFactory parserFactory
Reader may create another SAXParser from this factory

pool

public final ExpressionPool pool
this object must be used to create a new expression

prefixResolver

public GrammarReader.PrefixResolver prefixResolver

WRN_DEPRECATED_TYPENAME

public static final String WRN_DEPRECATED_TYPENAME

WRN_MAYBE_WRONG_NAMESPACE

public static final String WRN_MAYBE_WRONG_NAMESPACE

Method Detail

addBackPatchJob

public final void addBackPatchJob(GrammarReader.BackPatch job)

addBackPatchJob

public final void addBackPatchJob(XSDatatypeExp job)

combineURI

public final String combineURI(String baseURI, String relativeURI)
converts the relative URL to the absolute one by using the specified base URL.

combineURL

public final String combineURL(String baseURI, String relativeURI)

Deprecated: use the combineURI method.

createExpressionChildState

public abstract State createExpressionChildState(State parent, StartTagInfo tag)
this method must be implemented by the derived class to create language-default expresion state.

Returns: null if the start tag is an error.

detectUndefinedOnes

public void detectUndefinedOnes(ReferenceContainer container, String errMsg)
detects undefined ReferenceExp and reports it as an error. this method is used in the final wrap-up process of parsing.

endPrefixMapping

public void endPrefixMapping(String prefix)

getBackwardCompatibleType

public XSDatatype getBackwardCompatibleType(String typeName)
tries to obtain a DataType object by resolving obsolete names. this method is useful for backward compatibility purpose.

getBaseUri

public String getBaseUri()

getCurrentState

public final State getCurrentState()
gets current State object.

getDeclaredLocationOf

public Locator getDeclaredLocationOf(Object o)

getResultAsGrammar

public abstract Grammar getResultAsGrammar()
gets the parsed AGM. Should any error happens, this method should returns null. derived classes should implement type-safe getGrammar method, along with this method.

isNotation

public boolean isNotation(String notationName)

isUnparsedEntity

public boolean isUnparsedEntity(String entityName)

iterateInscopeNamespaces

public Iterator iterateInscopeNamespaces()
Iterates Map.Entry objects which has the prefix as key and the namespace URI as value.

onID

public final void onID(Datatype dt, StringToken token)

parse

public final void parse(String source)
parses a grammar from the specified source

parse

public final void parse(InputSource source)
parses a grammar from the specified source

popState

public void popState()
pops the previous state from the stack

pushState

public void pushState(State newState, State parentState, StartTagInfo startTag)
pushs the current state into the stack and sets new one

reportError

public final void reportError(String propertyName)

reportError

public final void reportError(String propertyName, Object arg1)

reportError

public final void reportError(String propertyName, Object arg1, Object arg2)

reportError

public final void reportError(String propertyName, Object arg1, Object arg2, Object arg3)

reportError

public final void reportError(Exception nestedException, String propertyName)

reportError

public final void reportError(Exception nestedException, String propertyName, Object arg1)

reportError

public final void reportError(Locator[] locs, String propertyName, Object[] args)

reportError

public final void reportError(String propertyName, Object[] args, Exception nestedException, Locator[] errorLocations)
reports an error to the controller

reportWarning

public final void reportWarning(String propertyName)

reportWarning

public final void reportWarning(String propertyName, Object arg1)

reportWarning

public final void reportWarning(String propertyName, Object arg1, Object arg2)

reportWarning

public final void reportWarning(String propertyName, Object[] args, Locator[] locations)
reports a warning to the controller

resolveLocation

public final InputSource resolveLocation(State sourceState, String uri)
obtains InputSource for the specified url. Also this method allows GrammarReaderController to redirect or prohibit inclusion.

Parameters: sourceState The base URI of this state is used to resolve the resource.

Returns: always return non-null valid object

resolveNamespacePrefix

public String resolveNamespacePrefix(String prefix)

runBackPatchJob

public final void runBackPatchJob()
Performs all back-patchings.

setDeclaredLocationOf

public void setDeclaredLocationOf(Object o)

setDocumentLocator

public void setDocumentLocator(Locator loc)

splitQName

public String[] splitQName(String qName)
Resolves a QName into a pair of (namespace URI,local name). Therefore this method returns null if it fails to process QName.

startPrefixMapping

public void startPrefixMapping(String prefix, String uri)

switchSource

public void switchSource(State sourceState, String url, State newState)
Switchs InputSource to the specified URL and parses it by the specified state. The method will return after the parsing of the new source is completed. derived classes can use this method to realize semantics of 'include'.

Parameters: sourceState this state is used to resolve the URL. newState this state will parse top-level of new XML source. this state receives document element by its createChildState method.

switchSource

public void switchSource(InputSource source, State newState)

_parse

public final void _parse(Object source, Locator errorSource)
parses a grammar from the specified source