[ONOS-5482][ONOS-5275] Yms Operation requirement Implementation in onos-yang-tools
Change-Id: I463ed105f85ca65a61ff251e5ca062903d465551
diff --git a/generator/src/main/java/org/onosproject/yangutils/linker/impl/XpathLinkingTypes.java b/generator/src/main/java/org/onosproject/yangutils/linker/impl/XpathLinkingTypes.java
new file mode 100644
index 0000000..87e7fae
--- /dev/null
+++ b/generator/src/main/java/org/onosproject/yangutils/linker/impl/XpathLinkingTypes.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.linker.impl;
+
+/**
+ * Represents x path linking types.
+ */
+public enum XpathLinkingTypes {
+
+ // Augment path linking.
+ AUGMENT_LINKING,
+
+ // Leaf ref path linking.
+ LEAF_REF_LINKING,
+
+ // Compiler annotation linking.
+ COMPILER_ANNOTATION_LINKING
+}
diff --git a/generator/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java b/generator/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
index 84de876..480d8c6 100644
--- a/generator/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
+++ b/generator/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
@@ -78,6 +78,8 @@
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNDEFINED;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNRESOLVED;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.PATH_DATA;
+import static org.onosproject.yangutils.linker.impl.XpathLinkingTypes.AUGMENT_LINKING;
+import static org.onosproject.yangutils.linker.impl.XpathLinkingTypes.LEAF_REF_LINKING;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.detectCollisionForAugmentedNode;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.getErrorInfoForLinker;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.getLeafRefErrorInfo;
@@ -1026,7 +1028,8 @@
YangNode targetNode;
YangAugment augment = (YangAugment) entityToResolve;
targetNode = xPathLinker
- .processAugmentXpathLinking(augment.getTargetNode(), (YangNode) root);
+ .processXpathLinking(augment.getTargetNode(), (YangNode)
+ root, AUGMENT_LINKING);
if (targetNode != null) {
if (targetNode instanceof YangAugmentableNode) {
detectCollisionForAugmentedNode(targetNode, augment);
@@ -1053,8 +1056,9 @@
} else if (entityToResolve instanceof YangCompilerAnnotation) {
YangNode targetNode;
YangCompilerAnnotation ca = (YangCompilerAnnotation) entityToResolve;
- targetNode = xPathLinker.processAugmentXpathLinking(ca.getAtomicPathList(),
- (YangNode) root);
+ targetNode = xPathLinker.processXpathLinking(ca.getAtomicPathList(),
+ (YangNode) root,
+ AUGMENT_LINKING);
if (targetNode != null) {
if (targetNode instanceof YangList) {
((YangList) targetNode).setCompilerAnnotation(
@@ -1074,7 +1078,7 @@
} else if (entityToResolve instanceof YangLeafRef) {
YangLeafRef leafRef = (YangLeafRef) entityToResolve;
Object target = xPathLinker.processLeafRefXpathLinking(
- leafRef.getAtomicPath(), (YangNode) root, leafRef);
+ leafRef.getAtomicPath(), (YangNode) root, leafRef, LEAF_REF_LINKING);
if (target != null) {
YangLeaf leaf;
YangLeafList leafList;
@@ -1210,13 +1214,13 @@
/*
* Obtain the referred node of top of stack entity under resolution
*/
- T referredNode = getRefNode();
+ T refNode = getRefNode();
/*
* Check for null for scenario when it's not linked and inter-file
* linking is required.
*/
- if (referredNode == null) {
+ if (refNode == null) {
/*
* Check if prefix is null or not, to identify whether to search in
@@ -1247,7 +1251,7 @@
throw ex;
} else {
((Resolvable) entity).setResolvableStatus(INTER_FILE_LINKED);
- addUnresolvedRecursiveReferenceToStack((YangNode) referredNode);
+ addUnresolvedRecursiveReferenceToStack((YangNode) refNode);
}
}
diff --git a/generator/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java b/generator/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java
index 83f4a1a..f049dbd 100644
--- a/generator/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java
+++ b/generator/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java
@@ -20,6 +20,7 @@
import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
+import org.onosproject.yangutils.datamodel.YangGrouping;
import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangInclude;
import org.onosproject.yangutils.datamodel.YangInput;
@@ -48,7 +49,9 @@
import static org.onosproject.yangutils.linker.impl.PrefixResolverType.INTRA_TO_INTER;
import static org.onosproject.yangutils.linker.impl.PrefixResolverType.NO_PREFIX_CHANGE_FOR_INTER;
import static org.onosproject.yangutils.linker.impl.PrefixResolverType.NO_PREFIX_CHANGE_FOR_INTRA;
+import static org.onosproject.yangutils.linker.impl.XpathLinkingTypes.AUGMENT_LINKING;
import static org.onosproject.yangutils.utils.UtilConstants.COLON;
+import static org.onosproject.yangutils.utils.UtilConstants.ERROR_MSG_FOR_AUGMENT_LINKING;
import static org.onosproject.yangutils.utils.UtilConstants.FAILED_TO_FIND_LEAD_INFO_HOLDER;
import static org.onosproject.yangutils.utils.UtilConstants.INPUT;
import static org.onosproject.yangutils.utils.UtilConstants.IS_INVALID;
@@ -69,6 +72,7 @@
private Map<YangAtomicPath, PrefixResolverType> prefixResolverTypes;
private String curPrefix;
private String constructsParentsPrefix;
+ private XpathLinkingTypes linkingType;
/**
* Creates an instance of x-path linker.
@@ -101,14 +105,16 @@
* @param atomicPaths atomic path node list
* @param root root node
* @param leafref instance of YANG leafref
+ * @param curLinking x path linking type
* @return linked target node
*/
T processLeafRefXpathLinking(List<YangAtomicPath> atomicPaths, YangNode root,
- YangLeafRef leafref) {
+ YangLeafRef leafref, XpathLinkingTypes curLinking) {
YangNode targetNode;
rootNode = root;
prefixResolverTypes = new HashMap<>();
+ linkingType = curLinking;
parsePrefixResolverList(atomicPaths);
YangAtomicPath leafRefPath = atomicPaths.get(atomicPaths.size() - 1);
@@ -191,15 +197,17 @@
/**
* Process absolute node path linking for augment.
*
- * @param paths absolute path node list
- * @param root root node
+ * @param paths absolute path node list
+ * @param root root node
+ * @param curLinking x path linker type
* @return linked target node
*/
- public YangNode processAugmentXpathLinking(List<YangAtomicPath> paths,
- YangNode root) {
+ public YangNode processXpathLinking(List<YangAtomicPath> paths,
+ YangNode root, XpathLinkingTypes curLinking) {
absPaths = paths;
rootNode = root;
prefixResolverTypes = new HashMap<>();
+ linkingType = curLinking;
parsePrefixResolverList(paths);
YangNode targetNode = parseData(root);
if (targetNode == null) {
@@ -237,8 +245,8 @@
/**
* Searches for the referred leaf-list in target node.
*
- * @param targetNode target node
- * @param name leaf-list name
+ * @param targetNode target node
+ * @param name leaf-list name
* @return target leaf-list
*/
private YangLeafList searchReferredLeafList(YangNode targetNode, String name) {
@@ -317,6 +325,7 @@
if (tempNode != null) {
tempPath.setResolvedNode(tempNode);
+ validateTempPathNode(tempNode);
}
if (index == absPaths.size() - 1) {
@@ -329,6 +338,29 @@
}
/**
+ * Validates temp path nodes for augment linking.
+ *
+ * @param node temp path node
+ */
+ private void validateTempPathNode(YangNode node) {
+
+ if (linkingType != AUGMENT_LINKING) {
+ return;
+ }
+ if (node instanceof YangGrouping) {
+ LinkerException ex = new LinkerException(
+ ERROR_MSG_FOR_AUGMENT_LINKING +
+ getAugmentNodeIdentifier(
+ absPaths.get(absPaths.size() - 1).getNodeIdentifier(),
+ absPaths,
+ rootNode));
+ ex.setFileName(rootNode.getFileName());
+ throw ex;
+
+ }
+ }
+
+ /**
* Resolves intra file augment linking.
*
* @param tempPath temporary absolute path
@@ -739,5 +771,4 @@
YangNode rootNode) {
((RpcNotificationContainer) rootNode).addToAugmentList(augment);
}
-
}
\ No newline at end of file