InstanceIdentifierContext does not take generics
[netconf.git] / restconf / restconf-nb-bierman02 / src / main / java / org / opendaylight / netconf / sal / restconf / impl / ControllerContext.java
index ed3b7a8c975fd21b35a4d2715accab7633c90c35..cc01ef9fe477410590be4a659429d6fdb701237e 100644 (file)
  */
 package org.opendaylight.netconf.sal.restconf.impl;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.base.Splitter;
 import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Iterables;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import java.io.Closeable;
 import java.io.UnsupportedEncodingException;
-import java.net.URI;
 import java.net.URLDecoder;
 import java.net.URLEncoder;
-import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Date;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
+import java.util.Optional;
 import java.util.concurrent.atomic.AtomicReference;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import javax.ws.rs.core.Response.Status;
-import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException;
-import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationOperation;
-import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizer;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.dom.api.DOMMountPoint;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
+import org.opendaylight.netconf.sal.rest.api.Draft02;
 import org.opendaylight.netconf.sal.rest.api.Draft02.RestConfModule;
-import org.opendaylight.netconf.sal.rest.impl.RestUtil;
-import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
-import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
-import org.opendaylight.yangtools.concepts.Codec;
+import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.opendaylight.restconf.common.util.RestUtil;
+import org.opendaylight.yangtools.concepts.IllegalArgumentCodec;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.common.XMLNamespace;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
+import org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
+import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class ControllerContext implements SchemaContextListener {
+@Singleton
+public final class ControllerContext implements EffectiveModelContextListener, Closeable {
     // FIXME: this should be in md-sal somewhere
     public static final String MOUNT = "yang-ext:mount";
 
     private static final Logger LOG = LoggerFactory.getLogger(ControllerContext.class);
 
-    // FIXME: this should be the current instance which is mutated
-    private static final ControllerContext INSTANCE = new ControllerContext();
-
     private static final String NULL_VALUE = "null";
 
     private static final String MOUNT_MODULE = "yang-ext";
 
     private static final String MOUNT_NODE = "mount";
 
-    private static final Charset URI_ENCODING_CHARSET = StandardCharsets.UTF_8;
-
     private static final Splitter SLASH_SPLITTER = Splitter.on('/');
 
     private final AtomicReference<Map<QName, RpcDefinition>> qnameToRpc = new AtomicReference<>(Collections.emptyMap());
 
-    // FIXME; these three should be final
-    private volatile SchemaContext globalSchema;
-    private volatile DOMMountPointService mountService;
-    private DataNormalizer dataNormalizer;
+    private final DOMMountPointService mountService;
+    private final DOMYangTextSourceProvider yangTextSourceProvider;
+    private final ListenerRegistration<?> listenerRegistration;
+    private volatile EffectiveModelContext globalSchema;
+    private volatile DataNormalizer dataNormalizer;
 
+    @Inject
+    public ControllerContext(final DOMSchemaService schemaService, final DOMMountPointService mountService,
+            final DOMSchemaService domSchemaService) {
+        this.mountService = mountService;
+        yangTextSourceProvider = domSchemaService.getExtensions().getInstance(DOMYangTextSourceProvider.class);
 
-    public void setGlobalSchema(final SchemaContext globalSchema) {
-        this.globalSchema = globalSchema;
-        this.dataNormalizer = new DataNormalizer(globalSchema);
+        onModelContextUpdated(schemaService.getGlobalContext());
+        listenerRegistration = schemaService.registerSchemaContextListener(this);
     }
 
-    public void setMountService(final DOMMountPointService mountService) {
-        this.mountService = mountService;
+    /**
+     * Factory method.
+     *
+     * @deprecated Just use the
+     *             {@link #ControllerContext(DOMSchemaService, DOMMountPointService, DOMSchemaService)}
+     *             constructor instead.
+     */
+    @Deprecated
+    public static ControllerContext newInstance(final DOMSchemaService schemaService,
+            final DOMMountPointService mountService, final DOMSchemaService domSchemaService) {
+        return new ControllerContext(schemaService, mountService, domSchemaService);
     }
 
-    private ControllerContext() {
+    private void setGlobalSchema(final EffectiveModelContext globalSchema) {
+        this.globalSchema = globalSchema;
+        dataNormalizer = new DataNormalizer(globalSchema);
     }
 
-    public static ControllerContext getInstance() {
-        return INSTANCE;
+    public DOMYangTextSourceProvider getYangTextSourceProvider() {
+        return yangTextSourceProvider;
     }
 
     private void checkPreconditions() {
-        if (this.globalSchema == null) {
+        if (globalSchema == null) {
             throw new RestconfDocumentedException(Status.SERVICE_UNAVAILABLE);
         }
     }
 
-    public void setSchemas(final SchemaContext schemas) {
-        onGlobalContextUpdated(schemas);
+    @Override
+    @PreDestroy
+    public void close() {
+        listenerRegistration.close();
+    }
+
+    public void setSchemas(final EffectiveModelContext schemas) {
+        onModelContextUpdated(schemas);
     }
 
-    public InstanceIdentifierContext<?> toInstanceIdentifier(final String restconfInstance) {
+    public InstanceIdentifierContext toInstanceIdentifier(final String restconfInstance) {
         return toIdentifier(restconfInstance, false);
     }
 
-    public SchemaContext getGlobalSchema() {
-        return this.globalSchema;
+    public EffectiveModelContext getGlobalSchema() {
+        return globalSchema;
     }
 
-    public InstanceIdentifierContext<?> toMountPointIdentifier(final String restconfInstance) {
+    public InstanceIdentifierContext toMountPointIdentifier(final String restconfInstance) {
         return toIdentifier(restconfInstance, true);
     }
 
-    private InstanceIdentifierContext<?> toIdentifier(final String restconfInstance,
-                                                      final boolean toMountPointIdentifier) {
+    private InstanceIdentifierContext toIdentifier(final String restconfInstance,
+                                                   final boolean toMountPointIdentifier) {
         checkPreconditions();
 
         if (restconfInstance == null) {
-            return new InstanceIdentifierContext<>(YangInstanceIdentifier.EMPTY, this.globalSchema, null,
-                    this.globalSchema);
+            return new InstanceIdentifierContext(YangInstanceIdentifier.empty(), globalSchema, null, globalSchema);
         }
 
         final List<String> pathArgs = urlPathArgsDecode(SLASH_SPLITTER.split(restconfInstance));
@@ -157,15 +183,15 @@ public class ControllerContext implements SchemaContextListener {
         }
 
         final InstanceIdentifierBuilder builder = YangInstanceIdentifier.builder();
-        final Module latestModule = this.globalSchema.findModuleByName(startModule, null);
+        final Collection<? extends Module> latestModule = globalSchema.findModules(startModule);
 
-        if (latestModule == null) {
+        if (latestModule.isEmpty()) {
             throw new RestconfDocumentedException("The module named '" + startModule + "' does not exist.",
                     ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT);
         }
 
-        final InstanceIdentifierContext<?> iiWithSchemaNode =
-                collectPathArguments(builder, pathArgs, latestModule, null, toMountPointIdentifier);
+        final InstanceIdentifierContext iiWithSchemaNode =
+                collectPathArguments(builder, pathArgs, latestModule.iterator().next(), null, toMountPointIdentifier);
 
         if (iiWithSchemaNode == null) {
             throw new RestconfDocumentedException("URI has bad format", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
@@ -198,55 +224,46 @@ public class ControllerContext implements SchemaContextListener {
 
     public Module findModuleByName(final String moduleName) {
         checkPreconditions();
-        Preconditions.checkArgument((moduleName != null) && !moduleName.isEmpty());
-        return this.globalSchema.findModuleByName(moduleName, null);
+        checkArgument(moduleName != null && !moduleName.isEmpty());
+        return globalSchema.findModules(moduleName).stream().findFirst().orElse(null);
     }
 
-    public Module findModuleByName(final DOMMountPoint mountPoint, final String moduleName) {
-        Preconditions.checkArgument((moduleName != null) && (mountPoint != null));
+    public static Module findModuleByName(final DOMMountPoint mountPoint, final String moduleName) {
+        checkArgument(moduleName != null && mountPoint != null);
 
-        final SchemaContext mountPointSchema = mountPoint.getSchemaContext();
-        if (mountPointSchema == null) {
-            return null;
-        }
-
-        return mountPointSchema.findModuleByName(moduleName, null);
+        final EffectiveModelContext mountPointSchema = getModelContext(mountPoint);
+        return mountPointSchema == null ? null
+            : mountPointSchema.findModules(moduleName).stream().findFirst().orElse(null);
     }
 
-    public Module findModuleByNamespace(final URI namespace) {
+    public Module findModuleByNamespace(final XMLNamespace namespace) {
         checkPreconditions();
-        Preconditions.checkArgument(namespace != null);
-        return this.globalSchema.findModuleByNamespaceAndRevision(namespace, null);
+        checkArgument(namespace != null);
+        return globalSchema.findModules(namespace).stream().findFirst().orElse(null);
     }
 
-    public Module findModuleByNamespace(final DOMMountPoint mountPoint, final URI namespace) {
-        Preconditions.checkArgument((namespace != null) && (mountPoint != null));
-
-        final SchemaContext mountPointSchema = mountPoint.getSchemaContext();
-        if (mountPointSchema == null) {
-            return null;
-        }
+    public static Module findModuleByNamespace(final DOMMountPoint mountPoint, final XMLNamespace namespace) {
+        checkArgument(namespace != null && mountPoint != null);
 
-        return mountPointSchema.findModuleByNamespaceAndRevision(namespace, null);
+        final EffectiveModelContext mountPointSchema = getModelContext(mountPoint);
+        return mountPointSchema == null ? null
+            : mountPointSchema.findModules(namespace).stream().findFirst().orElse(null);
     }
 
-    public Module findModuleByNameAndRevision(final QName module) {
+    public Module findModuleByNameAndRevision(final String name, final Revision revision) {
         checkPreconditions();
-        Preconditions
-                .checkArgument((module != null) && (module.getLocalName() != null) && (module.getRevision() != null));
+        checkArgument(name != null && revision != null);
 
-        return this.globalSchema.findModuleByName(module.getLocalName(), module.getRevision());
+        return globalSchema.findModule(name, revision).orElse(null);
     }
 
-    public Module findModuleByNameAndRevision(final DOMMountPoint mountPoint, final QName module) {
+    public Module findModuleByNameAndRevision(final DOMMountPoint mountPoint, final String name,
+            final Revision revision) {
         checkPreconditions();
-        Preconditions
-                .checkArgument((module != null) && (module.getLocalName() != null) && (module.getRevision() != null)
-                && (mountPoint != null));
+        checkArgument(name != null && revision != null && mountPoint != null);
 
-        final SchemaContext schemaContext = mountPoint.getSchemaContext();
-        return schemaContext == null ? null : schemaContext.findModuleByName(module.getLocalName(),
-                module.getRevision());
+        final EffectiveModelContext schemaContext = getModelContext(mountPoint);
+        return schemaContext == null ? null : schemaContext.findModule(name, revision).orElse(null);
     }
 
     public DataNodeContainer getDataNodeContainerFor(final YangInstanceIdentifier path) {
@@ -255,13 +272,12 @@ public class ControllerContext implements SchemaContextListener {
         final Iterable<PathArgument> elements = path.getPathArguments();
         final PathArgument head = elements.iterator().next();
         final QName startQName = head.getNodeType();
-        final Module initialModule = this.globalSchema.findModuleByNamespaceAndRevision(startQName.getNamespace(),
-                startQName.getRevision());
+        final Module initialModule = globalSchema.findModule(startQName.getModule()).orElse(null);
         DataNodeContainer node = initialModule;
         for (final PathArgument element : elements) {
             final QName _nodeType = element.getNodeType();
             final DataSchemaNode potentialNode = childByQName(node, _nodeType);
-            if ((potentialNode == null) || !isListOrContainer(potentialNode)) {
+            if (potentialNode == null || !isListOrContainer(potentialNode)) {
                 return null;
             }
             node = (DataNodeContainer) potentialNode;
@@ -277,20 +293,19 @@ public class ControllerContext implements SchemaContextListener {
         final StringBuilder builder = new StringBuilder();
         final PathArgument head = elements.iterator().next();
         final QName startQName = head.getNodeType();
-        final SchemaContext schemaContext;
+        final EffectiveModelContext schemaContext;
         if (mount != null) {
-            schemaContext = mount.getSchemaContext();
+            schemaContext = getModelContext(mount);
         } else {
-            schemaContext = this.globalSchema;
+            schemaContext = globalSchema;
         }
-        final Module initialModule = schemaContext.findModuleByNamespaceAndRevision(startQName.getNamespace(),
-                startQName.getRevision());
+        final Module initialModule = schemaContext.findModule(startQName.getModule()).orElse(null);
         DataNodeContainer node = initialModule;
         for (final PathArgument element : elements) {
             if (!(element instanceof AugmentationIdentifier)) {
                 final QName _nodeType = element.getNodeType();
                 final DataSchemaNode potentialNode = childByQName(node, _nodeType);
-                if (!((element instanceof NodeIdentifier) && (potentialNode instanceof ListSchemaNode))
+                if ((!(element instanceof NodeIdentifier) || !(potentialNode instanceof ListSchemaNode))
                         && !(potentialNode instanceof ChoiceSchemaNode)) {
                     builder.append(convertToRestconfIdentifier(element, potentialNode, mount));
                     if (potentialNode instanceof DataNodeContainer) {
@@ -303,73 +318,62 @@ public class ControllerContext implements SchemaContextListener {
         return builder.toString();
     }
 
-    public String findModuleNameByNamespace(final URI namespace) {
+    public String findModuleNameByNamespace(final XMLNamespace namespace) {
         checkPreconditions();
 
         final Module module = this.findModuleByNamespace(namespace);
         return module == null ? null : module.getName();
     }
 
-    public String findModuleNameByNamespace(final DOMMountPoint mountPoint, final URI namespace) {
-        final Module module = this.findModuleByNamespace(mountPoint, namespace);
+    public static String findModuleNameByNamespace(final DOMMountPoint mountPoint, final XMLNamespace namespace) {
+        final Module module = findModuleByNamespace(mountPoint, namespace);
         return module == null ? null : module.getName();
     }
 
-    public URI findNamespaceByModuleName(final String moduleName) {
+    public XMLNamespace findNamespaceByModuleName(final String moduleName) {
         final Module module = this.findModuleByName(moduleName);
         return module == null ? null : module.getNamespace();
     }
 
-    public URI findNamespaceByModuleName(final DOMMountPoint mountPoint, final String moduleName) {
-        final Module module = this.findModuleByName(mountPoint, moduleName);
+    public static XMLNamespace findNamespaceByModuleName(final DOMMountPoint mountPoint, final String moduleName) {
+        final Module module = findModuleByName(mountPoint, moduleName);
         return module == null ? null : module.getNamespace();
     }
 
-    public Set<Module> getAllModules(final DOMMountPoint mountPoint) {
+    public Collection<? extends Module> getAllModules(final DOMMountPoint mountPoint) {
         checkPreconditions();
 
-        final SchemaContext schemaContext = mountPoint == null ? null : mountPoint.getSchemaContext();
+        final EffectiveModelContext schemaContext = mountPoint == null ? null : getModelContext(mountPoint);
         return schemaContext == null ? null : schemaContext.getModules();
     }
 
-    public Set<Module> getAllModules() {
+    public Collection<? extends Module> getAllModules() {
         checkPreconditions();
-        return this.globalSchema.getModules();
+        return globalSchema.getModules();
     }
 
-    private static CharSequence toRestconfIdentifier(final SchemaContext context, final QName qname) {
-        final Module schema = context.findModuleByNamespaceAndRevision(qname.getNamespace(), qname.getRevision());
+    private static String toRestconfIdentifier(final EffectiveModelContext context, final QName qname) {
+        final Module schema = context.findModule(qname.getModule()).orElse(null);
         return schema == null ? null : schema.getName() + ':' + qname.getLocalName();
     }
 
-    public CharSequence toRestconfIdentifier(final QName qname, final DOMMountPoint mount) {
-        final SchemaContext schema;
-        if (mount != null) {
-            schema = mount.getSchemaContext();
-        } else {
-            checkPreconditions();
-            schema = this.globalSchema;
-        }
-
-        return toRestconfIdentifier(schema, qname);
+    public String toRestconfIdentifier(final QName qname, final DOMMountPoint mountPoint) {
+        return mountPoint != null ? toRestconfIdentifier(getModelContext(mountPoint), qname)
+            : toRestconfIdentifier(qname);
     }
 
-    public CharSequence toRestconfIdentifier(final QName qname) {
+    public String toRestconfIdentifier(final QName qname) {
         checkPreconditions();
 
-        return toRestconfIdentifier(this.globalSchema, qname);
+        return toRestconfIdentifier(globalSchema, qname);
     }
 
-    public CharSequence toRestconfIdentifier(final DOMMountPoint mountPoint, final QName qname) {
-        if (mountPoint == null) {
-            return null;
-        }
-
-        return toRestconfIdentifier(mountPoint.getSchemaContext(), qname);
+    public static String toRestconfIdentifier(final DOMMountPoint mountPoint, final QName qname) {
+        return mountPoint == null ? null : toRestconfIdentifier(getModelContext(mountPoint), qname);
     }
 
     public Module getRestconfModule() {
-        return findModuleByNameAndRevision(RestConfModule.IETF_RESTCONF_QNAME);
+        return findModuleByNameAndRevision(Draft02.RestConfModule.NAME, Revision.of(Draft02.RestConfModule.REVISION));
     }
 
     public DataSchemaNode getRestconfModuleErrorsSchemaNode() {
@@ -378,9 +382,9 @@ public class ControllerContext implements SchemaContextListener {
             return null;
         }
 
-        final Set<GroupingDefinition> groupings = restconfModule.getGroupings();
+        final Collection<? extends GroupingDefinition> groupings = restconfModule.getGroupings();
 
-        final Iterable<GroupingDefinition> filteredGroups = Iterables.filter(groupings,
+        final Iterable<? extends GroupingDefinition> filteredGroups = Iterables.filter(groupings,
             g -> RestConfModule.ERRORS_GROUPING_SCHEMA_NODE.equals(g.getQName().getLocalName()));
 
         final GroupingDefinition restconfGrouping = Iterables.getFirst(filteredGroups, null);
@@ -401,8 +405,8 @@ public class ControllerContext implements SchemaContextListener {
             return null;
         }
 
-        final Set<GroupingDefinition> groupings = restconfModule.getGroupings();
-        final Iterable<GroupingDefinition> filteredGroups = Iterables.filter(groupings,
+        final Collection<? extends GroupingDefinition> groupings = restconfModule.getGroupings();
+        final Iterable<? extends GroupingDefinition> filteredGroups = Iterables.filter(groupings,
             g -> RestConfModule.RESTCONF_GROUPING_SCHEMA_NODE.equals(g.getQName().getLocalName()));
         final GroupingDefinition restconfGrouping = Iterables.getFirst(filteredGroups, null);
 
@@ -412,33 +416,33 @@ public class ControllerContext implements SchemaContextListener {
 
         if (RestConfModule.OPERATIONS_CONTAINER_SCHEMA_NODE.equals(schemaNodeName)) {
             final List<DataSchemaNode> instances = findInstanceDataChildrenByName(
-                    ((DataNodeContainer) restconfContainer), RestConfModule.OPERATIONS_CONTAINER_SCHEMA_NODE);
+                    (DataNodeContainer) restconfContainer, RestConfModule.OPERATIONS_CONTAINER_SCHEMA_NODE);
             return Iterables.getFirst(instances, null);
         } else if (RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE.equals(schemaNodeName)) {
             final List<DataSchemaNode> instances = findInstanceDataChildrenByName(
-                    ((DataNodeContainer) restconfContainer), RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
+                    (DataNodeContainer) restconfContainer, RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
             return Iterables.getFirst(instances, null);
         } else if (RestConfModule.STREAM_LIST_SCHEMA_NODE.equals(schemaNodeName)) {
             List<DataSchemaNode> instances = findInstanceDataChildrenByName(
-                    ((DataNodeContainer) restconfContainer), RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
+                    (DataNodeContainer) restconfContainer, RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
             final DataSchemaNode modules = Iterables.getFirst(instances, null);
-            instances = findInstanceDataChildrenByName(((DataNodeContainer) modules),
+            instances = findInstanceDataChildrenByName((DataNodeContainer) modules,
                     RestConfModule.STREAM_LIST_SCHEMA_NODE);
             return Iterables.getFirst(instances, null);
         } else if (RestConfModule.MODULES_CONTAINER_SCHEMA_NODE.equals(schemaNodeName)) {
             final List<DataSchemaNode> instances = findInstanceDataChildrenByName(
-                    ((DataNodeContainer) restconfContainer), RestConfModule.MODULES_CONTAINER_SCHEMA_NODE);
+                    (DataNodeContainer) restconfContainer, RestConfModule.MODULES_CONTAINER_SCHEMA_NODE);
             return Iterables.getFirst(instances, null);
         } else if (RestConfModule.MODULE_LIST_SCHEMA_NODE.equals(schemaNodeName)) {
             List<DataSchemaNode> instances = findInstanceDataChildrenByName(
-                    ((DataNodeContainer) restconfContainer), RestConfModule.MODULES_CONTAINER_SCHEMA_NODE);
+                    (DataNodeContainer) restconfContainer, RestConfModule.MODULES_CONTAINER_SCHEMA_NODE);
             final DataSchemaNode modules = Iterables.getFirst(instances, null);
-            instances = findInstanceDataChildrenByName(((DataNodeContainer) modules),
+            instances = findInstanceDataChildrenByName((DataNodeContainer) modules,
                     RestConfModule.MODULE_LIST_SCHEMA_NODE);
             return Iterables.getFirst(instances, null);
         } else if (RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE.equals(schemaNodeName)) {
             final List<DataSchemaNode> instances = findInstanceDataChildrenByName(
-                    ((DataNodeContainer) restconfContainer), RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
+                    (DataNodeContainer) restconfContainer, RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
             return Iterables.getFirst(instances, null);
         }
 
@@ -446,7 +450,7 @@ public class ControllerContext implements SchemaContextListener {
     }
 
     private static DataSchemaNode childByQName(final ChoiceSchemaNode container, final QName name) {
-        for (final ChoiceCaseNode caze : container.getCases()) {
+        for (final CaseSchemaNode caze : container.getCases()) {
             final DataSchemaNode ret = childByQName(caze, name);
             if (ret != null) {
                 return ret;
@@ -456,8 +460,8 @@ public class ControllerContext implements SchemaContextListener {
         return null;
     }
 
-    private static DataSchemaNode childByQName(final ChoiceCaseNode container, final QName name) {
-        return container.getDataChildByName(name);
+    private static DataSchemaNode childByQName(final CaseSchemaNode container, final QName name) {
+        return container.dataChildByName(name);
     }
 
     private static DataSchemaNode childByQName(final ContainerSchemaNode container, final QName name) {
@@ -478,8 +482,8 @@ public class ControllerContext implements SchemaContextListener {
 
 
     private static DataSchemaNode childByQName(final Object container, final QName name) {
-        if (container instanceof ChoiceCaseNode) {
-            return childByQName((ChoiceCaseNode) container, name);
+        if (container instanceof CaseSchemaNode) {
+            return childByQName((CaseSchemaNode) container, name);
         } else if (container instanceof ChoiceSchemaNode) {
             return childByQName((ChoiceSchemaNode) container, name);
         } else if (container instanceof ContainerSchemaNode) {
@@ -492,16 +496,16 @@ public class ControllerContext implements SchemaContextListener {
             return childByQName((Module) container, name);
         } else {
             throw new IllegalArgumentException("Unhandled parameter types: "
-                    + Arrays.<Object>asList(container, name).toString());
+                    + Arrays.asList(container, name).toString());
         }
     }
 
     private static DataSchemaNode dataNodeChildByQName(final DataNodeContainer container, final QName name) {
-        final DataSchemaNode ret = container.getDataChildByName(name);
+        final DataSchemaNode ret = container.dataChildByName(name);
         if (ret == null) {
             for (final DataSchemaNode node : container.getChildNodes()) {
-                if ((node instanceof ChoiceSchemaNode)) {
-                    final ChoiceSchemaNode choiceNode = ((ChoiceSchemaNode) node);
+                if (node instanceof ChoiceSchemaNode) {
+                    final ChoiceSchemaNode choiceNode = (ChoiceSchemaNode) node;
                     final DataSchemaNode childByQName = childByQName(choiceNode, name);
                     if (childByQName != null) {
                         return childByQName;
@@ -512,28 +516,34 @@ public class ControllerContext implements SchemaContextListener {
         return ret;
     }
 
-    private static String toUriString(final Object object, final LeafSchemaNode leafNode, final DOMMountPoint mount)
+    private String toUriString(final Object object, final LeafSchemaNode leafNode, final DOMMountPoint mount)
             throws UnsupportedEncodingException {
-        final Codec<Object, Object> codec = RestCodec.from(leafNode.getType(), mount);
-        // FIXME: UrlEncoder looks up a well-known charset, we need something that will use it directly
-        return object == null ? "" : URLEncoder.encode(codec.serialize(object).toString(), URI_ENCODING_CHARSET.name());
+        final IllegalArgumentCodec<Object, Object> codec = RestCodec.from(leafNode.getType(), mount, this);
+        return object == null ? "" : URLEncoder.encode(codec.serialize(object).toString(), StandardCharsets.UTF_8);
     }
 
-    private InstanceIdentifierContext<?> collectPathArguments(final InstanceIdentifierBuilder builder,
+    @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification = "Unrecognised NullableDecl")
+    private InstanceIdentifierContext collectPathArguments(final InstanceIdentifierBuilder builder,
             final List<String> strings, final DataNodeContainer parentNode, final DOMMountPoint mountPoint,
             final boolean returnJustMountPoint) {
-        Preconditions.<List<String>>checkNotNull(strings);
+        requireNonNull(strings);
 
         if (parentNode == null) {
             return null;
         }
 
         if (strings.isEmpty()) {
-            return createContext(builder.build(), ((DataSchemaNode) parentNode),
-                mountPoint,mountPoint != null ? mountPoint.getSchemaContext() : this.globalSchema);
+            return createContext(builder.build(), (DataSchemaNode) parentNode, mountPoint,
+                mountPoint != null ? getModelContext(mountPoint) : globalSchema);
         }
 
         final String head = strings.iterator().next();
+
+        if (head.isEmpty()) {
+            final List<String> remaining = strings.subList(1, strings.size());
+            return collectPathArguments(builder, remaining, parentNode, mountPoint, returnJustMountPoint);
+        }
+
         final String nodeName = toNodeName(head);
         final String moduleName = toModuleName(head);
 
@@ -545,30 +555,30 @@ public class ControllerContext implements SchemaContextListener {
                             ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED);
                 }
 
-                if (this.mountService == null) {
+                if (mountService == null) {
                     throw new RestconfDocumentedException(
                             "MountService was not found. Finding behind mount points does not work.",
                             ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED);
                 }
 
-                final YangInstanceIdentifier partialPath = this.dataNormalizer.toNormalized(builder.build());
-                final Optional<DOMMountPoint> mountOpt = this.mountService.getMountPoint(partialPath);
-                if (!mountOpt.isPresent()) {
+                final YangInstanceIdentifier partialPath = dataNormalizer.toNormalized(builder.build());
+                final Optional<DOMMountPoint> mountOpt = mountService.getMountPoint(partialPath);
+                if (mountOpt.isEmpty()) {
                     LOG.debug("Instance identifier to missing mount point: {}", partialPath);
                     throw new RestconfDocumentedException("Mount point does not exist.", ErrorType.PROTOCOL,
                             ErrorTag.DATA_MISSING);
                 }
                 final DOMMountPoint mount = mountOpt.get();
 
-                final SchemaContext mountPointSchema = mount.getSchemaContext();
+                final EffectiveModelContext mountPointSchema = getModelContext(mount);
                 if (mountPointSchema == null) {
                     throw new RestconfDocumentedException("Mount point does not contain any schema with modules.",
                             ErrorType.APPLICATION, ErrorTag.UNKNOWN_ELEMENT);
                 }
 
-                if (returnJustMountPoint || (strings.size() == 1)) {
-                    final YangInstanceIdentifier instance = YangInstanceIdentifier.builder().build();
-                    return new InstanceIdentifierContext<>(instance, mountPointSchema, mount,mountPointSchema);
+                if (returnJustMountPoint || strings.size() == 1) {
+                    return new InstanceIdentifierContext(YangInstanceIdentifier.empty(), mountPointSchema, mount,
+                        mountPointSchema);
                 }
 
                 final String moduleNameBehindMountPoint = toModuleName(strings.get(1));
@@ -578,30 +588,30 @@ public class ControllerContext implements SchemaContextListener {
                             ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
                 }
 
-                final Module moduleBehindMountPoint =
-                        mountPointSchema.findModuleByName(moduleNameBehindMountPoint, null);
-                if (moduleBehindMountPoint == null) {
+                final Iterator<? extends Module> it = mountPointSchema.findModules(moduleNameBehindMountPoint)
+                        .iterator();
+                if (!it.hasNext()) {
                     throw new RestconfDocumentedException("\"" + moduleNameBehindMountPoint
                             + "\" module does not exist in mount point.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT);
                 }
 
                 final List<String> subList = strings.subList(1, strings.size());
-                return collectPathArguments(YangInstanceIdentifier.builder(), subList, moduleBehindMountPoint, mount,
+                return collectPathArguments(YangInstanceIdentifier.builder(), subList, it.next(), mount,
                         returnJustMountPoint);
             }
 
             Module module = null;
             if (mountPoint == null) {
                 checkPreconditions();
-                module = this.globalSchema.findModuleByName(moduleName, null);
+                module = globalSchema.findModules(moduleName).stream().findFirst().orElse(null);
                 if (module == null) {
                     throw new RestconfDocumentedException("\"" + moduleName + "\" module does not exist.",
                             ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT);
                 }
             } else {
-                final SchemaContext schemaContext = mountPoint.getSchemaContext();
+                final EffectiveModelContext schemaContext = getModelContext(mountPoint);
                 if (schemaContext != null) {
-                    module = schemaContext.findModuleByName(moduleName, null);
+                    module = schemaContext.findModules(moduleName).stream().findFirst().orElse(null);
                 } else {
                     module = null;
                 }
@@ -613,18 +623,17 @@ public class ControllerContext implements SchemaContextListener {
 
             targetNode = findInstanceDataChildByNameAndNamespace(parentNode, nodeName, module.getNamespace());
 
-            if ((targetNode == null) && (parentNode instanceof Module)) {
+            if (targetNode == null && parentNode instanceof Module) {
                 final RpcDefinition rpc;
                 if (mountPoint == null) {
-                    rpc = ControllerContext.getInstance().getRpcDefinition(head, module.getRevision());
+                    rpc = getRpcDefinition(head, module.getRevision());
                 } else {
                     final String rpcName = toNodeName(head);
-                    ControllerContext.getInstance();
-                    rpc = ControllerContext.getRpcDefinition(module, rpcName);
+                    rpc = getRpcDefinition(module, rpcName);
                 }
                 if (rpc != null) {
-                    return new InstanceIdentifierContext<>(builder.build(), rpc, mountPoint,
-                            mountPoint != null ? mountPoint.getSchemaContext() : this.globalSchema);
+                    return new InstanceIdentifierContext(builder.build(), rpc, mountPoint,
+                            mountPoint != null ? getModelContext(mountPoint) : globalSchema);
                 }
             }
 
@@ -665,10 +674,10 @@ public class ControllerContext implements SchemaContextListener {
         }
 
         int consumed = 1;
-        if ((targetNode instanceof ListSchemaNode)) {
-            final ListSchemaNode listNode = ((ListSchemaNode) targetNode);
+        if (targetNode instanceof ListSchemaNode) {
+            final ListSchemaNode listNode = (ListSchemaNode) targetNode;
             final int keysSize = listNode.getKeyDefinition().size();
-            if ((strings.size() - consumed) < keysSize) {
+            if (strings.size() - consumed < keysSize) {
                 throw new RestconfDocumentedException("Missing key for list \"" + listNode.getQName().getLocalName()
                         + "\".", ErrorType.PROTOCOL, ErrorTag.DATA_MISSING);
             }
@@ -696,25 +705,26 @@ public class ControllerContext implements SchemaContextListener {
             builder.node(targetNode.getQName());
         }
 
-        if ((targetNode instanceof DataNodeContainer)) {
+        if (targetNode instanceof DataNodeContainer) {
             final List<String> remaining = strings.subList(consumed, strings.size());
-            return collectPathArguments(builder, remaining, ((DataNodeContainer) targetNode), mountPoint,
+            return collectPathArguments(builder, remaining, (DataNodeContainer) targetNode, mountPoint,
                     returnJustMountPoint);
         }
 
         return createContext(builder.build(), targetNode, mountPoint,
-            mountPoint != null ? mountPoint.getSchemaContext() : this.globalSchema);
+            mountPoint != null ? getModelContext(mountPoint) : globalSchema);
     }
 
-    private static InstanceIdentifierContext<?> createContext(final YangInstanceIdentifier instance,
-            final DataSchemaNode dataSchemaNode, final DOMMountPoint mountPoint, final SchemaContext schemaContext) {
+    private static InstanceIdentifierContext createContext(final YangInstanceIdentifier instance,
+            final DataSchemaNode dataSchemaNode, final DOMMountPoint mountPoint,
+            final EffectiveModelContext schemaContext) {
         final YangInstanceIdentifier instanceIdentifier = new DataNormalizer(schemaContext).toNormalized(instance);
-        return new InstanceIdentifierContext<>(instanceIdentifier, dataSchemaNode, mountPoint, schemaContext);
+        return new InstanceIdentifierContext(instanceIdentifier, dataSchemaNode, mountPoint, schemaContext);
     }
 
     public static DataSchemaNode findInstanceDataChildByNameAndNamespace(final DataNodeContainer container,
-            final String name, final URI namespace) {
-        Preconditions.checkNotNull(namespace);
+            final String name, final XMLNamespace namespace) {
+        requireNonNull(namespace);
 
         final Iterable<DataSchemaNode> result = Iterables.filter(findInstanceDataChildrenByName(container, name),
             node -> namespace.equals(node.getQName().getNamespace()));
@@ -723,18 +733,16 @@ public class ControllerContext implements SchemaContextListener {
 
     public static List<DataSchemaNode> findInstanceDataChildrenByName(final DataNodeContainer container,
             final String name) {
-        Preconditions.checkNotNull(container);
-        Preconditions.checkNotNull(name);
-
         final List<DataSchemaNode> instantiatedDataNodeContainers = new ArrayList<>();
-        collectInstanceDataNodeContainers(instantiatedDataNodeContainers, container, name);
+        collectInstanceDataNodeContainers(instantiatedDataNodeContainers, requireNonNull(container),
+            requireNonNull(name));
         return instantiatedDataNodeContainers;
     }
 
     private static void collectInstanceDataNodeContainers(final List<DataSchemaNode> potentialSchemaNodes,
             final DataNodeContainer container, final String name) {
 
-        final Iterable<DataSchemaNode> nodes = Iterables.filter(container.getChildNodes(),
+        final Iterable<? extends DataSchemaNode> nodes = Iterables.filter(container.getChildNodes(),
             node -> name.equals(node.getQName().getLocalName()));
 
         // Can't combine this loop with the filter above because the filter is
@@ -747,38 +755,37 @@ public class ControllerContext implements SchemaContextListener {
 
         final Iterable<ChoiceSchemaNode> choiceNodes = Iterables.filter(container.getChildNodes(),
             ChoiceSchemaNode.class);
-        final Iterable<Set<ChoiceCaseNode>> map = Iterables.transform(choiceNodes, ChoiceSchemaNode::getCases);
-        for (final ChoiceCaseNode caze : Iterables.concat(map)) {
+        final Iterable<Collection<? extends CaseSchemaNode>> map = Iterables.transform(choiceNodes,
+            ChoiceSchemaNode::getCases);
+        for (final CaseSchemaNode caze : Iterables.concat(map)) {
             collectInstanceDataNodeContainers(potentialSchemaNodes, caze, name);
         }
     }
 
     public static boolean isInstantiatedDataSchema(final DataSchemaNode node) {
-        return (node instanceof LeafSchemaNode) || (node instanceof LeafListSchemaNode)
-                || (node instanceof ContainerSchemaNode) || (node instanceof ListSchemaNode)
-                || (node instanceof AnyXmlSchemaNode);
+        return node instanceof LeafSchemaNode || node instanceof LeafListSchemaNode
+                || node instanceof ContainerSchemaNode || node instanceof ListSchemaNode
+                || node instanceof AnyxmlSchemaNode;
     }
 
     private void addKeyValue(final HashMap<QName, Object> map, final DataSchemaNode node, final String uriValue,
             final DOMMountPoint mountPoint) {
-        Preconditions.checkNotNull(uriValue);
-        Preconditions.checkArgument((node instanceof LeafSchemaNode));
+        checkArgument(node instanceof LeafSchemaNode);
 
-        final String urlDecoded = urlPathArgDecode(uriValue);
+        final EffectiveModelContext schemaContext = mountPoint == null ? globalSchema : getModelContext(mountPoint);
+        final String urlDecoded = urlPathArgDecode(requireNonNull(uriValue));
         TypeDefinition<?> typedef = ((LeafSchemaNode) node).getType();
         final TypeDefinition<?> baseType = RestUtil.resolveBaseTypeFrom(typedef);
         if (baseType instanceof LeafrefTypeDefinition) {
-            typedef = SchemaContextUtil.getBaseTypeForLeafRef((LeafrefTypeDefinition) baseType, this.globalSchema,
-                node);
+            typedef = SchemaInferenceStack.ofInstantiatedPath(schemaContext, node.getPath())
+                .resolveLeafref((LeafrefTypeDefinition) baseType);
         }
-        final Codec<Object, Object> codec = RestCodec.from(typedef, mountPoint);
+        final IllegalArgumentCodec<Object, Object> codec = RestCodec.from(typedef, mountPoint, this);
         Object decoded = codec.deserialize(urlDecoded);
         String additionalInfo = "";
         if (decoded == null) {
-            if ((typedef instanceof IdentityrefTypeDefinition)) {
-                final SchemaContext schemaContext =
-                        mountPoint == null ? this.globalSchema : mountPoint.getSchemaContext();
-                decoded = toQName(schemaContext, urlDecoded, null);
+            if (typedef instanceof IdentityrefTypeDefinition) {
+                decoded = toQName(schemaContext, urlDecoded);
                 additionalInfo =
                         "For key which is of type identityref it should be in format module_name:identity_name.";
             }
@@ -820,21 +827,35 @@ public class ControllerContext implements SchemaContextListener {
         return str.substring(idx + 1);
     }
 
-    private QName toQName(final SchemaContext schemaContext, final String name, final Date revisionDate) {
+    private QName toQName(final EffectiveModelContext schemaContext, final String name,
+            final Optional<Revision> revisionDate) {
         checkPreconditions();
         final String module = toModuleName(name);
         final String node = toNodeName(name);
-        final Module m = schemaContext.findModuleByName(module, revisionDate);
+        final Module m = schemaContext.findModule(module, revisionDate).orElse(null);
         return m == null ? null : QName.create(m.getQNameModule(), node);
     }
 
+    private QName toQName(final EffectiveModelContext schemaContext, final String name) {
+        checkPreconditions();
+        final String module = toModuleName(name);
+        final String node = toNodeName(name);
+        final Collection<? extends Module> modules = schemaContext.findModules(module);
+        return modules.isEmpty() ? null : QName.create(modules.iterator().next().getQNameModule(), node);
+    }
+
     private static boolean isListOrContainer(final DataSchemaNode node) {
-        return (node instanceof ListSchemaNode) || (node instanceof ContainerSchemaNode);
+        return node instanceof ListSchemaNode || node instanceof ContainerSchemaNode;
+    }
+
+    public RpcDefinition getRpcDefinition(final String name, final Optional<Revision> revisionDate) {
+        final QName validName = toQName(globalSchema, name, revisionDate);
+        return validName == null ? null : qnameToRpc.get().get(validName);
     }
 
-    public RpcDefinition getRpcDefinition(final String name, final Date revisionDate) {
-        final QName validName = toQName(this.globalSchema, name, revisionDate);
-        return validName == null ? null : this.qnameToRpc.get().get(validName);
+    public RpcDefinition getRpcDefinition(final String name) {
+        final QName validName = toQName(globalSchema, name);
+        return validName == null ? null : qnameToRpc.get().get(validName);
     }
 
     private static RpcDefinition getRpcDefinition(final Module module, final String rpcName) {
@@ -848,9 +869,9 @@ public class ControllerContext implements SchemaContextListener {
     }
 
     @Override
-    public void onGlobalContextUpdated(final SchemaContext context) {
+    public void onModelContextUpdated(final EffectiveModelContext context) {
         if (context != null) {
-            final Collection<RpcDefinition> defs = context.getOperations();
+            final Collection<? extends RpcDefinition> defs = context.getOperations();
             final Map<QName, RpcDefinition> newMap = new HashMap<>(defs.size());
 
             for (final RpcDefinition operation : defs) {
@@ -858,46 +879,35 @@ public class ControllerContext implements SchemaContextListener {
             }
 
             // FIXME: still not completely atomic
-            this.qnameToRpc.set(ImmutableMap.copyOf(newMap));
+            qnameToRpc.set(ImmutableMap.copyOf(newMap));
             setGlobalSchema(context);
         }
     }
 
-    public static List<String> urlPathArgsDecode(final Iterable<String> strings) {
-        try {
-            final List<String> decodedPathArgs = new ArrayList<>();
-            for (final String pathArg : strings) {
-                final String _decode = URLDecoder.decode(pathArg, URI_ENCODING_CHARSET.name());
-                decodedPathArgs.add(_decode);
-            }
-            return decodedPathArgs;
-        } catch (final UnsupportedEncodingException e) {
-            throw new RestconfDocumentedException("Invalid URL path '" + strings + "': " + e.getMessage(),
-                    ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
+    private static List<String> urlPathArgsDecode(final Iterable<String> strings) {
+        final List<String> decodedPathArgs = new ArrayList<>();
+        for (final String pathArg : strings) {
+            final String _decode = URLDecoder.decode(pathArg, StandardCharsets.UTF_8);
+            decodedPathArgs.add(_decode);
         }
+        return decodedPathArgs;
     }
 
-    public String urlPathArgDecode(final String pathArg) {
-        if (pathArg != null) {
-            try {
-                return URLDecoder.decode(pathArg, URI_ENCODING_CHARSET.name());
-            } catch (final UnsupportedEncodingException e) {
-                throw new RestconfDocumentedException("Invalid URL path arg '" + pathArg + "': " + e.getMessage(),
-                        ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
-            }
+    static String urlPathArgDecode(final String pathArg) {
+        if (pathArg == null) {
+            return null;
         }
-
-        return null;
+        return URLDecoder.decode(pathArg, StandardCharsets.UTF_8);
     }
 
     private CharSequence convertToRestconfIdentifier(final PathArgument argument, final DataSchemaNode node,
             final DOMMountPoint mount) {
         if (argument instanceof NodeIdentifier) {
             return convertToRestconfIdentifier((NodeIdentifier) argument, mount);
-        } else if ((argument instanceof NodeIdentifierWithPredicates) && (node instanceof ListSchemaNode)) {
+        } else if (argument instanceof NodeIdentifierWithPredicates && node instanceof ListSchemaNode) {
             return convertToRestconfIdentifierWithPredicates((NodeIdentifierWithPredicates) argument,
                 (ListSchemaNode) node, mount);
-        } else if ((argument != null) && (node != null)) {
+        } else if (argument != null && node != null) {
             throw new IllegalArgumentException("Conversion of generic path argument is not supported");
         } else {
             throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.asList(argument, node));
@@ -912,12 +922,8 @@ public class ControllerContext implements SchemaContextListener {
             final ListSchemaNode node, final DOMMountPoint mount) {
         final QName nodeType = argument.getNodeType();
         final CharSequence nodeIdentifier = this.toRestconfIdentifier(nodeType, mount);
-        final Map<QName, Object> keyValues = argument.getKeyValues();
 
-        final StringBuilder builder = new StringBuilder();
-        builder.append('/');
-        builder.append(nodeIdentifier);
-        builder.append('/');
+        final StringBuilder builder = new StringBuilder().append('/').append(nodeIdentifier).append('/');
 
         final List<QName> keyDefinition = node.getKeyDefinition();
         boolean hasElements = false;
@@ -930,12 +936,14 @@ public class ControllerContext implements SchemaContextListener {
                         builder.append('/');
                     }
 
+                    checkState(listChild instanceof LeafSchemaNode,
+                        "List key has to consist of leaves, not %s", listChild);
+
+                    final Object value = argument.getValue(key);
                     try {
-                        Preconditions.checkState(listChild instanceof LeafSchemaNode,
-                            "List key has to consist of leaves, not %s", listChild);
-                        builder.append(toUriString(keyValues.get(key), (LeafSchemaNode)listChild, mount));
+                        builder.append(toUriString(value, (LeafSchemaNode)listChild, mount));
                     } catch (final UnsupportedEncodingException e) {
-                        LOG.error("Error parsing URI: {}", keyValues.get(key), e);
+                        LOG.error("Error parsing URI: {}", value, e);
                         return null;
                     }
                     break;
@@ -948,7 +956,7 @@ public class ControllerContext implements SchemaContextListener {
 
     public YangInstanceIdentifier toNormalized(final YangInstanceIdentifier legacy) {
         try {
-            return this.dataNormalizer.toNormalized(legacy);
+            return dataNormalizer.toNormalized(legacy);
         } catch (final NullPointerException e) {
             throw new RestconfDocumentedException("Data normalizer isn't set. Normalization isn't possible", e);
         }
@@ -956,7 +964,7 @@ public class ControllerContext implements SchemaContextListener {
 
     public YangInstanceIdentifier toXpathRepresentation(final YangInstanceIdentifier instanceIdentifier) {
         try {
-            return this.dataNormalizer.toLegacy(instanceIdentifier);
+            return dataNormalizer.toLegacy(instanceIdentifier);
         } catch (final NullPointerException e) {
             throw new RestconfDocumentedException("Data normalizer isn't set. Normalization isn't possible", e);
         } catch (final DataNormalizationException e) {
@@ -967,15 +975,16 @@ public class ControllerContext implements SchemaContextListener {
     public boolean isNodeMixin(final YangInstanceIdentifier path) {
         final DataNormalizationOperation<?> operation;
         try {
-            operation = this.dataNormalizer.getOperation(path);
+            operation = dataNormalizer.getOperation(path);
         } catch (final DataNormalizationException e) {
             throw new RestconfDocumentedException("Data normalizer failed. Normalization isn't possible", e);
         }
         return operation.isMixin();
     }
 
-    public DataNormalizationOperation<?> getRootOperation() {
-        return this.dataNormalizer.getRootOperation();
+    private static EffectiveModelContext getModelContext(final DOMMountPoint mountPoint) {
+        return mountPoint.getService(DOMSchemaService.class)
+            .flatMap(svc -> Optional.ofNullable(svc.getGlobalContext()))
+            .orElse(null);
     }
-
 }