use of com.sun.tools.xjc.util.ErrorReceiverFilter in project raml-for-jax-rs by mulesoft-labs.
the class JAXBHelper method generateClassesFromXmlSchemas.
private static List<JDefinedClass> generateClassesFromXmlSchemas(String pack, JCodeModel codeModel, File schemaFile) throws GenerationException {
try {
ArrayList<JDefinedClass> classList = new ArrayList<JDefinedClass>();
ArrayList<String> argList = new ArrayList<>();
argList.add("-mark-generated");
argList.add("-p");
argList.add(pack);
argList.add(schemaFile.getAbsolutePath());
String[] args = argList.toArray(new String[argList.size()]);
final Options opt = new Options();
opt.setSchemaLanguage(Language.XMLSCHEMA);
opt.parseArguments(args);
ErrorReceiver receiver = new ErrorReceiverFilter() {
@Override
public void info(SAXParseException exception) {
if (opt.verbose)
super.info(exception);
}
@Override
public void warning(SAXParseException exception) {
if (!opt.quiet)
super.warning(exception);
}
};
Model model = ModelLoader.load(opt, codeModel, receiver);
Outline outline = model.generateCode(opt, receiver);
for (ClassOutline co : outline.getClasses()) {
JDefinedClass cl = co.implClass;
if (cl.outer() == null) {
classList.add(cl);
}
}
return classList;
} catch (Exception e) {
throw new GenerationException(e);
}
}
Aggregations