BUG-1070: split off YangSourceContext 18/7418/1
authorRobert Varga <rovarga@cisco.com>
Sun, 25 May 2014 17:47:55 +0000 (19:47 +0200)
committerRobert Varga <rovarga@cisco.com>
Tue, 27 May 2014 09:56:02 +0000 (11:56 +0200)
This patch just splits up the various static classes out of
YangSourceContext, making the structure more navigable.

Change-Id: I26c973ebe6d931d870e22d5965ba7baab0cc24e9
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/YangSourceContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/YangSourceContextResolver.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/YangSourceFromCapabilitiesResolver.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/YangSourceFromDependencyInfoResolver.java [new file with mode: 0644]

index eccd60dd1a99c3a1d49747129c9fed793f86b0da..fe0e81e43e22debf9286b50402c4d6dc24ee0674 100644 (file)
@@ -9,11 +9,9 @@ package org.opendaylight.yangtools.yang.parser.impl.util;
 
 import java.io.InputStream;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 import java.util.Set;
 
 import org.opendaylight.yangtools.yang.common.QName;
@@ -22,16 +20,12 @@ import org.opendaylight.yangtools.yang.model.api.ModuleImport;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.util.repo.AdvancedSchemaSourceProvider;
 import org.opendaylight.yangtools.yang.model.util.repo.SchemaSourceProvider;
-import org.opendaylight.yangtools.yang.model.util.repo.SchemaSourceProviders;
 import org.opendaylight.yangtools.yang.model.util.repo.SourceIdentifier;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableMultimap;
 import com.google.common.collect.ImmutableSet;
 
@@ -43,10 +37,10 @@ public class YangSourceContext implements AdvancedSchemaSourceProvider<InputStre
     private final ImmutableMultimap<SourceIdentifier, ModuleImport> missingDependencies;
     private AdvancedSchemaSourceProvider<InputStream> sourceProvider;
 
