Top Description Inners Fields Constructors Methods
com.sun.msv.reader.util

public Class GrammarLoader

extends Object
Class Inheritance
Imports
java.util.Vector, javax.xml.parsers.ParserConfigurationException, .SAXParserFactory, org.iso_relax.verifier.Schema, .Verifier, .VerifierConfigurationException, .VerifierFilter, org.xml.sax.Attributes, .ContentHandler, .InputSource, .Locator, .SAXException, .SAXParseException, .XMLReader, org.xml.sax.helpers.DefaultHandler, com.sun.msv.grammar.ExpressionPool, .Grammar, com.sun.msv.grammar.xmlschema.XMLSchemaGrammar, com.sun.msv.reader.Controller, .GrammarReader, .GrammarReaderController, com.sun.msv.reader.dtd.DTDReader, com.sun.msv.reader.relax.core.RELAXCoreReader, com.sun.msv.reader.trex.classic.TREXGrammarReader, com.sun.msv.reader.trex.ng.comp.RELAXNGCompReader, com.sun.msv.reader.xmlschema.XMLSchemaReader, com.sun.msv.relaxns.reader.RELAXNSReader, com.sun.msv.util.Util, com.sun.msv.verifier.jaxp.SAXParserFactoryImpl, com.sun.msv.verifier.regexp.REDocumentDeclaration, com.sun.msv.verifier.regexp.xmlschema.XSREDocDecl

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
GrammarLoader.GrammarLoaderException

wrapper exception so that we can throw it from the GrammarReaderController.

private static class

Field Summary

Modifier and TypeField and Description
private Controller
private SAXParserFactory
private ExpressionPool
private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private Grammar
_loadSchema(Object source)

Actual "meat" of parsing schema.

public Controller
public ExpressionPool
public SAXParserFactory
public boolean
private boolean
hasDTDextension(String name)

Checks if the specified name has ".dtd" extension.

public static Grammar

Returns:

null if there was an error in the grammar.
loadSchema
(String url, GrammarReaderController controller, SAXParserFactory factory)

parses the specified schema and returns the result as a Grammar object.

public static Grammar
public static Grammar
loadSchema(String source, GrammarReaderController controller)

returns a thread-safe AGM object, depending on the language used.

public static Grammar
loadSchema(InputSource source, GrammarReaderController controller)

returns a thread-safe AGM object, depending on the language used.

public static Grammar

Returns:

a non-null valid Grammar.
loadSchema
(String url)

parses the specified schema and returns the result as a Grammar object.

public static Grammar
public static REDocumentDeclaration

Returns:

null if there was an error in the grammar.
loadVGM
(String url, GrammarReaderController controller, SAXParserFactory factory)

parses the specified schema and returns the result as a VGM.

public static REDocumentDeclaration
public static REDocumentDeclaration

Returns:

non-null valid VGM object.
loadVGM
(String url)

parses the specified schema and returns the result as a VGM.

public static REDocumentDeclaration
public Grammar
public Grammar
public REDocumentDeclaration
public REDocumentDeclaration
public void
setController(GrammarReaderController controller)

sets the GrammarReaderController object that will control various aspects of the parsing.

public void
setPool(ExpressionPool pool)

Sets the ExpressionPool object that will be used during the loading process.

public void
setSAXParserFactory(SAXParserFactory factory)

sets the factory object which is used to create XML parsers to parse schema files.

public void
setStrictCheck(boolean value)

Sets the strict check flag.

private static REDocumentDeclaration
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

controllerback to summary
private Controller controller
factoryback to summary
private SAXParserFactory factory
poolback to summary
private ExpressionPool pool
strictCheckback to summary
private boolean strictCheck

Constructor Detail

GrammarLoaderback to summary
public GrammarLoader()

Method Detail

_loadSchemaback to summary
private Grammar _loadSchema(Object source) throws SAXException, ParserConfigurationException, IOException

Actual "meat" of parsing schema. All other methods will ultimately come down to this method.

getControllerback to summary
public Controller getController()
getPoolback to summary
public ExpressionPool getPool()
getSAXParserFactoryback to summary
public SAXParserFactory getSAXParserFactory()
getStrictCheckback to summary
public boolean getStrictCheck()
hasDTDextensionback to summary
private boolean hasDTDextension(String name)

Checks if the specified name has ".dtd" extension.

loadSchemaback to summary
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:Grammar

null if there was an error in the grammar.

loadSchemaback to summary
public static Grammar loadSchema(InputSource source, GrammarReaderController controller, SAXParserFactory factory) throws SAXException, ParserConfigurationException, IOException
loadSchemaback to summary
public static Grammar loadSchema(String source, GrammarReaderController controller) throws SAXException, ParserConfigurationException, IOException

