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.java;fp=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fbinding%2Fcodegen%2FRuntimeCodeHelper.java;h=0000000000000000000000000000000000000000;hp=ae90a7739eb6fff27d8aff5265d3d6c397b5e5ad;hb=39820d64e08adb79530b03a000daeaab44f5761c;hpb=d7b9d07f266accf0e2bb6fd80fe994379bafba9b diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeHelper.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeHelper.java deleted file mode 100644 index ae90a7739e..0000000000 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeHelper.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.sal.binding.codegen; - -import java.lang.reflect.Field; -import java.util.Map; - -import org.opendaylight.yangtools.yang.binding.BaseIdentity; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.binding.RpcService; - -public final class RuntimeCodeHelper { - private RuntimeCodeHelper() { - throw new UnsupportedOperationException("Utility class should never be instantiated"); - } - - private static Field getField(final Class cls, final String name) { - try { - return cls.getField(name); - } catch (NoSuchFieldException e) { - throw new IllegalArgumentException( - String.format("Class %s is missing field %s", cls, name), e); - } catch (SecurityException e) { - throw new IllegalStateException(String.format("Failed to examine class %s", cls), e); - } - } - - private static Field getDelegateField(final Class cls) { - return getField(cls, RuntimeCodeSpecification.DELEGATE_FIELD); - } - - private static Object getFieldValue(final Field field, final Object obj) { - try { - return field.get(obj); - } catch (IllegalAccessException e) { - throw new IllegalStateException(String.format("Failed to get field %s of object %s", field, obj), e); - } - } - - private static void setFieldValue(final Field field, final Object obj, final Object value) { - try { - field.set(obj, value); - } catch (IllegalAccessException e) { - throw new IllegalStateException(String.format("Failed to set field %s to %s", field, value), e); - } - } - - /** - * Helper method to return delegate from ManagedDirectedProxy with use of reflection. - * - * Note: This method uses reflection, but access to delegate field should be - * avoided and called only if necessary. - */ - @SuppressWarnings("unchecked") - public static T getDelegate(final RpcService proxy) { - return (T)getFieldValue(getDelegateField(proxy.getClass()), 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 void setDelegate(final Object proxy, final Object delegate) { - final Field field = getDelegateField(proxy.getClass()); - - if (delegate != null) { - final Class ft = field.getType(); - if (!ft.isAssignableFrom(delegate.getClass())) { - throw new IllegalArgumentException( - String.format("Field %s type %s is not compatible with delegate type %s", - field, ft, delegate.getClass())); - } - } - - setFieldValue(field, proxy, delegate); - } - - @SuppressWarnings("unchecked") - public static Map,? extends RpcService> getRoutingTable(final RpcService target, final Class tableClass) { - final Field field = getField(target.getClass(), RuntimeCodeSpecification.getRoutingTableField(tableClass)); - return (Map,? extends RpcService>) getFieldValue(field, target); - } - - public static void setRoutingTable(final RpcService target, final Class tableClass, final Map,? extends RpcService> routingTable) { - final Field field = getField(target.getClass(), RuntimeCodeSpecification.getRoutingTableField(tableClass)); - setFieldValue(field, target, routingTable); - } -}