BUG-997 Fix unused argument in SchemaResolutionException
[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.annotations.Beta;
11 import com.google.common.base.Objects;
12 import com.google.common.base.Objects.ToStringHelper;
13 import com.google.common.collect.ImmutableList;
14 import com.google.common.collect.ImmutableMultimap;
15 import com.google.common.collect.Multimap;
16
17 import java.util.Collection;
18 import java.util.Collections;
19
20 import javax.annotation.Nonnull;
21
22 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
23
24 /**
25  * Exception thrown when a Schema Source fails to resolve.
26  */
27 @Beta
28 public class SchemaResolutionException extends SchemaSourceException {
29     private static final long serialVersionUID = 1L;
30     private final Multimap<SourceIdentifier, ModuleImport> unsatisfiedImports;
31     private final Collection<SourceIdentifier> resolvedSources;
32
33     public SchemaResolutionException(final @Nonnull String message) {
34         this(message, (Throwable)null);
35     }
36
37     public SchemaResolutionException(final @Nonnull String message, final Throwable cause) {
38         this(message, cause, Collections.<SourceIdentifier>emptySet(), ImmutableMultimap.<SourceIdentifier, ModuleImport>of());
39     }
40
41     public SchemaResolutionException(final @Nonnull String message, final Collection<SourceIdentifier> resolvedSources,
42             final @Nonnull Multimap<SourceIdentifier, ModuleImport> unsatisfiedImports) {
43         this(message, null, resolvedSources, unsatisfiedImports);
44     }
45
46     public SchemaResolutionException(final @Nonnull String message, final Throwable cause,
47             @Nonnull final Collection<SourceIdentifier> resolvedSources,
48             @Nonnull final Multimap<SourceIdentifier, ModuleImport> unsatisfiedImports) {
49         super(formatMessage(message, resolvedSources, unsatisfiedImports), cause);
50         this.unsatisfiedImports = ImmutableMultimap.copyOf(unsatisfiedImports);
51         this.resolvedSources = ImmutableList.copyOf(resolvedSources);
52     }
53
54     private static final String MESSAGE_BLUEPRINT = "%s, resolved sources: %s, unsatisfied imports: %s";
55     private static String formatMessage(final String message, final Collection<SourceIdentifier> resolvedSources, final Multimap<SourceIdentifier, ModuleImport> unsatisfiedImports) {
56         return String.format(MESSAGE_BLUEPRINT, message, resolvedSources, unsatisfiedImports);
57     }
58
59     /**
60      * Return the list of sources which failed to resolve along with reasons
61      * why they were not resolved.
62      *
63      * @return Source/reason map.
64      */
65     public final Multimap<SourceIdentifier, ModuleImport> getUnsatisfiedImports() {
66         return unsatisfiedImports;
67     }
68
69
70     // FIXME: should be leak actual mapping?
71     public final Collection<SourceIdentifier> getResolvedSources() {
72         return resolvedSources;
73     }
74
75     @Override
76     public final String toString() {
77         return addToStringAttributes(Objects.toStringHelper(this).add("unsatisfiedImports", unsatisfiedImports)).toString();
78     }
79
80     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
81         return toStringHelper;
82     }
83 }