2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.model.repo.api;
10 import com.google.common.annotations.Beta;
11 import com.google.common.base.MoreObjects;
12 import com.google.common.base.MoreObjects.ToStringHelper;
13 import com.google.common.collect.ImmutableList;
14 import com.google.common.collect.ImmutableMultimap;
15 import com.google.common.collect.Multimap;
16 import java.util.Collection;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
21 * Exception thrown when a Schema Source fails to resolve.
24 public class SchemaResolutionException extends SchemaSourceException {
25 private static final long serialVersionUID = 1L;
27 private final SourceIdentifier failedSource;
28 private final @NonNull ImmutableMultimap<SourceIdentifier, ModuleImport> unsatisfiedImports;
29 private final @NonNull ImmutableList<SourceIdentifier> resolvedSources;
31 public SchemaResolutionException(final @NonNull String message) {
35 public SchemaResolutionException(final @NonNull String message, final Throwable cause) {
36 this(message, null, cause, ImmutableList.of(), ImmutableMultimap.of());
39 public SchemaResolutionException(final @NonNull String message, final SourceIdentifier failedSource,
40 final Throwable cause) {
41 this(message, failedSource, cause, ImmutableList.of(), ImmutableMultimap.of());
44 public SchemaResolutionException(final @NonNull String message,
45 final @NonNull Collection<SourceIdentifier> resolvedSources,
46 final @NonNull Multimap<SourceIdentifier, ModuleImport> unsatisfiedImports) {
47 this(message, null, null, resolvedSources, unsatisfiedImports);
50 public SchemaResolutionException(final @NonNull String message, final SourceIdentifier failedSource,
51 final Throwable cause, final @NonNull Collection<SourceIdentifier> resolvedSources,
52 final @NonNull Multimap<SourceIdentifier, ModuleImport> unsatisfiedImports) {
53 super(formatMessage(message, failedSource, resolvedSources, unsatisfiedImports), cause);
54 this.failedSource = failedSource;
55 this.unsatisfiedImports = ImmutableMultimap.copyOf(unsatisfiedImports);
56 this.resolvedSources = ImmutableList.copyOf(resolvedSources);
59 private static String formatMessage(final String message, final SourceIdentifier failedSource,
60 final Collection<SourceIdentifier> resolvedSources,
61 final Multimap<SourceIdentifier, ModuleImport> unsatisfiedImports) {
62 return String.format("%s, failed source: %s, resolved sources: %s, unsatisfied imports: %s", message,
63 failedSource, resolvedSources, unsatisfiedImports);
67 * Return YANG schema source identifier consisting of name and revision of the module which caused this exception.
69 * @return YANG schema source identifier
71 public final SourceIdentifier getFailedSource() {
72 return this.failedSource;
76 * Return the list of sources which failed to resolve along with reasons why they were not resolved.
78 * @return Source/reason map.
80 public final @NonNull Multimap<SourceIdentifier, ModuleImport> getUnsatisfiedImports() {
81 return unsatisfiedImports;
84 // FIXME: should be leak actual mapping?
85 public final @NonNull Collection<SourceIdentifier> getResolvedSources() {
86 return resolvedSources;
90 public final String toString() {
91 return addToStringAttributes(MoreObjects.toStringHelper(this).add("unsatisfiedImports", unsatisfiedImports))
95 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
96 return toStringHelper;