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.impl;
10 import com.google.common.base.Objects;
11 import com.google.common.base.Preconditions;
13 import org.opendaylight.controller.sal.binding.codegen.RuntimeCodeHelper;
14 import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory.NotificationInvoker;
15 import org.opendaylight.yangtools.yang.binding.Notification;
16 import org.opendaylight.yangtools.yang.binding.NotificationListener;
18 final class RuntimeGeneratedInvoker implements NotificationInvoker {
19 private final org.opendaylight.controller.sal.binding.api.NotificationListener<Notification> invocationProxy;
20 private final RuntimeGeneratedInvokerPrototype prototype;
21 private final NotificationListener delegate;
23 @SuppressWarnings("unchecked")
24 private RuntimeGeneratedInvoker(final NotificationListener delegate, final RuntimeGeneratedInvokerPrototype prototype, final org.opendaylight.controller.sal.binding.api.NotificationListener<?> proxy) {
25 this.invocationProxy = (org.opendaylight.controller.sal.binding.api.NotificationListener<Notification>) proxy;
26 this.delegate = Preconditions.checkNotNull(delegate);
27 this.prototype = prototype;
30 public static RuntimeGeneratedInvoker create(final NotificationListener delegate, final RuntimeGeneratedInvokerPrototype prototype) throws InstantiationException, IllegalAccessException {
31 final org.opendaylight.controller.sal.binding.api.NotificationListener<?> proxy = Preconditions.checkNotNull(prototype.getProtoClass().newInstance());
32 RuntimeCodeHelper.setDelegate(proxy, delegate);
33 return new RuntimeGeneratedInvoker(delegate, prototype, proxy);
37 public NotificationListener getDelegate() {
42 public org.opendaylight.controller.sal.binding.api.NotificationListener<Notification> getInvocationProxy() {
43 return invocationProxy;
47 public Set<Class<? extends Notification>> getSupportedNotifications() {
48 return prototype.getSupportedNotifications();
57 public int hashCode() {
60 result = prime * result + delegate.hashCode();
61 result = prime * result + invocationProxy.hashCode();
62 result = prime * result + prototype.hashCode();
67 public boolean equals(final Object obj) {
71 if (!(obj instanceof RuntimeGeneratedInvoker)) {
74 final RuntimeGeneratedInvoker other = (RuntimeGeneratedInvoker) obj;
75 if (!delegate.equals(other.delegate)) {
78 if (!invocationProxy.equals(other.invocationProxy)) {
81 return prototype.equals(other.prototype);
85 public String toString() {
86 return Objects.toStringHelper(this).toString();