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

  1. To instanciate an object of GrammarLoader
  2. call setXXX methods to configure the parameters
  3. call loadSchema/loadVGM methods (possibly multiple times) to load grammars.
This approach will give you finer control.

Author:
Kohsuke KAWAGUCHI

Constructor Summary
GrammarLoader()
           
 
Method Summary
 GrammarReaderController getController()
           
 ExpressionPool getPool()
           
 javax.xml.parsers.SAXParserFactory getSAXParserFactory()
           
static Grammar loadSchema(InputSource source)
           
static Grammar loadSchema(InputSource source, GrammarReaderController controller, javax.xml.parsers.SAXParserFactory factory)
           
static Grammar loadSchema(String url)
          parses the specified schema and returns the result as a Grammar object.
static Grammar loadSchema(String source, GrammarReaderController controller)
          returns a thread-safe AGM object, depending on the language used.
static Grammar loadSchema(String url, GrammarReaderController controller, javax.xml.parsers.SAXParserFactory factory)
          parses the specified schema and returns the result as a Grammar object.
static REDocumentDeclaration loadVGM(InputSource source)
           
static REDocumentDeclaration loadVGM(InputSource source, GrammarReaderController controller, javax.xml.parsers.SAXParserFactory factory)
           
static REDocumentDeclaration loadVGM(String url)
          parses the specified schema and returns the result as a VGM.
static REDocumentDeclaration loadVGM(String url, GrammarReaderController controller, javax.xml.parsers.SAXParserFactory factory)
          parses the specified schema and returns the result as a VGM.
 Grammar parse(InputSource source)
           
 Grammar parse(String url)
           
 REDocumentDeclaration parseVGM(InputSource source)
           
 REDocumentDeclaration parseVGM(String url)
           
 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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GrammarLoader

public GrammarLoader()
Method Detail

loadVGM

public static REDocumentDeclaration loadVGM(String url,
                                            GrammarReaderController controller,
                                            javax.xml.parsers.SAXParserFactory factory)
                                     throws SAXException,
                                            javax.xml.parsers.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.

loadVGM

public static REDocumentDeclaration loadVGM(InputSource source,
                                            GrammarReaderController controller,
                                            javax.xml.parsers.SAXParserFactory factory)
                                     throws SAXException,
                                            javax.xml.parsers.ParserConfigurationException,
                                            IOException

loadVGM

public static REDocumentDeclaration loadVGM(String url)
                                     throws SAXException,
                                            javax.xml.parsers.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.

loadVGM

public static REDocumentDeclaration loadVGM(InputSource source)
                                     throws SAXException,
                                            javax.xml.parsers.ParserConfigurationException,
                                            IOException

loadSchema

public static Grammar loadSchema(String url,
                                 GrammarReaderController controller,
                                 javax.xml.parsers.SAXParserFactory factory)
                          throws SAXException,
                                 javax.xml.parsers.ParserConfigurationException,
                                 IOException
parses the specified schema and returns the result as a Grammar object.
Returns:
null if there was an error in the grammar.

loadSchema

public static Grammar loadSchema(InputSource source,
                                 GrammarReaderController controller,
                                 javax.xml.parsers.SAXParserFactory factory)
                          throws SAXException,
                                 javax.xml.parsers.ParserConfigurationException,
                                 IOException

loadSchema

public static Grammar loadSchema(String source,
                                 GrammarReaderController controller)
                          throws SAXException,
                                 javax.xml.parsers.ParserConfigurationException,
                                 IOException
returns a thread-safe AGM object, depending on the language used.

loadSchema

public static Grammar loadSchema(String url)
                          throws SAXException,
                                 javax.xml.parsers.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.

loadSchema

public static Grammar loadSchema(InputSource source)
                          throws SAXException,
                                 javax.xml.parsers.ParserConfigurationException,
                                 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 GrammarReaderController 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()

parse

public Grammar parse(InputSource source)
              throws SAXException,
                     javax.xml.parsers.ParserConfigurationException,
                     IOException

parse

public Grammar parse(String url)
              throws SAXException,
                     javax.xml.parsers.ParserConfigurationException,
                     IOException

parseVGM

public REDocumentDeclaration parseVGM(String url)
                               throws SAXException,
                                      javax.xml.parsers.ParserConfigurationException,
                                      IOException

parseVGM

public REDocumentDeclaration parseVGM(InputSource source)
                               throws SAXException,
                                      javax.xml.parsers.ParserConfigurationException,
                                      IOException