Move LegacyDOMDataBrokerAdapter to sal-core-compat
[controller.git] / opendaylight / md-sal / sal-dom-compat / src / main / java / org / opendaylight / controller / sal / core / compat / ReadFailedExceptionAdapter.java
diff --git a/opendaylight/md-sal/sal-dom-compat/src/main/java/org/opendaylight/controller/sal/core/compat/ReadFailedExceptionAdapter.java b/opendaylight/md-sal/sal-dom-compat/src/main/java/org/opendaylight/controller/sal/core/compat/ReadFailedExceptionAdapter.java
new file mode 100644 (file)
index 0000000..a2fe06b
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2018 Inocybe Technologies 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.core.compat;
+
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.yangtools.util.concurrent.ExceptionMapper;
+
+/**
+ * Adapter that maps the controller API-based ReadFailedException to the mdsal API-based ReadFailedException.
+ *
+ * @author Thomas Pantelis
+ */
+public final class ReadFailedExceptionAdapter extends ExceptionMapper<ReadFailedException> {
+    public static final ReadFailedExceptionAdapter INSTANCE = new ReadFailedExceptionAdapter();
+
+    private ReadFailedExceptionAdapter() {
+        super("read", ReadFailedException.class);
+    }
+
+    @Override
+    protected ReadFailedException newWithCause(String message, Throwable cause) {
+        if (cause instanceof org.opendaylight.mdsal.common.api.ReadFailedException) {
+            return new ReadFailedException(cause.getMessage(), cause.getCause());
+        }
+
+        return new ReadFailedException(message, cause);
+    }
+}