VinodKumarS-Huawei
Committed by Gerrit Code Review

[ONOS-4636]YANG Grouping linking bug fix + YANG Code review comment fix

Change-Id: I68ee8dd08266a02593e217cef1a9bb010037d673
(cherry picked from commit 2ee9e7e8)
Showing 72 changed files with 1726 additions and 598 deletions
......@@ -79,7 +79,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
/**
* Representation of data model node to maintain information defined in YANG augment.
*/
public class YangAugment extends YangNode
public class YangAugment
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
/**
......@@ -163,13 +164,15 @@ public class YangAugment extends YangNode
}
@Override
public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
public void detectCollidingChild(String identifierName, YangConstructType dataType)
throws DataModelException {
// Detect colliding child.
detectCollidingChildUtil(identifierName, dataType, this);
}
@Override
public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
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 input \""
+ this.getName() + "\"");
......@@ -191,7 +194,8 @@ public class YangAugment extends YangNode
*
* @param leafsList the list of leaf to set
*/
private void setListOfLeaf(List<YangLeaf> leafsList) {
@Override
public void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
}
......@@ -224,7 +228,8 @@ public class YangAugment extends YangNode
*
* @param listOfLeafList the list of leaf-list to set
*/
private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
@Override
public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
}
......@@ -298,7 +303,8 @@ public class YangAugment extends YangNode
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
public void validateDataOnEntry()
throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
......@@ -308,7 +314,8 @@ public class YangAugment extends YangNode
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
public void validateDataOnExit()
throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
......
......@@ -88,10 +88,12 @@ import static org.onosproject.yangutils.utils.YangConstructType.CASE_DATA;
* | when | 7.19.5 | 0..1 |-TODO |
* +--------------+---------+-------------+------------------+
*/
/**
* Represents data model node to maintain information defined in YANG case.
*/
public class YangCase extends YangNode
public class YangCase
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
/**
......@@ -188,7 +190,8 @@ public class YangCase extends YangNode
*
* @param leafsList the list of leaf to set
*/
private void setListOfLeaf(List<YangLeaf> leafsList) {
@Override
public void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
}
......@@ -221,7 +224,8 @@ public class YangCase extends YangNode
*
* @param listOfLeafList the list of leaf-list to set
*/
private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
@Override
public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
}
......@@ -295,7 +299,8 @@ public class YangCase extends YangNode
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
public void validateDataOnEntry()
throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
......@@ -305,12 +310,14 @@ public class YangCase extends YangNode
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
public void validateDataOnExit()
throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
@Override
public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
public void detectCollidingChild(String identifierName, YangConstructType dataType)
throws DataModelException {
if (!(getParent() instanceof YangChoice)) {
throw new DataModelException("Internal Data Model Tree Error: Invalid/Missing holder in case " +
getName());
......@@ -320,7 +327,8 @@ public class YangCase extends YangNode
}
@Override
public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
public void detectSelfCollision(String identifierName, YangConstructType dataType)
throws DataModelException {
if (dataType == CASE_DATA) {
if (getName().equals(identifierName)) {
......
......@@ -87,7 +87,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
/**
* Represents data model node to maintain information defined in YANG container.
*/
public class YangContainer extends YangNode
public class YangContainer
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
/**
......@@ -211,7 +212,8 @@ public class YangContainer extends YangNode
*
* @param leafsList the list of leaf to set
*/
private void setListOfLeaf(List<YangLeaf> leafsList) {
@Override
public void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
}
......@@ -245,7 +247,8 @@ public class YangContainer extends YangNode
*
* @param listOfLeafList the list of leaf-list to set
*/
private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
@Override
public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
}
......@@ -338,7 +341,8 @@ public class YangContainer extends YangNode
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
public void validateDataOnEntry()
throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
......@@ -348,7 +352,8 @@ public class YangContainer extends YangNode
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
public void validateDataOnExit()
throws DataModelException {
List<YangLeaf> leaves = getListOfLeaf();
List<YangLeafList> leafLists = getListOfLeafList();
......@@ -397,7 +402,8 @@ public class YangContainer extends YangNode
* @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 {
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
......@@ -423,13 +429,15 @@ public class YangContainer extends YangNode
}
@Override
public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
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 {
public void detectSelfCollision(String identifierName, YangConstructType dataType)
throws DataModelException {
if (getName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate input identifier detected, same as container \""
+ getName() + "\"");
......
......@@ -17,7 +17,8 @@
package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.linker.impl.ResolvableStatus;
import org.onosproject.yangutils.linker.ResolvableStatus;
import com.google.common.base.Strings;
import static org.onosproject.yangutils.datamodel.YangDataTypes.BINARY;
......@@ -30,8 +31,8 @@ import static org.onosproject.yangutils.datamodel.YangDataTypes.IDENTITYREF;
import static org.onosproject.yangutils.datamodel.YangDataTypes.LEAFREF;
import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
import static org.onosproject.yangutils.datamodel.YangDataTypes.UNION;
import static org.onosproject.yangutils.linker.impl.ResolvableStatus.INTRA_FILE_RESOLVED;
import static org.onosproject.yangutils.linker.impl.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.linker.ResolvableStatus.INTRA_FILE_RESOLVED;
import static org.onosproject.yangutils.linker.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.utils.RestrictionResolver.isOfRangeRestrictedType;
import static org.onosproject.yangutils.utils.RestrictionResolver.processLengthRestriction;
import static org.onosproject.yangutils.utils.RestrictionResolver.processRangeRestriction;
......@@ -41,7 +42,8 @@ import static org.onosproject.yangutils.utils.RestrictionResolver.processRangeRe
*
* @param <T> extended information.
*/
public class YangDerivedInfo<T> implements LocationInfo {
public class YangDerivedInfo<T>
implements LocationInfo, Cloneable {
/**
* YANG typedef reference.
......@@ -224,8 +226,11 @@ public class YangDerivedInfo<T> implements LocationInfo {
* @return resolution status
* @throws DataModelException a violation in data mode rule
*/
public ResolvableStatus resolve() throws DataModelException {
public ResolvableStatus resolve()
throws DataModelException {
YangType<?> baseType = getReferredTypeDef().getTypeDefBaseType();
/*
* Checks the data type of the referred typedef, if it's derived,
* obtain effective built-in type and restrictions from it's derived
......@@ -238,6 +243,7 @@ public class YangDerivedInfo<T> implements LocationInfo {
if (baseType.getResolvableStatus() != INTRA_FILE_RESOLVED && baseType.getResolvableStatus() != RESOLVED) {
throw new DataModelException("Linker Error: Referred typedef is not resolved for type.");
}
/*
* Check if the referred typedef is intra file resolved, if yes sets
* current status also to intra file resolved .
......@@ -401,6 +407,7 @@ public class YangDerivedInfo<T> implements LocationInfo {
}
}
}
/*
* Check if the data type is the one which can't be restricted, in
* this case check whether no self restrictions should be present.
......@@ -414,6 +421,7 @@ public class YangDerivedInfo<T> implements LocationInfo {
throw new DataModelException("YANG file error: Restrictions can't be applied to a given type");
}
}
// Throw exception for unsupported types
throw new DataModelException("Linker error: Unable to process the derived type.");
}
......@@ -424,7 +432,8 @@ public class YangDerivedInfo<T> implements LocationInfo {
* @param refStringRestriction referred string restriction of typedef
* @throws DataModelException a violation in data model rule
*/
private void resolveStringRestriction(YangStringRestriction refStringRestriction) throws DataModelException {
private void resolveStringRestriction(YangStringRestriction refStringRestriction)
throws DataModelException {
YangStringRestriction curStringRestriction = null;
YangRangeRestriction refRangeRestriction = null;
YangPatternRestriction refPatternRestriction = null;
......@@ -522,7 +531,8 @@ public class YangDerivedInfo<T> implements LocationInfo {
* @return resolved length restriction
* @throws DataModelException a violation in data model rule
*/
private YangRangeRestriction resolveLengthRestriction(YangRangeRestriction refLengthRestriction) throws
private YangRangeRestriction resolveLengthRestriction(YangRangeRestriction refLengthRestriction)
throws
DataModelException {
/*
......@@ -572,7 +582,8 @@ public class YangDerivedInfo<T> implements LocationInfo {
* @param curRestriction self restriction
*/
private void resolveLengthAndRangeRestriction(YangRangeRestriction refRestriction,
YangRangeRestriction curRestriction) throws DataModelException {
YangRangeRestriction curRestriction)
throws DataModelException {
for (Object curInterval : curRestriction.getAscendingRangeIntervals()) {
if (!(curInterval instanceof YangRangeInterval)) {
throw new DataModelException("Linker error: Current range intervals not processed correctly.");
......@@ -594,7 +605,8 @@ public class YangDerivedInfo<T> implements LocationInfo {
* @param refRangeRestriction referred range restriction of typedef
* @throws DataModelException a violation in data model rule
*/
private void resolveRangeRestriction(YangRangeRestriction refRangeRestriction) throws DataModelException {
private void resolveRangeRestriction(YangRangeRestriction refRangeRestriction)
throws DataModelException {
/*
* Check that string restriction should be null when built-in type is
......
......@@ -31,7 +31,9 @@ import org.onosproject.yangutils.utils.YangConstructType;
/**
* Represents the enumeration data type information.
*/
public class YangEnumeration extends YangNode implements Parsable, CollisionDetector {
public class YangEnumeration
extends YangNode
implements Parsable, CollisionDetector {
// Enumeration info set.
private SortedSet<YangEnum> enumSet;
......@@ -71,7 +73,8 @@ public class YangEnumeration extends YangNode implements Parsable, CollisionDete
* @param enumInfo the ENUM information to be added
* @throws DataModelException due to violation in data model rules
*/
public void addEnumInfo(YangEnum enumInfo) throws DataModelException {
public void addEnumInfo(YangEnum enumInfo)
throws DataModelException {
if (!getEnumSet().add(enumInfo)) {
throw new DataModelException("YANG ENUM already exists");
}
......@@ -113,7 +116,8 @@ public class YangEnumeration extends YangNode implements Parsable, CollisionDete
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
public void validateDataOnEntry()
throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
......@@ -123,21 +127,24 @@ public class YangEnumeration extends YangNode implements Parsable, CollisionDete
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
public void validateDataOnExit()
throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
@Override
public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
public void detectCollidingChild(String identifierName, YangConstructType dataType)
throws DataModelException {
/*
Do nothing.The implementation for this is not required.
Do nothing, since it is not part of the schema tree, it is only type of an existing node in schema tree.
*/
}
@Override
public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
public void detectSelfCollision(String identifierName, YangConstructType dataType)
throws DataModelException {
/*
Do nothing.The implementation for this is not required.
Do nothing, since it is not part of the schema tree, it is only type of an existing node in schema tree.
*/
}
}
......
......@@ -77,7 +77,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
/**
* Represents data model node to maintain information defined in YANG grouping.
*/
public class YangGrouping extends YangNode
public class YangGrouping
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
/**
......@@ -174,7 +175,8 @@ public class YangGrouping extends YangNode
*
* @param leafsList the list of leaf to set
*/
private void setListOfLeaf(List<YangLeaf> leafsList) {
@Override
public void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
}
......@@ -203,7 +205,8 @@ public class YangGrouping extends YangNode
*
* @param listOfLeafList the list of leaf-list to set
*/
private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
@Override
public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
}
......@@ -273,7 +276,8 @@ public class YangGrouping extends YangNode
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
public void validateDataOnEntry()
throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
......@@ -283,7 +287,8 @@ public class YangGrouping extends YangNode
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
public void validateDataOnExit()
throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
......@@ -299,13 +304,15 @@ public class YangGrouping extends YangNode
* module.
*/
@Override
public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
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 {
public void detectSelfCollision(String identifierName, YangConstructType dataType)
throws DataModelException {
if (getName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate input identifier detected, same as grouping \"" +
getName() + "\"");
......
......@@ -68,7 +68,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
/**
* Represents data model node to maintain information defined in YANG input.
*/
public class YangInput extends YangNode
public class YangInput
extends YangNode
implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentationHolder {
/**
......@@ -96,13 +97,15 @@ public class YangInput extends YangNode
}
@Override
public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
public void detectCollidingChild(String identifierName, YangConstructType dataType)
throws DataModelException {
// Detect colliding child.
detectCollidingChildUtil(identifierName, dataType, this);
}
@Override
public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
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 input \""
+ this.getName() + "\"");
......@@ -115,12 +118,14 @@ public class YangInput extends YangNode
}
@Override
public void validateDataOnEntry() throws DataModelException {
public void validateDataOnEntry()
throws DataModelException {
//TODO: implement the method.
}
@Override
public void validateDataOnExit() throws DataModelException {
public void validateDataOnExit()
throws DataModelException {
//TODO: implement the method.
}
......@@ -130,6 +135,12 @@ public class YangInput extends YangNode
}
@Override
public void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
}
@Override
public void addLeaf(YangLeaf leaf) {
getListOfLeaf().add(leaf);
}
......@@ -140,6 +151,11 @@ public class YangInput extends YangNode
}
@Override
public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
}
@Override
public void addLeafList(YangLeafList leafList) {
getListOfLeafList().add(leafList);
}
......
......@@ -58,7 +58,7 @@ import org.onosproject.yangutils.utils.YangConstructType;
* Represents leaf data represented in YANG.
*/
public class YangLeaf
implements YangCommonInfo, Parsable {
implements YangCommonInfo, Parsable, Cloneable {
/**
* Name of leaf.
......@@ -107,6 +107,11 @@ public class YangLeaf
private String defaultValueInString;
/**
* YANG Node in which the leaf is contained.
*/
YangLeavesHolder containedIn;
/**
* Creates a YANG leaf.
*/
public YangLeaf() {
......@@ -281,6 +286,30 @@ public class YangLeaf
}
/**
* Retrieves the YANG node in which the leaf is defined.
*
* @return the YANG node in which the leaf is defined
*/
public YangLeavesHolder getContainedIn() {
return containedIn;
}
/**
* Assigns the YANG node in which the leaf is defined.
*
* @param containedIn the YANG node in which the leaf is defined
*/
public void setContainedIn(YangLeavesHolder containedIn) {
this.containedIn = containedIn;
}
@Override
public YangLeaf clone()
throws CloneNotSupportedException {
return (YangLeaf) super.clone();
}
/**
* Returns the type of the parsed data.
*
* @return returns LEAF_DATA
......
......@@ -54,7 +54,7 @@ import org.onosproject.yangutils.utils.YangConstructType;
* Represents leaf-list data represented in YANG.
*/
public class YangLeafList
implements YangCommonInfo, Parsable {
implements YangCommonInfo, Parsable, Cloneable {
/**
* Name of leaf-list.
......@@ -124,6 +124,11 @@ public class YangLeafList
private YangType<?> dataType;
/**
* YANG Node in which the leaf is contained.
*/
YangLeavesHolder containedIn;
/**
* Creates a YANG leaf-list.
*/
public YangLeafList() {
......@@ -298,6 +303,30 @@ public class YangLeafList
}
/**
* Retrieves the YANG node in which the leaf is defined.
*
* @return the YANG node in which the leaf is defined
*/
public YangLeavesHolder getContainedIn() {
return containedIn;
}
/**
* Assigns the YANG node in which the leaf is defined.
*
* @param containedIn the YANG node in which the leaf is defined
*/
public void setContainedIn(YangLeavesHolder containedIn) {
this.containedIn = containedIn;
}
@Override
public YangLeafList clone()
throws CloneNotSupportedException {
return (YangLeafList) super.clone();
}
/**
* Returns the type of the parsed data.
*
* @return returns LEAF_LIST_DATA
......
......@@ -33,6 +33,13 @@ public interface YangLeavesHolder {
List<YangLeaf> getListOfLeaf();
/**
* Sets the list of leaves.
*
* @param leafsList the list of leaf to set
*/
void setListOfLeaf(List<YangLeaf> leafsList);
/**
* Adds leaf in data holder like container / list.
*
* @param leaf the leaf to be added
......@@ -47,6 +54,13 @@ public interface YangLeavesHolder {
List<YangLeafList> getListOfLeafList();
/**
* Sets the list of leaf-list.
*
* @param listOfLeafList the list of leaf-list to set
*/
void setListOfLeafList(List<YangLeafList> listOfLeafList);
/**
* Adds leaf-list in data holder like container / list.
*
* @param leafList the leaf-list to be added
......
......@@ -67,7 +67,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
/**
* Represents list data represented in YANG.
*/
public class YangList extends YangNode
public class YangList
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
/**
......@@ -254,7 +255,8 @@ public class YangList extends YangNode
* @param key key field name.
* @throws DataModelException a violation of data model rules
*/
public void addKey(String key) throws DataModelException {
public void addKey(String key)
throws DataModelException {
if (getKeyList() == null) {
setKeyList(new LinkedList<String>());
}
......@@ -282,7 +284,8 @@ public class YangList extends YangNode
*
* @param leafsList the list of leaf to set
*/
private void setListOfLeaf(List<YangLeaf> leafsList) {
@Override
public void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
}
......@@ -315,7 +318,8 @@ public class YangList extends YangNode
*
* @param listOfLeafList the list of leaf-list to set
*/
private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
@Override
public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
}
......@@ -425,7 +429,8 @@ public class YangList extends YangNode
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
public void validateDataOnEntry()
throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
......@@ -435,7 +440,8 @@ public class YangList extends YangNode
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
public void validateDataOnExit()
throws DataModelException {
List<String> keys = getKeyList();
List<YangLeaf> leaves = getListOfLeaf();
List<YangLeafList> leafLists = getListOfLeafList();
......@@ -493,7 +499,8 @@ public class YangList extends YangNode
* @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 {
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
......@@ -526,7 +533,8 @@ public class YangList extends YangNode
* @param keys list of key attributes of list
* @throws DataModelException a violation of data model rules
*/
private void validateKey(List<YangLeaf> leaves, List<YangLeafList> leafLists, List<String> keys) throws
private void validateKey(List<YangLeaf> leaves, List<YangLeafList> leafLists, List<String> keys)
throws
DataModelException {
boolean leafFound = false;
List<YangLeaf> keyLeaves = new LinkedList<>();
......@@ -595,13 +603,15 @@ public class YangList extends YangNode
}
@Override
public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
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 {
public void detectSelfCollision(String identifierName, YangConstructType dataType)
throws DataModelException {
if (getName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate input identifier detected, same as list \"" +
getName() + "\"");
......
......@@ -19,9 +19,11 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.linker.impl.YangReferenceResolver;
import org.onosproject.yangutils.linker.ResolvableType;
import org.onosproject.yangutils.linker.YangReferenceResolver;
import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.plugin.manager.YangFileInfo;
......@@ -74,7 +76,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLi
/**
* Represents data model node to maintain information defined in YANG module.
*/
public class YangModule extends YangNode
public class YangModule
extends YangNode
implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver,
RpcNotificationContainer {
......@@ -85,7 +88,7 @@ public class YangModule extends YangNode
/**
* Reference:RFC 6020.
* <p>
*
* The "contact" statement provides contact information for the module. The
* argument is a string that is used to specify contact information for the
* person or persons to whom technical queries concerning this module should
......@@ -96,7 +99,7 @@ public class YangModule extends YangNode
/**
* Reference:RFC 6020.
* <p>
*
* The "description" statement takes as an argument a string that contains a
* human-readable textual description of this definition. The text is
* provided in a language (or languages) chosen by the module developer; for
......@@ -131,7 +134,7 @@ public class YangModule extends YangNode
/**
* Reference:RFC 6020.
* <p>
*
* The "organization" statement defines the party responsible for this
* module. The argument is a string that is used to specify a textual
* description of the organization(s) under whose auspices this module was
......@@ -193,7 +196,12 @@ public class YangModule extends YangNode
* matching "typedef" or "grouping" statement among the immediate
* sub-statements of each ancestor statement.
*/
private List<YangResolutionInfo> unresolvedResolutionList;
private List<YangResolutionInfo> derivedTypeResolutionList;
/**
* uses resolution list.
*/
private List<YangResolutionInfo> usesResolutionList;
/**
* Creates a YANG node of module type.
......@@ -201,7 +209,8 @@ public class YangModule extends YangNode
public YangModule() {
super(YangNodeType.MODULE_NODE);
unresolvedResolutionList = new LinkedList<YangResolutionInfo>();
derivedTypeResolutionList = new LinkedList<YangResolutionInfo>();
usesResolutionList = new LinkedList<YangResolutionInfo>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
......@@ -326,6 +335,11 @@ public class YangModule extends YangNode
return listOfLeaf;
}
@Override
public void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
}
/**
* Adds a leaf in module.
*
......@@ -346,6 +360,12 @@ public class YangModule extends YangNode
return listOfLeafList;
}
@Override
public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
}
/**
* Adds a leaf-list in module.
*
......@@ -413,17 +433,19 @@ public class YangModule extends YangNode
}
@Override
public void resolveSelfFileLinking() throws DataModelException {
public void resolveSelfFileLinking(ResolvableType type)
throws DataModelException {
// Get the list to be resolved.
List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList();
List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(type);
// Resolve linking for a resolution list.
resolveLinkingForResolutionList(resolutionList, this);
}
@Override
public void resolveInterFileLinking() throws DataModelException {
public void resolveInterFileLinking(ResolvableType type)
throws DataModelException {
// Get the list to be resolved.
List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList();
List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(type);
// Resolve linking for a resolution list.
linkInterFileReferences(resolutionList, this);
}
......@@ -500,7 +522,8 @@ public class YangModule extends YangNode
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
public void validateDataOnEntry()
throws DataModelException {
/*
* Module is root in the data model tree, hence there is no entry
* validation
......@@ -513,7 +536,8 @@ public class YangModule extends YangNode
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
public void validateDataOnExit()
throws DataModelException {
/*
* TODO: perform symbol linking for the imported or included YANG info.
* TODO: perform symbol resolution for referred YANG entities.
......@@ -521,29 +545,47 @@ public class YangModule extends YangNode
}
@Override
public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
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 {
public void detectSelfCollision(String identifierName, YangConstructType dataType)
throws DataModelException {
// Not required as module doesn't have any parent.
}
@Override
public List<YangResolutionInfo> getUnresolvedResolutionList() {
return unresolvedResolutionList;
public List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type) {
if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
return derivedTypeResolutionList;
} else {
return usesResolutionList;
}
}
@Override
public void addToResolutionList(YangResolutionInfo resolutionInfo) {
unresolvedResolutionList.add(resolutionInfo);
public void addToResolutionList(YangResolutionInfo resolutionInfo,
ResolvableType type) {
if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
derivedTypeResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_USES) {
usesResolutionList.add(resolutionInfo);
}
}
@Override
public void setResolutionList(List<YangResolutionInfo> resolutionList) {
unresolvedResolutionList = resolutionList;
public void setResolutionList(List<YangResolutionInfo> resolutionList,
ResolvableType type) {
if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
derivedTypeResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_USES) {
usesResolutionList = resolutionList;
}
}
@Override
......
......@@ -16,12 +16,6 @@
package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.translator.tojava.TraversalType;
import static org.onosproject.yangutils.translator.tojava.TraversalType.CHILD;
import static org.onosproject.yangutils.translator.tojava.TraversalType.PARENT;
import static org.onosproject.yangutils.translator.tojava.TraversalType.SIBILING;
/**
* Represents base class of a node in data model tree.
......@@ -229,179 +223,4 @@ public abstract class YangNode
newChild.setPreviousSibling(curNode);
}
}
/**
* Clone the current node contents and create a new node.
*
* @return cloned node
* @throws CloneNotSupportedException clone is not supported by the referred
* node
*/
@Override
public YangNode clone()
throws CloneNotSupportedException {
YangNode clonedNode = (YangNode) super.clone();
clonedNode.setParent(null);
clonedNode.setChild(null);
clonedNode.setNextSibling(null);
clonedNode.setPreviousSibling(null);
return clonedNode;
}
/**
* Clone the subtree from the specified source node to the mentioned target
* node. The source and target root node cloning is carried out by the
* caller.
*
* @param srcRootNode source node for sub tree cloning
* @param dstRootNode destination node where the sub tree needs to be cloned
* @throws DataModelException data model error
*/
public static void cloneSubTree(YangNode srcRootNode, YangNode dstRootNode)
throws DataModelException {
YangNode nextNodeToClone = srcRootNode;
TraversalType curTraversal;
YangNode clonedTreeCurNode = dstRootNode;
YangNode newNode = null;
nextNodeToClone = nextNodeToClone.getChild();
if (nextNodeToClone == null) {
return;
} else {
/**
* Root level cloning is taken care in the caller.
*/
curTraversal = CHILD;
}
/**
* Caller ensures the cloning of the root nodes
*/
try {
while (nextNodeToClone != srcRootNode) {
if (nextNodeToClone == null) {
throw new DataModelException("Internal error: Cloning failed, source tree null pointer reached");
}
if (curTraversal != PARENT) {
newNode = nextNodeToClone.clone();
detectCollisionWhileCloning(clonedTreeCurNode, newNode, curTraversal);
}
if (curTraversal == CHILD) {
/**
* add the new node to the cloned tree.
*/
clonedTreeCurNode.addChild(newNode);
/**
* update the cloned tree's traversal current node as the
* new node.
*/
clonedTreeCurNode = newNode;
} else if (curTraversal == SIBILING) {
clonedTreeCurNode.addNextSibling(newNode);
clonedTreeCurNode = newNode;
} else if (curTraversal == PARENT) {
clonedTreeCurNode = clonedTreeCurNode.getParent();
}
if (curTraversal != PARENT && nextNodeToClone.getChild() != null) {
curTraversal = CHILD;
/**
* update the traversal's current node.
*/
nextNodeToClone = nextNodeToClone.getChild();
} else if (nextNodeToClone.getNextSibling() != null) {
curTraversal = SIBILING;
nextNodeToClone = nextNodeToClone.getNextSibling();
} else {
curTraversal = PARENT;
nextNodeToClone = nextNodeToClone.getParent();
}
}
} catch (CloneNotSupportedException e) {
throw new DataModelException("Failed to clone the tree");
}
}
/**
* Detects collision when the grouping is deep copied to the uses's parent.
*
* @param currentNode parent/previous sibling node for the new node
* @param newNode node which has to be added
* @param addAs traversal type of the node
* @throws DataModelException data model error
*/
private static void detectCollisionWhileCloning(YangNode currentNode, YangNode newNode, TraversalType addAs)
throws DataModelException {
if (!(currentNode instanceof CollisionDetector)
|| !(newNode instanceof Parsable)) {
throw new DataModelException("Node in data model tree does not support collision detection");
}
CollisionDetector collisionDetector = (CollisionDetector) currentNode;
Parsable parsable = (Parsable) newNode;
if (addAs == TraversalType.CHILD) {
collisionDetector.detectCollidingChild(newNode.getName(), parsable.getYangConstructType());
} else if (addAs == TraversalType.SIBILING) {
currentNode = currentNode.getParent();
if (!(currentNode instanceof CollisionDetector)) {
throw new DataModelException("Node in data model tree does not support collision detection");
}
collisionDetector = (CollisionDetector) currentNode;
collisionDetector.detectCollidingChild(newNode.getName(), parsable.getYangConstructType());
} else {
throw new DataModelException("Errored tree cloning");
}
}
/**
* Add a new next sibling.
*
* @param newSibling new sibling to be added
* @throws DataModelException data model error
*/
private void addNextSibling(YangNode newSibling)
throws DataModelException {
if (newSibling.getNodeType() == null) {
throw new DataModelException("Cloned abstract node cannot be inserted into a tree");
}
if (newSibling.getParent() == null) {
/**
* Since the siblings needs to have a common parent, set the parent
* as the current node's parent
*/
newSibling.setParent(getParent());
} else {
throw new DataModelException("Node is already part of a tree, and cannot be added as a sibling");
}
if (newSibling.getPreviousSibling() == null) {
newSibling.setPreviousSibling(this);
setNextSibling(newSibling);
} else {
throw new DataModelException("New sibling to be added is not atomic, it already has a previous sibling");
}
if (newSibling.getChild() != null) {
throw new DataModelException("Sibling to be added is not atomic, it already has a child");
}
if (newSibling.getNextSibling() != null) {
throw new DataModelException("Sibling to be added is not atomic, it already has a next sibling");
}
}
}
......
......@@ -74,7 +74,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
/**
* Represents data model node to maintain information defined in YANG notification.
*/
public class YangNotification extends YangNode
public class YangNotification
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
/**
......@@ -117,13 +118,15 @@ public class YangNotification extends YangNode
}
@Override
public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
public void detectCollidingChild(String identifierName, YangConstructType dataType)
throws DataModelException {
// Detect colliding child.
detectCollidingChildUtil(identifierName, dataType, this);
}
@Override
public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
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 notification \""
+ this.getName() + "\"");
......@@ -136,12 +139,14 @@ public class YangNotification extends YangNode
}
@Override
public void validateDataOnEntry() throws DataModelException {
public void validateDataOnEntry()
throws DataModelException {
//TODO: implement the method.
}
@Override
public void validateDataOnExit() throws DataModelException {
public void validateDataOnExit()
throws DataModelException {
//TODO: implement the method.
}
......@@ -161,6 +166,11 @@ public class YangNotification extends YangNode
}
@Override
public void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
}
@Override
public void addLeaf(YangLeaf leaf) {
getListOfLeaf().add(leaf);
}
......@@ -171,6 +181,11 @@ public class YangNotification extends YangNode
}
@Override
public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
}
@Override
public void addLeafList(YangLeafList leafList) {
getListOfLeafList().add(leafList);
}
......
......@@ -67,7 +67,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
/**
* Represents data model node to maintain information defined in YANG output.
*/
public class YangOutput extends YangNode
public class YangOutput
extends YangNode
implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentationHolder {
/**
......@@ -95,13 +96,15 @@ public class YangOutput extends YangNode
}
@Override
public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
public void detectCollidingChild(String identifierName, YangConstructType dataType)
throws DataModelException {
// Detect colliding child.
detectCollidingChildUtil(identifierName, dataType, this);
}
@Override
public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
public void detectSelfCollision(String identifierName, YangConstructType dataType)
throws DataModelException {
if (this.getName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate identifier detected, same as output \""
+ this.getName() + "\"");
......@@ -114,12 +117,14 @@ public class YangOutput extends YangNode
}
@Override
public void validateDataOnEntry() throws DataModelException {
public void validateDataOnEntry()
throws DataModelException {
//TODO: implement the method.
}
@Override
public void validateDataOnExit() throws DataModelException {
public void validateDataOnExit()
throws DataModelException {
//TODO: implement the method.
}
......@@ -134,11 +139,22 @@ public class YangOutput extends YangNode
}
@Override
public void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
}
@Override
public List<YangLeafList> getListOfLeafList() {
return listOfLeafList;
}
@Override
public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
}
@Override
public void addLeafList(YangLeafList leafList) {
getListOfLeafList().add(leafList);
}
......
......@@ -19,9 +19,11 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.linker.impl.YangReferenceResolver;
import org.onosproject.yangutils.linker.ResolvableType;
import org.onosproject.yangutils.linker.YangReferenceResolver;
import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.plugin.manager.YangFileInfo;
......@@ -82,7 +84,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLi
/**
* Represents data model node to maintain information defined in YANG sub-module.
*/
public class YangSubModule extends YangNode
public class YangSubModule
extends YangNode
implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver,
RpcNotificationContainer {
......@@ -156,6 +159,7 @@ public class YangSubModule extends YangNode
* Prefix of parent module.
*/
private String prefix;
/*-
* Reference RFC 6020.
*
......@@ -190,14 +194,20 @@ public class YangSubModule extends YangNode
* matching "typedef" or "grouping" statement among the immediate
* sub-statements of each ancestor statement.
*/
private List<YangResolutionInfo> unresolvedResolutionList;
private List<YangResolutionInfo> derivedTypeResolutionList;
/**
* uses resolution list.
*/
private List<YangResolutionInfo> usesResolutionList;
/**
* Creates a sub module node.
*/
public YangSubModule() {
super(YangNodeType.SUB_MODULE_NODE);
unresolvedResolutionList = new LinkedList<YangResolutionInfo>();
derivedTypeResolutionList = new LinkedList<YangResolutionInfo>();
usesResolutionList = new LinkedList<YangResolutionInfo>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
......@@ -341,17 +351,19 @@ public class YangSubModule extends YangNode
}
@Override
public void resolveSelfFileLinking() throws DataModelException {
public void resolveSelfFileLinking(ResolvableType type)
throws DataModelException {
// Get the list to be resolved.
List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList();
List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(type);
// Resolve linking for a resolution list.
resolveLinkingForResolutionList(resolutionList, this);
}
@Override
public void resolveInterFileLinking() throws DataModelException {
public void resolveInterFileLinking(ResolvableType type)
throws DataModelException {
// Get the list to be resolved.
List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList();
List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(type);
// Resolve linking for a resolution list.
linkInterFileReferences(resolutionList, this);
}
......@@ -366,6 +378,11 @@ public class YangSubModule extends YangNode
return listOfLeaf;
}
@Override
public void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
}
/**
* Adds a leaf.
*
......@@ -386,6 +403,11 @@ public class YangSubModule extends YangNode
return listOfLeafList;
}
@Override
public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
}
/**
* Adds a leaf-list.
*
......@@ -486,7 +508,8 @@ public class YangSubModule extends YangNode
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
public void validateDataOnEntry()
throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
......@@ -496,34 +519,52 @@ public class YangSubModule extends YangNode
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
public void validateDataOnExit()
throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
@Override
public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
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 {
public void detectSelfCollision(String identifierName, YangConstructType dataType)
throws DataModelException {
// Not required as module doesn't have any parent.
}
@Override
public List<YangResolutionInfo> getUnresolvedResolutionList() {
return unresolvedResolutionList;
public List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type) {
if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
return derivedTypeResolutionList;
} else {
return usesResolutionList;
}
}
@Override
public void addToResolutionList(YangResolutionInfo resolutionInfo) {
this.unresolvedResolutionList.add(resolutionInfo);
public void addToResolutionList(YangResolutionInfo resolutionInfo,
ResolvableType type) {
if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
derivedTypeResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_USES) {
usesResolutionList.add(resolutionInfo);
}
}
@Override
public void setResolutionList(List<YangResolutionInfo> resolutionList) {
this.unresolvedResolutionList = resolutionList;
public void setResolutionList(List<YangResolutionInfo> resolutionList,
ResolvableType type) {
if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
derivedTypeResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_USES) {
usesResolutionList = resolutionList;
}
}
/**
......
......@@ -17,9 +17,9 @@
package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.linker.Resolvable;
import org.onosproject.yangutils.linker.ResolvableStatus;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.linker.impl.Resolvable;
import org.onosproject.yangutils.linker.impl.ResolvableStatus;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
......@@ -247,7 +247,8 @@ public class YangType<T>
}
@Override
public void resolve() throws LinkerException {
public void resolve()
throws LinkerException {
/*
* Check whether the data type is derived.
*/
......
......@@ -18,15 +18,18 @@ package org.onosproject.yangutils.datamodel.utils;
import java.util.List;
import java.util.Set;
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.linker.impl.YangReferenceResolver;
import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
import org.onosproject.yangutils.datamodel.YangRpc;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.linker.ResolvableType;
import org.onosproject.yangutils.linker.YangReferenceResolver;
import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.plugin.manager.YangFileInfo;
import org.onosproject.yangutils.utils.YangConstructType;
......@@ -45,8 +48,7 @@ public final class 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 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
......@@ -77,8 +79,7 @@ public final class DataModelUtils {
/**
* Detects colliding of uses and grouping only with uses and grouping respectively.
*
* @param identifierName name for which collision detection is to be
* checked
* @param identifierName name for which collision detection is to be checked
* @param dataType type of YANG node asking for detecting collision
* @param node node instance of calling node
* @throws DataModelException a violation of data model rules
......@@ -101,8 +102,7 @@ public final class DataModelUtils {
* Detects the colliding identifier name in a given leaf node.
*
* @param listOfLeaf List of leaves to detect collision
* @param identifierName name for which collision detection is to be
* checked
* @param identifierName name for which collision detection is to be checked
* @throws DataModelException a violation of data model rules
*/
private static void detectCollidingLeaf(List<YangLeaf> listOfLeaf, String identifierName)
......@@ -123,8 +123,7 @@ public final class DataModelUtils {
* Detects the colliding identifier name in a given leaf-list node.
*
* @param listOfLeafList list of leaf-lists to detect collision
* @param identifierName name for which collision detection is to be
* checked
* @param identifierName name for which collision detection is to be checked
* @throws DataModelException a violation of data model rules
*/
private static void detectCollidingLeafList(List<YangLeafList> listOfLeafList, String identifierName)
......@@ -144,8 +143,7 @@ public final class DataModelUtils {
/**
* Add a resolution information.
*
* @param resolutionInfo information about the YANG construct which has to
* be resolved
* @param resolutionInfo information about the YANG construct which has to be resolved
* @throws DataModelException a violation of data model rules
*/
public static void addResolutionInfo(YangResolutionInfo resolutionInfo)
......@@ -162,7 +160,15 @@ public final class DataModelUtils {
}
YangReferenceResolver resolutionNode = (YangReferenceResolver) curNode;
resolutionNode.addToResolutionList(resolutionInfo);
if (resolutionInfo.getEntityToResolveInfo()
.getEntityToResolve() instanceof YangType) {
resolutionNode.addToResolutionList(resolutionInfo,
ResolvableType.YANG_DERIVED_DATA_TYPE);
} else {
resolutionNode.addToResolutionList(resolutionInfo,
ResolvableType.YANG_USES);
}
}
/**
......@@ -173,7 +179,7 @@ public final class DataModelUtils {
* @throws DataModelException a violation of data model rules
*/
public static void resolveLinkingForResolutionList(List<YangResolutionInfo> resolutionList,
YangReferenceResolver dataModelRootNode)
YangReferenceResolver dataModelRootNode)
throws DataModelException {
for (YangResolutionInfo resolutionInfo : resolutionList) {
......@@ -189,7 +195,7 @@ public final class DataModelUtils {
* @throws DataModelException a violation of data model rules
*/
public static void linkInterFileReferences(List<YangResolutionInfo> resolutionList,
YangReferenceResolver dataModelRootNode)
YangReferenceResolver dataModelRootNode)
throws DataModelException {
/*
* Run through the resolution list, find type/uses referring to
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.onosproject.yangutils.linker.impl;
package org.onosproject.yangutils.linker;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.onosproject.yangutils.linker.impl;
package org.onosproject.yangutils.linker;
/**
* Represents the status of resolvable entity.
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.linker;
/**
* Type of the resolvable info.
*/
public enum ResolvableType {
/**
* Identifies the derived data type.
*/
YANG_DERIVED_DATA_TYPE,
/**
* Identifies the uses.
*/
YANG_USES
}
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.linker;
/**
* Represents the phase of YANG file reference linking.
*/
public enum YangLinkingPhase {
/**
* Linking the reference within the files.
*/
INTRA_FILE,
/**
* Linking the reference across the files.
*/
INTER_FILE
}
......@@ -14,14 +14,16 @@
* limitations under the License.
*/
package org.onosproject.yangutils.linker.impl;
package org.onosproject.yangutils.linker;
import java.util.List;
import java.util.Set;
import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangInclude;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
import org.onosproject.yangutils.plugin.manager.YangFileInfo;
/**
......@@ -33,23 +35,26 @@ public interface YangReferenceResolver {
/**
* Returns unresolved resolution list.
*
* @return unresolved resolution list
* @param type resolvable type
* @return list of resolution information objects
*/
List<YangResolutionInfo> getUnresolvedResolutionList();
List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type);
/**
* Adds to the resolution list.
*
* @param resolutionInfo resolution information
* @param type resolvable type
*/
void addToResolutionList(YangResolutionInfo resolutionInfo);
void addToResolutionList(YangResolutionInfo resolutionInfo, ResolvableType type);
/**
* Creates resolution list.
*
* @param resolutionList resolution list
* @param type resolvable type
*/
void setResolutionList(List<YangResolutionInfo> resolutionList);
void setResolutionList(List<YangResolutionInfo> resolutionList, ResolvableType type);
/**
* Returns unresolved imported list.
......@@ -110,16 +115,20 @@ public interface YangReferenceResolver {
/**
* Resolves self file linking.
*
* @param type resolvable type
* @throws DataModelException a violation in data model rule
*/
void resolveSelfFileLinking() throws DataModelException;
void resolveSelfFileLinking(ResolvableType type)
throws DataModelException;
/**
* Resolves inter file linking.
*
* @param type resolvable type
* @throws DataModelException a violation in data model rule
*/
void resolveInterFileLinking() throws DataModelException;
void resolveInterFileLinking(ResolvableType type)
throws DataModelException;
/**
* Adds references to include.
......@@ -127,7 +136,8 @@ public interface YangReferenceResolver {
* @param yangFileInfoSet YANG file info set
* @throws LinkerException a violation of linker rules
*/
void addReferencesToIncludeList(Set<YangFileInfo> yangFileInfoSet) throws LinkerException;
void addReferencesToIncludeList(Set<YangFileInfo> yangFileInfoSet)
throws LinkerException;
/**
* Adds references to import.
......@@ -135,5 +145,6 @@ public interface YangReferenceResolver {
* @param yangFileInfoSet YANG file info set
* @throws LinkerException a violation of linker rules
*/
void addReferencesToImportList(Set<YangFileInfo> yangFileInfoSet) throws LinkerException;
void addReferencesToImportList(Set<YangFileInfo> yangFileInfoSet)
throws LinkerException;
}
......
......@@ -17,10 +17,13 @@
package org.onosproject.yangutils.linker.impl;
import java.util.Set;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.linker.ResolvableType;
import org.onosproject.yangutils.linker.YangLinker;
import org.onosproject.yangutils.linker.YangReferenceResolver;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.plugin.manager.YangFileInfo;
......@@ -29,7 +32,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
/**
* Representation of entity which provides linking service of YANG files.
*/
public class YangLinkerManager implements YangLinker {
public class YangLinkerManager
implements YangLinker {
@Override
public void resolveDependencies(Set<YangFileInfo> yangFileInfoSet) {
......@@ -54,7 +58,8 @@ public class YangLinkerManager implements YangLinker {
* @param yangFileInfoSet set of YANG files info
* @throws LinkerException fails to link sub-module to parent module
*/
public void linkSubModulesToParentModule(Set<YangFileInfo> yangFileInfoSet) throws LinkerException {
public void linkSubModulesToParentModule(Set<YangFileInfo> yangFileInfoSet)
throws LinkerException {
for (YangFileInfo yangFileInfo : yangFileInfoSet) {
YangNode yangNode = yangFileInfo.getRootNode();
if (yangNode instanceof YangSubModule) {
......@@ -106,10 +111,13 @@ public class YangLinkerManager implements YangLinker {
* @param yangFileInfoSet set of YANG files info
* @throws LinkerException a violation in linker execution
*/
public void processInterFileLinking(Set<YangFileInfo> yangFileInfoSet) throws LinkerException {
public void processInterFileLinking(Set<YangFileInfo> yangFileInfoSet)
throws LinkerException {
for (YangFileInfo yangFileInfo : yangFileInfoSet) {
try {
((YangReferenceResolver) yangFileInfo.getRootNode()).resolveInterFileLinking();
((YangReferenceResolver) yangFileInfo.getRootNode()).resolveInterFileLinking(ResolvableType.YANG_USES);
((YangReferenceResolver) yangFileInfo.getRootNode())
.resolveInterFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
} catch (DataModelException e) {
String errorInfo = "Error in file: " + yangFileInfo.getYangFileName() + " at line: "
+ e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE + e.getMessage();
......
......@@ -17,6 +17,7 @@
package org.onosproject.yangutils.linker.impl;
import java.util.Stack;
import org.onosproject.yangutils.datamodel.LocationInfo;
import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
......@@ -28,12 +29,18 @@ import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import static org.onosproject.yangutils.linker.impl.ResolvableStatus.INTER_FILE_LINKED;
import static org.onosproject.yangutils.linker.impl.ResolvableStatus.INTRA_FILE_RESOLVED;
import static org.onosproject.yangutils.linker.impl.ResolvableStatus.LINKED;
import static org.onosproject.yangutils.linker.impl.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.linker.impl.ResolvableStatus.UNRESOLVED;
import org.onosproject.yangutils.linker.Resolvable;
import org.onosproject.yangutils.linker.ResolvableStatus;
import org.onosproject.yangutils.linker.YangLinkingPhase;
import org.onosproject.yangutils.linker.YangReferenceResolver;
import static org.onosproject.yangutils.linker.ResolvableStatus.INTER_FILE_LINKED;
import static org.onosproject.yangutils.linker.ResolvableStatus.INTRA_FILE_RESOLVED;
import static org.onosproject.yangutils.linker.ResolvableStatus.LINKED;
import static org.onosproject.yangutils.linker.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.linker.ResolvableStatus.UNRESOLVED;
import static org.onosproject.yangutils.linker.YangLinkingPhase.INTER_FILE;
import static org.onosproject.yangutils.linker.YangLinkingPhase.INTRA_FILE;
import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.GROUPING_LINKER_ERROR;
......@@ -42,7 +49,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.GROUPING_LINKER_ERRO
*
* @param <T> type of resolution entity uses / type
*/
public class YangResolutionInfo<T> implements LocationInfo {
public class YangResolutionInfo<T>
implements LocationInfo {
/**
* Information about the entity that needs to be resolved.
......@@ -164,7 +172,7 @@ public class YangResolutionInfo<T> implements LocationInfo {
* resolve the references and pop the entity and
* continue with remaining stack elements to resolve.
*/
resolveTopOfStack();
resolveTopOfStack(INTRA_FILE);
getPartialResolvedStack().pop();
break;
}
......@@ -213,7 +221,7 @@ public class YangResolutionInfo<T> implements LocationInfo {
/**
* Resolves the current entity in the stack.
*/
private void resolveTopOfStack()
private void resolveTopOfStack(YangLinkingPhase linkingPhase)
throws DataModelException {
((Resolvable) getCurrentEntityToResolveFromStack()).resolve();
if (((Resolvable) getCurrentEntityToResolveFromStack()).getResolvableStatus()
......@@ -280,7 +288,8 @@ public class YangResolutionInfo<T> implements LocationInfo {
* @return true if self file reference, false otherwise
* @throws DataModelException a violation of data model rules
*/
private boolean isCandidateForSelfFileReference() throws DataModelException {
private boolean isCandidateForSelfFileReference()
throws DataModelException {
String prefix = getRefPrefix();
return prefix == null || prefix.contentEquals(getCurReferenceResolver().getPrefix());
}
......@@ -598,7 +607,8 @@ public class YangResolutionInfo<T> implements LocationInfo {
* @return referenced prefix of entity under resolution
* @throws DataModelException a violation in data model rule
*/
private String getRefPrefix() throws DataModelException {
private String getRefPrefix()
throws DataModelException {
String refPrefix;
if (getCurrentEntityToResolveFromStack() instanceof YangType) {
refPrefix = ((YangType<?>) getCurrentEntityToResolveFromStack()).getPrefix();
......@@ -643,7 +653,7 @@ public class YangResolutionInfo<T> implements LocationInfo {
* resolve the references and pop the entity and
* continue with remaining stack elements to resolve
*/
resolveTopOfStack();
resolveTopOfStack(INTER_FILE);
getPartialResolvedStack().pop();
break;
}
......@@ -679,7 +689,8 @@ public class YangResolutionInfo<T> implements LocationInfo {
*
* @throws DataModelException data model error
*/
private void linkInterFileTopOfStackRefUpdateStack() throws DataModelException {
private void linkInterFileTopOfStackRefUpdateStack()
throws DataModelException {
/*
* Obtain the referred node of top of stack entity under resolution
......@@ -727,7 +738,8 @@ public class YangResolutionInfo<T> implements LocationInfo {
* @return true if resolved, false otherwise
* @throws DataModelException a violation in data model rule
*/
private boolean resolveWithInclude() throws DataModelException {
private boolean resolveWithInclude()
throws DataModelException {
/*
* Run through all the nodes in include list and search for referred
* typedef/grouping at the root level.
......@@ -762,7 +774,8 @@ public class YangResolutionInfo<T> implements LocationInfo {
* @return true if resolved, false otherwise
* @throws DataModelException a violation in data model rule
*/
private boolean resolveWithImport() throws DataModelException {
private boolean resolveWithImport()
throws DataModelException {
/*
* Run through import list to find the referred typedef/grouping.
*/
......@@ -808,7 +821,8 @@ public class YangResolutionInfo<T> implements LocationInfo {
* @return referred typedef/grouping node
* @throws DataModelException a violation in data model rule
*/
private T getRefNode() throws DataModelException {
private T getRefNode()
throws DataModelException {
if (getCurrentEntityToResolveFromStack() instanceof YangType) {
YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>)
((YangType<?>) getCurrentEntityToResolveFromStack()).getDataTypeExtendedInfo();
......
......@@ -39,8 +39,10 @@ import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerU
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.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;
......@@ -98,7 +100,7 @@ public final class AugmentListener {
* @param ctx context object of the grammar rule
*/
public static void processAugmentEntry(TreeWalkListener listener,
GeneratedYangParser.AugmentStatementContext ctx) {
GeneratedYangParser.AugmentStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, AUGMENT_DATA, ctx.augment().getText(), ENTRY);
......@@ -120,7 +122,8 @@ public final class AugmentListener {
YangNode curNode = (YangNode) curData;
YangAugment yangAugment = getYangAugmentNode(JAVA_GENERATION);
validateTargetNodePath(targetNodes, curNode, ctx);
//validateTargetNodePath(targetNodes, curNode, ctx);
// TODO: handle in linker.
yangAugment.setTargetNode(targetNodes);
yangAugment.setName(generateNameForAugmentNode(curData, targetNodes, listener));
......@@ -147,7 +150,7 @@ public final class AugmentListener {
* @param ctx context object of the grammar rule
*/
public static void processAugmentExit(TreeWalkListener listener,
GeneratedYangParser.AugmentStatementContext ctx) {
GeneratedYangParser.AugmentStatementContext ctx) {
//Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, AUGMENT_DATA, ctx.augment().getText(), EXIT);
......@@ -170,15 +173,15 @@ public final class AugmentListener {
validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, AUGMENT_DATA, ctx.augment().getText());
validateCardinalityMaxOne(ctx.whenStatement(), WHEN_DATA, AUGMENT_DATA, ctx.augment().getText());
validateMutuallyExclusiveChilds(ctx.dataDefStatement(), DATA_DEF_DATA, ctx.caseStatement(),
CASE_DATA, AUGMENT_DATA, ctx.augment().getText());
CASE_DATA, AUGMENT_DATA, ctx.augment().getText());
}
/**
* Validates whether the current target node path is correct or not.
*
* @param targetNodes list of target nodes
* @param line line in YANG file
* @param charPositionInLine char position in YANG file
* @param curNode current Node
* @param ctx augment context
* @param curNode current YANG node
*/
private static void validateTargetNodePath(List<YangNodeIdentifier> targetNodes, YangNode curNode,
......@@ -189,7 +192,8 @@ public final class AugmentListener {
if (!moduleId.getName().equals(curNode.getName())) {
throw parserException(ctx);
} else {
validateNodeInTargetPath(curNode, targetNodes, ctx);
//validateNodeInTargetPath(curNode, targetNodes, ctx);
// TODO: handle in linker.
}
} else {
String parentPrefix = getParentsPrefix(curNode);
......
......@@ -113,11 +113,12 @@ public final class LeafListListener {
leafList.setLeafName(identifier);
Parsable tmpData = listener.getParsedDataStack().peek();
YangLeavesHolder leaves;
YangLeavesHolder leavesHolder;
if (tmpData instanceof YangLeavesHolder) {
leaves = (YangLeavesHolder) tmpData;
leaves.addLeafList(leafList);
leavesHolder = (YangLeavesHolder) tmpData;
leavesHolder.addLeafList(leafList);
leafList.setContainedIn(leavesHolder);
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAF_LIST_DATA,
ctx.identifier().getText(), ENTRY));
......
......@@ -115,11 +115,12 @@ public final class LeafListener {
leaf.setLeafName(identifier);
Parsable tmpData = listener.getParsedDataStack().peek();
YangLeavesHolder leaves;
YangLeavesHolder leavesHolder;
if (tmpData instanceof YangLeavesHolder) {
leaves = (YangLeavesHolder) tmpData;
leaves.addLeaf(leaf);
leavesHolder = (YangLeavesHolder) tmpData;
leavesHolder.addLeaf(leaf);
leaf.setContainedIn(leavesHolder);
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAF_DATA,
ctx.identifier().getText(), ENTRY));
......
......@@ -16,10 +16,11 @@
package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.linker.impl.YangReferenceResolver;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangRevision;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.linker.ResolvableType;
import org.onosproject.yangutils.linker.YangReferenceResolver;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
......@@ -28,7 +29,8 @@ import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_G
import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangModuleNode;
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
.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;
......@@ -116,7 +118,10 @@ public final class ModuleListener {
ctx.identifier().getText(), EXIT));
}
try {
((YangReferenceResolver) listener.getParsedDataStack().peek()).resolveSelfFileLinking();
((YangReferenceResolver) listener.getParsedDataStack()
.peek()).resolveSelfFileLinking(ResolvableType.YANG_USES);
((YangReferenceResolver) listener.getParsedDataStack()
.peek()).resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
} catch (DataModelException e) {
ParserException parserException = new ParserException(e.getMessage());
parserException.setLine(e.getLineNumber());
......
......@@ -151,7 +151,7 @@ public final class PatternRestrictionListener {
* @param ctx context object of the grammar rule
*/
public static void processPatternRestrictionExit(TreeWalkListener listener,
GeneratedYangParser.PatternStatementContext ctx) {
GeneratedYangParser.PatternStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, PATTERN_DATA, ctx.string().getText(), EXIT);
......
......@@ -16,10 +16,11 @@
package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.linker.impl.YangReferenceResolver;
import org.onosproject.yangutils.datamodel.YangRevision;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.linker.ResolvableType;
import org.onosproject.yangutils.linker.YangReferenceResolver;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
......@@ -28,7 +29,8 @@ import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_G
import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangSubModuleNode;
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
.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;
......@@ -121,7 +123,10 @@ public final class SubModuleListener {
ctx.identifier().getText(), EXIT));
}
try {
((YangReferenceResolver) listener.getParsedDataStack().peek()).resolveSelfFileLinking();
((YangReferenceResolver) listener.getParsedDataStack().peek())
.resolveSelfFileLinking(ResolvableType.YANG_USES);
((YangReferenceResolver) listener.getParsedDataStack().peek())
.resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
} catch (DataModelException e) {
ParserException parserException = new ParserException(e.getMessage());
parserException.setLine(e.getLineNumber());
......
......@@ -35,7 +35,7 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangType;
import static org.onosproject.yangutils.linker.impl.ResolvableStatus.UNRESOLVED;
import static org.onosproject.yangutils.linker.ResolvableStatus.UNRESOLVED;
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;
......
......@@ -247,7 +247,7 @@ public final class AugmentListenerUtil {
/**
* Validates whether nodes in target node list are valid or not.
*
* @param targetNodeName current target node
* @param targetNodes target node
* @param curNode YANG node
* @return true or false
*/
......
......@@ -17,7 +17,7 @@
package org.onosproject.yangutils.plugin.manager;
import java.util.Objects;
import org.onosproject.yangutils.linker.impl.ResolvableStatus;
import org.onosproject.yangutils.linker.ResolvableStatus;
import org.onosproject.yangutils.datamodel.YangNode;
/**
......
......@@ -62,7 +62,8 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getDirectory;
*/
@Mojo(name = "yang2java", defaultPhase = GENERATE_SOURCES, requiresDependencyResolution = COMPILE,
requiresProject = true)
public class YangUtilManager extends AbstractMojo {
public class YangUtilManager
extends AbstractMojo {
private YangNode rootNode;
// YANG file information set.
......@@ -134,7 +135,8 @@ public class YangUtilManager extends AbstractMojo {
private BuildContext context;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
public void execute()
throws MojoExecutionException, MojoFailureException {
try {
......@@ -204,7 +206,8 @@ public class YangUtilManager extends AbstractMojo {
*
* @throws MojoExecutionException a violation in mojo excecution
*/
public void resolveDependenciesUsingLinker() throws MojoExecutionException {
public void resolveDependenciesUsingLinker()
throws MojoExecutionException {
for (YangFileInfo yangFileInfo : getYangFileInfoSet()) {
setCurYangFileInfo(yangFileInfo);
try {
......@@ -220,7 +223,8 @@ public class YangUtilManager extends AbstractMojo {
*
* @throws IOException a violation in IO
*/
public void parseYangFileInfoSet() throws IOException {
public void parseYangFileInfoSet()
throws IOException {
for (YangFileInfo yangFileInfo : getYangFileInfoSet()) {
setCurYangFileInfo(yangFileInfo);
try {
......
......@@ -64,10 +64,10 @@ public final class JavaCodeGeneratorUtil {
/**
* Generates Java code files corresponding to the YANG schema.
*
* @param rootNode root node of the data model tree
* @param rootNode root node of the data model tree
* @param yangPlugin YANG plugin config
* @throws TranslatorException when fails to generate java code file the current
* node
* node
*/
public static void generateJavaCode(YangNode rootNode, YangPluginConfig yangPlugin)
throws TranslatorException {
......@@ -77,18 +77,35 @@ public final class JavaCodeGeneratorUtil {
while (codeGenNode != null) {
if (curTraversal != PARENT) {
if (!(codeGenNode instanceof JavaCodeGenerator)) {
throw new TranslatorException("Unsupported node to generate code");
}
setCurNode(codeGenNode);
generateCodeEntry(codeGenNode, yangPlugin);
try {
generateCodeEntry(codeGenNode, yangPlugin);
} catch (Exception e) {
throw new TranslatorException(e.getMessage());
}
}
if (curTraversal != PARENT && codeGenNode.getChild() != null) {
curTraversal = CHILD;
codeGenNode = codeGenNode.getChild();
} else if (codeGenNode.getNextSibling() != null) {
generateCodeExit(codeGenNode);
try {
generateCodeExit(codeGenNode);
} catch (Exception e) {
throw new TranslatorException(e.getMessage());
}
curTraversal = SIBILING;
codeGenNode = codeGenNode.getNextSibling();
} else {
generateCodeExit(codeGenNode);
try {
generateCodeExit(codeGenNode);
} catch (Exception e) {
throw new TranslatorException(e.getMessage());
}
curTraversal = PARENT;
codeGenNode = codeGenNode.getParent();
}
......@@ -99,10 +116,10 @@ public final class JavaCodeGeneratorUtil {
* Generates the current nodes code snippet.
*
* @param codeGenNode current data model node for which the code needs to be
* generated
* @param yangPlugin YANG plugin config
* generated
* @param yangPlugin YANG plugin config
* @throws TranslatorException when fails to generate java code file the current
* node
* node
*/
private static void generateCodeEntry(YangNode codeGenNode, YangPluginConfig yangPlugin)
throws TranslatorException {
......@@ -119,11 +136,12 @@ public final class JavaCodeGeneratorUtil {
* Generates the current nodes code target code from the snippet.
*
* @param codeGenNode current data model node for which the code needs to be
* generated
* generated
* @throws TranslatorException when fails to generate java code file the current
* node
* node
*/
private static void generateCodeExit(YangNode codeGenNode) throws TranslatorException {
private static void generateCodeExit(YangNode codeGenNode)
throws TranslatorException {
if (codeGenNode instanceof JavaCodeGenerator) {
((JavaCodeGenerator) codeGenNode).generateCodeExit();
......@@ -188,7 +206,7 @@ public final class JavaCodeGeneratorUtil {
* Delete Java code files corresponding to the YANG schema.
*
* @param rootNode root node of data-model tree
* @throws IOException when fails to delete java code file the current node
* @throws IOException when fails to delete java code file the current node
*/
public static void translatorErrorHandler(YangNode rootNode)
throws IOException {
......
......@@ -20,8 +20,6 @@ import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
import static java.util.Collections.sort;
import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT_EVENT;
import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER_CLASS_IMPORT_CLASS;
......@@ -45,6 +43,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static java.util.Collections.sort;
/**
* Represents that generated Java file can contain imports.
*/
......@@ -116,20 +116,52 @@ public class JavaImportData {
* a qualified manner.
*
* @param newImportInfo class/interface info being imported
* @return status of new addition of class/interface to the import set
* @param className name of the call being generated
* @param classPkg generated class package
* @return qualified access status of the import node being added
*/
public boolean addImportInfo(JavaQualifiedTypeInfo newImportInfo) {
public boolean addImportInfo(JavaQualifiedTypeInfo newImportInfo,
String className, String classPkg) {
if (newImportInfo.getClassInfo().contentEquals(className)) {
/*
* if the current class name is same as the attribute class name,
* then the attribute must be accessed in a qualified manner.
*/
return true;
} else if (newImportInfo.getPkgInfo() == null) {
/*
* If the package info is null, then it is not a candidate for import / qualified access
*/
return false;
}
/*
* If the attribute type is having the package info, it is contender
* for import list and also need to check if it needs to be a
* qualified access.
*/
if (newImportInfo.getPkgInfo().contentEquals(classPkg)) {
/**
* Package of the referred attribute and the generated class is same, so no need import
* or qualified access.
*/
return false;
}
for (JavaQualifiedTypeInfo curImportInfo : getImportSet()) {
if (curImportInfo.getClassInfo()
.contentEquals(newImportInfo.getClassInfo())) {
return curImportInfo.getPkgInfo()
return !curImportInfo.getPkgInfo()
.contentEquals(newImportInfo.getPkgInfo());
}
}
/*
* import is added, so it is a member for non qualified access
*/
getImportSet().add(newImportInfo);
return true;
return false;
}
/**
......
......@@ -134,10 +134,10 @@ public class JavaQualifiedTypeInfo
* Returns the import info for an attribute, which needs to be used for code
* generation for import or for qualified access.
*
* @param curNode current data model node for which the java file is being
* generated
* @param curNode current data model node for which the java file is being
* generated
* @param attributeName name of the attribute being added, it will used in
* import info for child class
* import info for child class
* @return return the import info for this attribute
*/
public static JavaQualifiedTypeInfo getQualifiedTypeInfoOfCurNode(YangNode curNode,
......@@ -149,14 +149,10 @@ public class JavaQualifiedTypeInfo
throw new TranslatorException("missing java file information to get the package details "
+ "of attribute corresponding to child node");
}
/*
* The scenario when we need to add the child class as an attribute in
* the current class. The child class is in the package of the current
* classes package with current classes name.
*/
importInfo.setClassInfo(attributeName);
importInfo.setPkgInfo((((JavaFileInfoContainer) curNode).getJavaFileInfo().getPackage() + "."
+ ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName()).toLowerCase());
importInfo.setPkgInfo(((JavaFileInfoContainer) curNode)
.getJavaFileInfo().getPackage());
return importInfo;
}
......@@ -165,7 +161,7 @@ public class JavaQualifiedTypeInfo
* Returns the java qualified type information for the wrapper classes.
*
* @param referredTypesAttrInfo attribute of referred type
* @param conflictResolver plugin configurations
* @param conflictResolver plugin configurations
* @return return the import info for this attribute
*/
public static JavaQualifiedTypeInfo getQualifiedInfoOfFromString(JavaAttributeInfo referredTypesAttrInfo,
......
......@@ -71,11 +71,11 @@ import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.VOID;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MANAGER_SETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
/**
......@@ -119,6 +119,7 @@ public class TempJavaServiceFragmentFiles
* File name for event subject setter temp file.
*/
private static final String EVENT_SUBJECT_SETTER_FILE_NAME = "EventSubjectSetter";
/**
* File name for generated class file for service
* suffix.
......@@ -370,14 +371,13 @@ public class TempJavaServiceFragmentFiles
* Constructs java code exit.
*
* @param fileType generated file type
* @param curNode current YANG node
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
@Override
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
List<String> imports = new ArrayList<>();
imports = getJavaImportData().getImports();
List<String> imports = getJavaImportData().getImports();
createPackage(curNode);
......@@ -433,15 +433,16 @@ public class TempJavaServiceFragmentFiles
/**
* Adds rpc string information to applicable temp file.
*
* @param javaAttributeInfoOfInput rpc's input node attribute info
* @param javaAttributeInfoOfInput rpc's input node attribute info
* @param javaAttributeInfoOfOutput rpc's output node attribute info
* @param rpcName name of the rpc function
* @param pluginConfig plugin configurations
* @param rpcName name of the rpc function
* @param pluginConfig plugin configurations
* @throws IOException IO operation fail
*/
private void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput,
JavaAttributeInfo javaAttributeInfoOfOutput, YangPluginConfig pluginConfig,
String rpcName) throws IOException {
String rpcName)
throws IOException {
String rpcInput = EMPTY_STRING;
String rpcOutput = VOID;
String rpcInputJavaDoc = EMPTY_STRING;
......@@ -464,20 +465,21 @@ public class TempJavaServiceFragmentFiles
/**
* Adds rpc string information to applicable temp file.
*
* @param javaAttributeInfoOfInput rpc's input node attribute info
* @param javaAttributeInfoOfInput rpc's input node attribute info
* @param javaAttributeInfoOfOutput rpc's output node attribute info
* @param rpcName name of the rpc function
* @param pluginConfig plugin configurations
* @param isInputLeafHolder if input node is leaf holder
* @param isOutputLeafHolder if output node is leaf holder
* @param isInputSingleChildHolder if input node is single child holder
* @param rpcName name of the rpc function
* @param pluginConfig plugin configurations
* @param isInputLeafHolder if input node is leaf holder
* @param isOutputLeafHolder if output node is leaf holder
* @param isInputSingleChildHolder if input node is single child holder
* @param isOutputSingleChildHolder if input node is single child holder
* @throws IOException IO operation fail
*/
public void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput,
JavaAttributeInfo javaAttributeInfoOfOutput, YangPluginConfig pluginConfig,
String rpcName, boolean isInputLeafHolder, boolean isOutputLeafHolder,
boolean isInputSingleChildHolder, boolean isOutputSingleChildHolder) throws IOException {
boolean isInputSingleChildHolder, boolean isOutputSingleChildHolder)
throws IOException {
String rpcInput = EMPTY_STRING;
String rpcOutput = VOID;
String rpcInputJavaDoc = EMPTY_STRING;
......@@ -504,10 +506,10 @@ public class TempJavaServiceFragmentFiles
/**
* Returns names for input and output.
*
* @param attr attribute info
* @param isLeafHolder if leaf holder
* @param attr attribute info
* @param isLeafHolder if leaf holder
* @param isSinglechildHolder if single child holder
* @param pluginConfig plugin configurations
* @param pluginConfig plugin configurations
* @return names for input and output
*/
private String getInputOutputNames(JavaAttributeInfo attr, boolean isLeafHolder, boolean isSinglechildHolder,
......@@ -550,13 +552,13 @@ public class TempJavaServiceFragmentFiles
/**
* Adds the JAVA rpc snippet information.
*
* @param javaAttributeInfoOfInput rpc's input node attribute info
* @param javaAttributeInfoOfInput rpc's input node attribute info
* @param javaAttributeInfoOfOutput rpc's output node attribute info
* @param pluginConfig plugin configurations
* @param rpcName name of the rpc function
* @param isInputLeafHolder if input node is leaf holder
* @param isOutputLeafHolder if output node is leaf holder
* @param isInputSingleChildHolder if input node is single child holder
* @param pluginConfig plugin configurations
* @param rpcName name of the rpc function
* @param isInputLeafHolder if input node is leaf holder
* @param isOutputLeafHolder if output node is leaf holder
* @param isInputSingleChildHolder if input node is single child holder
* @param isOutputSingleChildHolder if input node is single child holder
* @throws IOException IO operation fail
*/
......@@ -573,7 +575,7 @@ public class TempJavaServiceFragmentFiles
* Constructs java code exit.
*
* @param fileType generated file type
* @param curNode current YANG node
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateEventJavaFile(int fileType, YangNode curNode)
......@@ -604,7 +606,7 @@ public class TempJavaServiceFragmentFiles
* Constructs java code exit.
*
* @param fileType generated file type
* @param curNode current YANG node
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateEventListenerJavaFile(int fileType, YangNode curNode)
......@@ -632,7 +634,7 @@ public class TempJavaServiceFragmentFiles
* Constructs java code exit.
*
* @param fileType generated file type
* @param curNode current YANG node
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateEventSubjectJavaFile(int fileType, YangNode curNode)
......@@ -657,8 +659,8 @@ public class TempJavaServiceFragmentFiles
* Removes all temporary file handles.
*
* @param isErrorOccurred when translator fails to generate java files we
* need to close all open file handles include temporary files
* and java files.
* need to close all open file handles include temporary files
* and java files.
* @throws IOException when failed to delete the temporary files
*/
@Override
......@@ -782,17 +784,18 @@ public class TempJavaServiceFragmentFiles
/**
* Adds java snippet for events to event subject file.
*
* @param curNode current node
* @param curNode current node
* @param pluginConfig plugin configurations
* @throws IOException when fails to do IO operations
*/
public void addJavaSnippetOfEvent(YangNode curNode, YangPluginConfig pluginConfig) throws IOException {
public void addJavaSnippetOfEvent(YangNode curNode, YangPluginConfig pluginConfig)
throws IOException {
String currentInfo = getCapitalCase(getCamelCase(((YangNotification) curNode).getName(),
pluginConfig.getConflictResolver()));
String notificationName = ((YangNotification) curNode).getName();
JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode.getParent(),
JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
getCapitalCase(currentInfo));
JavaAttributeInfo javaAttributeInfo =
......@@ -807,14 +810,16 @@ public class TempJavaServiceFragmentFiles
}
/*Adds event to enum temp file.*/
private void addEventEnum(String notificationName, YangPluginConfig pluginConfig) throws IOException {
private void addEventEnum(String notificationName, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getEventEnumTempFileHandle(),
getJavaDoc(ENUM_ATTRIBUTE, notificationName, false, pluginConfig) + FOUR_SPACE_INDENTATION
+ getEnumJavaAttribute(notificationName).toUpperCase() + COMMA + NEW_LINE);
}
/*Adds event method in event class*/
private void addEnumMethod(String eventClassname, String className) throws IOException {
private void addEnumMethod(String eventClassname, String className)
throws IOException {
appendToFile(getEventMethodTempFileHandle(), getEventFileContents(eventClassname, className));
}
......@@ -853,7 +858,8 @@ public class TempJavaServiceFragmentFiles
}
/*Adds getter method for event in event subject class.*/
private void addEventSubjectGetter(JavaAttributeInfo attr, YangPluginConfig pluginConfig) throws IOException {
private void addEventSubjectGetter(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getEventSubjectGetterTempFileHandle(),
getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
+ getGetterForClass(attr, GENERATE_EVENT_SUBJECT_CLASS) + NEW_LINE);
......
......@@ -76,6 +76,7 @@ public class TempJavaTypeFragmentFiles
* Temporary file handle for of string method of class.
*/
private File ofStringImplTempFileHandle;
/**
* Temporary file handle for constructor for type class.
*/
......@@ -85,6 +86,7 @@ public class TempJavaTypeFragmentFiles
* Java file handle for typedef class file.
*/
private File typedefClassJavaFileHandle;
/**
* Java file handle for type class like union, typedef file.
*/
......@@ -211,7 +213,7 @@ public class TempJavaTypeFragmentFiles
YangJavaType<?> javaType = (YangJavaType<?>) yangType;
javaType.updateJavaQualifiedInfo(pluginConfig.getConflictResolver());
String typeName = javaType.getDataTypeName();
typeName = getCamelCase(typeName, pluginConfig.getConflictResolver());
typeName = getCamelCase(typeName, pluginConfig.getConflictResolver());
JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
javaType.getJavaQualifiedInfo(),
typeName, javaType,
......
......@@ -24,14 +24,14 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.updatePackageInfo;
/**
* Represents grouping information extended to support java code generation.
*/
public class YangJavaGrouping
extends YangGrouping implements JavaCodeGeneratorInfo, JavaCodeGenerator {
extends YangGrouping
implements JavaCodeGeneratorInfo, JavaCodeGenerator {
/**
* Contains the information of the java file being generated.
......@@ -50,7 +50,6 @@ public class YangJavaGrouping
public YangJavaGrouping() {
super();
setJavaFileInfo(new JavaFileInfo());
getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
}
/**
......@@ -96,35 +95,22 @@ public class YangJavaGrouping
tempFileHandle = fileHandle;
}
/**
* Prepare the information for java code generation corresponding to YANG
* grouping info.
*
* @param yangPlugin YANG plugin config
* @throws TranslatorException translator operation fail
*/
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws TranslatorException {
try {
generateCodeOfNode(this, yangPlugin);
updatePackageInfo(this, yangPlugin);
} catch (IOException e) {
throw new TranslatorException(
"Failed to prepare generate code entry for container node " + this.getName());
throw new TranslatorException(e.getCause());
}
}
/**
* Create a java file using the YANG grouping info.
*
* @throws TranslatorException translator operation fail
*/
@Override
public void generateCodeExit() throws TranslatorException {
try {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for container node " + this.getName());
}
public void generateCodeExit()
throws TranslatorException {
/*
* Do nothing.
*/
}
}
......
......@@ -16,7 +16,12 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangGrouping;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
......@@ -24,15 +29,16 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeAsAttributeInTargetTempFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.updatePackageInfo;
/**
* Represents uses information extended to support java code generation.
*/
public class YangJavaUses
extends YangUses implements JavaCodeGeneratorInfo, JavaCodeGenerator {
extends YangUses
implements JavaCodeGeneratorInfo, JavaCodeGenerator {
/**
* Contains the information of the java file being generated.
......@@ -51,7 +57,6 @@ public class YangJavaUses
public YangJavaUses() {
super();
setJavaFileInfo(new JavaFileInfo());
getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
}
/**
......@@ -97,31 +102,57 @@ public class YangJavaUses
tempFileHandle = fileHandle;
}
/**
* Prepare the information for java code generation corresponding to YANG
* uses info.
*
* @param yangPlugin YANG plugin config
* @throws TranslatorException translator operation fail
*/
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws TranslatorException {
try {
addCurNodeInfoInParentTempFile(this, false, yangPlugin);
updatePackageInfo(this, yangPlugin);
if (!(getParentNodeInGenCode(this) instanceof JavaCodeGeneratorInfo)) {
throw new TranslatorException("invalid container of uses");
}
JavaCodeGeneratorInfo javaCodeGeneratorInfo = (JavaCodeGeneratorInfo) getParentNodeInGenCode(this);
if (javaCodeGeneratorInfo instanceof YangGrouping) {
/*
* Do nothing, since it will taken care in the groupings uses.
*/
return;
}
for (List<YangLeaf> leavesList :
getUsesResolvedLeavesList()) {
//add the resolved leaves to the parent as an attribute
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.getBeanTempFiles().addLeavesInfoToTempFiles(leavesList, yangPlugin);
}
for (List<YangLeafList> listOfLeafLists :
getUsesResolvedListOfLeafList()) {
//add the resolved leaf-list to the parent as an attribute
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.getBeanTempFiles().addLeafListInfoToTempFiles(listOfLeafLists, yangPlugin);
}
for (YangNode usesResolvedNode :
getUsesResolvedNodeList()) {
//add the resolved nodes to the parent as an attribute
addCurNodeAsAttributeInTargetTempFile(usesResolvedNode, yangPlugin,
getParentNodeInGenCode(this));
}
} catch (IOException e) {
throw new TranslatorException(
"Failed to prepare generate code entry for container node " + this.getName());
throw new TranslatorException(e.getCause());
}
}
/**
* Create a java file using the YANG uses info.
*
* @throws TranslatorException translator operation fail
*/
@Override
public void generateCodeExit() throws TranslatorException {
// no code generation will be done for uses.
public void generateCodeExit()
throws TranslatorException {
/*
* Do nothing.
*/
}
}
......
......@@ -27,6 +27,7 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.getTempJavaFragement;
/**
......@@ -58,7 +59,7 @@ public class JavaExtendsListHolder {
/**
* Sets extends list.
*
* @param extendsList list of classes need to be extended
* @param extendedClass map of classes need to be extended
*/
private void setExtendedClassStore(Map<JavaQualifiedTypeInfo, Boolean> extendedClass) {
this.extendedClassStore = extendedClass;
......@@ -73,14 +74,13 @@ public class JavaExtendsListHolder {
public void addToExtendsList(JavaQualifiedTypeInfo info, YangNode node) {
JavaFileInfo fileInfo = ((JavaFileInfoContainer) node).getJavaFileInfo();
if (!fileInfo.getPackage().equals(info.getPkgInfo())) {
JavaImportData importData = getTempJavaFragement(node).getJavaImportData();
importData.addImportInfo(info);
JavaImportData importData = getTempJavaFragement(node).getJavaImportData();
boolean qualified = importData.addImportInfo(info,
getCapitalCase(fileInfo.getJavaName()), fileInfo.getPackage());
/*true means import should be added*/
getExtendedClassStore().put(info, true);
}
getExtendedClassStore().put(info, false);
getExtendedClassStore().put(info, qualified);
addToExtendsList(info);
}
......
......@@ -29,12 +29,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInput;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaOutput;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
import static java.util.Collections.sort;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
......@@ -69,6 +64,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.THIS;
import static org.onosproject.yangutils.utils.UtilConstants.TYPE;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle;
import static java.util.Collections.sort;
/**
* Represents utilities for temporary java code fragments.
*/
......@@ -83,8 +80,8 @@ public final class TempJavaCodeFragmentFilesUtils {
/**
* Adds import for AugmentationHolders class.
*
* @param curNode current YANG node
* @param imports list of imports
* @param curNode current YANG node
* @param imports list of imports
* @param operation add or delete import
*/
public static void addAugmentationHoldersImport(YangNode curNode, List<String> imports, boolean operation) {
......@@ -95,8 +92,8 @@ public final class TempJavaCodeFragmentFilesUtils {
/**
* Adds import for AugmentedInfo class.
*
* @param curNode current YANG node
* @param imports list of imports
* @param curNode current YANG node
* @param imports list of imports
* @param operation add or delete import
*/
public static void addAugmentedInfoImport(YangNode curNode, List<String> imports, boolean operation) {
......@@ -126,8 +123,8 @@ public final class TempJavaCodeFragmentFilesUtils {
/**
* Updated imports with augmented nodes import.
*
* @param curNode current YANG node
* @param imports list of imports
* @param curNode current YANG node
* @param imports list of imports
* @param operation to add or to delete
*/
public static void addAugmentedNodesImport(YangNode curNode, List<String> imports, boolean operation) {
......@@ -156,7 +153,7 @@ public final class TempJavaCodeFragmentFilesUtils {
/**
* Returns imports for augmented node.
*
* @param parent parent YANG node
* @param parent parent YANG node
* @param targetNodes list of target nodes
* @param isImplClass if impl class's import required
* @return imports for augmented node
......@@ -204,8 +201,8 @@ public final class TempJavaCodeFragmentFilesUtils {
/**
* Adds import for array list.
*
* @param curNode current YANG node
* @param imports list of imports
* @param curNode current YANG node
* @param imports list of imports
* @param operation add or delete import
*/
public static void addArrayListImport(YangNode curNode, List<String> imports, boolean operation) {
......@@ -224,8 +221,8 @@ public final class TempJavaCodeFragmentFilesUtils {
/**
* Adds listener's imports.
*
* @param curNode currentYangNode.
* @param imports import list
* @param curNode currentYangNode.
* @param imports import list
* @param operation add or remove
* @param classInfo class info to be added to import list
*/
......@@ -244,7 +241,7 @@ public final class TempJavaCodeFragmentFilesUtils {
/**
* Adds annotations imports.
*
* @param imports list if imports
* @param imports list if imports
* @param operation to add or to delete
*/
public static void addAnnotationsImports(List<String> imports, boolean operation) {
......@@ -269,7 +266,7 @@ public final class TempJavaCodeFragmentFilesUtils {
/**
* Performs given operations on import list.
*
* @param imports list of imports
* @param imports list of imports
* @param curImport current import
* @param operation add or remove
* @return import list
......@@ -314,7 +311,7 @@ public final class TempJavaCodeFragmentFilesUtils {
/**
* Closes the file handle for temporary file.
*
* @param file file to be closed
* @param file file to be closed
* @param toBeDeleted flag to indicate if file needs to be deleted
* @throws IOException when failed to close the file handle
*/
......@@ -330,33 +327,6 @@ public final class TempJavaCodeFragmentFilesUtils {
}
/**
* Detects collision between parent and child node which have same name.
* When parent and child node both have the same name in that case child node should be used with
* qualified name.
*
* @param curNode current YANG node
* @param qualifiedTypeInfo current node's qualified info
* @return true if collision is detected
*/
public static boolean detectCollisionBwParentAndChildForImport(YangNode curNode,
JavaQualifiedTypeInfo qualifiedTypeInfo) {
YangNode parent = curNode.getParent();
if (parent instanceof YangJavaModule
|| parent instanceof YangJavaSubModule
|| parent instanceof YangJavaInput
|| parent instanceof YangJavaOutput) {
return false;
}
String parentsClassInfo = getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName());
String childsClassInfo = qualifiedTypeInfo.getClassInfo();
if (childsClassInfo.equals(parentsClassInfo)) {
return true;
}
return false;
}
/**
* Returns sorted import list.
*
* @param imports import list
......
......@@ -19,8 +19,6 @@ package org.onosproject.yangutils.translator.tojava.utils;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentationHolder;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
......@@ -45,9 +43,6 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG;
/**
* Represents utility class for YANG java model.
......@@ -64,7 +59,7 @@ public final class YangJavaModelUtils {
* Updates YANG java file package information.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param yangPluginConfig YANG plugin config
* @param yangPluginConfig YANG plugin config
* @throws IOException IO operations fails
*/
public static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
......@@ -85,7 +80,7 @@ public final class YangJavaModelUtils {
* Updates YANG java file package information for specified package.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param yangPlugin YANG plugin config
* @param yangPlugin YANG plugin config
* @throws IOException IO operations fails
*/
private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin,
......@@ -128,7 +123,7 @@ public final class YangJavaModelUtils {
*/
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.getServiceTempFiles().addCurNodeLeavesInfoToTempFiles(
(YangNode) javaCodeGeneratorInfo, yangPluginConfig);
(YangNode) javaCodeGeneratorInfo, yangPluginConfig);
if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) {
if (!((YangJavaModule) javaCodeGeneratorInfo).getNotificationNodes().isEmpty()) {
updateNotificaitonNodeInfo(javaCodeGeneratorInfo, yangPluginConfig);
......@@ -151,7 +146,7 @@ public final class YangJavaModelUtils {
*/
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.getBeanTempFiles().addCurNodeLeavesInfoToTempFiles(
(YangNode) javaCodeGeneratorInfo, yangPluginConfig);
(YangNode) javaCodeGeneratorInfo, yangPluginConfig);
} else if (javaCodeGeneratorInfo instanceof YangTypeHolder) {
/*
* Typedef
......@@ -194,11 +189,12 @@ public final class YangJavaModelUtils {
* Updates notification node info in service temporary file.
*
* @param javaCodeGeneratorInfo java code generator info
* @param yangPluginConfig plugin configurations
* @param yangPluginConfig plugin configurations
* @throws IOException when fails to do IO operations
*/
private static void updateNotificaitonNodeInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
YangPluginConfig yangPluginConfig) throws IOException {
YangPluginConfig yangPluginConfig)
throws IOException {
if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) {
for (YangNode notificaiton : ((YangJavaModule) javaCodeGeneratorInfo).getNotificationNodes()) {
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
......@@ -220,8 +216,8 @@ public final class YangJavaModelUtils {
* Generates code for the current ata model node and adds itself as an attribute in the parent.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param yangPlugin YANG plugin config
* @param isMultiInstance flag to indicate whether it's a list
* @param yangPlugin YANG plugin config
* @param isMultiInstance flag to indicate whether it's a list
* @throws IOException IO operations fails
*/
public static void generateCodeAndUpdateInParent(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
......@@ -246,7 +242,7 @@ public final class YangJavaModelUtils {
* Generates code for the current data model node and adds support for it to be augmented.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param yangPlugin YANG plugin config
* @param yangPlugin YANG plugin config
* @throws IOException IO operations fails
*/
public static void generateCodeOfAugmentableNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
......@@ -259,8 +255,9 @@ public final class YangJavaModelUtils {
generateCodeOfNode(javaCodeGeneratorInfo, yangPlugin);
/*
TODO: Need to use this, when augmentation is added in YMS
* For augmentation of nodes.
*/
if (javaCodeGeneratorInfo instanceof YangAugmentationHolder) {
JavaQualifiedTypeInfo augmentationHoldersInfo = new JavaQualifiedTypeInfo();
augmentationHoldersInfo.setClassInfo(AUGMENTATION_HOLDER);
......@@ -276,7 +273,7 @@ public final class YangJavaModelUtils {
.addToExtendsList(augmentedInfo, (YangNode) javaCodeGeneratorInfo);
}
*/
if (javaCodeGeneratorInfo instanceof YangCase) {
YangNode parent = ((YangCase) javaCodeGeneratorInfo).getParent();
JavaQualifiedTypeInfo parentsInfo = new JavaQualifiedTypeInfo();
......@@ -297,7 +294,7 @@ public final class YangJavaModelUtils {
* Generates code for the current data model node.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param yangPluginConfig YANG plugin config
* @param yangPluginConfig YANG plugin config
* @throws IOException IO operations fails
*/
public static void generateCodeOfNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
......@@ -314,8 +311,8 @@ public final class YangJavaModelUtils {
* Generates code for the root module/sub-module node.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param yangPluginConfig YANG plugin config
* @param rootPkg package of the root node
* @param yangPluginConfig YANG plugin config
* @param rootPkg package of the root node
* @throws IOException IO operations fails
*/
public static void generateCodeOfRootNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
......
......@@ -966,6 +966,7 @@ public final class UtilConstants {
* Static attribute for augmentable.
*/
public static final String AUGMENTABLE = "Augmentable";
/**
* Static attribute for list.
*/
......@@ -1018,6 +1019,11 @@ public final class UtilConstants {
public static final String COMPONENT_ANNOTATION = "@Component";
/**
* Static attribute for component.
*/
public static final String COMPONENT = "Component";
/**
* Static attribute for immediate.
*/
public static final String IMMEDIATE = "immediate";
......@@ -1134,6 +1140,16 @@ public final class UtilConstants {
+ "grouping for given uses";
/**
* Static attribute for reference.
*/
public static final String REFERENCE = "Reference";
/**
* Static attribute for ReferenceCardinality.
*/
public static final String REFERENCE_CARDINALITY = "ReferenceCardinality";
/**
* Creates an instance of util constants.
*/
private UtilConstants() {
......
......@@ -56,8 +56,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTA
import static org.onosproject.yangutils.utils.UtilConstants.YANG_RESOURCES;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.appendFileContents;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.PACKAGE_INFO;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.slf4j.LoggerFactory.getLogger;
/**
......@@ -67,7 +67,7 @@ public final class YangIoUtils {
private static final Logger log = getLogger(YangIoUtils.class);
private static final String TARGET_RESOURCE_PATH = SLASH + TEMP + SLASH + YANG_RESOURCES + SLASH;
private static final int LINE_SIZE = 116;
private static final int LINE_SIZE = 118;
private static final int SUB_LINE_SIZE = 112;
private static final int ZERO = 0;
......@@ -92,10 +92,10 @@ public final class YangIoUtils {
/**
* Adds package info file for the created directory.
*
* @param path directory path
* @param classInfo class info for the package
* @param pack package of the directory
* @param isChildNode is it a child node
* @param path directory path
* @param classInfo class info for the package
* @param pack package of the directory
* @param isChildNode is it a child node
* @param pluginConfig plugin configurations
* @throws IOException when fails to create package info file
*/
......@@ -159,7 +159,8 @@ public final class YangIoUtils {
* @param dir generated directory in previous build
* @throws IOException when failed to delete directory
*/
public static void deleteDirectory(String dir) throws IOException {
public static void deleteDirectory(String dir)
throws IOException {
File generatedDirectory = new File(dir);
if (generatedDirectory.exists()) {
try {
......@@ -177,7 +178,8 @@ public final class YangIoUtils {
* @param root root directory
* @throws IOException when fails to do IO operations.
*/
public static void searchAndDeleteTempDir(String root) throws IOException {
public static void searchAndDeleteTempDir(String root)
throws IOException {
List<File> store = new LinkedList<>();
Stack<String> stack = new Stack<>();
stack.push(root);
......@@ -207,7 +209,7 @@ public final class YangIoUtils {
/**
* Adds generated source directory to the compilation root.
*
* @param source directory
* @param source directory
* @param project current maven project
* @param context current build context
*/
......@@ -220,7 +222,7 @@ public final class YangIoUtils {
/**
* Removes extra char from the string.
*
* @param valueString string to be trimmed
* @param valueString string to be trimmed
* @param removealStirng extra chars
* @return new string
*/
......@@ -255,8 +257,8 @@ public final class YangIoUtils {
* Returns the directory path of the package in canonical form.
*
* @param baseCodeGenPath base path where the generated files needs to be
* put
* @param pathOfJavaPkg java package of the file being generated
* put
* @param pathOfJavaPkg java package of the file being generated
* @return absolute path of the package in canonical form
*/
public static String getDirectory(String baseCodeGenPath, String pathOfJavaPkg) {
......@@ -276,8 +278,8 @@ public final class YangIoUtils {
* Returns the absolute path of the package in canonical form.
*
* @param baseCodeGenPath base path where the generated files needs to be
* put
* @param pathOfJavaPkg java package of the file being generated
* put
* @param pathOfJavaPkg java package of the file being generated
* @return absolute path of the package in canonical form
*/
public static String getAbsolutePackagePath(String baseCodeGenPath, String pathOfJavaPkg) {
......@@ -288,8 +290,8 @@ public final class YangIoUtils {
* Copies YANG files to the current project's output directory.
*
* @param yangFileInfo list of YANG files
* @param outputDir project's output directory
* @param project maven project
* @param outputDir project's output directory
* @param project maven project
* @throws IOException when fails to copy files to destination resource directory
*/
public static void copyYangFilesToTarget(Set<YangFileInfo> yangFileInfo, String outputDir, MavenProject project)
......@@ -334,7 +336,8 @@ public final class YangIoUtils {
* @param srcFile main file
* @throws IOException when fails to append contents
*/
public static void mergeJavaFiles(File appendFile, File srcFile) throws IOException {
public static void mergeJavaFiles(File appendFile, File srcFile)
throws IOException {
try {
appendFileContents(appendFile, srcFile);
} catch (IOException e) {
......@@ -349,7 +352,8 @@ public final class YangIoUtils {
* @param data data which need to be inserted
* @throws IOException when fails to insert into file
*/
public static void insertDataIntoJavaFile(File file, String data) throws IOException {
public static void insertDataIntoJavaFile(File file, String data)
throws IOException {
try {
updateFileHandle(file, data, false);
} catch (IOException e) {
......@@ -365,7 +369,8 @@ public final class YangIoUtils {
* @return updated file
* @throws IOException when fails to do IO operations.
*/
public static File validateLineLength(File dataFile) throws IOException {
public static File validateLineLength(File dataFile)
throws IOException {
File tempFile = dataFile;
FileReader fileReader = new FileReader(dataFile);
BufferedReader bufferReader = new BufferedReader(fileReader);
......
......@@ -19,6 +19,7 @@ package org.onosproject.yangutils.linker;
import java.io.IOException;
import java.util.Iterator;
import java.util.ListIterator;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangDataTypes;
......@@ -30,12 +31,12 @@ import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.linker.impl.ResolvableStatus;
import org.onosproject.yangutils.linker.impl.YangLinkerManager;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.plugin.manager.YangFileInfo;
import org.onosproject.yangutils.plugin.manager.YangUtilManager;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import static org.hamcrest.CoreMatchers.nullValue;
......@@ -44,7 +45,8 @@ import static org.hamcrest.core.Is.is;
import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
import static org.onosproject.yangutils.linker.impl.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.linker.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
/**
* Test cases for testing inter file linking.
......@@ -186,13 +188,13 @@ public class InterFileLinkingTest {
assertThat(uses.getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
leafIterator = yangNode.getListOfLeaf().listIterator();
leafInfo = leafIterator.next();
// Check whether the information in the leaf is correct under module.
assertThat(leafInfo.getName(), is("hello"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
// leafIterator = yangNode.getListOfLeaf().listIterator();
// leafInfo = leafIterator.next();
//
// // Check whether the information in the leaf is correct under module.
// assertThat(leafInfo.getName(), is("hello"));
// assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
// assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
}
/**
......@@ -332,13 +334,13 @@ public class InterFileLinkingTest {
assertThat(uses.getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
leafIterator = yangNode.getListOfLeaf().listIterator();
leafInfo = leafIterator.next();
// Check whether the information in the leaf is correct under module.
assertThat(leafInfo.getName(), is("hello"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
// leafIterator = yangNode.getListOfLeaf().listIterator();
// leafInfo = leafIterator.next();
//
// // Check whether the information in the leaf is correct under module.
// assertThat(leafInfo.getName(), is("hello"));
// assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
// assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
}
/**
......@@ -599,4 +601,117 @@ public class InterFileLinkingTest {
assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
}
/**
* Checks hierarchical intra with inter file type linking.
*/
@Test
public void interFileWithUsesReferringType()
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfilewithusesreferringtype";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
String userDir = System.getProperty("user.dir");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/interfilewithusesreferringtype/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
deleteDirectory(userDir + "/target/interfilewithusesreferringtype/");
}
/**
* Checks hierarchical intra with inter file type linking.
*/
@Test
public void file1UsesFile2TypeDefFile3Type()
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/file1UsesFile2TypeDefFile3Type";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
String userDir = System.getProperty("user.dir");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/file1UsesFile2TypeDefFile3Type/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
deleteDirectory(userDir + "/target/file1UsesFile2TypeDefFile3Type/");
}
/**
* Checks hierarchical intra with inter file type linking.
*/
@Test
public void interFileIetf()
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfileietf";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
String userDir = System.getProperty("user.dir");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/interfileietf/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
deleteDirectory(userDir + "/target/interfileietf/");
}
/**
* Checks hierarchical intra with inter file type linking.
*/
@Test
public void usesInContainer()
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/usesInContainer";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
String userDir = System.getProperty("user.dir");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/usesInContainer/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
deleteDirectory(userDir + "/target/usesInContainer/");
}
/**
* Checks hierarchical intra with inter file type linking.
*/
@Test
public void groupingNodeSameAsModule()
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/groupingNodeSameAsModule";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
String userDir = System.getProperty("user.dir");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/groupingNodeSameAsModule/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
deleteDirectory(userDir + "/target/groupingNodeSameAsModule/");
}
}
......
......@@ -33,12 +33,12 @@ import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.onosproject.yangutils.datamodel.YangDataTypes.BINARY;
import static org.onosproject.yangutils.linker.ResolvableStatus.INTRA_FILE_RESOLVED;
import static org.onosproject.yangutils.linker.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32;
import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
import static org.onosproject.yangutils.linker.impl.ResolvableStatus.INTRA_FILE_RESOLVED;
import static org.onosproject.yangutils.linker.impl.ResolvableStatus.RESOLVED;
/**
* Test cases for testing "type" intra file linking.
......
......@@ -40,11 +40,11 @@ import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.onosproject.yangutils.linker.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32;
import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
import static org.onosproject.yangutils.linker.impl.ResolvableStatus.RESOLVED;
/**
* Test cases for testing restriction resolution.
......
......@@ -32,6 +32,7 @@ public class TreeWalkListenerTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
/**
* Checks whether exception is thrown for ordered statement.
*/
......
......@@ -18,6 +18,7 @@ package org.onosproject.yangutils.parser.impl.listeners;
import java.io.IOException;
import java.util.ListIterator;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangLeaf;
......
module ietf-inet-types {
yang-version 1;
namespace
"urn:ietf:params:xml:ns:yang:ietf-inet-types";
prefix inet;
typedef uri {
type string;
}
}
module ietf-network-topology {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network-topology";
prefix lnk;
import ietf-inet-types {
prefix inet;
}
typedef tp-id {
type inet:uri;
description
"An identifier for termination points on a node.
The identifier SHOULD be chosen such that the same TP in a
real network topology will always be identified through the
same identifier, even if the model is instantiated in
separate datastores. An implementation MAY choose to capture
semantics in the identifier, for example to indicate the type
of TP and/or the type of node and topology that the TP is a
part of.";
}
grouping tp-ref {
description
"References a termination point in a specific node.";
leaf tp-ref {
type tp-id;
description
"A type for an absolute reference to a termination point.
(This type should not be used for relative references.
In such a case, a relative path should be used instead.)";
}
}
}
module ietf-te-topology {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-te-topology";
// replace with IANA namespace when assigned
prefix "tet";
import ietf-network-topology {
prefix "nt";
}
container underlay-trail-src {
uses nt:tp-ref;
description
"Source TE link of the underlay trail.";
}
}
module port-pair {
yang-version 1;
namespace "sfc.portpair";
prefix "port-pair";
grouping port-pair {
container port-pair {
leaf name {
type string;
}
leaf description {
type string;
}
}
}
rpc get-port-pair {
output {
uses port-pair;
}
}
}
module ietf-network-topology {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network-topology";
prefix lnk;
import ietf-inet-types {
prefix inet;
}
import ietf-network {
prefix nd;
}
organization
"IETF I2RS (Interface to the Routing System) Working Group";
contact
"WG Web: <http://tools.ietf.org/wg/i2rs/>
WG List: <mailto:i2rs@ietf.org>
WG Chair: Susan Hares
<mailto:shares@ndzh.com>
WG Chair: Jeffrey Haas
<mailto:jhaas@pfrc.org>
Editor: Alexander Clemm
<mailto:alex@cisco.com>
Editor: Jan Medved
<mailto:jmedved@cisco.com>
Editor: Robert Varga
<mailto:rovarga@cisco.com>
Editor: Tony Tkacik
<mailto:ttkacik@cisco.com>
Editor: Nitin Bahadur
<mailto:nitin_bahadur@yahoo.com>
Editor: Hariharan Ananthakrishnan
<mailto:hari@packetdesign.com>";
description
"This module defines a common base model for network topology,
augmenting the base network model with links to connect nodes,
as well as termination points to terminate links on nodes.
Copyright (c) 2015 IETF Trust and the persons identified as
authors of the code. All rights reserved.
Redistribution and use in source and binary forms, with or
without modification, is permitted pursuant to, and subject
to the license terms contained in, the Simplified BSD License
set forth in Section 4.c of the IETF Trust's Legal Provisions
Relating to IETF Documents
(http://trustee.ietf.org/license-info).
This version of this YANG module is part of
draft-ietf-i2rs-yang-network-topo-02;
see the RFC itself for full legal notices.
NOTE TO RFC EDITOR: Please replace above reference to
draft-ietf-i2rs-yang-network-topo-02 with RFC
number when published (i.e. RFC xxxx).";
revision 2015-12-08 {
description
"Initial revision.
NOTE TO RFC EDITOR: Please replace the following reference
to draft-ietf-i2rs-yang-network-topo-02 with
RFC number when published (i.e. RFC xxxx).";
reference
"draft-ietf-i2rs-yang-network-topo-02.";
}
typedef link-id {
type inet:uri;
description
"An identifier for a link in a topology.
The identifier SHOULD be chosen such that the same link in a
real network topology will always be identified through the
same identifier, even if the model is instantiated in
separate datastores. An implementation MAY choose to capture
semantics in the identifier, for example to indicate the type
of link and/or the type of topology that the link is a part
of.";
}
typedef tp-id {
type inet:uri;
description
"An identifier for termination points on a node.
The identifier SHOULD be chosen such that the same TP in a
real network topology will always be identified through the
same identifier, even if the model is instantiated in
separate datastores. An implementation MAY choose to capture
semantics in the identifier, for example to indicate the type
of TP and/or the type of node and topology that the TP is a
part of.";
}
grouping link-ref {
description
"References a link in a specific network.";
leaf link-ref {
type link-id;
description
"A type for an absolute reference a link instance.
(This type should not be used for relative references.
In such a case, a relative path should be used instead.)";
}
uses nd:network-ref;
}
grouping tp-ref {
description
"References a termination point in a specific node.";
leaf tp-ref {
type tp-id;
description
"A type for an absolute reference to a termination point.
(This type should not be used for relative references.
In such a case, a relative path should be used instead.)";
}
uses nd:node-ref;
}
augment "/nd:networks/nd:network" {
description
"Add links to the network model.";
list link {
key "link-id";
description
"A Network Link connects a by Local (Source) node and
a Remote (Destination) Network Nodes via a set of the
nodes' termination points.
As it is possible to have several links between the same
source and destination nodes, and as a link could
potentially be re-homed between termination points, to
ensure that we would always know to distinguish between
links, every link is identified by a dedicated link
identifier.
Note that a link models a point-to-point link, not a
multipoint link.
Layering dependencies on links in underlay topologies are
not represented as the layering information of nodes and of
termination points is sufficient.";
container source {
description
"This container holds the logical source of a particular
link.";
leaf source-node {
type nd:node-id;
mandatory true;
description
"Source node identifier, must be in same topology.";
}
leaf source-tp {
type tp-id;
description
"Termination point within source node that terminates
the link.";
}
}
container destination {
description
"This container holds the logical destination of a
particular link.";
leaf dest-node {
type nd:node-id;
mandatory true;
description
"Destination node identifier, must be in the same
network.";
}
leaf dest-tp {
type tp-id;
description
"Termination point within destination node that
terminates the link.";
}
}
leaf link-id {
type link-id;
description
"The identifier of a link in the topology.
A link is specific to a topology to which it belongs.";
}
list supporting-link {
key "network-ref link-ref";
description
"Identifies the link, or links, that this link
is dependent on.";
leaf network-ref {
type nd:network-id;
description
"This leaf identifies in which underlay topology
supporting link is present.";
}
leaf link-ref {
type link-id;
description
"This leaf identifies a link which is a part
of this link's underlay. Reference loops, in which
a link identifies itself as its underlay, either
directly or transitively, are not allowed.";
}
}
}
}
augment "/nd:networks/nd:network/nd:node" {
description
"Augment termination points which terminate links.
Termination points can ultimately be mapped to interfaces.";
list termination-point {
key "tp-id";
description
"A termination point can terminate a link.
Depending on the type of topology, a termination point
could, for example, refer to a port or an interface.";
leaf tp-id {
type tp-id;
description
"Termination point identifier.";
}
list supporting-termination-point {
key "network-ref node-ref tp-ref";
description
"The leaf list identifies any termination points that
the termination point is dependent on, or maps onto.
Those termination points will themselves be contained
in a supporting node.
This dependency information can be inferred from
the dependencies between links. For this reason,
this item is not separately configurable. Hence no
corresponding constraint needs to be articulated.
The corresponding information is simply provided by the
implementing system.";
leaf network-ref {
type nd:network-id;
description
"This leaf identifies in which topology the
supporting termination point is present.";
}
leaf node-ref {
type nd:node-id;
description
"This leaf identifies in which node the supporting
termination point is present.";
}
leaf tp-ref {
type tp-id;
description
"Reference to the underlay node, must be in a
different topology";
}
}
}
}
}
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
import ietf-inet-types {
prefix inet;
}
organization
"IETF I2RS (Interface to the Routing System) Working Group";
contact
"WG Web: <http://tools.ietf.org/wg/i2rs/>
WG List: <mailto:i2rs@ietf.org>
WG Chair: Susan Hares
<mailto:shares@ndzh.com>
WG Chair: Jeffrey Haas
<mailto:jhaas@pfrc.org>
Editor: Alexander Clemm
<mailto:alex@cisco.com>
Editor: Jan Medved
<mailto:jmedved@cisco.com>
Editor: Robert Varga
<mailto:rovarga@cisco.com>
Editor: Tony Tkacik
<mailto:ttkacik@cisco.com>
Editor: Nitin Bahadur
<mailto:nitin_bahadur@yahoo.com>
Editor: Hariharan Ananthakrishnan
<mailto:hari@packetdesign.com>";
description
"This module defines a common base model for a collection
of nodes in a network. Node definitions are further used
in network topologies and inventories.
Copyright (c) 2015 IETF Trust and the persons identified as
authors of the code. All rights reserved.
Redistribution and use in source and binary forms, with or
without modification, is permitted pursuant to, and subject
to the license terms contained in, the Simplified BSD License
set forth in Section 4.c of the IETF Trust's Legal Provisions
Relating to IETF Documents
(http://trustee.ietf.org/license-info).
This version of this YANG module is part of
draft-ietf-i2rs-yang-network-topo-02;
see the RFC itself for full legal notices.
NOTE TO RFC EDITOR: Please replace above reference to
draft-ietf-i2rs-yang-network-topo-02 with RFC
number when published (i.e. RFC xxxx).";
revision 2015-12-08 {
description
"Initial revision.
NOTE TO RFC EDITOR: Please replace the following reference
to draft-ietf-i2rs-yang-network-topo-02 with
RFC number when published (i.e. RFC xxxx).";
reference
"draft-ietf-i2rs-yang-network-topo-02";
}
typedef node-id {
type inet:uri;
description
"Identifier for a node.";
}
typedef network-id {
type inet:uri;
description
"Identifier for a network.";
}
grouping network-ref {
description
"Contains the information necessary to reference a network,
for example an underlay network.";
leaf network-ref {
type network-id;
description
"Used to reference a network, for example an underlay
network.";
}
}
grouping node-ref {
description
"Contains the information necessary to reference a node.";
leaf node-ref {
type node-id;
description
"Used to reference a node.
Nodes are identified relative to the network they are
contained in.";
}
uses network-ref;
}
container networks {
description
"Serves as top-level container for a list of networks.";
list network {
key "network-id";
description
"Describes a network.
A network typically contains an inventory of nodes,
topological information (augmented through
network-topology model), as well as layering
information.";
container network-types {
description
"Serves as an augmentation target.
The network type is indicated through corresponding
presence containers augmented into this container.";
}
leaf network-id {
type network-id;
description
"Identifies a network.";
}
list supporting-network {
key "network-ref";
description
"An underlay network, used to represent layered network
topologies.";
leaf network-ref {
type network-id;
description
"References the underlay network.";
}
}
list node {
key "node-id";
description
"The inventory of nodes of this network.";
leaf node-id {
type node-id;
description
"Identifies a node uniquely within the containing
network.";
}
list supporting-node {
key "network-ref node-ref";
description
"Represents another node, in an underlay network, that
this node is supported by. Used to represent layering
structure.";
leaf network-ref {
type network-id;
description
"References the underlay network that the
underlay node is part of.";
}
leaf node-ref {
type node-id;
description
"References the underlay node itself.";
}
}
}
}
}
container networks-state {
config false;
description
"Serves as top-level container for a list of state information
for networks";
list network {
key "network-ref";
description
"Data nodes representing operational data and state of
networks.
An instance is automatically created for every network
in the corresponding list under the networks container.";
uses network-ref;
leaf server-provided {
type boolean;
description
"Indicates whether the information concerning this
particular network is populated by the server
(server-provided true, the general case for network
information discovered from the server),
or whether it is configured by a client
(server-provided true, possible e.g. for
service overlays managed through a controller).";
}
}
}
}
module ietf-schedule {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-schedule";
// replace with IANA namespace when assigned
prefix "sch";
import ietf-yang-types {
prefix "yang";
}
organization "TBD";
contact "TBD";
description
"The model allows time scheduling parameters to be specified.";
revision "2016-03-01" {
description "Initial revision";
reference "TBD";
}
/*
* Groupings
*/
grouping schedules {
description
"A list of schedules defining when a particular
configuration takes effect.";
container schedules {
description
"Container of a schedule list defining when a particular
configuration takes effect.";
list schedule {
key "schedule-id";
description "A list of schedule elements.";
leaf schedule-id {
type uint32;
description "Identifies the schedule element.";
}
leaf start {
type yang:date-and-time;
description "Start time.";
}
leaf schedule-duration {
type string {
pattern
'P(\d+Y)?(\d+M)?(\d+W)?(\d+D)?T(\d+H)?(\d+M)?(\d+S)?';
}
description "Schedule duration in ISO 8601 format.";
}
leaf repeat-interval {
type string {
pattern
'R\d*/P(\d+Y)?(\d+M)?(\d+W)?(\d+D)?T(\d+H)?(\d+M)?'
+ '(\d+S)?';
}
description "Repeat interval in ISO 8601 format.";
}
}
}
} // schedules
}
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
container networks {
container network-types {
description
"Serves as an augmentation target.
The network type is indicated through corresponding
presence containers augmented into this container.";
}
}
}
module ietf-te-topology {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-te-topology";
// replace with IANA namespace when assigned
prefix "tet";
import ietf-network {
prefix "nw";
}
grouping te-topologies-augment {
description
"Augmentation for TE topologies.";
leaf reference-change-policy {
type enumeration {
enum no-action {
description
"When an attribute changes in this template, the
configuration node referring to this template does
not take any action.";
}
enum not-allowed {
description
"When any configuration object has a reference to this
template, changing this template is not allowed.";
}
enum cascade {
description
"When an attribute changes in this template, the
configuration object referring to this template applies
the new attribute value to the corresponding
configuration.";
}
}
description
"This attribute specifies the action taken to a configuration
node that has a reference to this template.";
}
} // te-topologies-augment
augment "/nw:networks" {
description
"Augmentation parameters for TE topologies.";
uses te-topologies-augment;
}
}
module ietf-sd-onos-service-types {
namespace "urn:ietf:params:xml:ns:yang:ietf-sd-onos-service-types";
prefix service-types ;
grouping qos-if-car {
description "qos parameter." ;
list qos-if-car {
key "direction";
description "cars qos policy." ;
leaf direction {
type enumeration {
enum inbound{
value 0 ;
description "inbound." ;
}
enum outbound {
value 1 ;
description "outbound." ;
}
}
description "qos for interface car" ;
}
}
}
container qos-policy {
description "The qos policy of the vpn service." ;
container qos-if-cars {
description "qos policy if car." ;
list qos-if-car {
key "direction";
uses qos-if-car;
description "List of qos parameters." ;
}
}
}
rpc close-l3vpn {
description "Close l3vpn." ;
input {
leaf l3vpn-id {
type string;
description "vpn id." ;
}
container ac-status {
description "Access status of the vpn." ;
list acs{
key "id";
description "Access information." ;
leaf id {
type string;
description "Access id." ;
}
leaf admin-status {
type string;
description "Administration status." ;
}
}
}
}
}
}