Use Optional.isEmpty()
[netconf.git] / restconf / restconf-nb-bierman02 / src / main / java / org / opendaylight / netconf / sal / restconf / impl / ControllerContext.java
index 39a61379eb4daaa4a139c18afd317172e6fedb09..1ff954517348d7cbade7e3cde0dc150fbc8ec755 100644 (file)
@@ -7,7 +7,10 @@
  */
 package org.opendaylight.netconf.sal.restconf.impl;
 
-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;
@@ -18,7 +21,6 @@ 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;
@@ -29,16 +31,12 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
-import java.util.Set;
 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.apache.aries.blueprint.annotation.service.Reference;
-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.mdsal.dom.api.DOMMountPoint;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
@@ -50,7 +48,7 @@ import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
 import org.opendaylight.restconf.common.util.RestUtil;
-import org.opendaylight.yangtools.concepts.Codec;
+import org.opendaylight.yangtools.concepts.IllegalArgumentCodec;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Revision;
@@ -60,12 +58,14 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceI
 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.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;
@@ -73,7 +73,6 @@ 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;
@@ -82,7 +81,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @Singleton
-public final class ControllerContext implements SchemaContextListener, Closeable {
+public final class ControllerContext implements EffectiveModelContextListener, Closeable {
     // FIXME: this should be in md-sal somewhere
     public static final String MOUNT = "yang-ext:mount";
 
@@ -94,16 +93,14 @@ public final class ControllerContext implements SchemaContextListener, Closeable
 
     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());
 
     private final DOMMountPointService mountService;
     private final DOMYangTextSourceProvider yangTextSourceProvider;
-    private final ListenerRegistration<SchemaContextListener> listenerRegistration;
-    private volatile SchemaContext globalSchema;
+    private final ListenerRegistration<?> listenerRegistration;
+    private volatile EffectiveModelContext globalSchema;
     private volatile DataNormalizer dataNormalizer;
 
     @Inject
@@ -112,7 +109,7 @@ public final class ControllerContext implements SchemaContextListener, Closeable
         this.mountService = mountService;
         this.yangTextSourceProvider = domSchemaService.getExtensions().getInstance(DOMYangTextSourceProvider.class);
 
-        onGlobalContextUpdated(schemaService.getGlobalContext());
+        onModelContextUpdated(schemaService.getGlobalContext());
         listenerRegistration = schemaService.registerSchemaContextListener(this);
     }
 
@@ -129,7 +126,7 @@ public final class ControllerContext implements SchemaContextListener, Closeable
         return new ControllerContext(schemaService, mountService, domSchemaService);
     }
 
-    private void setGlobalSchema(final SchemaContext globalSchema) {
+    private void setGlobalSchema(final EffectiveModelContext globalSchema) {
         this.globalSchema = globalSchema;
         this.dataNormalizer = new DataNormalizer(globalSchema);
     }
@@ -150,15 +147,15 @@ public final class ControllerContext implements SchemaContextListener, Closeable
         listenerRegistration.close();
     }
 
