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;
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;
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;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
import org.opendaylight.yangtools.yang.model.repo.util.InMemorySchemaSourceCache;
-import org.opendaylight.yangtools.yang.parser.rfc7950.repo.ASTSchemaSource;
-import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToASTTransformer;
+import org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource;
+import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private final Multimap<SourceIdentifier, YangTextSchemaSource> texts = ArrayListMultimap.create();
private final AtomicReference<Optional<EffectiveModelContext>> currentSchemaContext =
new AtomicReference<>(Optional.empty());
- private final InMemorySchemaSourceCache<ASTSchemaSource> cache;
+ private final InMemorySchemaSourceCache<IRSchemaSource> cache;
private final SchemaListenerRegistration transReg;
private final SchemaSourceRegistry registry;
private final SchemaRepository repository;
this.repository = requireNonNull(repository);
this.registry = requireNonNull(registry);
- final TextToASTTransformer t = TextToASTTransformer.create(repository, registry);
+ final TextToIRTransformer t = TextToIRTransformer.create(repository, registry);
transReg = registry.registerSchemaSourceListener(t);
- cache = InMemorySchemaSourceCache.createSoftCache(registry, ASTSchemaSource.class, SOURCE_LIFETIME_SECONDS,
+ cache = InMemorySchemaSourceCache.createSoftCache(registry, IRSchemaSource.class, SOURCE_LIFETIME_SECONDS,
TimeUnit.SECONDS);
}
throws SchemaSourceException, IOException, YangSyntaxErrorException {
checkArgument(source != null);
- final ASTSchemaSource ast = TextToASTTransformer.transformText(source);
+ final IRSchemaSource ast = TextToIRTransformer.transformText(source);
LOG.trace("Resolved source {} to source {}", source, ast);
// AST carries an accurate identifier, check if it matches the one supplied by the source. If it
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) {
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);