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
1 /*
2  * Copyright (c) 2018 Inocybe Technologies 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.core.compat;
9
10 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
11 import org.opendaylight.yangtools.util.concurrent.ExceptionMapper;
12
13 /**
14  * Adapter that maps the controller API-based ReadFailedException to the mdsal API-based ReadFailedException.
15  *
16  * @author Thomas Pantelis
17  */
18 public final class ReadFailedExceptionAdapter extends ExceptionMapper<ReadFailedException> {
19     public static final ReadFailedExceptionAdapter INSTANCE = new ReadFailedExceptionAdapter();
20
21     private ReadFailedExceptionAdapter() {
22         super("read", ReadFailedException.class);
23     }
24
25     @Override
26     protected ReadFailedException newWithCause(String message, Throwable cause) {
27         if (cause instanceof org.opendaylight.mdsal.common.api.ReadFailedException) {
28             return new ReadFailedException(cause.getMessage(), cause.getCause());
29         }
30
31         return new ReadFailedException(message, cause);
32     }
33 }