Do not subclass YangTextSchemaSource in yang-parser-impl
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / repo / YangTextSchemaContextResolver.java
index 24cb91f87b55348daf113d91b22e293207ea5da4..6cdcaac81c57ef724385921f9845e798714468fa 100644 (file)
@@ -13,7 +13,6 @@ import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediate
 import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFluentFuture;
 
 import com.google.common.annotations.Beta;
-import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.base.Verify;
 import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.ImmutableSet;
@@ -21,7 +20,6 @@ import com.google.common.collect.Multimap;
 import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.io.IOException;
-import java.io.InputStream;
 import java.net.URL;
 import java.util.Collection;
 import java.util.Optional;
@@ -33,7 +31,6 @@ import java.util.concurrent.atomic.AtomicReference;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.parser.api.YangParserFactory;
 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory;
@@ -178,18 +175,7 @@ public final class YangTextSchemaContextResolver implements AutoCloseable, Schem
 
         final String path = url.getPath();
         final String fileName = path.substring(path.lastIndexOf('/') + 1);
-        final SourceIdentifier guessedId = guessSourceIdentifier(fileName);
-        return registerSource(new YangTextSchemaSource(guessedId) {
-            @Override
-            public InputStream openStream() throws IOException {
-                return url.openStream();
-            }
-
-            @Override
-            protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
-                return toStringHelper.add("url", url);
-            }
-        });
+        return registerSource(YangTextSchemaSource.forURL(url, guessSourceIdentifier(fileName)));
     }
 
     private static SourceIdentifier guessSourceIdentifier(final @NonNull String fileName) {
@@ -270,33 +256,8 @@ public final class YangTextSchemaContextResolver implements AutoCloseable, Schem
         return sc;
     }
 
-    /**
-     * Try to parse all currently available yang files and build new schema context.
-     *
-     * @return new schema context iif there is at least 1 yang file registered and new schema context was successfully
-     *         built.
-     * @deprecated Use {@link #getEffectiveModelContext()} instead.
-     */
-    @Deprecated(forRemoval = true)
-    public Optional<? extends SchemaContext> getSchemaContext() {
-        return getEffectiveModelContext();
-    }
-
-    /**
-     * Try to parse all currently available yang files and build new schema context depending on specified parsing mode.
-     *
-     * @param statementParserMode mode of statement parser
-     * @return new schema context iif there is at least 1 yang file registered and
-     *         new schema context was successfully built.
-     * @deprecated Use {@link #getEffectiveModelContext(StatementParserMode)} instead.
-     */
-    @Deprecated(forRemoval = true)
-    public Optional<? extends SchemaContext> getSchemaContext(final StatementParserMode statementParserMode) {
-        return getEffectiveModelContext(statementParserMode);
-    }
-
     @Override
-    public synchronized FluentFuture<YangTextSchemaSource> getSource(
+    public synchronized @NonNull FluentFuture<YangTextSchemaSource> getSource(
             final SourceIdentifier sourceIdentifier) {
         final Collection<YangTextSchemaSource> ret = texts.get(sourceIdentifier);