use of pl.themolka.arcade.parser.ParsersFile in project Arcade2 by ShootGame.
the class ArcadePlugin method loadParsers.
private void loadParsers() {
this.domEngines = new EngineManager();
this.domEngines.registerDefault();
this.domPreprocessor = new Preprocessor();
this.domPreprocessor.install(new Import(this.domEngines, this.domPreprocessor));
this.parsers = new ParserManager(this);
this.parsers.setContextFactory(new ParserContext.Factory());
try (InputStream input = this.getClass().getClassLoader().getResourceAsStream(ParsersFile.DEFAULT_FILENAME)) {
ParsersFile file = new ParsersFile(this, input);
int done = 0;
int doneSilent = 0;
ParserContainer container = new ParserContainer();
for (Class<? extends Parser<?>> parser : file.getParsers()) {
try {
container.register(parser.newInstance());
done++;
Silent silent = parser.getAnnotation(Silent.class);
Produces produces = parser.getAnnotation(Produces.class);
if (produces == null) {
throw new ReflectiveOperationException(parser.getName() + " is not @Produces decorated!");
} else if (silent == null) {
Class<?> producesType = produces.value();
if (producesType != null) {
this.parsers.registerType(producesType, parser);
}
} else {
doneSilent++;
}
} catch (ReflectiveOperationException ex) {
ex.printStackTrace();
}
}
this.parsers.getContainer().register(container);
String silentString = "";
if (doneSilent > 0) {
silentString = " (" + doneSilent + " of them " + (doneSilent == 1 ? "was" : "were") + " silent)";
}
this.getLogger().info("Registered " + done + " parsers" + silentString + ".");
} catch (DOMException | IOException ex) {
ex.printStackTrace();
}
// Install parser dependencies
int done = 0;
try {
done = this.parsers.install();
} catch (ParserNotSupportedException ex) {
this.getLogger().log(Level.SEVERE, "Given parser is not supported", ex);
}
this.getLogger().info("Installed " + done + " parser dependencies.");
}
Aggregations