1 package com.thaiopensource.relaxng.parse.sax;2 3 import com.thaiopensource.xml.sax.XMLReaderCreator;4 import com.thaiopensource.relaxng.parse.BuildException;5 import com.thaiopensource.relaxng.parse.IllegalSchemaException;6 import com.thaiopensource.relaxng.parse.Parseable;7 import com.thaiopensource.relaxng.parse.ParsedPattern;8 import com.thaiopensource.relaxng.parse.SchemaBuilder;9 import com.thaiopensource.relaxng.parse.Scope;10 import org.xml.sax.ErrorHandler ;11 import org.xml.sax.InputSource ;12 import org.xml.sax.SAXException ;13 import org.xml.sax.XMLReader ;14 15 import java.io.IOException ;16 17 public class SAXParseable extends SAXSubParser implements Parseable {18 private final InputSource in;19 20 public SAXParseable(XMLReaderCreator xrc, InputSource in, ErrorHandler eh) {21 super(xrc, eh);22 this.in = in;23 }24 25 public ParsedPattern parse(SchemaBuilder schemaBuilder, Scope scope) throws BuildException, IllegalSchemaException {26 try {27 XMLReader xr = xrc.createXMLReader();28 SchemaParser sp = new SchemaParser(xr, eh, schemaBuilder, null, scope);29 xr.parse(in);30 return sp.getParsedPattern();31 }32 catch (SAXException e) {33 throw toBuildException(e);34 }35 catch (IOException e) {36 throw new BuildException(e);37 }38 }39 40 }41