com.sun.msv.reader.trex.ng
Class RELAXNGReader

java.lang.Object
  extended by org.xml.sax.helpers.XMLFilterImpl
      extended by com.sun.msv.reader.GrammarReader
          extended by com.sun.msv.reader.trex.TREXBaseReader
              extended by com.sun.msv.reader.trex.ng.RELAXNGReader
All Implemented Interfaces:
IDContextProvider2, ValidationContext, ContentHandler, DTDHandler, EntityResolver, ErrorHandler, XMLFilter, XMLReader
Direct Known Subclasses:
RELAXNGCompReader, SRELAXNGReader

public class RELAXNGReader
extends TREXBaseReader

reads RELAX NG grammar from SAX2 and constructs abstract grammar model.

Author:
Kohsuke KAWAGUCHI

Nested Class Summary
protected static class RELAXNGReader.RefExpParseInfo
          information necessary to correctly parse pattern definitions.
static class RELAXNGReader.StateFactory
          creates various State object, which in turn parses grammar.
 
Nested classes/interfaces inherited from class com.sun.msv.reader.GrammarReader
GrammarReader.BackPatch, GrammarReader.BackwardReferenceMap, GrammarReader.ChainPrefixResolver, GrammarReader.PrefixResolver
 
Field Summary
protected  RELAXNGReader.RefExpParseInfo currentNamedPattern
          Info about the current ReferenceExp object which is being defined.
protected  String datatypeLibURI
          the namespace URI of the currently active datatype library.
protected  boolean directRefernce
          Flag to indicate whether we saw <element> or not.
static String ERR_BAD_DATA_VALUE
           
static String ERR_BAD_FACET
           
static String ERR_INCONSISTENT_COMBINE
           
static String ERR_INCONSISTENT_KEY_TYPE
           
static String ERR_INFOSET_URI_ATTRIBUTE
           
static String ERR_INVALID_PARAMETERS
           
static String ERR_MULTIPLE_EXCEPT
           
static String ERR_NAKED_INFINITE_ATTRIBUTE_NAMECLASS
           
static String ERR_NOT_ABSOLUTE_URI
           
static String ERR_REDEFINING_UNDEFINED
           
static String ERR_UNDEFINED_DATATYPE_1
           
static String ERR_UNDEFINED_KEY
           
static String ERR_UNKNOWN_DATATYPE_VOCABULARY_1
           
static String ERR_XMLNS_ATTRIBUTE
           
static String RELAXNGNamespace
          Namespace URI of RELAX NG
protected static Schema relaxNGSchema4Schema
          Schema for schema of RELAX NG.
protected  RestrictionChecker restrictionChecker
          Contextual restriction checker.
 
Fields inherited from class com.sun.msv.reader.trex.TREXBaseReader
ERR_BAD_COMBINE, ERR_COMBINE_MISSING, ERR_DUPLICATE_DEFINITION, ERR_INTERLEAVED_ANYSTRING, ERR_INTERLEAVED_STRING, ERR_MISSING_CHILD_NAMECLASS, ERR_MORE_THAN_ONE_NAMECLASS, ERR_NONEXISTENT_PARENT_GRAMMAR, ERR_REPEATED_STRING, ERR_SEQUENCED_STRING, ERR_UNDECLARED_PREFIX, ERR_UNDEFINED_PATTERN, ERR_UNKNOWN_DATATYPE_VOCABULARY, grammar, sfactory, targetNamespace, WRN_COMBINE_IGNORED, WRN_OBSOLETED_XMLSCHEMA_NAMSPACE
 
Fields inherited from class com.sun.msv.reader.GrammarReader
backwardReference, basePrefixResolver, controller, ERR_BAD_ATTRIBUTE_VALUE, ERR_BAD_TYPE, ERR_CHARACTERS, ERR_CONFLICTING_ATTRIBUTES, ERR_DATATYPE_ALREADY_DEFINED, ERR_DISALLOWED_ATTRIBUTE, ERR_FRAGMENT_IDENTIFIER, ERR_ILLEGAL_FINAL_VALUE, ERR_MALPLACED_ELEMENT, ERR_MISSING_ATTRIBUTE, ERR_MISSING_ATTRIBUTE_2, ERR_MISSING_CHILD_EXPRESSION, ERR_MISSING_CHILD_TYPE, ERR_MISSING_TOPLEVEL, ERR_MORE_THAN_ONE_CHILD_EXPRESSION, ERR_MORE_THAN_ONE_CHILD_TYPE, ERR_RECURSIVE_DATATYPE, ERR_RECURSIVE_INCLUDE, ERR_RUNAWAY_EXPRESSION, ERR_UNDEFINED_DATATYPE, parserFactory, pool, prefixResolver, WRN_DEPRECATED_TYPENAME, WRN_MAYBE_WRONG_NAMESPACE
 
Constructor Summary
RELAXNGReader(GrammarReaderController controller)
          easy-to-use constructor.
RELAXNGReader(GrammarReaderController controller, SAXParserFactory parserFactory)
          easy-to-use constructor.
