Package com.sun.msv.reader
Class GrammarReader
java.lang.Object
org.xml.sax.helpers.XMLFilterImpl
com.sun.msv.reader.GrammarReader
- All Implemented Interfaces:
IDContextProvider2
,org.relaxng.datatype.ValidationContext
,ContentHandler
,DTDHandler
,EntityResolver
,ErrorHandler
,XMLFilter
,XMLReader
- Direct Known Subclasses:
RELAXReader
,TREXBaseReader
,XMLSchemaReader
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
Or you may want to use several pre-defined static "parse" methods for ease of use.GrammarReader reader = new RELAXGrammarReader(...); XMLReader parser = .... // create a new XMLReader here parser.setContentHandler(reader); parser.parse(whateverYouLike); return reader.grammar; // obtain parsed grammar.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
class
memorizes what declarations are referenced from where.class
private class
information that must be sheltered before switching InputSource (typically by inclusion).static interface
namespace prefix to URI conversion map. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Vector
keeps track of all backward references to every ReferenceExp.static final GrammarReader.PrefixResolver
The namespace prefix resolver that only resolves "xml" prefix.final Controller
this object receives errors and warningsprivate final Map
this map remembers where ReferenceExps are defined, and where user defined types are defined.private final Vector
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
private Locator
document Locator that is given by XML readerfinal SAXParserFactory
Reader may create another SAXParser from this factoryprivate GrammarReader.InclusionContext
current inclusion contextfinal ExpressionPool
this object must be used to create a new expressionstatic final String
static final String
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
GrammarReader
(GrammarReaderController _controller, SAXParserFactory parserFactory, ExpressionPool pool, State initialState) constructor that should be called from parse method. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
parses a grammar from the specified sourcefinal void
final void
final String
combineURI
(String baseURI, String relativeURI) converts the relative URL to the absolute one by using the specified base URL.final String
combineURL
(String baseURI, String relativeURI) Deprecated.use the combineURI method.abstract State
createExpressionChildState
(State parent, StartTagInfo tag) this method must be implemented by the derived class to create language-default expresion state.protected static SAXParserFactory
Creates a default SAXParserFactory.void
detectUndefinedOnes
(ReferenceContainer container, String errMsg) detects undefined ReferenceExp and reports it as an error.void
endPrefixMapping
(String prefix) getBackwardCompatibleType
(String typeName) tries to obtain a DataType object by resolving obsolete names.final State
gets current State object.abstract Grammar
gets the parsed AGM.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
checks if given element is that of the grammar elements.boolean
isNotation
(String notationName) boolean
isUnparsedEntity
(String entityName) 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 argumentsfinal void
onID
(org.relaxng.datatype.Datatype dt, StringToken token) this method is called when a type with ID semantics is matched.final void
parses a grammar from the specified sourcevoid
Parse from an arbitrary javax.xml.transform source.final void
parse
(InputSource source) parses a grammar from the specified sourceprivate void
void
popState()
pops the previous state from the stackprivate Locator[]
prepareLocation
(Locator[] param) private void
void
pushState
(State newState, State parentState, StartTagInfo startTag) pushs the current state into the stack and sets new onefinal void
reportError
(Exception nestedException, String propertyName) final void
reportError
(Exception nestedException, String propertyName, Object arg1) final void
reportError
(String propertyName) final void
reportError
(String propertyName, Object arg1) final void
reportError
(String propertyName, Object[] args, Exception nestedException, Locator[] errorLocations) reports an error to the controllerfinal void
reportError
(String propertyName, Object arg1, Object arg2) final void
reportError
(String propertyName, Object arg1, Object arg2, Object arg3) final void
reportError
(Locator[] locs, String propertyName, Object[] args) final void
reportWarning
(String propertyName) final void
reportWarning
(String propertyName, Object arg1) final void
reportWarning
(String propertyName, Object[] args, Locator[] locations) reports a warning to the controllerfinal void
reportWarning
(String propertyName, Object arg1, Object arg2) final InputSource
resolveLocation
(State sourceState, String uri) obtains InputSource for the specified url.resolveNamespacePrefix
(String prefix) final void
Performs all back-patchings.private final void
runBackPatchJob
(Vector vec) void
void
void
setLocator
(Locator locator) String[]
splitQName
(String qName) Resolves a QName into a pair of (namespace URI,local name).void
startPrefixMapping
(String prefix, String uri) void
switchSource
(State sourceState, String url, State newState) Switchs InputSource to the specified URL and parses it by the specified state.void
switchSource
(Source source, State newState) Start reading input from a source defined by a javax.xml.transform source.void
switchSource
(InputSource source, State newState) start reading input from a source defined by a SAX InputSource.Methods inherited from class org.xml.sax.helpers.XMLFilterImpl
characters, endDocument, endElement, error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, getProperty, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setContentHandler, setDTDHandler, setEntityResolver, setErrorHandler, setFeature, setParent, setProperty, skippedEntity, startDocument, startElement, unparsedEntityDecl, warning
-
Field Details
-
locator
document Locator that is given by XML reader -
controller
this object receives errors and warnings -
parserFactory
Reader may create another SAXParser from this factory -
pool
this object must be used to create a new expression -
basePrefixResolver
The namespace prefix resolver that only resolves "xml" prefix. This class should be used as the base resolver. -
prefixResolver
-
pendingIncludes
current inclusion context -
backwardReference
keeps track of all backward references to every ReferenceExp. this map should be used to report the source of error of undefined-something. -
declaredLocations
this map remembers where ReferenceExps are defined, and where user defined types are defined. some ReferenceExp can be defined in more than one location. In those cases, the last one is always memorized. This behavior is essential to correctly implement TREX constraint that no two <define> is allowed in the same file. -
backPatchJobs
-
delayedBackPatchJobs
-
ERR_MALPLACED_ELEMENT
- See Also:
-
ERR_CHARACTERS
- See Also:
-
ERR_DISALLOWED_ATTRIBUTE
- See Also:
-
ERR_MISSING_ATTRIBUTE
- See Also:
-
ERR_BAD_ATTRIBUTE_VALUE
- See Also:
-
ERR_MISSING_ATTRIBUTE_2
- See Also:
-
ERR_CONFLICTING_ATTRIBUTES
- See Also:
-
ERR_RECURSIVE_INCLUDE
- See Also:
-
ERR_FRAGMENT_IDENTIFIER
- See Also:
-
ERR_UNDEFINED_DATATYPE
- See Also:
-
ERR_DATATYPE_ALREADY_DEFINED
- See Also:
-
ERR_MISSING_CHILD_EXPRESSION
- See Also:
-
ERR_MORE_THAN_ONE_CHILD_EXPRESSION
- See Also:
-
ERR_MORE_THAN_ONE_CHILD_TYPE
- See Also:
-
ERR_MISSING_CHILD_TYPE
- See Also:
-
ERR_ILLEGAL_FINAL_VALUE
- See Also:
-
ERR_RUNAWAY_EXPRESSION
- See Also:
-
ERR_MISSING_TOPLEVEL
- See Also:
-
WRN_MAYBE_WRONG_NAMESPACE
- See Also:
-
WRN_DEPRECATED_TYPENAME
- See Also:
-
ERR_BAD_TYPE
- See Also:
-
ERR_RECURSIVE_DATATYPE
- See Also:
-
-
Constructor Details
-
GrammarReader
protected GrammarReader(GrammarReaderController _controller, SAXParserFactory parserFactory, ExpressionPool pool, State initialState) constructor that should be called from parse method.
-
-
Method Details
-
createParserFactory
Creates a default SAXParserFactory. -
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. -
isGrammarElement
checks if given element is that of the grammar elements. -
startPrefixMapping
- Specified by:
startPrefixMapping
in interfaceContentHandler
- Overrides:
startPrefixMapping
in classXMLFilterImpl
- Throws:
SAXException
-
endPrefixMapping
- Specified by:
endPrefixMapping
in interfaceContentHandler
- Overrides:
endPrefixMapping
in classXMLFilterImpl
- Throws:
SAXException
-
iterateInscopeNamespaces
Iterates Map.Entry objects which has the prefix as key and the namespace URI as value. -
splitQName
Resolves a QName into a pair of (namespace URI,local name). Therefore this method returns null if it fails to process QName. -
interceptExpression
intercepts an expression made by ExpressionState before it is passed to the parent state. derived class can perform further wrap-up before it is received by the parent. This mechanism is used by RELAXReader to handle occurs attribute. -
getBackwardCompatibleType
tries to obtain a DataType object by resolving obsolete names. this method is useful for backward compatibility purpose. -
pushInclusionContext
private void pushInclusionContext() -
popInclusionContext
private void popInclusionContext() -
resolveLocation
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
- Throws:
AbortException
-
combineURI
converts the relative URL to the absolute one by using the specified base URL. -
combineURL
Deprecated.use the combineURI method. -
switchSource
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.- Throws:
AbortException
-
switchSource
start reading input from a source defined by a SAX InputSource.- Parameters:
source
-newState
-
-
switchSource
Start reading input from a source defined by a javax.xml.transform source.- Parameters:
source
-newState
-
-
parse
parses a grammar from the specified source- Specified by:
parse
in interfaceXMLReader
- Overrides:
parse
in classXMLFilterImpl
-
parse
parses a grammar from the specified source- Specified by:
parse
in interfaceXMLReader
- Overrides:
parse
in classXMLFilterImpl
-
parse
Parse from an arbitrary javax.xml.transform source. If the Source can be processed bySAXSource.sourceToInputSource(Source)
, then this API will use that. Otherwise, it will use a transformer to create a stream of SAX events. In that later case, the grammar controller will not be called for any errors on the source side or to resolve any references; the caller is responsible for making separate arrangements.- Parameters:
source
-- Throws:
TransformerConfigurationException
TransformerException
-
_parse
parses a grammar from the specified source -
setDeclaredLocationOf
-
getDeclaredLocationOf
-
detectUndefinedOnes
detects undefined ReferenceExp and reports it as an error. this method is used in the final wrap-up process of parsing. -
pushState
pushs the current state into the stack and sets new one -
popState
public void popState()pops the previous state from the stack -
getCurrentState
gets current State object. -
createExpressionChildState
this method must be implemented by the derived class to create language-default expresion state.- Returns:
- null if the start tag is an error.
-
setDocumentLocator
- Specified by:
setDocumentLocator
in interfaceContentHandler
- Overrides:
setDocumentLocator
in classXMLFilterImpl
-
resolveNamespacePrefix
- Specified by:
resolveNamespacePrefix
in interfaceorg.relaxng.datatype.ValidationContext
-
isUnparsedEntity
- Specified by:
isUnparsedEntity
in interfaceorg.relaxng.datatype.ValidationContext
-
isNotation
- Specified by:
isNotation
in interfaceorg.relaxng.datatype.ValidationContext
-
getBaseUri
- Specified by:
getBaseUri
in interfaceorg.relaxng.datatype.ValidationContext
-
onID
Description copied from interface:IDContextProvider2
this method is called when a type with ID semantics is matched. It is the callee's responsibility that stores ID and checks doubly defined ID, if it is necessary.- Specified by:
onID
in interfaceIDContextProvider2
-
addBackPatchJob
-
addBackPatchJob
-
runBackPatchJob
public final void runBackPatchJob()Performs all back-patchings. -
runBackPatchJob
-
reportError
-
reportError
-
reportError
-
reportError
-
reportError
-
reportError
-
reportError
-
reportWarning
-
reportWarning
-
reportWarning
-
prepareLocation
-
reportError
public final void reportError(String propertyName, Object[] args, Exception nestedException, Locator[] errorLocations) reports an error to the controller -
reportWarning
reports a warning to the controller -
inputSourceFromLSInput
This is a stopgap until we can wean more of this code from SAX-dependence.- Parameters:
input
-- Returns:
-
localizeMessage
formats localized message with arguments -
setLocator
-
getLocator
-