Do not pull in xtend-lib-osgi
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / sal / binding / codegen / impl / RuntimeGeneratedInvoker.java
1 /**
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.sal.binding.codegen.impl;
9
10 import com.google.common.base.Objects;
11 import com.google.common.base.Preconditions;
12 import java.util.Set;
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;
17
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;
22
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;
28     }
29
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);
34     }
35
36     @Override
37     public NotificationListener getDelegate() {
38         return delegate;
39     }
40
41     @Override
42     public org.opendaylight.controller.sal.binding.api.NotificationListener<Notification> getInvocationProxy() {
43         return invocationProxy;
44     }
45
46     @Override
47     public Set<Class<? extends Notification>> getSupportedNotifications() {
48         return prototype.getSupportedNotifications();
49     }
50
51     @Override
52     public void close() {
53         // Nothing to do
54     }
55
56     @Override
57     public int hashCode() {
58         final int prime = 31;
59         int result = 1;
60         result = prime * result + delegate.hashCode();
61         result = prime * result + invocationProxy.hashCode();
62         result = prime * result + prototype.hashCode();
63         return result;
64     }
65
66     @Override
67     public boolean equals(final Object obj) {
68         if (this == obj) {
69             return true;
70         }
71         if (!(obj instanceof RuntimeGeneratedInvoker)) {
72             return false;
73         }
74         final RuntimeGeneratedInvoker other = (RuntimeGeneratedInvoker) obj;
75         if (!delegate.equals(other.delegate)) {
76             return false;
77         }
78         if (!invocationProxy.equals(other.invocationProxy)) {
79             return false;
80         }
81         return prototype.equals(other.prototype);
82     }
83
84     @Override
85     public String toString() {
86         return Objects.toStringHelper(this).toString();
87     }
88 }