Gaurav Agrawal
Committed by Gerrit Code Review

[ONOS-4063 to 68] Intra YANG file Linking Implementation and Intra YANG file Linking Framework

Change-Id: I06e602c351ab54178bf90b8676af71a70e42371f
Showing 58 changed files with 1138 additions and 421 deletions
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.datamodel;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
/**
* Abstraction of YANG dependency resolution information. Abstracted to obtain the
* resolution information.
*/
public interface HasResolutionInfo {
/**
* Returns unresolved resolution list.
*
* @return unresolved resolution list
*/
List<YangResolutionInfo> getUnresolvedResolutionList();
/**
* Add to the resolution list.
*
* @param resolutionInfo resolution information
*/
void addToResolutionList(YangResolutionInfo resolutionInfo);
/**
* Creates resolution list.
*
* @param resolutionList resolution list
*/
void setResolutionList(List<YangResolutionInfo> resolutionList);
/**
* Returns unresolved imported list.
*
* @return unresolved imported list
*/
List<YangImport> getImportList();
/**
* Add to the import list.
*
* @param yangImport import to be added
*/
void addToImportList(YangImport yangImport);
/**
* Create import list.
*
* @param importList import list
*/
void setImportList(List<YangImport> importList);
/**
* Returns unresolved include list.
*
* @return unresolved include list
*/
List<YangInclude> getIncludeList();
/**
* Add to the include list.
*
* @param yangInclude include to be added
*/
void addToIncludeList(YangInclude yangInclude);
/**
* Create include list.
*
* @param includeList include list
*/
void setIncludeList(List<YangInclude> includeList);
/**
* Returns prefix of resolution root node.
*
* @return prefix resolution root node prefix
*/
String getPrefix();
/**
* Set prefix of resolution list root node.
*
* @param prefix resolution root node prefix
*/
void setPrefix(String prefix);
/**
* Resolve self file linking.
*
* @throws DataModelException a violation in data model rule
*/
void resolveSelfFileLinking() throws DataModelException;
}
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.datamodel;
/**
* ENUM to identify the YANG resolution type.
*/
public enum ResolutionType {
/**
* Identifies that resolution is for typedef.
*/
TYPEDEF_RESOLUTION,
/**
* Identifies that resolution is for grouping.
*/
GROUPING_RESOLUTION;
}
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.datamodel;
/**
* Abstraction of YANG resolvable information. Abstracted to obtain the
* information required for linking resolution.
*/
public interface Resolvable {
/**
* Returns the status of resolution. If completely resolved returns enum
* value "RESOLVED", if not returns "UNRESOLVED", in case reference of
* grouping/typedef is added to uses/type but it's not resolved
* "PARTIALLY_RESOLVED" is returned.
*
* @return status of resolution
*/
ResolvableStatus getResolvableStatus();
/**
* Set the status of type/uses resolution. If completely resolved set enum
* value "RESOLVED", if not set it to "UNRESOLVED", in case reference of
* grouping/typedef is added to uses/type but it's not resolved
* "PARTIALLY_RESOLVED" should be set.
*
* @param resolvableStatus status of resolution
*/
void setResolvableStatus(ResolvableStatus resolvableStatus);
/**
* Resolves the linking.
*/
void resolve();
}
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.datamodel;
/**
* Represents the status of resolvable entity.
*/
public enum ResolvableStatus {
/**
* Identifies that resolvable entity is resolved.
*/
RESOLVED,
/**
* Identifies that resolvable entity is unresolved.
*/
UNRESOLVED,
/**
* Identifies that resolvable entity is partially resolved.
*/
PARTIALLY_RESOLVED;
}
......@@ -16,112 +16,83 @@
package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
/*-
* Reference RFC 6020.
*
* The typedef Statement
*
* The "typedef" statement defines a new type that may be used locally
* in the module, in modules or submodules which include it, and by
* other modules that import from it. The new type is called the
* "derived type", and the type from which it was derived is called
* the "base type". All derived types can be traced back to a YANG
* built-in type.
*
* The "typedef" statement's argument is an identifier that is the name
* of the type to be defined, and MUST be followed by a block of
* sub-statements that holds detailed typedef information.
*
* The name of the type MUST NOT be one of the YANG built-in types. If
* the typedef is defined at the top level of a YANG module or
* submodule, the name of the type to be defined MUST be unique within
* the module.
*/
/**
* Derived type information.
* Maintains the derived information.
*
* @param <T> extended information.
*/
public class YangDerivedType implements Parsable {
public class YangDerivedInfo<T> {
/**
* All derived types can be traced back to a YANG built-in type.
* YANG typedef reference.
*/
private YangDataTypes effectiveYangBuiltInType;
private YangTypeDef referredTypeDef;
/**
* Base type from which the current type is derived.
* Resolved additional information about data type after linking, example
* restriction info, named values, etc. The extra information is based
* on the data type. Based on the data type, the extended info can vary.
*/
private YangType<?> baseType;
private T resolvedExtendedInfo;
/**
* Default constructor.
* Additional information about data type, example restriction info, named
* values, etc. The extra information is based on the data type. Based on
* the data type, the extended info can vary.
*/
public YangDerivedType() {
}
private T extendedInfo;
/**
* Get the effective YANG built-in type of the derived data type.
* Returns the referred typedef reference.
*
* @return effective YANG built-in type of the derived data type
* @return referred typedef reference
*/
public YangDataTypes getEffectiveYangBuiltInType() {
return effectiveYangBuiltInType;
public YangTypeDef getReferredTypeDef() {
return referredTypeDef;
}
/**
* Set the effective YANG built-in type of the derived data type.
* Set the referred typedef reference.
*
* @param builtInType effective YANG built-in type of the derived data type
* @param referredTypeDef referred typedef reference
*/
public void setEffectiveYangBuiltInType(YangDataTypes builtInType) {
effectiveYangBuiltInType = builtInType;
public void setReferredTypeDef(YangTypeDef referredTypeDef) {
this.referredTypeDef = referredTypeDef;
}
/**
* Get the base type information.
* Returns resolved extended information after successful linking.
*
* @return base type information
* @return resolved extended information
*/
public YangType<?> getBaseType() {
return baseType;
public T getResolvedExtendedInfo() {
return resolvedExtendedInfo;
}
/**
* Get the base type information.
* Set resolved extended information after successful linking.
*
* @param baseType base type information
* @param resolvedExtendedInfo resolved extended information
*/
public void setBaseType(YangType<?> baseType) {
this.baseType = baseType;
public void setResolvedExtendedInfo(T resolvedExtendedInfo) {
this.resolvedExtendedInfo = resolvedExtendedInfo;
}
/**
* Get the parsable type.
*/
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.DERIVED;
}
/**
* TODO.
* Returns extended information.
*
* @return extended information
*/
@Override
public void validateDataOnEntry() throws DataModelException {
// TODO Auto-generated method stub
public T getExtendedInfo() {
return extendedInfo;
}
/**
* TODO.
* Set extended information.
*
* @param extendedInfo extended information
*/
@Override
public void validateDataOnExit() throws DataModelException {
// TODO Auto-generated method stub
public void setExtendedInfo(T extendedInfo) {
this.extendedInfo = extendedInfo;
}
}
......
......@@ -75,6 +75,11 @@ public class YangImport implements Parsable {
private String prefixId;
/**
* Resolution information root node which is also the data model root node.
*/
private HasResolutionInfo resolutionInfoNode;
/**
* Reference:RFC 6020.
*
* The import's "revision-date" statement is used to specify the exact
......@@ -177,4 +182,22 @@ public class YangImport implements Parsable {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Returns the resolution information node.
*
* @return the resolution information node
*/
public HasResolutionInfo getResolutionInfoNode() {
return resolutionInfoNode;
}
/**
* Set the dresolution information node.
*
* @param resolutionInfoNode the resolution information node
*/
public void setResolutionInfoNode(HasResolutionInfo resolutionInfoNode) {
this.resolutionInfoNode = resolutionInfoNode;
}
}
......
......@@ -51,6 +51,11 @@ public class YangInclude implements Parsable {
private String revision;
/**
* Resolution information root node which is also the data model root node.
*/
private HasResolutionInfo resolutionInfoNode;
/**
* Default constructor.
*/
public YangInclude() {
......@@ -124,4 +129,21 @@ public class YangInclude implements Parsable {
}
/**
* Returns the resolution information node.
*
* @return the resolution information node
*/
public HasResolutionInfo getResolutionInfoNode() {
return resolutionInfoNode;
}
/**
* Set the dresolution information node.
*
* @param resolutionInfoNode the resolution information node
*/
public void setResolutionInfoNode(HasResolutionInfo resolutionInfoNode) {
this.resolutionInfoNode = resolutionInfoNode;
}
}
......
......@@ -17,12 +17,12 @@ package org.onosproject.yangutils.datamodel;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLinkingForResolutionList;
/*-
* Reference:RFC 6020.
......@@ -68,7 +68,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
* Data model node to maintain information defined in YANG module.
*/
public class YangModule extends YangNode
implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector {
implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, HasResolutionInfo {
/**
* Name of the module.
......@@ -185,16 +185,19 @@ public class YangModule extends YangNode
* matching "typedef" or "grouping" statement among the immediate
* sub-statements of each ancestor statement.
*/
/**
* List of nodes which require nested reference resolution.
*/
private List<YangNode> nestedReferenceResoulutionList;
private List<YangResolutionInfo> unresolvedResolutionList;
/**
* Create a YANG node of module type.
*/
public YangModule() {
super(YangNodeType.MODULE_NODE);
unresolvedResolutionList = new LinkedList<YangResolutionInfo>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
listOfLeafList = new LinkedList<YangLeafList>();
}
/**
......@@ -265,28 +268,17 @@ public class YangModule extends YangNode
}
/**
* prevent setting the import list from outside.
*
* @param importList the import list to set
*/
private void setImportList(List<YangImport> importList) {
this.importList = importList;
}
/**
* Add the imported module information to the import list.
*
* @param importedModule module being imported
*/
public void addImportedInfo(YangImport importedModule) {
if (getImportList() == null) {
setImportList(new LinkedList<YangImport>());
}
public void addToImportList(YangImport importedModule) {
getImportList().add(importedModule);
}
return;
@Override
public void setImportList(List<YangImport> importList) {
this.importList = importList;
}
/**
......@@ -299,27 +291,17 @@ public class YangModule extends YangNode
}
/**
* Set the list of included sub modules.
*
* @param includeList the included list to set
*/
private void setIncludeList(List<YangInclude> includeList) {
this.includeList = includeList;
}
/**
* Add the included sub module information to the include list.
*
* @param includeModule submodule being included
*/
public void addIncludedInfo(YangInclude includeModule) {
if (getIncludeList() == null) {
setIncludeList(new LinkedList<YangInclude>());
}
public void addToIncludeList(YangInclude includeModule) {
getIncludeList().add(includeModule);
return;
}
@Override
public void setIncludeList(List<YangInclude> includeList) {
this.includeList = includeList;
}
/**
......@@ -333,25 +315,12 @@ public class YangModule extends YangNode
}
/**
* Set the list of leaf in module.
*
* @param leafsList the list of leaf to set
*/
private void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
}
/**
* Add a leaf in module.
*
* @param leaf the leaf to be added
*/
@Override
public void addLeaf(YangLeaf leaf) {
if (getListOfLeaf() == null) {
setListOfLeaf(new LinkedList<YangLeaf>());
}
getListOfLeaf().add(leaf);
}
......@@ -366,25 +335,12 @@ public class YangModule extends YangNode
}
/**
* Set the list of leaf-list in module.
*
* @param listOfLeafList the list of leaf-list to set
*/
private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
}
/**
* Add a leaf-list in module.
*
* @param leafList the leaf-list to be added
*/
@Override
public void addLeafList(YangLeafList leafList) {
if (getListOfLeafList() == null) {
setListOfLeafList(new LinkedList<YangLeafList>());
}
getListOfLeafList().add(leafList);
}
......@@ -442,6 +398,14 @@ public class YangModule extends YangNode
this.prefix = prefix;
}
@Override
public void resolveSelfFileLinking() throws DataModelException {
// Get the list to be resolved.
List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList();
// Resolve linking for a resolution list.
resolveLinkingForResolutionList(resolutionList, this);
}
/**
* Get the textual reference.
*
......@@ -499,37 +463,6 @@ public class YangModule extends YangNode
}
/**
* Get the list of nested reference's which required resolution.
*
* @return list of nested reference's which required resolution
*/
public List<YangNode> getNestedReferenceResoulutionList() {
return nestedReferenceResoulutionList;
}
/**
* Set list of nested reference's which requires resolution.
*
* @param nestedReferenceResoulutionList list of nested reference's which
* requires resolution
*/
private void setNestedReferenceResoulutionList(List<YangNode> nestedReferenceResoulutionList) {
this.nestedReferenceResoulutionList = nestedReferenceResoulutionList;
}
/**
* Set list of nested reference's which requires resolution.
*
* @param nestedReference nested reference which requires resolution
*/
public void addToNestedReferenceResoulutionList(YangNode nestedReference) {
if (getNestedReferenceResoulutionList() == null) {
setNestedReferenceResoulutionList(new LinkedList<YangNode>());
}
getNestedReferenceResoulutionList().add(nestedReference);
}
/**
* Returns the type of the parsed data.
*
* @return returns MODULE_DATA
......@@ -565,31 +498,6 @@ public class YangModule extends YangNode
*/
}
/**
* Add a type to resolve the nested references.
*
* @param node grouping or typedef node which needs to be resolved
* @throws DataModelException data model exception
*/
public static void addToResolveList(YangNode node) throws DataModelException {
/* get the module node to add maintain the list of nested reference */
YangModule module;
YangNode curNode = node;
while (curNode.getNodeType() != YangNodeType.MODULE_NODE) {
curNode = curNode.getParent();
if (curNode == null) {
break;
}
}
if (curNode == null) {
throw new DataModelException("Datamodel tree is not correct");
}
module = (YangModule) curNode;
module.addToNestedReferenceResoulutionList(node);
return;
}
@Override
public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
// Asks helper to detect colliding child.
......@@ -601,4 +509,18 @@ public class YangModule extends YangNode
// Not required as module doesn't have any parent.
}
@Override
public List<YangResolutionInfo> getUnresolvedResolutionList() {
return unresolvedResolutionList;
}
@Override
public void addToResolutionList(YangResolutionInfo resolutionInfo) {
unresolvedResolutionList.add(resolutionInfo);
}
@Override
public void setResolutionList(List<YangResolutionInfo> resolutionList) {
unresolvedResolutionList = resolutionList;
}
}
......
......@@ -45,7 +45,7 @@ public class YangNodeIdentifier {
/**
* Set name of the node identifier.
*
* @param name node identifier name
* @param name name of the node identifier
*/
public void setName(String name) {
this.name = name;
......@@ -54,7 +54,7 @@ public class YangNodeIdentifier {
/**
* Returns prefix of the node identifier.
*
* @return prefix of the node identifier
* @return name of the node identifier
*/
public String getPrefix() {
return prefix;
......
......@@ -17,12 +17,12 @@ package org.onosproject.yangutils.datamodel;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLinkingForResolutionList;
/*
* Reference RFC 6020.
......@@ -75,7 +75,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
* Data model node to maintain information defined in YANG sub-module.
*/
public class YangSubModule extends YangNode
implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector {
implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, HasResolutionInfo {
/**
* Name of sub module.
......@@ -124,17 +124,17 @@ public class YangSubModule extends YangNode
private List<YangLeafList> listOfLeafList;
/**
* organization owner of the sub-module.
* Organization owner of the sub-module.
*/
private String organization;
/**
* reference of the sub-module.
* Reference of the sub-module.
*/
private String reference;
/**
* revision info of the sub-module.
* Revision info of the sub-module.
*/
private YangRevision revision;
......@@ -144,10 +144,54 @@ public class YangSubModule extends YangNode
private byte version;
/**
* Prefix of parent module.
*/
private String prefix;
/*-
* Reference RFC 6020.
*
* Nested typedefs and groupings.
* Typedefs and groupings may appear nested under many YANG statements,
* allowing these to be lexically scoped by the hierarchy under which
* they appear. This allows types and groupings to be defined near
* where they are used, rather than placing them at the top level of the
* hierarchy. The close proximity increases readability.
*
* Scoping also allows types to be defined without concern for naming
* conflicts between types in different submodules. Type names can be
* specified without adding leading strings designed to prevent name
* collisions within large modules.
*
* Finally, scoping allows the module author to keep types and groupings
* private to their module or submodule, preventing their reuse. Since
* only top-level types and groupings (i.e., those appearing as
* sub-statements to a module or submodule statement) can be used outside
* the module or submodule, the developer has more control over what
* pieces of their module are presented to the outside world, supporting
* the need to hide internal information and maintaining a boundary
* between what is shared with the outside world and what is kept
* private.
*
* Scoped definitions MUST NOT shadow definitions at a higher scope. A
* type or grouping cannot be defined if a higher level in the schema
* hierarchy has a definition with a matching identifier.
*
* A reference to an unprefixed type or grouping, or one which uses the
* prefix of the current module, is resolved by locating the closest
* matching "typedef" or "grouping" statement among the immediate
* sub-statements of each ancestor statement.
*/
private List<YangResolutionInfo> unresolvedResolutionList;
/**
* Create a sub module node.
*/
public YangSubModule() {
super(YangNodeType.SUB_MODULE_NODE);
unresolvedResolutionList = new LinkedList<YangResolutionInfo>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
listOfLeafList = new LinkedList<YangLeafList>();
}
/**
......@@ -236,28 +280,17 @@ public class YangSubModule extends YangNode
}
/**
* prevent setting the import list from outside.
*
* @param importList the import list to set
*/
private void setImportList(List<YangImport> importList) {
this.importList = importList;
}
/**
* Add the imported module information to the import list.
*
* @param importedModule module being imported
*/
public void addImportedInfo(YangImport importedModule) {
if (getImportList() == null) {
setImportList(new LinkedList<YangImport>());
}
public void addToImportList(YangImport importedModule) {
getImportList().add(importedModule);
}
return;
@Override
public void setImportList(List<YangImport> importList) {
this.importList = importList;
}
/**
......@@ -270,27 +303,35 @@ public class YangSubModule extends YangNode
}
/**
* Set the list of included sub modules.
* Add the included sub module information to the include list.
*
* @param includeList the included list to set
* @param includeModule submodule being included
*/
private void setIncludeList(List<YangInclude> includeList) {
public void addToIncludeList(YangInclude includeModule) {
getIncludeList().add(includeModule);
}
@Override
public void setIncludeList(List<YangInclude> includeList) {
this.includeList = includeList;
}
/**
* Add the included sub module information to the include list.
*
* @param includeModule submodule being included
*/
public void addIncludedInfo(YangInclude includeModule) {
@Override
public String getPrefix() {
return prefix;
}
if (getIncludeList() == null) {
setIncludeList(new LinkedList<YangInclude>());
}
@Override
public void setPrefix(String prefix) {
this.prefix = prefix;
}
getIncludeList().add(includeModule);
return;
@Override
public void resolveSelfFileLinking() throws DataModelException {
// Get the list to be resolved.
List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList();
// Resolve linking for a resolution list.
resolveLinkingForResolutionList(resolutionList, this);
}
/**
......@@ -304,25 +345,12 @@ public class YangSubModule extends YangNode
}
/**
* Set the list of leaves.
*
* @param leafsList the list of leaf to set
*/
private void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
}
/**
* Add a leaf.
*
* @param leaf the leaf to be added
*/
@Override
public void addLeaf(YangLeaf leaf) {
if (getListOfLeaf() == null) {
setListOfLeaf(new LinkedList<YangLeaf>());
}
getListOfLeaf().add(leaf);
}
......@@ -337,25 +365,12 @@ public class YangSubModule extends YangNode
}
/**
* Set the list of leaf-list.
*
* @param listOfLeafList the list of leaf-list to set
*/
private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
}
/**
* Add a leaf-list.
*
* @param leafList the leaf-list to be added
*/
@Override
public void addLeafList(YangLeafList leafList) {
if (getListOfLeafList() == null) {
setListOfLeafList(new LinkedList<YangLeafList>());
}
getListOfLeafList().add(leafList);
}
......@@ -473,4 +488,19 @@ public class YangSubModule extends YangNode
public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
// Not required as module doesn't have any parent.
}
@Override
public List<YangResolutionInfo> getUnresolvedResolutionList() {
return unresolvedResolutionList;
}
@Override
public void addToResolutionList(YangResolutionInfo resolutionInfo) {
this.unresolvedResolutionList.add(resolutionInfo);
}
@Override
public void setResolutionList(List<YangResolutionInfo> resolutionList) {
this.unresolvedResolutionList = resolutionList;
}
}
......
......@@ -49,12 +49,12 @@ import org.onosproject.yangutils.utils.YangConstructType;
*
* @param <T> YANG data type info
*/
public class YangType<T> implements Parsable {
public class YangType<T> implements Parsable, Resolvable {
/**
* YANG data type name.
* YANG node identifier.
*/
private String dataTypeName;
private YangNodeIdentifier nodeIdentifier;
/**
* Java package in which the Java type is defined.
......@@ -74,9 +74,50 @@ public class YangType<T> implements Parsable {
private T dataTypeExtendedInfo;
/**
* Effective built-in type, requried in case type of typedef is again a
* derived type. This information is to be added during linking.
*/
private YangDataTypes effectiveBuiltInType;
/**
* Effective pattern restriction, requried in case type of typedef is again
* a derived type. This information is to be added during linking.
*/
private YangPatternRestriction effectivePatternRestriction;
/**
* 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
* "PARTIALLY_RESOLVED".
*/
private ResolvableStatus resolvableStatus;
/**
* Default constructor.
*/
public YangType() {
nodeIdentifier = new YangNodeIdentifier();
resolvableStatus = ResolvableStatus.UNRESOLVED;
}
/**
* Returns prefix associated with data type name.
*
* @return prefix associated with data type name
*/
public String getPrefix() {
return nodeIdentifier.getPrefix();
}
/**
* Set prefix associated with data type name.
*
* @param prefix prefix associated with data type name
*/
public void setPrefix(String prefix) {
nodeIdentifier.setPrefix(prefix);
}
/**
......@@ -85,7 +126,7 @@ public class YangType<T> implements Parsable {
* @return the name of data type
*/
public String getDataTypeName() {
return dataTypeName;
return nodeIdentifier.getName();
}
/**
......@@ -94,7 +135,7 @@ public class YangType<T> implements Parsable {
* @param typeName the name to set
*/
public void setDataTypeName(String typeName) {
dataTypeName = typeName;
nodeIdentifier.setName(typeName);
}
/**
......@@ -152,6 +193,60 @@ public class YangType<T> implements Parsable {
}
/**
* Returns node identifier.
*
* @return node identifier
*/
public YangNodeIdentifier getNodeIdentifier() {
return nodeIdentifier;
}
/**
* Set node identifier.
*
* @param nodeIdentifier the node identifier
*/
public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) {
this.nodeIdentifier = nodeIdentifier;
}
/**
* Return effective built-in type.
*
* @return effective built-in type
*/
public YangDataTypes getEffectiveBuiltInType() {
return effectiveBuiltInType;
}
/**
* Set effective built-in type.
*
* @param effectiveBuiltInType effective built-in type
*/
public void setEffectiveBuiltInType(YangDataTypes effectiveBuiltInType) {
this.effectiveBuiltInType = effectiveBuiltInType;
}
/**
* Returns effective pattern restriction.
*
* @return effective pattern restriction
*/
public YangPatternRestriction getEffectivePatternRestriction() {
return effectivePatternRestriction;
}
/**
* Set effective pattern restriction.
*
* @param effectivePatternRestriction effective pattern restriction
*/
public void setEffectivePatternRestriction(YangPatternRestriction effectivePatternRestriction) {
this.effectivePatternRestriction = effectivePatternRestriction;
}
/**
* Returns the type of the parsed data.
*
* @return returns TYPE_DATA
......@@ -182,4 +277,19 @@ public class YangType<T> implements Parsable {
// TODO auto-generated method stub, to be implemented by parser
}
@Override
public ResolvableStatus getResolvableStatus() {
return resolvableStatus;
}
@Override
public void setResolvableStatus(ResolvableStatus resolvableStatus) {
this.resolvableStatus = resolvableStatus;
}
@Override
public void resolve() {
//TODO: implement the method.
}
}
......
......@@ -75,9 +75,14 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
private YangStatusType status;
/**
* Maintain the derived type information.
* Name of the typedef.
*/
private YangType<YangDerivedType> derivedType;
private String name;
/**
* Maintain the data type information.
*/
private YangType<?> dataType;
/**
* Units of the data type.
......@@ -92,7 +97,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
}
/**
* Get the default value.
* Returns the default value.
*
* @return the default value
*/
......@@ -110,7 +115,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
}
/**
* Get the description.
* Returns the description.
*
* @return the description
*/
......@@ -130,7 +135,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
}
/**
* Get the textual reference.
* Returns the textual reference.
*
* @return the reference
*/
......@@ -150,7 +155,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
}
/**
* Get the status.
* Returns the status.
*
* @return the status
*/
......@@ -170,25 +175,25 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
}
/**
* Get the derived type.
* Returns the data type.
*
* @return the derived type
* @return the data type
*/
public YangType<YangDerivedType> getDerivedType() {
return derivedType;
public YangType<?> getDataType() {
return dataType;
}
/**
* Set the derived type.
* Set the data type.
*
* @param derivedType the derived type
* @param dataType the data type
*/
public void setDerivedType(YangType<YangDerivedType> derivedType) {
this.derivedType = derivedType;
public void setDataType(YangType<?> dataType) {
this.dataType = dataType;
}
/**
* Get the unit.
* Returns the unit.
*
* @return the units
*/
......@@ -232,47 +237,17 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
*/
@Override
public void validateDataOnExit() throws DataModelException {
YangType<YangDerivedType> type = getDerivedType();
if (type == null) {
throw new DataModelException("Typedef does not have type info.");
}
if (type.getDataType() != YangDataTypes.DERIVED
|| type.getDataTypeName() == null) {
throw new DataModelException("Typedef type is not derived.");
}
YangDerivedType derivedTypeInfo = type.getDataTypeExtendedInfo();
if (derivedTypeInfo == null) {
throw new DataModelException("derrived type does not have derived info.");
}
YangType<?> baseType = derivedTypeInfo.getBaseType();
if (baseType == null) {
throw new DataModelException("Base type of a derived type is missing.");
}
if (derivedTypeInfo.getEffectiveYangBuiltInType() == null) {
/* resolve the effective type from the data tree. */
/*
* TODO: try to resolve the nested reference, if possible in the
* partial tree, otherwise we need to resolve finally when the
* complete module is created.
*/
YangModule.addToResolveList(this);
}
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Get the YANG name of the typedef.
* Returns the YANG name of the typedef.
*
* @return YANG name of the typedef
*/
@Override
public String getName() {
if (getDerivedType() != null) {
return getDerivedType().getDataTypeName();
}
return null;
return name;
}
/**
......@@ -282,12 +257,6 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
*/
@Override
public void setName(String name) {
if (getDerivedType() == null) {
throw new RuntimeException(
"Derrived Type info needs to be set in parser when the typedef listner is processed");
}
getDerivedType().setDataTypeName(name);
getDerivedType().setDataType(YangDataTypes.DERIVED);
this.name = name;
}
}
......
......@@ -52,12 +52,12 @@ import org.onosproject.yangutils.utils.YangConstructType;
* Data model node to maintain information defined in YANG uses.
*
*/
public class YangUses extends YangNode implements YangCommonInfo, Parsable {
public class YangUses extends YangNode implements YangCommonInfo, Parsable, Resolvable {
/**
* Name of YANG uses.
* YANG node identifier.
*/
private String name;
private YangNodeIdentifier nodeIdentifier;
/**
* Referred group.
......@@ -80,28 +80,20 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
private YangStatusType status;
/**
* Create an YANG uses node.
* 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
* "PARTIALLY_RESOLVED".
*/
public YangUses() {
super(YangNodeType.USES_NODE);
}
private ResolvableStatus resolvableStatus;
/**
* Returns the name.
*
* @return the name
*/
public String getRefGroupingName() {
return name;
}
/**
* Set the name.
*
* @param refGroupingName the referred grouping name to set
* Create an YANG uses node.
*/
public void setRefGroupingName(String refGroupingName) {
name = refGroupingName;
public YangUses() {
super(YangNodeType.USES_NODE);
nodeIdentifier = new YangNodeIdentifier();
resolvableStatus = ResolvableStatus.UNRESOLVED;
}
/**
......@@ -214,12 +206,62 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
@Override
public String getName() {
return name;
return nodeIdentifier.getName();
}
@Override
public void setName(String name) {
this.name = name;
nodeIdentifier.setName(name);
}
/**
* Returns node identifier.
*
* @return node identifier
*/
public YangNodeIdentifier getNodeIdentifier() {
return nodeIdentifier;
}
/**
* Set node identifier.
*
* @param nodeIdentifier the node identifier
*/
public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) {
this.nodeIdentifier = nodeIdentifier;
}
/**
* Returns prefix associated with uses.
*
* @return prefix associated with uses
*/
public String getPrefix() {
return nodeIdentifier.getPrefix();
}
/**
* Get prefix associated with uses.
*
* @param prefix prefix associated with uses
*/
public void setPrefix(String prefix) {
nodeIdentifier.setPrefix(prefix);
}
@Override
public void resolve() {
//TODO: implement the method.
}
@Override
public ResolvableStatus getResolvableStatus() {
return resolvableStatus;
}
@Override
public void setResolvableStatus(ResolvableStatus resolvableStatus) {
this.resolvableStatus = resolvableStatus;
}
}
......
......@@ -21,6 +21,8 @@ package org.onosproject.yangutils.datamodel.exceptions;
public class DataModelException extends Exception {
private static final long serialVersionUID = 201601270658L;
private int lineNumber;
private int charPositionInLine;
/**
* Constructor to create a data model exception with message.
......@@ -49,4 +51,40 @@ public class DataModelException extends Exception {
public DataModelException(final Throwable cause) {
super(cause);
}
/**
* Returns line number of the exception.
*
* @return line number of the exception
*/
public int getLineNumber() {
return this.lineNumber;
}
/**
* Returns position of the exception.
*
* @return position of the exception
*/
public int getCharPositionInLine() {
return this.charPositionInLine;
}
/**
* Sets line number of YANG file.
*
* @param line line number of YANG file
*/
public void setLine(int line) {
this.lineNumber = line;
}
/**
* Sets position of exception.
*
* @param charPosition position of exception
*/
public void setCharPosition(int charPosition) {
this.charPositionInLine = charPosition;
}
}
......
......@@ -16,11 +16,14 @@
package org.onosproject.yangutils.datamodel.utils;
import java.util.List;
import org.onosproject.yangutils.datamodel.CollisionDetector;
import org.onosproject.yangutils.datamodel.HasResolutionInfo;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangResolutionInfo;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.utils.YangConstructType;
......@@ -39,27 +42,23 @@ public final class DataModelUtils {
* Detects the colliding identifier name in a given YANG node and its child.
*
* @param identifierName name for which collision detection is to be
* checked.
* @param dataType type of YANG node asking for detecting collision.
* @param node instance of calling node.
* @throws DataModelException a violation of data model rules.
* checked
* @param dataType type of YANG node asking for detecting collision
* @param node instance of calling node
* @throws DataModelException a violation of data model rules
*/
public static void detectCollidingChildUtil(String identifierName, YangConstructType dataType, YangNode node)
throws DataModelException {
if (((YangLeavesHolder) node).getListOfLeaf() != null) {
for (YangLeaf leaf : ((YangLeavesHolder) node).getListOfLeaf()) {
if (leaf.getLeafName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf \""
+ leaf.getLeafName() + "\"");
}
if (dataType == YangConstructType.LEAF_DATA) {
YangLeavesHolder leavesHolder = (YangLeavesHolder) node;
if (leavesHolder.getListOfLeaf() != null) {
detectCollidingLeaf(leavesHolder, identifierName);
}
}
if (((YangLeavesHolder) node).getListOfLeafList() != null) {
for (YangLeafList leafList : ((YangLeavesHolder) node).getListOfLeafList()) {
if (leafList.getLeafName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf " +
"list \"" + leafList.getLeafName() + "\"");
}
if (dataType == YangConstructType.LEAF_LIST_DATA) {
if (((YangLeavesHolder) node).getListOfLeafList() != null) {
YangLeavesHolder leavesHolder = (YangLeavesHolder) node;
detectCollidingLeafList(leavesHolder, identifierName);
}
}
node = node.getChild();
......@@ -70,4 +69,78 @@ public final class DataModelUtils {
node = node.getNextSibling();
}
}
/**
* Detects the colliding identifier name in a given leaf node.
*
* @param leavesHolder leaves node against which collision to be checked
* @param identifierName name for which collision detection is to be
* checked
* @throws DataModelException a violation of data model rules
*/
private static void detectCollidingLeaf(YangLeavesHolder leavesHolder, String identifierName) throws
DataModelException {
for (YangLeaf leaf : leavesHolder.getListOfLeaf()) {
if (leaf.getLeafName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf \""
+ leaf.getLeafName() + "\"");
}
}
}
/**
* Detects the colliding identifier name in a given leaf-list node.
*
* @param leavesHolder leaves node against which collision to be checked
* @param identifierName name for which collision detection is to be
* checked
* @throws DataModelException a violation of data model rules
*/
private static void detectCollidingLeafList(YangLeavesHolder leavesHolder, String identifierName) throws
DataModelException {
for (YangLeafList leafList : leavesHolder.getListOfLeafList()) {
if (leafList.getLeafName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf " +
"list \"" + leafList.getLeafName() + "\"");
}
}
}
/**
* Add a resolution information.
*
* @param resolutionInfo information about the YANG construct which has to
* be resolved
* @throws DataModelException a violation of data model rules
*/
public static void addResolutionInfo(YangResolutionInfo resolutionInfo) throws DataModelException {
/* get the module node to add maintain the list of nested reference */
YangNode curNode = resolutionInfo.getHolderOfEntityToResolve();
while (!(curNode instanceof HasResolutionInfo)) {
curNode = curNode.getParent();
if (curNode == null) {
throw new DataModelException("Internal datamodel error: Datamodel tree is not correct");
}
}
HasResolutionInfo resolutionNode = (HasResolutionInfo) curNode;
resolutionNode.addToResolutionList(resolutionInfo);
}
/**
* Resolve linking for a resolution list.
*
* @param resolutionList resolution list for which linking to be done
* @param resolutionInfoNode module/sub-module node
* @throws DataModelException a violation of data model rules
*/
public static void resolveLinkingForResolutionList(List<YangResolutionInfo> resolutionList,
HasResolutionInfo resolutionInfoNode)
throws DataModelException {
for (YangResolutionInfo resolutionInfo : resolutionList) {
if (resolutionInfo.getPrefix() == null ||
resolutionInfo.getPrefix().equals(resolutionInfoNode.getPrefix())) {
resolutionInfo.resolveLinkingForResolutionInfo(resolutionInfoNode.getPrefix());
}
}
}
}
......
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.onosproject.yangutils.linker;
import java.util.Map;
import org.onosproject.yangutils.datamodel.HasResolutionInfo;
/**
* Abstraction of entity which provides linking service of YANG files.
*/
public interface YangLinker {
/**
* Resolve the import and include dependencies for a given resolution
* information.
*
* @param fileMapEntry map entry for which resolution is to be done
* @param yangFilesMap map of dependent file and resolution information*/
void resolveDependencies(Map.Entry<String, HasResolutionInfo> fileMapEntry, Map<String,
HasResolutionInfo> yangFilesMap);
}
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provide inter file and inter jar linking implementation.
*/
package org.onosproject.yangutils.linker.impl;
\ No newline at end of file
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provide inter jar and inter file linking abstract interface.
*/
package org.onosproject.yangutils.linker;
\ No newline at end of file
......@@ -23,13 +23,13 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
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;
import static org.onosproject.yangutils.utils.YangConstructType.BELONGS_TO_DATA;
......@@ -119,6 +119,7 @@ public final class BelongsToListener {
case SUB_MODULE_DATA: {
YangSubModule subModule = (YangSubModule) tmpNode;
subModule.setBelongsTo((YangBelongsTo) tmpBelongstoNode);
subModule.setPrefix(subModule.getBelongsTo().getPrefix());
break;
}
default:
......
......@@ -113,12 +113,12 @@ public final class ImportListener {
switch (tmpNode.getYangConstructType()) {
case MODULE_DATA: {
YangModule module = (YangModule) tmpNode;
module.addImportedInfo((YangImport) tmpImportNode);
module.addToImportList((YangImport) tmpImportNode);
break;
}
case SUB_MODULE_DATA: {
YangSubModule subModule = (YangSubModule) tmpNode;
subModule.addImportedInfo((YangImport) tmpImportNode);
subModule.addToImportList((YangImport) tmpImportNode);
break;
}
default:
......
......@@ -24,13 +24,13 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
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;
import static org.onosproject.yangutils.utils.YangConstructType.INCLUDE_DATA;
......@@ -112,12 +112,12 @@ public final class IncludeListener {
switch (tmpNode.getYangConstructType()) {
case MODULE_DATA: {
YangModule module = (YangModule) tmpNode;
module.addIncludedInfo((YangInclude) tmpIncludeNode);
module.addToIncludeList((YangInclude) tmpIncludeNode);
break;
}
case SUB_MODULE_DATA: {
YangSubModule subModule = (YangSubModule) tmpNode;
subModule.addIncludedInfo((YangInclude) tmpIncludeNode);
subModule.addToIncludeList((YangInclude) tmpIncludeNode);
break;
}
default:
......
......@@ -16,8 +16,10 @@
package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.HasResolutionInfo;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangRevision;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
......@@ -113,5 +115,13 @@ public final class ModuleListener {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, MODULE_DATA,
ctx.identifier().getText(), EXIT));
}
try {
((HasResolutionInfo) listener.getParsedDataStack().peek()).resolveSelfFileLinking();
} catch (DataModelException e) {
ParserException parserException = new ParserException(e.getMessage());
parserException.setLine(e.getLineNumber());
parserException.setCharPosition(e.getCharPositionInLine());
throw parserException;
}
}
}
......
......@@ -16,8 +16,10 @@
package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.HasResolutionInfo;
import org.onosproject.yangutils.datamodel.YangRevision;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
......@@ -118,5 +120,13 @@ public final class SubModuleListener {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, SUB_MODULE_DATA,
ctx.identifier().getText(), EXIT));
}
try {
((HasResolutionInfo) listener.getParsedDataStack().peek()).resolveSelfFileLinking();
} catch (DataModelException e) {
ParserException parserException = new ParserException(e.getMessage());
parserException.setLine(e.getLineNumber());
parserException.setCharPosition(e.getCharPositionInLine());
throw parserException;
}
}
}
......
......@@ -17,18 +17,15 @@
package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangDerivedType;
import org.onosproject.yangutils.datamodel.YangInput;
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangInput;
import org.onosproject.yangutils.datamodel.YangOutput;
import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.datamodel.YangOutput;
import org.onosproject.yangutils.datamodel.YangRpc;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
......@@ -123,12 +120,8 @@ public final class TypeDefListener {
* Create a derived type information, the base type must be set in type
* listener.
*/
YangType<YangDerivedType> derivedType = new YangType<YangDerivedType>();
derivedType.setDataType(YangDataTypes.DERIVED);
derivedType.setDataTypeName(identifier);
YangTypeDef typeDefNode = getYangTypeDefNode(JAVA_GENERATION);
typeDefNode.setDerivedType(derivedType);
typeDefNode.setName(identifier);
Parsable curData = listener.getParsedDataStack().peek();
......
......@@ -1102,7 +1102,7 @@ public class TempJavaCodeFragmentFiles {
public void addTypeDefAttributeToTempFiles(YangNode curNode) throws IOException {
JavaAttributeInfo javaAttributeInfo = getAttributeInfoOfTypeDef(curNode,
((YangTypeDef) curNode).getDerivedType().getDataTypeExtendedInfo().getBaseType(),
((YangTypeDef) curNode).getDataType(),
((YangTypeDef) curNode).getName(), false);
addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
}
......
......@@ -18,7 +18,6 @@ package org.onosproject.yangutils.parser.impl.listeners;
import java.io.IOException;
import java.util.ListIterator;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
......@@ -170,7 +169,7 @@ public class ConfigListenerTest {
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
assertThat(leafInfo.getUnits(), is("\"seconds\""));
assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
......@@ -206,7 +205,7 @@ public class ConfigListenerTest {
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
assertThat(leafInfo.getUnits(), is("\"seconds\""));
assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
......
......@@ -193,7 +193,7 @@ public class ContainerListenerTest {
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
assertThat(leafInfo.getUnits(), is("\"seconds\""));
assertThat(leafInfo.getStatus(), is(YangStatusType.CURRENT));
......
......@@ -18,7 +18,6 @@ package org.onosproject.yangutils.parser.impl.listeners;
import java.io.IOException;
import java.util.ListIterator;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
......@@ -178,7 +177,7 @@ public class DescriptionListenerTest {
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
assertThat(leafInfo.getUnits(), is("\"seconds\""));
assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
......@@ -215,7 +214,7 @@ public class DescriptionListenerTest {
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
assertThat(leafInfo.getUnits(), is("\"seconds\""));
assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
......
......@@ -18,7 +18,6 @@ package org.onosproject.yangutils.parser.impl.listeners;
import java.io.IOException;
import java.util.ListIterator;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
......@@ -68,7 +67,7 @@ public class LeafListListenerTest {
YangLeafList leafListInfo = leafListIterator.next();
assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\""));
assertThat(leafListInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
assertThat(leafListInfo.getUnits(), is("\"seconds\""));
assertThat(leafListInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
......@@ -163,7 +162,7 @@ public class LeafListListenerTest {
YangLeafList leafListInfo = leafListIterator.next();
assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\""));
assertThat(leafListInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
assertThat(leafListInfo.getUnits(), is("\"seconds\""));
assertThat(leafListInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
......@@ -200,7 +199,7 @@ public class LeafListListenerTest {
YangLeafList leafListInfo = leafListIterator.next();
assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\""));
assertThat(leafListInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
assertThat(leafListInfo.getUnits(), is("\"seconds\""));
assertThat(leafListInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
......
......@@ -68,7 +68,7 @@ public class LeafListenerTest {
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
assertThat(leafInfo.getUnits(), is("\"seconds\""));
assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
......@@ -162,7 +162,7 @@ public class LeafListenerTest {
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
assertThat(leafInfo.getUnits(), is("\"seconds\""));
assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
......@@ -225,7 +225,7 @@ public class LeafListenerTest {
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
assertThat(leafInfo.getUnits(), is("\"seconds\""));
assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
......
......@@ -162,7 +162,7 @@ public class ListListenerTest {
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
assertThat(leafInfo.getUnits(), is("\"seconds\""));
assertThat(leafInfo.getStatus(), is(YangStatusType.CURRENT));
......
......@@ -16,21 +16,19 @@
package org.onosproject.yangutils.parser.impl.listeners;
import java.io.IOException;
import java.util.ListIterator;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangNode;
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.YangNotification;
import org.onosproject.yangutils.datamodel.YangStatusType;
import org.onosproject.yangutils.datamodel.YangNodeType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangDataTypes;
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;
......@@ -63,8 +61,6 @@ public class NotificationListenerTest {
YangTypeDef typeDef = (YangTypeDef) yangNotification.getChild();
assertThat(typeDef.getName(), is("my-type"));
assertThat(typeDef.getStatus(), is(YangStatusType.DEPRECATED));
assertThat(typeDef.getDerivedType().getDataTypeExtendedInfo()
.getBaseType().getDataType(), is(YangDataTypes.INT32));
ListIterator<YangLeaf> leafIterator = yangNotification.getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
......
......@@ -18,7 +18,6 @@ package org.onosproject.yangutils.parser.impl.listeners;
import java.io.IOException;
import java.util.ListIterator;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
......@@ -177,7 +176,7 @@ public class ReferenceListenerTest {
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
assertThat(leafInfo.getUnits(), is("\"seconds\""));
assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
......@@ -214,7 +213,7 @@ public class ReferenceListenerTest {
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
assertThat(leafInfo.getUnits(), is("\"seconds\""));
assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
......
......@@ -18,7 +18,6 @@ package org.onosproject.yangutils.parser.impl.listeners;
import java.io.IOException;
import java.util.ListIterator;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
......@@ -187,7 +186,7 @@ public class StatusListenerTest {
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
assertThat(leafInfo.getUnits(), is("\"seconds\""));
assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
......@@ -224,7 +223,7 @@ public class StatusListenerTest {
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
assertThat(leafInfo.getUnits(), is("\"seconds\""));
assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
......
......@@ -2,7 +2,6 @@ package org.onosproject.yangutils.parser.impl.listeners;
import java.io.IOException;
import java.util.ListIterator;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangLeaf;
......@@ -45,7 +44,7 @@ public class TypeListenerTest {
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"hello\""));
assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
}
......@@ -71,7 +70,7 @@ public class TypeListenerTest {
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
}
......@@ -97,7 +96,7 @@ public class TypeListenerTest {
YangLeafList leafListInfo = leafListIterator.next();
assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\""));
assertThat(leafListInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
}
}
\ No newline at end of file
......
......@@ -18,7 +18,6 @@ package org.onosproject.yangutils.parser.impl.listeners;
import java.io.IOException;
import java.util.ListIterator;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
......@@ -117,7 +116,7 @@ public class UnitsListenerTest {
// Check whether leaf properties is set correctly.
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafInfo.getUnits(), is("\"seconds\""));
assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
assertThat(leafInfo.isConfig(), is(true));
......
......@@ -3,6 +3,6 @@ module Test {
namespace http://huawei.com;
prefix Ant;
leaf invalid-interval {
type "hello";
type P:hello;
}
}
\ No newline at end of file
}
......
......@@ -5,17 +5,17 @@ module Test {
list valid {
key address;
leaf address {
type ip;
type P:ip;
}
grouping endpoint {
description "grouping under test";
status current;
reference "RFC 6020";
leaf address {
type ip-address;
type P:ip-address;
}
leaf port {
type port-number;
type P:port-number;
}
}
}
......
......@@ -5,10 +5,10 @@ module Test {
container valid {
grouping endpoint {
leaf address {
type ip-address;
type P:ip-address;
}
leaf port {
type port-number;
type P:port-number;
}
}
}
......
......@@ -5,14 +5,14 @@ module Test {
list valid {
key address;
leaf address {
type ip;
type P:ip;
}
grouping endpoint {
leaf address {
type ip-address;
type P:ip-address;
}
leaf port {
type port-number;
type P:port-number;
}
}
}
......
......@@ -4,10 +4,10 @@ module Test {
prefix Ant;
grouping endpoint {
leaf address {
type ip-address;
type P:ip-address;
}
leaf port {
type port-number;
type P:port-number;
}
}
}
......
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
container ospf {
list valid {
key "invalid-interval";
leaf invalid-interval {
type hello;
}
}
typedef hello {
type String;
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
container ospf {
list valid {
key "invalid-interval";
leaf invalid-interval {
type hello;
}
}
}
typedef hello {
type String;
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
typedef hello {
type String;
}
container ospf {
list valid {
key "invalid-interval";
leaf invalid-interval {
type hello;
}
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
container ospf {
list valid {
key "invalid-interval";
leaf invalid-interval {
type hello;
}
}
}
container isis {
typedef hello {
type String;
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
typedef Percentage {
type INT;
}
container ospf {
list valid {
key "invalid-interval";
leaf invalid-interval {
type Ant:FirstClass;
}
typedef FirstClass {
type Ant:PassingClass;
}
}
typedef PassingClass {
type Percentage;
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
typedef Percentage {
type P:Per;
}
container ospf {
list valid {
key "invalid-interval";
leaf invalid-interval {
type FirstClass;
}
typedef FirstClass {
type PassingClass;
}
}
typedef PassingClass {
type Percentage;
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
typedef Percentage {
type int32;
}
container ospf {
list valid {
key "invalid-interval";
leaf invalid-interval {
type FirstClass;
}
typedef FirstClass {
type PassingClass;
}
}
typedef PassingClass {
type Percentage;
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
typedef Percentage {
type int32;
}
container ospf {
list valid {
key "invalid-interval";
leaf invalid-interval {
type Ant:FirstClass;
}
typedef FirstClass {
type P:PassingClass;
}
}
typedef PassingClass {
type Ant:Percentage;
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
typedef Percentage {
type int32;
}
container ospf {
list valid {
key "invalid-interval";
leaf invalid-interval {
type Ant:FirstClass;
}
typedef FirstClass {
type PassingClass;
}
}
typedef PassingClass {
type Ant:Percentage;
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
leaf invalid-interval {
type hello;
}
typedef hello {
type String;
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
leaf invalid-interval {
type hello;
}
typedef hi {
type String;
}
}
......@@ -5,7 +5,7 @@ module Test {
list valid {
key address;
leaf address {
type ip;
type P:ip;
}
uses endpoint {
description "grouping under test";
......
......@@ -16,10 +16,10 @@ module rock {
}
}
leaf if-admin-status {
type admin-status;
type P:admin-status;
}
leaf if-oper-status {
type oper-status;
type P:oper-status;
}
}
}
......
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
typedef hello {
type String;
}
leaf invalid-interval {
type hello;
}
}