RELAXNGReader(GrammarReaderController controller, SAXParserFactory parserFactory, RELAXNGReader.StateFactory stateFactory, ExpressionPool pool)
          full constructor
 
Method Summary
 State createExpressionChildState(State parent, StartTagInfo tag)
          this method must be implemented by the derived class to create language-default expresion state.
protected  State createNameClassChildState(State parent, StartTagInfo tag)
           
 void endDocument()
           
 void endElement(String a, String b, String c)
           
 DatatypeLibrary getCurrentDatatypeLibrary()
           
 DatatypeLibraryFactory getDatatypeLibraryFactory()
          Returns the datatypeLibraryFactory.
protected  TREXGrammar getGrammar()
           
protected  RELAXNGReader.RefExpParseInfo getRefExpParseInfo(ReferenceExp exp)
          Gets RefExpParseInfo object for the specified ReferenceExp.
static Schema getRELAXNGSchema4Schema()
           
protected  RELAXNGReader.StateFactory getStateFactory()
           
protected  boolean isGrammarElement(StartTagInfo tag)
          checks if given element is that of the grammar elements.
protected  String localizeMessage(String propertyName, Object[] args)
          formats localized message with arguments
static TREXGrammar parse(InputSource grammar, SAXParserFactory factory, GrammarReaderController controller)
          loads RELAX NG pattern
static TREXGrammar parse(String grammarURL, SAXParserFactory factory, GrammarReaderController controller)
          loads RELAX NG pattern
 Datatype resolveDataType(String localName)
          obtains a named DataType object referenced by a local name.
 DatatypeLibrary resolveDataTypeLibrary(String uri)
          obtains the DataTypeLibrary that represents the specified namespace URI.
 String resolveNamespacePrefix(String prefix)
           
 void setDatatypeLibraryFactory(DatatypeLibraryFactory datatypeLibraryFactory)
          Sets the datatypeLibraryFactory.
 void startDocument()
           
 void startElement(String a, String b, String c, Attributes d)
           
 void wrapUp()
          performs final wrap-up.
 
Methods inherited from class com.sun.msv.reader.trex.TREXBaseReader
getResult, getResultAsGrammar, getTargetNamespace
 
Methods inherited from class com.sun.msv.reader.GrammarReader
_parse, addBackPatchJob, addBackPatchJob, combineURI, combineURL, createParserFactory, detectUndefinedOnes, endPrefixMapping, getBackwardCompatibleType, getBaseUri, getCurrentState, getDeclaredLocationOf, getLocator, inputSourceFromLSInput, interceptExpression, isNotation, isUnparsedEntity, iterateInscopeNamespaces, onID, parse, parse, parse, popState, pushState, reportError, reportError, reportError, reportError, reportError, reportError, reportError, reportError, reportWarning, reportWarning, reportWarning, reportWarning, resolveLocation, runBackPatchJob, setDeclaredLocationOf, setDocumentLocator, setLocator, splitQName, startPrefixMapping, switchSource, switchSource, switchSource
 
Methods inherited from class org.xml.sax.helpers.XMLFilterImpl
characters, error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, getProperty, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setContentHandler, setDTDHandler, setEntityResolver, setErrorHandler, setFeature, setParent, setProperty, skippedEntity, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

relaxNGSchema4Schema

protected static Schema relaxNGSchema4Schema
Schema for schema of RELAX NG.


currentNamedPattern

protected RELAXNGReader.RefExpParseInfo currentNamedPattern
Info about the current ReferenceExp object which is being defined. This field is maintained by DefineState.

This field is set to null when there is an error, or the pattern being defined is being re-defined.

This is a part of the process of the recursive self reference error detection.


directRefernce

protected boolean directRefernce
Flag to indicate whether we saw <element> or not. If we don't see any <element> between <define>/<start> and <ref>/<parentRef>, then that reference will go to currentNamedPattern.refs.

This is a part of the process of the recursive self reference error detection.


RELAXNGNamespace

public static final String RELAXNGNamespace
Namespace URI of RELAX NG

See Also:
Constant Field Values

restrictionChecker

protected final RestrictionChecker restrictionChecker
Contextual restriction checker.


datatypeLibURI

protected String datatypeLibURI
the namespace URI of the currently active datatype library. The empty string indicates the built-in datatype library.


ERR_BAD_FACET

public static final String ERR_BAD_FACET
See Also:
Constant Field Values

ERR_INVALID_PARAMETERS

public static final String ERR_INVALID_PARAMETERS
See Also:
Constant Field Values

ERR_BAD_DATA_VALUE

public static final String ERR_BAD_DATA_VALUE
See Also:
Constant Field Values

ERR_UNDEFINED_KEY

public static final String ERR_UNDEFINED_KEY
See Also:
Constant Field Values

ERR_UNDEFINED_DATATYPE_1

public static final String ERR_UNDEFINED_DATATYPE_1
See Also:
Constant Field Values

ERR_INCONSISTENT_KEY_TYPE

public static final String ERR_INCONSISTENT_KEY_TYPE
See Also:
Constant Field Values

