throws SAXException, IOException {
if (! Validator.GRAMMAR_RELAX_NG.equals(grammar)) {
throw new IllegalArgumentException("Unsupported grammar " + grammar);
}
SchemaReader schemaReader = SAXSchemaReader.getInstance();
JingResolver context = new JingResolver(sourceResolver, entityResolver);
InputSource input = context.resolveSource(source);
try {
/* Create a simple property map builder */
PropertyMapBuilder builder = new PropertyMapBuilder();
ValidateProperty.ENTITY_RESOLVER.put(builder, context);
ValidateProperty.XML_READER_CREATOR.put(builder, context);
ValidateProperty.ERROR_HANDLER.put(builder,
DraconianErrorHandler.INSTANCE);
PropertyMap validatorProperties = builder.toPropertyMap();
/* Parse, rewrap, and return the schema */
final com.thaiopensource.validate.Schema schema;
schema = schemaReader.createSchema(input, validatorProperties);
return new JingSchema(schema, context.close());
} catch (IncorrectSchemaException exception) {
String message = "Incorrect schema \"" + source.getURI() + "\"";
throw new SAXException(message, exception);