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 java.util.Collections;
18 import javax.annotation.Nonnull;
19 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
22 * Exception thrown when a Schema Source fails to resolve.
25 public class SchemaResolutionException extends SchemaSourceException {
27 private static final long serialVersionUID = 1L;
28 private final SourceIdentifier failedSource;
29 private final Multimap<SourceIdentifier, ModuleImport> unsatisfiedImports;
30 private final Collection<SourceIdentifier> resolvedSources;
32 public SchemaResolutionException(@Nonnull final String message) {
36 public SchemaResolutionException(@Nonnull final String message, final Throwable cause) {
37 this(message, null, cause, Collections.emptySet(), ImmutableMultimap.of());
40 public SchemaResolutionException(@Nonnull final String message, final SourceIdentifier failedSource,
41 final Throwable cause) {
42 this(message, failedSource, cause, Collections.emptySet(), ImmutableMultimap.of());
45 public SchemaResolutionException(@Nonnull final String message, final Collection<SourceIdentifier> resolvedSources,
46 final @Nonnull Multimap<SourceIdentifier, ModuleImport> unsatisfiedImports) {
47 this(message, null, null, resolvedSources, unsatisfiedImports);
50 public SchemaResolutionException(@Nonnull final String message, final SourceIdentifier failedSource,
51 final Throwable cause, @Nonnull final Collection<SourceIdentifier> resolvedSources,
52 @Nonnull final 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
77 * why they were not resolved.
79 * @return Source/reason map.
81 public final Multimap<SourceIdentifier, ModuleImport> getUnsatisfiedImports() {
82 return unsatisfiedImports;
86 // FIXME: should be leak actual mapping?
87 public final Collection<SourceIdentifier> getResolvedSources() {
88 return resolvedSources;
92 public final String toString() {
93 return addToStringAttributes(MoreObjects.toStringHelper(this).add("unsatisfiedImports", unsatisfiedImports))
97 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
98 return toStringHelper;