if (gc.sc.callBacks.isEmpty()) {
return;
}
// public void sendEvt...
CodeVisitor mv = gc.cv.visitMethod(ACC_PUBLIC, "sendEvent",
"(ILjava/lang/Object;Ljava/lang/Object;Z)V", null, null);
int nbCase = gc.sc.callBacks.size();
int[] keys = new int[nbCase];
Label[] keyLabels = new Label[nbCase];
int i = 0;
List keysList = new ArrayList((Set<Integer>) gc.sc.callBacks.keySet());
Collections.sort(keysList);
for (int cbid : (List<Integer>) keysList) {
keys[i] = cbid;
keyLabels[i] = new Label();
i++;
}
Label switchEndLabel = new Label();
mv.visitVarInsn(ILOAD, 1);
mv.visitLookupSwitchInsn(switchEndLabel, keys, keyLabels);
String listenclass = null;
// switch (evt.type) {
for (int j = 0; j < nbCase; j++) {
// case [assoc EJB_CB(cbn) <-> evt.type]:
mv.visitLabel(keyLabels[j]);
ArrayList<SpeedoCallback> cbl = (ArrayList<SpeedoCallback>) gc.sc.callBacks.get(keys[j]);
if (cbl == null) {
continue;
}
for (SpeedoCallback actualcbn : cbl) {
if (actualcbn.listenerClassName == null) { // this a callback from the persistent class
// CALL THE CALLBACK METHOD INTO THE PERSISTENT CLASS
mv.visitVarInsn(ALOAD, 2);
mv.visitTypeInsn(CHECKCAST, gc.xJCN);
mv.visitMethodInsn(INVOKEVIRTUAL, gc.xJCN,
actualcbn.callbackName,
actualcbn.methodByteCodeSignature);
} else { // this is a callback from the listener class
if (listenclass == null) {
listenclass = actualcbn.listenerClassName;
}
// CALL THE CALLBACK METHOD INTO THE LISTENER CLASS
//this.eventListener.myMethod(param1)
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, gc.xHomeJCN, LISTENER_FIELD,
getJVMType(actualcbn.listenerClassName));
mv.visitVarInsn(ALOAD, 2);
mv.visitTypeInsn(CHECKCAST, gc.xJCN);
mv.visitMethodInsn(INVOKEVIRTUAL,
getJVMClassName(actualcbn.listenerClassName),
actualcbn.callbackName,
actualcbn.methodByteCodeSignature);
}
}
// break;
mv.visitJumpInsn(GOTO, switchEndLabel);
}
mv.visitLabel(switchEndLabel);
// }
mv.visitInsn(RETURN);
mv.visitMaxs(0, 0);
if (listenclass != null) {
// ADD THE DEFINITION OF THE LISTENER CLASS VARIABLE
gc.cv.visitField(ACC_PUBLIC + ACC_FINAL,
LISTENER_FIELD, getJVMType(listenclass), null, null);
gc.ctx.put("listenClass", listenclass);
}
//public boolean hasInstanceLifeCycleListeners() {
mv = gc.cv.visitMethod(ACC_PUBLIC, "hasInstanceLifeCycleListeners",
"()Z", null, null);
//return true;
mv.visitInsn(ICONST_1);
mv.visitInsn(IRETURN);
mv.visitMaxs(0, 0);
//}
}