-    public void setSchemas(final SchemaContext schemas) {
-        onGlobalContextUpdated(schemas);
+    public void setSchemas(final EffectiveModelContext schemas) {
+        onModelContextUpdated(schemas);
     }
 
     public InstanceIdentifierContext<?> toInstanceIdentifier(final String restconfInstance) {
         return toIdentifier(restconfInstance, false);
     }
 
-    public SchemaContext getGlobalSchema() {
+    public EffectiveModelContext getGlobalSchema() {
         return this.globalSchema;
     }
 
@@ -171,7 +168,7 @@ public final class ControllerContext implements SchemaContextListener, Closeable
         checkPreconditions();
 
         if (restconfInstance == null) {
-            return new InstanceIdentifierContext<>(YangInstanceIdentifier.EMPTY, this.globalSchema, null,
+            return new InstanceIdentifierContext<>(YangInstanceIdentifier.empty(), this.globalSchema, null,
                     this.globalSchema);
         }
 
@@ -189,7 +186,7 @@ public final class ControllerContext implements SchemaContextListener, Closeable
         }
 
         final InstanceIdentifierBuilder builder = YangInstanceIdentifier.builder();
-        final Set<Module> latestModule = this.globalSchema.findModules(startModule);
+        final Collection<? extends Module> latestModule = this.globalSchema.findModules(startModule);
 
         if (latestModule.isEmpty()) {
             throw new RestconfDocumentedException("The module named '" + startModule + "' does not exist.",
@@ -230,14 +227,14 @@ public final class ControllerContext implements SchemaContextListener, Closeable
 
     public Module findModuleByName(final String moduleName) {
         checkPreconditions();
-        Preconditions.checkArgument(moduleName != null && !moduleName.isEmpty());
+        checkArgument(moduleName != null && !moduleName.isEmpty());
         return this.globalSchema.findModules(moduleName).stream().findFirst().orElse(null);
     }
 
     public Module findModuleByName(final DOMMountPoint mountPoint, final String moduleName) {
-        Preconditions.checkArgument(moduleName != null && mountPoint != null);
+        checkArgument(moduleName != null && mountPoint != null);
 
-        final SchemaContext mountPointSchema = mountPoint.getSchemaContext();
+        final SchemaContext mountPointSchema = getModelContext(mountPoint);
         if (mountPointSchema == null) {
             return null;
         }
@@ -247,14 +244,14 @@ public final class ControllerContext implements SchemaContextListener, Closeable
 
     public Module findModuleByNamespace(final URI namespace) {
         checkPreconditions();
-        Preconditions.checkArgument(namespace != null);
+        checkArgument(namespace != null);
         return this.globalSchema.findModules(namespace).stream().findFirst().orElse(null);
     }
 
     public Module findModuleByNamespace(final DOMMountPoint mountPoint, final URI namespace) {
-        Preconditions.checkArgument(namespace != null && mountPoint != null);
+        checkArgument(namespace != null && mountPoint != null);
 
-        final SchemaContext mountPointSchema = mountPoint.getSchemaContext();
+        final SchemaContext mountPointSchema = getModelContext(mountPoint);
         if (mountPointSchema == null) {
             return null;
         }
@@ -264,7 +261,7 @@ public final class ControllerContext implements SchemaContextListener, Closeable
 
     public Module findModuleByNameAndRevision(final String name, final Revision revision) {
         checkPreconditions();
-        Preconditions.checkArgument(name != null && revision != null);
+        checkArgument(name != null && revision != null);
 
         return this.globalSchema.findModule(name, revision).orElse(null);
     }
@@ -272,9 +269,9 @@ public final class ControllerContext implements SchemaContextListener, Closeable
     public Module findModuleByNameAndRevision(final DOMMountPoint mountPoint, final String name,
             final Revision revision) {
         checkPreconditions();
-        Preconditions.checkArgument(name != null && revision != null && mountPoint != null);
+        checkArgument(name != null && revision != null && mountPoint != null);
 
-        final SchemaContext schemaContext = mountPoint.getSchemaContext();
+        final SchemaContext schemaContext = getModelContext(mountPoint);
         return schemaContext == null ? null : schemaContext.findModule(name, revision).orElse(null);
     }
 
@@ -307,7 +304,7 @@ public final class ControllerContext implements SchemaContextListener, Closeable
         final QName startQName = head.getNodeType();
         final SchemaContext schemaContext;
         if (mount != null) {
-            schemaContext = mount.getSchemaContext();
+            schemaContext = getModelContext(mount);
         } else {
             schemaContext = this.globalSchema;
         }
@@ -317,7 +314,7 @@ public final class ControllerContext implements SchemaContextListener, Closeable
             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) {
@@ -352,14 +349,14 @@ public final class ControllerContext implements SchemaContextListener, Closeable
         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 SchemaContext 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();
     }
@@ -372,7 +369,7 @@ public final class ControllerContext implements SchemaContextListener, Closeable
     public CharSequence toRestconfIdentifier(final QName qname, final DOMMountPoint mount) {
         final SchemaContext schema;
         if (mount != null) {
-            schema = mount.getSchemaContext();
+            schema = getModelContext(mount);
         } else {
             checkPreconditions();
             schema = this.globalSchema;
@@ -392,7 +389,7 @@ public final class ControllerContext implements SchemaContextListener, Closeable
             return null;
         }
 
-        return toRestconfIdentifier(mountPoint.getSchemaContext(), qname);
+        return toRestconfIdentifier(getModelContext(mountPoint), qname);
     }
 
     public Module getRestconfModule() {
@@ -405,9 +402,9 @@ public final class ControllerContext implements SchemaContextListener, Closeable
             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);
@@ -428,8 +425,8 @@ public final class ControllerContext implements SchemaContextListener, Closeable
             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);
 
@@ -473,7 +470,7 @@ public final class ControllerContext implements SchemaContextListener, Closeable
     }
 
     private static DataSchemaNode childByQName(final ChoiceSchemaNode container, final QName name) {
-        for (final CaseSchemaNode caze : container.getCases().values()) {
+        for (final CaseSchemaNode caze : container.getCases()) {
             final DataSchemaNode ret = childByQName(caze, name);
             if (ret != null) {
                 return ret;
@@ -541,24 +538,23 @@ public final class ControllerContext implements SchemaContextListener, Closeable
 
     private String toUriString(final Object object, final LeafSchemaNode leafNode, final DOMMountPoint mount)
             throws UnsupportedEncodingException {
-        final Codec<Object, Object> codec = RestCodec.from(leafNode.getType(), mount, this);
-        // 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);
     }
 
     @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.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) : this.globalSchema);
         }
 
         final String head = strings.iterator().next();
@@ -587,14 +583,14 @@ public final class ControllerContext implements SchemaContextListener, Closeable
 
                 final YangInstanceIdentifier partialPath = this.dataNormalizer.toNormalized(builder.build());
                 final Optional<DOMMountPoint> mountOpt = this.mountService.getMountPoint(partialPath);
-                if (!mountOpt.isPresent()) {
+                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);
@@ -602,7 +598,7 @@ public final class ControllerContext implements SchemaContextListener, Closeable
 
                 if (returnJustMountPoint || strings.size() == 1) {
                     final YangInstanceIdentifier instance = YangInstanceIdentifier.builder().build();
-                    return new InstanceIdentifierContext<>(instance, mountPointSchema, mount,mountPointSchema);
+                    return new InstanceIdentifierContext<>(instance, mountPointSchema, mount, mountPointSchema);
                 }
 
                 final String moduleNameBehindMountPoint = toModuleName(strings.get(1));
@@ -612,7 +608,8 @@ public final class ControllerContext implements SchemaContextListener, Closeable
                             ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
                 }
 
-                final Iterator<Module> it = mountPointSchema.findModules(moduleNameBehindMountPoint).iterator();
+                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);
@@ -632,7 +629,7 @@ public final class ControllerContext implements SchemaContextListener, Closeable
                             ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT);
                 }
             } else {
-                final SchemaContext schemaContext = mountPoint.getSchemaContext();
+                final EffectiveModelContext schemaContext = getModelContext(mountPoint);
                 if (schemaContext != null) {
                     module = schemaContext.findModules(moduleName).stream().findFirst().orElse(null);
                 } else {
@@ -656,7 +653,7 @@ public final class ControllerContext implements SchemaContextListener, Closeable
                 }
                 if (rpc != null) {
                     return new InstanceIdentifierContext<>(builder.build(), rpc, mountPoint,
-                            mountPoint != null ? mountPoint.getSchemaContext() : this.globalSchema);
+                            mountPoint != null ? getModelContext(mountPoint) : this.globalSchema);
                 }
             }
 
