- private def void implementsType(CtClass it, CtClass supertype) {
- checkArgument(supertype.interface, "Supertype must be interface");
- addInterface(supertype);
+ protected def generateListenerInvoker(Class<? extends NotificationListener> iface) {
+ val callbacks = iface.methods.filter[notificationCallback]
+
+ val supportedNotification = callbacks.map[parameterTypes.get(0) as Class<? extends Notification>].toSet;
+
+ val targetCls = createClass(iface.invokerName, BROKER_NOTIFICATION_LISTENER) [
+ field(DELEGATE_FIELD, iface)
+ implementMethodsFrom(BROKER_NOTIFICATION_LISTENER) [
+ body = '''
+ {
+ «FOR callback : callbacks SEPARATOR " else "»
+ «val cls = callback.parameterTypes.get(0).name»
+ if($1 instanceof «cls») {
+ «DELEGATE_FIELD».«callback.name»((«cls») $1);
+ return null;
+ }
+ «ENDFOR»
+ return null;
+ }
+ '''
+ ]
+ ]
+ val finalClass = targetCls.toClass(iface.classLoader, iface.protectionDomain)
+ return new RuntimeGeneratedInvokerPrototype(supportedNotification,
+ finalClass as Class<? extends org.opendaylight.controller.sal.binding.api.NotificationListener<?>>);