001 package com.thaiopensource.relaxng.jarv;
002
003 import com.thaiopensource.validate.IncorrectSchemaException;
004 import com.thaiopensource.xml.sax.XMLReaderCreator;
005 import com.thaiopensource.relaxng.impl.SchemaBuilderImpl;
006 import com.thaiopensource.relaxng.impl.SchemaPatternBuilder;
007 import com.thaiopensource.relaxng.parse.Parseable;
008 import com.thaiopensource.relaxng.parse.sax.SAXParseable;
009 import com.thaiopensource.xml.sax.DraconianErrorHandler;
010 import com.thaiopensource.xml.sax.Jaxp11XMLReaderCreator;
011 import org.iso_relax.verifier.Schema;
012 import org.iso_relax.verifier.VerifierFactory;
013 import org.relaxng.datatype.DatatypeLibraryFactory;
014 import org.relaxng.datatype.helpers.DatatypeLibraryLoader;
015 import org.xml.sax.EntityResolver;
016 import org.xml.sax.ErrorHandler;
017 import org.xml.sax.InputSource;
018 import org.xml.sax.SAXException;
019 import org.xml.sax.helpers.DefaultHandler;
020
021 import java.io.IOException;
022
023 public class VerifierFactoryImpl extends VerifierFactory {
024 private final XMLReaderCreator xrc = new Jaxp11XMLReaderCreator();
025 private final DatatypeLibraryFactory dlf = new DatatypeLibraryLoader();
026 private final ErrorHandler eh = new DraconianErrorHandler();
027 private final EntityResolver er = new DefaultHandler();
028
029 public VerifierFactoryImpl() { }
030
031 public Schema compileSchema(InputSource is) throws SAXException, IOException {
032 SchemaPatternBuilder spb = new SchemaPatternBuilder();
033 Parseable parseable = new SAXParseable(xrc, is, eh, er);
034 try {
035 return new SchemaImpl(SchemaBuilderImpl.parse(parseable, eh, dlf, spb, false), spb);
036 }
037 catch (IncorrectSchemaException e) {
038 throw new SAXException("unreported schema error");
039 }
040 }
041 }