if (!Boolean.parseBoolean(Play.configuration.getProperty("morphia.autoRegisterEventHandler", "true"))) return;
// -- register handlers from event handler class --
List<Class> classes = Play.classloader.getAssignableClasses(IMorphiaEventHandler.class);
for (Class c: classes) {
IMorphiaEventHandler h = null;
try {
Constructor cnst = c.getDeclaredConstructor();
cnst.setAccessible(true);
h = (IMorphiaEventHandler)cnst.newInstance();
} catch (Exception e) {
Logger.error(e, "Cannot init IMorphiaEventHandler from class: %s", c.getName());
continue;
}
Watch w = (Watch)c.getAnnotation(Watch.class);
if (null != w) {
Class[] ca = w.value();
for (Class modelClass: ca) {
registerModelEventHandlers_(modelClass, h);
}
}
}
// -- register handlers from model class --
classes = Play.classloader.getAssignableClasses(Model.class);
for (Class c: classes) {
WatchBy wb = (WatchBy)c.getAnnotation(WatchBy.class);
if (null == wb) continue;
Class[] ca = wb.value();
for (Class handler: ca) {
if ((IMorphiaEventHandler.class.isAssignableFrom(handler))) {
IMorphiaEventHandler h = null;
try {
Constructor cnst = handler.getDeclaredConstructor();
cnst.setAccessible(true);
h = (IMorphiaEventHandler)cnst.newInstance();
} catch (Exception e) {