X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=yang%2Fyang-model-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fmodel%2Frepo%2Fapi%2FSchemaResolutionException.java;h=bb9618de9ea26300b56cdfb093b76ce0e30ec66c;hb=c24d6e2f39acbb11e22b5676bb7481ed52bec461;hp=e0be4adb7936c6afab7cd2be00e69440b6f4af0d;hpb=d9fdeeabb54138867c33e674215e1a04a4c21292;p=yangtools.git diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SchemaResolutionException.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SchemaResolutionException.java index e0be4adb79..bb9618de9e 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SchemaResolutionException.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SchemaResolutionException.java @@ -3,22 +3,19 @@ * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/eplv10.html + * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.yangtools.yang.model.repo.api; import com.google.common.annotations.Beta; -import com.google.common.base.Objects; -import com.google.common.base.Objects.ToStringHelper; +import com.google.common.base.MoreObjects; +import com.google.common.base.MoreObjects.ToStringHelper; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Multimap; - import java.util.Collection; import java.util.Collections; - import javax.annotation.Nonnull; - import org.opendaylight.yangtools.yang.model.api.ModuleImport; /** @@ -26,31 +23,55 @@ import org.opendaylight.yangtools.yang.model.api.ModuleImport; */ @Beta public class SchemaResolutionException extends SchemaSourceException { + private static final long serialVersionUID = 1L; + private final SourceIdentifier failedSource; private final Multimap unsatisfiedImports; private final Collection resolvedSources; - public SchemaResolutionException(final @Nonnull String message) { - this(message, (Throwable)null); + public SchemaResolutionException(@Nonnull final String message) { + this(message, null); } - public SchemaResolutionException(final @Nonnull String message, final Throwable cause) { - this(message, cause, Collections.emptySet(), ImmutableMultimap.of()); + public SchemaResolutionException(@Nonnull final String message, final Throwable cause) { + this(message, null, cause, Collections.emptySet(), ImmutableMultimap.of()); } - public SchemaResolutionException(final @Nonnull String message, final Collection resolvedSources, + public SchemaResolutionException(@Nonnull final String message, final SourceIdentifier failedSource, + final Throwable cause) { + this(message, failedSource, cause, Collections.emptySet(), ImmutableMultimap.of()); + } + + public SchemaResolutionException(@Nonnull final String message, final Collection resolvedSources, final @Nonnull Multimap unsatisfiedImports) { - this(message, null, Collections.emptySet(), unsatisfiedImports); + this(message, null, null, resolvedSources, unsatisfiedImports); } - public SchemaResolutionException(final @Nonnull String message, final Throwable cause, - @Nonnull final Collection resolvedSources, + public SchemaResolutionException(@Nonnull final String message, final SourceIdentifier failedSource, + final Throwable cause, @Nonnull final Collection resolvedSources, @Nonnull final Multimap unsatisfiedImports) { - super(message, cause); + super(formatMessage(message, failedSource, resolvedSources, unsatisfiedImports), cause); + this.failedSource = failedSource; this.unsatisfiedImports = ImmutableMultimap.copyOf(unsatisfiedImports); this.resolvedSources = ImmutableList.copyOf(resolvedSources); } + private static String formatMessage(final String message, final SourceIdentifier failedSource, + final Collection resolvedSources, + final Multimap unsatisfiedImports) { + return String.format("%s, failed source: %s, resolved sources: %s, unsatisfied imports: %s", message, + failedSource, resolvedSources, unsatisfiedImports); + } + + /** + * Return YANG schema source identifier consisting of name and revision of the module which caused this exception + * + * @return YANG schema source identifier + */ + public final SourceIdentifier getFailedSource() { + return this.failedSource; + } + /** * Return the list of sources which failed to resolve along with reasons * why they were not resolved. @@ -69,7 +90,7 @@ public class SchemaResolutionException extends SchemaSourceException { @Override public final String toString() { - return addToStringAttributes(Objects.toStringHelper(this).add("unsatisfiedImports", unsatisfiedImports)).toString(); + return addToStringAttributes(MoreObjects.toStringHelper(this).add("unsatisfiedImports", unsatisfiedImports)).toString(); } protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {