/**
* Compiles internal callback registry.
*/
synchronized void initCallbacks() {
if (callbackRegistry == null) {
LifecycleCallbackRegistry callbackRegistry = new LifecycleCallbackRegistry(
this);
// load default callbacks
for (DataMap map : maps) {
for (EntityListener listener : map.getDefaultEntityListeners()) {
Object listenerInstance = createListener(listener, null);
if (listenerInstance == null) {
continue;
}
CallbackDescriptor[] callbacks = listener
.getCallbackMap()
.getCallbacks();
for (CallbackDescriptor callback : callbacks) {
for (String method : callback.getCallbackMethods()) {
// note that callbacks[i].getCallbackType() == i
callbackRegistry.addDefaultListener(callback
.getCallbackType(), listenerInstance, method);
}
}
}
}
// load entity callbacks
for (ObjEntity entity : getObjEntities()) {
Class<?> entityClass = entity.getJavaClass();
// external listeners go first, entity's own callbacks go next
for (EntityListener listener : entity.getEntityListeners()) {
Object listenerInstance = createListener(listener, entity);
if (listenerInstance == null) {
continue;
}
CallbackDescriptor[] callbacks = listener
.getCallbackMap()
.getCallbacks();
for (CallbackDescriptor callback : callbacks) {
for (String method : callback.getCallbackMethods()) {
callbackRegistry.addListener(
callback.getCallbackType(),
entityClass,
listenerInstance,
method);
}
}
}
CallbackDescriptor[] callbacks = entity.getCallbackMap().getCallbacks();
for (CallbackDescriptor callback : callbacks) {
for (String method : callback.getCallbackMethods()) {
callbackRegistry.addListener(
callback.getCallbackType(),
entityClass,
method);
}
}