List<Reference> classes = new ArrayList<Reference>();
// simply ignore all the interface definitions,
// so that users won't have to manually exclude interfaces, which is silly.
filterClass(classes, roundEnv.getRootElements());
J2SJAXBModel model = XJC.createJavaCompiler().bind(classes, Collections.<QName, Reference>emptyMap(), null, processingEnv);
if (model == null)
return false; // error
try {
model.generateSchema(
new SchemaOutputResolver() {
public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
File file;
OutputStream out;
if (schemaLocations.containsKey(namespaceUri)) {
file = schemaLocations.get(namespaceUri);
if (file == null) return null; // don't generate
out = new FileOutputStream(file);
} else {
// use the default
file = new File(suggestedFileName);
out = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", suggestedFileName)
.openOutputStream();
file = file.getAbsoluteFile();
}
StreamResult ss = new StreamResult(out);
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Writing "+file);
ss.setSystemId(file.toURL().toExternalForm());
return ss;
}
}, errorListener);
if (episodeFile != null) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Writing "+episodeFile);
model.generateEpisodeFile(new StreamResult(episodeFile));
}
} catch (IOException e) {
errorListener.error(e.getMessage(), e);
}
return false;