X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fbinding%2Fcodegen%2FRuntimeCodeHelper.xtend;h=dff0d215b2ac14dece9c9139d677db4de3d74f65;hp=6bdb3c8fbed555b188c17fd9789fb4d7af9a93c7;hb=8f4996a3a1d486d83907c656a6c5390686c360a1;hpb=2887eded48bd70a9e332e98530f23304ce153bc7 diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeHelper.xtend b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeHelper.xtend index 6bdb3c8fbe..dff0d215b2 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeHelper.xtend +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeHelper.xtend @@ -39,27 +39,43 @@ class RuntimeCodeHelper { public static def void setDelegate(RpcService proxy, RpcService delegate) { val field = proxy.class.getField(DELEGATE_FIELD) if (field == null) throw new UnsupportedOperationException("Unable to set delegate to proxy"); - if (field.type.isAssignableFrom(delegate.class)) { + if (delegate == null || field.type.isAssignableFrom(delegate.class)) { field.set(proxy, delegate) } else throw new IllegalArgumentException("delegate class is not assignable to proxy"); } + + /** + * Helper method to set delegate to ManagedDirectedProxy with use of reflection. + * + * Note: This method uses reflection, but setting delegate field should not occur too much + * to introduce any significant performance hits. + * + */ + public static def void setDelegate(Object proxy, Object delegate) { + val field = proxy.class.getField(DELEGATE_FIELD) + if (field == null) throw new UnsupportedOperationException("Unable to set delegate to proxy"); + if (delegate == null || field.type.isAssignableFrom(delegate.class)) { + field.set(proxy, delegate) + } else + throw new IllegalArgumentException("delegate class is not assignable to proxy"); + } + - public static def Map getRoutingTable(RpcService target, + public static def Map, ? extends RpcService> getRoutingTable(RpcService target, Class tableClass) { val field = target.class.getField(tableClass.routingTableField) if (field == null) throw new UnsupportedOperationException( "Unable to get routing table. Table field does not exists"); - return field.get(target) as Map; + return field.get(target) as Map, ? extends RpcService>; } public static def void setRoutingTable(RpcService target, Class tableClass, - Map routingTable) { + Map, ? extends RpcService> routingTable) { val field = target.class.getField(tableClass.routingTableField) if (field == null) throw new UnsupportedOperationException( "Unable to set routing table. Table field does not exists"); field.set(target,routingTable); - } }