X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fdom%2Fbroker%2Futil%2FYangSchemaUtils.java;h=248a294aff38d1788b254ca5ff0be97680a1c699;hp=29392dc7b3e91e6c6dbe202cbe1b4e4292cce17d;hb=4ef15f7a7e3fb5bcaa6a3202d268a5c945e0aa71;hpb=cbe83ca3074fa0182d4f079f528bb710a997ced7 diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/util/YangSchemaUtils.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/util/YangSchemaUtils.java index 29392dc7b3..248a294aff 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/util/YangSchemaUtils.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/util/YangSchemaUtils.java @@ -10,19 +10,16 @@ package org.opendaylight.controller.sal.dom.broker.util; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; -import com.google.common.base.Function; -import com.google.common.collect.FluentIterable; - +import com.google.common.collect.Lists; import java.util.Iterator; import java.util.List; import java.util.Set; - import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; -import org.opendaylight.yangtools.yang.model.api.ChoiceNode; +import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode; import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition; import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; @@ -38,32 +35,20 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.UsesNode; public final class YangSchemaUtils { - - private static final Function QNAME_FROM_PATH_ARGUMENT = new Function(){ - - @Override - public QName apply(final PathArgument input) { - if(input == null) { - return null; - } - return input.getNodeType(); - } - }; - private YangSchemaUtils() { throw new UnsupportedOperationException("Utility class."); } - public static DataSchemaNode getSchemaNode(final SchemaContext schema,final InstanceIdentifier path) { - checkArgument(schema != null,"YANG Schema must not be null."); - checkArgument(path != null,"Path must not be null."); - return getSchemaNode(schema, FluentIterable.from(path.getPathArguments()).transform(QNAME_FROM_PATH_ARGUMENT)); + public static DataSchemaNode getSchemaNode(final SchemaContext schema, final YangInstanceIdentifier path) { + checkArgument(schema != null, "YANG Schema must not be null."); + checkArgument(path != null, "Path must not be null."); + return getSchemaNode(schema, Lists.transform(path.getPathArguments(), PathArgument::getNodeType)); } - public static DataSchemaNode getSchemaNode(final SchemaContext schema,final Iterable path) { - checkArgument(schema != null,"YANG Schema must not be null."); - checkArgument(path != null,"Path must not be null."); - if(!path.iterator().hasNext()){ + public static DataSchemaNode getSchemaNode(final SchemaContext schema, final Iterable path) { + checkArgument(schema != null, "YANG Schema must not be null."); + checkArgument(path != null, "Path must not be null."); + if (!path.iterator().hasNext()) { return toRootDataNode(schema); } @@ -73,10 +58,10 @@ public final class YangSchemaUtils { Iterator iterator = path.iterator(); while (iterator.hasNext()) { - checkArgument(previous!= null, "Supplied path does not resolve into valid schema node."); + checkArgument(previous != null, "Supplied path does not resolve into valid schema node."); QName arg = iterator.next(); DataSchemaNode currentNode = previous.getDataChildByName(arg); - if (currentNode == null && previous instanceof DataNodeContainer) { + if (currentNode == null) { currentNode = searchInChoices(previous, arg); } if (currentNode instanceof DataNodeContainer) { @@ -85,17 +70,17 @@ public final class YangSchemaUtils { checkArgument(!iterator.hasNext(), "Path nests inside leaf node, which is not allowed."); return currentNode; } - checkState(currentNode != null, "Current node should not be null for %s",path); + checkState(currentNode != null, "Current node should not be null for %s", path); } - checkState(previous instanceof DataSchemaNode, "Schema node for %s should be instance of DataSchemaNode. Found %s",path,previous); + checkState(previous instanceof DataSchemaNode, + "Schema node for %s should be instance of DataSchemaNode. Found %s", path, previous); return (DataSchemaNode) previous; } private static DataSchemaNode searchInChoices(final DataNodeContainer node, final QName arg) { - Set children = node.getChildNodes(); - for (DataSchemaNode child : children) { - if (child instanceof ChoiceNode) { - ChoiceNode choiceNode = (ChoiceNode) child; + for (DataSchemaNode child : node.getChildNodes()) { + if (child instanceof ChoiceSchemaNode) { + ChoiceSchemaNode choiceNode = (ChoiceSchemaNode) child; DataSchemaNode potential = searchInCases(choiceNode, arg); if (potential != null) { return potential; @@ -105,7 +90,7 @@ public final class YangSchemaUtils { return null; } - private static DataSchemaNode searchInCases(final ChoiceNode choiceNode, final QName arg) { + private static DataSchemaNode searchInCases(final ChoiceSchemaNode choiceNode, final QName arg) { Set cases = choiceNode.getCases(); for (ChoiceCaseNode caseNode : cases) { DataSchemaNode node = caseNode.getDataChildByName(arg); @@ -122,7 +107,7 @@ public final class YangSchemaUtils { private static final class NetconfDataRootNode implements ContainerSchemaNode { - public NetconfDataRootNode(final SchemaContext schema) { + NetconfDataRootNode(final SchemaContext schema) { // TODO Auto-generated constructor stub } @@ -150,12 +135,6 @@ public final class YangSchemaUtils { return null; } - @Override - public DataSchemaNode getDataChildByName(final String name) { - // TODO Auto-generated method stub - return null; - } - @Override public Set getUses() { // TODO Auto-generated method stub