@Beta
public interface SchemaRepository {
/**
- * Instantiate a new {@link SchemaContextFactory}, which will filter available schema sources using the provided
- * filter.
+ * Returns {@link SchemaContextFactory} with supplied configuration.
*
- * @param filter Filter which acts as the gating function before a schema source is considered by the factory
- * for inclusion in the {@link SchemaContext} it produces.
- * @return A new schema context factory.
- * @deprecated Use {@link #createSchemaContextFactory(SchemaContextFactoryConfiguration)} instead.
+ * @param config configuration of schema context factory.
+ * @return schema context factory.
*/
- @Deprecated
- @NonNull SchemaContextFactory createSchemaContextFactory(@NonNull SchemaSourceFilter filter);
+ @NonNull SchemaContextFactory createSchemaContextFactory(@NonNull SchemaContextFactoryConfiguration config);
/**
- * Returns {@link SchemaContextFactory} with supplied configuration.
+ * Returns {@link SchemaContextFactory} with {@link SchemaContextFactoryConfiguration#getDefault()}.
*
- * @param config configuration of schema context factory.
* @return schema context factory.
*/
- @NonNull SchemaContextFactory createSchemaContextFactory(@NonNull SchemaContextFactoryConfiguration config);
+ default @NonNull SchemaContextFactory createSchemaContextFactory() {
+ return createSchemaContextFactory(SchemaContextFactoryConfiguration.getDefault());
+ }
<T extends SchemaSourceRepresentation> @NonNull ListenableFuture<T> getSchemaSource(@NonNull SourceIdentifier id,
@NonNull Class<T> represetation);
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
final TextToASTTransformer astTransformer = TextToASTTransformer.create(schemaRegistry, schemaRegistry);
schemaRegistry.registerSchemaSourceListener(astTransformer);
- schemaContextFactory = schemaRegistry.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
+ schemaContextFactory = schemaRegistry.createSchemaContextFactory();
allTestSources = new HashSet<>();
final SchemaListenerRegistration reg = schemaRegistry.registerSchemaSourceListener(new SchemaSourceListener() {
import javax.annotation.concurrent.GuardedBy;
import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
import org.slf4j.LoggerFactory;
/**
- * Abstract base class for {@link SchemaRepository} implementations. It handles registration
- * and lookup of schema sources, subclasses need only to provide their own
- * {@link #createSchemaContextFactory(SchemaSourceFilter)} implementation.
+ * Abstract base class for {@link SchemaRepository} implementations. It handles registration and lookup of schema
+ * sources, subclasses need only to provide their own {@link #createSchemaContextFactory()} implementation.
*/
@Beta
public abstract class AbstractSchemaRepository implements SchemaRepository, SchemaSourceRegistry {
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.YangSchemaSourceRepresentation;
}
private class Provider extends AbstractSchemaRepository {
- @Deprecated
- @Override
- public SchemaContextFactory createSchemaContextFactory(final SchemaSourceFilter filter) {
- return mock(SchemaContextFactory.class);
- }
-
@Override
public SchemaContextFactory createSchemaContextFactory(final SchemaContextFactoryConfiguration config) {
return mock(SchemaContextFactory.class);
}
private class Consumer extends AbstractSchemaRepository {
- @Deprecated
- @Override
- public SchemaContextFactory createSchemaContextFactory(final SchemaSourceFilter filter) {
- return mock(SchemaContextFactory.class);
- }
-
@Override
public SchemaContextFactory createSchemaContextFactory(final SchemaContextFactoryConfiguration config) {
return mock(SchemaContextFactory.class);
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
import org.opendaylight.yangtools.yang.parser.impl.DefaultReactors;
private final @NonNull SchemaRepository repository;
private final @NonNull SchemaContextFactoryConfiguration config;
- // FIXME SchemaRepository should be the type for repository parameter instead of SharedSchemaRepository
- // (final implementation)
- @Deprecated
- SharedSchemaContextFactory(final @NonNull SharedSchemaRepository repository,
- final @NonNull SchemaSourceFilter filter) {
- this(repository, SchemaContextFactoryConfiguration.builder().setFilter(filter).build());
- }
-
SharedSchemaContextFactory(final @NonNull SchemaRepository repository,
final @NonNull SchemaContextFactoryConfiguration config) {
this.repository = requireNonNull(repository);
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.util.AbstractSchemaRepository;
@Beta
@MetaInfServices(value = SchemaRepository.class)
public final class SharedSchemaRepository extends AbstractSchemaRepository implements Identifiable<String> {
- @Deprecated
- private final LoadingCache<SchemaSourceFilter, SchemaContextFactory> cacheByFilter = CacheBuilder.newBuilder()
- .softValues().build(new CacheLoader<SchemaSourceFilter, SchemaContextFactory>() {
- @Override
- public SchemaContextFactory load(final SchemaSourceFilter key) {
- return new SharedSchemaContextFactory(SharedSchemaRepository.this, key);
- }
- });
-
private final LoadingCache<SchemaContextFactoryConfiguration, SchemaContextFactory> cacheByConfig = CacheBuilder
.newBuilder().softValues()
.build(new CacheLoader<SchemaContextFactoryConfiguration, SchemaContextFactory>() {
return id;
}
- @Override
- @Deprecated
- public @NonNull SchemaContextFactory createSchemaContextFactory(final @NonNull SchemaSourceFilter filter) {
- return cacheByFilter.getUnchecked(filter);
- }
-
@Override
public @NonNull SchemaContextFactory createSchemaContextFactory(
final @NonNull SchemaContextFactoryConfiguration config) {
import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
+import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
* new schema context was successfully built.
*/
public Optional<SchemaContext> getSchemaContext(final StatementParserMode statementParserMode) {
- final SchemaContextFactory factory = repository.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
+ final SchemaContextFactory factory = repository.createSchemaContextFactory(config(statementParserMode));
Optional<SchemaContext> sc;
Object ver;
do {
public SchemaContext trySchemaContext(final StatementParserMode statementParserMode)
throws SchemaResolutionException {
final ListenableFuture<SchemaContext> future = repository
- .createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT)
+ .createSchemaContextFactory(config(statementParserMode))
.createSchemaContext(ImmutableSet.copyOf(requiredSources), statementParserMode);
try {
public void close() {
transReg.close();
}
+
+ private static SchemaContextFactoryConfiguration config(final StatementParserMode statementParserMode) {
+ return SchemaContextFactoryConfiguration.builder().setStatementParserMode(statementParserMode).build();
+ }
}
* 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.yangtools.yang.parser.repo;
import static org.junit.Assert.assertEquals;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.ASTSchemaSource;
setAndRegister(sharedSchemaRepository, bar2);
setAndRegister(sharedSchemaRepository, bar3);
- final SchemaContextFactory fact = sharedSchemaRepository
- .createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
-
- final ListenableFuture<SchemaContext> schemaContextFuture = fact
+ final ListenableFuture<SchemaContext> schemaContextFuture = sharedSchemaRepository.createSchemaContextFactory()
.createSchemaContext(ImmutableList.of(foo.getId(), bar1.getId(), bar2.getId(), bar3.getId()));
assertTrue(schemaContextFuture.isDone());
setAndRegister(sharedSchemaRepository, bar1);
setAndRegister(sharedSchemaRepository, bar2);
- final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory(
- SchemaSourceFilter.ALWAYS_ACCEPT);
- final ListenableFuture<SchemaContext> schemaContextFuture = fact.createSchemaContext(
- ImmutableList.of(foo.getId(), bar1.getId(), bar2.getId()));
+ final ListenableFuture<SchemaContext> schemaContextFuture = sharedSchemaRepository.createSchemaContextFactory()
+ .createSchemaContext(ImmutableList.of(foo.getId(), bar1.getId(), bar2.getId()));
assertTrue(schemaContextFuture.isDone());
try {
import org.junit.Test;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter;
import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.ASTSchemaSource;
semVer.register(sharedSchemaRepository);
semVer.setResult();
- final SchemaContextFactory fact = sharedSchemaRepository
- .createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
+ final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory();
final ListenableFuture<SchemaContext> inetAndTopologySchemaContextFuture =
fact.createSchemaContext(ImmutableList.of(bar.getId(), foo.getId(), semVer.getId()),
semVer.register(sharedSchemaRepository);
semVer.setResult();
- final SchemaContextFactory fact = sharedSchemaRepository
- .createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
-
+ final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory();
final ListenableFuture<SchemaContext> inetAndTopologySchemaContextFuture =
fact.createSchemaContext(ImmutableList.of(bar.getId(), foo.getId(), semVer.getId()));
assertTrue(inetAndTopologySchemaContextFuture.isDone());
import java.util.concurrent.ExecutionException;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.Mock;
+import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter;
+import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.ASTSchemaSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToASTTransformer;
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class SharedSchemaContextFactoryTest {
private final SharedSchemaRepository repository = new SharedSchemaRepository("test");
- @Mock
- private SchemaSourceFilter filter;
+ private final SchemaContextFactoryConfiguration config = SchemaContextFactoryConfiguration.getDefault();
private SourceIdentifier s1;
private SourceIdentifier s2;
@Test
public void testCreateSchemaContextWithDuplicateRequiredSources() throws InterruptedException, ExecutionException {
final SharedSchemaContextFactory sharedSchemaContextFactory = new SharedSchemaContextFactory(repository,
- filter);
+ config);
final ListenableFuture<SchemaContext> schemaContext =
sharedSchemaContextFactory.createSchemaContext(Arrays.asList(s1, s1, s2));
assertNotNull(schemaContext.get());
sIdWithoutRevision, ASTSchemaSource.class, PotentialSchemaSource.Costs.IMMEDIATE.getValue()));
final SharedSchemaContextFactory sharedSchemaContextFactory = new SharedSchemaContextFactory(repository,
- filter);
+ config);
final ListenableFuture<SchemaContext> schemaContext =
sharedSchemaContextFactory.createSchemaContext(Arrays.asList(sIdWithoutRevision, provider.getId()));
assertNotNull(schemaContext.get());
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFluentFuture;
-import static org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter.ALWAYS_ACCEPT;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.collect.ImmutableList;
remoteInetTypesYang.getId(), ASTSchemaSource.class);
assertFalse(registeredSourceFuture.isDone());
- final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory(ALWAYS_ACCEPT);
+ final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory();
final ListenableFuture<SchemaContext> schemaContextFuture =
fact.createSchemaContext(ImmutableList.of(remoteInetTypesYang.getId()));
assertSchemaContext(firstSchemaContext, 1);
// Try same schema second time
- final ListenableFuture<SchemaContext> secondSchemaFuture = sharedSchemaRepository
- .createSchemaContextFactory(ALWAYS_ACCEPT)
+ final ListenableFuture<SchemaContext> secondSchemaFuture = sharedSchemaRepository.createSchemaContextFactory()
.createSchemaContext(ImmutableList.of(remoteInetTypesYang.getId()));
// Verify second schema created successfully immediately
getImmediateYangSourceProviderFromResource("/no-revision/module-without-revision.yang");
remoteModuleNoRevYang.register(sharedSchemaRepository);
- final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory(ALWAYS_ACCEPT);
+ final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory();
final ListenableFuture<SchemaContext> inetAndTopologySchemaContextFuture = fact
.createSchemaContext(ImmutableList.of(remoteInetTypesYang.getId(), remoteTopologyYang.getId()));
assertTrue(inetAndTopologySchemaContextFuture.isDone());
"/ietf/ietf-inet-types@2010-09-24.yang");
remoteInetTypesYang.register(sharedSchemaRepository);
- final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory(ALWAYS_ACCEPT);
+ final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory();
// Make source appear
final Throwable ex = new IllegalStateException("failed schema");
remoteInetTypesYang.register(sharedSchemaRepository);
remoteInetTypesYang.setResult();
- final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory(ALWAYS_ACCEPT);
-
+ final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory();
final ListenableFuture<SchemaContext> schemaContextFuture =
fact.createSchemaContext(ImmutableList.of(remoteInetTypesYang.getId()));
// Request schema to make repository notify the cache
final ListenableFuture<SchemaContext> schemaFuture = sharedSchemaRepository
- .createSchemaContextFactory(ALWAYS_ACCEPT).createSchemaContext(ImmutableList.of(runningId));
+ .createSchemaContextFactory()
+ .createSchemaContext(ImmutableList.of(runningId));
Futures.addCallback(schemaFuture, new FutureCallback<SchemaContext>() {
@Override
public void onSuccess(final SchemaContext result) {
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.ASTSchemaSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToASTTransformer;
foobar.register(sharedSchemaRepository);
foobar.setResult();
- final SchemaContextFactory fact = sharedSchemaRepository
- .createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
-
+ final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory();
final ListenableFuture<SchemaContext> testSchemaContextFuture =
fact.createSchemaContext(ImmutableList.of(foobar.getId()), supportedFeatures);
assertTrue(testSchemaContextFuture.isDone());
foobar.register(sharedSchemaRepository);
foobar.setResult();
- final SchemaContextFactory fact = sharedSchemaRepository
- .createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
-
+ final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory();
final ListenableFuture<SchemaContext> testSchemaContextFuture =
fact.createSchemaContext(ImmutableList.of(foobar.getId()));
assertTrue(testSchemaContextFuture.isDone());
foobar.register(sharedSchemaRepository);
foobar.setResult();
- final SchemaContextFactory fact = sharedSchemaRepository
- .createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
-
+ final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory();
final ListenableFuture<SchemaContext> testSchemaContextFuture =
fact.createSchemaContext(ImmutableList.of(foobar.getId()), supportedFeatures);
assertTrue(testSchemaContextFuture.isDone());