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

public abstract Class GrammarReader

extends XMLFilterImpl
implements IDContextProvider2
Class Inheritance
All Implemented Interfaces
com.sun.msv.grammar.IDContextProvider2, org.relaxng.datatype.ValidationContext
Known Direct Subclasses
com.sun.msv.reader.relax.RELAXReader, com.sun.msv.reader.trex.TREXBaseReader, com.sun.msv.reader.xmlschema.XMLSchemaReader
Imports
java.io.IOException, .StringReader, java.util.ArrayList, .Iterator, .Map, .Vector, javax.xml.parsers.ParserConfigurationException, .SAXParserFactory, javax.xml.transform.Source, .TransformerConfigurationException, .TransformerException, .TransformerFactory, javax.xml.transform.dom.DOMSource, javax.xml.transform.sax.SAXResult, .SAXSource, org.relaxng.datatype.Datatype, org.w3c.dom.ls.LSInput, org.xml.sax.InputSource, .Locator, .SAXException, .SAXParseException, .XMLReader, org.xml.sax.helpers.LocatorImpl, .XMLFilterImpl, com.sun.msv.datatype.xsd.XSDatatype, com.sun.msv.grammar.Expression, .ExpressionPool, .Grammar, .IDContextProvider2, .ReferenceContainer, .ReferenceExp, com.sun.msv.reader.datatype.xsd.XSDatatypeExp, com.sun.msv.util.StartTagInfo, .Uri, com.sun.msv.verifier.regexp.StringToken

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
public class
GrammarReader.BackwardReferenceMap

memorizes what declarations are referenced from where.

public class
private class
GrammarReader.InclusionContext

information that must be sheltered before switching InputSource (typically by inclusion).

public static interface
GrammarReader.PrefixResolver

namespace prefix to URI conversion map.

Field Summary

Modifier and TypeField and Description
private final Vector<GrammarReader.BackPatch>
public final GrammarReader.BackwardReferenceMap
backwardReference

keeps track of all backward references to every ReferenceExp.

public static final GrammarReader.PrefixResolver
basePrefixResolver

The namespace prefix resolver that only resolves "xml" prefix.

public final Controller
controller

this object receives errors and warnings

private final Map<Object, Locator>
declaredLocations

this map remembers where ReferenceExps are defined, and where user defined types are defined.

private final Vector<GrammarReader.BackPatch>
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
private Locator
locator

Hides org.xml.sax.helpers.XMLFilterImpl.locator.

document Locator that is given by XML reader
public final SAXParserFactory
parserFactory

Reader may create another SAXParser from this factory

private GrammarReader.InclusionContext
pendingIncludes

current inclusion context

public final ExpressionPool
pool

this object must be used to create a new expression

public GrammarReader.PrefixResolver
public static final String
public static final String

Constructor Summary

AccessConstructor and Description
protected
GrammarReader(GrammarReaderController _controller, SAXParserFactory parserFactory, ExpressionPool pool, State initialState)

constructor that should be called from parse method.

Method Summary

Modifier and TypeMethod and Description
public final void
_parse(Object source, Locator errorSource)

parses a grammar from the specified source

public final void
public final void
public final String
combineURI(String baseURI, String relativeURI)

converts the relative URL to the absolute one by using the specified base URL.

public final String
combineURL(String baseURI, String relativeURI)

Deprecated use the combineURI method.
public abstract State

Returns:

null if the start tag is an error.
createExpressionChildState
(State parent, StartTagInfo tag)

this method must be implemented by the derived class to create language-default expresion state.

protected static SAXParserFactory
createParserFactory()

Creates a default SAXParserFactory.

public void
detectUndefinedOnes(ReferenceContainer container, String errMsg)

detects undefined ReferenceExp and reports it as an error.

public void
endPrefixMapping(String
The Namespace prefix.
prefix
)

Overrides org.xml.sax.helpers.XMLFilterImpl.endPrefixMapping.

Implements org.xml.sax.ContentHandler.endPrefixMapping.

Filter an end Namespace prefix mapping event.
public XSDatatype
getBackwardCompatibleType(String typeName)

tries to obtain a DataType object by resolving obsolete names.

public String
getBaseUri()

Implements org.relaxng.datatype.ValidationContext.getBaseUri.

Returns the base URI of the context.
public final State
getCurrentState()

gets current State object.

public Locator
public Locator
public abstract Grammar
getResultAsGrammar()

