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/eplv10.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 {
26 private static final long serialVersionUID = 1L;
27 private final Multimap<SourceIdentifier, ModuleImport> unsatisfiedImports;
28 private final Collection<SourceIdentifier> resolvedSources;
30 public SchemaResolutionException(@Nonnull final String message) {
31 this(message, (Throwable)null);
34 public SchemaResolutionException(@Nonnull final String message, final Throwable cause) {
35 this(message, cause, Collections.<SourceIdentifier>emptySet(), ImmutableMultimap.<SourceIdentifier, ModuleImport>of());
38 public SchemaResolutionException(@Nonnull final String message, final Collection<SourceIdentifier> resolvedSources,
39 final @Nonnull Multimap<SourceIdentifier, ModuleImport> unsatisfiedImports) {
40 this(message, null, resolvedSources, unsatisfiedImports);
43 public SchemaResolutionException(@Nonnull final String message, final Throwable cause,
44 @Nonnull final Collection<SourceIdentifier> resolvedSources,
45 @Nonnull final Multimap<SourceIdentifier, ModuleImport> unsatisfiedImports) {
46 super(formatMessage(message, resolvedSources, unsatisfiedImports), cause);
47 this.unsatisfiedImports = ImmutableMultimap.copyOf(unsatisfiedImports);
48 this.resolvedSources = ImmutableList.copyOf(resolvedSources);
51 private static final String MESSAGE_BLUEPRINT = "%s, resolved sources: %s, unsatisfied imports: %s";
52 private static String formatMessage(final String message, final Collection<SourceIdentifier> resolvedSources, final Multimap<SourceIdentifier, ModuleImport> unsatisfiedImports) {
53 return String.format(MESSAGE_BLUEPRINT, message, resolvedSources, unsatisfiedImports);
57 * Return the list of sources which failed to resolve along with reasons
58 * why they were not resolved.
60 * @return Source/reason map.
62 public final Multimap<SourceIdentifier, ModuleImport> getUnsatisfiedImports() {
63 return unsatisfiedImports;
67 // FIXME: should be leak actual mapping?
68 public final Collection<SourceIdentifier> getResolvedSources() {
69 return resolvedSources;
73 public final String toString() {
74 return addToStringAttributes(MoreObjects.toStringHelper(this).add("unsatisfiedImports", unsatisfiedImports)).toString();
77 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
78 return toStringHelper;