2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.sal.binding.codegen;
10 import com.google.common.base.Objects;
11 import java.lang.reflect.Field;
13 import org.eclipse.xtext.xbase.lib.Exceptions;
14 import org.opendaylight.controller.sal.binding.codegen.RuntimeCodeSpecification;
15 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
17 import org.opendaylight.yangtools.yang.binding.RpcService;
19 @SuppressWarnings("all")
20 public class RuntimeCodeHelper {
22 * Helper method to return delegate from ManagedDirectedProxy with use of reflection.
24 * Note: This method uses reflection, but access to delegate field should be
25 * avoided and called only if neccessary.
27 public static <T extends RpcService> T getDelegate(final RpcService proxy) {
29 Class<? extends RpcService> _class = proxy.getClass();
30 final Field field = _class.getField(RuntimeCodeSpecification.DELEGATE_FIELD);
31 boolean _equals = Objects.equal(field, null);
33 UnsupportedOperationException _unsupportedOperationException = new UnsupportedOperationException("Unable to get delegate from proxy");
34 throw _unsupportedOperationException;
37 Object _get = field.get(proxy);
39 } catch (Throwable _e) {
40 throw Exceptions.sneakyThrow(_e);
42 } catch (Throwable _e_1) {
43 throw Exceptions.sneakyThrow(_e_1);
48 * Helper method to set delegate to ManagedDirectedProxy with use of reflection.
50 * Note: This method uses reflection, but setting delegate field should not occur too much
51 * to introduce any significant performance hits.
53 public static void setDelegate(final RpcService proxy, final RpcService delegate) {
55 Class<? extends RpcService> _class = proxy.getClass();
56 final Field field = _class.getField(RuntimeCodeSpecification.DELEGATE_FIELD);
57 boolean _equals = Objects.equal(field, null);
59 UnsupportedOperationException _unsupportedOperationException = new UnsupportedOperationException("Unable to set delegate to proxy");
60 throw _unsupportedOperationException;
63 boolean _equals_1 = Objects.equal(delegate, null);
67 Class<? extends Object> _type = field.getType();
68 Class<? extends RpcService> _class_1 = delegate.getClass();
69 boolean _isAssignableFrom = _type.isAssignableFrom(_class_1);
70 _or = (_equals_1 || _isAssignableFrom);
73 field.set(proxy, delegate);
75 IllegalArgumentException _illegalArgumentException = new IllegalArgumentException("delegate class is not assignable to proxy");
76 throw _illegalArgumentException;
78 } catch (Throwable _e) {
79 throw Exceptions.sneakyThrow(_e);
84 * Helper method to set delegate to ManagedDirectedProxy with use of reflection.
86 * Note: This method uses reflection, but setting delegate field should not occur too much
87 * to introduce any significant performance hits.
89 public static void setDelegate(final Object proxy, final Object delegate) {
91 Class<? extends Object> _class = proxy.getClass();
92 final Field field = _class.getField(RuntimeCodeSpecification.DELEGATE_FIELD);
93 boolean _equals = Objects.equal(field, null);
95 UnsupportedOperationException _unsupportedOperationException = new UnsupportedOperationException("Unable to set delegate to proxy");
96 throw _unsupportedOperationException;
99 boolean _equals_1 = Objects.equal(delegate, null);
103 Class<? extends Object> _type = field.getType();
104 Class<? extends Object> _class_1 = delegate.getClass();
105 boolean _isAssignableFrom = _type.isAssignableFrom(_class_1);
106 _or = (_equals_1 || _isAssignableFrom);
109 field.set(proxy, delegate);
111 IllegalArgumentException _illegalArgumentException = new IllegalArgumentException("delegate class is not assignable to proxy");
112 throw _illegalArgumentException;
114 } catch (Throwable _e) {
115 throw Exceptions.sneakyThrow(_e);
119 public static Map<InstanceIdentifier<? extends Object>,? extends RpcService> getRoutingTable(final RpcService target, final Class<? extends BaseIdentity> tableClass) {
121 Class<? extends RpcService> _class = target.getClass();
122 String _routingTableField = RuntimeCodeSpecification.getRoutingTableField(tableClass);
123 final Field field = _class.getField(_routingTableField);
124 boolean _equals = Objects.equal(field, null);
126 UnsupportedOperationException _unsupportedOperationException = new UnsupportedOperationException(
127 "Unable to get routing table. Table field does not exists");
128 throw _unsupportedOperationException;
131 Object _get = field.get(target);
132 return ((Map<InstanceIdentifier<? extends Object>,? extends RpcService>) _get);
133 } catch (Throwable _e) {
134 throw Exceptions.sneakyThrow(_e);
136 } catch (Throwable _e_1) {
137 throw Exceptions.sneakyThrow(_e_1);
141 public static void setRoutingTable(final RpcService target, final Class<? extends BaseIdentity> tableClass, final Map<InstanceIdentifier<? extends Object>,? extends RpcService> routingTable) {
143 Class<? extends RpcService> _class = target.getClass();
144 String _routingTableField = RuntimeCodeSpecification.getRoutingTableField(tableClass);
145 final Field field = _class.getField(_routingTableField);
146 boolean _equals = Objects.equal(field, null);
148 UnsupportedOperationException _unsupportedOperationException = new UnsupportedOperationException(
149 "Unable to set routing table. Table field does not exists");
150 throw _unsupportedOperationException;
152 field.set(target, routingTable);
153 } catch (Throwable _e) {
154 throw Exceptions.sneakyThrow(_e);