import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;
-import com.google.common.util.concurrent.ListenableFuture;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class CurrentAdapterSerializerTest {
}
@Override
- public EffectiveModelContext modelContext() {
- throw new UnsupportedOperationException();
+ @SuppressWarnings("unchecked")
+ public <T> Class<T> loadClass(final String fullyQualifiedName) throws ClassNotFoundException {
+ return (Class<T>) Class.forName(fullyQualifiedName);
}
@Override
- public ListenableFuture<? extends YangTextSource> getSource(final SourceIdentifier sourceIdentifier) {
- throw new UnsupportedOperationException();
+ public YangTextSource yangTextSource(final SourceIdentifier arg0) {
+ return null;
}
@Override
- @SuppressWarnings("unchecked")
- public <T> Class<T> loadClass(final String fullyQualifiedName) throws ClassNotFoundException {
- return (Class<T>) Class.forName(fullyQualifiedName);
+ public YangTextSource getYangTextSource(final SourceIdentifier sourceId) throws MissingSchemaSourceException {
+ throw new MissingSchemaSourceException(sourceId, "no sources");
}
+
+ @Override
+ public EffectiveModelContext modelContext() {
+ throw new UnsupportedOperationException();
+ }
+
}
}
</dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-repo-spi</artifactId>
+ <artifactId>yang-repo-api</artifactId>
</dependency>
<dependency>
<groupId>org.opendaylight.mdsal</groupId>
requires transitive org.opendaylight.yangtools.concepts;
requires transitive org.opendaylight.yangtools.yang.common;
requires transitive org.opendaylight.yangtools.yang.model.api;
+ requires transitive org.opendaylight.yangtools.yang.repo.api;
requires transitive org.opendaylight.yangtools.yang.binding;
- requires transitive org.opendaylight.yangtools.yang.repo.spi;
requires transitive org.opendaylight.yangtools.rfc8040.model.api;
requires transitive org.opendaylight.mdsal.binding.model.api;
requires org.slf4j;
package org.opendaylight.mdsal.binding.runtime.api;
import com.google.common.annotations.Beta;
-import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
-import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
+import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
/**
* A snapshot of a set of {@link YangModuleInfo}s, assembled to form an {@link EffectiveModelContext}.
*/
@Beta
-public interface ModuleInfoSnapshot extends Immutable, SchemaSourceProvider<YangTextSource> {
+@NonNullByDefault
+public interface ModuleInfoSnapshot extends Immutable {
/**
* The {@link EffectiveModelContext} resulting from all models exposed from constituent module infos.
*
* @return the resulting model context
*/
- @NonNull EffectiveModelContext modelContext();
+ EffectiveModelContext modelContext();
+
+ @Nullable YangTextSource yangTextSource(SourceIdentifier sourceId);
+
+ YangTextSource getYangTextSource(SourceIdentifier sourceId) throws MissingSchemaSourceException;
<T> Class<T> loadClass(String fullyQualifiedName) throws ClassNotFoundException;
}
import static java.util.Objects.requireNonNull;
import com.google.common.collect.ImmutableMap;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot;
}
@Override
- public ListenableFuture<? extends YangTextSource> getSource(final SourceIdentifier sourceId) {
+ public YangTextSource yangTextSource(final SourceIdentifier sourceId) {
final var info = moduleInfos.get(sourceId);
- return info == null
- ? Futures.immediateFailedFuture(new MissingSchemaSourceException(sourceId, "No source registered"))
- : Futures.immediateFuture(new DelegatedYangTextSource(sourceId, info.getYangTextCharSource()));
+ return info == null ? null : new DelegatedYangTextSource(sourceId, info.getYangTextCharSource());
+ }
+
+ @Override
+ public YangTextSource getYangTextSource(final SourceIdentifier sourceId) throws MissingSchemaSourceException {
+ final var source = yangTextSource(sourceId);
+ if (source == null) {
+ throw new MissingSchemaSourceException(sourceId, "No source registered");
+ }
+ return source;
}
@Override
import com.google.common.annotations.Beta;
import com.google.common.collect.ForwardingObject;
-import com.google.common.util.concurrent.ListenableFuture;
-import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
@Beta
+@NonNullByDefault
public abstract class ForwardingModuleInfoSnapshot extends ForwardingObject implements ModuleInfoSnapshot {
@Override
protected abstract ModuleInfoSnapshot delegate();
}
@Override
- public @NonNull EffectiveModelContext modelContext() {
+ public EffectiveModelContext modelContext() {
return delegate().modelContext();
}
@Override
- public ListenableFuture<? extends YangTextSource> getSource(final SourceIdentifier sourceIdentifier) {
- return delegate().getSource(sourceIdentifier);
+ public @Nullable YangTextSource yangTextSource(final SourceIdentifier sourceId) {
+ return delegate().yangTextSource(sourceId);
+ }
+
+ @Override
+ public YangTextSource getYangTextSource(final SourceIdentifier sourceId) throws MissingSchemaSourceException {
+ return delegate().getYangTextSource(sourceId);
}
}
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-model-api</artifactId>
</dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-model-spi</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-repo-spi</artifactId>
- </dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
requires transitive org.opendaylight.yangtools.yang.data.api;
requires transitive org.opendaylight.yangtools.yang.data.tree.api;
requires transitive org.opendaylight.yangtools.yang.model.api;
- requires transitive org.opendaylight.yangtools.yang.model.spi;
- requires transitive org.opendaylight.yangtools.yang.repo.spi;
requires transitive org.opendaylight.mdsal.common.api;
requires transitive org.opendaylight.yangtools.concepts;
requires org.opendaylight.yangtools.util;
*/
package org.opendaylight.mdsal.dom.api;
+import com.google.common.util.concurrent.ListenableFuture;
import java.util.function.Consumer;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
@NonNullByDefault
public interface DOMSchemaService extends DOMService<DOMSchemaService, DOMSchemaService.Extension> {
* @throws NullPointerException if {@code listener} is {@code null}
*/
Registration registerSchemaContextListener(Consumer<EffectiveModelContext> listener);
+
+ /**
+ * An {@link Extension} exposing access to {@link YangTextSource}.
+ */
+ @FunctionalInterface
+ interface YangTextSourceExtension extends Extension {
+ /**
+ * Return a future producing a {@link YangTextSource} containing the YANG text of specified source.
+ *
+ * @param sourceId A {@link SourceIdentifier}
+ * @return A future
+ */
+ ListenableFuture<YangTextSource> getYangTexttSource(SourceIdentifier sourceId);
+ }
}
+++ /dev/null
-/*
- * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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/epl-v10.html
- */
-package org.opendaylight.mdsal.dom.api;
-
-import com.google.common.annotations.Beta;
-import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
-import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
-
-/**
- * A {@link DOMSchemaService.Extension} exposing access to {@link YangTextSource}. Instances of this method should
- * be acquired from {@link DOMSchemaService}.
- */
-@Beta
-public interface DOMYangTextSourceProvider
- extends DOMSchemaService.Extension, SchemaSourceProvider<YangTextSource> {
-
-}
import static java.util.Objects.requireNonNull;
+import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
import org.opendaylight.mdsal.dom.schema.osgi.OSGiModuleInfoSnapshot;
import org.opendaylight.yangtools.concepts.AbstractRegistration;
import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
import org.osgi.service.component.ComponentFactory;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
/**
* OSGi Service Registry-backed implementation of {@link DOMSchemaService}.
*/
-@Component(service = DOMSchemaService.class, immediate = true)
-public final class OSGiDOMSchemaService implements DOMSchemaService, DOMYangTextSourceProvider {
+@Component(immediate = true)
+public final class OSGiDOMSchemaService implements DOMSchemaService, DOMSchemaService.YangTextSourceExtension {
private static final Logger LOG = LoggerFactory.getLogger(OSGiDOMSchemaService.class);
private final List<Consumer<EffectiveModelContext>> listeners = new CopyOnWriteArrayList<>();
LOG.info("DOM Schema services activated");
}
+ @Override
+ public List<Extension> supportedExtensions() {
+ return List.of(this);
+ }
+
@Deactivate
void deactivate() {
LOG.info("DOM Schema services deactivated");
}
@Override
- public ListenableFuture<? extends YangTextSource> getSource(final SourceIdentifier sourceIdentifier) {
- return currentSnapshot.get().getSource(sourceIdentifier);
+ public ListenableFuture<YangTextSource> getYangTexttSource(final SourceIdentifier sourceId) {
+ try {
+ return Futures.immediateFuture(currentSnapshot.get().getYangTextSource(sourceId));
+ } catch (MissingSchemaSourceException e) {
+ return Futures.immediateFailedFuture(e);
+ }
}
@SuppressWarnings("checkstyle:illegalCatch")
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-model-api</artifactId>
</dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-repo-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-repo-spi</artifactId>
- </dependency>
<dependency>
<groupId>org.opendaylight.mdsal</groupId>
<artifactId>mdsal-common-api</artifactId>
<artifactId>yang-parser-api</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-repo-api</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-test-util</artifactId>
requires transitive org.opendaylight.yangtools.yang.common;
requires transitive org.opendaylight.yangtools.yang.data.tree.api;
requires transitive org.opendaylight.yangtools.yang.model.api;
- requires transitive org.opendaylight.yangtools.yang.repo.api;
- requires transitive org.opendaylight.yangtools.yang.repo.spi;
requires com.google.common;
requires org.opendaylight.yangtools.concepts;
requires org.opendaylight.yangtools.odlext.model.api;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.Beta;
-import com.google.common.util.concurrent.ListenableFuture;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
-import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
/**
- * {@link DOMSchemaService} (and {@link DOMYangTextSourceProvider}) implementations backed by a
- * {@code Supplier<EffectiveModelContext>} (and {@link SchemaSourceProvider}) which are known to be fixed and never
- * change schemas.
+ * {@link DOMSchemaService} backed by a {@code Supplier<EffectiveModelContext>}
+ * (and potentially a {@link YangTextSourceExtension}) which are known to be fixed
+ * and never change schemas.
*
* @author Michael Vorburger.ch
*/
@Beta
@NonNullByDefault
-public sealed class FixedDOMSchemaService implements DOMSchemaService {
- private static final class WithYangTextSources extends FixedDOMSchemaService implements DOMYangTextSourceProvider {
- private final SchemaSourceProvider<YangTextSource> schemaSourceProvider;
-
- WithYangTextSources(final Supplier<EffectiveModelContext> modelContextSupplier,
- final SchemaSourceProvider<YangTextSource> schemaSourceProvider) {
- super(modelContextSupplier);
- this.schemaSourceProvider = requireNonNull(schemaSourceProvider);
- }
-
- @Override
- public List<Extension> supportedExtensions() {
- return List.of(this);
- }
-
- @Override
- public ListenableFuture<? extends YangTextSource> getSource(final SourceIdentifier sourceIdentifier) {
- return schemaSourceProvider.getSource(sourceIdentifier);
- }
+public record FixedDOMSchemaService(
+ Supplier<EffectiveModelContext> modelContextSupplier,
+ @Nullable YangTextSourceExtension extension) implements DOMSchemaService {
+ public FixedDOMSchemaService {
+ requireNonNull(modelContextSupplier);
}
- private final Supplier<EffectiveModelContext> modelContextSupplier;
-
- private FixedDOMSchemaService(final Supplier<EffectiveModelContext> modelContextSupplier) {
- this.modelContextSupplier = requireNonNull(modelContextSupplier);
+ public FixedDOMSchemaService(final Supplier<EffectiveModelContext> modelContextSupplier) {
+ this(modelContextSupplier, null);
}
- public static DOMSchemaService of(final EffectiveModelContext effectiveModel) {
- final var checked = requireNonNull(effectiveModel);
- return new FixedDOMSchemaService(() -> checked);
+ public FixedDOMSchemaService(final EffectiveModelContext effectiveModel) {
+ this(() -> effectiveModel, null);
+ requireNonNull(effectiveModel);
}
- public static DOMSchemaService of(final Supplier<EffectiveModelContext> modelContextSupplier) {
- return new FixedDOMSchemaService(modelContextSupplier);
- }
-
- public static DOMSchemaService of(final Supplier<EffectiveModelContext> modelContextSupplier,
- final SchemaSourceProvider<YangTextSource> yangTextSourceProvider) {
- return new WithYangTextSources(modelContextSupplier, requireNonNull(yangTextSourceProvider));
+ @Override
+ public List<Extension> supportedExtensions() {
+ final var local = extension;
+ return local == null ? List.of() : List.of(local);
}
@Override