Package com.sun.msv.reader.util
Class GrammarLoader
- java.lang.Object
-
- com.sun.msv.reader.util.GrammarLoader
-
public class GrammarLoader extends java.lang.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
GrammarLoader.GrammarLoaderException
wrapper exception so that we can throw it from the GrammarReaderController.private static class
GrammarLoader.ThrowController
-
Field Summary
Fields Modifier and Type Field Description private Controller
controller
private javax.xml.parsers.SAXParserFactory
factory
private ExpressionPool
pool
private boolean
strictCheck
-
Constructor Summary
Constructors Constructor Description GrammarLoader()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private Grammar
_loadSchema(java.lang.Object source)
Actual "meat" of parsing schema.Controller
getController()
ExpressionPool
getPool()
javax.xml.parsers.SAXParserFactory
getSAXParserFactory()
boolean
getStrictCheck()
private boolean
hasDTDextension(java.lang.String name)
Checks if the specified name has ".dtd" extension.static Grammar
loadSchema(java.lang.String url)
parses the specified schema and returns the result as a Grammar object.static Grammar
loadSchema(java.lang.String source, GrammarReaderController controller)
returns a thread-safe AGM object, depending on the language used.static Grammar
loadSchema(java.lang.String url, GrammarReaderController controller, javax.xml.parsers.SAXParserFactory factory)
parses the specified schema and returns the result as a Grammar object.static Grammar
loadSchema(org.xml.sax.InputSource source)
static Grammar
loadSchema(org.xml.sax.InputSource source, GrammarReaderController controller)
returns a thread-safe AGM object, depending on the language used.static Grammar
loadSchema(org.xml.sax.InputSource source, GrammarReaderController controller, javax.xml.parsers.SAXParserFactory factory)
static REDocumentDeclaration
loadVGM(java.lang.String url)
parses the specified schema and returns the result as a VGM.static REDocumentDeclaration
loadVGM(java.lang.String url, GrammarReaderController controller, javax.xml.parsers.SAXParserFactory factory)
parses the specified schema and returns the result as a VGM.static REDocumentDeclaration
loadVGM(org.xml.sax.InputSource source)
static REDocumentDeclaration
loadVGM(org.xml.sax.InputSource source, GrammarReaderController controller, javax.xml.parsers.SAXParserFactory factory)
Grammar
parse(java.lang.String url)
Grammar
parse(org.xml.sax.InputSource source)
REDocumentDeclaration
parseVGM(java.lang.String url)
REDocumentDeclaration
parseVGM(org.xml.sax.InputSource source)
void
setController(GrammarReaderController controller)
sets the GrammarReaderController object that will control various aspects of the parsing.void
setPool(ExpressionPool pool)
Sets the ExpressionPool object that will be used during the loading process.void
setSAXParserFactory(javax.xml.parsers.SAXParserFactory factory)
sets the factory object which is used to create XML parsers to parse schema files.void
setStrictCheck(boolean value)
Sets the strict check flag.private static REDocumentDeclaration
wrapByVGM(Grammar g)
-
-
-
Field Detail
-
factory
private javax.xml.parsers.SAXParserFactory factory
-
controller
private Controller controller
-
pool
private ExpressionPool pool
-
strictCheck
private boolean strictCheck
-
-
Method Detail
-
loadVGM
public static REDocumentDeclaration loadVGM(java.lang.String url, GrammarReaderController controller, javax.xml.parsers.SAXParserFactory factory) throws org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException, java.io.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:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
-
loadVGM
public static REDocumentDeclaration loadVGM(org.xml.sax.InputSource source, GrammarReaderController controller, javax.xml.parsers.SAXParserFactory factory) throws org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException, java.io.IOException
- Throws:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
-
wrapByVGM
private static REDocumentDeclaration wrapByVGM(Grammar g)
-
loadVGM
public static REDocumentDeclaration loadVGM(java.lang.String url) throws org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException, java.io.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:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
-
loadVGM
public static REDocumentDeclaration loadVGM(org.xml.sax.InputSource source) throws org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException, java.io.IOException
- Throws:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
-
loadSchema
public static Grammar loadSchema(java.lang.String url, GrammarReaderController controller, javax.xml.parsers.SAXParserFactory factory) throws org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException, java.io.IOException
parses the specified schema and returns the result as a Grammar object.- Returns:
- null if there was an error in the grammar.
- Throws:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
-
loadSchema
public static Grammar loadSchema(org.xml.sax.InputSource source, GrammarReaderController controller, javax.xml.parsers.SAXParserFactory factory) throws org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException, java.io.IOException
- Throws:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
-
loadSchema
public static Grammar loadSchema(java.lang.String source, GrammarReaderController controller) throws org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException, java.io.IOException
returns a thread-safe AGM object, depending on the language used.- Throws:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
-
loadSchema
public static Grammar loadSchema(org.xml.sax.InputSource source, GrammarReaderController controller) throws org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException, java.io.IOException
returns a thread-safe AGM object, depending on the language used.- Throws:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
-
loadSchema
public static Grammar loadSchema(java.lang.String url) throws org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException, java.io.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:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
-
loadSchema
public static Grammar loadSchema(org.xml.sax.InputSource source) throws org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException, java.io.IOException
- Throws:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
-
setSAXParserFactory
public void setSAXParserFactory(javax.xml.parsers.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 javax.xml.parsers.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(org.xml.sax.InputSource source) throws org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException, java.io.IOException
- Throws:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
-
parse
public Grammar parse(java.lang.String url) throws org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException, java.io.IOException
- Throws:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
-
parseVGM
public REDocumentDeclaration parseVGM(java.lang.String url) throws org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException, java.io.IOException
- Throws:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
-
parseVGM
public REDocumentDeclaration parseVGM(org.xml.sax.InputSource source) throws org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException, java.io.IOException
- Throws:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
-
hasDTDextension
private boolean hasDTDextension(java.lang.String name)
Checks if the specified name has ".dtd" extension.
-
_loadSchema
private Grammar _loadSchema(java.lang.Object source) throws org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException, java.io.IOException
Actual "meat" of parsing schema. All other methods will ultimately come down to this method.- Throws:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
-
-