@@ -735,18 +732,19 @@ public final class ControllerContext implements SchemaContextListener, Closeable
         }
 
         return createContext(builder.build(), targetNode, mountPoint,
-            mountPoint != null ? mountPoint.getSchemaContext() : this.globalSchema);
+            mountPoint != null ? getModelContext(mountPoint) : this.globalSchema);
     }
 
     private static InstanceIdentifierContext<?> createContext(final YangInstanceIdentifier instance,
-            final DataSchemaNode dataSchemaNode, final DOMMountPoint mountPoint, final SchemaContext schemaContext) {
+            final DataSchemaNode dataSchemaNode, final DOMMountPoint mountPoint,
+            final EffectiveModelContext schemaContext) {
         final YangInstanceIdentifier instanceIdentifier = new DataNormalizer(schemaContext).toNormalized(instance);
         return new InstanceIdentifierContext<>(instanceIdentifier, dataSchemaNode, mountPoint, schemaContext);
     }
 
     public static DataSchemaNode findInstanceDataChildByNameAndNamespace(final DataNodeContainer container,
             final String name, final URI namespace) {
-        Preconditions.checkNotNull(namespace);
+        requireNonNull(namespace);
 
         final Iterable<DataSchemaNode> result = Iterables.filter(findInstanceDataChildrenByName(container, name),
             node -> namespace.equals(node.getQName().getNamespace()));
@@ -755,18 +753,16 @@ public final class ControllerContext implements SchemaContextListener, Closeable
 
     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
@@ -779,8 +775,8 @@ public final class ControllerContext implements SchemaContextListener, Closeable
 
         final Iterable<ChoiceSchemaNode> choiceNodes = Iterables.filter(container.getChildNodes(),
             ChoiceSchemaNode.class);
-        final Iterable<Collection<CaseSchemaNode>> map = Iterables.transform(choiceNodes,
-            choice -> choice.getCases().values());
+        final Iterable<Collection<? extends CaseSchemaNode>> map = Iterables.transform(choiceNodes,
+            ChoiceSchemaNode::getCases);
         for (final CaseSchemaNode caze : Iterables.concat(map)) {
             collectInstanceDataNodeContainers(potentialSchemaNodes, caze, name);
         }
@@ -789,22 +785,21 @@ public final class ControllerContext implements SchemaContextListener, Closeable
     public static boolean isInstantiatedDataSchema(final DataSchemaNode node) {
         return node instanceof LeafSchemaNode || node instanceof LeafListSchemaNode
                 || node instanceof ContainerSchemaNode || node instanceof ListSchemaNode
-                || node instanceof AnyXmlSchemaNode;
+                || 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 SchemaContext schemaContext = mountPoint == null ? this.globalSchema : mountPoint.getSchemaContext();
-        final String urlDecoded = urlPathArgDecode(uriValue);
+        final SchemaContext schemaContext = mountPoint == null ? this.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, schemaContext, node);
         }