gets the parsed AGM.

public static Source
inputSourceFromLSInput(LSInput input)

This is a stopgap until we can wean more of this code from SAX-dependence.

protected Expression
interceptExpression(State state, Expression exp)

intercepts an expression made by ExpressionState before it is passed to the parent state.

protected abstract boolean
isGrammarElement(StartTagInfo tag)

checks if given element is that of the grammar elements.

public boolean
isNotation(String notationName)

Implements org.relaxng.datatype.ValidationContext.isNotation.

Checks if a notation is declared with the specified name.
public boolean
isUnparsedEntity(String entityName)

Implements org.relaxng.datatype.ValidationContext.isUnparsedEntity.

Checks if an unparsed entity is declared with the specified name.
public Iterator<Object>
iterateInscopeNamespaces()

Iterates Map.Entry objects which has the prefix as key and the namespace URI as value.

protected abstract String
localizeMessage(String propertyName, Object[] args)

formats localized message with arguments

public final void
onID(Datatype dt, StringToken token)

Implements com.sun.msv.grammar.IDContextProvider2.onID.

this method is called when a type with ID semantics is matched.
public final void
parse(String
The system identifier as a fully-qualified URI.
source
)

Overrides org.xml.sax.helpers.XMLFilterImpl.parse.

Implements org.xml.sax.XMLReader.parse.

parses a grammar from the specified source
public final void
parse(InputSource
The input source for the document entity.
source
)

Overrides org.xml.sax.helpers.XMLFilterImpl.parse.

Implements org.xml.sax.XMLReader.parse.

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

Parse from an arbitrary javax.xml.transform source.

private void
public void
popState()

pops the previous state from the stack

private Locator[]
private void
public void
pushState(State newState, State parentState, StartTagInfo startTag)

pushs the current state into the stack and sets new one

public final void
reportError(String propertyName)

public final void
reportError(String propertyName, Object arg1)

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

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

public final void
reportError(Exception nestedException, String propertyName)

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

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

public final void
reportError(String propertyName, Object[] args, Exception nestedException, Locator[] errorLocations)

reports an error to the controller

public final void
reportWarning(String propertyName)

public final void
reportWarning(String propertyName, Object arg1)

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

public final void
reportWarning(String propertyName, Object[] args, Locator[] locations)

reports a warning to the controller

public final InputSource

Returns:

always return non-null valid object
resolveLocation
(State
The base URI of this state is used to resolve the resource.
sourceState
,
String uri)

obtains InputSource for the specified url.

public String
resolveNamespacePrefix(String prefix)

Implements org.relaxng.datatype.ValidationContext.resolveNamespacePrefix.

Resolves a namespace prefix to the corresponding namespace URI.
public final void
runBackPatchJob()

Performs all back-patchings.

private final void
public void
public void
setDocumentLocator(Locator
The document locator.
loc
)

Overrides org.xml.sax.helpers.XMLFilterImpl.setDocumentLocator.

Implements org.xml.sax.ContentHandler.setDocumentLocator.

Filter a new document locator event.
public void
public String[]
splitQName(String qName)

Resolves a QName into a pair of (namespace URI,local name).

public void
startPrefixMapping(String
The Namespace prefix.
prefix
,
String
The Namespace URI.
uri
)

Overrides org.xml.sax.helpers.XMLFilterImpl.startPrefixMapping.

Implements org.xml.sax.ContentHandler.startPrefixMapping.

Filter a start Namespace prefix mapping event.
public void
switchSource(State
this state is used to resolve the URL.
sourceState
,
String url, State
this state will parse top-level of new XML source. this state receives document element by its createChildState method.
newState
)

Switchs InputSource to the specified URL and parses it by the specified state.

public void
switchSource(InputSource source, State newState)

start reading input from a source defined by a SAX InputSource.

public void
switchSource(Source source, State newState)

Start reading input from a source defined by a javax.xml.transform source.

Inherited from org.xml.sax.helpers.XMLFilterImpl:
charactersendDocumentendElementerrorfatalErrorgetContentHandlergetDTDHandlergetEntityResolvergetErrorHandlergetFeaturegetParentgetPropertyignorableWhitespacenotationDeclprocessingInstructionresolveEntitysetContentHandlersetDTDHandlersetEntityResolversetErrorHandlersetFeaturesetParentsetPropertyskippedEntitystartDocumentstartElementunparsedEntityDeclwarning