*/
package org.opendaylight.yangtools.yang.parser.repo;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.annotations.Beta;
-import com.google.common.base.Preconditions;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
import org.kohsuke.MetaInfServices;
import org.opendaylight.yangtools.concepts.Identifiable;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
+import org.opendaylight.yangtools.yang.model.parser.api.YangParserFactory;
+import org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory;
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;
+import org.opendaylight.yangtools.yang.model.repo.spi.AbstractSchemaRepository;
+import org.opendaylight.yangtools.yang.parser.impl.YangParserFactoryImpl;
/**
* A {@link SchemaRepository} which allows sharing of {@link SchemaContext} as long as their specification is the same.
@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>() {
+ private final LoadingCache<SchemaContextFactoryConfiguration, EffectiveModelContextFactory> cacheByConfig =
+ CacheBuilder.newBuilder().softValues()
+ .build(new CacheLoader<SchemaContextFactoryConfiguration, EffectiveModelContextFactory>() {
@Override
- public SchemaContextFactory load(@Nonnull final SchemaSourceFilter key) {
+ public EffectiveModelContextFactory load(final SchemaContextFactoryConfiguration key) {
return new SharedSchemaContextFactory(SharedSchemaRepository.this, key);
}
});
- private final LoadingCache<SchemaContextFactoryConfiguration, SchemaContextFactory> cacheByConfig = CacheBuilder
- .newBuilder().softValues()
- .build(new CacheLoader<SchemaContextFactoryConfiguration, SchemaContextFactory>() {
- @Override
- public SchemaContextFactory load(@Nonnull final SchemaContextFactoryConfiguration key) {
- return new SharedSchemaContextFactory(SharedSchemaRepository.this, key);
- }
- });
+ private final @NonNull String id;
+ private final @NonNull YangParserFactory factory;
- private final String id;
+ public SharedSchemaRepository() {
+ this("unnamed");
+ }
public SharedSchemaRepository(final String id) {
- this.id = Preconditions.checkNotNull(id);
+ this(id, new YangParserFactoryImpl());
}
- @Override
- public String getIdentifier() {
- return id;
+ public SharedSchemaRepository(final String id, final YangParserFactory factory) {
+ this.id = requireNonNull(id);
+ this.factory = requireNonNull(factory);
}
@Override
- @Deprecated
- public SchemaContextFactory createSchemaContextFactory(@Nonnull final SchemaSourceFilter filter) {
- return cacheByFilter.getUnchecked(filter);
+ public @NonNull String getIdentifier() {
+ return id;
}
@Override
- public SchemaContextFactory createSchemaContextFactory(@Nonnull final SchemaContextFactoryConfiguration config) {
+ public @NonNull EffectiveModelContextFactory createEffectiveModelContextFactory(
+ final @NonNull SchemaContextFactoryConfiguration config) {
return cacheByConfig.getUnchecked(config);
}
+ @NonNull YangParserFactory factory() {
+ return factory;
+ }
+
@Override
public String toString() {
return "SchemaRepository: " + id;