returns a thread-safe AGM object, depending on the language used.

loadSchemaback to summary
public static Grammar loadSchema(InputSource source, GrammarReaderController controller) throws SAXException, ParserConfigurationException, IOException

returns a thread-safe AGM object, depending on the language used.

loadSchemaback to summary
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:Grammar

a non-null valid Grammar.

loadSchemaback to summary
public static Grammar loadSchema(InputSource source) throws SAXException, ParserConfigurationException, IOException
loadVGMback to summary
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:REDocumentDeclaration

null if there was an error in the grammar.

loadVGMback to summary
public static REDocumentDeclaration loadVGM(InputSource source, GrammarReaderController controller, SAXParserFactory factory) throws SAXException, ParserConfigurationException, IOException
loadVGMback to summary
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:REDocumentDeclaration

non-null valid VGM object.

loadVGMback to summary
public static REDocumentDeclaration loadVGM(InputSource source) throws SAXException, ParserConfigurationException, IOException
parseback to summary
public Grammar parse(InputSource source) throws SAXException, ParserConfigurationException, IOException
parseback to summary
public Grammar parse(String url) throws SAXException, ParserConfigurationException, IOException
parseVGMback to summary
public REDocumentDeclaration parseVGM(String url) throws SAXException, ParserConfigurationException, IOException
parseVGMback to summary
public REDocumentDeclaration parseVGM(InputSource source) throws SAXException, ParserConfigurationException, IOException
setControllerback to summary
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.

setPoolback to summary
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.

setSAXParserFactoryback to summary
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()).

setStrictCheckback to summary
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.

wrapByVGMback to summary
private static REDocumentDeclaration wrapByVGM(Grammar g)
com.sun.msv.reader.util back to summary

private Class GrammarLoader.GrammarLoaderException

extends RuntimeException
Class Inheritance
Annotations
@SuppressWarnings:serial

wrapper exception so that we can throw it from the GrammarReaderController.

Field Summary

Modifier and TypeField and Description
public final SAXException
e

Constructor Summary

AccessConstructor and Description
pack-priv

Field Detail

eback to summary
public final SAXException e

Constructor Detail

GrammarLoaderExceptionback to summary
pack-priv GrammarLoaderException(SAXException e)
com.sun.msv.reader.util back to summary

private Class GrammarLoader.ThrowController

extends Object
implements GrammarReaderController
Class Inheritance
All Implemented Interfaces
com.sun.msv.reader.GrammarReaderController, org.xml.sax.EntityResolver

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
error(Locator[] locs, String errorMessage, Exception nestedException)

Implements com.sun.msv.reader.GrammarReaderController.error.

public InputSource
resolveEntity(String
The public identifier of the external entity being referenced, or null if none was supplied.
p
,
String
The system identifier of the external entity being referenced.
s
)

Implements org.xml.sax.EntityResolver.resolveEntity.

Allow the application to resolve external entities.
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ThrowControllerback to summary
private ThrowController()

Method Detail

errorback to summary
public void error(Locator[] locs, String errorMessage, Exception nestedException)

Implements com.sun.msv.reader.GrammarReaderController.error.

resolveEntityback to summary
public InputSource resolveEntity(String p, String s)

Implements org.xml.sax.EntityResolver.resolveEntity.

Doc from org.xml.sax.EntityResolver.resolveEntity.

Allow the application to resolve external entities.

The parser will call this method before opening any external entity except the top-level document entity. Such entities include the external DTD subset and external parameter entities referenced within the DTD (in either case, only if the parser reads external parameter entities), and external general entities referenced within the document element (if the parser reads external general entities). The application may request that the parser locate the entity itself, that it use an alternative URI, or that it use data provided by the application (as a character or byte input stream).

Application writers can use this method to redirect external system identifiers to secure and/or local URIs, to look up public identifiers in a catalogue, or to read an entity from a database or other input source (including, for example, a dialog box). Neither XML nor SAX specifies a preferred policy for using public or system IDs to resolve resources. However, SAX specifies how to interpret any InputSource returned by this method, and that if none is returned, then the system ID will be dereferenced as a URL.

If the system identifier is a URL, the SAX parser must resolve it fully before reporting it to the application.

Parameters
p:String

The public identifier of the external entity being referenced, or null if none was supplied.

s:String

The system identifier of the external entity being referenced.

Returns:InputSource

An InputSource object describing the new input source, or null to request that the parser open a regular URI connection to the system identifier.

warningback to summary
public void warning(Locator[] locs, String errorMessage)

Implements com.sun.msv.reader.GrammarReaderController.warning.