Merge "BUG-432: remove type argument from Registration"
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / repo / api / SchemaResolutionException.java
1 /*
2  * Copyright (c) 2014 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/eplv10.html
7  */
8 package org.opendaylight.yangtools.yang.model.repo.api;
9
10 import com.google.common.base.Objects;
11 import com.google.common.base.Objects.ToStringHelper;
12 import com.google.common.base.Preconditions;
13 import com.google.common.collect.ImmutableMap;
14
15 import java.util.Map;
16
17 import javax.annotation.Nonnull;
18
19 /**
20  * Exception thrown when a Schema Source fails to resolve.
21  */
22 public class SchemaResolutionException extends Exception {
23     private static final long serialVersionUID = 1L;
24     private final Map<SourceIdentifier, Throwable> unresolvedSources;
25
26     public SchemaResolutionException(final @Nonnull String message) {
27         this(message, (Throwable)null);
28     }
29
30     public SchemaResolutionException(final @Nonnull String message, final Throwable cause) {
31         this(message, cause, ImmutableMap.<SourceIdentifier, Exception>of());
32     }
33
34     public SchemaResolutionException(final @Nonnull String message, final @Nonnull Map<SourceIdentifier, ? extends Throwable> unresolvedSources) {
35         super(Preconditions.checkNotNull(message));
36         this.unresolvedSources = ImmutableMap.copyOf(unresolvedSources);
37     }
38
39     public SchemaResolutionException(final @Nonnull String message, final Throwable cause, @Nonnull final Map<SourceIdentifier, ? extends Throwable> unresolvedSources) {
40         super(message, cause);
41         this.unresolvedSources = ImmutableMap.copyOf(unresolvedSources);
42     }
43
44     /**
45      * Return the list of sources which failed to resolve along with reasons
46      * why they were not resolved.
47      *
48      * @return Source/reason map.
49      */
50     public final Map<SourceIdentifier, Throwable> getUnresolvedSources() {
51         return unresolvedSources;
52     }
53
54     @Override
55     public final String toString() {
56         return addToStringAttributes(Objects.toStringHelper(this).add("unresolvedSources", unresolvedSources)).toString();
57     }
58
59     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
60         return toStringHelper;
61     }
62 }