use of ninja.utils.NinjaProperties in project ninja by ninjaframework.
the class Bootstrap method configure.
protected void configure() throws Exception {
// Base configuration of Ninja
addModule(new NinjaBaseModule(ninjaProperties));
// Main application module (conf.Module or com.example.conf.Module)
String applicationModuleClassName = ninjaBaseDirectoryResolver.resolveApplicationClassName(APPLICATION_GUICE_MODULE_CONVENTION_LOCATION);
AbstractModule applicationModule = null;
if (SwissKnife.doesClassExist(applicationModuleClassName, this)) {
Class<?> applicationModuleClass = Class.forName(applicationModuleClassName);
// Tries to instantiate module by giving the NinjaProperties as constructor arg
try {
applicationModule = (AbstractModule) applicationModuleClass.getConstructor(NinjaProperties.class).newInstance(ninjaProperties);
} catch (NoSuchMethodException e) {
applicationModule = (AbstractModule) applicationModuleClass.getConstructor().newInstance();
}
}
// Slipstream in the "classic" ninja configuration?
if (applicationModule == null || !(applicationModule instanceof FrameworkModule)) {
// Classic configuration of Ninja
logger.info("Enabling Ninja classic configuration");
addModule(new NinjaClassicModule(ninjaProperties));
}
if (applicationModule != null) {
addModule(applicationModule);
}
// Ninja module
String applicationNinjaClassName = ninjaBaseDirectoryResolver.resolveApplicationClassName(NINJA_CONVENTION_LOCATION);
final Class<? extends Ninja> ninjaClass;
if (SwissKnife.doesClassExist(applicationNinjaClassName, this)) {
final Class<?> clazzPotentially = Class.forName(applicationNinjaClassName);
if (Ninja.class.isAssignableFrom(clazzPotentially)) {
ninjaClass = (Class<? extends Ninja>) clazzPotentially;
} else {
final String ERROR_MESSAGE = String.format("Found a class %s in your application's conf directory." + " This class does not implement Ninja interface %s. " + " Please implement the interface or remove the class.", applicationNinjaClassName, Ninja.class.getName());
logger.error(ERROR_MESSAGE);
throw new IllegalStateException(ERROR_MESSAGE);
}
} else {
ninjaClass = NinjaDefault.class;
}
addModule(new AbstractModule() {
@Override
protected void configure() {
bind(Ninja.class).to(ninjaClass).in(Singleton.class);
}
});
}
Aggregations