+ private def getJavaClass(CtClass cls) {
+ Thread.currentThread.contextClassLoader.loadClass(cls.name)
+ }
+
+ override getInvokerFactory() {
+ return this;
+ }
+
+ override invokerFor(NotificationListener instance) {
+ val cls = instance.class
+ val prototype = resolveInvokerClass(cls);
+
+ return new RuntimeGeneratedInvoker(instance, prototype)
+ }
+
+ 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>);
+ }
+
+ private def void method(CtClass it, Class<?> returnType, String name, Class<?> parameter, MethodGenerator function1) {
+ val method = new CtMethod(returnType.asCtClass, name, Arrays.asList(parameter.asCtClass), it);
+ function1.process(method);
+ it.addMethod(method);
+ }
+