Honeycomb-73 Extensible initializers framework
[honeycomb.git] / infra / translate-api / src / main / java / io / fd / honeycomb / translate / read / ReadFailedException.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.honeycomb.translate.read;
18
19 import static com.google.common.base.Preconditions.checkNotNull;
20
21 import io.fd.honeycomb.translate.TranslationException;
22 import javax.annotation.Nonnull;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24
25 /**
26  * Thrown when a reader or customizer is not able to read data for the given id.
27  */
28 public class ReadFailedException extends TranslationException {
29
30     private final InstanceIdentifier<?> failedId;
31
32     /**
33      * Constructs an ReadFailedException given data id and exception cause.
34      *
35      * @param failedId instance identifier of the data object that could not be read
36      * @param cause              the cause of read failure
37      */
38     public ReadFailedException(@Nonnull final InstanceIdentifier<?> failedId, final Throwable cause) {
39         this("Failed to read: ", failedId, cause);
40     }
41
42     protected ReadFailedException(@Nonnull final String msgPrefix,
43                                   @Nonnull final InstanceIdentifier<?> failedId,
44                                   @Nonnull final Throwable cause) {
45         super(msgPrefix + failedId, cause);
46         this.failedId = checkNotNull(failedId, "failedId should not be null");
47     }
48
49     /**
50      * Constructs an ReadFailedException given data id.
51      *
52      * @param failedId instance identifier of the data object that could not be read
53      */
54     public ReadFailedException(@Nonnull final InstanceIdentifier<?> failedId) {
55         this(failedId, null);
56     }
57
58     /**
59      * Returns id of the data object that could not be read.
60      *
61      * @return data object instance identifier
62      */
63     @Nonnull
64     public InstanceIdentifier<?> getFailedId() {
65         return failedId;
66     }
67 }