Board sourceBoard;
try {
Class<?> sourceBoardClass = Class.forName("net.easymodo.asagi." + sourceEngine);
sourceBoard = (Board) sourceBoardClass.getConstructor(String.class, BoardSettings.class).newInstance(boardName, bSet);
} catch(ClassNotFoundException e) {
throw new BoardInitException("Error initializing board engine " + sourceEngine + ", no such engine?");
} catch(Exception e) {
throw new BoardInitException("Error initializing board engine " + sourceEngine);
}
// Same for DB engine
String boardEngine = bSet.getEngine() == null ? "Mysql" : bSet.getEngine();
bSet.setEngine(boardEngine);
Class<?> sqlBoardClass;
Constructor<?> boardCnst;
// Init two DB objects: one for topic insertion and another
// for media insertion
Object topicDbObj;
Object mediaDbObj;
try {
sqlBoardClass = Class.forName("net.easymodo.asagi." + boardEngine);
boardCnst = sqlBoardClass.getConstructor(String.class, BoardSettings.class);
// For topics
topicDbObj = boardCnst.newInstance(bSet.getPath(), bSet);
// For media
mediaDbObj = boardCnst.newInstance(bSet.getPath(), bSet);
} catch(ClassNotFoundException e) {
throw new BoardInitException("Could not find board engine for " + boardEngine);
} catch(NoSuchMethodException e) {
throw new BoardInitException("Error initializing board engine " + boardEngine);
} catch(InstantiationException e) {
throw new BoardInitException("Error initializing board engine " + boardEngine);
} catch(IllegalAccessException e) {
throw new BoardInitException("Error initializing board engine " + boardEngine);
} catch(InvocationTargetException e) {
if(e.getCause() instanceof BoardInitException)
throw (BoardInitException)e.getCause();
else if(e.getCause() instanceof RuntimeException)
throw (RuntimeException)e.getCause();
throw new BoardInitException("Error initializing board engine " + boardEngine);
}
// Making sure we got valid DB engines for post and media insertion
DB topicDb = null;
DB mediaDb = null;
if(topicDbObj instanceof DB && mediaDbObj instanceof DB) {
topicDb = (DB) topicDbObj;
mediaDb = (DB) mediaDbObj;
}
if(topicDb == null) {
throw new BoardInitException("Wrong engine specified for " + boardEngine);
}
Local topicLocalBoard = new Local(bSet.getPath(), bSet, topicDb);
Local mediaLocalBoard = new Local(bSet.getPath(), bSet, mediaDb);
// And the dumper, le sigh.
AbstractDumper dumper;
try {
Class<?> dumperClass = Class.forName("net.easymodo.asagi." + dumperEngine);
dumper = (AbstractDumper) dumperClass.getConstructor(String.class, Local.class, Local.class, Board.class, boolean.class, boolean.class, int.class)
.newInstance(boardName, topicLocalBoard, mediaLocalBoard, sourceBoard, fullThumb, fullMedia, pageLimbo);
} catch(ClassNotFoundException e) {
throw new BoardInitException("Error initializing dumper engine " + dumperEngine + ", no such engine?");
} catch(Exception e) {
throw new BoardInitException("Error initializing dumper engine " + dumperEngine);
}
dumper.initDumper(bSet);
}