Gaurav Agrawal
Committed by Gerrit Code Review

YANG construct collision detection framework added

Change-Id: I1458f9e3192641f3f90c444798c31a64536ffa5d
Showing 89 changed files with 1610 additions and 1049 deletions
/*
* Copyright 2016 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.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.utils.YangConstructType;
/**
* Abstraction of YANG collision function. Abstracted to unify the collision
* detection functionality.
*/
public interface CollisionDetector {
/**
* Checks for the colliding child.
*
* @param identifierName name of identifier for which collision to be
* checked
* @param dataType type of the YANG construct for which collision to be
* checked
* @throws DataModelException if there is any collision in YANG rules in
* parsed data, corresponding exception should be thrown
*/
void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException;
/**
* Check for the self collision.
*
* @param identifierName name of identifier for which collision to be
* checked
* @param dataType type of the YANG construct for which collision to be
* checked
* @throws DataModelException if there is any collision in YANG rules in
* parsed data, corresponding exception should be thrown
*/
void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException;
}
......@@ -20,7 +20,7 @@ import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.utils.YangConstructType;
import org.onosproject.yangutils.translator.CachedFileHandle;
/*-
......@@ -85,7 +85,7 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
private String targetNode;
/**
* description of augment.
* Description of augment.
*/
private String description;
......@@ -100,7 +100,7 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
private List<YangLeafList> listOfLeafList;
/**
* reference.
* Reference of the YANG augment.
*/
private String reference;
......@@ -110,7 +110,7 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
private YangStatusType status;
/**
* package of the generated java code.
* Package of the generated java code.
*/
private String pkg;
......@@ -124,7 +124,7 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
/**
* Get the augmented node.
*
* @return the augmented node.
* @return the augmented node
*/
public String getTargetNode() {
return targetNode;
......@@ -133,7 +133,7 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
/**
* Set the augmented node.
*
* @param targetNode the augmented node.
* @param targetNode the augmented node
*/
public void setTargetNode(String targetNode) {
this.targetNode = targetNode;
......@@ -142,7 +142,7 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
/**
* Get the description.
*
* @return the description.
* @return the description
*/
@Override
public String getDescription() {
......@@ -152,7 +152,7 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
/**
* Set the description.
*
* @param description set the description.
* @param description set the description
*/
@Override
public void setDescription(String description) {
......@@ -162,7 +162,7 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
/**
* Get the list of leaves.
*
* @return the list of leaves.
* @return the list of leaves
*/
@Override
public List<YangLeaf> getListOfLeaf() {
......@@ -172,7 +172,7 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
/**
* Set the list of leaves.
*
* @param leafsList the list of leaf to set.
* @param leafsList the list of leaf to set
*/
private void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
......@@ -181,7 +181,7 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
/**
* Add a leaf.
*
* @param leaf the leaf to be added.
* @param leaf the leaf to be added
*/
@Override
public void addLeaf(YangLeaf leaf) {
......@@ -195,7 +195,7 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
/**
* Get the list of leaf-list.
*
* @return the list of leaf-list.
* @return the list of leaf-list
*/
@Override
public List<YangLeafList> getListOfLeafList() {
......@@ -205,7 +205,7 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
/**
* Set the list of leaf-list.
*
* @param listOfLeafList the list of leaf-list to set.
* @param listOfLeafList the list of leaf-list to set
*/
private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
......@@ -214,7 +214,7 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
/**
* Add a leaf-list.
*
* @param leafList the leaf-list to be added.
* @param leafList the leaf-list to be added
*/
@Override
public void addLeafList(YangLeafList leafList) {
......@@ -228,7 +228,7 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
/**
* Get the textual reference.
*
* @return the reference.
* @return the reference
*/
@Override
public String getReference() {
......@@ -238,7 +238,7 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
/**
* Set the textual reference.
*
* @param reference the reference to set.
* @param reference the reference to set
*/
@Override
public void setReference(String reference) {
......@@ -248,7 +248,7 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
/**
* Get the status.
*
* @return the status.
* @return the status
*/
@Override
public YangStatusType getStatus() {
......@@ -258,7 +258,7 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
/**
* Set the status.
*
* @param status the status to set.
* @param status the status to set
*/
@Override
public void setStatus(YangStatusType status) {
......@@ -268,17 +268,17 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
/**
* Returns the type of the data as belongs-to.
*
* @return returns AUGMENT_DATA.
* @return returns AUGMENT_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.AUGMENT_DATA;
public YangConstructType getYangConstructType() {
return YangConstructType.AUGMENT_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
......@@ -288,7 +288,7 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
......@@ -298,7 +298,7 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
/**
* Get the target nodes name where the augmentation is being done.
*
* @return target nodes name where the augmentation is being done.
* @return target nodes name where the augmentation is being done
*/
@Override
public String getName() {
......@@ -308,7 +308,7 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
/**
* Set the target nodes name where the augmentation is being done.
*
* @param name target nodes name where the augmentation is being done.
* @param name target nodes name where the augmentation is being done
*/
@Override
public void setName(String name) {
......
......@@ -17,7 +17,7 @@ package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.utils.YangConstructType;
/*-
* Reference 6020.
......@@ -94,7 +94,7 @@ public class YangBelongsTo implements Parsable {
/**
* Get the prefix.
*
* @return the prefix.
* @return the prefix
*/
public String getPrefix() {
return prefix;
......@@ -115,14 +115,14 @@ public class YangBelongsTo implements Parsable {
* @return ParsedDataType returns BELONGS_TO_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.BELONGS_TO_DATA;
public YangConstructType getYangConstructType() {
return YangConstructType.BELONGS_TO_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
......@@ -132,7 +132,7 @@ public class YangBelongsTo implements Parsable {
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
......
......@@ -18,7 +18,7 @@ package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.utils.YangConstructType;
import java.util.Objects;
......@@ -83,7 +83,7 @@ public class YangBit implements YangCommonInfo, Parsable {
/**
* Returns bit name.
*
* @return the bit name.
* @return the bit name
*/
public String getBitName() {
return bitName;
......@@ -92,7 +92,7 @@ public class YangBit implements YangCommonInfo, Parsable {
/**
* Set the bit name.
*
* @param bitName the bit name to set.
* @param bitName the bit name to set
*/
public void setBitName(String bitName) {
this.bitName = bitName;
......@@ -101,7 +101,7 @@ public class YangBit implements YangCommonInfo, Parsable {
/**
* Returns description.
*
* @return the description.
* @return the description
*/
@Override
public String getDescription() {
......@@ -111,7 +111,7 @@ public class YangBit implements YangCommonInfo, Parsable {
/**
* Set the description.
*
* @param description set the description.
* @param description set the description
*/
@Override
public void setDescription(String description) {
......@@ -121,7 +121,7 @@ public class YangBit implements YangCommonInfo, Parsable {
/**
* Returns textual reference.
*
* @return the reference.
* @return the reference
*/
@Override
public String getReference() {
......@@ -131,7 +131,7 @@ public class YangBit implements YangCommonInfo, Parsable {
/**
* Set the textual reference.
*
* @param reference the reference to set.
* @param reference the reference to set
*/
@Override
public void setReference(String reference) {
......@@ -141,7 +141,7 @@ public class YangBit implements YangCommonInfo, Parsable {
/**
* Returns status.
*
* @return the status.
* @return the status
*/
@Override
public YangStatusType getStatus() {
......@@ -151,7 +151,7 @@ public class YangBit implements YangCommonInfo, Parsable {
/**
* Set the status.
*
* @param status the status to set.
* @param status the status to set
*/
@Override
public void setStatus(YangStatusType status) {
......@@ -170,7 +170,7 @@ public class YangBit implements YangCommonInfo, Parsable {
/**
* Set the bit position.
*
* @param position the position to set.
* @param position the position to set
*/
public void setPosition(int position) {
this.position = position;
......@@ -182,8 +182,8 @@ public class YangBit implements YangCommonInfo, Parsable {
* @return ParsedDataType returns BIT_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.BIT_DATA;
public YangConstructType getYangConstructType() {
return YangConstructType.BIT_DATA;
}
@Override
......@@ -206,7 +206,7 @@ public class YangBit implements YangCommonInfo, Parsable {
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
......@@ -216,7 +216,7 @@ public class YangBit implements YangCommonInfo, Parsable {
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
......
......@@ -21,7 +21,7 @@ import java.util.Set;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.utils.YangConstructType;
/*
* Reference RFC 6020.
......@@ -70,12 +70,13 @@ public class YangBits implements Parsable {
/**
* Add bit info.
*
* @param bitInfo the bit information to be added.
* @throws DataModelException due to violation in data model rules.
* @param bitInfo the bit information to be added
* @throws DataModelException due to violation in data model rules
*/
public void addBitInfo(YangBit bitInfo) throws DataModelException {
if (!getBitSet().add(bitInfo)) {
throw new DataModelException("YANG Bit already exists");
throw new DataModelException("YANG file error: Duplicate identifier detected, same as bit \""
+ bitInfo.getBitName() + "\"");
}
}
......@@ -85,14 +86,14 @@ public class YangBits implements Parsable {
* @return ParsedDataType returns BITS_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.BITS_DATA;
public YangConstructType getYangConstructType() {
return YangConstructType.BITS_DATA;
}
/**
* Returns the bits name.
*
* @return name of the bits.
* @return name of the bits
*/
public String getBitsName() {
return bitsName;
......@@ -101,7 +102,7 @@ public class YangBits implements Parsable {
/**
* Set bits name.
*
* @param bitsName bit name to be set.
* @param bitsName bit name to be set
*/
public void setBitsName(String bitsName) {
this.bitsName = bitsName;
......@@ -110,7 +111,7 @@ public class YangBits implements Parsable {
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
......@@ -120,7 +121,7 @@ public class YangBits implements Parsable {
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
......
......@@ -15,13 +15,15 @@
*/
package org.onosproject.yangutils.datamodel;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.translator.CachedFileHandle;
import org.onosproject.yangutils.utils.YangConstructType;
import static org.onosproject.yangutils.utils.YangConstructType.CASE_DATA;
import java.util.LinkedList;
import java.util.List;
/*-
* Reference RFC 6020.
......@@ -90,7 +92,7 @@ import org.onosproject.yangutils.translator.CachedFileHandle;
* Data model node to maintain information defined in YANG case.
*/
public class YangCase extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable {
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
/**
* Case name.
......@@ -100,7 +102,7 @@ public class YangCase extends YangNode
// TODO: default field identification for the case
/**
* Description of container.
* Description of case.
*/
private String description;
......@@ -125,7 +127,7 @@ public class YangCase extends YangNode
private YangStatusType status;
/**
* package of the generated java code.
* Package of the generated java code.
*/
private String pkg;
......@@ -139,7 +141,7 @@ public class YangCase extends YangNode
/**
* Get the case name.
*
* @return case name.
* @return case name
*/
@Override
public String getName() {
......@@ -149,7 +151,7 @@ public class YangCase extends YangNode
/**
* Set the case name.
*
* @param name case name.
* @param name case name
*/
@Override
public void setName(String name) {
......@@ -159,7 +161,7 @@ public class YangCase extends YangNode
/**
* Get the description.
*
* @return the description.
* @return the description
*/
@Override
public String getDescription() {
......@@ -169,7 +171,7 @@ public class YangCase extends YangNode
/**
* Set the description.
*
* @param description set the description.
* @param description set the description
*/
@Override
public void setDescription(String description) {
......@@ -179,7 +181,7 @@ public class YangCase extends YangNode
/**
* Get the list of leaves.
*
* @return the list of leaves.
* @return the list of leaves
*/
@Override
public List<YangLeaf> getListOfLeaf() {
......@@ -189,7 +191,7 @@ public class YangCase extends YangNode
/**
* Set the list of leaves.
*
* @param leafsList the list of leaf to set.
* @param leafsList the list of leaf to set
*/
private void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
......@@ -198,7 +200,7 @@ public class YangCase extends YangNode
/**
* Add a leaf.
*
* @param leaf the leaf to be added.
* @param leaf the leaf to be added
*/
@Override
public void addLeaf(YangLeaf leaf) {
......@@ -212,7 +214,7 @@ public class YangCase extends YangNode
/**
* Get the list of leaf-list.
*
* @return the list of leaf-list.
* @return the list of leaf-list
*/
@Override
public List<YangLeafList> getListOfLeafList() {
......@@ -222,7 +224,7 @@ public class YangCase extends YangNode
/**
* Set the list of leaf-list.
*
* @param listOfLeafList the list of leaf-list to set.
* @param listOfLeafList the list of leaf-list to set
*/
private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
......@@ -231,7 +233,7 @@ public class YangCase extends YangNode
/**
* Add a leaf-list.
*
* @param leafList the leaf-list to be added.
* @param leafList the leaf-list to be added
*/
@Override
public void addLeafList(YangLeafList leafList) {
......@@ -245,7 +247,7 @@ public class YangCase extends YangNode
/**
* Get the textual reference.
*
* @return the reference.
* @return the reference
*/
@Override
public String getReference() {
......@@ -255,7 +257,7 @@ public class YangCase extends YangNode
/**
* Set the textual reference.
*
* @param reference the reference to set.
* @param reference the reference to set
*/
@Override
public void setReference(String reference) {
......@@ -265,7 +267,7 @@ public class YangCase extends YangNode
/**
* Get the status.
*
* @return the status.
* @return the status
*/
@Override
public YangStatusType getStatus() {
......@@ -275,7 +277,7 @@ public class YangCase extends YangNode
/**
* Set the status.
*
* @param status the status to set.
* @param status the status to set
*/
@Override
public void setStatus(YangStatusType status) {
......@@ -288,14 +290,14 @@ public class YangCase extends YangNode
* @return returns CASE_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.CASE_DATA;
public YangConstructType getYangConstructType() {
return YangConstructType.CASE_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
......@@ -305,7 +307,7 @@ public class YangCase extends YangNode
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
......@@ -361,6 +363,30 @@ public class YangCase extends YangNode
@Override
public void setFileHandle(CachedFileHandle fileHandle) {
// TODO Auto-generated method stub
}
@Override
public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
if ((this.getParent() == null) || (!(this.getParent() instanceof YangChoice))) {
throw new DataModelException("Internal Data Model Tree Error: Invalid/Missing holder in case " +
this.getName());
}
// Traverse up in tree to ask parent choice start collision detection.
((CollisionDetector) this.getParent()).detectCollidingChild(identifierName, dataType);
}
@Override
public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
if (dataType == CASE_DATA) {
if (this.getName().equals(identifierName)) {
throw new DataModelException("YANG File Error: Identifier collision detected in case \"" +
this.getName() + "\"");
}
return;
}
// Asks helper to detect colliding child.
detectCollidingChildUtil(identifierName, dataType, this);
}
}
......
......@@ -15,13 +15,11 @@
*/
package org.onosproject.yangutils.datamodel;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.translator.CachedFileHandle;
import org.onosproject.yangutils.utils.YangConstructType;
import static org.onosproject.yangutils.utils.YangConstructType.CHOICE_DATA;
/*-
* Reference RFC 6020.
......@@ -61,7 +59,7 @@ import org.onosproject.yangutils.translator.CachedFileHandle;
/**
* Data model node to maintain information defined in YANG choice.
*/
public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
public class YangChoice extends YangNode implements YangCommonInfo, Parsable, CollisionDetector {
/**
* Name of choice.
......@@ -69,11 +67,6 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
private String name;
/**
* List of cases for the current choice.
*/
private List<YangCase> caseList;
/**
* If the choice represents config data.
*/
private boolean isConfig;
......@@ -105,7 +98,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
private String defaultCase;
/**
* Description.
* Description of choice.
*/
private String description;
......@@ -131,7 +124,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
private String mandatory;
/**
* reference of the choice.
* Reference of the choice.
*/
private String reference;
......@@ -141,13 +134,15 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
private YangStatusType status;
/**
* Create a Choice node.
* Create a choice node.
*/
public YangChoice() {
super(YangNodeType.CHOICE_NODE);
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.onosproject.yangutils.datamodel.YangNode#getName()
*/
@Override
......@@ -155,8 +150,11 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
return name;
}
/* (non-Javadoc)
* @see org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String)
/*
* (non-Javadoc)
*
* @see
* org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String)
*/
@Override
public void setName(String name) {
......@@ -164,40 +162,9 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
}
/**
* Get the list of cases.
*
* @return the case list
*/
public List<YangCase> getCaseList() {
return caseList;
}
/**
* Set the list of cases.
*
* @param caseList list of cases.
*/
private void setCaseList(List<YangCase> caseList) {
this.caseList = caseList;
}
/**
* Add a case.
*
* @param newCase new case for the choice
*/
public void addCase(YangCase newCase) {
if (getCaseList() == null) {
setCaseList(new LinkedList<YangCase>());
}
getCaseList().add(newCase);
}
/**
* Get config flag.
*
* @return the config flag.
* @return the config flag
*/
public boolean isConfig() {
return isConfig;
......@@ -206,7 +173,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
/**
* Set config flag.
*
* @param isCfg the config flag.
* @param isCfg the config flag
*/
public void setConfig(boolean isCfg) {
isConfig = isCfg;
......@@ -215,7 +182,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
/**
* Get the default case.
*
* @return the default case.
* @return the default case
*/
public String getDefaultCase() {
return defaultCase;
......@@ -233,7 +200,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
/**
* Get the mandatory status.
*
* @return the mandatory status.
* @return the mandatory status
*/
public String getMandatory() {
return mandatory;
......@@ -242,7 +209,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
/**
* Set the mandatory status.
*
* @param mandatory the mandatory status.
* @param mandatory the mandatory status
*/
public void setMandatory(String mandatory) {
this.mandatory = mandatory;
......@@ -251,7 +218,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
/**
* Get the description.
*
* @return the description.
* @return the description
*/
@Override
public String getDescription() {
......@@ -261,7 +228,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
/**
* Set the description.
*
* @param description set the description.
* @param description set the description
*/
@Override
public void setDescription(String description) {
......@@ -271,7 +238,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
/**
* Get the textual reference.
*
* @return the reference.
* @return the reference
*/
@Override
public String getReference() {
......@@ -281,7 +248,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
/**
* Set the textual reference.
*
* @param reference the reference to set.
* @param reference the reference to set
*/
@Override
public void setReference(String reference) {
......@@ -291,7 +258,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
/**
* Get the status.
*
* @return the status.
* @return the status
*/
@Override
public YangStatusType getStatus() {
......@@ -301,7 +268,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
/**
* Set the status.
*
* @param status the status to set.
* @param status the status to set
*/
@Override
public void setStatus(YangStatusType status) {
......@@ -314,14 +281,14 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
* @return returns CHOICE_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.CHOICE_DATA;
public YangConstructType getYangConstructType() {
return YangConstructType.CHOICE_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
......@@ -331,14 +298,16 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.onosproject.yangutils.datamodel.YangNode#getPackage()
*/
@Override
......@@ -347,8 +316,11 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
return null;
}
/* (non-Javadoc)
* @see org.onosproject.yangutils.datamodel.YangNode#setPackage(java.lang.String)
/*
* (non-Javadoc)
*
* @see
* org.onosproject.yangutils.datamodel.YangNode#setPackage(java.lang.String)
*/
@Override
public void setPackage(String pkg) {
......@@ -356,8 +328,12 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
}
/* (non-Javadoc)
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
/*
* (non-Javadoc)
*
* @see
* org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry(
* )
*/
@Override
public void generateJavaCodeEntry() {
......@@ -365,8 +341,11 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
}
/* (non-Javadoc)
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
/*
* (non-Javadoc)
*
* @see
* org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
*/
@Override
public void generateJavaCodeExit() {
......@@ -385,4 +364,36 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
// TODO Auto-generated method stub
}
@Override
public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
YangNode node = this.getChild();
while ((node != null)) {
if (node instanceof CollisionDetector) {
((CollisionDetector) node).detectSelfCollision(identifierName, dataType);
}
node = node.getNextSibling();
}
}
@Override
public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
if (dataType == CHOICE_DATA) {
if (this.getName().equals(identifierName)) {
throw new DataModelException("YANG file error: Identifier collision detected in choice \"" +
this.getName() + "\"");
}
return;
}
YangNode node = this.getChild();
while ((node != null)) {
if (node instanceof CollisionDetector) {
((CollisionDetector) node).detectSelfCollision(identifierName, dataType);
}
node = node.getNextSibling();
}
}
}
......
......@@ -21,8 +21,9 @@ import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.utils.YangConstructType;
import org.onosproject.yangutils.translator.CachedFileHandle;
import org.onosproject.yangutils.translator.GeneratedFileType;
import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
......@@ -90,7 +91,7 @@ import org.onosproject.yangutils.utils.io.impl.FileSystemUtil;
/**
* Data model node to maintain information defined in YANG container.
*/
public class YangContainer extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable {
public class YangContainer extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
/**
* Name of the container.
......@@ -153,7 +154,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
/**
* Get the YANG name of container.
*
* @return the name of container as defined in YANG file.
* @return the name of container as defined in YANG file
*/
@Override
public String getName() {
......@@ -163,7 +164,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
/**
* Set the YANG name of container.
*
* @param name the name of container as defined in YANG file.
* @param name the name of container as defined in YANG file
*/
@Override
public void setName(String name) {
......@@ -182,7 +183,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
/**
* Set the config flag.
*
* @param isCfg the config flag.
* @param isCfg the config flag
*/
public void setConfig(boolean isCfg) {
isConfig = isCfg;
......@@ -191,7 +192,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
/**
* Get the description.
*
* @return the description.
* @return the description
*/
@Override
public String getDescription() {
......@@ -201,7 +202,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
/**
* Set the description.
*
* @param description set the description.
* @param description set the description
*/
@Override
public void setDescription(String description) {
......@@ -211,7 +212,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
/**
* Get the list of leaves.
*
* @return the list of leaves.
* @return the list of leaves
*/
@Override
public List<YangLeaf> getListOfLeaf() {
......@@ -221,7 +222,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
/**
* Set the list of leaves.
*
* @param leafsList the list of leaf to set.
* @param leafsList the list of leaf to set
*/
private void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
......@@ -230,7 +231,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
/**
* Add a leaf.
*
* @param leaf the leaf to be added.
* @param leaf the leaf to be added
*/
@Override
public void addLeaf(YangLeaf leaf) {
......@@ -244,7 +245,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
/**
* Get the list of leaf-list.
*
* @return the list of leaf-list.
* @return the list of leaf-list
*/
@Override
public List<YangLeafList> getListOfLeafList() {
......@@ -254,7 +255,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
/**
* Set the list of leaf-list.
*
* @param listOfLeafList the list of leaf-list to set.
* @param listOfLeafList the list of leaf-list to set
*/
private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
......@@ -263,7 +264,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
/**
* Add a leaf-list.
*
* @param leafList the leaf-list to be added.
* @param leafList the leaf-list to be added
*/
@Override
public void addLeafList(YangLeafList leafList) {
......@@ -277,7 +278,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
/**
* Get the presence string if present.
*
* @return the isPressence.
* @return the presence
*/
public String getPresence() {
return presence;
......@@ -295,7 +296,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
/**
* Get the textual reference.
*
* @return the reference.
* @return the reference
*/
@Override
public String getReference() {
......@@ -305,7 +306,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
/**
* Set the textual reference.
*
* @param reference the reference to set.
* @param reference the reference to set
*/
@Override
public void setReference(String reference) {
......@@ -315,7 +316,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
/**
* Get the status.
*
* @return the status.
* @return the status
*/
@Override
public YangStatusType getStatus() {
......@@ -325,7 +326,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
/**
* Set the status.
*
* @param status the status to set.
* @param status the status to set
*/
@Override
public void setStatus(YangStatusType status) {
......@@ -355,17 +356,17 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
/**
* Returns the type of the data.
*
* @return returns CONTAINER_DATA.
* @return returns CONTAINER_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.CONTAINER_DATA;
public YangConstructType getYangConstructType() {
return YangConstructType.CONTAINER_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
......@@ -375,7 +376,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
......@@ -387,15 +388,18 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
}
/**
* Sets the config's value to all leaf if leaf's config statement is not specified.
* Sets the config's value to all leaf if leaf's config statement is not
* specified.
*
* @param leaves list of leaf attributes of container.
* @param leafLists list of leaf-list attributes of container.
* @param leaves list of leaf attributes of container
* @param leafLists list of leaf-list attributes of container
*/
private void setDefaultConfigValueToChild(List<YangLeaf> leaves, List<YangLeafList> leafLists) {
/* If "config" is not specified, the default is the same as the parent
schema node's "config" value.*/
/*
* If "config" is not specified, the default is the same as the parent
* schema node's "config" value.
*/
if (leaves != null) {
for (YangLeaf leaf : leaves) {
if (leaf.isConfig() == null) {
......@@ -404,8 +408,10 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
}
}
/* If "config" is not specified, the default is the same as the parent
schema node's "config" value.*/
/*
* If "config" is not specified, the default is the same as the parent
* schema node's "config" value.
*/
if (leafLists != null) {
for (YangLeafList leafList : leafLists) {
if (leafList.isConfig() == null) {
......@@ -418,14 +424,16 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
/**
* Validates config statement of container.
*
* @param leaves list of leaf attributes of container.
* @param leafLists list of leaf-list attributes of container.
* @throws DataModelException a violation of data model rules.
* @param leaves list of leaf attributes of container
* @param leafLists list of leaf-list attributes of container
* @throws DataModelException a violation of data model rules
*/
private void validateConfig(List<YangLeaf> leaves, List<YangLeafList> leafLists) throws DataModelException {
/* If a node has "config" set to "false", no node underneath it can have
"config" set to "true".*/
/*
* If a node has "config" set to "false", no node underneath it can have
* "config" set to "true".
*/
if ((!isConfig) && (leaves != null)) {
for (YangLeaf leaf : leaves) {
if (leaf.isConfig()) {
......@@ -468,7 +476,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
/**
* Generate the java code corresponding to YANG container.
*
* @throws IOException when fails to generate the source files.
* @throws IOException when fails to generate the source files
*/
@Override
public void generateJavaCodeEntry() throws IOException {
......@@ -532,4 +540,18 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
}
return;
}
@Override
public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
// Asks helper to detect colliding child.
detectCollidingChildUtil(identifierName, dataType, this);
}
@Override
public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
if (this.getName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate input identifier detected, same as container \""
+ this.getName() + "\"");
}
}
}
......
......@@ -15,7 +15,7 @@ package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.utils.YangConstructType;
/*-
* The typedef Statement
......@@ -60,7 +60,7 @@ public class YangDerivedType implements Parsable {
/**
* Get the effective YANG built-in type of the derived data type.
*
* @return effective YANG built-in type of the derived data type.
* @return effective YANG built-in type of the derived data type
*/
public YangDataTypes getEffectiveYangBuiltInType() {
return effectiveYangBuiltInType;
......@@ -69,7 +69,7 @@ public class YangDerivedType implements Parsable {
/**
* Set the effective YANG built-in type of the derived data type.
*
* @param builtInType effective YANG built-in type of the derived data type.
* @param builtInType effective YANG built-in type of the derived data type
*/
public void setEffectiveYangBuiltInType(YangDataTypes builtInType) {
effectiveYangBuiltInType = builtInType;
......@@ -78,7 +78,7 @@ public class YangDerivedType implements Parsable {
/**
* Get the base type information.
*
* @return base type information.
* @return base type information
*/
public YangType<?> getBaseType() {
return baseType;
......@@ -87,7 +87,7 @@ public class YangDerivedType implements Parsable {
/**
* Get the base type information.
*
* @param baseType base type information.
* @param baseType base type information
*/
public void setBaseType(YangType<?> baseType) {
this.baseType = baseType;
......@@ -97,8 +97,8 @@ public class YangDerivedType implements Parsable {
* Get the parsable type.
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.DERIVED;
public YangConstructType getYangConstructType() {
return YangConstructType.DERIVED;
}
/**
......
......@@ -18,7 +18,7 @@ package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.utils.YangConstructType;
import java.util.Objects;
......@@ -73,7 +73,7 @@ public class YangEnum implements YangCommonInfo, Parsable {
private YangStatusType status;
/**
* value of ENUM.
* Value of ENUM.
*/
private int value;
......@@ -87,7 +87,7 @@ public class YangEnum implements YangCommonInfo, Parsable {
/**
* Get the named value.
*
* @return the named value.
* @return the named value
*/
public String getNamedValue() {
return namedValue;
......@@ -96,7 +96,7 @@ public class YangEnum implements YangCommonInfo, Parsable {
/**
* Set the named value.
*
* @param namedValue the named value to set.
* @param namedValue the named value to set
*/
public void setNamedValue(String namedValue) {
this.namedValue = namedValue;
......@@ -105,7 +105,7 @@ public class YangEnum implements YangCommonInfo, Parsable {
/**
* Get the description.
*
* @return the description.
* @return the description
*/
@Override
public String getDescription() {
......@@ -115,7 +115,7 @@ public class YangEnum implements YangCommonInfo, Parsable {
/**
* Set the description.
*
* @param description set the description.
* @param description set the description
*/
@Override
public void setDescription(String description) {
......@@ -125,7 +125,7 @@ public class YangEnum implements YangCommonInfo, Parsable {
/**
* Get the textual reference.
*
* @return the reference.
* @return the reference
*/
@Override
public String getReference() {
......@@ -135,7 +135,7 @@ public class YangEnum implements YangCommonInfo, Parsable {
/**
* Set the textual reference.
*
* @param reference the reference to set.
* @param reference the reference to set
*/
@Override
public void setReference(String reference) {
......@@ -145,7 +145,7 @@ public class YangEnum implements YangCommonInfo, Parsable {
/**
* Get the status.
*
* @return the status.
* @return the status
*/
@Override
public YangStatusType getStatus() {
......@@ -155,7 +155,7 @@ public class YangEnum implements YangCommonInfo, Parsable {
/**
* Set the status.
*
* @param status the status to set.
* @param status the status to set
*/
@Override
public void setStatus(YangStatusType status) {
......@@ -165,7 +165,7 @@ public class YangEnum implements YangCommonInfo, Parsable {
/**
* Get the value.
*
* @return the value.
* @return the value
*/
public int getValue() {
return value;
......@@ -174,7 +174,7 @@ public class YangEnum implements YangCommonInfo, Parsable {
/**
* Set the value.
*
* @param value the value to set.
* @param value the value to set
*/
public void setValue(int value) {
this.value = value;
......@@ -186,8 +186,8 @@ public class YangEnum implements YangCommonInfo, Parsable {
* @return ParsedDataType returns ENUM_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.ENUM_DATA;
public YangConstructType getYangConstructType() {
return YangConstructType.ENUM_DATA;
}
@Override
......@@ -210,7 +210,7 @@ public class YangEnum implements YangCommonInfo, Parsable {
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
......@@ -220,7 +220,7 @@ public class YangEnum implements YangCommonInfo, Parsable {
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
......
......@@ -21,7 +21,7 @@ import java.util.Set;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.utils.YangConstructType;
/*
* The enumeration built-in type represents values from a set of
......@@ -67,8 +67,8 @@ public class YangEnumeration implements Parsable {
/**
* Add ENUM information.
*
* @param enumInfo the ENUM information to be added.
* @throws DataModelException due to violation in data model rules.
* @param enumInfo the ENUM information to be added
* @throws DataModelException due to violation in data model rules
*/
public void addEnumInfo(YangEnum enumInfo) throws DataModelException {
if (!getEnumSet().add(enumInfo)) {
......@@ -100,14 +100,14 @@ public class YangEnumeration implements Parsable {
* @return returns ENUMERATION_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.ENUMERATION_DATA;
public YangConstructType getYangConstructType() {
return YangConstructType.ENUMERATION_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
......@@ -117,7 +117,7 @@ public class YangEnumeration implements Parsable {
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
......
......@@ -20,7 +20,7 @@ import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.utils.YangConstructType;
import org.onosproject.yangutils.translator.CachedFileHandle;
/*-
......@@ -110,7 +110,7 @@ public class YangGrouping extends YangNode
private YangStatusType status;
/**
* package of the generated java code.
* Package of the generated java code.
*/
private String pkg;
......@@ -124,7 +124,7 @@ public class YangGrouping extends YangNode
/**
* Get YANG grouping name.
*
* @return YANG grouping name.
* @return YANG grouping name
*/
@Override
public String getName() {
......@@ -134,7 +134,7 @@ public class YangGrouping extends YangNode
/**
* Set YANG grouping name.
*
* @param name YANG grouping name.
* @param name YANG grouping name
*/
@Override
public void setName(String name) {
......@@ -144,7 +144,7 @@ public class YangGrouping extends YangNode
/**
* Get the description.
*
* @return the description.
* @return the description
*/
@Override
public String getDescription() {
......@@ -154,7 +154,7 @@ public class YangGrouping extends YangNode
/**
* Set the description.
*
* @param description set the description.
* @param description set the description
*/
@Override
public void setDescription(String description) {
......@@ -164,7 +164,7 @@ public class YangGrouping extends YangNode
/**
* Get the list of leaves.
*
* @return the list of leaves.
* @return the list of leaves
*/
@Override
public List<YangLeaf> getListOfLeaf() {
......@@ -174,7 +174,7 @@ public class YangGrouping extends YangNode
/**
* Set the list of leaves.
*
* @param leafsList the list of leaf to set.
* @param leafsList the list of leaf to set
*/
private void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
......@@ -183,7 +183,7 @@ public class YangGrouping extends YangNode
/**
* Add a leaf.
*
* @param leaf the leaf to be added.
* @param leaf the leaf to be added
*/
@Override
public void addLeaf(YangLeaf leaf) {
......@@ -197,7 +197,7 @@ public class YangGrouping extends YangNode
/**
* Get the list of leaf-list.
*
* @return the list of leaf-list.
* @return the list of leaf-list
*/
@Override
public List<YangLeafList> getListOfLeafList() {
......@@ -207,7 +207,7 @@ public class YangGrouping extends YangNode
/**
* Set the list of leaf-list.
*
* @param listOfLeafList the list of leaf-list to set.
* @param listOfLeafList the list of leaf-list to set
*/
private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
......@@ -216,7 +216,7 @@ public class YangGrouping extends YangNode
/**
* Add a leaf-list.
*
* @param leafList the leaf-list to be added.
* @param leafList the leaf-list to be added
*/
@Override
public void addLeafList(YangLeafList leafList) {
......@@ -230,7 +230,7 @@ public class YangGrouping extends YangNode
/**
* Get the textual reference.
*
* @return the reference.
* @return the reference
*/
@Override
public String getReference() {
......@@ -240,7 +240,7 @@ public class YangGrouping extends YangNode
/**
* Set the textual reference.
*
* @param reference the reference to set.
* @param reference the reference to set
*/
@Override
public void setReference(String reference) {
......@@ -250,7 +250,7 @@ public class YangGrouping extends YangNode
/**
* Get the status.
*
* @return the status.
* @return the status
*/
@Override
public YangStatusType getStatus() {
......@@ -260,7 +260,7 @@ public class YangGrouping extends YangNode
/**
* Set the status.
*
* @param status the status to set.
* @param status the status to set
*/
@Override
public void setStatus(YangStatusType status) {
......@@ -270,17 +270,17 @@ public class YangGrouping extends YangNode
/**
* Returns the type of the data.
*
* @return returns GROUPING_DATA.
* @return returns GROUPING_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.GROUPING_DATA;
public YangConstructType getYangConstructType() {
return YangConstructType.GROUPING_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
......@@ -290,7 +290,7 @@ public class YangGrouping extends YangNode
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
......
......@@ -17,7 +17,7 @@ package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.utils.YangConstructType;
/*
* Reference:RFC 6020.
......@@ -94,7 +94,7 @@ public class YangImport implements Parsable {
/**
* Get the imported module name.
*
* @return the module name.
* @return the module name
*/
public String getModuleName() {
return name;
......@@ -113,7 +113,7 @@ public class YangImport implements Parsable {
* Get the prefix used to identify the entities from the imported module.
*
* @return the prefix used to identify the entities from the imported
* module.
* module
*/
public String getPrefixId() {
return prefixId;
......@@ -122,7 +122,7 @@ public class YangImport implements Parsable {
/**
* Set prefix identifier.
*
* @param prefixId set the prefix identifier of the imported module.
* @param prefixId set the prefix identifier of the imported module
*/
public void setPrefixId(String prefixId) {
this.prefixId = prefixId;
......@@ -131,7 +131,7 @@ public class YangImport implements Parsable {
/**
* Get the revision of the imported module.
*
* @return the revision of the imported module.
* @return the revision of the imported module
*/
public String getRevision() {
return revision;
......@@ -140,7 +140,7 @@ public class YangImport implements Parsable {
/**
* Set the revision of the imported module.
*
* @param rev set the revision of the imported module.
* @param rev set the revision of the imported module
*/
public void setRevision(String rev) {
revision = rev;
......@@ -152,8 +152,8 @@ public class YangImport implements Parsable {
* @return returns IMPORT_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.IMPORT_DATA;
public YangConstructType getYangConstructType() {
return YangConstructType.IMPORT_DATA;
}
/**
......
......@@ -17,7 +17,7 @@ package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.utils.YangConstructType;
/*
* Reference:RFC 6020.
......@@ -98,8 +98,8 @@ public class YangInclude implements Parsable {
* @return returns INCLUDE_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.INCLUDE_DATA;
public YangConstructType getYangConstructType() {
return YangConstructType.INCLUDE_DATA;
}
/**
......
......@@ -18,7 +18,7 @@ package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.utils.YangConstructType;
/*
* Reference:RFC 6020.
......@@ -108,7 +108,7 @@ public class YangLeaf implements YangCommonInfo, Parsable {
/**
* Get the name of leaf.
*
* @return the leaf name.
* @return the leaf name
*/
public String getLeafName() {
return name;
......@@ -117,7 +117,7 @@ public class YangLeaf implements YangCommonInfo, Parsable {
/**
* Set the name of leaf.
*
* @param leafName the leaf name to set.
* @param leafName the leaf name to set
*/
public void setLeafName(String leafName) {
name = leafName;
......@@ -126,7 +126,7 @@ public class YangLeaf implements YangCommonInfo, Parsable {
/**
* Get the config flag.
*
* @return if config flag.
* @return if config flag
*/
public Boolean isConfig() {
return isConfig;
......@@ -135,7 +135,7 @@ public class YangLeaf implements YangCommonInfo, Parsable {
/**
* Set the config flag.
*
* @param isCfg the flag value to set.
* @param isCfg the flag value to set
*/
public void setConfig(boolean isCfg) {
isConfig = isCfg;
......@@ -144,7 +144,7 @@ public class YangLeaf implements YangCommonInfo, Parsable {
/**
* Get the description.
*
* @return the description.
* @return the description
*/
@Override
public String getDescription() {
......@@ -154,7 +154,7 @@ public class YangLeaf implements YangCommonInfo, Parsable {
/**
* Set the description.
*
* @param description set the description.
* @param description set the description
*/
@Override
public void setDescription(String description) {
......@@ -164,7 +164,7 @@ public class YangLeaf implements YangCommonInfo, Parsable {
/**
* Get if the leaf is mandatory.
*
* @return if leaf is mandatory.
* @return if leaf is mandatory
*/
public boolean isMandatory() {
return isMandatory;
......@@ -182,7 +182,7 @@ public class YangLeaf implements YangCommonInfo, Parsable {
/**
* Get the textual reference.
*
* @return the reference.
* @return the reference
*/
@Override
public String getReference() {
......@@ -192,7 +192,7 @@ public class YangLeaf implements YangCommonInfo, Parsable {
/**
* Set the textual reference.
*
* @param reference the reference to set.
* @param reference the reference to set
*/
@Override
public void setReference(String reference) {
......@@ -202,7 +202,7 @@ public class YangLeaf implements YangCommonInfo, Parsable {
/**
* Get the status.
*
* @return the status.
* @return the status
*/
@Override
public YangStatusType getStatus() {
......@@ -212,7 +212,7 @@ public class YangLeaf implements YangCommonInfo, Parsable {
/**
* Set the status.
*
* @param status the status to set.
* @param status the status to set
*/
@Override
public void setStatus(YangStatusType status) {
......@@ -222,7 +222,7 @@ public class YangLeaf implements YangCommonInfo, Parsable {
/**
* Get the units.
*
* @return the units.
* @return the units
*/
public String getUnits() {
return units;
......@@ -231,7 +231,7 @@ public class YangLeaf implements YangCommonInfo, Parsable {
/**
* Set the units.
*
* @param units the units to set.
* @param units the units to set
*/
public void setUnits(String units) {
this.units = units;
......@@ -240,7 +240,7 @@ public class YangLeaf implements YangCommonInfo, Parsable {
/**
* Get the data type.
*
* @return the data type.
* @return the data type
*/
public YangType<?> getDataType() {
return dataType;
......@@ -249,7 +249,7 @@ public class YangLeaf implements YangCommonInfo, Parsable {
/**
* Set the data type.
*
* @param dataType the data type to set.
* @param dataType the data type to set
*/
public void setDataType(YangType<?> dataType) {
this.dataType = dataType;
......@@ -258,17 +258,17 @@ public class YangLeaf implements YangCommonInfo, Parsable {
/**
* Returns the type of the parsed data.
*
* @return returns LEAF_DATA.
* @return returns LEAF_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.LEAF_DATA;
public YangConstructType getYangConstructType() {
return YangConstructType.LEAF_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
......@@ -279,7 +279,7 @@ public class YangLeaf implements YangCommonInfo, Parsable {
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
......
......@@ -18,7 +18,7 @@ package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.utils.YangConstructType;
/*
* Reference:RFC 6020.
......@@ -130,7 +130,7 @@ public class YangLeafList implements YangCommonInfo, Parsable {
/**
* Get the leaf-list name.
*
* @return the leaf-list name.
* @return the leaf-list name
*/
public String getLeafName() {
return name;
......@@ -139,7 +139,7 @@ public class YangLeafList implements YangCommonInfo, Parsable {
/**
* Set the leaf-list name.
*
* @param leafListName the leaf-list name to set.
* @param leafListName the leaf-list name to set
*/
public void setLeafName(String leafListName) {
name = leafListName;
......@@ -148,7 +148,7 @@ public class YangLeafList implements YangCommonInfo, Parsable {
/**
* Get the config flag.
*
* @return the config flag.
* @return the config flag
*/
public Boolean isConfig() {
return isConfig;
......@@ -157,7 +157,7 @@ public class YangLeafList implements YangCommonInfo, Parsable {
/**
* Set the config flag.
*
* @param isCfg the config flag.
* @param isCfg the config flag
*/
public void setConfig(boolean isCfg) {
isConfig = isCfg;
......@@ -166,7 +166,7 @@ public class YangLeafList implements YangCommonInfo, Parsable {
/**
* Get the description.
*
* @return the description.
* @return the description
*/
@Override
public String getDescription() {
......@@ -176,7 +176,7 @@ public class YangLeafList implements YangCommonInfo, Parsable {
/**
* Set the description.
*
* @param description set the description.
* @param description set the description
*/
@Override
public void setDescription(String description) {
......@@ -186,7 +186,7 @@ public class YangLeafList implements YangCommonInfo, Parsable {
/**
* Get the max elements no.
*
* @return the max elements no.
* @return the max elements no
*/
public int getMaxElelements() {
return maxElelements;
......@@ -195,7 +195,7 @@ public class YangLeafList implements YangCommonInfo, Parsable {
/**
* Set the max elements no.
*
* @param maxElelements max elements no.
* @param maxElelements max elements no
*/
public void setMaxElelements(int maxElelements) {
this.maxElelements = maxElelements;
......@@ -204,7 +204,7 @@ public class YangLeafList implements YangCommonInfo, Parsable {
/**
* Get the min elements no.
*
* @return the min elements no.
* @return the min elements no
*/
public int getMinElements() {
return minElements;
......@@ -213,7 +213,7 @@ public class YangLeafList implements YangCommonInfo, Parsable {
/**
* Set the min elements no.
*
* @param minElements the min elements no.
* @param minElements the min elements no
*/
public void setMinElements(int minElements) {
this.minElements = minElements;
......@@ -222,7 +222,7 @@ public class YangLeafList implements YangCommonInfo, Parsable {
/**
* Get the textual reference.
*
* @return the reference.
* @return the reference
*/
@Override
public String getReference() {
......@@ -232,7 +232,7 @@ public class YangLeafList implements YangCommonInfo, Parsable {
/**
* Set the textual reference.
*
* @param reference the reference to set.
* @param reference the reference to set
*/
@Override
public void setReference(String reference) {
......@@ -242,7 +242,7 @@ public class YangLeafList implements YangCommonInfo, Parsable {
/**
* Get the status.
*
* @return the status.
* @return the status
*/
@Override
public YangStatusType getStatus() {
......@@ -252,7 +252,7 @@ public class YangLeafList implements YangCommonInfo, Parsable {
/**
* Set the status.
*
* @param status the status to set.
* @param status the status to set
*/
@Override
public void setStatus(YangStatusType status) {
......@@ -262,7 +262,7 @@ public class YangLeafList implements YangCommonInfo, Parsable {
/**
* Get the units.
*
* @return the units.
* @return the units
*/
public String getUnits() {
return units;
......@@ -271,7 +271,7 @@ public class YangLeafList implements YangCommonInfo, Parsable {
/**
* Set the units.
*
* @param units the units to set.
* @param units the units to set
*/
public void setUnits(String units) {
this.units = units;
......@@ -280,7 +280,7 @@ public class YangLeafList implements YangCommonInfo, Parsable {
/**
* Get the data type.
*
* @return the data type.
* @return the data type
*/
public YangType<?> getDataType() {
return dataType;
......@@ -289,7 +289,7 @@ public class YangLeafList implements YangCommonInfo, Parsable {
/**
* Set the data type.
*
* @param dataType the data type to set.
* @param dataType the data type to set
*/
public void setDataType(YangType<?> dataType) {
this.dataType = dataType;
......@@ -298,17 +298,17 @@ public class YangLeafList implements YangCommonInfo, Parsable {
/**
* Returns the type of the parsed data.
*
* @return returns LEAF_LIST_DATA.
* @return returns LEAF_LIST_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.LEAF_LIST_DATA;
public YangConstructType getYangConstructType() {
return YangConstructType.LEAF_LIST_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
......@@ -319,7 +319,7 @@ public class YangLeafList implements YangCommonInfo, Parsable {
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
......
......@@ -16,13 +16,14 @@
package org.onosproject.yangutils.datamodel;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.translator.CachedFileHandle;
import org.onosproject.yangutils.utils.YangConstructType;
import java.util.LinkedList;
import java.util.List;
/*-
* The "list" statement is used to define an interior data node in the
......@@ -67,10 +68,10 @@ import org.onosproject.yangutils.translator.CachedFileHandle;
* List data represented in YANG.
*/
public class YangList extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable {
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
/**
* name of the YANG list.
* Name of the YANG list.
*/
private String name;
......@@ -177,7 +178,7 @@ public class YangList extends YangNode
/**
* Get the YANG list name.
*
* @return YANG list name.
* @return YANG list name
*/
@Override
public String getName() {
......@@ -187,7 +188,7 @@ public class YangList extends YangNode
/**
* Set the YANG list name.
*
* @param name YANG list name.
* @param name YANG list name
*/
@Override
public void setName(String name) {
......@@ -206,7 +207,7 @@ public class YangList extends YangNode
/**
* Set the config flag.
*
* @param isCfg the config flag.
* @param isCfg the config flag
*/
public void setConfig(boolean isCfg) {
isConfig = isCfg;
......@@ -215,7 +216,7 @@ public class YangList extends YangNode
/**
* Get the description.
*
* @return the description.
* @return the description
*/
@Override
public String getDescription() {
......@@ -225,7 +226,7 @@ public class YangList extends YangNode
/**
* Set the description.
*
* @param description set the description.
* @param description set the description
*/
@Override
public void setDescription(String description) {
......@@ -235,7 +236,7 @@ public class YangList extends YangNode
/**
* Get the list of key field names.
*
* @return the list of key field names.
* @return the list of key field names
*/
public List<String> getKeyList() {
return keyList;
......@@ -244,7 +245,7 @@ public class YangList extends YangNode
/**
* Set the list of key field names.
*
* @param keyList the list of key field names.
* @param keyList the list of key field names
*/
private void setKeyList(List<String> keyList) {
this.keyList = keyList;
......@@ -254,7 +255,7 @@ public class YangList extends YangNode
* Add a key field name.
*
* @param key key field name.
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
public void addKey(String key) throws DataModelException {
if (getKeyList() == null) {
......@@ -272,7 +273,7 @@ public class YangList extends YangNode
/**
* Get the list of leaves.
*
* @return the list of leaves.
* @return the list of leaves
*/
@Override
public List<YangLeaf> getListOfLeaf() {
......@@ -282,7 +283,7 @@ public class YangList extends YangNode
/**
* Set the list of leaves.
*
* @param leafsList the list of leaf to set.
* @param leafsList the list of leaf to set
*/
private void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
......@@ -291,7 +292,7 @@ public class YangList extends YangNode
/**
* Add a leaf.
*
* @param leaf the leaf to be added.
* @param leaf the leaf to be added
*/
@Override
public void addLeaf(YangLeaf leaf) {
......@@ -305,7 +306,7 @@ public class YangList extends YangNode
/**
* Get the list of leaf-list.
*
* @return the list of leaf-list.
* @return the list of leaf-list
*/
@Override
public List<YangLeafList> getListOfLeafList() {
......@@ -315,7 +316,7 @@ public class YangList extends YangNode
/**
* Set the list of leaf-list.
*
* @param listOfLeafList the list of leaf-list to set.
* @param listOfLeafList the list of leaf-list to set
*/
private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
......@@ -324,7 +325,7 @@ public class YangList extends YangNode
/**
* Add a leaf-list.
*
* @param leafList the leaf-list to be added.
* @param leafList the leaf-list to be added
*/
@Override
public void addLeafList(YangLeafList leafList) {
......@@ -338,7 +339,7 @@ public class YangList extends YangNode
/**
* Get the max elements.
*
* @return the max elements.
* @return the max elements
*/
public int getMaxElelements() {
return maxElelements;
......@@ -347,7 +348,7 @@ public class YangList extends YangNode
/**
* Set the max elements.
*
* @param maxElelements the max elements.
* @param maxElelements the max elements
*/
public void setMaxElelements(int maxElelements) {
this.maxElelements = maxElelements;
......@@ -356,7 +357,7 @@ public class YangList extends YangNode
/**
* Get the minimum elements.
*
* @return the minimum elements.
* @return the minimum elements
*/
public int getMinElements() {
return minElements;
......@@ -365,7 +366,7 @@ public class YangList extends YangNode
/**
* Set the minimum elements.
*
* @param minElements the minimum elements.
* @param minElements the minimum elements
*/
public void setMinElements(int minElements) {
this.minElements = minElements;
......@@ -374,7 +375,7 @@ public class YangList extends YangNode
/**
* Get the textual reference.
*
* @return the reference.
* @return the reference
*/
@Override
public String getReference() {
......@@ -384,7 +385,7 @@ public class YangList extends YangNode
/**
* Set the textual reference.
*
* @param reference the reference to set.
* @param reference the reference to set
*/
@Override
public void setReference(String reference) {
......@@ -394,7 +395,7 @@ public class YangList extends YangNode
/**
* Get the status.
*
* @return the status.
* @return the status
*/
@Override
public YangStatusType getStatus() {
......@@ -404,7 +405,7 @@ public class YangList extends YangNode
/**
* Set the status.
*
* @param status the status to set.
* @param status the status to set
*/
@Override
public void setStatus(YangStatusType status) {
......@@ -414,17 +415,17 @@ public class YangList extends YangNode
/**
* Returns the type of the parsed data.
*
* @return returns LIST_DATA.
* @return returns LIST_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.LIST_DATA;
public YangConstructType getYangConstructType() {
return YangConstructType.LIST_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
......@@ -434,7 +435,7 @@ public class YangList extends YangNode
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
......@@ -464,8 +465,8 @@ public class YangList extends YangNode
* Sets the config's value to all leaf if leaf's config statement is not
* specified.
*
* @param leaves list of leaf attributes of YANG list.
* @param leafLists list of leaf-list attributes of YANG list.
* @param leaves list of leaf attributes of YANG list
* @param leafLists list of leaf-list attributes of YANG list
*/
private void setDefaultConfigValueToChild(List<YangLeaf> leaves, List<YangLeafList> leafLists) {
......@@ -497,9 +498,9 @@ public class YangList extends YangNode
/**
* Validates config statement of YANG list.
*
* @param leaves list of leaf attributes of YANG list.
* @param leafLists list of leaf-list attributes of YANG list.
* @throws DataModelException a violation of data model rules.
* @param leaves list of leaf attributes of YANG list
* @param leafLists list of leaf-list attributes of YANG list
* @throws DataModelException a violation of data model rules
*/
private void validateConfig(List<YangLeaf> leaves, List<YangLeafList> leafLists) throws DataModelException {
......@@ -529,9 +530,9 @@ public class YangList extends YangNode
/**
* Validates key statement of list.
*
* @param leaves list of leaf attributes of list.
* @param keys list of key attributes of list.
* @throws DataModelException a violation of data model rules.
* @param leaves list of leaf attributes of list
* @param keys list of key attributes of list
* @throws DataModelException a violation of data model rules
*/
private void validateLeafKey(List<YangLeaf> leaves, List<String> keys) throws DataModelException {
boolean leafFound = false;
......@@ -574,9 +575,9 @@ public class YangList extends YangNode
/**
* Validates key statement of list.
*
* @param leafLists list of leaf-list attributes of list.
* @param keys list of key attributes of list.
* @throws DataModelException a violation of data model rules.
* @param leafLists list of leaf-list attributes of list
* @param keys list of key attributes of list
* @throws DataModelException a violation of data model rules
*/
private void validateLeafListKey(List<YangLeafList> leafLists, List<String> keys) throws DataModelException {
boolean leafFound = false;
......@@ -668,4 +669,18 @@ public class YangList extends YangNode
// TODO Auto-generated method stub
}
@Override
public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
// Asks helper to detect colliding child.
detectCollidingChildUtil(identifierName, dataType, this);
}
@Override
public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
if (this.getName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate input identifier detected, same as list \"" +
this.getName() + "\"");
}
}
}
......
......@@ -15,20 +15,21 @@
*/
package org.onosproject.yangutils.datamodel;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.translator.CachedFileHandle;
import org.onosproject.yangutils.translator.CodeGenerator;
import org.onosproject.yangutils.translator.GeneratedFileType;
import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
import org.onosproject.yangutils.utils.UtilConstants;
import org.onosproject.yangutils.utils.YangConstructType;
import org.onosproject.yangutils.utils.io.impl.FileSystemUtil;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
/*-
* Reference:RFC 6020.
* The "module" statement defines the module's name,
......@@ -73,7 +74,7 @@ import org.onosproject.yangutils.utils.io.impl.FileSystemUtil;
* Data model node to maintain information defined in YANG module.
*/
public class YangModule extends YangNode
implements YangLeavesHolder, YangDesc, YangReference, Parsable, CodeGenerator {
implements YangLeavesHolder, YangDesc, YangReference, Parsable, CodeGenerator, CollisionDetector {
/**
* Name of the module.
......@@ -588,8 +589,8 @@ public class YangModule extends YangNode
* @return returns MODULE_DATA.
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.MODULE_DATA;
public YangConstructType getYangConstructType() {
return YangConstructType.MODULE_DATA;
}
/**
......@@ -697,4 +698,15 @@ public class YangModule extends YangNode
module.addToNestedReferenceResoulutionList(node);
return;
}
@Override
public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
// Asks helper to detect colliding child.
detectCollidingChildUtil(identifierName, dataType, this);
}
@Override
public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
// Not required as module doesn't have any parent.
}
}
......
......@@ -17,7 +17,7 @@ package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.utils.YangConstructType;
/*-
* The "must" statement, which is optional, takes as an argument a string that
......@@ -59,7 +59,7 @@ public class YangMust implements YangDesc, YangReference, Parsable {
private String description;
/**
* reference string.
* Reference string.
*/
private String reference;
......@@ -72,7 +72,7 @@ public class YangMust implements YangDesc, YangReference, Parsable {
/**
* Get the constraint.
*
* @return the constraint.
* @return the constraint
*/
public String getConstratint() {
return constratint;
......@@ -90,7 +90,7 @@ public class YangMust implements YangDesc, YangReference, Parsable {
/**
* Get the description.
*
* @return the description.
* @return the description
*/
@Override
public String getDescription() {
......@@ -100,7 +100,7 @@ public class YangMust implements YangDesc, YangReference, Parsable {
/**
* Set the description.
*
* @param description set the description.
* @param description set the description
*/
@Override
public void setDescription(String description) {
......@@ -110,7 +110,7 @@ public class YangMust implements YangDesc, YangReference, Parsable {
/**
* Get the textual reference.
*
* @return the reference.
* @return the reference
*/
@Override
public String getReference() {
......@@ -120,7 +120,7 @@ public class YangMust implements YangDesc, YangReference, Parsable {
/**
* Set the textual reference.
*
* @param reference the reference to set.
* @param reference the reference to set
*/
@Override
public void setReference(String reference) {
......@@ -133,14 +133,14 @@ public class YangMust implements YangDesc, YangReference, Parsable {
* @return returns MUST_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.MUST_DATA;
public YangConstructType getYangConstructType() {
return YangConstructType.MUST_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
......@@ -150,7 +150,7 @@ public class YangMust implements YangDesc, YangReference, Parsable {
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
......
......@@ -18,7 +18,7 @@ package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.utils.YangConstructType;
/*
* Reference:RFC 6020.
......@@ -45,7 +45,7 @@ public class YangNameSpace implements Parsable {
/**
* Get the name space URI.
*
* @return the URI.
* @return the URI
*/
public String getUri() {
return uri;
......@@ -63,17 +63,17 @@ public class YangNameSpace implements Parsable {
/**
* Returns the type of the parsed data.
*
* @return returns NAMESPACE_DATA.
* @return returns NAMESPACE_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.NAMESPACE_DATA;
public YangConstructType getYangConstructType() {
return YangConstructType.NAMESPACE_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
......@@ -84,7 +84,7 @@ public class YangNameSpace implements Parsable {
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
......
......@@ -17,7 +17,7 @@ package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.utils.YangConstructType;
/*
* Reference:RFC 6020.
......@@ -86,7 +86,7 @@ public class YangRevision implements YangDesc, YangReference, Parsable {
/**
* Get the description.
*
* @return the description.
* @return the description
*/
@Override
public String getDescription() {
......@@ -96,7 +96,7 @@ public class YangRevision implements YangDesc, YangReference, Parsable {
/**
* Set the description.
*
* @param description set the description.
* @param description set the description
*/
@Override
public void setDescription(String description) {
......@@ -106,7 +106,7 @@ public class YangRevision implements YangDesc, YangReference, Parsable {
/**
* Get the textual reference.
*
* @return the reference.
* @return the reference
*/
@Override
public String getReference() {
......@@ -116,7 +116,7 @@ public class YangRevision implements YangDesc, YangReference, Parsable {
/**
* Set the textual reference.
*
* @param reference the reference to set.
* @param reference the reference to set
*/
@Override
public void setReference(String reference) {
......@@ -126,17 +126,17 @@ public class YangRevision implements YangDesc, YangReference, Parsable {
/**
* Returns the type of the parsed data.
*
* @return returns REVISION_DATA.
* @return returns REVISION_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.REVISION_DATA;
public YangConstructType getYangConstructType() {
return YangConstructType.REVISION_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
......@@ -147,7 +147,7 @@ public class YangRevision implements YangDesc, YangReference, Parsable {
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
......
......@@ -15,13 +15,14 @@
*/
package org.onosproject.yangutils.datamodel;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.translator.CachedFileHandle;
import org.onosproject.yangutils.utils.YangConstructType;
import java.util.LinkedList;
import java.util.List;
/*
* Reference RFC 6020.
......@@ -74,7 +75,7 @@ import org.onosproject.yangutils.translator.CachedFileHandle;
* Data model node to maintain information defined in YANG sub-module.
*/
public class YangSubModule extends YangNode
implements YangLeavesHolder, YangDesc, YangReference, Parsable {
implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector {
/**
* Name of sub module.
......@@ -186,7 +187,7 @@ public class YangSubModule extends YangNode
/**
* Set the module info.
*
* @param belongsTo module info to set.
* @param belongsTo module info to set
*/
public void setBelongsTo(YangBelongsTo belongsTo) {
this.belongsTo = belongsTo;
......@@ -195,7 +196,7 @@ public class YangSubModule extends YangNode
/**
* Get the contact.
*
* @return the contact.
* @return the contact
*/
public String getContact() {
return contact;
......@@ -213,7 +214,7 @@ public class YangSubModule extends YangNode
/**
* Get the description.
*
* @return the description.
* @return the description
*/
@Override
public String getDescription() {
......@@ -223,7 +224,7 @@ public class YangSubModule extends YangNode
/**
* Set the description.
*
* @param description set the description.
* @param description set the description
*/
@Override
public void setDescription(String description) {
......@@ -233,7 +234,7 @@ public class YangSubModule extends YangNode
/**
* Get the list of imported modules.
*
* @return the list of imported modules.
* @return the list of imported modules
*/
public List<YangImport> getImportList() {
return importList;
......@@ -242,7 +243,7 @@ public class YangSubModule extends YangNode
/**
* prevent setting the import list from outside.
*
* @param importList the import list to set.
* @param importList the import list to set
*/
private void setImportList(List<YangImport> importList) {
this.importList = importList;
......@@ -251,7 +252,7 @@ public class YangSubModule extends YangNode
/**
* Add the imported module information to the import list.
*
* @param importedModule module being imported.
* @param importedModule module being imported
*/
public void addImportedInfo(YangImport importedModule) {
......@@ -267,7 +268,7 @@ public class YangSubModule extends YangNode
/**
* Get the list of included sub modules.
*
* @return the included list of sub modules.
* @return the included list of sub modules
*/
public List<YangInclude> getIncludeList() {
return includeList;
......@@ -276,7 +277,7 @@ public class YangSubModule extends YangNode
/**
* Set the list of included sub modules.
*
* @param includeList the included list to set.
* @param includeList the included list to set
*/
private void setIncludeList(List<YangInclude> includeList) {
this.includeList = includeList;
......@@ -285,7 +286,7 @@ public class YangSubModule extends YangNode
/**
* Add the included sub module information to the include list.
*
* @param includeModule submodule being included.
* @param includeModule submodule being included
*/
public void addIncludedInfo(YangInclude includeModule) {
......@@ -300,7 +301,7 @@ public class YangSubModule extends YangNode
/**
* Get the list of leaves.
*
* @return the list of leaves.
* @return the list of leaves
*/
@Override
public List<YangLeaf> getListOfLeaf() {
......@@ -310,7 +311,7 @@ public class YangSubModule extends YangNode
/**
* Set the list of leaves.
*
* @param leafsList the list of leaf to set.
* @param leafsList the list of leaf to set
*/
private void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
......@@ -319,7 +320,7 @@ public class YangSubModule extends YangNode
/**
* Add a leaf.
*
* @param leaf the leaf to be added.
* @param leaf the leaf to be added
*/
@Override
public void addLeaf(YangLeaf leaf) {
......@@ -333,7 +334,7 @@ public class YangSubModule extends YangNode
/**
* Get the list of leaf-list.
*
* @return the list of leaf-list.
* @return the list of leaf-list
*/
@Override
public List<YangLeafList> getListOfLeafList() {
......@@ -343,7 +344,7 @@ public class YangSubModule extends YangNode
/**
* Set the list of leaf-list.
*
* @param listOfLeafList the list of leaf-list to set.
* @param listOfLeafList the list of leaf-list to set
*/
private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
......@@ -352,7 +353,7 @@ public class YangSubModule extends YangNode
/**
* Add a leaf-list.
*
* @param leafList the leaf-list to be added.
* @param leafList the leaf-list to be added
*/
@Override
public void addLeafList(YangLeafList leafList) {
......@@ -366,7 +367,7 @@ public class YangSubModule extends YangNode
/**
* Get the sub-modules organization.
*
* @return the organization.
* @return the organization
*/
public String getOrganization() {
return organization;
......@@ -375,7 +376,7 @@ public class YangSubModule extends YangNode
/**
* Set the sub-modules organization.
*
* @param org the organization to set.
* @param org the organization to set
*/
public void setOrganization(String org) {
organization = org;
......@@ -384,7 +385,7 @@ public class YangSubModule extends YangNode
/**
* Get the textual reference.
*
* @return the reference.
* @return the reference
*/
@Override
public String getReference() {
......@@ -394,7 +395,7 @@ public class YangSubModule extends YangNode
/**
* Set the textual reference.
*
* @param reference the reference to set.
* @param reference the reference to set
*/
@Override
public void setReference(String reference) {
......@@ -404,7 +405,7 @@ public class YangSubModule extends YangNode
/**
* Get the revision.
*
* @return the revision.
* @return the revision
*/
public YangRevision getRevision() {
return revision;
......@@ -413,7 +414,7 @@ public class YangSubModule extends YangNode
/**
* Set the revision.
*
* @param revision the revision to set.
* @param revision the revision to set
*/
public void setRevision(YangRevision revision) {
this.revision = revision;
......@@ -422,7 +423,7 @@ public class YangSubModule extends YangNode
/**
* Get the version.
*
* @return the version.
* @return the version
*/
public byte getVersion() {
return version;
......@@ -431,7 +432,7 @@ public class YangSubModule extends YangNode
/**
* Set the version.
*
* @param version the version to set.
* @param version the version to set
*/
public void setVersion(byte version) {
this.version = version;
......@@ -440,17 +441,17 @@ public class YangSubModule extends YangNode
/**
* Returns the type of the parsed data.
*
* @return returns SUB_MODULE_DATA.
* @return returns SUB_MODULE_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.SUB_MODULE_DATA;
public YangConstructType getYangConstructType() {
return YangConstructType.SUB_MODULE_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
......@@ -460,7 +461,7 @@ public class YangSubModule extends YangNode
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
......@@ -515,4 +516,15 @@ public class YangSubModule extends YangNode
// TODO Auto-generated method stub
}
@Override
public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
// Asks helper to detect colliding child.
detectCollidingChildUtil(identifierName, dataType, this);
}
@Override
public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
// Not required as module doesn't have any parent.
}
}
......
......@@ -18,7 +18,7 @@ package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.utils.YangConstructType;
/*
* Reference:RFC 6020.
......@@ -77,7 +77,7 @@ public class YangType<T> implements Parsable {
/**
* Get the name of data type.
*
* @return the name of data type.
* @return the name of data type
*/
public String getDataTypeName() {
return dataTypeName;
......@@ -95,7 +95,7 @@ public class YangType<T> implements Parsable {
/**
* Get the type of data.
*
* @return the data type.
* @return the data type
*/
public YangDataTypes getDataType() {
return dataType;
......@@ -104,7 +104,7 @@ public class YangType<T> implements Parsable {
/**
* Set the type of data.
*
* @param dataType data type.
* @param dataType data type
*/
public void setDataType(YangDataTypes dataType) {
this.dataType = dataType;
......@@ -113,7 +113,7 @@ public class YangType<T> implements Parsable {
/**
* Get the data type meta data.
*
* @return the data type meta data.
* @return the data type meta data
*/
public T getDataTypeExtendedInfo() {
return dataTypeExtendedInfo;
......@@ -131,17 +131,17 @@ public class YangType<T> implements Parsable {
/**
* Returns the type of the parsed data.
*
* @return returns TYPE_DATA.
* @return returns TYPE_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.TYPE_DATA;
public YangConstructType getYangConstructType() {
return YangConstructType.TYPE_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
......@@ -152,7 +152,7 @@ public class YangType<T> implements Parsable {
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
......
......@@ -17,7 +17,7 @@ package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.utils.YangConstructType;
import org.onosproject.yangutils.translator.CachedFileHandle;
/*-
......@@ -103,7 +103,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
/**
* Get the default value.
*
* @return the default value.
* @return the default value
*/
public String getDefaultValueInString() {
return defaultValueInString;
......@@ -112,7 +112,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
/**
* Set the default value.
*
* @param defaultValueInString the default value.
* @param defaultValueInString the default value
*/
public void setDefaultValueInString(String defaultValueInString) {
this.defaultValueInString = defaultValueInString;
......@@ -121,7 +121,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
/**
* Get the description.
*
* @return the description.
* @return the description
*/
@Override
public String getDescription() {
......@@ -131,7 +131,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
/**
* Set the description.
*
* @param description set the description.
* @param description set the description
*/
@Override
public void setDescription(String description) {
......@@ -141,7 +141,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
/**
* Get the textual reference.
*
* @return the reference.
* @return the reference
*/
@Override
public String getReference() {
......@@ -151,7 +151,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
/**
* Set the textual reference.
*
* @param reference the reference to set.
* @param reference the reference to set
*/
@Override
public void setReference(String reference) {
......@@ -161,7 +161,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
/**
* Get the status.
*
* @return the status.
* @return the status
*/
@Override
public YangStatusType getStatus() {
......@@ -171,7 +171,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
/**
* Set the status.
*
* @param status the status to set.
* @param status the status to set
*/
@Override
public void setStatus(YangStatusType status) {
......@@ -181,7 +181,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
/**
* Get the derived type.
*
* @return the derived type.
* @return the derived type
*/
public YangType<YangDerivedType> getDerivedType() {
return derivedType;
......@@ -190,7 +190,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
/**
* Set the derived type.
*
* @param derivedType the derived type.
* @param derivedType the derived type
*/
public void setDerivedType(YangType<YangDerivedType> derivedType) {
this.derivedType = derivedType;
......@@ -220,14 +220,14 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
* @return returns TYPEDEF_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.TYPEDEF_DATA;
public YangConstructType getYangConstructType() {
return YangConstructType.TYPEDEF_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
......@@ -237,7 +237,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
......@@ -274,7 +274,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
/**
* Get the YANG name of the typedef.
*
* @return YANG name of the typedef.
* @return YANG name of the typedef
*/
@Override
public String getName() {
......@@ -287,7 +287,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
/**
* Set YANG name of the typedef.
*
* @param name YANG name of the typedef.
* @param name YANG name of the typedef
*/
@Override
public void setName(String name) {
......@@ -330,7 +330,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
/**
* Set the mapped java package.
*
* @param pakg mapped java package.
* @param pakg mapped java package
*/
@Override
public void setPackage(String pakg) {
......@@ -341,7 +341,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
/**
* Get the file handle of the cached file used during code generation.
*
* @return cached file handle.
* @return cached file handle
*/
@Override
public CachedFileHandle getFileHandle() {
......@@ -352,7 +352,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
/**
* Set the file handle to be used used for code generation.
*
* @param fileHandle cached file handle.
* @param fileHandle cached file handle
*/
@Override
public void setFileHandle(CachedFileHandle fileHandle) {
......
......@@ -17,7 +17,7 @@ package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.utils.YangConstructType;
import org.onosproject.yangutils.translator.CachedFileHandle;
/*-
......@@ -90,7 +90,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
/**
* Get the name.
*
* @return the name.
* @return the name
*/
public String getRefGroupingName() {
return name;
......@@ -108,7 +108,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
/**
* Get the referred group.
*
* @return the referred group.
* @return the referred group
*/
public YangGrouping getRefGroup() {
return refGroup;
......@@ -117,7 +117,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
/**
* Set the referred group.
*
* @param refGroup the referred group.
* @param refGroup the referred group
*/
public void setRefGroup(YangGrouping refGroup) {
this.refGroup = refGroup;
......@@ -126,7 +126,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
/**
* Get the description.
*
* @return the description.
* @return the description
*/
@Override
public String getDescription() {
......@@ -136,7 +136,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
/**
* Set the description.
*
* @param description set the description.
* @param description set the description
*/
@Override
public void setDescription(String description) {
......@@ -146,7 +146,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
/**
* Get the textual reference.
*
* @return the reference.
* @return the reference
*/
@Override
public String getReference() {
......@@ -156,7 +156,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
/**
* Set the textual reference.
*
* @param reference the reference to set.
* @param reference the reference to set
*/
@Override
public void setReference(String reference) {
......@@ -166,7 +166,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
/**
* Get the status.
*
* @return the status.
* @return the status
*/
@Override
public YangStatusType getStatus() {
......@@ -176,7 +176,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
/**
* Set the status.
*
* @param status the status to set.
* @param status the status to set
*/
@Override
public void setStatus(YangStatusType status) {
......@@ -186,17 +186,17 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
/**
* Returns the type of the data.
*
* @return returns USES_DATA.
* @return returns USES_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.USES_DATA;
public YangConstructType getYangConstructType() {
return YangConstructType.USES_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
......@@ -206,7 +206,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
......
/*
* Copyright 2016 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.datamodel.utils;
import org.onosproject.yangutils.datamodel.CollisionDetector;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.utils.YangConstructType;
/**
* Utilities for data model tree.
*/
public final class DataModelUtils {
/**
* Creates a new data model tree utility.
*/
private DataModelUtils() {
}
/**
* Detects the colliding identifier name in a given YANG node and its child.
*
* @param identifierName name for which collision detection is to be
* checked.
* @param dataType type of YANG node asking for detecting collision.
* @param node instance of calling node.
* @throws DataModelException a violation of data model rules.
*/
public static void detectCollidingChildUtil(String identifierName, YangConstructType dataType, YangNode node)
throws DataModelException {
if (((YangLeavesHolder) node).getListOfLeaf() != null) {
for (YangLeaf leaf : ((YangLeavesHolder) node).getListOfLeaf()) {
if (leaf.getLeafName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf \""
+ leaf.getLeafName() + "\"");
}
}
}
if (((YangLeavesHolder) node).getListOfLeafList() != null) {
for (YangLeafList leafList : ((YangLeavesHolder) node).getListOfLeafList()) {
if (leafList.getLeafName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf " +
"list \"" + leafList.getLeafName() + "\"");
}
}
}
node = node.getChild();
while ((node != null)) {
if (node instanceof CollisionDetector) {
((CollisionDetector) node).detectSelfCollision(identifierName, dataType);
}
node = node.getNextSibling();
}
}
}
/*
* Copyright 2016 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.
*/
/**
* Utilities for checking data model tree collisions.
*/
package org.onosproject.yangutils.datamodel.utils;
\ No newline at end of file
......@@ -17,6 +17,7 @@
package org.onosproject.yangutils.parser;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.utils.YangConstructType;
/**
* Abstraction of an entity which process the data of lexer's parse tree.
......@@ -24,11 +25,11 @@ import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
public interface Parsable {
/**
* Get the type of parsable data.
* Get the type of YANG construct data.
*
* @return the type of parsable data
* @return the type of YANG construct data.
*/
ParsableDataType getParsableDataType();
YangConstructType getYangConstructType();
/**
* Check if the node is valid as per YANG grammar's syntax and semantics.
......
......@@ -29,10 +29,10 @@ public interface YangUtilsParser {
/**
* It is an entry function to initiate the YANG file parsing.
*
* @param file input YANG file.
* @return YangNode root node of the data model tree.
* @throws ParserException when fails to get the data model.
* @throws IOException when there is an exception in IO operation.
* @param file input YANG file
* @return YangNode root node of the data model tree
* @throws ParserException when fails to get the data model
* @throws IOException when there is an exception in IO operation
*/
YangNode getDataModel(String file) throws IOException, ParserException;
}
......
......@@ -88,7 +88,7 @@ public class TreeWalkListener implements GeneratedYangListener {
/**
* Returns root node.
*
* @return rootNode of data model tree.
* @return rootNode of data model tree
*/
public YangNode getRootNode() {
return rootNode;
......@@ -97,7 +97,7 @@ public class TreeWalkListener implements GeneratedYangListener {
/**
* Set parsed data stack.
*
* @param parsedDataStack stack of parsable data objects.
* @param parsedDataStack stack of parsable data objects
*/
public void setParsedDataStack(Stack<Parsable> parsedDataStack) {
this.parsedDataStack = parsedDataStack;
......@@ -106,7 +106,7 @@ public class TreeWalkListener implements GeneratedYangListener {
/**
* Set root node.
*
* @param rootNode root node of data model tree.
* @param rootNode root node of data model tree
*/
public void setRootNode(YangNode rootNode) {
this.rootNode = rootNode;
......
......@@ -22,14 +22,15 @@ import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.YANGBASE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.*;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_CHILD;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.utils.YangConstructType.YANGBASE_DATA;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -55,8 +56,8 @@ public final class BaseFileListener {
* It is called when parser receives an input matching the grammar rule
* (yangfile), perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processYangFileEntry(TreeWalkListener listener, GeneratedYangParser.YangfileContext ctx) {
......@@ -69,8 +70,8 @@ public final class BaseFileListener {
* It is called when parser exits from grammar rule (yangfile), it perform
* validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processYangFileExit(TreeWalkListener listener, GeneratedYangParser.YangfileContext ctx) {
......
......@@ -22,13 +22,14 @@ import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.BELONGS_TO_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.*;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.utils.YangConstructType.BELONGS_TO_DATA;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -70,8 +71,8 @@ public final class BelongsToListener {
* It is called when parser receives an input matching the grammar rule
* (belongsto), perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processBelongsToEntry(TreeWalkListener listener,
GeneratedYangParser.BelongstoStatementContext ctx) {
......@@ -91,8 +92,8 @@ public final class BelongsToListener {
* It is called when parser exits from grammar rule (belongsto), it perform
* validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processBelongsToExit(TreeWalkListener listener,
GeneratedYangParser.BelongstoStatementContext ctx) {
......@@ -110,7 +111,7 @@ public final class BelongsToListener {
ctx.IDENTIFIER().getText(), EXIT);
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
switch (tmpNode.getYangConstructType()) {
case SUB_MODULE_DATA: {
YangSubModule subModule = (YangSubModule) tmpNode;
subModule.setBelongsTo((YangBelongsTo) tmpBelongstoNode);
......
......@@ -65,7 +65,7 @@ import org.onosproject.yangutils.datamodel.YangBit;
import org.onosproject.yangutils.datamodel.YangBits;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import static org.onosproject.yangutils.parser.ParsableDataType.BIT_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.BIT_DATA;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
......@@ -95,8 +95,8 @@ public final class BitListener {
* It is called when parser enters grammar rule (bit), it perform
* validations and updates the data model tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processBitEntry(TreeWalkListener listener,
GeneratedYangParser.BitStatementContext ctx) {
......@@ -113,8 +113,8 @@ public final class BitListener {
* It is called when parser exits from grammar rule (bit), it perform
* validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processBitExit(TreeWalkListener listener,
GeneratedYangParser.BitStatementContext ctx) {
......@@ -130,7 +130,7 @@ public final class BitListener {
checkStackIsNotEmpty(listener, MISSING_HOLDER, BIT_DATA, ctx.IDENTIFIER().getText(), EXIT);
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
switch (tmpNode.getYangConstructType()) {
case BITS_DATA: {
YangBits yangBits = (YangBits) tmpNode;
if ((ctx.bitBodyStatement() == null) || (ctx.bitBodyStatement().positionStatement() == null)) {
......
......@@ -46,8 +46,8 @@ import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.parser.Parsable;
import static org.onosproject.yangutils.parser.ParsableDataType.BITS_DATA;
import static org.onosproject.yangutils.parser.ParsableDataType.TYPE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.BITS_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
......@@ -75,8 +75,8 @@ public final class BitsListener {
* It is called when parser enters grammar rule (bits), it perform
* validations and updates the data model tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processBitsEntry(TreeWalkListener listener,
GeneratedYangParser.BitsSpecificationContext ctx) {
......@@ -93,7 +93,7 @@ public final class BitsListener {
Parsable tmpData = listener.getParsedDataStack().peek();
switch (tmpData.getParsableDataType()) {
switch (tmpData.getYangConstructType()) {
case LEAF_DATA:
bitsNode.setBitsName(((YangLeaf) tmpData).getLeafName());
break;
......@@ -116,8 +116,8 @@ public final class BitsListener {
* It is called when parser exits from grammar rule (bits), it perform
* validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processBitsExit(TreeWalkListener listener,
GeneratedYangParser.BitsSpecificationContext ctx) {
......@@ -133,7 +133,7 @@ public final class BitsListener {
checkStackIsNotEmpty(listener, MISSING_HOLDER, BITS_DATA, "", EXIT);
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
switch (tmpNode.getYangConstructType()) {
case TYPE_DATA: {
YangType typeNode = (YangType) tmpNode;
typeNode.setDataTypeExtendedInfo((YangBits) tmpBitsNode);
......
......@@ -24,13 +24,12 @@ import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.CONFIG_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.utils.YangConstructType.CONFIG_DATA;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -62,8 +61,8 @@ public final class ConfigListener {
* It is called when parser receives an input matching the grammar rule
* (config), performs validation and updates the data model tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processConfigEntry(TreeWalkListener listener,
GeneratedYangParser.ConfigStatementContext ctx) {
......@@ -77,7 +76,7 @@ public final class ConfigListener {
}
Parsable tmpData = listener.getParsedDataStack().peek();
switch (tmpData.getParsableDataType()) {
switch (tmpData.getYangConstructType()) {
case LEAF_DATA:
YangLeaf leaf = (YangLeaf) tmpData;
leaf.setConfig(isConfig);
......
......@@ -23,7 +23,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.CONTACT_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.CONTACT_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
......@@ -86,8 +86,8 @@ public final class ContactListener {
* It is called when parser receives an input matching the grammar rule
* (contact), perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processContactEntry(TreeWalkListener listener, GeneratedYangParser.ContactStatementContext ctx) {
......@@ -96,7 +96,7 @@ public final class ContactListener {
// Obtain the node of the stack.
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
switch (tmpNode.getYangConstructType()) {
case MODULE_DATA: {
YangModule module = (YangModule) tmpNode;
module.setContact(ctx.string().getText());
......
......@@ -22,24 +22,27 @@ import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
import static org.onosproject.yangutils.parser.ParsableDataType.CONTAINER_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_CARDINALITY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinality;
import static org.onosproject.yangutils.utils.YangConstructType.CONFIG_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.CONTAINER_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.PRESENCE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -76,8 +79,6 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidati
*/
public final class ContainerListener {
private static ParsableDataType yangConstruct;
/**
* Creates a new container listener.
*/
......@@ -85,30 +86,34 @@ public final class ContainerListener {
}
/**
* It is called when parser receives an input matching the grammar
* rule (container), performs validation and updates the data model
* tree.
* It is called when parser receives an input matching the grammar rule
* (container), performs validation and updates the data model tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processContainerEntry(TreeWalkListener listener,
GeneratedYangParser.ContainerStatementContext ctx) {
GeneratedYangParser.ContainerStatementContext ctx) {
YangNode parentNode;
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, CONTAINER_DATA, ctx.IDENTIFIER().getText(), ENTRY);
boolean result = validateSubStatementsCardinality(ctx);
if (!result) {
throw new ParserException(constructListenerErrorMessage(INVALID_CARDINALITY, yangConstruct, "", ENTRY));
}
// Validate sub statement cardinality.
validateSubStatementsCardinality(ctx);
// Check for identifier collision
int line = ctx.IDENTIFIER().getSymbol().getLine();
int charPositionInLine = ctx.IDENTIFIER().getSymbol().getCharPositionInLine();
String identifierName = ctx.IDENTIFIER().getText();
detectCollidingChildUtil(listener, line, charPositionInLine, identifierName, CONTAINER_DATA);
YangContainer container = new YangContainer();
container.setName(ctx.IDENTIFIER().getText());
/* If "config" is not specified, the default is the same as the parent
schema node's "config" value. */
/*
* If "config" is not specified, the default is the same as the parent
* schema node's "config" value.
*/
if (ctx.configStatement().isEmpty()) {
boolean parentConfig = ListenerValidation.getParentNodeConfig(listener);
container.setConfig(parentConfig);
......@@ -122,7 +127,7 @@ public final class ContainerListener {
curNode.addChild(container);
} catch (DataModelException e) {
throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
CONTAINER_DATA, ctx.IDENTIFIER().getText(), ENTRY, e.getMessage()));
CONTAINER_DATA, ctx.IDENTIFIER().getText(), ENTRY, e.getMessage()));
}
listener.getParsedDataStack().push(container);
} else {
......@@ -135,11 +140,11 @@ public final class ContainerListener {
* It is called when parser exits from grammar rule (container), it perform
* validations and updates the data model tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processContainerExit(TreeWalkListener listener,
GeneratedYangParser.ContainerStatementContext ctx) {
GeneratedYangParser.ContainerStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, CONTAINER_DATA, ctx.IDENTIFIER().getText(), EXIT);
......@@ -155,48 +160,22 @@ public final class ContainerListener {
listener.getParsedDataStack().pop();
} else {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, CONTAINER_DATA,
ctx.IDENTIFIER().getText(), EXIT));
ctx.IDENTIFIER().getText(), EXIT));
}
}
/**
* Validates the cardinality of container sub-statements as per grammar.
*
* @param ctx context object of the grammar rule.
* @return true/false validation success or failure.
* @param ctx context object of the grammar rule
*/
private static boolean validateSubStatementsCardinality(GeneratedYangParser.ContainerStatementContext ctx) {
if ((!ctx.presenceStatement().isEmpty())
&& (ctx.presenceStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.PRESENCE_DATA;
return false;
}
if ((!ctx.configStatement().isEmpty())
&& (ctx.configStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.CONFIG_DATA;
return false;
}
if ((!ctx.descriptionStatement().isEmpty())
&& (ctx.descriptionStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.DESCRIPTION_DATA;
return false;
}
if ((!ctx.referenceStatement().isEmpty())
&& (ctx.referenceStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.REFERENCE_DATA;
return false;
}
if ((!ctx.statusStatement().isEmpty())
&& (ctx.statusStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.STATUS_DATA;
return false;
}
return true;
private static void validateSubStatementsCardinality(GeneratedYangParser.ContainerStatementContext ctx) {
validateCardinality(ctx.presenceStatement(), PRESENCE_DATA, CONTAINER_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.configStatement(), CONFIG_DATA, CONTAINER_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.descriptionStatement(), DESCRIPTION_DATA, CONTAINER_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.referenceStatement(), REFERENCE_DATA, CONTAINER_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.statusStatement(), STATUS_DATA, CONTAINER_DATA, ctx.IDENTIFIER().getText());
// TODO when, grouping, typedef.
}
}
......
......@@ -45,7 +45,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.DEFAULT_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.DEFAULT_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
......@@ -64,8 +64,8 @@ public final class DefaultListener {
* It is called when parser enters grammar rule (default), it perform
* validations and updates the data model tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processDefaultEntry(TreeWalkListener listener,
GeneratedYangParser.DefaultStatementContext ctx) {
......@@ -74,7 +74,7 @@ public final class DefaultListener {
checkStackIsNotEmpty(listener, MISSING_HOLDER, DEFAULT_DATA, ctx.string().getText(), ENTRY);
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
switch (tmpNode.getYangConstructType()) {
case TYPEDEF_DATA: {
YangTypeDef typeDef = (YangTypeDef) tmpNode;
typeDef.setDefaultValueInString(ctx.string().getText());
......
......@@ -22,7 +22,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.DESCRIPTION_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
......@@ -56,8 +56,8 @@ public final class DescriptionListener {
* rule (description), perform validations and updates the data model
* tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processDescriptionEntry(TreeWalkListener listener,
GeneratedYangParser.DescriptionStatementContext ctx) {
......
......@@ -64,7 +64,7 @@ import org.onosproject.yangutils.datamodel.YangEnum;
import org.onosproject.yangutils.datamodel.YangEnumeration;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import static org.onosproject.yangutils.parser.ParsableDataType.ENUM_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.ENUM_DATA;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
......@@ -94,8 +94,8 @@ public final class EnumListener {
* It is called when parser enters grammar rule (enum), it perform
* validations and updates the data model tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processEnumEntry(TreeWalkListener listener, GeneratedYangParser.EnumStatementContext ctx) {
......@@ -111,8 +111,8 @@ public final class EnumListener {
* It is called when parser exits from grammar rule (enum), it perform
* validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processEnumExit(TreeWalkListener listener, GeneratedYangParser.EnumStatementContext ctx) {
......@@ -127,7 +127,7 @@ public final class EnumListener {
checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUM_DATA, ctx.string().getText(), EXIT);
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
switch (tmpNode.getYangConstructType()) {
case ENUMERATION_DATA: {
YangEnumeration yangEnumeration = (YangEnumeration) tmpNode;
if ((ctx.enumStatementBody() == null) || (ctx.enumStatementBody().valueStatement() == null)) {
......
......@@ -46,8 +46,8 @@ import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.parser.Parsable;
import static org.onosproject.yangutils.parser.ParsableDataType.ENUMERATION_DATA;
import static org.onosproject.yangutils.parser.ParsableDataType.TYPE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.ENUMERATION_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
......@@ -76,8 +76,8 @@ public final class EnumerationListener {
* It is called when parser enters grammar rule (enumeration), it perform
* validations and updates the data model tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processEnumerationEntry(TreeWalkListener listener,
GeneratedYangParser.EnumSpecificationContext ctx) {
......@@ -94,7 +94,7 @@ public final class EnumerationListener {
Parsable tmpData = listener.getParsedDataStack().peek();
switch (tmpData.getParsableDataType()) {
switch (tmpData.getYangConstructType()) {
case LEAF_DATA:
enumerationNode.setEnumerationName(((YangLeaf) tmpData).getLeafName());
break;
......@@ -117,8 +117,8 @@ public final class EnumerationListener {
* It is called when parser exits from grammar rule (enumeration), it
* perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processEnumerationExit(TreeWalkListener listener,
GeneratedYangParser.EnumSpecificationContext ctx) {
......@@ -134,7 +134,7 @@ public final class EnumerationListener {
checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUMERATION_DATA, "", EXIT);
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
switch (tmpNode.getYangConstructType()) {
case TYPE_DATA: {
YangType typeNode = (YangType) tmpNode;
typeNode.setDataTypeExtendedInfo((YangEnumeration) tmpEnumerationNode);
......
......@@ -23,13 +23,14 @@ import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.IMPORT_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.*;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.utils.YangConstructType.IMPORT_DATA;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -69,8 +70,8 @@ public final class ImportListener {
* It is called when parser receives an input matching the grammar rule
* (import), perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processImportEntry(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) {
......@@ -88,8 +89,8 @@ public final class ImportListener {
* It is called when parser exits from grammar rule (import), it perform
* validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processImportExit(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) {
......@@ -105,7 +106,7 @@ public final class ImportListener {
EXIT);
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
switch (tmpNode.getYangConstructType()) {
case MODULE_DATA: {
YangModule module = (YangModule) tmpNode;
module.addImportedInfo((YangImport) tmpImportNode);
......
......@@ -23,13 +23,14 @@ import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.INCLUDE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.*;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.utils.YangConstructType.INCLUDE_DATA;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -68,8 +69,8 @@ public final class IncludeListener {
* It is called when parser receives an input matching the grammar rule
* (include), perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processIncludeEntry(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) {
......@@ -87,8 +88,8 @@ public final class IncludeListener {
* It is called when parser exits from grammar rule (include), it perform
* validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processIncludeExit(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) {
......@@ -104,7 +105,7 @@ public final class IncludeListener {
EXIT);
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
switch (tmpNode.getYangConstructType()) {
case MODULE_DATA: {
YangModule module = (YangModule) tmpNode;
module.addIncludedInfo((YangInclude) tmpIncludeNode);
......
......@@ -23,7 +23,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.KEY_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.KEY_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
......@@ -59,8 +59,8 @@ public final class KeyListener {
* rule (key), perform validations and updates the data model
* tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processKeyEntry(TreeWalkListener listener,
GeneratedYangParser.KeyStatementContext ctx) {
......
......@@ -19,21 +19,28 @@ package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import static org.onosproject.yangutils.parser.ParsableDataType.LEAF_LIST_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_CARDINALITY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinality;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityEqualsOne;
import static org.onosproject.yangutils.utils.YangConstructType.CONFIG_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.LEAF_LIST_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.MAX_ELEMENT_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.MIN_ELEMENT_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.UNITS_DATA;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -68,8 +75,6 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidati
*/
public final class LeafListListener {
private static ParsableDataType yangConstruct;
/**
* Creates a new leaf list listener.
*/
......@@ -77,23 +82,26 @@ public final class LeafListListener {
}
/**
* It is called when parser receives an input matching the grammar
* rule (leaf-list), performs validation and updates the data model
* tree.
* It is called when parser receives an input matching the grammar rule
* (leaf-list), performs validation and updates the data model tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processLeafListEntry(TreeWalkListener listener,
GeneratedYangParser.LeafListStatementContext ctx) {
GeneratedYangParser.LeafListStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, LEAF_LIST_DATA, ctx.IDENTIFIER().getText(), ENTRY);
boolean result = validateSubStatementsCardinality(ctx);
if (!result) {
throw new ParserException(constructListenerErrorMessage(INVALID_CARDINALITY, yangConstruct, "", ENTRY));
}
// Validate sub statement cardinality.
validateSubStatementsCardinality(ctx);
// Check for identifier collision
int line = ctx.IDENTIFIER().getSymbol().getLine();
int charPositionInLine = ctx.IDENTIFIER().getSymbol().getCharPositionInLine();
String identifierName = ctx.IDENTIFIER().getText();
detectCollidingChildUtil(listener, line, charPositionInLine, identifierName, LEAF_LIST_DATA);
YangLeafList leafList = new YangLeafList();
leafList.setLeafName(ctx.IDENTIFIER().getText());
......@@ -106,7 +114,7 @@ public final class LeafListListener {
leaves.addLeafList(leafList);
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAF_LIST_DATA,
ctx.IDENTIFIER().getText(), ENTRY));
ctx.IDENTIFIER().getText(), ENTRY));
}
listener.getParsedDataStack().push(leafList);
}
......@@ -115,11 +123,11 @@ public final class LeafListListener {
* It is called when parser exits from grammar rule (leaf-list), it performs
* validation and updates the data model tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processLeafListExit(TreeWalkListener listener,
GeneratedYangParser.LeafListStatementContext ctx) {
GeneratedYangParser.LeafListStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, LEAF_LIST_DATA, ctx.IDENTIFIER().getText(), EXIT);
......@@ -136,59 +144,17 @@ public final class LeafListListener {
* Validates the cardinality of leaf-list sub-statements as per grammar.
*
* @param ctx context object of the grammar rule.
* @return true/false validation success or failure.
*/
private static boolean validateSubStatementsCardinality(GeneratedYangParser
.LeafListStatementContext ctx) {
if (ctx.typeStatement().isEmpty()
|| (ctx.typeStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.TYPE_DATA;
return false;
}
if ((!ctx.unitsStatement().isEmpty())
&& (ctx.unitsStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.UNITS_DATA;
return false;
}
if ((!ctx.configStatement().isEmpty())
&& (ctx.configStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.CONFIG_DATA;
return false;
}
if ((!ctx.maxElementsStatement().isEmpty())
&& (ctx.maxElementsStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.MAX_ELEMENT_DATA;
return false;
}
if ((!ctx.minElementsStatement().isEmpty())
&& (ctx.minElementsStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.MIN_ELEMENT_DATA;
return false;
}
if ((!ctx.descriptionStatement().isEmpty())
&& (ctx.descriptionStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.DESCRIPTION_DATA;
return false;
}
if ((!ctx.referenceStatement().isEmpty())
&& (ctx.referenceStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.REFERENCE_DATA;
return false;
}
if ((!ctx.statusStatement().isEmpty())
&& (ctx.statusStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.STATUS_DATA;
return false;
}
return true;
private static void validateSubStatementsCardinality(GeneratedYangParser.LeafListStatementContext ctx) {
validateCardinalityEqualsOne(ctx.typeStatement(), TYPE_DATA, LEAF_LIST_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.unitsStatement(), UNITS_DATA, LEAF_LIST_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.configStatement(), CONFIG_DATA, LEAF_LIST_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.maxElementsStatement(), MAX_ELEMENT_DATA, LEAF_LIST_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.minElementsStatement(), MIN_ELEMENT_DATA, LEAF_LIST_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.descriptionStatement(), DESCRIPTION_DATA, LEAF_LIST_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.referenceStatement(), REFERENCE_DATA, LEAF_LIST_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.statusStatement(), STATUS_DATA, LEAF_LIST_DATA, ctx.IDENTIFIER().getText());
//TODO ordered by
}
}
\ No newline at end of file
}
......
......@@ -21,23 +21,29 @@
package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import static org.onosproject.yangutils.parser.ParsableDataType.LEAF_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_CARDINALITY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinality;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityEqualsOne;
import static org.onosproject.yangutils.utils.YangConstructType.CONFIG_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.LEAF_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.MANDATORY_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.UNITS_DATA;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -66,13 +72,11 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidati
*/
/**
* Implements listener based call back function corresponding to the "leaf"
* rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
* Implements listener based call back function corresponding to the "leaf" rule
* defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
*/
public final class LeafListener {
private static ParsableDataType yangConstruct;
/**
* Creates a new leaf listener.
*/
......@@ -80,23 +84,26 @@ public final class LeafListener {
}
/**
* It is called when parser receives an input matching the grammar
* rule (leaf), performs validation and updates the data model
* tree.
* It is called when parser receives an input matching the grammar rule
* (leaf), performs validation and updates the data model tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processLeafEntry(TreeWalkListener listener,
GeneratedYangParser.LeafStatementContext ctx) {
GeneratedYangParser.LeafStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, LEAF_DATA, ctx.IDENTIFIER().getText(), ENTRY);
boolean result = validateSubStatementsCardinality(ctx);
if (!result) {
throw new ParserException(constructListenerErrorMessage(INVALID_CARDINALITY, yangConstruct, "", ENTRY));
}
// Validate sub statement cardinality.
validateSubStatementsCardinality(ctx);
// Check for identifier collision
int line = ctx.IDENTIFIER().getSymbol().getLine();
int charPositionInLine = ctx.IDENTIFIER().getSymbol().getCharPositionInLine();
String identifierName = ctx.IDENTIFIER().getText();
detectCollidingChildUtil(listener, line, charPositionInLine, identifierName, LEAF_DATA);
YangLeaf leaf = new YangLeaf();
leaf.setLeafName(ctx.IDENTIFIER().getText());
......@@ -123,7 +130,7 @@ public final class LeafListener {
* @param ctx context object of the grammar rule.
*/
public static void processLeafExit(TreeWalkListener listener,
GeneratedYangParser.LeafStatementContext ctx) {
GeneratedYangParser.LeafStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, LEAF_DATA, ctx.IDENTIFIER().getText(), EXIT);
......@@ -132,7 +139,7 @@ public final class LeafListener {
listener.getParsedDataStack().pop();
} else {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, LEAF_DATA,
ctx.IDENTIFIER().getText(), EXIT));
ctx.IDENTIFIER().getText(), EXIT));
}
}
......@@ -140,53 +147,16 @@ public final class LeafListener {
* Validates the cardinality of leaf sub-statements as per grammar.
*
* @param ctx context object of the grammar rule.
* @return true/false validation success or failure.
*/
private static boolean validateSubStatementsCardinality(GeneratedYangParser
.LeafStatementContext ctx) {
if (ctx.typeStatement().isEmpty()
|| (ctx.typeStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.TYPE_DATA;
return false;
}
if ((!ctx.unitsStatement().isEmpty())
&& (ctx.unitsStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.UNITS_DATA;
return false;
}
if ((!ctx.configStatement().isEmpty())
&& (ctx.configStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.CONFIG_DATA;
return false;
}
if ((!ctx.mandatoryStatement().isEmpty())
&& (ctx.mandatoryStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.MANDATORY_DATA;
return false;
}
if ((!ctx.descriptionStatement().isEmpty())
&& (ctx.descriptionStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.DESCRIPTION_DATA;
return false;
}
if ((!ctx.referenceStatement().isEmpty())
&& (ctx.referenceStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.REFERENCE_DATA;
return false;
}
if ((!ctx.statusStatement().isEmpty())
&& (ctx.statusStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.STATUS_DATA;
return false;
}
return true;
private static void validateSubStatementsCardinality(GeneratedYangParser.LeafStatementContext ctx) {
validateCardinalityEqualsOne(ctx.typeStatement(), TYPE_DATA, LEAF_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.unitsStatement(), UNITS_DATA, LEAF_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.configStatement(), CONFIG_DATA, LEAF_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.mandatoryStatement(), MANDATORY_DATA, LEAF_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.descriptionStatement(), DESCRIPTION_DATA, LEAF_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.referenceStatement(), REFERENCE_DATA, LEAF_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.statusStatement(), STATUS_DATA, LEAF_DATA, ctx.IDENTIFIER().getText());
//TODO when.
}
}
\ No newline at end of file
}
......
......@@ -16,31 +16,38 @@
package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeType;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
import static org.onosproject.yangutils.parser.ParsableDataType.LIST_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_CARDINALITY;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinality;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityNonNull;
import static org.onosproject.yangutils.utils.YangConstructType.CONFIG_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.DATA_DEF_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.KEY_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.LIST_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.MAX_ELEMENT_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.MIN_ELEMENT_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -74,13 +81,11 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidati
*/
/**
* Implements listener based call back function corresponding to the "list"
* rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
* Implements listener based call back function corresponding to the "list" rule
* defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
*/
public final class ListListener {
private static ParsableDataType yangConstruct;
/**
* Creates a new list listener.
*/
......@@ -88,30 +93,35 @@ public final class ListListener {
}
/**
* It is called when parser receives an input matching the grammar
* rule (list), performs validation and updates the data model
* tree.
* It is called when parser receives an input matching the grammar rule
* (list), performs validation and updates the data model tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processListEntry(TreeWalkListener listener,
GeneratedYangParser.ListStatementContext ctx) {
GeneratedYangParser.ListStatementContext ctx) {
YangNode curNode;
checkStackIsNotEmpty(listener, MISSING_HOLDER, LIST_DATA, ctx.IDENTIFIER().getText(), ENTRY);
boolean result = validateSubStatementsCardinality(ctx);
if (!result) {
throw new ParserException(constructListenerErrorMessage(INVALID_CARDINALITY, yangConstruct, "", ENTRY));
}
// Validate sub statement cardinality.
validateSubStatementsCardinality(ctx);
// Check for identifier collision
int line = ctx.IDENTIFIER().getSymbol().getLine();
int charPositionInLine = ctx.IDENTIFIER().getSymbol().getCharPositionInLine();
String identifierName = ctx.IDENTIFIER().getText();
detectCollidingChildUtil(listener, line, charPositionInLine, identifierName, LIST_DATA);
YangList yangList = new YangList(YangNodeType.LIST_NODE);
yangList.setName(ctx.IDENTIFIER().getText());
/* If "config" is not specified, the default is the same as the parent
schema node's "config" value. */
/*
* If "config" is not specified, the default is the same as the parent
* schema node's "config" value.
*/
if (ctx.configStatement().isEmpty()) {
boolean parentConfig = ListenerValidation.getParentNodeConfig(listener);
yangList.setConfig(parentConfig);
......@@ -130,7 +140,7 @@ public final class ListListener {
listener.getParsedDataStack().push(yangList);
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LIST_DATA,
ctx.IDENTIFIER().getText(), ENTRY));
ctx.IDENTIFIER().getText(), ENTRY));
}
}
......@@ -138,11 +148,11 @@ public final class ListListener {
* It is called when parser exits from grammar rule (list), it performs
* validation and updates the data model tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processListExit(TreeWalkListener listener,
GeneratedYangParser.ListStatementContext ctx) {
GeneratedYangParser.ListStatementContext ctx) {
checkStackIsNotEmpty(listener, MISSING_HOLDER, LIST_DATA, ctx.IDENTIFIER().getText(), EXIT);
......@@ -157,65 +167,25 @@ public final class ListListener {
listener.getParsedDataStack().pop();
} else {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, LIST_DATA,
ctx.IDENTIFIER().getText(), EXIT));
ctx.IDENTIFIER().getText(), EXIT));
}
}
/**
* Validates the cardinality of list sub-statements as per grammar.
*
* @param ctx context object of the grammar rule.
* @return true/false validation success or failure.
* @param ctx context object of the grammar rule
*/
private static boolean validateSubStatementsCardinality(GeneratedYangParser.ListStatementContext ctx) {
if ((!ctx.keyStatement().isEmpty())
&& (ctx.keyStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.KEY_DATA;
return false;
}
if ((!ctx.configStatement().isEmpty())
&& (ctx.configStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.CONFIG_DATA;
return false;
}
if ((!ctx.maxElementsStatement().isEmpty())
&& (ctx.maxElementsStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.MAX_ELEMENT_DATA;
return false;
}
if ((!ctx.minElementsStatement().isEmpty())
&& (ctx.minElementsStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.MIN_ELEMENT_DATA;
return false;
}
if ((!ctx.descriptionStatement().isEmpty())
&& (ctx.descriptionStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.DESCRIPTION_DATA;
return false;
}
if ((!ctx.referenceStatement().isEmpty())
&& (ctx.referenceStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.REFERENCE_DATA;
return false;
}
if ((!ctx.statusStatement().isEmpty())
&& (ctx.statusStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = ParsableDataType.STATUS_DATA;
return false;
}
if (ctx.dataDefStatement().isEmpty()) {
yangConstruct = ParsableDataType.LIST_DATA;
return false;
}
return true;
private static void validateSubStatementsCardinality(GeneratedYangParser.ListStatementContext ctx) {
validateCardinality(ctx.keyStatement(), KEY_DATA, LIST_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.configStatement(), CONFIG_DATA, LIST_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.maxElementsStatement(), MAX_ELEMENT_DATA, LIST_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.minElementsStatement(), MIN_ELEMENT_DATA, LIST_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.descriptionStatement(), DESCRIPTION_DATA, LIST_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.referenceStatement(), REFERENCE_DATA, LIST_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.statusStatement(), STATUS_DATA, LIST_DATA, ctx.IDENTIFIER().getText());
validateCardinalityNonNull(ctx.dataDefStatement(), DATA_DEF_DATA, LIST_DATA, ctx.IDENTIFIER().getText());
//TODO when, typedef, grouping, unique
}
}
\ No newline at end of file
}
......
......@@ -22,7 +22,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.MANDATORY_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.MANDATORY_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
......@@ -62,8 +62,8 @@ public final class MandatoryListener {
* rule (mandatory), performs validation and updates the data model
* tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processMandatoryEntry(TreeWalkListener listener,
GeneratedYangParser.MandatoryStatementContext ctx) {
......@@ -72,7 +72,7 @@ public final class MandatoryListener {
checkStackIsNotEmpty(listener, MISSING_HOLDER, MANDATORY_DATA, "", ENTRY);
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
switch (tmpNode.getYangConstructType()) {
case LEAF_DATA:
YangLeaf leaf = (YangLeaf) tmpNode;
if (ctx.TRUE_KEYWORD() != null) {
......
......@@ -23,7 +23,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.MAX_ELEMENT_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.MAX_ELEMENT_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
......@@ -60,8 +60,8 @@ public final class MaxElementsListener {
* rule (max-elements), performs validation and updates the data model
* tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processMaxElementsEntry(TreeWalkListener listener,
GeneratedYangParser.MaxElementsStatementContext ctx) {
......@@ -77,7 +77,7 @@ public final class MaxElementsListener {
}
Parsable tmpData = listener.getParsedDataStack().peek();
switch (tmpData.getParsableDataType()) {
switch (tmpData.getYangConstructType()) {
case LEAF_LIST_DATA:
YangLeafList leafList = (YangLeafList) tmpData;
leafList.setMaxElelements(maxElementsValue);
......
......@@ -23,7 +23,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.MIN_ELEMENT_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.MIN_ELEMENT_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
......@@ -61,8 +61,8 @@ public final class MinElementsListener {
* rule (min-elements), performs validation and updates the data model
* tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processMinElementsEntry(TreeWalkListener listener,
GeneratedYangParser.MinElementsStatementContext ctx) {
......@@ -71,7 +71,7 @@ public final class MinElementsListener {
checkStackIsNotEmpty(listener, MISSING_HOLDER, MIN_ELEMENT_DATA, ctx.INTEGER().getText(), ENTRY);
Parsable tmpData = listener.getParsedDataStack().peek();
switch (tmpData.getParsableDataType()) {
switch (tmpData.getYangConstructType()) {
case LEAF_LIST_DATA:
YangLeafList leafList = (YangLeafList) tmpData;
leafList.setMinElements(Integer.parseInt(ctx.INTEGER().getText()));
......
......@@ -20,14 +20,15 @@ import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.MODULE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.*;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.utils.YangConstructType.MODULE_DATA;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -63,8 +64,8 @@ public final class ModuleListener {
* It is called when parser receives an input matching the grammar rule
* (module), perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processModuleEntry(TreeWalkListener listener, GeneratedYangParser.ModuleStatementContext ctx) {
......@@ -74,6 +75,10 @@ public final class ModuleListener {
YangModule yangModule = new YangModule();
yangModule.setName(ctx.IDENTIFIER().getText());
if (ctx.moduleBody(0).moduleHeaderStatement().yangVersionStatement() == null) {
yangModule.setVersion((byte) 1);
}
listener.getParsedDataStack().push(yangModule);
}
......@@ -81,8 +86,8 @@ public final class ModuleListener {
* It is called when parser exits from grammar rule (module), it perform
* validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processModuleExit(TreeWalkListener listener, GeneratedYangParser.ModuleStatementContext ctx) {
......
......@@ -25,7 +25,7 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import java.net.URI;
import static org.onosproject.yangutils.parser.ParsableDataType.NAMESPACE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.NAMESPACE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
......@@ -70,8 +70,8 @@ public final class NamespaceListener {
* It is called when parser receives an input matching the grammar rule
* (namespace), perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processNamespaceEntry(TreeWalkListener listener,
GeneratedYangParser.NamespaceStatementContext ctx) {
......@@ -80,7 +80,7 @@ public final class NamespaceListener {
checkStackIsNotEmpty(listener, MISSING_HOLDER, NAMESPACE_DATA, ctx.string().getText(), ENTRY);
if (!validateUriValue(ctx.string().getText())) {
ParserException parserException = new ParserException("Invalid namespace URI");
ParserException parserException = new ParserException("YANG file error: Invalid namespace URI");
parserException.setLine(ctx.string().STRING(0).getSymbol().getLine());
parserException.setCharPosition(ctx.string().STRING(0).getSymbol().getCharPositionInLine());
throw parserException;
......@@ -88,7 +88,7 @@ public final class NamespaceListener {
// Obtain the node of the stack.
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
switch (tmpNode.getYangConstructType()) {
case MODULE_DATA: {
YangModule module = (YangModule) tmpNode;
YangNameSpace uri = new YangNameSpace();
......
......@@ -23,7 +23,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.ORGANIZATION_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.ORGANIZATION_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
......@@ -88,8 +88,8 @@ public final class OrganizationListener {
* It is called when parser receives an input matching the grammar rule
* (organization), perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processOrganizationEntry(TreeWalkListener listener,
GeneratedYangParser.OrganizationStatementContext ctx) {
......@@ -100,7 +100,7 @@ public final class OrganizationListener {
// Obtain the node of the stack.
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
switch (tmpNode.getYangConstructType()) {
case MODULE_DATA: {
YangModule module = (YangModule) tmpNode;
module.setOrganization(ctx.string().getText());
......
......@@ -36,7 +36,7 @@ package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangBit;
import org.onosproject.yangutils.datamodel.YangBits;
import org.onosproject.yangutils.parser.Parsable;
import static org.onosproject.yangutils.parser.ParsableDataType.POSITION_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.POSITION_DATA;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
......@@ -65,8 +65,8 @@ public final class PositionListener {
* It is called when parser receives an input matching the grammar rule
* (position), perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processPositionEntry(TreeWalkListener listener,
GeneratedYangParser.PositionStatementContext ctx) {
......@@ -76,7 +76,7 @@ public final class PositionListener {
// Obtain the node of the stack.
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
switch (tmpNode.getYangConstructType()) {
case BIT_DATA: {
YangBit bitNode = (YangBit) tmpNode;
if (!isBitPositionValid(listener, ctx)) {
......@@ -97,8 +97,8 @@ public final class PositionListener {
/**
* Validates BITS position value correctness and uniqueness.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
* @return validation result
*/
private static boolean isBitPositionValid(TreeWalkListener listener,
......@@ -109,18 +109,18 @@ public final class PositionListener {
checkStackIsNotEmpty(listener, MISSING_HOLDER, POSITION_DATA, ctx.INTEGER().getText(), ENTRY);
if (Integer.valueOf(ctx.INTEGER().getText()) < 0) {
errMsg = "Negative value of position is invalid";
errMsg = "YANG file error: Negative value of position is invalid.";
listener.getParsedDataStack().push(bitNode);
return false;
}
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
switch (tmpNode.getYangConstructType()) {
case BITS_DATA: {
YangBits yangBits = (YangBits) tmpNode;
for (YangBit curBit : yangBits.getBitSet()) {
if (Integer.valueOf(ctx.INTEGER().getText()) == curBit.getPosition()) {
errMsg = "Duplicate value of position is invalid";
errMsg = "YANG file error: Duplicate value of position is invalid.";
listener.getParsedDataStack().push(bitNode);
return false;
}
......
......@@ -24,7 +24,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.PREFIX_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.PREFIX_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
......@@ -70,8 +70,8 @@ public final class PrefixListener {
* It is called when parser receives an input matching the grammar rule
* (prefix),perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processPrefixEntry(TreeWalkListener listener, GeneratedYangParser.PrefixStatementContext ctx) {
......@@ -80,7 +80,7 @@ public final class PrefixListener {
// Obtain the node of the stack.
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
switch (tmpNode.getYangConstructType()) {
case MODULE_DATA: {
YangModule module = (YangModule) tmpNode;
module.setPrefix(ctx.IDENTIFIER().getText());
......
......@@ -22,8 +22,8 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.PRESENCE_DATA;
import static org.onosproject.yangutils.parser.ParsableDataType.CONTAINER_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.PRESENCE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.CONTAINER_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
......@@ -57,8 +57,8 @@ public final class PresenceListener {
* rule (presence), performs validation and updates the data model
* tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processPresenceEntry(TreeWalkListener listener,
GeneratedYangParser.PresenceStatementContext ctx) {
......@@ -67,7 +67,7 @@ public final class PresenceListener {
checkStackIsNotEmpty(listener, MISSING_HOLDER, PRESENCE_DATA, ctx.string().getText(), ENTRY);
Parsable tmpData = listener.getParsedDataStack().peek();
if (tmpData.getParsableDataType() == CONTAINER_DATA) {
if (tmpData.getYangConstructType() == CONTAINER_DATA) {
YangContainer container = (YangContainer) tmpData;
container.setPresence(ctx.string().getText());
} else {
......
......@@ -22,7 +22,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.REFERENCE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
......@@ -56,8 +56,8 @@ public final class ReferenceListener {
* rule (reference), performs validation and updates the data model
* tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processReferenceEntry(TreeWalkListener listener,
GeneratedYangParser.ReferenceStatementContext ctx) {
......
......@@ -27,7 +27,7 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import static org.onosproject.yangutils.parser.ParsableDataType.REVISION_DATE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.REVISION_DATE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
......@@ -79,8 +79,8 @@ public final class RevisionDateListener {
* It is called when parser receives an input matching the grammar rule
* (revision date),perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processRevisionDateEntry(TreeWalkListener listener,
GeneratedYangParser.RevisionDateStatementContext ctx) {
......@@ -90,7 +90,7 @@ public final class RevisionDateListener {
ENTRY);
if (!isDateValid(ctx.DATE_ARG().getText())) {
ParserException parserException = new ParserException("Input date is not correct");
ParserException parserException = new ParserException("YANG file error: Input date is not correct");
parserException.setLine(ctx.DATE_ARG().getSymbol().getLine());
parserException.setCharPosition(ctx.DATE_ARG().getSymbol().getCharPositionInLine());
throw parserException;
......@@ -98,7 +98,7 @@ public final class RevisionDateListener {
// Obtain the node of the stack.
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
switch (tmpNode.getYangConstructType()) {
case IMPORT_DATA: {
YangImport importNode = (YangImport) tmpNode;
importNode.setRevision(ctx.DATE_ARG().getText());
......@@ -118,8 +118,8 @@ public final class RevisionDateListener {
/**
* Validates the revision date.
*
* @param dateToValidate input revision date.
* @return validation result, true for success, false for failure.
* @param dateToValidate input revision date
* @return validation result, true for success, false for failure
*/
private static boolean isDateValid(String dateToValidate) {
......
......@@ -24,13 +24,19 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.REVISION_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.utils.YangConstructType.REVISION_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.*;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
*
......@@ -75,8 +81,8 @@ public final class RevisionListener {
* It is called when parser receives an input matching the grammar rule
* (revision),perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processRevisionEntry(TreeWalkListener listener,
GeneratedYangParser.RevisionStatementContext ctx) {
......@@ -91,6 +97,13 @@ public final class RevisionListener {
// TODO to be implemented.
}
if (!isDateValid(ctx.DATE_ARG().getText())) {
ParserException parserException = new ParserException("YANG file error: Input date is not correct");
parserException.setLine(ctx.DATE_ARG().getSymbol().getLine());
parserException.setCharPosition(ctx.DATE_ARG().getSymbol().getCharPositionInLine());
throw parserException;
}
YangRevision revisionNode = new YangRevision();
revisionNode.setRevDate(ctx.DATE_ARG().getText());
......@@ -101,8 +114,8 @@ public final class RevisionListener {
* It is called when parser exits from grammar rule (revision), it perform
* validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processRevisionExit(TreeWalkListener listener, GeneratedYangParser.RevisionStatementContext
ctx) {
......@@ -119,7 +132,7 @@ public final class RevisionListener {
EXIT);
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
switch (tmpNode.getYangConstructType()) {
case MODULE_DATA: {
YangModule module = (YangModule) tmpNode;
module.setRevision((YangRevision) tmpRevisionNode);
......@@ -144,8 +157,8 @@ public final class RevisionListener {
/**
* Validate revision.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
* @return validation result
*/
private static boolean validateRevision(TreeWalkListener listener,
......@@ -153,4 +166,29 @@ public final class RevisionListener {
// TODO to be implemented
return true;
}
/**
* Validates the revision date.
*
* @param dateToValidate input revision date
* @return validation result, true for success, false for failure
*/
private static boolean isDateValid(String dateToValidate) {
if (dateToValidate == null) {
return false;
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
sdf.setLenient(false);
try {
//if not valid, it will throw ParseException
Date date = sdf.parse(dateToValidate);
System.out.println(date);
} catch (ParseException e) {
return false;
}
return true;
}
}
......
......@@ -23,7 +23,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.STATUS_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
......@@ -62,8 +62,8 @@ public final class StatusListener {
* rule (status), performs validation and updates the data model
* tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processStatusEntry(TreeWalkListener listener,
GeneratedYangParser.StatusStatementContext ctx) {
......
......@@ -20,14 +20,15 @@ import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.SUB_MODULE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.*;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.utils.YangConstructType.SUB_MODULE_DATA;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -64,8 +65,8 @@ public final class SubModuleListener {
* It is called when parser receives an input matching the grammar rule (sub
* module), perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processSubModuleEntry(TreeWalkListener listener,
GeneratedYangParser.SubModuleStatementContext ctx) {
......@@ -77,6 +78,10 @@ public final class SubModuleListener {
YangSubModule yangSubModule = new YangSubModule();
yangSubModule.setName(ctx.IDENTIFIER().getText());
if (ctx.submoduleBody(0).submoduleHeaderStatement().yangVersionStatement() == null) {
yangSubModule.setVersion((byte) 1);
}
listener.getParsedDataStack().push(yangSubModule);
}
......@@ -84,8 +89,8 @@ public final class SubModuleListener {
* It is called when parser exits from grammar rule (submodule), it perform
* validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processSubModuleExit(TreeWalkListener listener,
GeneratedYangParser.SubModuleStatementContext ctx) {
......
......@@ -58,24 +58,23 @@ import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinality;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityEqualsOne;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import static org.onosproject.yangutils.parser.ParsableDataType.DEFAULT_DATA;
import static org.onosproject.yangutils.parser.ParsableDataType.DESCRIPTION_DATA;
import static org.onosproject.yangutils.parser.ParsableDataType.REFERENCE_DATA;
import static org.onosproject.yangutils.parser.ParsableDataType.STATUS_DATA;
import static org.onosproject.yangutils.parser.ParsableDataType.TYPEDEF_DATA;
import static org.onosproject.yangutils.parser.ParsableDataType.TYPE_DATA;
import static org.onosproject.yangutils.parser.ParsableDataType.UNITS_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.DEFAULT_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.TYPEDEF_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.UNITS_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_CARDINALITY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
......@@ -88,8 +87,6 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidati
*/
public final class TypeDefListener {
private static ParsableDataType yangConstruct;
/**
* Creates a new typedef listener.
*/
......@@ -100,8 +97,8 @@ public final class TypeDefListener {
* It is called when parser enters grammar rule (typedef), it perform
* validations and updates the data model tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processTypeDefEntry(TreeWalkListener listener,
GeneratedYangParser.TypedefStatementContext ctx) {
......@@ -109,10 +106,8 @@ public final class TypeDefListener {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPEDEF_DATA, ctx.IDENTIFIER().getText(), ENTRY);
boolean result = validateSubStatementsCardinality(ctx);
if (!result) {
throw new ParserException(constructListenerErrorMessage(INVALID_CARDINALITY, yangConstruct, "", ENTRY));
}
// Validate sub statement cardinality.
validateSubStatementsCardinality(ctx);
/*
* Create a derived type information, the base type must be set in type
......@@ -150,8 +145,8 @@ public final class TypeDefListener {
* It is called when parser exits from grammar rule (typedef), it perform
* validations and updates the data model tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processTypeDefExit(TreeWalkListener listener,
GeneratedYangParser.TypedefStatementContext ctx) {
......@@ -178,45 +173,15 @@ public final class TypeDefListener {
/**
* Validates the cardinality of typedef sub-statements as per grammar.
*
* @param ctx context object of the grammar rule.
* @return true/false validation success or failure.
* @param ctx context object of the grammar rule
*/
private static boolean validateSubStatementsCardinality(GeneratedYangParser.TypedefStatementContext ctx) {
if ((!ctx.unitsStatement().isEmpty())
&& (ctx.unitsStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = UNITS_DATA;
return false;
}
if ((!ctx.defaultStatement().isEmpty())
&& (ctx.defaultStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = DEFAULT_DATA;
return false;
}
if (ctx.typeStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY) {
yangConstruct = TYPE_DATA;
return false;
}
if ((!ctx.descriptionStatement().isEmpty())
&& (ctx.descriptionStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = DESCRIPTION_DATA;
return false;
}
if ((!ctx.referenceStatement().isEmpty())
&& (ctx.referenceStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = REFERENCE_DATA;
return false;
}
if ((!ctx.statusStatement().isEmpty())
&& (ctx.statusStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
yangConstruct = STATUS_DATA;
return false;
}
return true;
private static void validateSubStatementsCardinality(GeneratedYangParser.TypedefStatementContext ctx) {
validateCardinality(ctx.unitsStatement(), UNITS_DATA, TYPEDEF_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.defaultStatement(), DEFAULT_DATA, TYPEDEF_DATA, ctx.IDENTIFIER().getText());
validateCardinalityEqualsOne(ctx.typeStatement(), TYPE_DATA, TYPEDEF_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.descriptionStatement(), DESCRIPTION_DATA, TYPEDEF_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.referenceStatement(), REFERENCE_DATA, TYPEDEF_DATA, ctx.IDENTIFIER().getText());
validateCardinality(ctx.statusStatement(), STATUS_DATA, TYPEDEF_DATA, ctx.IDENTIFIER().getText());
}
}
......
......@@ -27,7 +27,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.TYPE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
......@@ -66,8 +66,8 @@ public final class TypeListener {
* It is called when parser receives an input matching the grammar rule
* (type), performs validation and updates the data model tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processTypeEntry(TreeWalkListener listener,
GeneratedYangParser.TypeStatementContext ctx) {
......@@ -88,8 +88,8 @@ public final class TypeListener {
* It is called when parser exits from grammar rule (type), it perform
* validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processTypeExit(TreeWalkListener listener,
GeneratedYangParser.TypeStatementContext ctx) {
......@@ -107,7 +107,7 @@ public final class TypeListener {
checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPE_DATA, ctx.string().getText(), EXIT);
Parsable tmpData = listener.getParsedDataStack().peek();
switch (tmpData.getParsableDataType()) {
switch (tmpData.getYangConstructType()) {
case LEAF_DATA:
YangLeaf leaf = (YangLeaf) tmpData;
leaf.setDataType((YangType) type);
......
......@@ -23,7 +23,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.UNITS_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.UNITS_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
......@@ -57,8 +57,8 @@ public final class UnitsListener {
* rule (units), performs validation and updates the data model
* tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processUnitsEntry(TreeWalkListener listener,
GeneratedYangParser.UnitsStatementContext ctx) {
......@@ -67,7 +67,7 @@ public final class UnitsListener {
checkStackIsNotEmpty(listener, MISSING_HOLDER, UNITS_DATA, ctx.string().getText(), ENTRY);
Parsable tmpData = listener.getParsedDataStack().peek();
switch (tmpData.getParsableDataType()) {
switch (tmpData.getYangConstructType()) {
case LEAF_DATA:
YangLeaf leaf = (YangLeaf) tmpData;
leaf.setUnits(ctx.string().getText());
......
......@@ -29,7 +29,7 @@ package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangEnum;
import org.onosproject.yangutils.datamodel.YangEnumeration;
import org.onosproject.yangutils.parser.Parsable;
import static org.onosproject.yangutils.parser.ParsableDataType.VALUE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.VALUE_DATA;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
......@@ -55,8 +55,8 @@ public final class ValueListener {
* It is called when parser receives an input matching the grammar rule
* (value), perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processValueEntry(TreeWalkListener listener, GeneratedYangParser.ValueStatementContext ctx) {
......@@ -65,7 +65,7 @@ public final class ValueListener {
// Obtain the node of the stack.
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
switch (tmpNode.getYangConstructType()) {
case ENUM_DATA: {
YangEnum enumNode = (YangEnum) tmpNode;
if (!isEnumValueValid(listener, ctx)) {
......@@ -86,8 +86,8 @@ public final class ValueListener {
/**
* Validates ENUM value uniqueness.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
* @return validation result
*/
private static boolean isEnumValueValid(TreeWalkListener listener, GeneratedYangParser.ValueStatementContext ctx) {
......@@ -97,7 +97,7 @@ public final class ValueListener {
checkStackIsNotEmpty(listener, MISSING_HOLDER, VALUE_DATA, ctx.INTEGER().getText(), ENTRY);
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
switch (tmpNode.getYangConstructType()) {
case ENUMERATION_DATA: {
YangEnumeration yangEnumeration = (YangEnumeration) tmpNode;
for (YangEnum curEnum : yangEnumeration.getEnumSet()) {
......
......@@ -23,7 +23,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.VERSION_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.VERSION_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
......@@ -78,8 +78,8 @@ public final class VersionListener {
* It is called when parser receives an input matching the grammar rule
* (version), perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processVersionEntry(TreeWalkListener listener,
GeneratedYangParser.YangVersionStatementContext ctx) {
......@@ -89,7 +89,7 @@ public final class VersionListener {
Integer version = Integer.valueOf(ctx.INTEGER().getText());
if (!isVersionValid(version)) {
ParserException parserException = new ParserException("Input version not supported");
ParserException parserException = new ParserException("YANG file error: Input version not supported");
parserException.setLine(ctx.INTEGER().getSymbol().getLine());
parserException.setCharPosition(ctx.INTEGER().getSymbol().getCharPositionInLine());
throw parserException;
......@@ -97,7 +97,7 @@ public final class VersionListener {
// Obtain the node of the stack.
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
switch (tmpNode.getYangConstructType()) {
case MODULE_DATA: {
YangModule module = (YangModule) tmpNode;
module.setVersion((byte) 1);
......
/*
* Copyright 2016 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.parser.impl.parserutils;
import org.onosproject.yangutils.datamodel.CollisionDetector;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import org.onosproject.yangutils.utils.YangConstructType;
/**
* Check the YANG construct collision in a YANG file.
*/
public final class ListenerCollisionDetector {
/**
* Creates a new listener collision.
*/
private ListenerCollisionDetector() {
}
/**
* Detects that the identifiers of all these child nodes must be unique
* within all cases in a choice.
*
* @param listener listener's object
* @param line line of identifier in YANG file, required for error
* reporting
* @param charPosition character position of identifier in YANG file,
* required for error reporting
* @param identifierName name for which uniqueness is to be detected
* @param constructType type of YANG construct for which collision check is
* to be performed
* @throws ParserException if identifier is not unique
*/
public static void detectCollidingChildUtil(TreeWalkListener listener, int line, int charPosition,
String identifierName, YangConstructType constructType)
throws ParserException {
if (listener.getParsedDataStack().peek() instanceof CollisionDetector) {
try {
((CollisionDetector) listener.getParsedDataStack().peek()).detectCollidingChild(
identifierName, constructType);
} catch (DataModelException e) {
ParserException parserException = new ParserException(e.getMessage());
parserException.setLine(line);
parserException.setCharPosition(charPosition);
throw parserException;
}
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, constructType, identifierName,
EXIT));
}
}
}
......@@ -33,8 +33,8 @@ public enum ListenerErrorLocation {
/**
* Returns the message corresponding to listener error location.
*
* @param errorLocation enum value for type of error.
* @return message corresponding to listener error location.
* @param errorLocation enum value for type of error
* @return message corresponding to listener error location
*/
public static String getErrorLocationMessage(ListenerErrorLocation errorLocation) {
......
......@@ -16,9 +16,9 @@
package org.onosproject.yangutils.parser.impl.parserutils;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.utils.YangConstructType;
import static org.onosproject.yangutils.parser.ParsableDataType.getParsableDataType;
import static org.onosproject.yangutils.utils.YangConstructType.getYangConstructType;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.getErrorLocationMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.getErrorType;
......@@ -37,21 +37,21 @@ public final class ListenerErrorMessageConstruction {
* Constructs message for error with extended information and returns the
* same.
*
* @param errorType error type needs to be set in error message.
* @param parsableDataType type of parsable data in which error occurred.
* @param errorType error type needs to be set in error message
* @param yangConstructType type of parsable data in which error occurred
* @param parsableDataTypeName identifier/string of parsable data type in
* which error occurred.
* @param errorLocation location where error occurred.
* @param extendedErrorInformation extended error information.
* @return constructed error message.
* which error occurred
* @param errorLocation location where error occurred
* @param extendedErrorInformation extended error information
* @return constructed error message
*/
public static String constructExtendedListenerErrorMessage(ListenerErrorType errorType,
ParsableDataType parsableDataType,
YangConstructType yangConstructType,
String parsableDataTypeName,
ListenerErrorLocation errorLocation,
String extendedErrorInformation) {
String newErrorMessage;
newErrorMessage = constructListenerErrorMessage(errorType, parsableDataType, parsableDataTypeName,
newErrorMessage = constructListenerErrorMessage(errorType, yangConstructType, parsableDataTypeName,
errorLocation)
+ "\n"
+ "Error Information: "
......@@ -63,22 +63,22 @@ public final class ListenerErrorMessageConstruction {
* Constructs message for error during listener based tree walk and returns
* the same.
*
* @param errorType error type needs to be set in error message.
* @param parsableDataType type of parsable data in which error occurred.
* @param errorType error type needs to be set in error message
* @param yangConstructType type of parsable data in which error occurred
* @param parsableDataTypeName identifier/string of parsable data type in
* which error occurred.
* @param errorLocation location where error occurred.
* @return constructed error message.
* which error occurred
* @param errorLocation location where error occurred
* @return constructed error message
*/
public static String constructListenerErrorMessage(ListenerErrorType errorType,
ParsableDataType parsableDataType,
YangConstructType yangConstructType,
String parsableDataTypeName,
ListenerErrorLocation errorLocation) {
String errorMessage;
errorMessage = "Internal parser error detected: " + getErrorType(errorType) + " "
+ getParsableDataType(parsableDataType);
+ getYangConstructType(yangConstructType);
if (!parsableDataTypeName.isEmpty()) {
errorMessage = errorMessage + " \"" + parsableDataTypeName + "\" ";
......
......@@ -60,6 +60,11 @@ public enum ListenerErrorType {
INVALID_CONTENT(),
/**
* Represents that the identifier collision is detected.
*/
IDENTIFIER_COLLISION(),
/**
* Represents that some of earlier parsed data is not handled correctly.
*/
UNHANDLED_PARSED_DATA();
......@@ -67,8 +72,8 @@ public enum ListenerErrorType {
/**
* Returns the message corresponding to listener error type.
*
* @param errorType enum value for type of error.
* @return message corresponding to listener error type.
* @param errorType enum value for type of error
* @return message corresponding to listener error type
*/
public static String getErrorType(ListenerErrorType errorType) {
......@@ -87,6 +92,8 @@ public enum ListenerErrorType {
return "Duplicate";
case INVALID_CONTENT:
return "Invalid content in";
case IDENTIFIER_COLLISION:
return "Identifier collision detected for";
case UNHANDLED_PARSED_DATA:
return "Unhandled parsed data at";
default:
......
......@@ -20,10 +20,13 @@ import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import org.onosproject.yangutils.utils.YangConstructType;
import static org.onosproject.yangutils.utils.YangConstructType.getYangConstructType;
import java.util.List;
/**
* It's a utility to carry out listener validation.
......@@ -39,15 +42,15 @@ public final class ListenerValidation {
/**
* Checks parsed data stack is not empty.
*
* @param listener Listener's object.
* @param errorType error type needs to be set in error message.
* @param parsableDataType type of parsable data in which error occurred.
* @param listener Listener's object
* @param errorType error type needs to be set in error message
* @param yangConstructType type of parsable data in which error occurred
* @param parsableDataTypeName name of parsable data type in which error
* occurred.
* @param errorLocation location where error occurred.
* occurred
* @param errorLocation location where error occurred
*/
public static void checkStackIsNotEmpty(TreeWalkListener listener, ListenerErrorType errorType,
ParsableDataType parsableDataType, String parsableDataTypeName,
YangConstructType yangConstructType, String parsableDataTypeName,
ListenerErrorLocation errorLocation) {
if (listener.getParsedDataStack().empty()) {
/*
......@@ -55,7 +58,7 @@ public final class ListenerValidation {
* parsableDataTypeName will be null in case there is no name
* attached to parsable data type.
*/
String message = constructListenerErrorMessage(errorType, parsableDataType, parsableDataTypeName,
String message = constructListenerErrorMessage(errorType, yangConstructType, parsableDataTypeName,
errorLocation);
throw new ParserException(message);
}
......@@ -64,16 +67,15 @@ public final class ListenerValidation {
/**
* Checks parsed data stack is empty.
*
* @param listener Listener's object.
* @param errorType error type needs to be set in error message.
* @param parsableDataType type of parsable data in which error occurred.
* @param listener Listener's object
* @param errorType error type needs to be set in error message
* @param yangConstructType type of parsable data in which error occurred
* @param parsableDataTypeName name of parsable data type in which error
* occurred.
* @param errorLocation location where error occurred.
* occurred
* @param errorLocation location where error occurred
*/
public static void checkStackIsEmpty(TreeWalkListener listener, ListenerErrorType errorType,
ParsableDataType parsableDataType, String parsableDataTypeName,
YangConstructType yangConstructType, String parsableDataTypeName,
ListenerErrorLocation errorLocation) {
if (!listener.getParsedDataStack().empty()) {
......@@ -82,7 +84,7 @@ public final class ListenerValidation {
* parsableDataTypeName will be null in case there is no name
* attached to parsable data type.
*/
String message = constructListenerErrorMessage(errorType, parsableDataType, parsableDataTypeName,
String message = constructListenerErrorMessage(errorType, yangConstructType, parsableDataTypeName,
errorLocation);
throw new ParserException(message);
}
......@@ -92,8 +94,8 @@ public final class ListenerValidation {
* Returns parent node config value, if top node does not specify a config statement
* then default value true is returned.
*
* @param listener listener's object.
* @return true/false parent's config value.
* @param listener listener's object
* @return true/false parent's config value
*/
public static boolean getParentNodeConfig(TreeWalkListener listener) {
YangNode parentNode;
......@@ -108,4 +110,71 @@ public final class ListenerValidation {
}
return true;
}
/**
* Checks if a rule occurrences is as per the expected YANG grammar's
* cardinality.
*
* @param childContext child's context
* @param yangChildConstruct child construct for whom cardinality is to be
* validated
* @param yangParentConstruct parent construct
* @param parentName parent name
* @throws ParserException exception if cardinality check fails
*/
public static void validateCardinality(List<?> childContext, YangConstructType yangChildConstruct,
YangConstructType yangParentConstruct, String parentName)
throws ParserException {
if (!childContext.isEmpty() && childContext.size() != 1) {
ParserException parserException = new ParserException("YANG file error: Invalid cardinality of "
+ getYangConstructType(yangChildConstruct) + " in " + getYangConstructType(yangParentConstruct)
+ " \"" + parentName + "\".");
throw parserException;
}
}
/**
* Checks if a rule occurrences is exactly 1.
*
* @param childContext child's context
* @param yangChildConstruct child construct for whom cardinality is to be
* validated
* @param yangParentConstruct parent construct
* @param parentName parent name
* @throws ParserException exception if cardinality check fails
*/
public static void validateCardinalityEqualsOne(List<?> childContext, YangConstructType yangChildConstruct,
YangConstructType yangParentConstruct, String parentName)
throws ParserException {
if (childContext.isEmpty() || childContext.size() != 1) {
ParserException parserException = new ParserException("YANG file error: Invalid cardinality of "
+ getYangConstructType(yangChildConstruct) + " in " + getYangConstructType(yangParentConstruct)
+ " \"" + parentName + "\".");
throw parserException;
}
}
/**
* Checks if a rule occurrences is minimum 1.
*
* @param childContext child's context
* @param yangChildConstruct child construct for whom cardinality is to be
* validated
* @param yangParentConstruct parent construct
* @param parentName parent name
* @throws ParserException exception if cardinality check fails
*/
public static void validateCardinalityNonNull(List<?> childContext, YangConstructType yangChildConstruct,
YangConstructType yangParentConstruct, String parentName)
throws ParserException {
if (childContext.isEmpty()) {
ParserException parserException = new ParserException("YANG file error: Invalid cardinality of "
+ getYangConstructType(yangChildConstruct) + " in " + getYangConstructType(yangParentConstruct)
+ " \"" + parentName + "\".");
throw parserException;
}
}
}
......
......@@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.parser;
package org.onosproject.yangutils.utils;
/**
* ENUM to represent the type of data in parse tree.
*/
public enum ParsableDataType {
public enum YangConstructType {
/**
* Identifies the module parsed data.
*/
......@@ -230,6 +230,11 @@ public enum ParsableDataType {
POSITION_DATA,
/**
* Identifies the YANG data definition statements.
*/
DATA_DEF_DATA,
/**
* Identifies the derived data type.
*/
DERIVED;
......@@ -237,12 +242,12 @@ public enum ParsableDataType {
/**
* Returns the YANG construct keyword corresponding to enum values.
*
* @param parsableDataType enum value for parsable data type.
* @return YANG construct keyword.
* @param yangConstructType enum value for parsable data type
* @return YANG construct keyword
*/
public static String getParsableDataType(ParsableDataType parsableDataType) {
public static String getYangConstructType(YangConstructType yangConstructType) {
switch (parsableDataType) {
switch (yangConstructType) {
case MODULE_DATA:
return "module";
case SUB_MODULE_DATA:
......@@ -327,6 +332,8 @@ public enum ParsableDataType {
return "position";
case DEFAULT_DATA:
return "default";
case DATA_DEF_DATA:
return "data-def-substatements";
case DERIVED:
return "derived";
default:
......
......@@ -69,6 +69,42 @@ public class ContainerListenerTest {
}
/**
* Checks if container identifier in module is duplicate.
*/
@Test(expected = ParserException.class)
public void processModuleDuplicateContainer() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/ModuleDuplicateContainer.yang");
}
/**
* Checks if container identifier in container is duplicate.
*/
@Test(expected = ParserException.class)
public void processContainerDuplicateContainer() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/ContainerDuplicateContainer.yang");
}
/**
* Checks if container identifier in list is duplicate.
*/
@Test(expected = ParserException.class)
public void processListDuplicateContainer() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/ListDuplicateContainer.yang");
}
/**
* Checks if container identifier collides with list at same level.
*/
@Test(expected = ParserException.class)
public void processDuplicateContainerAndList() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/DuplicateContainerAndList.yang");
}
/**
* Checks container statement as sub-statement of container.
*/
@Test
......@@ -170,7 +206,7 @@ public class ContainerListenerTest {
@Test
public void processContainerSubStatementCardinality() throws IOException, ParserException {
thrown.expect(ParserException.class);
thrown.expectMessage("Internal parser error detected: Invalid cardinality in reference before processing.");
thrown.expectMessage("YANG file error: Invalid cardinality of reference in container \"valid\".");
YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementCardinality.yang");
}
......@@ -193,4 +229,4 @@ public class ContainerListenerTest {
thrown.expectMessage("mismatched input '1valid' expecting IDENTIFIER");
YangNode node = manager.getDataModel("src/test/resources/ContainerInvalidIdentifier.yang");
}
}
\ No newline at end of file
}
......
......@@ -120,7 +120,7 @@ public class LeafListListenerTest {
@Test
public void processLeafListConfigInvalidCardinality() throws IOException, ParserException {
thrown.expect(ParserException.class);
thrown.expectMessage("Internal parser error detected: Invalid cardinality in config before processing.");
thrown.expectMessage("YANG file error: Invalid cardinality of config in leaf-list \"invalid-interval\".");
YangNode node = manager.getDataModel("src/test/resources/LeafListConfigInvalidCardinality.yang");
}
......@@ -131,7 +131,7 @@ public class LeafListListenerTest {
@Test
public void processLeafListUnitsInvalidCardinality() throws IOException, ParserException {
thrown.expect(ParserException.class);
thrown.expectMessage("Internal parser error detected: Invalid cardinality in units before processing.");
thrown.expectMessage("YANG file error: Invalid cardinality of units in leaf-list \"invalid-interval\".");
YangNode node = manager.getDataModel("src/test/resources/LeafListUnitsInvalidCardinality.yang");
}
......
......@@ -120,7 +120,7 @@ public class LeafListenerTest {
@Test
public void processLeafConfigInvalidCardinality() throws IOException, ParserException {
thrown.expect(ParserException.class);
thrown.expectMessage("Internal parser error detected: Invalid cardinality in config before processing.");
thrown.expectMessage("YANG file error: Invalid cardinality of config in leaf \"invalid-interval\".");
YangNode node = manager.getDataModel("src/test/resources/LeafConfigInvalidCardinality.yang");
}
......@@ -131,7 +131,7 @@ public class LeafListenerTest {
@Test
public void processLeafMandatoryInvalidCardinality() throws IOException, ParserException {
thrown.expect(ParserException.class);
thrown.expectMessage("Internal parser error detected: Invalid cardinality in mandatory before processing.");
thrown.expectMessage("YANG file error: Invalid cardinality of mandatory in leaf \"invalid-interval\".");
YangNode node = manager.getDataModel("src/test/resources/LeafMandatoryInvalidCardinality.yang");
}
......@@ -173,6 +173,33 @@ public class LeafListenerTest {
}
/**
* Checks duplicate leaf statement as sub-statement of module.
*/
@Test(expected = ParserException.class)
public void processModuleWithDuplicateLeaf() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/ModuleWithDuplicateLeaf.yang");
}
/**
* Checks duplicate leaf statement as sub-statement of container.
*/
@Test(expected = ParserException.class)
public void processContainerWithDuplicateLeaf() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/ContainerWithDuplicateLeaf.yang");
}
/**
* Checks duplicate leaf statement as sub-statement of list.
*/
@Test(expected = ParserException.class)
public void processListWithDuplicateLeaf() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/ListWithDuplicateLeaf.yang");
}
/**
* Checks leaf statement as sub-statement of list.
*/
@Test
......@@ -207,4 +234,4 @@ public class LeafListenerTest {
assertThat(leafInfo.getStatus(), is(YangStatusType.CURRENT));
assertThat(leafInfo.getReference(), is("\"RFC 6020\""));
}
}
\ No newline at end of file
}
......
......@@ -175,7 +175,7 @@ public class ListListenerTest {
@Test
public void processListSubStatementsCardinality() throws IOException, ParserException {
thrown.expect(ParserException.class);
thrown.expectMessage("Internal parser error detected: Invalid cardinality in reference before processing.");
thrown.expectMessage("YANG file error: Invalid cardinality of reference in list \"valid\".");
YangNode node = manager.getDataModel("src/test/resources/ListSubStatementsCardinality.yang");
}
......@@ -185,7 +185,7 @@ public class ListListenerTest {
@Test
public void processListStatementWithoutChild() throws IOException, ParserException {
thrown.expect(ParserException.class);
thrown.expectMessage("Internal parser error detected: Invalid cardinality in list before processing.");
thrown.expectMessage("YANG file error: Invalid cardinality of data-def-substatements in list \"valid\".");
YangNode node = manager.getDataModel("src/test/resources/ListStatementWithoutChild.yang");
}
......
......@@ -122,7 +122,7 @@ public class MaxElementsListenerTest {
@Test
public void processMaxElementsCardinality() throws IOException, ParserException {
thrown.expect(ParserException.class);
thrown.expectMessage("Internal parser error detected: Invalid cardinality in max-elements before processing.");
thrown.expectMessage("YANG file error: Invalid cardinality of max-elements in leaf-list \"invalid-interval\".");
YangNode node = manager.getDataModel("src/test/resources/MaxElementsCardinality.yang");
}
......
......@@ -133,8 +133,7 @@ public class MinElementsListenerTest {
@Test
public void processMinElementsInvalidCardinality() throws IOException, ParserException {
thrown.expect(ParserException.class);
thrown.expectMessage(
"Internal parser error detected: Invalid cardinality in" + " min-elements before processing.");
thrown.expectMessage("YANG file error: Invalid cardinality of min-elements in leaf-list \"invalid-interval\".");
YangNode node = manager.getDataModel("src/test/resources/MinElementsInvalidCardinality.yang");
}
......
......@@ -157,7 +157,7 @@ public class UnitsListenerTest {
@Test
public void processUnitsStatementCardinality() throws IOException, ParserException {
thrown.expect(ParserException.class);
thrown.expectMessage("Internal parser error detected: Invalid cardinality in units before processing.");
thrown.expectMessage("YANG file error: Invalid cardinality of units in leaf \"invalid-interval\".");
YangNode node = manager.getDataModel("src/test/resources/UnitsStatementCardinality.yang");
}
......
......@@ -64,7 +64,7 @@ public class VersionListenerTest {
YangNode node = manager.getDataModel("src/test/resources/VersionNotPresent.yang");
// Checks for the version value in data model tree.
assertThat(((YangModule) node).getVersion(), is((byte) 0));
assertThat(((YangModule) node).getVersion(), is((byte) 1));
}
/**
......
......@@ -20,7 +20,7 @@ import org.junit.Test;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.parser.ParsableDataType.CONTACT_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.CONTACT_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
......
......@@ -23,7 +23,7 @@ import org.onosproject.yangutils.datamodel.YangRevision;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.ParsableDataType.YANGBASE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.YANGBASE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
......
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
container ospf {
container valid {
leaf invalid-interval {
type "uint16";
units "seconds";
status current;
reference "RFC 6020";
}
}
container valid {
leaf invalid-interval {
type "uint16";
units "seconds";
status current;
reference "RFC 6020";
}
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
container valid {
leaf invalid-interval {
type "uint16";
units "seconds";
description "Interval before a route is declared invalid";
config true;
mandatory true;
status current;
reference "RFC 6020";
}
leaf valid-interval {
type "uint16";
units "seconds";
description "Interval before a route is declared invalid";
config true;
mandatory true;
status current;
reference "RFC 6020";
}
leaf valid-interval {
type "uint16";
units "seconds";
description "Interval before a route is declared invalid";
config true;
mandatory true;
status current;
reference "RFC 6020";
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
container ospf {
container valid {
leaf invalid-interval {
type "uint16";
units "seconds";
status current;
reference "RFC 6020";
}
}
list valid {
key "process-id";
container interface {
leaf invalid-interval {
type "uint16";
units "seconds";
status current;
reference "RFC 6020";
}
}
leaf process-id {
type "string";
}
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
list ospf {
key "process-id";
container interface {
leaf invalid-interval {
type "uint16";
units "seconds";
status current;
reference "RFC 6020";
}
}
leaf process-id {
type "string";
}
container interface {
leaf invalid-interval {
type "uint16";
units "seconds";
status current;
reference "RFC 6020";
}
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
list valid {
key "invalid-interval";
leaf invalid-interval {
type "uint16";
units "seconds";
description "Interval before a route is declared invalid";
config true;
mandatory true;
status current;
reference "RFC 6020";
}
leaf invalid-interval {
type "uint16";
units "seconds";
description "Interval before a route is declared invalid";
config true;
mandatory true;
status current;
reference "RFC 6020";
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
container valid {
leaf invalid-interval {
type "uint16";
units "seconds";
status current;
reference "RFC 6020";
}
}
container invalid {
leaf invalid-interval {
type "uint16";
units "seconds";
status current;
reference "RFC 6020";
}
}
container valid {
leaf invalid-interval {
type "uint16";
units "seconds";
status current;
reference "RFC 6020";
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
leaf invalid-interval {
type "uint16";
units "seconds";
description "Interval before a route is declared invalid";
config true;
mandatory true;
status current;
reference "RFC 6020";
}
leaf valid-interval {
type "uint16";
units "seconds";
description "Interval before a route is declared invalid";
config true;
mandatory true;
status current;
reference "RFC 6020";
}
leaf invalid-interval {
type "uint16";
units "seconds";
description "Interval before a route is declared invalid";
config true;
mandatory true;
status current;
reference "RFC 6020";
}
}