Add InstanceNotification(Publish)ServiceAdapter
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / main / java / org / opendaylight / mdsal / binding / dom / adapter / KeyedInstanceNotificationListenerAdapter.java
diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/KeyedInstanceNotificationListenerAdapter.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/KeyedInstanceNotificationListenerAdapter.java
new file mode 100644 (file)
index 0000000..a1d9a6d
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2015 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.mdsal.binding.dom.adapter;
+
+import static com.google.common.base.Verify.verify;
+
+import java.util.concurrent.Executor;
+import org.opendaylight.mdsal.binding.api.InstanceNotificationService.KeyedListListener;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.Identifiable;
+import org.opendaylight.yangtools.yang.binding.Identifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedListNotification;
+
+final class KeyedInstanceNotificationListenerAdapter<P extends DataObject & Identifiable<K>, K extends Identifier<P>,
+            N extends KeyedListNotification<N, P, K>>
+        extends AbstractInstanceNotificationListenerAdapter<P, N, KeyedListListener<P, N, K>> {
+    KeyedInstanceNotificationListenerAdapter(final AdapterContext adapterContext, final Class<N> notificationClass,
+            final KeyedListListener<P, N, K> delegate, final Executor executor) {
+        super(adapterContext, notificationClass, delegate, executor);
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    void onNotification(final KeyedListListener<P, N, K> delegate, final InstanceIdentifier<?> path,
+            final N notification) {
+        verify(path instanceof KeyedInstanceIdentifier, "Unexpected path %s", path);
+        delegate.onNotification((KeyedInstanceIdentifier<P, K>) path, notification);
+    }
+}