Vidyashree Rama
Committed by Gerrit Code Review

[ONOS-4650][ONOS-4726][ONOS-4727] [ONOS-4728]Implement must parser + when parser…

… + feature + if-feature + revision defect fix

Change-Id: I0a3aee6c1c6b72ef7da7f7f565fd0f149fe3fd42
Showing 79 changed files with 2975 additions and 208 deletions
......@@ -29,5 +29,10 @@ public enum ResolvableType {
/**
* Identifies the uses.
*/
YANG_USES
YANG_USES,
/**
* Identifies the if-feature.
*/
YANG_IF_FEATURE
}
......
......@@ -65,14 +65,14 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
* | choice | 7.9 | 0..n |-child nodes |
* | container | 7.5 | 0..n |-child nodes |
* | description | 7.19.3 | 0..1 |-string |
* | if-feature | 7.18.2 | 0..n |-TODO |
* | if-feature | 7.18.2 | 0..n |-YangIfFeature |
* | leaf | 7.6 | 0..n |-YangLeaf |
* | leaf-list | 7.7 | 0..n |-YangLeafList |
* | list | 7.8 | 0..n |-child nodes |
* | reference | 7.19.4 | 0..1 |-String |
* | status | 7.19.2 | 0..1 |-YangStatus |
* | uses | 7.12 | 0..n |-child nodes |
* | when | 7.19.5 | 0..1 |-TODO |
* | when | 7.19.5 | 0..1 |-YangWhen |
* +--------------+---------+-------------+------------------+
*/
......@@ -81,7 +81,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
*/
public class YangAugment
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangWhenHolder, YangIfFeatureHolder {
private static final long serialVersionUID = 806201602L;
......@@ -121,6 +121,16 @@ public class YangAugment
private YangStatusType status;
/**
* When data of the node.
*/
private YangWhen when;
/**
* List of if-feature.
*/
private List<YangIfFeature> ifFeatureList;
/**
* Create a YANG augment node.
*/
public YangAugment() {
......@@ -146,6 +156,26 @@ public class YangAugment
}
/**
* Returns the when.
*
* @return the when
*/
@Override
public YangWhen getWhen() {
return when;
}
/**
* Sets the when.
*
* @param when the when to set
*/
@Override
public void setWhen(YangWhen when) {
this.when = when;
}
/**
* Returns the description.
*
* @return the description
......@@ -341,4 +371,21 @@ public class YangAugment
this.name = name;
}
@Override
public List<YangIfFeature> getIfFeatureList() {
return ifFeatureList;
}
@Override
public void addIfFeatureList(YangIfFeature ifFeature) {
if (getIfFeatureList() == null) {
setIfFeatureList(new LinkedList<>());
}
getIfFeatureList().add(ifFeature);
}
@Override
public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
this.ifFeatureList = ifFeatureList;
}
}
......
......@@ -78,14 +78,14 @@ import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CASE_D
* | choice | 7.9 | 0..n |-child nodes |
* | container | 7.5 | 0..n |-child nodes |
* | description | 7.19.3 | 0..1 |-string |
* | if-feature | 7.18.2 | 0..n |-TODO |
* | if-feature | 7.18.2 | 0..n |-YangIfFeature |
* | leaf | 7.6 | 0..n |-YangLeaf |
* | leaf-list | 7.7 | 0..n |-YangLeafList |
* | list | 7.8 | 0..n |-child nodes |
* | reference | 7.19.4 | 0..1 |-string |
* | status | 7.19.2 | 0..1 |-YangStatus |
* | uses | 7.12 | 0..n |-child node |
* | when | 7.19.5 | 0..1 |-TODO |
* | when | 7.19.5 | 0..1 |-YangWhen |
* +--------------+---------+-------------+------------------+
*/
......@@ -94,7 +94,8 @@ import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CASE_D
*/
public class YangCase
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder,
YangWhenHolder, YangIfFeatureHolder {
private static final long serialVersionUID = 806201603L;
......@@ -131,6 +132,16 @@ public class YangCase
private YangStatusType status;
/**
* When data of the node.
*/
private YangWhen when;
/**
* List of if-feature.
*/
private List<YangIfFeature> ifFeatureList;
/**
* Creates a choice node.
*/
public YangCase() {
......@@ -138,6 +149,26 @@ public class YangCase
}
/**
* Returns the when.
*
* @return the when
*/
@Override
public YangWhen getWhen() {
return when;
}
/**
* Sets the when.
*
* @param when the when to set
*/
@Override
public void setWhen(YangWhen when) {
this.when = when;
}
/**
* Returns the case name.
*
* @return case name
......@@ -343,4 +374,22 @@ public class YangCase
// Asks helper to detect colliding child.
detectCollidingChildUtil(identifierName, dataType, this);
}
@Override
public List<YangIfFeature> getIfFeatureList() {
return ifFeatureList;
}
@Override
public void addIfFeatureList(YangIfFeature ifFeature) {
if (getIfFeatureList() == null) {
setIfFeatureList(new LinkedList<>());
}
getIfFeatureList().add(ifFeature);
}
@Override
public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
this.ifFeatureList = ifFeatureList;
}
}
......
......@@ -15,6 +15,8 @@
*/
package org.onosproject.yangutils.datamodel;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
......@@ -46,21 +48,23 @@ import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CHOICE
* | container | 7.5 | 0..n |-child case nodes |
* | default | 7.9.3 | 0..1 |-string |
* | description | 7.19.3 | 0..1 |-string |
* | if-feature | 7.18.2 | 0..n |-TODO |
* | if-feature | 7.18.2 | 0..n |-YangIfFeature |
* | leaf | 7.6 | 0..n |-child case nodes |
* | leaf-list | 7.7 | 0..n |-child case nodes |
* | list | 7.8 | 0..n |-child case nodes |
* | mandatory | 7.9.4 | 0..1 |-string |
* | reference | 7.19.4 | 0..1 |-string |
* | status | 7.19.2 | 0..1 |-string |
* | when | 7.19.5 | 0..1 |-TODO |
* | when | 7.19.5 | 0..1 |-YangWhen |
* +--------------+---------+-------------+------------------+
*/
/**
* Represents data model node to maintain information defined in YANG choice.
*/
public class YangChoice extends YangNode
implements YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
implements YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder, YangWhenHolder,
YangIfFeatureHolder {
private static final long serialVersionUID = 806201604L;
......@@ -143,6 +147,16 @@ public class YangChoice extends YangNode
private String defaultValueInString;
/**
* When data of the node.
*/
private YangWhen when;
/**
* List of if-feature.
*/
private List<YangIfFeature> ifFeatureList;
/**
* Create a choice node.
*/
public YangChoice() {
......@@ -150,6 +164,26 @@ public class YangChoice extends YangNode
}
/**
* Returns the when.
*
* @return the when
*/
@Override
public YangWhen getWhen() {
return when;
}
/**
* Sets the when.
*
* @param when the when to set
*/
@Override
public void setWhen(YangWhen when) {
this.when = when;
}
/**
* Returns the choice name.
*
* @return choice name
......@@ -365,4 +399,23 @@ public class YangChoice extends YangNode
node = node.getNextSibling();
}
}
@Override
public List<YangIfFeature> getIfFeatureList() {
return ifFeatureList;
}
@Override
public void addIfFeatureList(YangIfFeature ifFeature) {
if (getIfFeatureList() == null) {
setIfFeatureList(new LinkedList<>());
}
getIfFeatureList().add(ifFeature);
}
@Override
public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
this.ifFeatureList = ifFeatureList;
}
}
......
......@@ -70,17 +70,17 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
* | container | 7.5 | 0..n | -child nodes |
* | description | 7.19.3 | 0..1 | -string |
* | grouping | 7.11 | 0..n | -child nodes |
* | if-feature | 7.18.2 | 0..n | -TODO |
* | if-feature | 7.18.2 | 0..n | -YangIfFeature |
* | leaf | 7.6 | 0..n | -YangLeaf |
* | leaf-list | 7.7 | 0..n | -YangLeafList |
* | list | 7.8 | 0..n | -child nodes |
* | must | 7.5.3 | 0..n | -TODO |
* | must | 7.5.3 | 0..n | -YangMust |
* | presence | 7.5.5 | 0..1 | -boolean |
* | reference | 7.19.4 | 0..1 | -string |
* | status | 7.19.2 | 0..1 | -YangStatus |
* | typedef | 7.3 | 0..n | -child nodes |
* | uses | 7.12 | 0..n | -child nodes |
* | when | 7.19.5 | 0..1 | -TODO |
* | when | 7.19.5 | 0..1 | -YangWhen |
* +--------------+---------+-------------+------------------+
*/
......@@ -89,7 +89,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
*/
public class YangContainer
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder,
YangMustHolder, YangWhenHolder, YangIfFeatureHolder {
private static final long serialVersionUID = 806201605L;
......@@ -135,6 +136,21 @@ public class YangContainer
private YangStatusType status = YangStatusType.CURRENT;
/**
* List of must statement constraints.
*/
private List<YangMust> mustConstraintList;
/**
* When data of the node.
*/
private YangWhen when;
/**
* List of if-feature.
*/
private List<YangIfFeature> ifFeatureList;
/**
* Create a container node.
*/
public YangContainer() {
......@@ -142,6 +158,26 @@ public class YangContainer
}
/**
* Returns the when.
*
* @return the when
*/
@Override
public YangWhen getWhen() {
return when;
}
/**
* Sets the when.
*
* @param when the when to set
*/
@Override
public void setWhen(YangWhen when) {
this.when = when;
}
/**
* Returns the YANG name of container.
*
* @return the name of container as defined in YANG file
......@@ -445,4 +481,41 @@ public class YangContainer
+ getName() + "\"");
}
}
@Override
public List<YangIfFeature> getIfFeatureList() {
return ifFeatureList;
}
@Override
public void addIfFeatureList(YangIfFeature ifFeature) {
if (getIfFeatureList() == null) {
setIfFeatureList(new LinkedList<>());
}
getIfFeatureList().add(ifFeature);
}
@Override
public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
this.ifFeatureList = ifFeatureList;
}
@Override
public List<YangMust> getListOfMust() {
return mustConstraintList;
}
@Override
public void setListOfMust(List<YangMust> mustConstraintList) {
this.mustConstraintList = mustConstraintList;
}
@Override
public void addMust(YangMust must) {
if (getListOfMust() == null) {
setListOfMust(new LinkedList<>());
}
getListOfMust().add(must);
}
}
......
/*
* 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.datamodel;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
/*
* Reference RFC 6020.
*
* The "feature" statement is used to define a mechanism by which
* portions of the schema are marked as conditional. A feature name is
* defined that can later be referenced using the "if-feature" statement.
* Schema nodes tagged with a feature are ignored by the device unless
* the device supports the given feature. This allows portions of the
* YANG module to be conditional based on conditions on the device.
* The model can represent the abilities of the device within the model,
* giving a richer model that allows for differing device abilities and roles.
*
* The argument to the "feature" statement is the name of the new
* feature, and follows the rules for identifiers. This name is used by the
* "if-feature" statement to tie the schema nodes to the feature.
*
* The feature's Substatements
*
* +--------------+---------+-------------+------------------+
* | substatement | section | cardinality |data model mapping|
* +--------------+---------+-------------+------------------+
* | description | 7.19.3 | 0..1 | -string |
* | if-feature | 7.18.2 | 0..n | -YangIfFeature |
* | reference | 7.19.4 | 0..1 | -string |
* | status | 7.19.2 | 0..1 | -YangStatus |
* +--------------+---------+-------------+------------------+
*/
/**
* Represents data model node to maintain information defined in YANG feature.
*/
public class YangFeature implements YangCommonInfo, Parsable, YangIfFeatureHolder, Serializable {
private static final long serialVersionUID = 806201635L;
/**
* Name of the feature.
*/
private String name;
/**
* Description of feature.
*/
private String description;
/**
* Reference of the feature.
*/
private String reference;
/**
* Status of feature.
*/
private YangStatusType statusType;
/**
* List of if-feature.
*/
private List<YangIfFeature> ifFeatureList;
@Override
public String getDescription() {
return description;
}
@Override
public void setDescription(String description) {
this.description = description;
}
@Override
public String getReference() {
return reference;
}
@Override
public void setReference(String reference) {
this.reference = reference;
}
@Override
public YangStatusType getStatus() {
return statusType;
}
@Override
public void setStatus(YangStatusType status) {
this.statusType = status;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.FEATURE_DATA;
}
@Override
public void validateDataOnEntry() throws DataModelException {
//TODO : To be implemented
}
@Override
public void validateDataOnExit() throws DataModelException {
//TODO : To be implemented
}
@Override
public List<YangIfFeature> getIfFeatureList() {
return ifFeatureList;
}
@Override
public void addIfFeatureList(YangIfFeature ifFeature) {
if (getIfFeatureList() == null) {
setIfFeatureList(new LinkedList<>());
}
getIfFeatureList().add(ifFeature);
}
@Override
public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
this.ifFeatureList = ifFeatureList;
}
}
/*Copyright 2016.year Open Networking Laboratory
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/
package org.onosproject.yangutils.datamodel;
import java.util.List;
/**
* Abstraction of feature entity. It is used to abstract the data holders of feature.
*/
public interface YangFeatureHolder {
/**
* Returns the list of feature from data holder like container / list.
*
* @return the list of feature
*/
List<YangFeature> getFeatureList();
/**
* Adds feature in feature list.
*
* @param feature the feature to be added
*/
void addFeatureList(YangFeature feature);
/**
* Sets the list of feature.
*
* @param listOfFeature the list of feature to set
*/
void setListOfFeature(List<YangFeature> listOfFeature);
}
/*
* 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.datamodel;
import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
/*
* Reference RFC 6020.
*
* The "if-feature" statement makes its parent statement conditional.
* The argument is the name of a feature, as defined by a "feature"
* statement. The parent statement is implemented by servers that
* support this feature. If a prefix is present on the feature name, it
* refers to a feature defined in the module that was imported with that
* prefix, or the local module if the prefix matches the local module's
* prefix. Otherwise, a feature with the matching name MUST be defined
* in the current module or an included submodule.
*
* Since submodules cannot include the parent module, any features in
* the module that need to be exposed to submodules MUST be defined in a
* submodule. Submodules can then include this submodule to find the
* definition of the feature.
*/
/**
* Represents data model node to maintain information defined in YANG if-feature.
*/
public class YangIfFeature implements Parsable, Resolvable, Serializable {
private static final long serialVersionUID = 806201635L;
/**
* if-feature argument.
*/
YangNodeIdentifier name;
/**
* Referred feature information.
*/
YangFeature referredFeature;
/**
* Referred feature parent information.
*/
YangNode referredFeatureHolder;
/**
* Status of resolution. If completely resolved enum value is "RESOLVED",
* if not enum value is "UNRESOLVED", in case reference of grouping/typedef
* is added to uses/type but it's not resolved value of enum should be
* "INTRA_FILE_RESOLVED".
*/
private ResolvableStatus resolvableStatus;
/**
* Returns referred feature holder.
*
* @return referred feature holder
*/
public YangNode getReferredFeatureHolder() {
return referredFeatureHolder;
}
/**
* Sets the referred feature holder.
*
* @param referredFeatureHolder referred feature holder
*/
public void setReferredFeatureHolder(YangNode referredFeatureHolder) {
this.referredFeatureHolder = referredFeatureHolder;
}
/**
* Returns prefix associated with identifier.
*
* @return prefix associated with identifier
*/
public String getPrefix() {
return name.getPrefix();
}
/**
* Sets prefix associated with identifier.
*
* @param prefix prefix associated with identifier
*/
public void setPrefix(String prefix) {
name.setPrefix(prefix);
}
/**
* Returns referred feature associated with if-feature.
*
* @return referred feature associated with if-feature
*/
public YangFeature getReferredFeature() {
return referredFeature;
}
/**
* Sets referred feature associated with if-feature.
*
* @param referredFeature referred feature associated with if-feature
*/
public void setReferredFeature(YangFeature referredFeature) {
this.referredFeature = referredFeature;
}
/**
* Returns the YANG name of if-feature.
*
* @return the name of if-feature as defined in YANG file
*/
public YangNodeIdentifier getName() {
return name;
}
/**
* Sets the YANG name of if-feature.
*
* @param name the name of if-feature as defined in YANG file
*/
public void setName(YangNodeIdentifier name) {
this.name = name;
}
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.IF_FEATURE_DATA;
}
@Override
public void validateDataOnEntry() throws DataModelException {
// do nothing, no validation required for if-feature
}
@Override
public void validateDataOnExit() throws DataModelException {
// do nothing, no validation required for if-feature
}
@Override
public ResolvableStatus getResolvableStatus() {
return resolvableStatus;
}
@Override
public void setResolvableStatus(ResolvableStatus resolvableStatus) {
this.resolvableStatus = resolvableStatus;
}
@Override
public void resolve() throws DataModelException {
YangFeature feature = getReferredFeature();
// check whether feature has if-feature
List<YangIfFeature> ifFeatureList = feature.getIfFeatureList();
if (ifFeatureList != null && !ifFeatureList.isEmpty()) {
Iterator<YangIfFeature> ifFeatureIterator = ifFeatureList.iterator();
while (ifFeatureIterator.hasNext()) {
YangIfFeature ifFeature = ifFeatureIterator.next();
if (ifFeature.getResolvableStatus() != ResolvableStatus.RESOLVED) {
setResolvableStatus(ResolvableStatus.INTRA_FILE_RESOLVED);
return;
}
}
}
}
}
/*Copyright 2016.year Open Networking Laboratory
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/
package org.onosproject.yangutils.datamodel;
import java.util.List;
/**
* Abstraction of if-feature entity. It is used to abstract the data holders of if-feature.
*/
public interface YangIfFeatureHolder {
/**
* Returns the list of if-feature from data holder like container / list.
*
* @return the list of if-feature
*/
List<YangIfFeature> getIfFeatureList();
/**
* Adds if-feature in if-feature list.
*
* @param ifFeature the if-feature to be added
*/
void addIfFeatureList(YangIfFeature ifFeature);
/**
* Sets the list of if-feature.
*
* @param ifFeatureList the list of if-feature to set
*/
void setIfFeatureList(List<YangIfFeature> ifFeatureList);
}
......@@ -16,6 +16,7 @@
package org.onosproject.yangutils.datamodel;
import java.io.Serializable;
import java.util.Date;
import java.util.Set;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
......@@ -61,7 +62,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.findRefer
* | substatement | section | cardinality |data model mapping|
* +---------------+---------+-------------+------------------+
* | prefix | 7.1.4 | 1 | string |
* | revision-date | 7.1.5.1 | 0..1 | string |
* | revision-date | 7.1.5.1 | 0..1 | Date |
* +---------------+---------+-------------+------------------+
*/
......@@ -91,7 +92,7 @@ public class YangImport
* the most recent "revision" statement in the imported module. organization
* which defined the YANG module.
*/
private String revision;
private Date revision;
/**
* Reference to node which is imported.
......@@ -152,7 +153,7 @@ public class YangImport
*
* @return the revision of the imported module
*/
public String getRevision() {
public Date getRevision() {
return revision;
}
......@@ -161,7 +162,7 @@ public class YangImport
*
* @param rev set the revision of the imported module
*/
public void setRevision(String rev) {
public void setRevision(Date rev) {
revision = rev;
}
......@@ -245,7 +246,7 @@ public class YangImport
*/
public void addReferenceToImport(Set<YangNode> yangNodeSet) throws DataModelException {
String importedModuleName = getModuleName();
String importedModuleRevision = getRevision();
Date importedModuleRevision = getRevision();
YangNode moduleNode = null;
/*
* Find the imported module node for a given module name with a
......@@ -266,7 +267,7 @@ public class YangImport
if (moduleNode != null) {
if (moduleNode instanceof YangModule) {
if (getRevision() == null || getRevision().isEmpty()) {
if (getRevision() == null) {
setImportedNode(moduleNode);
return;
}
......
......@@ -16,6 +16,7 @@
package org.onosproject.yangutils.datamodel;
import java.io.Serializable;
import java.util.Date;
import java.util.Set;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
......@@ -56,7 +57,7 @@ public class YangInclude
* The include's "revision-date" statement is used to specify the exact
* version of the submodule to import.
*/
private String revision;
private Date revision;
/**
* Reference to node which is included.
......@@ -98,7 +99,7 @@ public class YangInclude
*
* @return the revision
*/
public String getRevision() {
public Date getRevision() {
return revision;
}
......@@ -107,7 +108,7 @@ public class YangInclude
*
* @param revision the revision to set
*/
public void setRevision(String revision) {
public void setRevision(Date revision) {
this.revision = revision;
}
......@@ -182,7 +183,7 @@ public class YangInclude
*/
public YangSubModule addReferenceToInclude(Set<YangNode> yangNodeSet) throws DataModelException {
String includedSubModuleName = getSubModuleName();
String includedSubModuleRevision = getRevision();
Date includedSubModuleRevision = getRevision();
YangNode subModuleNode = null;
/*
......@@ -204,7 +205,7 @@ public class YangInclude
if (subModuleNode != null) {
if (subModuleNode instanceof YangSubModule) {
if (getRevision() == null || getRevision().isEmpty()) {
if (getRevision() == null) {
setIncludedNode(subModuleNode);
return (YangSubModule) subModuleNode;
}
......
......@@ -17,7 +17,8 @@
package org.onosproject.yangutils.datamodel;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
......@@ -43,16 +44,16 @@ import org.onosproject.yangutils.datamodel.utils.YangConstructType;
* | substatement | section | cardinality |data model mapping|
* +--------------+---------+-------------+------------------+
* | config | 7.19.1 | 0..1 | - boolean |
* | default | 7.6.4 | 0..1 | - TODO |
* | default | 7.6.4 | 0..1 | - string |
* | description | 7.19.3 | 0..1 | - string |
* | if-feature | 7.18.2 | 0..n | - TODO |
* | if-feature | 7.18.2 | 0..n | - YangIfFeature |
* | mandatory | 7.6.5 | 0..1 | - boolean |
* | must | 7.5.3 | 0..n | - TODO |
* | must | 7.5.3 | 0..n | - YangMust |
* | reference | 7.19.4 | 0..1 | - string |
* | status | 7.19.2 | 0..1 | - YangStatus |
* | type | 7.6.3 | 1 | - YangType |
* | units | 7.3.3 | 0..1 | - String |
* | when | 7.19.5 | 0..1 | - TODO |
* | when | 7.19.5 | 0..1 | - YangWhen |
* +--------------+---------+-------------+------------------+
*/
......@@ -60,7 +61,8 @@ import org.onosproject.yangutils.datamodel.utils.YangConstructType;
* Represents leaf data represented in YANG.
*/
public class YangLeaf
implements YangCommonInfo, Parsable, Cloneable, Serializable {
implements YangCommonInfo, Parsable, Cloneable, Serializable,
YangMustHolder, YangIfFeatureHolder, YangWhenHolder {
private static final long serialVersionUID = 806201635L;
......@@ -111,11 +113,26 @@ public class YangLeaf
private String defaultValueInString;
/**
* When data of the leaf.
*/
private YangWhen when;
/**
* YANG Node in which the leaf is contained.
*/
private transient YangLeavesHolder containedIn;
/**
* List of must statement constraints.
*/
private List<YangMust> mustConstraintList;
/**
* List of if-feature.
*/
private List<YangIfFeature> ifFeatureList;
/**
* Creates a YANG leaf.
*/
public YangLeaf() {
......@@ -158,6 +175,26 @@ public class YangLeaf
}
/**
* Returns the when.
*
* @return the when
*/
@Override
public YangWhen getWhen() {
return when;
}
/**
* Sets the when.
*
* @param when the when to set
*/
@Override
public void setWhen(YangWhen when) {
this.when = when;
}
/**
* Returns the description.
*
* @return the description
......@@ -346,4 +383,40 @@ public class YangLeaf
// TODO auto-generated method stub, to be implemented by parser
}
@Override
public List<YangMust> getListOfMust() {
return mustConstraintList;
}
@Override
public void setListOfMust(List<YangMust> mustConstraintList) {
this.mustConstraintList = mustConstraintList;
}
@Override
public void addMust(YangMust must) {
if (getListOfMust() == null) {
setListOfMust(new LinkedList<>());
}
getListOfMust().add(must);
}
@Override
public List<YangIfFeature> getIfFeatureList() {
return ifFeatureList;
}
@Override
public void addIfFeatureList(YangIfFeature ifFeature) {
if (getIfFeatureList() == null) {
setIfFeatureList(new LinkedList<>());
}
getIfFeatureList().add(ifFeature);
}
@Override
public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
this.ifFeatureList = ifFeatureList;
}
}
......
......@@ -17,7 +17,8 @@
package org.onosproject.yangutils.datamodel;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
......@@ -39,16 +40,16 @@ import org.onosproject.yangutils.datamodel.utils.YangConstructType;
* +--------------+---------+-------------+------------------+
* | config | 7.19.1 | 0..1 | -boolean |
* | description | 7.19.3 | 0..1 | -string |
* | if-feature | 7.18.2 | 0..n | -TODO |
* | if-feature | 7.18.2 | 0..n | -YangIfFeature |
* | max-elements | 7.7.4 | 0..1 | -int |
* | min-elements | 7.7.3 | 0..1 | -int |
* | must | 7.5.3 | 0..n | -TODO |
* | must | 7.5.3 | 0..n | -YangMust |
* | ordered-by | 7.7.5 | 0..1 | -TODO |
* | reference | 7.19.4 | 0..1 | -string |
* | status | 7.19.2 | 0..1 | -YangStatus |
* | type | 7.4 | 1 | -YangType |
* | units | 7.3.3 | 0..1 | -string |
* | when | 7.19.5 | 0..1 | -TODO |
* | when | 7.19.5 | 0..1 | -YangWhen |
* +--------------+---------+-------------+------------------+
*/
......@@ -56,7 +57,8 @@ import org.onosproject.yangutils.datamodel.utils.YangConstructType;
* Represents leaf-list data represented in YANG.
*/
public class YangLeafList
implements YangCommonInfo, Parsable, Cloneable, Serializable {
implements YangCommonInfo, Parsable, Cloneable, Serializable,
YangMustHolder, YangWhenHolder, YangIfFeatureHolder {
private static final long serialVersionUID = 806201637L;
......@@ -133,6 +135,21 @@ public class YangLeafList
private transient YangLeavesHolder containedIn;
/**
* List of must statement constraints.
*/
private List<YangMust> mustConstraintList;
/**
* When data of the leaf.
*/
private YangWhen when;
/**
* List of if-feature.
*/
private List<YangIfFeature> ifFeatureList;
/**
* Creates a YANG leaf-list.
*/
public YangLeafList() {
......@@ -175,6 +192,26 @@ public class YangLeafList
}
/**
* Returns the when.
*
* @return the when
*/
@Override
public YangWhen getWhen() {
return when;
}
/**
* Sets the when.
*
* @param when the when to set
*/
@Override
public void setWhen(YangWhen when) {
this.when = when;
}
/**
* Returns the description.
*
* @return the description
......@@ -363,4 +400,40 @@ public class YangLeafList
// TODO auto-generated method stub, to be implemented by parser
}
@Override
public List<YangIfFeature> getIfFeatureList() {
return ifFeatureList;
}
@Override
public void addIfFeatureList(YangIfFeature ifFeature) {
if (getIfFeatureList() == null) {
setIfFeatureList(new LinkedList<>());
}
getIfFeatureList().add(ifFeature);
}
@Override
public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
this.ifFeatureList = ifFeatureList;
}
@Override
public List<YangMust> getListOfMust() {
return mustConstraintList;
}
@Override
public void setListOfMust(List<YangMust> mustConstraintList) {
this.mustConstraintList = mustConstraintList;
}
@Override
public void addMust(YangMust must) {
if (getListOfMust() == null) {
setListOfMust(new LinkedList<>());
}
getListOfMust().add(must);
}
}
......
......@@ -46,21 +46,21 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
* | container | 7.5 | 0..n |-child nodes |
* | description | 7.19.3 | 0..1 |-string |
* | grouping | 7.11 | 0..n |-child nodes |
* | if-feature | 7.18.2 | 0..n |-TODO |
* | if-feature | 7.18.2 | 0..n |-YangIfFeature |
* | key | 7.8.2 | 0..1 |-String list |
* | leaf | 7.6 | 0..n |-YangLeaf |
* | leaf-list | 7.7 | 0..n |-YangLeafList |
* | list | 7.8 | 0..n |-child nodes |
* | max-elements | 7.7.4 | 0..1 |-int |
* | min-elements | 7.7.3 | 0..1 |-int |
* | must | 7.5.3 | 0..n |-TODO |
* | must | 7.5.3 | 0..n |-YangMust |
* | ordered-by | 7.7.5 | 0..1 |-TODO |
* | reference | 7.19.4 | 0..1 |-string |
* | status | 7.19.2 | 0..1 |-YangStatus |
* | typedef | 7.3 | 0..n |-child nodes |
* | unique | 7.8.3 | 0..n |-TODO |
* | uses | 7.12 | 0..n |-child nodes(TODO)|
* | when | 7.19.5 | 0..1 |-TODO |
* | uses | 7.12 | 0..n |-child nodes |
* | when | 7.19.5 | 0..1 |-YangWhen |
* +--------------+---------+-------------+------------------+
*/
......@@ -69,7 +69,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
*/
public class YangList
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder,
YangMustHolder, YangIfFeatureHolder {
private static final long serialVersionUID = 806201609L;
......@@ -165,10 +166,24 @@ public class YangList
/**
* Status of the node.
*/
private YangStatusType status = YangStatusType.CURRENT;
/**
* List of must statement constraints.
*/
private List<YangMust> mustConstraintList;
/**
* When data of the node.
*/
private YangWhen when;
/**
* List of if-feature.
*/
private List<YangIfFeature> ifFeatureList;
/**
* Creates a YANG list object.
*/
public YangList() {
......@@ -176,6 +191,24 @@ public class YangList
}
/**
* Returns the when.
*
* @return the when
*/
public YangWhen getWhen() {
return when;
}
/**
* Sets the when.
*
* @param when the when to set
*/
public void setWhen(YangWhen when) {
this.when = when;
}
/**
* Returns the YANG list name.
*
* @return YANG list name
......@@ -643,4 +676,40 @@ public class YangList
return false;
// TODO When grouping linking is done this method has to be modified.
}
@Override
public List<YangIfFeature> getIfFeatureList() {
return ifFeatureList;
}
@Override
public void addIfFeatureList(YangIfFeature ifFeature) {
if (getIfFeatureList() == null) {
setIfFeatureList(new LinkedList<>());
}
getIfFeatureList().add(ifFeature);
}
@Override
public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
this.ifFeatureList = ifFeatureList;
}
@Override
public List<YangMust> getListOfMust() {
return mustConstraintList;
}
@Override
public void setListOfMust(List<YangMust> mustConstraintList) {
this.mustConstraintList = mustConstraintList;
}
@Override
public void addMust(YangMust must) {
if (getListOfMust() == null) {
setListOfMust(new LinkedList<>());
}
getListOfMust().add(must);
}
}
......
......@@ -74,7 +74,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLi
public class YangModule
extends YangNode
implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver,
RpcNotificationContainer {
RpcNotificationContainer, YangFeatureHolder {
private static final long serialVersionUID = 806201610L;
......@@ -85,7 +85,7 @@ public class YangModule
/**
* 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 +96,7 @@ public class YangModule
/**
* 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
......@@ -125,13 +125,18 @@ public class YangModule
private List<YangLeafList> listOfLeafList;
/**
* List of feature at root level in the module.
*/
private List<YangFeature> listOfFeature;
/**
* Name space of the module.
*/
private YangNameSpace nameSpace;
/**
* 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
......@@ -201,6 +206,11 @@ public class YangModule
private List<YangResolutionInfo> usesResolutionList;
/**
* if-feature resolution list.
*/
private List<YangResolutionInfo> ifFeatureResolutionList;
/**
* Creates a YANG node of module type.
*/
public YangModule() {
......@@ -208,6 +218,7 @@ public class YangModule
super(YangNodeType.MODULE_NODE);
derivedTypeResolutionList = new LinkedList<>();
usesResolutionList = new LinkedList<>();
ifFeatureResolutionList = new LinkedList<>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
......@@ -373,6 +384,24 @@ public class YangModule
getListOfLeafList().add(leafList);
}
@Override
public List<YangFeature> getFeatureList() {
return listOfFeature;
}
@Override
public void addFeatureList(YangFeature feature) {
if (getFeatureList() == null) {
setListOfFeature(new LinkedList<>());
}
getFeatureList().add(feature);
}
@Override
public void setListOfFeature(List<YangFeature> listOfFeature) {
this.listOfFeature = listOfFeature;
}
/**
* Returns the name space of module elements.
*
......@@ -558,10 +587,11 @@ public class YangModule
public List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type) {
if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
return derivedTypeResolutionList;
} else {
} else if (type == ResolvableType.YANG_USES) {
return usesResolutionList;
} else {
return ifFeatureResolutionList;
}
}
@Override
......@@ -571,6 +601,8 @@ public class YangModule
derivedTypeResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_USES) {
usesResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_IF_FEATURE) {
ifFeatureResolutionList.add(resolutionInfo);
}
}
......@@ -581,6 +613,8 @@ public class YangModule
derivedTypeResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_USES) {
usesResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_IF_FEATURE) {
ifFeatureResolutionList.add((YangResolutionInfo) resolutionList);
}
}
......
......@@ -55,7 +55,7 @@ public class YangMust implements YangDesc, YangReference, Parsable, Serializable
/**
* Constraint info.
*/
private String constratint;
private String constraint;
/**
* Description string.
......@@ -78,17 +78,17 @@ public class YangMust implements YangDesc, YangReference, Parsable, Serializable
*
* @return the constraint
*/
public String getConstratint() {
return constratint;
public String getConstraint() {
return constraint;
}
/**
* Sets the constraint.
*
* @param constratint the constraint to set
* @param constraint the constraint to set
*/
public void setConstratint(String constratint) {
this.constratint = constratint;
public void setConstraint(String constraint) {
this.constraint = constraint;
}
/**
......
/*
* 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.datamodel;
import java.util.List;
/**
* Abstraction of must entity. It is used to abstract the data holders of must.
*/
public interface YangMustHolder {
/**
* Returns the list of must from data holder like container / list.
*
* @return the list of must
*/
List<YangMust> getListOfMust();
/**
* Sets the list of must.
*
* @param mustConstraintList the list of must to set
*/
void setListOfMust(List<YangMust> mustConstraintList);
/**
* Adds must in data holder like container / list.
*
* @param must the must to be added
*/
void addMust(YangMust must);
}
......@@ -60,7 +60,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
* | container | 7.5 | 0..n | -child nodes |
* | description | 7.19.3 | 0..1 | -string |
* | grouping | 7.11 | 0..n | -child nodes |
* | if-feature | 7.18.2 | 0..n | -TODO |
* | if-feature | 7.18.2 | 0..n | -YangIfFeature |
* | leaf | 7.6 | 0..n | -YangLeaf |
* | leaf-list | 7.7 | 0..n | -YangLeafList |
* | list | 7.8 | 0..n | -child nodes |
......@@ -76,7 +76,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
*/
public class YangNotification
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder,
YangIfFeatureHolder {
private static final long serialVersionUID = 806201611L;
......@@ -111,6 +112,11 @@ public class YangNotification
private YangStatusType status = YangStatusType.CURRENT;
/**
* List of if-feature.
*/
private List<YangIfFeature> ifFeatureList;
/**
* Create a notification node.
*/
public YangNotification() {
......@@ -221,4 +227,22 @@ public class YangNotification
public void setStatus(YangStatusType status) {
this.status = status;
}
@Override
public List<YangIfFeature> getIfFeatureList() {
return ifFeatureList;
}
@Override
public void addIfFeatureList(YangIfFeature ifFeature) {
if (getIfFeatureList() == null) {
setIfFeatureList(new LinkedList<>());
}
getIfFeatureList().add(ifFeature);
}
@Override
public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
this.ifFeatureList = ifFeatureList;
}
}
......
......@@ -16,7 +16,7 @@
package org.onosproject.yangutils.datamodel;
import java.io.Serializable;
import java.util.Date;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
......@@ -41,6 +41,7 @@ import org.onosproject.yangutils.datamodel.utils.YangConstructType;
* | reference | 7.19.4 | 0..1 |sring |
* +--------------+---------+-------------+------------------+
*/
/**
* Represents the information about the revision.
*/
......@@ -51,7 +52,7 @@ public class YangRevision implements YangDesc, YangReference, Parsable, Serializ
/**
* Revision date. Date string in the format "YYYY-MM-DD"
*/
private String revDate;
private Date revDate;
/**
* Description of revision.
......@@ -74,7 +75,7 @@ public class YangRevision implements YangDesc, YangReference, Parsable, Serializ
*
* @return the revision date
*/
public String getRevDate() {
public Date getRevDate() {
return revDate;
}
......@@ -83,7 +84,7 @@ public class YangRevision implements YangDesc, YangReference, Parsable, Serializ
*
* @param revDate the revision date to set
*/
public void setRevDate(String revDate) {
public void setRevDate(Date revDate) {
this.revDate = revDate;
}
......
......@@ -16,6 +16,8 @@
package org.onosproject.yangutils.datamodel;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
......@@ -44,7 +46,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
* +--------------+---------+-------------+------------------+
* | description | 7.19.3 | 0..1 | -string |
* | grouping | 7.11 | 0..n | -child nodes |
* | if-feature | 7.18.2 | 0..n | -TODO |
* | if-feature | 7.18.2 | 0..n | -YangIfFeature |
* | input | 7.13.2 | 0..1 | -child nodes |
* | output | 7.13.3 | 0..1 | -child nodes |
* | reference | 7.19.4 | 0..1 | -string |
......@@ -57,7 +59,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
* Represents data model node to maintain information defined in YANG rpc.
*/
public class YangRpc extends YangNode implements YangCommonInfo, Parsable,
CollisionDetector {
CollisionDetector, YangIfFeatureHolder {
private static final long serialVersionUID = 806201613L;
......@@ -82,6 +84,11 @@ public class YangRpc extends YangNode implements YangCommonInfo, Parsable,
private YangStatusType status = YangStatusType.CURRENT;
/**
* List of if-feature.
*/
private List<YangIfFeature> ifFeatureList;
/**
* Create a rpc node.
*/
public YangRpc() {
......@@ -156,4 +163,22 @@ public class YangRpc extends YangNode implements YangCommonInfo, Parsable,
public void setStatus(YangStatusType status) {
this.status = status;
}
@Override
public List<YangIfFeature> getIfFeatureList() {
return ifFeatureList;
}
@Override
public void addIfFeatureList(YangIfFeature ifFeature) {
if (getIfFeatureList() == null) {
setIfFeatureList(new LinkedList<>());
}
getIfFeatureList().add(ifFeature);
}
@Override
public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
this.ifFeatureList = ifFeatureList;
}
}
......
......@@ -57,7 +57,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLi
* | description | 7.19.3 | 0..1 | - string |
* | deviation | 7.18.3 | 0..n | - TODO |
* | extension | 7.17 | 0..n | - TODO |
* | feature | 7.18.1 | 0..n | - TODO |
* | feature | 7.18.1 | 0..n | - YangFeature |
* | grouping | 7.11 | 0..n | - child nodes |
* | identity | 7.16 | 0..n | - TODO |
* | import | 7.1.5 | 0..n | - YangImport |
......@@ -82,7 +82,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLi
public class YangSubModule
extends YangNode
implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver,
RpcNotificationContainer {
RpcNotificationContainer, YangFeatureHolder {
private static final long serialVersionUID = 806201614L;
......@@ -133,6 +133,11 @@ public class YangSubModule
private List<YangLeafList> listOfLeafList;
/**
* List of feature at root level in the module.
*/
private List<YangFeature> listOfFeature;
/**
* Organization owner of the sub-module.
*/
private String organization;
......@@ -199,12 +204,18 @@ public class YangSubModule
private List<YangResolutionInfo> usesResolutionList;
/**
* if-feature resolution list.
*/
private List<YangResolutionInfo> ifFeatureResolutionList;
/**
* Creates a sub module node.
*/
public YangSubModule() {
super(YangNodeType.SUB_MODULE_NODE);
derivedTypeResolutionList = new LinkedList<>();
usesResolutionList = new LinkedList<>();
ifFeatureResolutionList = new LinkedList<>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
......@@ -538,8 +549,10 @@ public class YangSubModule
public List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type) {
if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
return derivedTypeResolutionList;
} else {
} else if (type == ResolvableType.YANG_USES) {
return usesResolutionList;
} else {
return ifFeatureResolutionList;
}
}
......@@ -550,6 +563,8 @@ public class YangSubModule
derivedTypeResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_USES) {
usesResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_IF_FEATURE) {
ifFeatureResolutionList.add(resolutionInfo);
}
}
......@@ -560,6 +575,8 @@ public class YangSubModule
derivedTypeResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_USES) {
usesResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_IF_FEATURE) {
ifFeatureResolutionList = resolutionList;
}
}
......@@ -601,4 +618,22 @@ public class YangSubModule
yangImport.addReferenceToImport(yangNodeSet);
}
}
@Override
public List<YangFeature> getFeatureList() {
return listOfFeature;
}
@Override
public void addFeatureList(YangFeature feature) {
if (getFeatureList() == null) {
setListOfFeature(new LinkedList<>());
}
getFeatureList().add(feature);
}
@Override
public void setListOfFeature(List<YangFeature> listOfFeature) {
this.listOfFeature = listOfFeature;
}
}
......
......@@ -48,11 +48,11 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParent
* +--------------+---------+-------------+------------------+
* | augment | 7.15 | 0..1 | -child nodes |
* | description | 7.19.3 | 0..1 | -string |
* | if-feature | 7.18.2 | 0..n | -TODO |
* | if-feature | 7.18.2 | 0..n | -YangIfFeature |
* | refine | 7.12.2 | 0..1 | -TODO |
* | reference | 7.19.4 | 0..1 | -string |
* | status | 7.19.2 | 0..1 | -YangStatus |
* | when | 7.19.5 | 0..1 | -TODO |
* | when | 7.19.5 | 0..1 | -YangWhen |
* +--------------+---------+-------------+------------------+
*/
......@@ -61,7 +61,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParent
*/
public class YangUses
extends YangNode
implements YangCommonInfo, Parsable, Resolvable, CollisionDetector {
implements YangCommonInfo, Parsable, Resolvable, CollisionDetector, YangWhenHolder,
YangIfFeatureHolder {
private static final long serialVersionUID = 806201617L;
......@@ -91,6 +92,16 @@ public class YangUses
private YangStatusType status;
/**
* When data of the node.
*/
private YangWhen when;
/**
* List of if-feature.
*/
private List<YangIfFeature> ifFeatureList;
/**
* Status of resolution. If completely resolved enum value is "RESOLVED",
* if not enum value is "UNRESOLVED", in case reference of grouping/typedef
* is added to uses/type but it's not resolved value of enum should be
......@@ -144,6 +155,26 @@ public class YangUses
}
/**
* Returns the when.
*
* @return the when
*/
@Override
public YangWhen getWhen() {
return when;
}
/**
* Sets the when.
*
* @param when the when to set
*/
@Override
public void setWhen(YangWhen when) {
this.when = when;
}
/**
* Returns the description.
*
* @return the description
......@@ -503,4 +534,22 @@ public class YangUses
public List<List<YangLeafList>> getUsesResolvedListOfLeafList() {
return resolvedGroupingLeafLists;
}
@Override
public List<YangIfFeature> getIfFeatureList() {
return ifFeatureList;
}
@Override
public void addIfFeatureList(YangIfFeature ifFeature) {
if (getIfFeatureList() == null) {
setIfFeatureList(new LinkedList<>());
}
getIfFeatureList().add(ifFeature);
}
@Override
public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
this.ifFeatureList = ifFeatureList;
}
}
......
/*
* 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.datamodel;
import java.io.Serializable;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
/*
* Reference RFC 6020.
*
* The "when" statement makes its parent data definition statement
* conditional. The node defined by the parent data definition
* statement is only valid when the condition specified by the "when"
* statement is satisfied.
*
* The statement's argument is an XPath expression, which is used to formally
* specify this condition. If the XPath expression conceptually evaluates to
* "true" for a particular instance, then the node defined by the parent data
* definition statement is valid; otherwise, it is not.
*
* The when's sub-statements
*
* +---------------+---------+-------------+------------------+
* | substatement | section | cardinality |data model mapping|
* +---------------+---------+-------------+------------------+
* | description | 7.19.3 | 0..1 | -string |
* | reference | 7.19.4 | 0..1 | -string |
* +---------------+---------+-------------+------------------+
*/
/**
* Represents information defined in YANG when.
*/
public class YangWhen implements YangDesc, YangReference, Parsable, Serializable {
private static final long serialVersionUID = 806201646L;
/**
* When condition info.
*/
private String condition;
/**
* Description string.
*/
private String description;
/**
* Reference string.
*/
private String reference;
/**
* Creates a YANG when restriction.
*/
public YangWhen() {
}
/**
* Returns the condition.
*
* @return the condition
*/
public String getCondition() {
return condition;
}
/**
* Sets the condition.
*
* @param condition the condition to set
*/
public void setCondition(String condition) {
this.condition = condition;
}
/**
* Returns the description.
*
* @return the description
*/
@Override
public String getDescription() {
return description;
}
/**
* Sets the description.
*
* @param description set the description
*/
@Override
public void setDescription(String description) {
this.description = description;
}
/**
* Returns the textual reference.
*
* @return the reference
*/
@Override
public String getReference() {
return reference;
}
/**
* Sets the textual reference.
*
* @param reference the reference to set
*/
@Override
public void setReference(String reference) {
this.reference = reference;
}
/**
* Returns the type of the parsed data.
*
* @return returns WHEN_DATA
*/
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.WHEN_DATA;
}
/**
* Validates the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Validates the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
}
/*
* 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.datamodel;
/**
* Abstraction of when entity. It is used to abstract the data holders of when.
*/
public interface YangWhenHolder {
/**
* Returns the when.
*
* @return the when
*/
YangWhen getWhen();
/**
* Sets the when.
*
* @param when the when to set
*/
void setWhen(YangWhen when);
}
......@@ -21,6 +21,7 @@ import java.util.Set;
import org.onosproject.yangutils.datamodel.CollisionDetector;
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangIfFeature;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
......@@ -29,13 +30,14 @@ import org.onosproject.yangutils.datamodel.YangReferenceResolver;
import org.onosproject.yangutils.datamodel.YangResolutionInfo;
import org.onosproject.yangutils.datamodel.YangRpc;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
/**
* Represents utilities for data model tree.
*/
public final class DataModelUtils {
/**
* Creates a new data model tree utility.
*/
......@@ -161,11 +163,15 @@ public final class DataModelUtils {
.getEntityToResolve() instanceof YangType) {
resolutionNode.addToResolutionList(resolutionInfo,
ResolvableType.YANG_DERIVED_DATA_TYPE);
} else {
} else if (resolutionInfo.getEntityToResolveInfo()
.getEntityToResolve() instanceof YangUses) {
resolutionNode.addToResolutionList(resolutionInfo,
ResolvableType.YANG_USES);
} else if (resolutionInfo.getEntityToResolveInfo()
.getEntityToResolve() instanceof YangIfFeature) {
resolutionNode.addToResolutionList(resolutionInfo,
ResolvableType.YANG_IF_FEATURE);
}
}
/**
......
......@@ -46,6 +46,11 @@ public enum ResolvableStatus {
* Identifies that resolvable entity is inter file linked (i.e. complete
* linking with external files).
*/
INTER_FILE_LINKED
INTER_FILE_LINKED,
/**
* Identifies that resolvable entity is referred node is not defined.
*/
UNDEFINED
}
......
......@@ -18,6 +18,7 @@ package org.onosproject.yangutils.linker.impl;
import java.io.Serializable;
import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo;
import org.onosproject.yangutils.datamodel.YangIfFeature;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangUses;
......@@ -76,6 +77,8 @@ public class YangEntityToResolveInfoImpl<T> implements YangEntityToResolveInfo<T
prefix = ((YangType<?>) entityToBeResolved).getPrefix();
} else if (entityToBeResolved instanceof YangUses) {
prefix = ((YangUses) entityToBeResolved).getPrefix();
} else if (entityToBeResolved instanceof YangIfFeature) {
prefix = ((YangIfFeature) entityToBeResolved).getPrefix();
} else {
throw new LinkerException("Linker Exception: Entity to resolved is other than type/uses");
}
......
......@@ -156,6 +156,8 @@ public class YangLinkerManager
throws LinkerException {
for (YangNode yangNode : yangNodeSet) {
try {
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_IF_FEATURE);
((YangReferenceResolver) yangNode).resolveInterFileLinking(ResolvableType.YANG_USES);
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
......
......@@ -40,7 +40,9 @@ import org.onosproject.yangutils.parser.impl.listeners.DefaultListener;
import org.onosproject.yangutils.parser.impl.listeners.DescriptionListener;
import org.onosproject.yangutils.parser.impl.listeners.EnumListener;
import org.onosproject.yangutils.parser.impl.listeners.EnumerationListener;
import org.onosproject.yangutils.parser.impl.listeners.FeatureListener;
import org.onosproject.yangutils.parser.impl.listeners.GroupingListener;
import org.onosproject.yangutils.parser.impl.listeners.IfFeatureListener;
import org.onosproject.yangutils.parser.impl.listeners.ImportListener;
import org.onosproject.yangutils.parser.impl.listeners.IncludeListener;
import org.onosproject.yangutils.parser.impl.listeners.InputListener;
......@@ -53,6 +55,7 @@ import org.onosproject.yangutils.parser.impl.listeners.MandatoryListener;
import org.onosproject.yangutils.parser.impl.listeners.MaxElementsListener;
import org.onosproject.yangutils.parser.impl.listeners.MinElementsListener;
import org.onosproject.yangutils.parser.impl.listeners.ModuleListener;
import org.onosproject.yangutils.parser.impl.listeners.MustListener;
import org.onosproject.yangutils.parser.impl.listeners.NotificationListener;
import org.onosproject.yangutils.parser.impl.listeners.NamespaceListener;
import org.onosproject.yangutils.parser.impl.listeners.OrganizationListener;
......@@ -76,6 +79,7 @@ import org.onosproject.yangutils.parser.impl.listeners.UnitsListener;
import org.onosproject.yangutils.parser.impl.listeners.UsesListener;
import org.onosproject.yangutils.parser.impl.listeners.ValueListener;
import org.onosproject.yangutils.parser.impl.listeners.VersionListener;
import org.onosproject.yangutils.parser.impl.listeners.WhenListener;
import static org.onosproject.yangutils.utils.UtilConstants.UNSUPPORTED_YANG_CONSTRUCT;
import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED;
......@@ -473,22 +477,22 @@ public class TreeWalkListener implements GeneratedYangListener {
@Override
public void enterFeatureStatement(GeneratedYangParser.FeatureStatementContext ctx) {
handleUnsupportedYangConstruct(YangConstructType.FEATURE_DATA, ctx, CURRENTLY_UNSUPPORTED);
FeatureListener.processFeatureEntry(this, ctx);
}
@Override
public void exitFeatureStatement(GeneratedYangParser.FeatureStatementContext ctx) {
//TODO: to be implemented
FeatureListener.processFeatureExit(this, ctx);
}
@Override
public void enterFeatureBody(GeneratedYangParser.FeatureBodyContext ctx) {
//TODO : to be implemented
// do nothing
}
@Override
public void exitFeatureBody(GeneratedYangParser.FeatureBodyContext ctx) {
//TODO : to be implemented
// do nothing.
}
@Override
......@@ -503,12 +507,12 @@ public class TreeWalkListener implements GeneratedYangListener {
@Override
public void enterIfFeatureStatement(GeneratedYangParser.IfFeatureStatementContext ctx) {
// TODO: to be implemented
IfFeatureListener.processIfFeatureEntry(this, ctx);
}
@Override
public void exitIfFeatureStatement(GeneratedYangParser.IfFeatureStatementContext ctx) {
// TODO: to be implemented
// do nothing.
}
@Override
......@@ -813,12 +817,12 @@ public class TreeWalkListener implements GeneratedYangListener {
@Override
public void enterMustStatement(GeneratedYangParser.MustStatementContext ctx) {
// TODO: to be implemented
MustListener.processMustEntry(this, ctx);
}
@Override
public void exitMustStatement(GeneratedYangParser.MustStatementContext ctx) {
// TODO: to be implemented
MustListener.processMustExit(this, ctx);
}
@Override
......@@ -1083,12 +1087,12 @@ public class TreeWalkListener implements GeneratedYangListener {
@Override
public void enterWhenStatement(GeneratedYangParser.WhenStatementContext ctx) {
// TODO: to be implemented
WhenListener.processWhenEntry(this, ctx);
}
@Override
public void exitWhenStatement(GeneratedYangParser.WhenStatementContext ctx) {
// TODO: to be implemented
WhenListener.processWhenExit(this, ctx);
}
@Override
......
/*
* 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.parser.impl.listeners;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
*
* ABNF grammar as per RFC6020
* feature-stmt = feature-keyword sep identifier-arg-str optsep
* (";" /
* "{" stmtsep
* ;; these stmts can appear in any order
* *(if-feature-stmt stmtsep)
* [status-stmt stmtsep]
* [description-stmt stmtsep]
* [reference-stmt stmtsep]
* "}")
*
*
*
* ANTLR grammar rule
* featureStatement : FEATURE_KEYWORD string (STMTEND | LEFT_CURLY_BRACE featureBody RIGHT_CURLY_BRACE);
*/
import org.onosproject.yangutils.datamodel.YangFeature;
import org.onosproject.yangutils.datamodel.YangFeatureHolder;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.FEATURE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/**
* Represents listener based call back function corresponding to the "feature"
* rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
*/
public final class FeatureListener {
/**
* Creates a new feature listener.
*/
private FeatureListener() {
}
/**
* Performs validation and updates the data model tree.It is called when parser receives
* an input matching the grammar rule (feature).
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processFeatureEntry(TreeWalkListener listener,
GeneratedYangParser.FeatureStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, FEATURE_DATA, ctx.string().getText(), ENTRY);
String identifier = getValidIdentifier(ctx.string().getText(), FEATURE_DATA, ctx);
// Obtain the node of the stack.
Parsable tmpNode = listener.getParsedDataStack().peek();
if (tmpNode instanceof YangFeatureHolder) {
YangFeatureHolder featureHolder = (YangFeatureHolder) tmpNode;
YangFeature feature = new YangFeature();
feature.setName(identifier);
featureHolder.addFeatureList(feature);
listener.getParsedDataStack().push(feature);
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, FEATURE_DATA,
ctx.string().getText(), ENTRY));
}
}
/**
* Perform validations and updates the data model tree.It is called when parser exits from
* grammar rule(feature).
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processFeatureExit(TreeWalkListener listener,
GeneratedYangParser.FeatureStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, FEATURE_DATA, ctx.string().getText(), EXIT);
if (listener.getParsedDataStack().peek() instanceof YangFeature) {
listener.getParsedDataStack().pop();
} else {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, FEATURE_DATA,
ctx.string().getText(), EXIT));
}
}
}
/*
* 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.parser.impl.listeners;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
*
* ABNF grammar as per RFC6020
*
* if-feature-stmt = if-feature-keyword sep identifier-ref-arg-str
* optsep stmtend
*
* ANTLR grammar rule
* ifFeatureStatement : IF_FEATURE_KEYWORD string STMTEND;
*/
import org.onosproject.yangutils.datamodel.YangFeature;
import org.onosproject.yangutils.datamodel.YangIfFeature;
import org.onosproject.yangutils.datamodel.YangIfFeatureHolder;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.datamodel.YangResolutionInfo;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.linker.impl.YangResolutionInfoImpl;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNRESOLVED;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.IF_FEATURE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidNodeIdentifier;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/**
* Represents listener based call back function corresponding to the "if-feature"
* rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
*/
public final class IfFeatureListener {
/**
* Creates a new IfFeature listener.
*/
private IfFeatureListener() {
}
/**
* Performs validation and updates the data model tree.It is called when parser receives
* an input matching the grammar rule (if-feature).
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processIfFeatureEntry(TreeWalkListener listener,
GeneratedYangParser.IfFeatureStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, IF_FEATURE_DATA, ctx.string().getText(), ENTRY);
// Validate if-feature argument string
YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.string().getText(),
IF_FEATURE_DATA, ctx);
YangIfFeature ifFeature = new YangIfFeature();
ifFeature.setName(nodeIdentifier);
ifFeature.setResolvableStatus(UNRESOLVED);
YangIfFeatureHolder ifFeatureHolder;
// Obtain the node of the stack.
Parsable tmpNode = listener.getParsedDataStack().peek();
if (tmpNode instanceof YangIfFeatureHolder) {
ifFeatureHolder = (YangIfFeatureHolder) tmpNode;
ifFeatureHolder.addIfFeatureList(ifFeature);
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IF_FEATURE_DATA,
ctx.string().getText(), ENTRY));
}
// Add resolution information to the list
Parsable parentNode;
if (tmpNode instanceof YangLeafList || tmpNode instanceof YangLeaf
|| tmpNode instanceof YangFeature) {
Parsable leafData = listener.getParsedDataStack().pop();
parentNode = listener.getParsedDataStack().peek();
listener.getParsedDataStack().push(leafData);
} else {
parentNode = tmpNode;
}
// Verify parent node of leaf
if (!(parentNode instanceof YangNode)) {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IF_FEATURE_DATA,
ctx.string().getText(), EXIT));
}
int errorLine = ctx.getStart().getLine();
int errorPosition = ctx.getStart().getCharPositionInLine();
YangResolutionInfoImpl resolutionInfo = new YangResolutionInfoImpl<YangIfFeature>(ifFeature,
(YangNode) parentNode, errorLine,
errorPosition);
addToResolutionList(resolutionInfo, ctx);
}
/**
* Add to resolution list.
*
* @param resolutionInfo resolution information.
* @param ctx context object of the grammar rule
*/
private static void addToResolutionList(YangResolutionInfo<YangIfFeature> resolutionInfo,
GeneratedYangParser.IfFeatureStatementContext ctx) {
try {
addResolutionInfo(resolutionInfo);
} catch (DataModelException e) {
throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
IF_FEATURE_DATA, ctx.string().getText(), EXIT, e.getMessage()));
}
}
}
......@@ -16,11 +16,13 @@
package org.onosproject.yangutils.parser.impl.listeners;
import java.util.Date;
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangReferenceResolver;
import org.onosproject.yangutils.datamodel.YangRevision;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
......@@ -34,8 +36,8 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMes
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getCurrentDateForRevision;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.setCurrentDateForRevision;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangModuleNode;
......@@ -91,13 +93,6 @@ public final class ModuleListener {
yangModule.setVersion((byte) 1);
}
if (ctx.moduleBody().revisionStatements().revisionStatement().isEmpty()) {
String currentDate = setCurrentDateForRevision();
YangRevision currentRevision = new YangRevision();
currentRevision.setRevDate(currentDate);
yangModule.setRevision(currentRevision);
}
listener.getParsedDataStack().push(yangModule);
}
......@@ -113,12 +108,23 @@ public final class ModuleListener {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, MODULE_DATA, ctx.identifier().getText(), EXIT);
if (!(listener.getParsedDataStack().peek() instanceof YangModule)) {
Parsable tmpNode = listener.getParsedDataStack().peek();
if (!(tmpNode instanceof YangModule)) {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, MODULE_DATA,
ctx.identifier().getText(), EXIT));
}
if (((YangModule) tmpNode).getRevision() == null) {
Date currentDate = getCurrentDateForRevision();
YangRevision currentRevision = new YangRevision();
currentRevision.setRevDate(currentDate);
((YangModule) tmpNode).setRevision(currentRevision);
}
try {
((YangReferenceResolver) listener.getParsedDataStack()
.peek()).resolveSelfFileLinking(ResolvableType.YANG_IF_FEATURE);
((YangReferenceResolver) listener.getParsedDataStack()
.peek()).resolveSelfFileLinking(ResolvableType.YANG_USES);
((YangReferenceResolver) listener.getParsedDataStack()
.peek()).resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
......
/*
* 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.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangMust;
import org.onosproject.yangutils.datamodel.YangMustHolder;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.MUST_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
*
* ABNF grammar as per RFC6020
*
* must-stmt = must-keyword sep string optsep
* (";" /
* "{" stmtsep
* ;; these stmts can appear in any order
* [error-message-stmt stmtsep]
* [error-app-tag-stmt stmtsep]
* [description-stmt stmtsep]
* [reference-stmt stmtsep]
* "}")
*
* ANTLR grammar rule
* mustStatement : MUST_KEYWORD string (STMTEND | LEFT_CURLY_BRACE commonStatements RIGHT_CURLY_BRACE);
*/
/**
* Represents listener based call back function corresponding to the
* "must" rule defined in ANTLR grammar file for corresponding ABNF rule
* in RFC 6020.
*/
public final class MustListener {
/**
* Creates a new must listener.
*/
private MustListener() {
}
/**
* Perform validations and updates the data model tree.It is called when parser
* receives an input matching the grammar rule (must).
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processMustEntry(TreeWalkListener listener,
GeneratedYangParser.MustStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, MUST_DATA, ctx.string().getText(), ENTRY);
String constraint = removeQuotesAndHandleConcat(ctx.string().getText());
// Obtain the node of the stack.
Parsable tmpNode = listener.getParsedDataStack().peek();
if (tmpNode instanceof YangMustHolder) {
YangMust must = new YangMust();
must.setConstraint(constraint);
YangMustHolder mustHolder = (YangMustHolder) tmpNode;
mustHolder.addMust(must);
listener.getParsedDataStack().push(must);
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, MUST_DATA,
ctx.string().getText(), ENTRY));
}
}
/**
* Performs validation and updates the data model tree.It is called when parser
* exits from grammar rule (must).
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processMustExit(TreeWalkListener listener,
GeneratedYangParser.MustStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, MUST_DATA, ctx.string().getText(), EXIT);
if (listener.getParsedDataStack().peek() instanceof YangMust) {
listener.getParsedDataStack().pop();
} else {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, MUST_DATA,
ctx.string().getText(), EXIT));
}
}
}
......@@ -16,6 +16,7 @@
package org.onosproject.yangutils.parser.impl.listeners;
import java.util.Date;
import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangInclude;
import org.onosproject.yangutils.datamodel.utils.Parsable;
......@@ -28,8 +29,7 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLoc
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.isDateValid;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidDateFromString;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
......@@ -87,13 +87,7 @@ public final class RevisionDateListener {
checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATE_DATA, ctx.dateArgumentString().getText(),
ENTRY);
String date = removeQuotesAndHandleConcat(ctx.dateArgumentString().getText());
if (!isDateValid(date)) {
ParserException parserException = new ParserException("YANG file error: Input date is not correct");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
}
Date date = getValidDateFromString(ctx.dateArgumentString().getText(), ctx);
// Obtain the node of the stack.
Parsable tmpNode = listener.getParsedDataStack().peek();
......
......@@ -16,6 +16,7 @@
package org.onosproject.yangutils.parser.impl.listeners;
import java.util.Date;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangRevision;
import org.onosproject.yangutils.datamodel.YangSubModule;
......@@ -31,8 +32,7 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMes
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.isDateValid;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidDateFromString;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
......@@ -88,20 +88,7 @@ public final class RevisionListener {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATA, ctx.dateArgumentString().getText(), ENTRY);
// Validate for reverse chronological order of revision & for revision
// value.
if (!validateRevision(listener, ctx)) {
return;
// TODO to be implemented.
}
String date = removeQuotesAndHandleConcat(ctx.dateArgumentString().getText());
if (!isDateValid(date)) {
ParserException parserException = new ParserException("YANG file error: Input date is not correct");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
}
Date date = getValidDateFromString(ctx.dateArgumentString().getText(), ctx);
YangRevision revisionNode = new YangRevision();
revisionNode.setRevDate(date);
......@@ -134,12 +121,26 @@ public final class RevisionListener {
switch (tmpNode.getYangConstructType()) {
case MODULE_DATA: {
YangModule module = (YangModule) tmpNode;
module.setRevision((YangRevision) tmpRevisionNode);
if (module.getRevision() != null) {
Date curRevisionDate = module.getRevision().getRevDate();
if (curRevisionDate.before(((YangRevision) tmpRevisionNode).getRevDate())) {
module.setRevision((YangRevision) tmpRevisionNode);
}
} else {
module.setRevision((YangRevision) tmpRevisionNode);
}
break;
}
case SUB_MODULE_DATA: {
YangSubModule subModule = (YangSubModule) tmpNode;
subModule.setRevision((YangRevision) tmpRevisionNode);
if (subModule.getRevision() != null) {
Date curRevisionDate = subModule.getRevision().getRevDate();
if (curRevisionDate.before(((YangRevision) tmpRevisionNode).getRevDate())) {
subModule.setRevision((YangRevision) tmpRevisionNode);
}
} else {
subModule.setRevision((YangRevision) tmpRevisionNode);
}
break;
}
default:
......
......@@ -16,11 +16,13 @@
package org.onosproject.yangutils.parser.impl.listeners;
import java.util.Date;
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangReferenceResolver;
import org.onosproject.yangutils.datamodel.YangRevision;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
......@@ -34,8 +36,8 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMes
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getCurrentDateForRevision;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.setCurrentDateForRevision;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangSubModuleNode;
......@@ -94,13 +96,6 @@ public final class SubModuleListener {
yangSubModule.setVersion((byte) 1);
}
if (ctx.submoduleBody().revisionStatements().revisionStatement().isEmpty()) {
String currentDate = setCurrentDateForRevision();
YangRevision currentRevision = new YangRevision();
currentRevision.setRevDate(currentDate);
yangSubModule.setRevision(currentRevision);
}
listener.getParsedDataStack().push(yangSubModule);
}
......@@ -118,12 +113,23 @@ public final class SubModuleListener {
checkStackIsNotEmpty(listener, MISSING_HOLDER, SUB_MODULE_DATA, ctx.identifier().getText(),
EXIT);
if (!(listener.getParsedDataStack().peek() instanceof YangSubModule)) {
Parsable tmpNode = listener.getParsedDataStack().peek();
if (!(tmpNode instanceof YangSubModule)) {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, SUB_MODULE_DATA,
ctx.identifier().getText(), EXIT));
}
if (((YangSubModule) tmpNode).getRevision() == null) {
Date currentDate = getCurrentDateForRevision();
YangRevision currentRevision = new YangRevision();
currentRevision.setRevDate(currentDate);
((YangSubModule) tmpNode).setRevision(currentRevision);
}
try {
((YangReferenceResolver) listener.getParsedDataStack().peek())
.resolveSelfFileLinking(ResolvableType.YANG_IF_FEATURE);
((YangReferenceResolver) listener.getParsedDataStack().peek())
.resolveSelfFileLinking(ResolvableType.YANG_USES);
((YangReferenceResolver) listener.getParsedDataStack().peek())
.resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
......
/*
* 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.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangWhen;
import org.onosproject.yangutils.datamodel.YangWhenHolder;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.WHEN_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
*
* ABNF grammar as per RFC6020
*
* when-stmt = when-keyword sep string optsep
* (";" /
* "{" stmtsep
* ;; these stmts can appear in any order
* [description-stmt stmtsep]
* [reference-stmt stmtsep]
* "}")
*
* ANTLR grammar rule
* whenStatement : WHEN_KEYWORD string (STMTEND | LEFT_CURLY_BRACE ((descriptionStatement? referenceStatement?)
* | (referenceStatement? descriptionStatement?)) RIGHT_CURLY_BRACE);
*/
/**
* Represents listener based call back function corresponding to the
* "when" rule defined in ANTLR grammar file for corresponding ABNF rule
* in RFC 6020.
*/
public final class WhenListener {
/**
* Creates a new when listener.
*/
private WhenListener() {
}
/**
* Perform validations and updates the data model tree.It is called when parser
* receives an input matching the grammar rule (when).
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processWhenEntry(TreeWalkListener listener,
GeneratedYangParser.WhenStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, WHEN_DATA, ctx.string().getText(), ENTRY);
String condition = removeQuotesAndHandleConcat(ctx.string().getText());
YangWhenHolder whenHolder;
// Obtain the node of the stack.
Parsable tmpNode = listener.getParsedDataStack().peek();
if (tmpNode instanceof YangWhenHolder) {
whenHolder = (YangWhenHolder) tmpNode;
YangWhen when = new YangWhen();
when.setCondition(condition);
whenHolder.setWhen(when);
listener.getParsedDataStack().push(when);
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
WHEN_DATA, ctx.string().getText(), ENTRY));
}
}
/**
* Performs validation and updates the data model tree.It is called when parser
* exits from grammar rule (when).
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processWhenExit(TreeWalkListener listener,
GeneratedYangParser.WhenStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, WHEN_DATA, ctx.string().getText(), EXIT);
if (listener.getParsedDataStack().peek() instanceof YangWhen) {
listener.getParsedDataStack().pop();
} else {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, WHEN_DATA,
ctx.string().getText(), EXIT));
}
}
}
......@@ -18,7 +18,7 @@ package org.onosproject.yangutils.parser.impl.parserutils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Pattern;
......@@ -30,20 +30,18 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import static org.onosproject.yangutils.utils.UtilConstants.ADD;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.COLON;
import static org.onosproject.yangutils.utils.UtilConstants.CARET;
import static org.onosproject.yangutils.utils.UtilConstants.COLON;
import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED;
import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_FILE_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF;
import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF;
import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_IDENTIFIER;
import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF;
import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_FILE_ERROR;
/**
* Represents an utility for listener.
......@@ -256,17 +254,24 @@ public final class ListenerUtil {
}
/**
* Sets current date and makes it in usable format for revision.
* Returns current date and makes it in usable format for revision.
*
* @return usable current date format for revision
*/
public static String setCurrentDateForRevision() {
public static Date getCurrentDateForRevision() {
Calendar date = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
String dateForRevision = dateFormat.format(date.getTime()).replaceAll(SLASH, HYPHEN).replaceAll(SPACE,
EMPTY_STRING);
return dateForRevision;
Date date = new Date();
String dateInString = dateFormat.format(date);
try {
//if not valid, it will throw ParseException
Date now = dateFormat.parse(dateInString);
return date;
} catch (ParseException e) {
ParserException parserException = new ParserException("YANG file error: Input date is not correct");
throw parserException;
}
}
/**
......@@ -373,4 +378,35 @@ public final class ListenerUtil {
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
}
/**
* Returns date and makes it in usable format for revision.
*
* @param dateInString date argument string from yang file
* @param ctx yang construct's context to get the line number and character position
* @return date format for revision
*/
public static Date getValidDateFromString(String dateInString, ParserRuleContext ctx) {
String dateArgument = removeQuotesAndHandleConcat(dateInString);
if (dateArgument == null || !dateArgument.matches(DATE_PATTERN)) {
ParserException parserException = new ParserException("YANG file error: Input date is not correct");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
}
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
sdf.setLenient(false);
try {
//if not valid, it will throw ParseException
Date date = sdf.parse(dateArgument);
return date;
} catch (ParseException e) {
ParserException parserException = new ParserException("YANG file error: Input date is not correct");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
}
}
}
\ No newline at end of file
......
......@@ -18,7 +18,9 @@ package org.onosproject.yangutils.translator.tojava.utils;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.exception.TranslatorException;
......@@ -59,6 +61,7 @@ public final class JavaIdentifierSyntax {
private static final int INDEX_TWO = 2;
private static final int VALUE_CHECK = 10;
private static final String ZERO = "0";
private static final String DATE_FORMAT = "yyyy-MM-dd";
/**
* Create instance of java identifier syntax.
......@@ -75,7 +78,7 @@ public final class JavaIdentifierSyntax {
* @param conflictResolver object of YANG to java naming conflict util
* @return the root package string
*/
public static String getRootPackage(byte version, String nameSpace, String revision,
public static String getRootPackage(byte version, String nameSpace, Date revision,
YangToJavaNamingConflictUtil conflictResolver) {
String pkg;
......@@ -125,30 +128,23 @@ public final class JavaIdentifierSyntax {
*
* @param date YANG module revision
* @return revision string
* @throws TranslatorException when date is invalid.
*/
private static String getYangRevisionStr(String date) throws TranslatorException {
String[] revisionArr = date.split(HYPHEN);
private static String getYangRevisionStr(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
String dateInString = sdf.format(date);
String[] revisionArr = dateInString.split(HYPHEN);
String rev = REVISION_PREFIX;
rev = rev + revisionArr[INDEX_ZERO];
if (Integer.parseInt(revisionArr[INDEX_ONE]) <= MAX_MONTHS
&& Integer.parseInt(revisionArr[INDEX_TWO]) <= MAX_DAYS) {
for (int i = INDEX_ONE; i < revisionArr.length; i++) {
Integer val = Integer.parseInt(revisionArr[i]);
if (val < VALUE_CHECK) {
rev = rev + ZERO;
}
rev = rev + val;
for (int i = INDEX_ONE; i < revisionArr.length; i++) {
Integer val = Integer.parseInt(revisionArr[i]);
if (val < VALUE_CHECK) {
rev = rev + ZERO;
}
return rev;
} else {
throw new TranslatorException("Date in revision is not proper: " + date);
rev = rev + val;
}
return rev;
}
/**
......
......@@ -1140,6 +1140,12 @@ public final class UtilConstants {
+ "grouping for given uses";
/**
* Static attribute for grouping linker error information.
*/
public static final String FEATURE_LINKER_ERROR = "YANG file error: Unable to find feature "
+ "for given if-feature";
/**
* Static attribute for reference.
*/
public static final String REFERENCE = "Reference";
......
......@@ -16,14 +16,15 @@
package org.onosproject.yangutils.parser.impl.listeners;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import java.io.IOException;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
......@@ -33,6 +34,8 @@ import static org.junit.Assert.assertThat;
public class ImportListenerTest {
private final YangUtilsParserManager manager = new YangUtilsParserManager();
private static final String DATE_FORMAT = "yyyy-MM-dd";
private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT);
/**
* Checks if mandatory parameter prefix is present in import.
......@@ -65,12 +68,12 @@ public class ImportListenerTest {
* Checks if import listener updates the data model tree.
*/
@Test
public void processImportValidEntry() throws IOException, ParserException {
public void processImportValidEntry() throws IOException, ParserException, ParseException {
YangNode node = manager.getDataModel("src/test/resources/ImportValidEntry.yang");
// Checks for the revision value in data model tree.
assertThat(((YangModule) node).getImportList().get(0).getRevision(), is("2015-02-03"));
assertThat(((YangModule) node).getImportList().get(0).getRevision(), is(simpleDateFormat.parse("2015-02-03")));
// Checks for the prefix id in data model tree.
assertThat(((YangModule) node).getImportList().get(0).getPrefixId(), is("On2"));
// Checks for the module name in data model tree.
......
......@@ -16,14 +16,15 @@
package org.onosproject.yangutils.parser.impl.listeners;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import java.io.IOException;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
......@@ -33,6 +34,8 @@ import static org.junit.Assert.assertThat;
public class IncludeListenerTest {
private final YangUtilsParserManager manager = new YangUtilsParserManager();
private static final String DATE_FORMAT = "yyyy-MM-dd";
private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT);
/**
* Checks if include listener with ; is valid and updates the data
......@@ -65,43 +68,43 @@ public class IncludeListenerTest {
* and updates the data model tree.
*/
@Test
public void processIncludeWithDate() throws IOException, ParserException {
public void processIncludeWithDate() throws IOException, ParserException, ParseException {
YangNode node = manager.getDataModel("src/test/resources/IncludeWithDate.yang");
// Checks for the sub module name in data model tree.
assertThat(((YangModule) node).getIncludeList().get(0).getSubModuleName(), is("itut"));
assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03"));
assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is(simpleDateFormat.parse("2016-02-03")));
}
/**
* Checks if include has more than one occurrence.
*/
@Test
public void processIncludeMultiInstance() throws IOException, ParserException {
public void processIncludeMultiInstance() throws IOException, ParserException, ParseException {
YangNode node = manager.getDataModel("src/test/resources/IncludeMultiInstance.yang");
// Checks for the sub module name in data model tree.
assertThat(((YangModule) node).getIncludeList().get(0).getSubModuleName(), is("itut"));
assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03"));
assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is(simpleDateFormat.parse("2016-02-03")));
assertThat(((YangModule) node).getIncludeList().get(1).getSubModuleName(), is("sdn"));
assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03"));
assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is(simpleDateFormat.parse("2014-02-03")));
}
/**
* Checks if include and import can come in any order.
*/
@Test
public void processIncludeImportAnyOrder() throws IOException, ParserException {
public void processIncludeImportAnyOrder() throws IOException, ParserException, ParseException {
YangNode node = manager.getDataModel("src/test/resources/IncludeImportAnyOrder.yang");
// Checks for the sub module name in data model tree.
assertThat(((YangModule) node).getIncludeList().get(0).getSubModuleName(), is("itut"));
assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03"));
assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is(simpleDateFormat.parse("2016-02-03")));
assertThat(((YangModule) node).getIncludeList().get(1).getSubModuleName(), is("sdn"));
assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03"));
assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is(simpleDateFormat.parse("2014-02-03")));
}
/**
......
/*
* 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.parser.impl.listeners;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangMust;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import java.io.IOException;
import java.util.List;
import java.util.ListIterator;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
/**
* Test cases for testing must listener functionality.
*/
public class MustListenerTest {
private final YangUtilsParserManager manager = new YangUtilsParserManager();
/**
* Checks if must listener updates the data model.
*/
@Test
public void processContainerSubStatementMust() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementMust.yang");
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("Test"));
YangContainer yangContainer = (YangContainer) yangNode.getChild();
assertThat(yangContainer.getName(), is("interface"));
String expectedConstraint = "ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)";
List<YangMust> mustConstraintList = yangContainer.getListOfMust();
assertThat(mustConstraintList.iterator().next().getConstraint(), is(expectedConstraint));
}
/**
* Checks if must listener updates the data model.
*/
@Test
public void processLeafSubStatementMust() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/LeafSubStatementMust.yang");
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("Test"));
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getListOfMust().iterator().next().getConstraint(), is("ifType != 'ethernet'"));
}
}
\ No newline at end of file
......@@ -16,14 +16,15 @@
package org.onosproject.yangutils.parser.impl.listeners;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import java.io.IOException;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
......@@ -33,6 +34,8 @@ import static org.junit.Assert.assertThat;
public class RevisionDateListenerTest {
private final YangUtilsParserManager manager = new YangUtilsParserManager();
private static final String DATE_FORMAT = "yyyy-MM-dd";
private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT);
/**
* Checks if revision date syntax is correct in include.
......@@ -56,26 +59,26 @@ public class RevisionDateListenerTest {
* Checks revision date in quotes inside include.
*/
@Test
public void processRevisionDateInQuotesAtInclude() throws IOException, ParserException {
public void processRevisionDateInQuotesAtInclude() throws IOException, ParserException, ParseException {
YangNode node = manager.getDataModel("src/test/resources/RevisionDateInQuotesAtInclude.yang");
// Checks for the version value in data model tree.
assertThat(((YangModule) node).getImportList().get(0).getRevision(), is("2015-02-03"));
assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03"));
assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03"));
assertThat(((YangModule) node).getImportList().get(0).getRevision(), is(simpleDateFormat.parse("2015-02-03")));
assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is(simpleDateFormat.parse("2016-02-03")));
assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is(simpleDateFormat.parse("2014-02-03")));
}
/**
* Checks revision date in quotes inside import.
*/
@Test
public void processRevisionDateInQuotesAtImport() throws IOException, ParserException {
public void processRevisionDateInQuotesAtImport() throws IOException, ParserException, ParseException {
YangNode node = manager.getDataModel("src/test/resources/RevisionDateInQuotesAtImport.yang");
// Checks for the version value in data model tree.
assertThat(((YangModule) node).getImportList().get(0).getRevision(), is("2015-02-03"));
assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03"));
assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03"));
assertThat(((YangModule) node).getImportList().get(0).getRevision(), is(simpleDateFormat.parse("2015-02-03")));
assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is(simpleDateFormat.parse("2016-02-03")));
assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is(simpleDateFormat.parse("2014-02-03")));
}
/**
......@@ -100,13 +103,13 @@ public class RevisionDateListenerTest {
* Checks if revision date listener updates the data model tree.
*/
@Test
public void processRevisionDateValidEntry() throws IOException, ParserException {
public void processRevisionDateValidEntry() throws IOException, ParserException, ParseException {
YangNode node = manager.getDataModel("src/test/resources/RevisionDateValidEntry.yang");
// Checks for the version value in data model tree.
assertThat(((YangModule) node).getImportList().get(0).getRevision(), is("2015-02-03"));
assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03"));
assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03"));
assertThat(((YangModule) node).getImportList().get(0).getRevision(), is(simpleDateFormat.parse("2015-02-03")));
assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is(simpleDateFormat.parse("2016-02-03")));
assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is(simpleDateFormat.parse("2014-02-03")));
}
}
\ No newline at end of file
......
......@@ -16,14 +16,15 @@
package org.onosproject.yangutils.parser.impl.listeners;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import java.io.IOException;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
......@@ -34,18 +35,19 @@ import static org.junit.Assert.assertThat;
public class RevisionListenerTest {
private final YangUtilsParserManager manager = new YangUtilsParserManager();
private static final String DATE_FORMAT = "yyyy-MM-dd";
private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT);
/**
* Checks if revision doesn't have optional parameters "revision and
* description".
*/
@Test
public void processRevisionNoOptionalParameter() throws IOException, ParserException {
public void processRevisionNoOptionalParameter() throws IOException, ParserException, ParseException {
YangNode node = manager.getDataModel("src/test/resources/RevisionNoOptionalParameter.yang");
// Checks for the version value in data model tree.
assertThat(((YangModule) node).getRevision().getRevDate(), is("2016-02-03"));
assertThat(((YangModule) node).getRevision().getRevDate(), is(simpleDateFormat.parse("2016-02-03")));
}
/**
......@@ -75,4 +77,14 @@ public class RevisionListenerTest {
YangNode node = manager.getDataModel("src/test/resources/RevisionAbsence.yang");
assertThat(((YangModule) node).getRevision().getRevDate(), notNullValue());
}
/**
* Checks latest date is stored when there are multiple revisions.
*/
@Test
public void processWithMultipleRevision() throws IOException, ParserException, ParseException {
YangNode node = manager.getDataModel("src/test/resources/MultipleRevision.yang");
assertThat(((YangModule) node).getRevision().getRevDate(), is(simpleDateFormat.parse("2013-07-15")));
}
}
\ No newline at end of file
......
/*
* 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.parser.impl.listeners;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import java.io.IOException;
import java.util.ListIterator;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
/**
* Test cases for testing when listener functionality.
*/
public class WhenListenerTest {
private final YangUtilsParserManager manager = new YangUtilsParserManager();
/**
* Checks if when listener updates the data model.
*/
@Test
public void processContainerSubStatementWhen() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementWhen.yang");
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("Test"));
YangList yangList = (YangList) yangNode.getChild();
assertThat(yangList.getName(), is("interface-switching-capability"));
YangContainer container = (YangContainer) yangList.getNextSibling();
assertThat(container.getName(), is("time-division-multiplex-capable"));
String expectedConstraint = "../switching-capability = 'TDM'";
assertThat(container.getWhen().getCondition(), is(expectedConstraint));
}
/**
* Checks if when listener updates the data model.
*/
@Test
public void processLeafSubStatementWhen() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/LeafSubStatementWhen.yang");
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("Test"));
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getWhen().getCondition(), is("ifType != 'ethernet'"));
}
}
\ No newline at end of file
/*
* 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.plugin.manager;
import java.io.IOException;
import java.util.List;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.YangFeature;
import org.onosproject.yangutils.datamodel.YangIfFeature;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeType;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
/**
* Test cases for testing if-feature intra file linking.
*/
public class IntraFileIfFeatureLinkingTest {
private final YangUtilsParserManager manager = new YangUtilsParserManager();
/**
* Checks self resolution when feature defined in same file.
*/
@Test
public void processSelfFileLinkingWithFeature()
throws IOException, ParserException {
YangNode node = manager
.getDataModel("src/test/resources/SelfFileLinkingWithFeature.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("syslog"));
List<YangFeature> featureList = yangNode.getFeatureList();
YangFeature feature = featureList.iterator().next();
assertThat(feature.getName(), is("local-storage"));
YangContainer container = (YangContainer) yangNode.getChild();
assertThat(container.getName(), is("speed"));
List<YangLeaf> listOfLeaf = container.getListOfLeaf();
YangLeaf leaf = listOfLeaf.iterator().next();
assertThat(leaf.getName(), is("local-storage-limit"));
List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList();
YangIfFeature ifFeature = ifFeatureList.iterator().next();
assertThat(ifFeature.getName().getName(), is("local-storage"));
assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
}
/**
* Checks self resolution when feature is undefined.
*/
@Test
public void processSelfFileLinkingWithFeatureUndefined()
throws IOException, ParserException {
YangNode node = manager
.getDataModel("src/test/resources/SelfFileLinkingWithFeatureUndefined.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("syslog"));
YangContainer container = (YangContainer) yangNode.getChild();
assertThat(container.getName(), is("speed"));
List<YangLeaf> listOfLeaf = container.getListOfLeaf();
YangLeaf leaf = listOfLeaf.iterator().next();
assertThat(leaf.getName(), is("local-storage-limit"));
List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList();
YangIfFeature ifFeature = ifFeatureList.iterator().next();
assertThat(ifFeature.getName().getName(), is("local-storage"));
assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.INTRA_FILE_RESOLVED));
}
/**
* Checks self resolution of feature with multiple dependency.
*/
@Test
public void processSelfFileLinkingWithMultipleDependency() throws IOException, ParserException {
YangNode node = manager
.getDataModel("src/test/resources/SelfFileLinkingWithMultipleDependency.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("syslog"));
List<YangFeature> featureList = yangNode.getFeatureList();
YangFeature feature = featureList.iterator().next();
assertThat(feature.getName(), is("p2mp-te"));
YangContainer container = (YangContainer) yangNode.getChild();
assertThat(container.getName(), is("speed"));
List<YangLeaf> listOfLeaf = container.getListOfLeaf();
YangLeaf leaf = listOfLeaf.iterator().next();
assertThat(leaf.getName(), is("local-storage-limit"));
List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList();
YangIfFeature ifFeature = ifFeatureList.iterator().next();
assertThat(ifFeature.getName().getName(), is("frr-te"));
assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
}
/**
* Checks self resolution of feature with multiple dependency undefined.
*/
@Test
public void processSelfFileLinkingWithMultipleDependencyUnresolved() throws IOException, ParserException {
YangNode node = manager
.getDataModel("src/test/resources/SelfFileLinkingWithMultipleDependencyUnresolved.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("syslog"));
List<YangFeature> featureList = yangNode.getFeatureList();
YangFeature feature = featureList.iterator().next();
assertThat(feature.getName(), is("frr-te"));
YangContainer container = (YangContainer) yangNode.getChild();
assertThat(container.getName(), is("speed"));
List<YangLeaf> listOfLeaf = container.getListOfLeaf();
YangLeaf leaf = listOfLeaf.iterator().next();
assertThat(leaf.getName(), is("local-storage-limit"));
List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList();
YangIfFeature ifFeature = ifFeatureList.iterator().next();
assertThat(ifFeature.getName().getName(), is("frr-te"));
assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.INTRA_FILE_RESOLVED));
}
/**
* Checks self resolution when feature is defined in same file in submodule.
*/
@Test
public void processSelfFileLinkingWithFeatureInSubModule()
throws IOException, ParserException {
YangNode node = manager
.getDataModel("src/test/resources/SelfFileLinkingWithFeatureInSubModule.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangSubModule), is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.SUB_MODULE_NODE));
// Check whether the module name is set correctly.
YangSubModule yangNode = (YangSubModule) node;
assertThat(yangNode.getName(), is("syslog"));
List<YangFeature> featureList = yangNode.getFeatureList();
YangFeature feature = featureList.iterator().next();
assertThat(feature.getName(), is("local-storage"));
YangContainer container = (YangContainer) yangNode.getChild();
assertThat(container.getName(), is("speed"));
List<YangLeaf> listOfLeaf = container.getListOfLeaf();
YangLeaf leaf = listOfLeaf.iterator().next();
assertThat(leaf.getName(), is("local-storage-limit"));
List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList();
YangIfFeature ifFeature = ifFeatureList.iterator().next();
assertThat(ifFeature.getName().getName(), is("local-storage"));
assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
}
}
......@@ -20,6 +20,9 @@ import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
......@@ -104,6 +107,8 @@ public final class JavaIdentifierSyntaxTest {
private static final String WITH_SMALL = "test_this";
private static final String WITH_CAMEL_CASE_WITH_PREFIX = "123addPrefixTry";
private static final String WITH_CAMEL_CASE_WITH_PREFIX1 = "abc1234567890Ss1123G123Gaa";
private static final String DATE_FORMAT = "yyyy-MM-dd";
private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT);
private static YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil();
private static final String BASE_DIR_PKG = "target.UnitTestCase.";
private static final String DIR_PATH = "exist1.exist2.exist3";
......@@ -140,9 +145,10 @@ public final class JavaIdentifierSyntaxTest {
* Unit test for root package generation with revision complexity.
*/
@Test
public void getRootPackageTest() {
public void getRootPackageTest() throws ParseException {
conflictResolver.setPrefixForIdentifier(null);
String rootPackage = getRootPackage((byte) 1, CHILD_PACKAGE, DATE1, conflictResolver);
Date date = simpleDateFormat.parse(DATE1);
String rootPackage = getRootPackage((byte) 1, CHILD_PACKAGE, date, conflictResolver);
assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
+ PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV1), is(true));
}
......@@ -151,31 +157,34 @@ public final class JavaIdentifierSyntaxTest {
* Unit test for root package generation with invalid prefix.
*/
@Test
public void getRootPackageWithInvalidPrefix() throws TranslatorException {
public void getRootPackageWithInvalidPrefix() throws TranslatorException, ParseException {
thrown.expect(TranslatorException.class);
thrown.expectMessage("The given prefix in pom.xml is invalid.");
conflictResolver.setPrefixForIdentifier(INVALID_PREFIX);
String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE_FOR_INVALID_PREFIX, DATE1, conflictResolver);
Date date = simpleDateFormat.parse(DATE1);
String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE_FOR_INVALID_PREFIX, date,
conflictResolver);
}
/**
* Unit test for root package generation with special characters presence.
*/
@Test
public void getRootPackageWithSpecialCharactersTest() {
public void getRootPackageWithSpecialCharactersTest() throws ParseException {
conflictResolver.setPrefixForIdentifier(VALID_PREFIX);
String rootPackage = getRootPackage((byte) 1, INVALID_NAME_SPACE1, DATE1, conflictResolver);
Date date = simpleDateFormat.parse(DATE1);
String rootPackage = getRootPackage((byte) 1, INVALID_NAME_SPACE1, date, conflictResolver);
assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
+ PERIOD + VALID_NAME_SPACE1 + PERIOD + DATE_WITH_REV1), is(true));
conflictResolver.setPrefixForIdentifier(null);
String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, DATE1, conflictResolver);
String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, date, conflictResolver);
assertThat(rootPackage1.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
+ PERIOD + VALID_NAME_SPACE2 + PERIOD + DATE_WITH_REV1), is(true));
String rootPackage2 = getRootPackage((byte) 1, INVALID_NAME_SPACE3, DATE1, conflictResolver);
String rootPackage2 = getRootPackage((byte) 1, INVALID_NAME_SPACE3, date, conflictResolver);
assertThat(rootPackage2.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
+ PERIOD + VALID_NAME_SPACE4 + PERIOD + DATE_WITH_REV1), is(true));
conflictResolver.setPrefixForIdentifier(INVALID_PREFIX1);
String rootPackage3 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, DATE1, conflictResolver);
String rootPackage3 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, date, conflictResolver);
assertThat(rootPackage3.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
+ PERIOD + VALID_NAME_SPACE3 + PERIOD + DATE_WITH_REV1), is(true));
......@@ -185,8 +194,9 @@ public final class JavaIdentifierSyntaxTest {
* Unit test for root package generation without complexity in revision.
*/
@Test
public void getRootPackageWithRevTest() {
String rootPkgWithRev = getRootPackage((byte) 1, CHILD_PACKAGE, DATE2, null);
public void getRootPackageWithRevTest() throws ParseException {
Date date = simpleDateFormat.parse(DATE2);
String rootPkgWithRev = getRootPackage((byte) 1, CHILD_PACKAGE, date, null);
assertThat(rootPkgWithRev.equals(
DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV2),
is(true));
......
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
container interface {
leaf ifType {
type enumeration {
enum ethernet;
enum atm;
}
}
leaf ifMTU {
type uint32;
}
must "ifType != 'ethernet' or " +
"(ifType = 'ethernet' and ifMTU = 1500)" {
description "An ethernet MTU must be 1500";
}
must "ifType != 'atm' or " +
"(ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)" {
description "An atm MTU must be 64 .. 17966";
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
list interface-switching-capability {
key "switching-capability";
description
"List of Interface Switching Capabilities Descriptors (ISCD)
for this link.";
reference
"RFC3471: Generalized Multi-Protocol Label Switching (GMPLS)
Signaling Functional Description.
RFC4203: OSPF Extensions in Support of Generalized
Multi-Protocol Label Switching (GMPLS).";
leaf switching-capability {
type string;
description
"Switching Capability for this interface.";
}
}
container time-division-multiplex-capable {
when "../switching-capability = 'TDM'" {
description "Valid only for TDM";
}
description
"Interface has time-division multiplex capabilities.";
leaf minimum-lsp-bandwidth {
type decimal64;
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
leaf ifType {
type enumeration {
enum ethernet;
enum atm;
}
must "ifType != 'ethernet'" {
description "ifType is not ethernet";
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
leaf ifType {
when "ifType != 'ethernet'" {
description "ifType is not ethernet";
}
type enumeration {
enum ethernet;
enum atm;
}
}
}
module Test {
yang-version 1;
namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
prefix test;
revision 2013-07-15 {
description
"This revision adds the following new data types:
- yang-identifier
- hex-string
- uuid
- dotted-quad";
reference
"RFC 6991: Common YANG Data Types";
}
revision 2013-07-14 {
description
"This revision adds the following new data types:
- yang-identifier
- hex-string
- uuid
- dotted-quad";
reference
"RFC 6991: Common YANG Data Types";
}
}
module syslog {
yang-version 1;
namespace http://huawei.com;
prefix "sys";
feature local-storage {
description
"This feature means the device supports local
storage (memory, flash or disk) that can be used to
store syslog messages.";
}
container speed {
leaf local-storage-limit {
if-feature local-storage;
type uint64;
units "kilobyte";
config false;
description
"The amount of local storage that can be
used to hold syslog messages.";
}
}
}
submodule syslog {
yang-version 1;
belongs-to "syslog1" {
prefix "sys";
}
feature local-storage {
description
"This feature means the device supports local
storage (memory, flash or disk) that can be used to
store syslog messages.";
}
container speed {
leaf local-storage-limit {
if-feature local-storage;
type uint64;
units "kilobyte";
config false;
description
"The amount of local storage that can be
used to hold syslog messages.";
}
}
}
module syslog {
yang-version 1;
namespace http://huawei.com;
prefix "sys";
container speed {
leaf local-storage-limit {
if-feature local-storage;
type uint64;
units "kilobyte";
config false;
description
"The amount of local storage that can be
used to hold syslog messages.";
}
}
}
module syslog {
yang-version 1;
namespace http://huawei.com;
prefix "sys";
feature p2mp-te {
description "Indicates support for P2MP-TE";
}
feature frr-te {
description "Indicates support for TE FastReroute (FRR)";
if-feature p2mp-te;
}
container speed {
leaf local-storage-limit {
if-feature frr-te;
type uint64;
units "kilobyte";
config false;
description
"The amount of local storage that can be
used to hold syslog messages.";
}
}
}
module syslog {
yang-version 1;
namespace http://huawei.com;
prefix "sys";
feature frr-te {
description "Indicates support for TE FastReroute (FRR)";
if-feature p2mp-te;
}
container speed {
leaf local-storage-limit {
if-feature frr-te;
type uint64;
units "kilobyte";
config false;
description
"The amount of local storage that can be
used to hold syslog messages.";
}
}
}
module syslog {
yang-version 1;
namespace http://huawei.com;
prefix "sys";
feature p2mp-te {
description "Indicates support for P2MP-TE";
}
feature frr-te {
description "Indicates support for TE FastReroute (FRR)";
if-feature p2mp-te;
}
container speed {
leaf local-storage-limit {
if-feature local-storage;
type uint64;
units "kilobyte";
config false;
description
"The amount of local storage that can be
used to hold syslog messages.";
}
}
}
module syslog1 {
yang-version 1;
namespace "http://huawei1.com";
prefix "sys1";
import "syslog2" {
prefix "sys2";
}
feature frr-te {
description "Indicates support for TE FastReroute (FRR)";
if-feature "sys2:p2mp-te";
}
container speed {
leaf local-storage-limit {
if-feature frr-te;
type uint64;
units "kilobyte";
config false;
description
"The amount of local storage that can be
used to hold syslog messages.";
}
}
}
module syslog2 {
yang-version 1;
namespace "http://huawei2.com";
prefix "sys2";
feature p2mp-te {
description "Indicates support for P2MP-TE";
}
}
module syslog1 {
yang-version 1;
namespace "http://huawei1.com";
prefix "sys1";
import "syslog2" {
prefix "sys2";
}
feature frr-te {
description "Indicates support for TE FastReroute (FRR)";
if-feature "sys2:p2mp-te";
}
container speed {
leaf local-storage-limit {
if-feature frr-te;
type uint64;
units "kilobyte";
config false;
description
"The amount of local storage that can be
used to hold syslog messages.";
}
}
}
module syslog2 {
yang-version 1;
namespace "http://huawei2.com";
prefix "sys2";
import "syslog3" {
prefix "sys3";
}
feature p2mp-te {
description "Indicates support for P2MP-TE";
if-feature "sys3:extended-admin-groups";
}
}
module syslog3 {
yang-version 1;
namespace "http://huawei3.com";
prefix "sys3";
feature extended-admin-groups {
description
"Indicates support for TE link extended admin
groups.";
}
}
module syslog1 {
yang-version 1;
namespace "http://huawei1.com";
prefix "sys1";
import "syslog2" {
prefix "sys2";
}
feature frr-te {
description "Indicates support for TE FastReroute (FRR)";
if-feature "sys2:p2mp-te";
}
container speed {
leaf local-storage-limit {
if-feature frr-te;
type uint64;
units "kilobyte";
config false;
description
"The amount of local storage that can be
used to hold syslog messages.";
}
}
}
module syslog2 {
yang-version 1;
namespace "http://huawei2.com";
prefix "sys2";
import "syslog3" {
prefix "sys3";
}
feature p2mp-te {
description "Indicates support for P2MP-TE";
if-feature "sys3:extended-admin-groups";
}
}
module syslog3 {
yang-version 1;
namespace "http://huawei3.com";
prefix "sys3";
}
module syslog3 {
yang-version 1;
namespace "http://huawei3.com";
prefix "sys3";
include "syslog4";
feature frr-te {
description "Indicates support for TE FastReroute (FRR)";
if-feature "p2mp-te";
}
container speed {
leaf local-storage-limit {
if-feature frr-te;
type uint64;
units "kilobyte";
config false;
description
"The amount of local storage that can be
used to hold syslog messages.";
}
}
}
submodule syslog4 {
yang-version 1;
belongs-to "syslog3" {
prefix "sys3";
}
feature p2mp-te {
description "Indicates support for P2MP-TE";
}
}
module syslog1 {
yang-version 1;
namespace "http://huawei3.com";
prefix "sys1";
include "syslog2";
feature frr-te {
description "Indicates support for TE FastReroute (FRR)";
if-feature "p2mp-te";
}
container speed {
leaf local-storage-limit {
if-feature frr-te;
type uint64;
units "kilobyte";
config false;
description
"The amount of local storage that can be
used to hold syslog messages.";
}
}
}
submodule syslog2 {
yang-version 1;
belongs-to "syslog1" {
prefix "sys1";
}
import "syslog3" {
prefix "sys3";
}
feature p2mp-te {
description "Indicates support for P2MP-TE";
if-feature "sys3:extended-admin-groups";
}
}
module syslog3 {
yang-version 1;
namespace "http://huawei3.com";
prefix "sys3";
feature extended-admin-groups {
description
"Indicates support for TE link extended admin
groups.";
}
}
module syslog1 {
yang-version 1;
namespace "http://huawei3.com";
prefix "sys1";
include "syslog2";
feature frr-te {
description "Indicates support for TE FastReroute (FRR)";
if-feature "p2mp-te";
}
container speed {
leaf local-storage-limit {
if-feature frr-te;
type uint64;
units "kilobyte";
config false;
description
"The amount of local storage that can be
used to hold syslog messages.";
}
}
}
submodule syslog2 {
yang-version 1;
belongs-to "syslog1" {
prefix "sys1";
}
import "syslog3" {
prefix "sys3";
}
feature p2mp-te {
description "Indicates support for P2MP-TE";
if-feature "sys3:extended-admin-groups";
}
}
module syslog3 {
yang-version 1;
namespace "http://huawei3.com";
prefix "sys3";
}
......@@ -68,7 +68,7 @@
* Features
*/
/*feature configuration-schedule {
feature configuration-schedule {
description
"This feature indicates that the system supports
configuration scheduling.";
......@@ -91,7 +91,7 @@
description
"This feature indicates that the system supports
template configuration.";
}*/
}
/*
* Typedefs
......
......@@ -257,7 +257,7 @@
}*/
/* TE basic features */
/*feature p2mp-te {
feature p2mp-te {
description
"Indicates support for P2MP-TE";
}
......@@ -291,7 +291,7 @@
feature named-path-constraints {
description
"Indicates support for named path constraints";
}*/
}
grouping explicit-route-subobject {
description
......