ERR_INCONSISTENT_COMBINE

public static final String ERR_INCONSISTENT_COMBINE
See Also:
Constant Field Values

ERR_REDEFINING_UNDEFINED

public static final String ERR_REDEFINING_UNDEFINED
See Also:
Constant Field Values

ERR_UNKNOWN_DATATYPE_VOCABULARY_1

public static final String ERR_UNKNOWN_DATATYPE_VOCABULARY_1
See Also:
Constant Field Values

ERR_MULTIPLE_EXCEPT

public static final String ERR_MULTIPLE_EXCEPT
See Also:
Constant Field Values

ERR_NOT_ABSOLUTE_URI

public static final String ERR_NOT_ABSOLUTE_URI
See Also:
Constant Field Values

ERR_INFOSET_URI_ATTRIBUTE

public static final String ERR_INFOSET_URI_ATTRIBUTE
See Also:
Constant Field Values

ERR_XMLNS_ATTRIBUTE

public static final String ERR_XMLNS_ATTRIBUTE
See Also:
Constant Field Values

ERR_NAKED_INFINITE_ATTRIBUTE_NAMECLASS

public static final String ERR_NAKED_INFINITE_ATTRIBUTE_NAMECLASS
See Also:
Constant Field Values
Constructor Detail

RELAXNGReader

public RELAXNGReader(GrammarReaderController controller)
easy-to-use constructor.


RELAXNGReader

public RELAXNGReader(GrammarReaderController controller,
                     SAXParserFactory parserFactory)
easy-to-use constructor.


RELAXNGReader

public RELAXNGReader(GrammarReaderController controller,
                     SAXParserFactory parserFactory,
                     RELAXNGReader.StateFactory stateFactory,
                     ExpressionPool pool)
full constructor

Method Detail

parse

public static TREXGrammar parse(String grammarURL,
                                SAXParserFactory factory,
                                GrammarReaderController controller)
loads RELAX NG pattern


parse

public static TREXGrammar parse(InputSource grammar,
                                SAXParserFactory factory,
                                GrammarReaderController controller)
loads RELAX NG pattern


getRELAXNGSchema4Schema

public static Schema getRELAXNGSchema4Schema()

localizeMessage

protected String localizeMessage(String propertyName,
                                 Object[] args)
Description copied from class: GrammarReader
formats localized message with arguments

Overrides:
localizeMessage in class TREXBaseReader

getGrammar

protected TREXGrammar getGrammar()

getRefExpParseInfo

protected RELAXNGReader.RefExpParseInfo getRefExpParseInfo(ReferenceExp exp)
Gets RefExpParseInfo object for the specified ReferenceExp.


isGrammarElement

protected boolean isGrammarElement(StartTagInfo tag)
Description copied from class: GrammarReader
checks if given element is that of the grammar elements.

Specified by:
isGrammarElement in class GrammarReader

getDatatypeLibraryFactory

public DatatypeLibraryFactory getDatatypeLibraryFactory()
Returns the datatypeLibraryFactory.


setDatatypeLibraryFactory

public void setDatatypeLibraryFactory(DatatypeLibraryFactory datatypeLibraryFactory)
Sets the datatypeLibraryFactory.


getStateFactory

protected RELAXNGReader.StateFactory getStateFactory()

createNameClassChildState

protected State createNameClassChildState(State parent,
                                          StartTagInfo tag)
Overrides:
createNameClassChildState in class TREXBaseReader

createExpressionChildState

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

Overrides:
createExpressionChildState in class TREXBaseReader
Returns:
null if the start tag is an error.

resolveDataType

public Datatype resolveDataType(String localName)
obtains a named DataType object referenced by a local name.


resolveDataTypeLibrary

public DatatypeLibrary resolveDataTypeLibrary(String uri)
obtains the DataTypeLibrary that represents the specified namespace URI. If the specified URI is undefined, then this method issues an error to the user and must return a dummy datatype library.


wrapUp

public void wrapUp()
Description copied from class: TREXBaseReader
performs final wrap-up. This method is called from the RootState object, after the parsing is completed.

This method has to be called after the run-away expression check is done.

Overrides:
wrapUp in class TREXBaseReader

getCurrentDatatypeLibrary

public DatatypeLibrary getCurrentDatatypeLibrary()

resolveNamespacePrefix

public String resolveNamespacePrefix(String prefix)
Specified by:
resolveNamespacePrefix in interface ValidationContext
Overrides:
resolveNamespacePrefix in class GrammarReader

startDocument

public void startDocument()
                   throws SAXException
Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class XMLFilterImpl
Throws:
SAXException

endDocument

public void endDocument()
                 throws SAXException
Specified by:
endDocument in interface ContentHandler
Overrides:
endDocument in class XMLFilterImpl
Throws:
SAXException

startElement

public void startElement(String a,
                         String b,
                         String c,
                         Attributes d)
                  throws SAXException
Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class TREXBaseReader
Throws:
SAXException

endElement

public void endElement(String a,
                       String b,
                       String c)
                throws SAXException
Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class TREXBaseReader
Throws:
SAXException


MSV