Remove deprecated SchemaRepository.createSchemaContextFactory()
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / repo / SharedSchemaRepository.java
index 1ff9f32908b024bde6b770a08930190fc60eef0b..86e9503d6614a673f2c143a602bd68f588658845 100644 (file)
@@ -7,50 +7,55 @@
  */
 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 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.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;
 
 /**
- * A {@link SchemaRepository} which allows sharing of {@link SchemaContext} as
- * long as their specification is the same.
+ * A {@link SchemaRepository} which allows sharing of {@link SchemaContext} as long as their specification is the same.
  *
- * Note: for current implementation, "same" means the same filter and the same
- * set of {@link SourceIdentifier}s.
+ * <p>
+ * Note: for current implementation, "same" means the same filter and the same set of {@link SourceIdentifier}s.
  */
 @Beta
+@MetaInfServices(value = SchemaRepository.class)
 public final class SharedSchemaRepository extends AbstractSchemaRepository implements Identifiable<String> {
-    private final LoadingCache<SchemaSourceFilter, SchemaContextFactory> cache =
-            CacheBuilder.newBuilder().softValues().build(new CacheLoader<SchemaSourceFilter, SchemaContextFactory>() {
+    private final LoadingCache<SchemaContextFactoryConfiguration, SchemaContextFactory> cacheByConfig = CacheBuilder
+            .newBuilder().softValues()
+            .build(new CacheLoader<SchemaContextFactoryConfiguration, SchemaContextFactory>() {
                 @Override
-                public SchemaContextFactory load(final SchemaSourceFilter key) {
+                public SchemaContextFactory load(final SchemaContextFactoryConfiguration key) {
                     return new SharedSchemaContextFactory(SharedSchemaRepository.this, key);
                 }
             });
-    private final String id;
+
+    private final @NonNull String id;
 
     public SharedSchemaRepository(final String id) {
-        this.id = Preconditions.checkNotNull(id);
+        this.id = requireNonNull(id);
     }
 
     @Override
-    public String getIdentifier() {
+    public @NonNull String getIdentifier() {
         return id;
     }
 
     @Override
-    public SchemaContextFactory createSchemaContextFactory(final SchemaSourceFilter filter) {
-        return cache.getUnchecked(filter);
+    public @NonNull SchemaContextFactory createSchemaContextFactory(
+            final @NonNull SchemaContextFactoryConfiguration config) {
+        return cacheByConfig.getUnchecked(config);
     }
 
     @Override