*
* @see org.exolab.castor.builder.SourceGenerator
* #generateSource(org.xml.sax.InputSource, java.lang.String)
*/
public void generateSource(final InputSource source, final String packageName) {
Parser parser = null;
try {
parser = _internalContext.getParser();
} catch (RuntimeException e) {
throw new BuildException("Unable to create SAX parser.", e);
}
if (parser == null) {
throw new BuildException("Unable to create SAX parser.");
}
SchemaContext schemaContext = new SchemaContextImpl();
SchemaUnmarshaller schemaUnmarshaller = null;
try {
schemaUnmarshaller = new SchemaUnmarshaller(schemaContext);
} catch (XMLException e) {
throw new BuildException("Unable to create schema unmarshaller.", e);
}
Sax2ComponentReader handler = new Sax2ComponentReader(schemaUnmarshaller);
parser.setDocumentHandler(handler);
parser.setErrorHandler(handler);
try {
parser.parse(source);
} catch (IOException e) {
String msg = "Can't read input file " + source.getSystemId() + ".\n" + e;
throw new BuildException(msg, e);
} catch (SAXException e) {
String msg = "Can't parse input file " + source.getSystemId() + ".\n" + e;