-    private YangSourceContext(ImmutableSet<SourceIdentifier> validSourcesSet,
-            ImmutableSet<SourceIdentifier> missingSourcesSet,
-            ImmutableMultimap<SourceIdentifier, ModuleImport> missingDependenciesMap,
-            AdvancedSchemaSourceProvider<InputStream> sourceProvicer) {
+    YangSourceContext(final ImmutableSet<SourceIdentifier> validSourcesSet,
+            final ImmutableSet<SourceIdentifier> missingSourcesSet,
+            final ImmutableMultimap<SourceIdentifier, ModuleImport> missingDependenciesMap,
+            final AdvancedSchemaSourceProvider<InputStream> sourceProvicer) {
         validSources = validSourcesSet;
         missingSources = missingSourcesSet;
         missingDependencies = missingDependenciesMap;
@@ -66,12 +60,12 @@ public class YangSourceContext implements AdvancedSchemaSourceProvider<InputStre
     }
 
     @Override
-    public Optional<InputStream> getSchemaSource(String moduleName, Optional<String> revision) {
+    public Optional<InputStream> getSchemaSource(final String moduleName, final Optional<String> revision) {
         return getSchemaSource(SourceIdentifier.create(moduleName, revision));
     }
 
     @Override
-    public Optional<InputStream> getSchemaSource(SourceIdentifier sourceIdentifier) {
+    public Optional<InputStream> getSchemaSource(final SourceIdentifier sourceIdentifier) {
         if (validSources.contains(sourceIdentifier)) {
             return getDelegateChecked().getSchemaSource(sourceIdentifier);
         }
@@ -90,30 +84,30 @@ public class YangSourceContext implements AdvancedSchemaSourceProvider<InputStre
         }
     }
 
-    public static final YangSourceContext createFrom(Iterable<QName> capabilities,
-            SchemaSourceProvider<InputStream> schemaSourceProvider) {
+    public static final YangSourceContext createFrom(final Iterable<QName> capabilities,
+            final SchemaSourceProvider<InputStream> schemaSourceProvider) {
         YangSourceContextResolver resolver = new YangSourceFromCapabilitiesResolver(capabilities, schemaSourceProvider);
         return resolver.resolveContext();
     }
 
-    public static final YangSourceContext createFrom(Map<SourceIdentifier, YangModelDependencyInfo> moduleDependencies) {
+    public static final YangSourceContext createFrom(final Map<SourceIdentifier, YangModelDependencyInfo> moduleDependencies) {
         YangSourceContextResolver resolver = new YangSourceFromDependencyInfoResolver(moduleDependencies);
         return resolver.resolveContext();
     }
 
-    public static final SchemaContext toSchemaContext(YangSourceContext context) {
+    public static final SchemaContext toSchemaContext(final YangSourceContext context) {
         List<InputStream> inputStreams = getValidInputStreams(context);
         YangParserImpl parser = new YangParserImpl();
         Set<Module> models = parser.parseYangModelsFromStreams(inputStreams);
         return parser.resolveSchemaContext(models);
     }
 
-    public static List<InputStream> getValidInputStreams(YangSourceContext context) {
+    public static List<InputStream> getValidInputStreams(final YangSourceContext context) {
         return getValidInputStreams(context, context.sourceProvider);
     }
 
-    public static List<InputStream> getValidInputStreams(YangSourceContext context,
-            AdvancedSchemaSourceProvider<InputStream> provider) {
+    public static List<InputStream> getValidInputStreams(final YangSourceContext context,
+            final AdvancedSchemaSourceProvider<InputStream> provider) {
         final HashSet<SourceIdentifier> sourcesToLoad = new HashSet<>();
         sourcesToLoad.addAll(context.getValidSources());
         for (SourceIdentifier source : context.getValidSources()) {
@@ -131,193 +125,4 @@ public class YangSourceContext implements AdvancedSchemaSourceProvider<InputStre
         }
         return ret.build();
     }
-
-    public static abstract class YangSourceContextResolver {
-
-        private static final Logger LOG = LoggerFactory.getLogger(YangSourceContextResolver.class);
-
-        private final AdvancedSchemaSourceProvider<InputStream> sourceProvider;
-
-        public AdvancedSchemaSourceProvider<InputStream> getSourceProvider() {
-            return sourceProvider;
-        }
-
-        private final HashMap<SourceIdentifier, ResolutionState> alreadyProcessed = new HashMap<>();
-
-        private final ImmutableSet.Builder<SourceIdentifier> missingSources = ImmutableSet.builder();
-
-        private ImmutableMultimap.Builder<SourceIdentifier, ModuleImport> missingDependencies = ImmutableMultimap
-                .builder();
-
-        private final ImmutableSet.Builder<SourceIdentifier> validSources = ImmutableSet.builder();
-
-        public YangSourceContextResolver() {
-            sourceProvider = null;
-        }
-
-        public YangSourceContextResolver(AdvancedSchemaSourceProvider<InputStream> sourceProvicer) {
-            super();
-            this.sourceProvider = sourceProvicer;
-        }
-
-        public abstract YangSourceContext resolveContext();
-
-        public ResolutionState resolveSource(String name, Optional<String> formattedRevision) {
-            return resolveSource(new SourceIdentifier(name, formattedRevision));
-        }
-
-        public ResolutionState resolveSource(SourceIdentifier identifier) {
-
-            if (alreadyProcessed.containsKey(identifier)) {
-                return alreadyProcessed.get(identifier);
-            }
-            LOG.trace("Resolving source: {}", identifier);
-            ResolutionState potentialState = ResolutionState.EVERYTHING_OK;
-            try {
-                Optional<YangModelDependencyInfo> potentialInfo = getDependencyInfo(identifier);
-                if (potentialInfo.isPresent()) {
-                    YangModelDependencyInfo info = potentialInfo.get();
-                    checkValidSource(identifier, info);
-                    for (ModuleImport dependency : info.getDependencies()) {
-                        LOG.trace("Source: {} Resolving dependency: {}", identifier, dependency);
-                        ResolutionState dependencyState = resolveDependency(dependency);
-                        if (dependencyState != ResolutionState.EVERYTHING_OK) {
-                            potentialState = ResolutionState.MISSING_DEPENDENCY;
-                            missingDependencies.put(identifier, dependency);
-                        }
-                    }
-                } else {
-                    missingSources.add(identifier);
-                    return ResolutionState.MISSING_SOURCE;
-                }
-            } catch (Exception e) {
-                potentialState = ResolutionState.OTHER_ERROR;
-            }
-            updateResolutionState(identifier, potentialState);
-            return potentialState;
-        }
-
-        public abstract Optional<YangModelDependencyInfo> getDependencyInfo(SourceIdentifier identifier);
-
-        private boolean checkValidSource(SourceIdentifier identifier, YangModelDependencyInfo info) {
-            if (!identifier.getName().equals(info.getName())) {
-                LOG.warn("Incorrect model returned. Identifier name was: {}, source contained: {}",
-                        identifier.getName(), info.getName());
-                throw new IllegalStateException("Incorrect source was returned");
-            }
-            return true;
-        }
-
-        private void updateResolutionState(SourceIdentifier identifier, ResolutionState potentialState) {
-            alreadyProcessed.put(identifier, potentialState);
-            switch (potentialState) {
-            case MISSING_SOURCE:
-                missingSources.add(identifier);
-                break;
-            case EVERYTHING_OK:
-                validSources.add(identifier);
-                break;
-            default:
-                break;
-            }
-        }
-
-        private ResolutionState resolveDependency(ModuleImport dependency) {
-            String name = dependency.getModuleName();
-            Optional<String> formattedRevision = Optional
-                    .fromNullable(QName.formattedRevision(dependency.getRevision()));
-            return resolveSource(new SourceIdentifier(name, formattedRevision));
-        }
-
-        protected YangSourceContext createSourceContext() {
-
-            ImmutableSet<SourceIdentifier> missingSourcesSet = missingSources.build();
-            ImmutableMultimap<SourceIdentifier, ModuleImport> missingDependenciesMap = missingDependencies.build();
-            ImmutableSet<SourceIdentifier> validSourcesSet = validSources.build();
-
-            return new YangSourceContext(validSourcesSet, missingSourcesSet, missingDependenciesMap, sourceProvider);
-
-        }
-    }
-
-    private enum ResolutionState {
-        MISSING_SOURCE, MISSING_DEPENDENCY, OTHER_ERROR, EVERYTHING_OK
-    }
-
-    public static final class YangSourceFromCapabilitiesResolver extends YangSourceContextResolver {
-
-        private Iterable<QName> capabilities;
-
-        public YangSourceFromCapabilitiesResolver(Iterable<QName> capabilities,
-                SchemaSourceProvider<InputStream> schemaSourceProvider) {
-            super(SchemaSourceProviders.toAdvancedSchemaSourceProvider(schemaSourceProvider));
-            this.capabilities = capabilities;
-        }
-
-        @Override
-        public YangSourceContext resolveContext() {
-            for (QName capability : capabilities) {
-                resolveCapability(capability);
-            }
-            return createSourceContext();
-        }
-
-        private void resolveCapability(QName capability) {
-            super.resolveSource(capability.getLocalName(), Optional.fromNullable(capability.getFormattedRevision()));
-        }
-
-        @Override
-        public Optional<YangModelDependencyInfo> getDependencyInfo(SourceIdentifier identifier) {
-            Optional<InputStream> source = getSchemaSource(identifier);
-            if (source.isPresent()) {
-                return Optional.of(YangModelDependencyInfo.fromInputStream(source.get()));
-            }
-            return Optional.absent();
-        }
-
-        private Optional<InputStream> getSchemaSource(SourceIdentifier identifier) {
-            return getSourceProvider().getSchemaSource(identifier.getName(),
-                    Optional.fromNullable(identifier.getRevision()));
-        }
-
-    }
-
-    public static final class YangSourceFromDependencyInfoResolver extends YangSourceContextResolver {
-
-        private final Map<SourceIdentifier, YangModelDependencyInfo> dependencyInfo;
-
-        public YangSourceFromDependencyInfoResolver(Map<SourceIdentifier, YangModelDependencyInfo> moduleDependencies) {
-            dependencyInfo = ImmutableMap.copyOf(moduleDependencies);
-        }
-
-        @Override
-        public Optional<YangModelDependencyInfo> getDependencyInfo(SourceIdentifier identifier) {
-            if (identifier.getRevision() != null) {
-                return Optional.fromNullable(dependencyInfo.get(identifier));
-            }
-            YangModelDependencyInfo potential = dependencyInfo.get(identifier);
-            if (potential == null) {
-                for (Entry<SourceIdentifier, YangModelDependencyInfo> newPotential : dependencyInfo.entrySet()) {
-                    String newPotentialName = newPotential.getKey().getName();
-
-                    if (newPotentialName.equals(identifier.getName())) {
-                        String newPotentialRevision = newPotential.getKey().getRevision();
-                        if (potential == null || 1 == newPotentialRevision.compareTo(potential.getFormattedRevision())) {
-                            potential = newPotential.getValue();
-                        }
-                    }
-                }
-            }
-            return Optional.fromNullable(potential);
-        }
-
-        @Override
-        public YangSourceContext resolveContext() {
-            for (SourceIdentifier source : dependencyInfo.keySet()) {
-                resolveSource(source);
-            }
-            return createSourceContext();
-        }
-    }
-
 }
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/YangSourceContextResolver.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/YangSourceContextResolver.java
new file mode 100644 (file)
index 0000000..50f4a3e
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * 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
+ */
+package org.opendaylight.yangtools.yang.parser.impl.util;
+
+import java.io.InputStream;
+import java.util.HashMap;
+
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.ModuleImport;
+import org.opendaylight.yangtools.yang.model.util.repo.AdvancedSchemaSourceProvider;
+import org.opendaylight.yangtools.yang.model.util.repo.SourceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableMultimap;
+import com.google.common.collect.ImmutableSet;
+
+public abstract class YangSourceContextResolver {
+
+    enum ResolutionState {
+        MISSING_SOURCE,
+        MISSING_DEPENDENCY,
+        OTHER_ERROR,
+        EVERYTHING_OK,
+    }
+
+    private static final Logger LOG = LoggerFactory.getLogger(YangSourceContextResolver.class);
+    private final HashMap<SourceIdentifier, YangSourceContextResolver.ResolutionState> alreadyProcessed = new HashMap<>();
+    private final ImmutableSet.Builder<SourceIdentifier> missingSources = ImmutableSet.builder();
+    private final ImmutableMultimap.Builder<SourceIdentifier, ModuleImport> missingDependencies =
+            ImmutableMultimap.builder();
+    private final ImmutableSet.Builder<SourceIdentifier> validSources = ImmutableSet.builder();
+    private final AdvancedSchemaSourceProvider<InputStream> sourceProvider;
+
+    public YangSourceContextResolver() {
+        sourceProvider = null;
+    }
+
+    public YangSourceContextResolver(final AdvancedSchemaSourceProvider<InputStream> sourceProvicer) {
+        super();
+        this.sourceProvider = sourceProvicer;
+    }
+
+    public abstract YangSourceContext resolveContext();
+    public abstract Optional<YangModelDependencyInfo> getDependencyInfo(SourceIdentifier identifier);
+
+    public AdvancedSchemaSourceProvider<InputStream> getSourceProvider() {
+        return sourceProvider;
+    }
+
+    public YangSourceContextResolver.ResolutionState resolveSource(final String name, final Optional<String> formattedRevision) {
+        return resolveSource(new SourceIdentifier(name, formattedRevision));
+    }
+
+    public YangSourceContextResolver.ResolutionState resolveSource(final SourceIdentifier identifier) {
+
+        if (alreadyProcessed.containsKey(identifier)) {
+            return alreadyProcessed.get(identifier);
+        }
+        LOG.trace("Resolving source: {}", identifier);
+        YangSourceContextResolver.ResolutionState potentialState = YangSourceContextResolver.ResolutionState.EVERYTHING_OK;
+        try {
+            Optional<YangModelDependencyInfo> potentialInfo = getDependencyInfo(identifier);
+            if (potentialInfo.isPresent()) {
+                YangModelDependencyInfo info = potentialInfo.get();
+                checkValidSource(identifier, info);
+                for (ModuleImport dependency : info.getDependencies()) {
+                    LOG.trace("Source: {} Resolving dependency: {}", identifier, dependency);
+                    YangSourceContextResolver.ResolutionState dependencyState = resolveDependency(dependency);
+                    if (dependencyState != YangSourceContextResolver.ResolutionState.EVERYTHING_OK) {
+                        potentialState = YangSourceContextResolver.ResolutionState.MISSING_DEPENDENCY;
+                        missingDependencies.put(identifier, dependency);
+                    }
+                }
+            } else {
+                missingSources.add(identifier);
+                return YangSourceContextResolver.ResolutionState.MISSING_SOURCE;
+            }
+        } catch (Exception e) {
+            potentialState = YangSourceContextResolver.ResolutionState.OTHER_ERROR;
+        }
+        updateResolutionState(identifier, potentialState);
+        return potentialState;
+    }
+
+    private boolean checkValidSource(final SourceIdentifier identifier, final YangModelDependencyInfo info) {
+        if (!identifier.getName().equals(info.getName())) {
+            LOG.warn("Incorrect model returned. Identifier name was: {}, source contained: {}",
+                    identifier.getName(), info.getName());
+            throw new IllegalStateException("Incorrect source was returned");
+        }
+        return true;
+    }
+
+    private void updateResolutionState(final SourceIdentifier identifier, final YangSourceContextResolver.ResolutionState potentialState) {
+        alreadyProcessed.put(identifier, potentialState);
+        switch (potentialState) {
+        case MISSING_SOURCE:
+            missingSources.add(identifier);
+            break;
+        case EVERYTHING_OK:
+            validSources.add(identifier);
+            break;
+        default:
+            break;
+        }
+    }
+
+    private YangSourceContextResolver.ResolutionState resolveDependency(final ModuleImport dependency) {
+        String name = dependency.getModuleName();
+        Optional<String> formattedRevision = Optional
+                .fromNullable(QName.formattedRevision(dependency.getRevision()));
+        return resolveSource(new SourceIdentifier(name, formattedRevision));
+    }
+
+    protected YangSourceContext createSourceContext() {
+        ImmutableSet<SourceIdentifier> missingSourcesSet = missingSources.build();
+        ImmutableMultimap<SourceIdentifier, ModuleImport> missingDependenciesMap = missingDependencies.build();
+        ImmutableSet<SourceIdentifier> validSourcesSet = validSources.build();
+        return new YangSourceContext(validSourcesSet, missingSourcesSet, missingDependenciesMap, sourceProvider);
+    }
+}
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/YangSourceFromCapabilitiesResolver.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/YangSourceFromCapabilitiesResolver.java
new file mode 100644 (file)
index 0000000..92d3fbd
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * 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
+ */
+package org.opendaylight.yangtools.yang.parser.impl.util;
+
+import java.io.InputStream;
+
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.util.repo.SchemaSourceProvider;
+import org.opendaylight.yangtools.yang.model.util.repo.SchemaSourceProviders;
+import org.opendaylight.yangtools.yang.model.util.repo.SourceIdentifier;
+
+import com.google.common.base.Optional;
+
+public final class YangSourceFromCapabilitiesResolver extends YangSourceContextResolver {
+
+    private final Iterable<QName> capabilities;
+
+    public YangSourceFromCapabilitiesResolver(final Iterable<QName> capabilities,
+            final SchemaSourceProvider<InputStream> schemaSourceProvider) {
+        super(SchemaSourceProviders.toAdvancedSchemaSourceProvider(schemaSourceProvider));
+        this.capabilities = capabilities;
+    }
+
+    @Override
+    public YangSourceContext resolveContext() {
+        for (QName capability : capabilities) {
+            resolveCapability(capability);
+        }
+        return createSourceContext();
+    }
+
+    private void resolveCapability(final QName capability) {
+        super.resolveSource(capability.getLocalName(), Optional.fromNullable(capability.getFormattedRevision()));
+    }
+
+    @Override
+    public Optional<YangModelDependencyInfo> getDependencyInfo(final SourceIdentifier identifier) {
+        Optional<InputStream> source = getSchemaSource(identifier);
+        if (source.isPresent()) {
+            return Optional.of(YangModelDependencyInfo.fromInputStream(source.get()));
+        }
+        return Optional.absent();
+    }
+
+    private Optional<InputStream> getSchemaSource(final SourceIdentifier identifier) {
+        return getSourceProvider().getSchemaSource(identifier.getName(),
+                Optional.fromNullable(identifier.getRevision()));
+    }
+
+}
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/YangSourceFromDependencyInfoResolver.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/YangSourceFromDependencyInfoResolver.java
new file mode 100644 (file)
index 0000000..9893c6c
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * 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
+ */
+package org.opendaylight.yangtools.yang.parser.impl.util;
+
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.opendaylight.yangtools.yang.model.util.repo.SourceIdentifier;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableMap;
+
+public final class YangSourceFromDependencyInfoResolver extends YangSourceContextResolver {
+
+    private final Map<SourceIdentifier, YangModelDependencyInfo> dependencyInfo;
+
+    public YangSourceFromDependencyInfoResolver(final Map<SourceIdentifier, YangModelDependencyInfo> moduleDependencies) {
+        dependencyInfo = ImmutableMap.copyOf(moduleDependencies);
+    }
+
+    @Override
+    public Optional<YangModelDependencyInfo> getDependencyInfo(final SourceIdentifier identifier) {
+        if (identifier.getRevision() != null) {
+            return Optional.fromNullable(dependencyInfo.get(identifier));
+        }
+        YangModelDependencyInfo potential = dependencyInfo.get(identifier);
+        if (potential == null) {
+            for (Entry<SourceIdentifier, YangModelDependencyInfo> newPotential : dependencyInfo.entrySet()) {
+                String newPotentialName = newPotential.getKey().getName();
+
+                if (newPotentialName.equals(identifier.getName())) {
+                    String newPotentialRevision = newPotential.getKey().getRevision();
+                    if (potential == null || 1 == newPotentialRevision.compareTo(potential.getFormattedRevision())) {
+                        potential = newPotential.getValue();
+                    }
+                }
+            }
+        }
+        return Optional.fromNullable(potential);
+    }
+
+    @Override
+    public YangSourceContext resolveContext() {
+        for (SourceIdentifier source : dependencyInfo.keySet()) {
+            resolveSource(source);
+        }
+        return createSourceContext();
+    }
+}