-        final Codec<Object, Object> codec = RestCodec.from(typedef, mountPoint, this);
+        final IllegalArgumentCodec<Object, Object> codec = RestCodec.from(typedef, mountPoint, this);
         Object decoded = codec.deserialize(urlDecoded);
         String additionalInfo = "";
         if (decoded == null) {
@@ -852,7 +847,7 @@ public final class ControllerContext implements SchemaContextListener, Closeable
     }
 
     private QName toQName(final SchemaContext schemaContext, final String name,
-            final java.util.Optional<Revision> revisionDate) {
+            final Optional<Revision> revisionDate) {
         checkPreconditions();
         final String module = toModuleName(name);
         final String node = toNodeName(name);
@@ -864,7 +859,7 @@ public final class ControllerContext implements SchemaContextListener, Closeable
         checkPreconditions();
         final String module = toModuleName(name);
         final String node = toNodeName(name);
-        final Set<Module> modules = schemaContext.findModules(module);
+        final Collection<? extends Module> modules = schemaContext.findModules(module);
         return modules.isEmpty() ? null : QName.create(modules.iterator().next().getQNameModule(), node);
     }
 
@@ -872,7 +867,7 @@ public final class ControllerContext implements SchemaContextListener, Closeable
         return node instanceof ListSchemaNode || node instanceof ContainerSchemaNode;
     }
 
-    public RpcDefinition getRpcDefinition(final String name, final java.util.Optional<Revision> revisionDate) {
+    public RpcDefinition getRpcDefinition(final String name, final Optional<Revision> revisionDate) {
         final QName validName = toQName(this.globalSchema, name, revisionDate);
         return validName == null ? null : this.qnameToRpc.get().get(validName);
     }
@@ -893,9 +888,9 @@ public final class ControllerContext implements SchemaContextListener, Closeable
     }
 
     @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) {
@@ -908,31 +903,20 @@ public final class ControllerContext implements SchemaContextListener, Closeable
         }
     }
 
-    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, e);
+    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, e);
-            }
+    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,
@@ -957,12 +941,8 @@ public final class ControllerContext implements SchemaContextListener, Closeable
             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;
@@ -975,12 +955,14 @@ public final class ControllerContext implements SchemaContextListener, Closeable
                         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;
@@ -1019,7 +1001,9 @@ public final class ControllerContext implements SchemaContextListener, Closeable
         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);
     }
 }