BUG-997 Add SourceIdentifier to MissingSchemaSourceException 11/9811/1
authorMaros Marsalek <mmarsale@cisco.com>
Fri, 8 Aug 2014 08:52:17 +0000 (10:52 +0200)
committerMaros Marsalek <mmarsale@cisco.com>
Fri, 8 Aug 2014 12:56:35 +0000 (14:56 +0200)
Change-Id: Ia4a595492935a66371faa844c5286a312a7897e2
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/MissingSchemaSourceException.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/AbstractSchemaRepository.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/FilesystemSchemaSourceCache.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/InMemorySchemaSourceCache.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/URLSchemaContextResolver.java

index 17c9c906172fbb40f3d164e0fb9801405cbda403..89138d6a57e7fdbf3772fa3a2d5c1524c7f2d539 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.yang.model.repo.api;
 
 import com.google.common.annotations.Beta;
+import com.google.common.base.Preconditions;
 
 /**
  * Exception thrown when a the specified schema source is not available.
@@ -16,11 +17,18 @@ import com.google.common.annotations.Beta;
 public class MissingSchemaSourceException extends SchemaSourceException {
     private static final long serialVersionUID = 1L;
 
-    public MissingSchemaSourceException(final String message) {
-        super(message);
+    private final SourceIdentifier id;
+
+    public MissingSchemaSourceException(final String message, final SourceIdentifier id) {
+        this(message, id, null);
+    }
+
+    public MissingSchemaSourceException(final String s, final SourceIdentifier id, final Throwable t) {
+        super(s, t);
+        this.id = Preconditions.checkNotNull(id);
     }
 
-    public MissingSchemaSourceException(final String message, final Throwable cause) {
-        super(message, cause);
+    public SourceIdentifier getSourceId() {
+        return id;
     }
 }
index 4b530e7dfbe3d9bc7ce40e9f713a142ea10929eb..e8bcc0651039413b7c4fa95cb00917e8ff2a95f9 100644 (file)
@@ -80,7 +80,7 @@ public abstract class AbstractSchemaRepository implements SchemaRepository, Sche
                     return fetchSource(id, it);
                 }
 
-                throw new MissingSchemaSourceException("All available providers exhausted", t);
+                throw new MissingSchemaSourceException("All available providers exhausted", id, t);
             }
         }), FETCH_MAPPER);
     }
@@ -89,7 +89,7 @@ public abstract class AbstractSchemaRepository implements SchemaRepository, Sche
     public <T extends SchemaSourceRepresentation> CheckedFuture<T, SchemaSourceException> getSchemaSource(final SourceIdentifier id, final Class<T> representation) {
         final ListMultimap<Class<? extends SchemaSourceRepresentation>, AbstractSchemaSourceRegistration<?>> srcs = sources.get(id);
         if (srcs == null) {
-            return Futures.<T, SchemaSourceException>immediateFailedCheckedFuture(new MissingSchemaSourceException("No providers registered for source" + id));
+            return Futures.<T, SchemaSourceException>immediateFailedCheckedFuture(new MissingSchemaSourceException("No providers registered for source" + id, id));
         }
 
         // TODO, remove and make sources keep sorted multimap (e.g. ArrayListMultimap with SortedLists)
@@ -99,7 +99,7 @@ public abstract class AbstractSchemaRepository implements SchemaRepository, Sche
         final Iterator<AbstractSchemaSourceRegistration<?>> regs = sortedSchemaSourceRegistrations.iterator();
         if (!regs.hasNext()) {
             return Futures.<T, SchemaSourceException>immediateFailedCheckedFuture(
-                    new MissingSchemaSourceException("No providers for source " + id + " representation " + representation + " available"));
+                    new MissingSchemaSourceException("No providers for source " + id + " representation " + representation + " available", id));
         }
 
         CheckedFuture<T, SchemaSourceException> fetchSourceFuture = fetchSource(id, regs);
index 8fc07a1d71fe9120a4dcb3bd29d03fce790ec8bc..675a6953418fbbd8a6e969bde48c35bd7d41f03a 100644 (file)
@@ -117,7 +117,7 @@ public final class FilesystemSchemaSourceCache<T extends SchemaSourceRepresentat
         }
 
         LOG.debug("Source {} not found in cache as {}", sourceIdentifier, file);
-        return Futures.<T, SchemaSourceException>immediateFailedCheckedFuture(new MissingSchemaSourceException("Source not found"));
+        return Futures.<T, SchemaSourceException>immediateFailedCheckedFuture(new MissingSchemaSourceException("Source not found", sourceIdentifier));
     }
 
     @Override
index ac820d28d70dc788d38e06d8d9b0be7c87541793..60dfb90a883a574c95a02e03afa472eb5d6e49d9 100644 (file)
@@ -54,7 +54,7 @@ public class InMemorySchemaSourceCache<T extends SchemaSourceRepresentation> ext
             return Futures.immediateCheckedFuture(present.source);
         }
 
-        return Futures.<T, SchemaSourceException>immediateFailedCheckedFuture(new MissingSchemaSourceException("Source not found"));
+        return Futures.<T, SchemaSourceException>immediateFailedCheckedFuture(new MissingSchemaSourceException("Source not found", sourceIdentifier));
     }
 
     @Override
index 47de6b1a540b5bd1b0a14014ce9a5364447977b3..bbcd95e220eb34737f50374cadd359c7af17e749 100644 (file)
@@ -169,7 +169,7 @@ public class URLSchemaContextResolver implements SchemaSourceProvider<YangTextSc
         final YangTextSchemaSource ret = sources.getIfPresent(sourceIdentifier);
         if (ret == null) {
             return Futures.<YangTextSchemaSource, SchemaSourceException>immediateFailedCheckedFuture(
-                    new MissingSchemaSourceException("URL for " + sourceIdentifier + " not registered"));
+                    new MissingSchemaSourceException("URL for " + sourceIdentifier + " not registered", sourceIdentifier));
         }
 
         return Futures.immediateCheckedFuture(ret);