X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2FControllerContext.java;h=93e6a2c0e98504e169703423837177078992c2a4;hp=16bbf9a4b144dc0e522db765cfc4755e2efde28b;hb=46751de4454b9a6f5cf73db39f90f0189ceae986;hpb=35ac0155c164ead34628292057008bd6e3a1ffb5 diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java index 16bbf9a4b1..93e6a2c0e9 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java @@ -9,15 +9,13 @@ package org.opendaylight.controller.sal.restconf.impl; import com.google.common.base.Function; import com.google.common.base.Objects; +import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.base.Predicate; import com.google.common.base.Splitter; import com.google.common.base.Strings; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; - import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URLDecoder; @@ -29,24 +27,27 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; - import javax.ws.rs.core.Response.Status; - -import org.opendaylight.controller.sal.core.api.mount.MountInstance; -import org.opendaylight.controller.sal.core.api.mount.MountService; +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.controller.sal.rest.api.Draft02; import org.opendaylight.controller.sal.rest.impl.RestUtil; import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag; import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType; import org.opendaylight.yangtools.concepts.Codec; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.InstanceIdentifierBuilder; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifier; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifierWithPredicates; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +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.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode; import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; import org.opendaylight.yangtools.yang.model.api.ChoiceNode; @@ -83,21 +84,20 @@ public class ControllerContext implements SchemaContextListener { private static final Splitter SLASH_SPLITTER = Splitter.on('/'); - private final BiMap uriToModuleName = HashBiMap. create(); - - private final Map moduleNameToUri = uriToModuleName.inverse(); - private final AtomicReference> qnameToRpc = new AtomicReference<>(Collections.emptyMap()); private volatile SchemaContext globalSchema; - private volatile MountService mountService; + private volatile DOMMountPointService mountService; + + private DataNormalizer dataNormalizer; public void setGlobalSchema(final SchemaContext globalSchema) { this.globalSchema = globalSchema; + this.dataNormalizer = new DataNormalizer(globalSchema); } - public void setMountService(final MountService mountService) { + public void setMountService(final DOMMountPointService mountService) { this.mountService = mountService; } @@ -142,8 +142,8 @@ public class ControllerContext implements SchemaContextListener { ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE); } - InstanceIdentifierBuilder builder = InstanceIdentifier.builder(); - Module latestModule = this.getLatestModule(globalSchema, startModule); + InstanceIdentifierBuilder builder = YangInstanceIdentifier.builder(); + Module latestModule = globalSchema.findModuleByName(startModule, null); InstanceIdWithSchemaNode iiWithSchemaNode = this.collectPathArguments(builder, pathArgs, latestModule, null, toMountPointIdentifier); @@ -175,59 +175,38 @@ public class ControllerContext implements SchemaContextListener { return list; } - - private Module getLatestModule(final SchemaContext schema, final String moduleName) { - Preconditions.checkArgument(schema != null); - Preconditions.checkArgument(moduleName != null && !moduleName.isEmpty()); - - Predicate filter = new Predicate() { - @Override - public boolean apply(final Module m) { - return Objects.equal(m.getName(), moduleName); - } - }; - - Iterable modules = Iterables.filter(schema.getModules(), filter); - return this.filterLatestModule(modules); - } - - private Module filterLatestModule(final Iterable modules) { - Module latestModule = modules.iterator().hasNext() ? modules.iterator().next() : null; - for (final Module module : modules) { - if (module.getRevision().after(latestModule.getRevision())) { - latestModule = module; - } - } - return latestModule; - } - public Module findModuleByName(final String moduleName) { this.checkPreconditions(); Preconditions.checkArgument(moduleName != null && !moduleName.isEmpty()); - return this.getLatestModule(globalSchema, moduleName); + return globalSchema.findModuleByName(moduleName, null); } - public Module findModuleByName(final MountInstance mountPoint, final String moduleName) { + public Module findModuleByName(final DOMMountPoint mountPoint, final String moduleName) { Preconditions.checkArgument(moduleName != null && mountPoint != null); final SchemaContext mountPointSchema = mountPoint.getSchemaContext(); - return mountPointSchema == null ? null : this.getLatestModule(mountPointSchema, moduleName); + if (mountPointSchema == null) { + return null; + } + + return mountPointSchema.findModuleByName(moduleName, null); } public Module findModuleByNamespace(final URI namespace) { this.checkPreconditions(); Preconditions.checkArgument(namespace != null); - - final Set moduleSchemas = globalSchema.findModuleByNamespace(namespace); - return moduleSchemas == null ? null : this.filterLatestModule(moduleSchemas); + return globalSchema.findModuleByNamespaceAndRevision(namespace, null); } - public Module findModuleByNamespace(final MountInstance mountPoint, final URI namespace) { + public Module findModuleByNamespace(final DOMMountPoint mountPoint, final URI namespace) { Preconditions.checkArgument(namespace != null && mountPoint != null); final SchemaContext mountPointSchema = mountPoint.getSchemaContext(); - Set moduleSchemas = mountPointSchema == null ? null : mountPointSchema.findModuleByNamespace(namespace); - return moduleSchemas == null ? null : this.filterLatestModule(moduleSchemas); + if (mountPointSchema == null) { + return null; + } + + return mountPointSchema.findModuleByNamespaceAndRevision(namespace, null); } public Module findModuleByNameAndRevision(final QName module) { @@ -237,7 +216,7 @@ public class ControllerContext implements SchemaContextListener { return globalSchema.findModuleByName(module.getLocalName(), module.getRevision()); } - public Module findModuleByNameAndRevision(final MountInstance mountPoint, final QName module) { + public Module findModuleByNameAndRevision(final DOMMountPoint mountPoint, final QName module) { this.checkPreconditions(); Preconditions.checkArgument(module != null && module.getLocalName() != null && module.getRevision() != null && mountPoint != null); @@ -247,7 +226,7 @@ public class ControllerContext implements SchemaContextListener { module.getRevision()); } - public DataNodeContainer getDataNodeContainerFor(final InstanceIdentifier path) { + public DataNodeContainer getDataNodeContainerFor(final YangInstanceIdentifier path) { this.checkPreconditions(); final Iterable elements = path.getPathArguments(); @@ -268,7 +247,7 @@ public class ControllerContext implements SchemaContextListener { return node; } - public String toFullRestconfIdentifier(final InstanceIdentifier path) { + public String toFullRestconfIdentifier(final YangInstanceIdentifier path) { this.checkPreconditions(); final Iterable elements = path.getPathArguments(); @@ -294,42 +273,26 @@ public class ControllerContext implements SchemaContextListener { public String findModuleNameByNamespace(final URI namespace) { this.checkPreconditions(); - String moduleName = this.uriToModuleName.get(namespace); - if (moduleName == null) { - final Module module = this.findModuleByNamespace(namespace); - if (module != null) { - moduleName = module.getName(); - this.uriToModuleName.put(namespace, moduleName); - } - } - - return moduleName; + final Module module = this.findModuleByNamespace(namespace); + return module == null ? null : module.getName(); } - public String findModuleNameByNamespace(final MountInstance mountPoint, final URI namespace) { + public String findModuleNameByNamespace(final DOMMountPoint mountPoint, final URI namespace) { final Module module = this.findModuleByNamespace(mountPoint, namespace); return module == null ? null : module.getName(); } public URI findNamespaceByModuleName(final String moduleName) { - URI namespace = this.moduleNameToUri.get(moduleName); - if (namespace == null) { - Module module = this.findModuleByName(moduleName); - if (module != null) { - URI _namespace = module.getNamespace(); - namespace = _namespace; - this.uriToModuleName.put(namespace, moduleName); - } - } - return namespace; + final Module module = this.findModuleByName(moduleName); + return module == null ? null : module.getNamespace(); } - public URI findNamespaceByModuleName(final MountInstance mountPoint, final String moduleName) { + public URI findNamespaceByModuleName(final DOMMountPoint mountPoint, final String moduleName) { final Module module = this.findModuleByName(mountPoint, moduleName); return module == null ? null : module.getNamespace(); } - public Set getAllModules(final MountInstance mountPoint) { + public Set getAllModules(final DOMMountPoint mountPoint) { this.checkPreconditions(); SchemaContext schemaContext = mountPoint == null ? null : mountPoint.getSchemaContext(); @@ -341,52 +304,36 @@ public class ControllerContext implements SchemaContextListener { return globalSchema.getModules(); } + private static final CharSequence toRestconfIdentifier(final SchemaContext context, final QName qname) { + final Module schema = context.findModuleByNamespaceAndRevision(qname.getNamespace(), qname.getRevision()); + return schema == null ? null : schema.getName() + ':' + qname.getLocalName(); + } + public CharSequence toRestconfIdentifier(final QName qname) { this.checkPreconditions(); - String module = this.uriToModuleName.get(qname.getNamespace()); - if (module == null) { - final Module moduleSchema = globalSchema.findModuleByNamespaceAndRevision(qname.getNamespace(), - qname.getRevision()); - if (moduleSchema == null) { - return null; - } - - this.uriToModuleName.put(qname.getNamespace(), moduleSchema.getName()); - module = moduleSchema.getName(); - } - - StringBuilder builder = new StringBuilder(); - builder.append(module); - builder.append(":"); - builder.append(qname.getLocalName()); - return builder.toString(); + return toRestconfIdentifier(globalSchema, qname); } - public CharSequence toRestconfIdentifier(final MountInstance mountPoint, final QName qname) { + public CharSequence toRestconfIdentifier(final DOMMountPoint mountPoint, final QName qname) { if (mountPoint == null) { return null; } - SchemaContext schemaContext = mountPoint.getSchemaContext(); - - final Module moduleSchema = schemaContext.findModuleByNamespaceAndRevision(qname.getNamespace(), - qname.getRevision()); - if (moduleSchema == null) { - return null; - } - - StringBuilder builder = new StringBuilder(); - builder.append(moduleSchema.getName()); - builder.append(":"); - builder.append(qname.getLocalName()); - return builder.toString(); + return toRestconfIdentifier(mountPoint.getSchemaContext(), qname); } public Module getRestconfModule() { return findModuleByNameAndRevision(Draft02.RestConfModule.IETF_RESTCONF_QNAME); } + private static final Predicate ERRORS_GROUPING_FILTER = new Predicate() { + @Override + public boolean apply(final GroupingDefinition g) { + return Draft02.RestConfModule.ERRORS_GROUPING_SCHEMA_NODE.equals(g.getQName().getLocalName()); + } + }; + public DataSchemaNode getRestconfModuleErrorsSchemaNode() { Module restconfModule = getRestconfModule(); if (restconfModule == null) { @@ -395,22 +342,22 @@ public class ControllerContext implements SchemaContextListener { Set groupings = restconfModule.getGroupings(); - final Predicate filter = new Predicate() { - @Override - public boolean apply(final GroupingDefinition g) { - return Objects.equal(g.getQName().getLocalName(), Draft02.RestConfModule.ERRORS_GROUPING_SCHEMA_NODE); - } - }; - - Iterable filteredGroups = Iterables.filter(groupings, filter); + Iterable filteredGroups = Iterables.filter(groupings, ERRORS_GROUPING_FILTER); final GroupingDefinition restconfGrouping = Iterables.getFirst(filteredGroups, null); - List instanceDataChildrenByName = this.findInstanceDataChildrenByName(restconfGrouping, + List instanceDataChildrenByName = findInstanceDataChildrenByName(restconfGrouping, Draft02.RestConfModule.ERRORS_CONTAINER_SCHEMA_NODE); return Iterables.getFirst(instanceDataChildrenByName, null); } + private static final Predicate GROUPING_FILTER = new Predicate() { + @Override + public boolean apply(final GroupingDefinition g) { + return Draft02.RestConfModule.RESTCONF_GROUPING_SCHEMA_NODE.equals(g.getQName().getLocalName()); + } + }; + public DataSchemaNode getRestconfModuleRestConfSchemaNode(final Module inRestconfModule, final String schemaNodeName) { Module restconfModule = inRestconfModule; if (restconfModule == null) { @@ -422,50 +369,41 @@ public class ControllerContext implements SchemaContextListener { } Set groupings = restconfModule.getGroupings(); - - final Predicate filter = new Predicate() { - @Override - public boolean apply(final GroupingDefinition g) { - return Objects.equal(g.getQName().getLocalName(), Draft02.RestConfModule.RESTCONF_GROUPING_SCHEMA_NODE); - } - }; - - Iterable filteredGroups = Iterables.filter(groupings, filter); - + Iterable filteredGroups = Iterables.filter(groupings, GROUPING_FILTER); final GroupingDefinition restconfGrouping = Iterables.getFirst(filteredGroups, null); - List instanceDataChildrenByName = this.findInstanceDataChildrenByName(restconfGrouping, + List instanceDataChildrenByName = findInstanceDataChildrenByName(restconfGrouping, Draft02.RestConfModule.RESTCONF_CONTAINER_SCHEMA_NODE); final DataSchemaNode restconfContainer = Iterables.getFirst(instanceDataChildrenByName, null); if (Objects.equal(schemaNodeName, Draft02.RestConfModule.OPERATIONS_CONTAINER_SCHEMA_NODE)) { - List instances = this.findInstanceDataChildrenByName( + List instances = findInstanceDataChildrenByName( ((DataNodeContainer) restconfContainer), Draft02.RestConfModule.OPERATIONS_CONTAINER_SCHEMA_NODE); return Iterables.getFirst(instances, null); } else if (Objects.equal(schemaNodeName, Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE)) { - List instances = this.findInstanceDataChildrenByName( + List instances = findInstanceDataChildrenByName( ((DataNodeContainer) restconfContainer), Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE); return Iterables.getFirst(instances, null); } else if (Objects.equal(schemaNodeName, Draft02.RestConfModule.STREAM_LIST_SCHEMA_NODE)) { - List instances = this.findInstanceDataChildrenByName( + List instances = findInstanceDataChildrenByName( ((DataNodeContainer) restconfContainer), Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE); final DataSchemaNode modules = Iterables.getFirst(instances, null); - instances = this.findInstanceDataChildrenByName(((DataNodeContainer) modules), + instances = findInstanceDataChildrenByName(((DataNodeContainer) modules), Draft02.RestConfModule.STREAM_LIST_SCHEMA_NODE); return Iterables.getFirst(instances, null); } else if (Objects.equal(schemaNodeName, Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE)) { - List instances = this.findInstanceDataChildrenByName( + List instances = findInstanceDataChildrenByName( ((DataNodeContainer) restconfContainer), Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE); return Iterables.getFirst(instances, null); } else if (Objects.equal(schemaNodeName, Draft02.RestConfModule.MODULE_LIST_SCHEMA_NODE)) { - List instances = this.findInstanceDataChildrenByName( + List instances = findInstanceDataChildrenByName( ((DataNodeContainer) restconfContainer), Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE); final DataSchemaNode modules = Iterables.getFirst(instances, null); - instances = this.findInstanceDataChildrenByName(((DataNodeContainer) modules), + instances = findInstanceDataChildrenByName(((DataNodeContainer) modules), Draft02.RestConfModule.MODULE_LIST_SCHEMA_NODE); return Iterables.getFirst(instances, null); } else if (Objects.equal(schemaNodeName, Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE)) { - List instances = this.findInstanceDataChildrenByName( + List instances = findInstanceDataChildrenByName( ((DataNodeContainer) restconfContainer), Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE); return Iterables.getFirst(instances, null); } @@ -508,9 +446,9 @@ public class ControllerContext implements SchemaContextListener { DataSchemaNode ret = container.getDataChildByName(name); if (ret == null) { for (final DataSchemaNode node : container.getChildNodes()) { - if ((node instanceof ChoiceCaseNode)) { - final ChoiceCaseNode caseNode = ((ChoiceCaseNode) node); - DataSchemaNode childByQName = ControllerContext.childByQName(caseNode, name); + if ((node instanceof ChoiceNode)) { + final ChoiceNode choiceNode = ((ChoiceNode) node); + DataSchemaNode childByQName = ControllerContext.childByQName(choiceNode, name); if (childByQName != null) { return childByQName; } @@ -525,7 +463,7 @@ public class ControllerContext implements SchemaContextListener { } private InstanceIdWithSchemaNode collectPathArguments(final InstanceIdentifierBuilder builder, - final List strings, final DataNodeContainer parentNode, final MountInstance mountPoint, + final List strings, final DataNodeContainer parentNode, final DOMMountPoint mountPoint, final boolean returnJustMountPoint) { Preconditions.> checkNotNull(strings); @@ -556,13 +494,14 @@ public class ControllerContext implements SchemaContextListener { ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED); } - final InstanceIdentifier partialPath = builder.toInstance(); - final MountInstance mount = mountService.getMountPoint(partialPath); - if (mount == null) { + final YangInstanceIdentifier partialPath = builder.toInstance(); + final Optional mountOpt = mountService.getMountPoint(partialPath); + if (!mountOpt.isPresent()) { LOG.debug("Instance identifier to missing mount point: {}", partialPath); throw new RestconfDocumentedException("Mount point does not exist.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT); } + DOMMountPoint mount = mountOpt.get(); final SchemaContext mountPointSchema = mount.getSchemaContext(); if (mountPointSchema == null) { @@ -571,12 +510,12 @@ public class ControllerContext implements SchemaContextListener { } if (returnJustMountPoint) { - InstanceIdentifier instance = InstanceIdentifier.builder().toInstance(); + YangInstanceIdentifier instance = YangInstanceIdentifier.builder().toInstance(); return new InstanceIdWithSchemaNode(instance, mountPointSchema, mount); } if (strings.size() == 1) { - InstanceIdentifier instance = InstanceIdentifier.builder().toInstance(); + YangInstanceIdentifier instance = YangInstanceIdentifier.builder().toInstance(); return new InstanceIdWithSchemaNode(instance, mountPointSchema, mount); } @@ -587,35 +526,38 @@ public class ControllerContext implements SchemaContextListener { ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE); } - final Module moduleBehindMountPoint = this - .getLatestModule(mountPointSchema, moduleNameBehindMountPoint); + final Module moduleBehindMountPoint = mountPointSchema.findModuleByName(moduleNameBehindMountPoint, null); if (moduleBehindMountPoint == null) { throw new RestconfDocumentedException("\"" + moduleName + "\" module does not exist in mount point.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT); } List subList = strings.subList(1, strings.size()); - return this.collectPathArguments(InstanceIdentifier.builder(), subList, moduleBehindMountPoint, mount, + return this.collectPathArguments(YangInstanceIdentifier.builder(), subList, moduleBehindMountPoint, mount, returnJustMountPoint); } Module module = null; if (mountPoint == null) { - module = this.getLatestModule(globalSchema, moduleName); + module = globalSchema.findModuleByName(moduleName, null); if (module == null) { throw new RestconfDocumentedException("\"" + moduleName + "\" module does not exist.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT); } } else { SchemaContext schemaContext = mountPoint.getSchemaContext(); - module = schemaContext == null ? null : this.getLatestModule(schemaContext, moduleName); + if (schemaContext != null) { + module = schemaContext.findModuleByName(moduleName, null); + } else { + module = null; + } if (module == null) { throw new RestconfDocumentedException("\"" + moduleName + "\" module does not exist in mount point.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT); } } - targetNode = this.findInstanceDataChildByNameAndNamespace(parentNode, nodeName, module.getNamespace()); + targetNode = findInstanceDataChildByNameAndNamespace(parentNode, nodeName, module.getNamespace()); if (targetNode == null) { throw new RestconfDocumentedException("URI has bad format. Possible reasons:\n" + " 1. \"" + head + "\" was not found in parent data node.\n" + " 2. \"" + head @@ -623,7 +565,7 @@ public class ControllerContext implements SchemaContextListener { ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE); } } else { - final List potentialSchemaNodes = this.findInstanceDataChildrenByName(parentNode, nodeName); + final List potentialSchemaNodes = findInstanceDataChildrenByName(parentNode, nodeName); if (potentialSchemaNodes.size() > 1) { final StringBuilder strBuilder = new StringBuilder(); for (final DataSchemaNode potentialNodeSchema : potentialSchemaNodes) { @@ -693,11 +635,11 @@ public class ControllerContext implements SchemaContextListener { return new InstanceIdWithSchemaNode(builder.toInstance(), targetNode, mountPoint); } - public DataSchemaNode findInstanceDataChildByNameAndNamespace(final DataNodeContainer container, final String name, + public static DataSchemaNode findInstanceDataChildByNameAndNamespace(final DataNodeContainer container, final String name, final URI namespace) { Preconditions. checkNotNull(namespace); - final List potentialSchemaNodes = this.findInstanceDataChildrenByName(container, name); + final List potentialSchemaNodes = findInstanceDataChildrenByName(container, name); Predicate filter = new Predicate() { @Override @@ -710,16 +652,23 @@ public class ControllerContext implements SchemaContextListener { return Iterables.getFirst(result, null); } - public List findInstanceDataChildrenByName(final DataNodeContainer container, final String name) { + public static List findInstanceDataChildrenByName(final DataNodeContainer container, final String name) { Preconditions. checkNotNull(container); Preconditions. checkNotNull(name); List instantiatedDataNodeContainers = new ArrayList(); - this.collectInstanceDataNodeContainers(instantiatedDataNodeContainers, container, name); + collectInstanceDataNodeContainers(instantiatedDataNodeContainers, container, name); return instantiatedDataNodeContainers; } - private void collectInstanceDataNodeContainers(final List potentialSchemaNodes, + private static final Function> CHOICE_FUNCTION = new Function>() { + @Override + public Set apply(final ChoiceNode node) { + return node.getCases(); + } + }; + + private static void collectInstanceDataNodeContainers(final List potentialSchemaNodes, final DataNodeContainer container, final String name) { Predicate filter = new Predicate() { @@ -734,37 +683,28 @@ public class ControllerContext implements SchemaContextListener { // Can't combine this loop with the filter above because the filter is // lazily-applied by Iterables.filter. for (final DataSchemaNode potentialNode : nodes) { - if (this.isInstantiatedDataSchema(potentialNode)) { + if (isInstantiatedDataSchema(potentialNode)) { potentialSchemaNodes.add(potentialNode); } } - Iterable choiceNodes = Iterables. filter(container.getChildNodes(), ChoiceNode.class); - - final Function> choiceFunction = new Function>() { - @Override - public Set apply(final ChoiceNode node) { - return node.getCases(); - } - }; - - Iterable> map = Iterables.> transform(choiceNodes, - choiceFunction); + Iterable choiceNodes = Iterables.filter(container.getChildNodes(), ChoiceNode.class); + Iterable> map = Iterables.transform(choiceNodes, CHOICE_FUNCTION); final Iterable allCases = Iterables. concat(map); for (final ChoiceCaseNode caze : allCases) { - this.collectInstanceDataNodeContainers(potentialSchemaNodes, caze, name); + collectInstanceDataNodeContainers(potentialSchemaNodes, caze, name); } } - public boolean isInstantiatedDataSchema(final DataSchemaNode node) { + public static boolean isInstantiatedDataSchema(final DataSchemaNode node) { return node instanceof LeafSchemaNode || node instanceof LeafListSchemaNode || node instanceof ContainerSchemaNode || node instanceof ListSchemaNode || node instanceof AnyXmlSchemaNode; } private void addKeyValue(final HashMap map, final DataSchemaNode node, final String uriValue, - final MountInstance mountPoint) { + final DOMMountPoint mountPoint) { Preconditions. checkNotNull(uriValue); Preconditions.checkArgument((node instanceof LeafSchemaNode)); @@ -891,11 +831,7 @@ public class ControllerContext implements SchemaContextListener { } private CharSequence convertToRestconfIdentifier(final NodeIdentifier argument, final ContainerSchemaNode node) { - StringBuilder builder = new StringBuilder(); - builder.append("/"); - QName nodeType = argument.getNodeType(); - builder.append(this.toRestconfIdentifier(nodeType)); - return builder.toString(); + return "/" + this.toRestconfIdentifier(argument.getNodeType()); } private CharSequence convertToRestconfIdentifier(final NodeIdentifierWithPredicates argument, @@ -905,9 +841,9 @@ public class ControllerContext implements SchemaContextListener { final Map keyValues = argument.getKeyValues(); StringBuilder builder = new StringBuilder(); - builder.append("/"); + builder.append('/'); builder.append(nodeIdentifier); - builder.append("/"); + builder.append('/'); List keyDefinition = node.getKeyDefinition(); boolean hasElements = false; @@ -915,7 +851,7 @@ public class ControllerContext implements SchemaContextListener { if (!hasElements) { hasElements = true; } else { - builder.append("/"); + builder.append('/'); } try { @@ -947,4 +883,35 @@ public class ControllerContext implements SchemaContextListener { + Arrays. asList(container, name).toString()); } } + + public Entry> toNormalized(final YangInstanceIdentifier legacy, + final CompositeNode compositeNode) { + try { + return dataNormalizer.toNormalized(legacy, compositeNode); + } catch (NullPointerException e) { + throw new RestconfDocumentedException("Data normalizer isn't set. Normalization isn't possible", e); + } + } + + public YangInstanceIdentifier toNormalized(final YangInstanceIdentifier legacy) { + try { + return dataNormalizer.toNormalized(legacy); + } catch (NullPointerException e) { + throw new RestconfDocumentedException("Data normalizer isn't set. Normalization isn't possible", e); + } + } + + public CompositeNode toLegacy(final YangInstanceIdentifier instanceIdentifier, + final NormalizedNode normalizedNode) { + try { + return dataNormalizer.toLegacy(instanceIdentifier, normalizedNode); + } catch (NullPointerException e) { + throw new RestconfDocumentedException("Data normalizer isn't set. Normalization isn't possible", e); + } + } + + public DataNormalizationOperation getRootOperation() { + return dataNormalizer.getRootOperation(); + } + }