import java.lang.ref.SoftReference;
import java.net.URI;
+import java.util.Collection;
import java.util.Date;
-import java.util.Set;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
+import java.util.Optional;
+import org.opendaylight.mdsal.dom.api.DOMMountPoint;
import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
/**
- * This class creates {@link SoftReference} of actual {@link SchemaContext}
+ * This class creates {@link SoftReference} of actual {@link EffectiveModelContext}
* object and even if the {@link SchemaContext} changes, this will be sticks
* reference to the old {@link SchemaContext} and provides work with the old
- * {@link SchemaContext}.
+ * {@link EffectiveModelContext}.
*
*/
public final class SchemaContextRef {
- private final SoftReference<SchemaContext> schemaContextRef;
+ private final SoftReference<EffectiveModelContext> schemaContextRef;
/**
- * Create {@link SoftReference} of actual {@link SchemaContext}.
+ * Create {@link SoftReference} of actual {@link EffectiveModelContext}.
*
* @param schemaContext
- * actual {@link SchemaContext}
+ * actual {@link EffectiveModelContext}
*/
- public SchemaContextRef(final SchemaContext schemaContext) {
- this.schemaContextRef = new SoftReference<SchemaContext>(schemaContext);
+ public SchemaContextRef(final EffectiveModelContext schemaContext) {
+ this.schemaContextRef = new SoftReference<>(schemaContext);
}
/**
- * Get {@link SchemaContext} from reference.
+ * Get {@link EffectiveModelContext} from reference.
*
- * @return {@link SchemaContext}
+ * @return {@link EffectiveModelContext}
*/
- public SchemaContext get() {
+ public EffectiveModelContext get() {
return this.schemaContextRef.get();
}
/**
- * Get all modules like {@link Set} of {@link Module} from
- * {@link SchemaContext}.
+ * Get all modules like {@link Collection} of {@link Module} from {@link SchemaContext}.
*
- * @return {@link Set} of {@link Module}
+ * @return {@link Collection} of {@link Module}
*/
- public Set<Module> getModules() {
+ public Collection<? extends Module> getModules() {
return get().getModules();
}
- /**
- * Get all modules like {@link Set} of {@link Module} from
- * {@link SchemaContext} of {@link DOMMountPoint}.
- *
- * @param mountPoint
- * mount point
- *
- * @return {@link Set} of {@link Module}
- */
- public Set<Module> getModules(final DOMMountPoint mountPoint) {
- final SchemaContext schemaContext = mountPoint == null ? null : mountPoint.getSchemaContext();
- return schemaContext == null ? null : schemaContext.getModules();
- }
-
/**
* Get {@link Module} by ietf-restconf qname from
* {@link Rfc8040.RestconfModule}.
* revision of module
* @return {@link Module}
*/
- public Module findModuleByNamespaceAndRevision(final URI namespace, final Date revision) {
- return this.get().findModuleByNamespaceAndRevision(namespace, revision);
+ public Module findModuleByNamespaceAndRevision(final URI namespace, final Optional<Revision> revision) {
+ return this.get().findModule(namespace, revision).orElse(null);
}
-
/**
* Find {@link Module} in {@link SchemaContext} of {@link DOMMountPoint} by
* {@link QName} of {@link Module}.
public Module findModuleInMountPointByQName(final DOMMountPoint mountPoint, final QName moduleQname) {
final SchemaContext schemaContext = mountPoint == null ? null : mountPoint.getSchemaContext();
return schemaContext == null ? null
- : schemaContext.findModuleByName(moduleQname.getLocalName(), moduleQname.getRevision());
+ : schemaContext.findModule(moduleQname.getLocalName(), moduleQname.getRevision()).orElse(null);
}
/**
* revision of module
* @return {@link Module}
*/
- public Module findModuleByNameAndRevision(final String localName, final Date revision) {
- return this.get().findModuleByName(localName, revision);
+ public Module findModuleByNameAndRevision(final String localName, final Optional<Revision> revision) {
+ return this.get().findModule(localName, revision).orElse(null);
}
}