Package com.sun.msv.reader.util
Class GrammarLoader
- java.lang.Object
-
- com.sun.msv.reader.util.GrammarLoader
-
public class GrammarLoader extends Object
loads any supported grammar (except XML DTD) by automatically detecting the schema language.The static version of loadVGM/loadSchema methods provides simple ways to load a grammar.
Another way to use GrammarLoader is
- To instanciate an object of GrammarLoader
- call setXXX methods to configure the parameters
- call loadSchema/loadVGM methods (possibly multiple times) to load grammars.
- Author:
- Kohsuke KAWAGUCHI
-
-
Constructor Summary
Constructors Constructor Description GrammarLoader()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ControllergetController()ExpressionPoolgetPool()SAXParserFactorygetSAXParserFactory()booleangetStrictCheck()static GrammarloadSchema(String url)parses the specified schema and returns the result as a Grammar object.static GrammarloadSchema(String source, GrammarReaderController controller)returns a thread-safe AGM object, depending on the language used.static GrammarloadSchema(String url, GrammarReaderController controller, SAXParserFactory factory)parses the specified schema and returns the result as a Grammar object.static GrammarloadSchema(InputSource source)static GrammarloadSchema(InputSource source, GrammarReaderController controller)returns a thread-safe AGM object, depending on the language used.static GrammarloadSchema(InputSource source, GrammarReaderController controller, SAXParserFactory factory)static REDocumentDeclarationloadVGM(String url)parses the specified schema and returns the result as a VGM.static REDocumentDeclarationloadVGM(String url, GrammarReaderController controller, SAXParserFactory factory)parses the specified schema and returns the result as a VGM.static REDocumentDeclarationloadVGM(InputSource source)static REDocumentDeclarationloadVGM(InputSource source, GrammarReaderController controller, SAXParserFactory factory)Grammarparse(String url)Grammarparse(InputSource source)REDocumentDeclarationparseVGM(String url)REDocumentDeclarationparseVGM(InputSource source)voidsetController(GrammarReaderController controller)sets the GrammarReaderController object that will control various aspects of the parsing.voidsetPool(ExpressionPool pool)Sets the ExpressionPool object that will be used during the loading process.voidsetSAXParserFactory(SAXParserFactory factory)sets the factory object which is used to create XML parsers to parse schema files.voidsetStrictCheck(boolean value)Sets the strict check flag.
-
-
-
Method Detail
-
loadVGM
public static REDocumentDeclaration loadVGM(String url, GrammarReaderController controller, SAXParserFactory factory) throws SAXException, ParserConfigurationException, IOException
parses the specified schema and returns the result as a VGM. This method is an utility method for those applications which don't need AGM (e.g., a single thread application).- Returns:
- null if there was an error in the grammar.
- Throws:
SAXExceptionParserConfigurationExceptionIOException
-
loadVGM
public static REDocumentDeclaration loadVGM(InputSource source, GrammarReaderController controller, SAXParserFactory factory) throws SAXException, ParserConfigurationException, IOException
-
loadVGM
public static REDocumentDeclaration loadVGM(String url) throws SAXException, ParserConfigurationException, IOException
parses the specified schema and returns the result as a VGM. This method uses the default SAX parser and throws an exception if there is an error in the schema.- Returns:
- non-null valid VGM object.
- Throws:
SAXExceptionParserConfigurationExceptionIOException
-
loadVGM
public static REDocumentDeclaration loadVGM(InputSource source) throws SAXException, ParserConfigurationException, IOException
-
loadSchema
public static Grammar loadSchema(String url, GrammarReaderController controller, SAXParserFactory factory) throws SAXException, ParserConfigurationException, IOException
parses the specified schema and returns the result as a Grammar object.- Returns:
- null if there was an error in the grammar.
- Throws:
SAXExceptionParserConfigurationExceptionIOException
-
loadSchema
public static Grammar loadSchema(InputSource source, GrammarReaderController controller, SAXParserFactory factory) throws SAXException, ParserConfigurationException, IOException
-
loadSchema
public static Grammar loadSchema(String source, GrammarReaderController controller) throws SAXException, ParserConfigurationException, IOException
returns a thread-safe AGM object, depending on the language used.
-
loadSchema
public static Grammar loadSchema(InputSource source, GrammarReaderController controller) throws SAXException, ParserConfigurationException, IOException
returns a thread-safe AGM object, depending on the language used.
-
loadSchema
public static Grammar loadSchema(String url) throws SAXException, ParserConfigurationException, IOException
parses the specified schema and returns the result as a Grammar object. This method uses the default SAX parser and throws an exception if there is an error in the schema.- Returns:
- a non-null valid Grammar.
- Throws:
SAXExceptionParserConfigurationExceptionIOException
-
loadSchema
public static Grammar loadSchema(InputSource source) throws SAXException, ParserConfigurationException, IOException
-
setSAXParserFactory
public void setSAXParserFactory(SAXParserFactory factory)
sets the factory object which is used to create XML parsers to parse schema files. The factory must be configured to namespace aware.If no SAXParserFactory is set, then the default parser is used. (The parser that can be obtained by SAXParserFactory.newInstance()).
-
getSAXParserFactory
public SAXParserFactory getSAXParserFactory()
-
setController
public void setController(GrammarReaderController controller)
sets the GrammarReaderController object that will control various aspects of the parsing. If not set, no error report will be done.
-
getController
public Controller getController()
-
setPool
public void setPool(ExpressionPool pool)
Sets the ExpressionPool object that will be used during the loading process. If not set, a fresh one is used for each time the loadXXX method is called.
-
getPool
public ExpressionPool getPool()
-
setStrictCheck
public void setStrictCheck(boolean value)
Sets the strict check flag. If set to true, schema readers will apply stricter checks so that it can find errors in the schema. If set to false, readers will skip some of the checks.When this flag is set to false, which is the default, the reader may accept incorrect schemas.
-
getStrictCheck
public boolean getStrictCheck()
-
parse
public Grammar parse(InputSource source) throws SAXException, ParserConfigurationException, IOException
-
parse
public Grammar parse(String url) throws SAXException, ParserConfigurationException, IOException
-
parseVGM
public REDocumentDeclaration parseVGM(String url) throws SAXException, ParserConfigurationException, IOException
-
parseVGM
public REDocumentDeclaration parseVGM(InputSource source) throws SAXException, ParserConfigurationException, IOException
-
-