[ONOS-4753] Identity/identityref implementation and UT
Change-Id: I40148fa228465555be3bdf410cc294ffc0f34c18
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/ResolvableType.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/ResolvableType.java
index 80ee4a0..ad00cae 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/ResolvableType.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/ResolvableType.java
@@ -39,5 +39,15 @@
/**
* Identifies the leafref.
*/
- YANG_LEAFREF
+ YANG_LEAFREF,
+
+ /**
+ * Identifies the base.
+ */
+ YANG_BASE,
+
+ /**
+ * Identifies the identityref.
+ */
+ YANG_IDENTITYREF
}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangBase.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangBase.java
new file mode 100644
index 0000000..40c2293
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangBase.java
@@ -0,0 +1,114 @@
+/*
+ * 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 org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
+
+import java.io.Serializable;
+
+/**
+ * Reference RFC 6020.
+ *
+ * Represents data model node to maintain information defined in YANG base.
+ * The "base" statement, which is optional, takes as an argument a
+ * string that is the name of an existing identity, from which the new
+ * identity is derived. If no "base" statement is present, the identity
+ * is defined from scratch.
+ *
+ * If a prefix is present on the base name, it refers to an identity
+ * defined in the module that was imported with that prefix, or the
+ * local module if the prefix matches the local module's prefix.
+ * Otherwise, an identity with the matching name MUST be defined in the
+ * current module or an included submodule.
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG base.
+ */
+ public class YangBase implements Resolvable, Serializable {
+
+ private static final long serialVersionUID = 806201693L;
+
+ // YANG node identifier.
+ private YangNodeIdentifier baseIdentifier;
+
+ // Referred identity parent information.
+ private YangIdentity referredIdentity;
+
+ /**
+ * Status of resolution. If completely resolved enum value is "RESOLVED",
+ * if not enum value is "UNRESOLVED", in case reference of grouping/typedef/base/identityref
+ * is added to uses/type/base/identityref but it's not resolved value of enum should be
+ * "INTRA_FILE_RESOLVED".
+ */
+ private ResolvableStatus resolvableStatus;
+
+ // Creates a base type of node.
+ public YangBase() {
+ resolvableStatus = ResolvableStatus.UNRESOLVED;
+ }
+
+ /**
+ * Returns the YANG node identifier.
+ *
+ * @return the YANG node identifier
+ */
+ public YangNodeIdentifier getBaseIdentifier() {
+ return baseIdentifier;
+ }
+
+ /**
+ * Sets the YANG node identifier.
+ *
+ * @param baseIdentifier the YANG node identifier to set
+ */
+ public void setBaseIdentifier(YangNodeIdentifier baseIdentifier) {
+ this.baseIdentifier = baseIdentifier;
+ }
+
+ /**
+ * Returns the parent identity node.
+ *
+ * @return the parent identity node
+ */
+ public YangIdentity getReferredIdentity() {
+ return referredIdentity;
+ }
+
+ /**
+ * Sets the parent identity node.
+ *
+ * @param referredIdentity the parent identity node to set
+ */
+ public void setReferredIdentity(YangIdentity referredIdentity) {
+ this.referredIdentity = referredIdentity;
+ }
+
+ @Override
+ public ResolvableStatus getResolvableStatus() {
+ return resolvableStatus;
+ }
+
+ @Override
+ public void setResolvableStatus(ResolvableStatus resolvableStatus) {
+ this.resolvableStatus = resolvableStatus;
+ }
+
+ @Override
+ public void resolve() throws DataModelException {
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
index 640aa64..1661d96 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
@@ -334,7 +334,7 @@
return RESOLVED;
}
}
- } else if (baseType.getDataType() == LEAFREF) {
+ } else if ((baseType.getDataType() == LEAFREF) || (baseType.getDataType() == IDENTITYREF)) {
setEffectiveBuiltInType(baseType.getDataType());
return RESOLVED;
} else {
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangIdentity.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangIdentity.java
new file mode 100644
index 0000000..5e57012
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangIdentity.java
@@ -0,0 +1,152 @@
+/*
+ * 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 org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+import java.io.Serializable;
+
+/*-
+ * Reference RFC 6020.
+ *
+ * The "identity" statement is used to define a new globally unique,
+ * abstract, and untyped identity. Its only purpose is to denote its
+ * name, semantics, and existence. An identity can either be defined
+ * from scratch or derived from a base identity. The identity's
+ * argument is an identifier that is the name of the identity. It is
+ * followed by a block of substatements that holds detailed identity
+ * information.
+ *
+ * The identity's Substatements
+ *
+ * +--------------+---------+-------------+-----------------------+
+ * | substatement | section | cardinality | data model mapping |
+ * +--------------+---------+-------------+-----------------------+
+ * | base | 7.16.2 | 0..1 | -YangNodeIdentifier |
+ * | description | 7.19.3 | 0..1 | -string |
+ * | reference | 7.19.4 | 0..1 | -string |
+ * | status | 7.19.2 | 0..1 | -YangStatus |
+ * +--------------+---------+-------------+-----------------------+
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG identity.
+ */
+public class YangIdentity extends YangNode implements YangCommonInfo, Parsable, Serializable {
+
+ private static final long serialVersionUID = 806201691L;
+
+ //Name of the identity.
+ private String name;
+
+ //Base node of identity.
+ private YangBase baseNode;
+
+ //Status of YANG identity.
+ private YangStatusType status;
+
+ //Description of YANG identity.
+ private String description;
+
+ //YANG reference of the identity.
+ private String reference;
+
+ //Creates a identity type of node.
+ public YangIdentity() {
+ super(YangNodeType.IDENTITY_NODE);
+ }
+
+ /**
+ * Returns the name of identity.
+ *
+ * @return the identity name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name of identity.
+ *
+ * @param name the identity name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public YangStatusType getStatus() {
+ return status;
+ }
+
+ @Override
+ public void setStatus(YangStatusType status) {
+ this.status = status;
+ }
+
+ @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 YangConstructType getYangConstructType() {
+ return YangConstructType.IDENTITY_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ }
+
+ /**
+ * Returns base node of identity.
+ *
+ * @return the base node of identity
+ */
+ public YangBase getBaseNode() {
+ return baseNode;
+ }
+
+ /**
+ * Sets the base node.
+ *
+ * @param baseNode the base node to set
+ */
+ public void setBaseNode(YangBase baseNode) {
+ this.baseNode = baseNode;
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangIdentityRef.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangIdentityRef.java
new file mode 100644
index 0000000..d03fcf4
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangIdentityRef.java
@@ -0,0 +1,196 @@
+/*
+ * 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 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;
+
+import java.io.Serializable;
+
+/*-
+ * Reference RFC 6020.
+ *
+ * The identityref type is used to reference an existing identity.
+ *
+ * The identityref's base Statement :
+ * The "base" statement, which is a substatement to the "type"
+ * statement, MUST be present if the type is "identityref". The
+ * argument is the name of an identity, as defined by an "identity"
+ * statement. If a prefix is present on the identity name, it refers to
+ * an identity defined in the module that was imported with that prefix.
+ * Otherwise, an identity with the matching name MUST be defined in the
+ * current module or an included submodule.
+ * Valid values for an identityref are any identities derived from the
+ * identityref's base identity. On a particular server, the valid
+ * values are further restricted to the set of identities defined in the
+ * modules supported by the server.
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG identityref.
+ */
+public class YangIdentityRef extends YangNode implements Parsable, Resolvable, Serializable {
+
+ private static final long serialVersionUID = 806201692L;
+
+ // Get referred identity parent information.
+ private YangIdentity referredIdentity;
+
+ // YANG node identifier.
+ private YangNodeIdentifier baseIdentity;
+
+ /**
+ * Status of resolution. If completely resolved enum value is "RESOLVED",
+ * if not enum value is "UNRESOLVED", in case reference of grouping/typedef/identityref/base
+ * is added to uses/type/identityref/base but it's not resolved value of enum should be
+ * "INTRA_FILE_RESOLVED".
+ */
+ private ResolvableStatus resolvableStatus;
+
+ // Creates a specific identityref of node.
+ public YangIdentityRef() {
+ super(YangNodeType.IDENTITYREF_NODE);
+ baseIdentity = new YangNodeIdentifier();
+ resolvableStatus = ResolvableStatus.UNRESOLVED;
+ }
+
+ @Override
+ public ResolvableStatus getResolvableStatus() {
+ return resolvableStatus;
+ }
+
+ @Override
+ public void setResolvableStatus(ResolvableStatus resolvableStatus) {
+ this.resolvableStatus = resolvableStatus;
+ }
+
+ @Override
+ public void resolve() throws DataModelException {
+
+ // Check if the derived info is present.
+ YangIdentity identity = getReferredIdentity();
+
+ if (identity == null) {
+ throw new DataModelException("Linker Error: Identity information is missing.");
+ }
+
+ while (identity.getBaseNode() != null) {
+ if (identity.getBaseNode().getResolvableStatus() != ResolvableStatus.RESOLVED) {
+ setResolvableStatus(ResolvableStatus.INTRA_FILE_RESOLVED);
+ return;
+ }
+ identity = identity.getBaseNode().getReferredIdentity();
+ }
+ }
+
+ /**
+ * Returns the YANG base node identifier.
+ *
+ * @return the YANG base node identifier
+ */
+ public YangNodeIdentifier getBaseIdentity() {
+ return baseIdentity;
+ }
+
+ /**
+ * Sets the YANG node identifier.
+ *
+ * @param baseIdentity the YANG node identifier to set
+ */
+ public void setBaseIdentity(YangNodeIdentifier baseIdentity) {
+ this.baseIdentity = baseIdentity;
+ }
+
+ /**
+ * Returns the name of identity.
+ *
+ * @return the identity name
+ */
+ @Override
+ public String getName() {
+ return baseIdentity.getName();
+ }
+
+ /**
+ * Sets the name of identity.
+ *
+ * @param name the identity name to set
+ */
+ @Override
+ public void setName(String name) {
+ baseIdentity.setName(name);
+ }
+
+ /**
+ * Sets node identifier.
+ *
+ * @param nodeIdentifier the node identifier
+ */
+ public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) {
+ this.baseIdentity = nodeIdentifier;
+ }
+
+ /**
+ * Returns prefix associated with base.
+ *
+ * @return prefix associated with base
+ */
+ public String getPrefix() {
+ return baseIdentity.getPrefix();
+ }
+
+ /**
+ * Sets prefix associated with base.
+ *
+ * @param prefix prefix associated with base
+ */
+ public void setPrefix(String prefix) {
+ baseIdentity.setPrefix(prefix);
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.IDENTITYREF_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ }
+
+ /**
+ * Returns the parent identity node.
+ *
+ * @return the parent identity node
+ */
+ public YangIdentity getReferredIdentity() {
+ return referredIdentity;
+ }
+
+ /**
+ * Sets the parent identity node.
+ *
+ * @param referredIdentity the parent identity node to set
+ */
+ public void setReferredIdentity(YangIdentity referredIdentity) {
+ this.referredIdentity = referredIdentity;
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
index ec25d65..6e515ad 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
@@ -216,6 +216,17 @@
private List<YangResolutionInfo> leafrefResolutionList;
/**
+ * base resolution list.
+ */
+ private List<YangResolutionInfo> baseResolutionList;
+
+ /**
+ * identityref resolution list.
+ */
+ private List<YangResolutionInfo> identityrefResolutionList;
+
+
+ /**
* Creates a YANG node of module type.
*/
public YangModule() {
@@ -225,6 +236,8 @@
usesResolutionList = new LinkedList<>();
ifFeatureResolutionList = new LinkedList<>();
leafrefResolutionList = new LinkedList<>();
+ baseResolutionList = new LinkedList<>();
+ identityrefResolutionList = new LinkedList<>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
@@ -597,8 +610,12 @@
return usesResolutionList;
} else if (type == ResolvableType.YANG_IF_FEATURE) {
return ifFeatureResolutionList;
- } else {
+ } else if (type == ResolvableType.YANG_LEAFREF) {
return leafrefResolutionList;
+ } else if (type == ResolvableType.YANG_BASE) {
+ return baseResolutionList;
+ } else {
+ return identityrefResolutionList;
}
}
@@ -611,8 +628,12 @@
usesResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_IF_FEATURE) {
ifFeatureResolutionList.add(resolutionInfo);
- } else {
+ } else if (type == ResolvableType.YANG_LEAFREF) {
leafrefResolutionList.add(resolutionInfo);
+ } else if (type == ResolvableType.YANG_BASE) {
+ baseResolutionList.add(resolutionInfo);
+ } else if (type == ResolvableType.YANG_IDENTITYREF) {
+ identityrefResolutionList.add(resolutionInfo);
}
}
@@ -627,6 +648,10 @@
ifFeatureResolutionList.add((YangResolutionInfo) resolutionList);
} else if (type == ResolvableType.YANG_LEAFREF) {
leafrefResolutionList = resolutionList;
+ } else if (type == ResolvableType.YANG_BASE) {
+ baseResolutionList = resolutionList;
+ } else if (type == ResolvableType.YANG_IDENTITYREF) {
+ identityrefResolutionList = resolutionList;
}
}
@@ -650,11 +675,8 @@
while (includeInfoIterator.hasNext()) {
YangInclude yangInclude = includeInfoIterator.next();
YangSubModule subModule = null;
- try {
- subModule = yangInclude.addReferenceToInclude(yangNodeSet);
- } catch (DataModelException e) {
- throw e;
- }
+ subModule = yangInclude.addReferenceToInclude(yangNodeSet);
+
// Check if the referred sub-modules parent is self
if (!(subModule.getBelongsTo().getModuleNode() == this)) {
yangInclude.reportIncludeError();
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNodeType.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNodeType.java
index 35fe918..c6108c7 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNodeType.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNodeType.java
@@ -102,5 +102,15 @@
/**
* Node contains "YANG's list" information.
*/
- LIST_NODE
+ LIST_NODE,
+
+ /**
+ * Identity node.
+ */
+ IDENTITY_NODE,
+
+ /**
+ * Identityref node.
+ */
+ IDENTITYREF_NODE
}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
index 5a5d52f..498f5e7 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
@@ -214,6 +214,16 @@
private List<YangResolutionInfo> leafrefResolutionList;
/**
+ * base resolution list.
+ */
+ private List<YangResolutionInfo> baseResolutionList;
+
+ /**
+ * identityref resolution list.
+ */
+ private List<YangResolutionInfo> identityrefResolutionList;
+
+ /**
* Creates a sub module node.
*/
public YangSubModule() {
@@ -222,6 +232,8 @@
usesResolutionList = new LinkedList<>();
ifFeatureResolutionList = new LinkedList<>();
leafrefResolutionList = new LinkedList<>();
+ baseResolutionList = new LinkedList<>();
+ identityrefResolutionList = new LinkedList<>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
@@ -559,8 +571,12 @@
return usesResolutionList;
} else if (type == ResolvableType.YANG_IF_FEATURE) {
return ifFeatureResolutionList;
- } else {
+ } else if (type == ResolvableType.YANG_LEAFREF) {
return leafrefResolutionList;
+ } else if (type == ResolvableType.YANG_BASE) {
+ return baseResolutionList;
+ } else {
+ return identityrefResolutionList;
}
}
@@ -573,8 +589,12 @@
usesResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_IF_FEATURE) {
ifFeatureResolutionList.add(resolutionInfo);
- } else {
+ } else if (type == ResolvableType.YANG_LEAFREF) {
leafrefResolutionList.add(resolutionInfo);
+ } else if (type == ResolvableType.YANG_BASE) {
+ baseResolutionList.add(resolutionInfo);
+ } else if (type == ResolvableType.YANG_IDENTITYREF) {
+ identityrefResolutionList.add(resolutionInfo);
}
}
@@ -589,6 +609,10 @@
ifFeatureResolutionList.add((YangResolutionInfo) resolutionList);
} else if (type == ResolvableType.YANG_LEAFREF) {
leafrefResolutionList = resolutionList;
+ } else if (type == ResolvableType.YANG_BASE) {
+ baseResolutionList = resolutionList;
+ } else if (type == ResolvableType.YANG_IDENTITYREF) {
+ identityrefResolutionList = resolutionList;
}
}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
index 3007ffa..489ac5c 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
@@ -22,6 +22,8 @@
import org.onosproject.yangutils.datamodel.CollisionDetector;
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangIfFeature;
+import org.onosproject.yangutils.datamodel.YangBase;
+import org.onosproject.yangutils.datamodel.YangIdentityRef;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeafRef;
@@ -176,6 +178,10 @@
.getEntityToResolve() instanceof YangLeafRef) {
resolutionNode.addToResolutionList(resolutionInfo,
ResolvableType.YANG_LEAFREF);
+ } else if (resolutionInfo.getEntityToResolveInfo().getEntityToResolve() instanceof YangBase) {
+ resolutionNode.addToResolutionList(resolutionInfo, ResolvableType.YANG_BASE);
+ } else if (resolutionInfo.getEntityToResolveInfo().getEntityToResolve() instanceof YangIdentityRef) {
+ resolutionNode.addToResolutionList(resolutionInfo, ResolvableType.YANG_IDENTITYREF);
}
}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangEntityToResolveInfoImpl.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangEntityToResolveInfoImpl.java
index 17285f6..d33dfd7 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangEntityToResolveInfoImpl.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangEntityToResolveInfoImpl.java
@@ -19,6 +19,8 @@
import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo;
import org.onosproject.yangutils.datamodel.YangIfFeature;
+import org.onosproject.yangutils.datamodel.YangBase;
+import org.onosproject.yangutils.datamodel.YangIdentityRef;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangUses;
@@ -79,6 +81,10 @@
prefix = ((YangUses) entityToBeResolved).getPrefix();
} else if (entityToBeResolved instanceof YangIfFeature) {
prefix = ((YangIfFeature) entityToBeResolved).getPrefix();
+ } else if (entityToBeResolved instanceof YangBase) {
+ prefix = ((YangBase) entityToBeResolved).getBaseIdentifier().getPrefix();
+ } else if (entityToBeResolved instanceof YangIdentityRef) {
+ prefix = ((YangIdentityRef) entityToBeResolved).getBaseIdentity().getPrefix();
} else {
throw new LinkerException("Linker Exception: Entity to resolved is other than type/uses");
}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
index 914b5d5..3847d3d 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
@@ -158,11 +158,16 @@
try {
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_IF_FEATURE);
- ((YangReferenceResolver) yangNode).resolveInterFileLinking(ResolvableType.YANG_USES);
+ ((YangReferenceResolver) yangNode)
+ .resolveInterFileLinking(ResolvableType.YANG_USES);
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_LEAFREF);
+ ((YangReferenceResolver) yangNode)
+ .resolveInterFileLinking(ResolvableType.YANG_BASE);
+ ((YangReferenceResolver) yangNode)
+ .resolveInterFileLinking(ResolvableType.YANG_IDENTITYREF);
} catch (DataModelException e) {
String errorInfo = "Error in file: " + yangNode.getName() + " at line: "
+ e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE + e.getMessage();
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
index b70d44c..eb42233 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
@@ -24,12 +24,15 @@
import org.onosproject.yangutils.datamodel.Resolvable;
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
+import org.onosproject.yangutils.datamodel.YangBase;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo;
import org.onosproject.yangutils.datamodel.YangFeature;
import org.onosproject.yangutils.datamodel.YangFeatureHolder;
import org.onosproject.yangutils.datamodel.YangGrouping;
import org.onosproject.yangutils.datamodel.YangIfFeature;
+import org.onosproject.yangutils.datamodel.YangIdentity;
+import org.onosproject.yangutils.datamodel.YangIdentityRef;
import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangInclude;
import org.onosproject.yangutils.datamodel.YangInput;
@@ -69,9 +72,12 @@
import static org.onosproject.yangutils.utils.UtilConstants.GROUPING_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.INPUT;
import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF;
+import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF;
import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.OUTPUT;
import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_LINKER_ERROR;
+import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF_LINKER_ERROR;
+import static org.onosproject.yangutils.utils.UtilConstants.BASE_LINKER_ERROR;
/**
* Represents implementation of resolution object which will be resolved by
@@ -143,7 +149,10 @@
setCurReferenceResolver(dataModelRootNode);
- // Current node to resolve, it can be a YANG type, YANG uses or YANG if-feature or YANG leafref.
+ /**
+ * Current node to resolve, it can be a YANG type, YANG uses or YANG if-feature or
+ * YANG leafref or YANG base or YANG identityref.
+ */
T entityToResolve = getEntityToResolveInfo().getEntityToResolve();
// Check if linking is already done
@@ -157,7 +166,7 @@
}
} else {
throw new DataModelException("Data Model Exception: Entity to resolved is other than " +
- "type/uses/if-feature/leafref");
+ "type/uses/if-feature/leafref/base/identityref");
}
// Push the initial entity to resolve in stack.
@@ -178,7 +187,10 @@
while (getPartialResolvedStack().size() != 0) {
- // Current node to resolve, it can be a YANG type or YANG uses.
+ /**
+ * Current node to resolve, it can be a YANG type or YANG uses or
+ * YANG if-feature or YANG leafref or YANG base or YANG identityref.
+ */
T entityToResolve = getCurrentEntityToResolveFromStack();
// Check if linking is already done
if (entityToResolve instanceof Resolvable) {
@@ -227,6 +239,10 @@
errorInfo = GROUPING_LINKER_ERROR;
} else if (resolvable instanceof YangIfFeature) {
errorInfo = FEATURE_LINKER_ERROR;
+ } else if (resolvable instanceof YangBase) {
+ errorInfo = BASE_LINKER_ERROR;
+ } else if (resolvable instanceof YangIdentityRef) {
+ errorInfo = IDENTITYREF_LINKER_ERROR;
} else {
errorInfo = LEAFREF_LINKER_ERROR;
}
@@ -246,14 +262,16 @@
} else {
throw new DataModelException(
- "Data Model Exception: Entity to resolved is other than type/uses/if-feature/leafref");
+ "Data Model Exception: Entity to resolved is other than type/uses/if-feature" +
+ "/leafref/base/identityref");
}
}
}
/**
- * Adds the leafref type to the type, which has derived type referring to typedef with leafref type.
+ * Adds the leafref/identityref type to the type, which has derived type referring to
+ * typedef with leafref/identityref type.
*/
private void addDerivedRefTypeToRefTypeResolutionList() throws DataModelException {
@@ -279,9 +297,10 @@
YangDerivedInfo derivedInfo = (YangDerivedInfo) yangType.getDataTypeExtendedInfo();
/*
- * If the derived types referred type is not leaf ref return
+ * If the derived types referred type is not leafref/identityref return
*/
- if (derivedInfo.getEffectiveBuiltInType() != YangDataTypes.LEAFREF) {
+ if ((derivedInfo.getEffectiveBuiltInType() != YangDataTypes.LEAFREF) &&
+ (derivedInfo.getEffectiveBuiltInType() != YangDataTypes.IDENTITYREF)) {
return;
}
@@ -292,28 +311,49 @@
extendedInfo = (T) derivedInfoFromTypedef.getReferredTypeDef().getTypeDefBaseType()
.getDataTypeExtendedInfo();
}
+
/*
- * Backup the derived types leaf ref info, delete all the info in
- * current type, but for resolution status as resolved. Copy the backed
- * up leaf ref to types extended info, create a leaf ref resolution info
- * using the current resolution info and add to leaf ref resolution
- * list.
+ * Backup the derived types leafref/identityref info, delete all the info in current type,
+ * but for resolution status as resolved. Copy the backed up leafref/identityref to types extended info,
+ * create a leafref/identityref resolution info using the current resolution info and
+ * add to leafref/identityref resolution list.
*/
- YangLeafRef leafRefInTypeDef = (YangLeafRef) extendedInfo;
- yangType.resetYangType();
+ if (derivedInfo.getEffectiveBuiltInType() == YangDataTypes.LEAFREF) {
+ YangLeafRef leafRefInTypeDef = (YangLeafRef) extendedInfo;
+ yangType.resetYangType();
- yangType.setResolvableStatus(RESOLVED);
- yangType.setDataType(YangDataTypes.LEAFREF);
- yangType.setDataTypeName(LEAFREF);
- yangType.setDataTypeExtendedInfo(leafRefInTypeDef);
- leafRefInTypeDef.setResolvableStatus(UNRESOLVED);
+ yangType.setResolvableStatus(RESOLVED);
+ yangType.setDataType(YangDataTypes.LEAFREF);
+ yangType.setDataTypeName(LEAFREF);
+ yangType.setDataTypeExtendedInfo(leafRefInTypeDef);
+ leafRefInTypeDef.setResolvableStatus(UNRESOLVED);
- // Add resolution information to the list.
- YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<>(leafRefInTypeDef,
- potentialAncestorWithReferredNode, getLineNumber(), getCharPosition());
- getCurReferenceResolver().addToResolutionList(resolutionInfoImpl,
- ResolvableType.YANG_LEAFREF);
- getCurReferenceResolver().resolveSelfFileLinking(ResolvableType.YANG_LEAFREF);
+ // Add resolution information to the list.
+ YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<>(leafRefInTypeDef,
+ potentialAncestorWithReferredNode,
+ getLineNumber(), getCharPosition());
+ getCurReferenceResolver().addToResolutionList(resolutionInfoImpl,
+ ResolvableType.YANG_LEAFREF);
+ getCurReferenceResolver().resolveSelfFileLinking(ResolvableType.YANG_LEAFREF);
+
+ } else if (derivedInfo.getEffectiveBuiltInType() == YangDataTypes.IDENTITYREF) {
+
+ YangIdentityRef identityRefInTypeDef = (YangIdentityRef) extendedInfo;
+ yangType.resetYangType();
+
+ yangType.setResolvableStatus(RESOLVED);
+ yangType.setDataType(YangDataTypes.IDENTITYREF);
+ yangType.setDataTypeName(IDENTITYREF);
+ yangType.setDataTypeExtendedInfo(identityRefInTypeDef);
+ identityRefInTypeDef.setResolvableStatus(UNRESOLVED);
+
+ // Add resolution information to the list.
+ YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<>(identityRefInTypeDef,
+ potentialAncestorWithReferredNode, getLineNumber(), getCharPosition());
+ getCurReferenceResolver().addToResolutionList(resolutionInfoImpl,
+ ResolvableType.YANG_IDENTITYREF);
+ getCurReferenceResolver().resolveSelfFileLinking(ResolvableType.YANG_IDENTITYREF);
+ }
}
/**
@@ -360,6 +400,10 @@
} else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) {
resolveSelfFileLinkingForLeafref(potentialAncestorWithReferredNode);
return;
+ } else if ((getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) ||
+ (getCurrentEntityToResolveFromStack() instanceof YangBase)) {
+ resolveSelfFileLinkingForBaseAndIdentityref();
+ return;
} else {
/**
@@ -453,6 +497,47 @@
}
/**
+ * Resolves self file linking for base/identityref.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ private void resolveSelfFileLinkingForBaseAndIdentityref()
+ throws DataModelException {
+
+ boolean referredIdentityFound = false;
+ String nodeName = null;
+
+ if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
+ nodeName = ((YangIdentityRef) getCurrentEntityToResolveFromStack()).getName();
+ }
+
+ if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
+ nodeName = ((YangBase) getCurrentEntityToResolveFromStack()).getBaseIdentifier().getName();
+ }
+
+ if (getCurReferenceResolver() instanceof YangModule) {
+ YangModule rootNode = (YangModule) getCurReferenceResolver();
+ // Sends list of nodes for finding the target identity.
+ referredIdentityFound = isIdentityReferenceFound(nodeName, rootNode);
+ } else if (getCurReferenceResolver() instanceof YangSubModule) {
+ YangSubModule rootNode = (YangSubModule) getCurReferenceResolver();
+ // Sends list of nodes for finding the target identity.
+ referredIdentityFound = isIdentityReferenceFound(nodeName, rootNode);
+ }
+
+ if (referredIdentityFound) {
+ return;
+ }
+
+ /*
+ * In case prefix is not present it's a candidate for inter-file resolution via include list.
+ */
+ if (getRefPrefix() == null) {
+ ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTRA_FILE_RESOLVED);
+ }
+ }
+
+ /**
* Returns the root parent with respect to the ancestor count from leafref.
*
* @param ancestorCount count of node where parent node can be reached
@@ -561,6 +646,41 @@
}
/**
+ * Returns the status of the referred identity found for base/identityref.
+ *
+ * @param nodeName the name of the base nodeidentifier/identityref nodeidentifier
+ * @param ancestorWithTheReferredNode the parent node of base/identityref
+ * @return status of referred base/identityref
+ * @throws DataModelException a violation of data model rules
+ */
+ private boolean isIdentityReferenceFound(String nodeName, YangNode ancestorWithTheReferredNode)
+ throws DataModelException {
+
+ // When child is not present return.
+ if (ancestorWithTheReferredNode.getChild() == null) {
+ return false;
+ }
+
+ ancestorWithTheReferredNode = ancestorWithTheReferredNode.getChild();
+
+ // Checks all the siblings under the node and returns the matched node.
+ YangNode nodeFound = isReferredNodeInSiblingProcessedForIdentity(ancestorWithTheReferredNode, nodeName);
+
+ if (nodeFound != null) {
+ // Adds reference link of entity to the node under resolution.
+ addReferredEntityLink(nodeFound, LINKED);
+
+ /**
+ * resolve the reference and update the partial resolution stack with any further recursive references
+ */
+ addUnresolvedRecursiveReferenceToStack(nodeFound);
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
* Fills the referred leaf or leaf-list inside the path predicates.
*
* @param ancestorWithTheReferredNode the actual node where YANG list will be present
@@ -856,6 +976,28 @@
}
/**
+ * Checks for the referred parent node for the base/identity.
+ *
+ * @param potentialReferredNode potential referred node
+ * @return the reffered parent node of base/identity.
+ * @throws DataModelException data model errors
+ */
+ private YangNode isReferredNodeInSiblingProcessedForIdentity(YangNode potentialReferredNode,
+ String referredNodeName) throws DataModelException {
+
+ while (potentialReferredNode != null) {
+ if (potentialReferredNode instanceof YangIdentity) {
+ // Check if the potential referred node is the actual referred node
+ if (isReferredNodeForIdentity(potentialReferredNode, referredNodeName)) {
+ return potentialReferredNode;
+ }
+ }
+ potentialReferredNode = potentialReferredNode.getNextSibling();
+ }
+ return null;
+ }
+
+ /**
* Checks if the current reference node name and the name in the path are equal.
*
* @param currentReferredNode the node where the reference is pointed
@@ -878,6 +1020,28 @@
}
/**
+ * Checks if the current reference node name and the name in the base/identityref base are equal.
+ *
+ * @param currentReferredNode the node where the reference is pointed
+ * @param nameOfIdentityRefBase name of the base in the base/identityref base
+ * @return status of the match between the name
+ * @throws DataModelException a violation of data model rules
+ */
+ private boolean isReferredNodeForIdentity(YangNode currentReferredNode, String nameOfIdentityRefBase)
+ throws DataModelException {
+
+ if ((getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) ||
+ (getCurrentEntityToResolveFromStack() instanceof YangBase)) {
+ /*
+ * Check if name of node name matches with the current reference node.
+ */
+ return currentReferredNode.getName().contentEquals(nameOfIdentityRefBase);
+ } else {
+ throw new DataModelException("Data Model Exception: Entity to resolved is other than identityref");
+ }
+ }
+
+ /**
* Checks for the referred node defined in a ancestor scope.
*
* @param potentialReferredNode potential referred node
@@ -946,8 +1110,18 @@
*/
return isNodeNameSameAsResolutionInfoName(potentialReferredNode);
}
+ } else if ((getCurrentEntityToResolveFromStack() instanceof YangBase) ||
+ (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef)) {
+ if (potentialReferredNode instanceof YangIdentity) {
+ /*
+ * Check if name of node name matches with the entity being
+ * resolved
+ */
+ return isNodeNameSameAsResolutionInfoName(potentialReferredNode);
+ }
} else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
+ throw new DataModelException("Data Model Exception: Entity to resolved is other than type/" +
+ "uses/base/identityref");
}
return false;
}
@@ -977,6 +1151,16 @@
}
} else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
return isFeatureDefinedInNode(node);
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
+ if (node.getName().contentEquals(
+ ((YangBase) getCurrentEntityToResolveFromStack()).getBaseIdentifier().getName())) {
+ return true;
+ }
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
+ if (node.getName().contentEquals(
+ ((YangIdentityRef) getCurrentEntityToResolveFromStack()).getName())) {
+ return true;
+ }
} else {
throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
}
@@ -1020,8 +1204,13 @@
// do nothing , referred node is already set
} else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) {
// do nothing , referred node is already set
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
+ ((YangBase) getCurrentEntityToResolveFromStack()).setReferredIdentity((YangIdentity) referredNode);
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
+ ((YangIdentityRef) getCurrentEntityToResolveFromStack()).setReferredIdentity((YangIdentity) referredNode);
} else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
+ throw new DataModelException("Data Model Exception: Entity to resolved is other than type" +
+ "/uses/base/identityref");
}
// Sets the resolution status in inside the type/uses.
@@ -1062,6 +1251,15 @@
} else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) {
// do nothing , referred node is already set
throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
+ } else if ((getCurrentEntityToResolveFromStack() instanceof YangBase) ||
+ (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef)) {
+ /*
+ * Search if the identity has any un resolved base, if so return true, else return false.
+ */
+ addUnResolvedBaseToStack(referredNode);
+ } else {
+ throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses/" +
+ "base/identityref");
}
}
@@ -1109,6 +1307,26 @@
}
/**
+ * Returns if there is any unresolved base in identity.
+ *
+ * @param node module/submodule node
+ */
+ private void addUnResolvedBaseToStack(YangNode node) {
+
+ YangIdentity curNode = (YangIdentity) node;
+ if (curNode.getBaseNode() != null) {
+ if (curNode.getBaseNode().getResolvableStatus() != RESOLVED) {
+ YangEntityToResolveInfoImpl<YangBase> unResolvedEntityInfo = new YangEntityToResolveInfoImpl<>();
+ unResolvedEntityInfo.setEntityToResolve(curNode.getBaseNode());
+ unResolvedEntityInfo.setHolderOfEntityToResolve(node);
+ addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedEntityInfo);
+
+ }
+ }
+ }
+
+
+ /**
* Returns stack of YANG type with partially resolved YANG construct
* hierarchy.
*
@@ -1247,8 +1465,13 @@
refPrefix = ((YangIfFeature) getCurrentEntityToResolveFromStack()).getPrefix();
} else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) {
refPrefix = refPrefixForLeafRef();
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
+ refPrefix = ((YangBase) getCurrentEntityToResolveFromStack()).getBaseIdentifier().getPrefix();
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
+ refPrefix = ((YangIdentityRef) getCurrentEntityToResolveFromStack()).getPrefix();
} else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
+ throw new DataModelException("Data Model Exception: Entity to resolved is other than " +
+ "type/uses/base/identityref");
}
return refPrefix;
}
@@ -1392,6 +1615,10 @@
errorInfo = GROUPING_LINKER_ERROR;
} else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
errorInfo = FEATURE_LINKER_ERROR;
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
+ errorInfo = BASE_LINKER_ERROR;
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
+ errorInfo = IDENTITYREF_LINKER_ERROR;
} else {
errorInfo = LEAFREF_LINKER_ERROR;
}
@@ -1449,7 +1676,12 @@
setCurReferenceResolver((YangReferenceResolver) yangInclude.getIncludedNode());
return referredNode;
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
+ linkedNode = findRefIdentity(yangInclude.getIncludedNode());
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
+ linkedNode = findRefIdentityRef(yangInclude.getIncludedNode());
}
+
if (linkedNode != null) {
// Add the link to external entity.
addReferredEntityLink(linkedNode, INTER_FILE_LINKED);
@@ -1502,6 +1734,10 @@
setCurReferenceResolver((YangReferenceResolver) yangImport.getImportedNode());
return referredNode;
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
+ linkedNode = findRefIdentity(yangImport.getImportedNode());
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
+ linkedNode = findRefIdentityRef(yangImport.getImportedNode());
}
if (linkedNode != null) {
// Add the link to external entity.
@@ -1584,8 +1820,13 @@
return (T) ((YangIfFeature) getCurrentEntityToResolveFromStack()).getReferredFeatureHolder();
} else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) {
return (T) ((YangLeafRef) getCurrentEntityToResolveFromStack()).getReferredLeafOrLeafList();
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
+ return (T) ((YangBase) getCurrentEntityToResolveFromStack()).getReferredIdentity();
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
+ return (T) ((YangIdentityRef) getCurrentEntityToResolveFromStack()).getReferredIdentity();
} else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
+ throw new DataModelException("Data Model Exception: Entity to resolved is other than type" +
+ "/uses/base/identityref");
}
}
@@ -1651,4 +1892,45 @@
}
return null;
}
+
+ /**
+ * Finds the referred identity node at the root level of imported/included node.
+ *
+ * @param refNode module/sub-module node
+ * @return referred identity
+ */
+ private YangNode findRefIdentity(YangNode refNode) {
+ YangNode tmpNode = refNode.getChild();
+ while (tmpNode != null) {
+ if (tmpNode instanceof YangIdentity) {
+ if (tmpNode.getName()
+ .equals(((YangBase) getCurrentEntityToResolveFromStack()).getBaseIdentifier().getName())) {
+ return tmpNode;
+ }
+ }
+ tmpNode = tmpNode.getNextSibling();
+ }
+ return null;
+ }
+
+ /**
+ * Finds the referred identity node at the root level of imported/included node.
+ *
+ * @param refNode module/sub-module node
+ * @return referred identity
+ */
+ private YangNode findRefIdentityRef(YangNode refNode) {
+ YangNode tmpNode = refNode.getChild();
+ while (tmpNode != null) {
+ if (tmpNode instanceof YangIdentity) {
+ if (tmpNode.getName()
+ .equals(((YangIdentityRef) getCurrentEntityToResolveFromStack())
+ .getBaseIdentity().getName())) {
+ return tmpNode;
+ }
+ }
+ tmpNode = tmpNode.getNextSibling();
+ }
+ return null;
+ }
}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
index 443c071..a1daf0f 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
@@ -28,6 +28,7 @@
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.impl.listeners.AugmentListener;
import org.onosproject.yangutils.parser.impl.listeners.BaseFileListener;
+import org.onosproject.yangutils.parser.impl.listeners.BaseListener;
import org.onosproject.yangutils.parser.impl.listeners.BelongsToListener;
import org.onosproject.yangutils.parser.impl.listeners.BitListener;
import org.onosproject.yangutils.parser.impl.listeners.BitsListener;
@@ -42,7 +43,9 @@
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.IdentityrefListener;
import org.onosproject.yangutils.parser.impl.listeners.IfFeatureListener;
+import org.onosproject.yangutils.parser.impl.listeners.IdentityListener;
import org.onosproject.yangutils.parser.impl.listeners.ImportListener;
import org.onosproject.yangutils.parser.impl.listeners.IncludeListener;
import org.onosproject.yangutils.parser.impl.listeners.InputListener;
@@ -450,12 +453,12 @@
@Override
public void enterIdentityStatement(GeneratedYangParser.IdentityStatementContext ctx) {
- handleUnsupportedYangConstruct(YangConstructType.IDENTITY_DATA, ctx, CURRENTLY_UNSUPPORTED);
+ IdentityListener.processIdentityEntry(this, ctx);
}
@Override
public void exitIdentityStatement(GeneratedYangParser.IdentityStatementContext ctx) {
- // do nothing.
+ IdentityListener.processIdentityExit(this, ctx);
}
@Override
@@ -470,7 +473,7 @@
@Override
public void enterBaseStatement(GeneratedYangParser.BaseStatementContext ctx) {
- handleUnsupportedYangConstruct(YangConstructType.BASE_DATA, ctx, CURRENTLY_UNSUPPORTED);
+ BaseListener.processBaseEntry(this, ctx);
}
@Override
@@ -710,12 +713,12 @@
@Override
public void enterIdentityrefSpecification(GeneratedYangParser.IdentityrefSpecificationContext ctx) {
- // do nothing.
+ IdentityrefListener.processIdentityrefEntry(this, ctx);
}
@Override
public void exitIdentityrefSpecification(GeneratedYangParser.IdentityrefSpecificationContext ctx) {
- // do nothing.
+ IdentityrefListener.processIdentityrefExit(this, ctx);
}
@Override
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BaseListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BaseListener.java
new file mode 100644
index 0000000..1925375
--- /dev/null
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BaseListener.java
@@ -0,0 +1,116 @@
+/*
+ * 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.YangBase;
+import org.onosproject.yangutils.datamodel.YangIdentity;
+import org.onosproject.yangutils.datamodel.YangIdentityRef;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.linker.impl.YangResolutionInfoImpl;
+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.DataModelUtils.addResolutionInfo;
+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.*;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidNodeIdentifier;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.BASE_DATA;
+
+/**
+ * base-stmt = base-keyword sep identifier-ref-arg-str
+ * optsep stmtend*
+ * identifier-ref-arg = [prefix ":"] identifier
+ */
+
+/**
+ * Represents listener based call back function corresponding to the "base"
+ * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class BaseListener {
+
+ //Creates a new base listener.
+ private BaseListener() {
+ }
+
+ /**
+ * Performs validation and updates the data model tree when parser receives an
+ * input matching the grammar rule (base).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processBaseEntry(TreeWalkListener listener,
+ GeneratedYangParser.BaseStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, BASE_DATA, ctx.string().getText(), ENTRY);
+
+ YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.string().getText(), BASE_DATA, ctx);
+
+ Parsable tmpData = listener.getParsedDataStack().peek();
+
+ /**
+ * For identityref base node identifier is copied in identity listener itself, so no need to process
+ * base statement for indentityref
+ */
+ if (tmpData instanceof YangIdentityRef) {
+ return;
+ }
+
+ if (!(tmpData instanceof YangIdentity)) {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, BASE_DATA,
+ ctx.string().getText(), ENTRY));
+ }
+
+ YangBase yangBase = new YangBase();
+ yangBase.setBaseIdentifier(nodeIdentifier);
+ ((YangIdentity) tmpData).setBaseNode(yangBase);
+
+ int errorLine = ctx.getStart().getLine();
+ int errorPosition = ctx.getStart().getCharPositionInLine();
+
+ // Add resolution information to the list
+ YangResolutionInfoImpl resolutionInfo =
+ new YangResolutionInfoImpl<YangBase>(yangBase, (YangNode) tmpData, 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(YangResolutionInfoImpl<YangBase> resolutionInfo,
+ GeneratedYangParser.BaseStatementContext ctx) {
+
+ try {
+ addResolutionInfo(resolutionInfo);
+ } catch (DataModelException e) {
+ throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
+ BASE_DATA, ctx.string().getText(), EXIT, e.getMessage()));
+ }
+ }
+
+}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IdentityListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IdentityListener.java
new file mode 100644
index 0000000..d8dec2c
--- /dev/null
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IdentityListener.java
@@ -0,0 +1,123 @@
+/*
+ * 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.YangIdentity;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+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.GeneratedLanguage.JAVA_GENERATION;
+import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangIdentityNode;
+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.MISSING_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
+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.ListenerUtil.getValidIdentifier;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.IDENTITY_DATA;
+
+/**
+ * Reference: RFC6020 and YANG ANTLR Grammar.
+ *
+ * ABNF grammar as per RFC6020
+ * identity-stmt = identity-keyword sep identifier-arg-str optsep
+ * (";" /
+ * "{" stmtsep
+ * ;; these stmts can appear in any order
+ * [base-stmt stmtsep]
+ * [status-stmt stmtsep]
+ * [description-stmt stmtsep]
+ * [reference-stmt stmtsep]
+ * "}")
+ */
+
+/**
+ * Represents listener based call back function corresponding to the "identity"
+ * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class IdentityListener {
+
+ //Creates a identity listener.
+ private IdentityListener() {
+ }
+
+ /**
+ * Performs validations and update the data model tree when parser receives an input
+ * matching the grammar rule (identity).
+ *
+ * @param listener Listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processIdentityEntry(TreeWalkListener listener,
+ GeneratedYangParser.IdentityStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, IDENTITY_DATA, ctx.identifier().getText(), ENTRY);
+
+ String identifier = getValidIdentifier(ctx.identifier().getText(), IDENTITY_DATA, ctx);
+
+ YangIdentity identity = getYangIdentityNode(JAVA_GENERATION);
+ identity.setName(identifier);
+
+ Parsable curData = listener.getParsedDataStack().peek();
+ if (curData instanceof YangModule || curData instanceof YangSubModule) {
+ YangNode curNode = (YangNode) curData;
+ try {
+ curNode.addChild(identity);
+ } catch (DataModelException e) {
+ throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
+ IDENTITY_DATA, ctx.identifier().getText(), ENTRY, e.getMessage()));
+ }
+ // Push identity node to the stack.
+ listener.getParsedDataStack().push(identity);
+ } else {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITY_DATA,
+ ctx.identifier().getText(), ENTRY));
+ }
+
+ }
+
+ /**
+ * Performs validations and update the data model tree when parser exits from grammar
+ * rule (identity).
+ *
+ * @param listener Listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processIdentityExit(TreeWalkListener listener,
+ GeneratedYangParser.IdentityStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_CURRENT_HOLDER, IDENTITY_DATA, ctx.identifier().getText(), EXIT);
+
+ Parsable parsableType = listener.getParsedDataStack().pop();
+ if (!(parsableType instanceof YangIdentity)) {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITY_DATA,
+ ctx.identifier().getText(), EXIT));
+ }
+ }
+
+}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IdentityrefListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IdentityrefListener.java
new file mode 100644
index 0000000..49037e2
--- /dev/null
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IdentityrefListener.java
@@ -0,0 +1,214 @@
+/*
+ * 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.YangIdentityRef;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
+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.BASE_DATA;
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.IDENTITYREF_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.MISSING_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
+import static org.onosproject.yangutils.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;
+
+/**
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ * identityref-specification =
+ * base-stmt stmtsep
+ * base-stmt = base-keyword sep identifier-ref-arg-str
+ * optsep stmtend*
+ * identifier-ref-arg = [prefix ":"] identifier
+ */
+
+/**
+ * Represents listener based call back function corresponding to the "identityref"
+ * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class IdentityrefListener {
+
+ //Creates a new type listener.
+ private IdentityrefListener() {
+ }
+
+ /**
+ * Performs validation and updates the data model tree when parser receives an input
+ * matching the grammar rule (identityref).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processIdentityrefEntry(TreeWalkListener listener,
+ GeneratedYangParser.IdentityrefSpecificationContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, IDENTITYREF_DATA, "", ENTRY);
+
+ if (listener.getParsedDataStack().peek() instanceof YangType) {
+
+ YangIdentityRef identityRef = new YangIdentityRef();
+ Parsable typeData = listener.getParsedDataStack().pop();
+ YangDataTypes yangDataTypes = ((YangType) typeData).getDataType();
+ YangResolutionInfoImpl resolutionInfo;
+
+ // Validate node identifier.
+ YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.baseStatement().string().getText(),
+ BASE_DATA, ctx);
+ identityRef.setBaseIdentity(nodeIdentifier);
+ ((YangType) typeData).setDataTypeExtendedInfo(identityRef);
+
+ int errorLine = ctx.getStart().getLine();
+ int errorPosition = ctx.getStart().getCharPositionInLine();
+
+ Parsable tmpData = listener.getParsedDataStack().peek();
+ switch (tmpData.getYangConstructType()) {
+ case LEAF_DATA:
+
+ // Pop the stack entry to obtain the parent YANG node.
+ Parsable leaf = listener.getParsedDataStack().pop();
+ Parsable parentNodeOfLeaf = listener.getParsedDataStack().peek();
+
+ // Push the popped entry back to the stack.
+ listener.getParsedDataStack().push(leaf);
+
+ // Verify parent node of leaf
+ if (!(parentNodeOfLeaf instanceof YangNode)) {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
+ IDENTITYREF_DATA, ctx.getText(), EXIT));
+ }
+
+ identityRef.setResolvableStatus(UNRESOLVED);
+
+ // Add resolution information to the list
+ resolutionInfo = new YangResolutionInfoImpl<YangIdentityRef>(identityRef,
+ (YangNode) parentNodeOfLeaf, errorLine, errorPosition);
+ addToResolutionList(resolutionInfo, ctx);
+
+ break;
+ case LEAF_LIST_DATA:
+
+ // Pop the stack entry to obtain the parent YANG node.
+ Parsable leafList = listener.getParsedDataStack().pop();
+ Parsable parentNodeOfLeafList = listener.getParsedDataStack().peek();
+
+ // Push the popped entry back to the stack.
+ listener.getParsedDataStack().push(leafList);
+
+ // Verify parent node of leaf
+ if (!(parentNodeOfLeafList instanceof YangNode)) {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
+ IDENTITYREF_DATA, ctx.getText(), EXIT));
+ }
+
+ identityRef.setResolvableStatus(UNRESOLVED);
+
+ // Add resolution information to the list
+ resolutionInfo = new YangResolutionInfoImpl<YangIdentityRef>(identityRef,
+ (YangNode) parentNodeOfLeafList, errorLine, errorPosition);
+ addToResolutionList(resolutionInfo, ctx);
+ break;
+ case UNION_DATA:
+
+ Parsable parentNodeOfUnionNode = listener.getParsedDataStack().peek();
+
+ // Verify parent node of leaf
+ if (!(parentNodeOfUnionNode instanceof YangNode)) {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
+ IDENTITYREF_DATA, ctx.getText(), EXIT));
+ }
+
+ identityRef.setResolvableStatus(UNRESOLVED);
+
+ // Add resolution information to the list
+ resolutionInfo = new YangResolutionInfoImpl<YangIdentityRef>(identityRef,
+ (YangNode) parentNodeOfUnionNode, errorLine, errorPosition);
+ addToResolutionList(resolutionInfo, ctx);
+
+ break;
+ case TYPEDEF_DATA:
+ /**
+ * Do not add the identity ref to resolution list. It needs to be
+ * added to resolution list, when leaf/leaf list references to
+ * this typedef. At this time that leaf/leaf-list becomes the
+ * parent for the identityref.
+ */
+ break;
+ default:
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITYREF_DATA,
+ ctx.getText(), EXIT));
+ }
+ listener.getParsedDataStack().push(typeData);
+ listener.getParsedDataStack().push(identityRef);
+ } else {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITYREF_DATA, "", ENTRY));
+ }
+ }
+
+ /**
+ * Performs validations and update the data model tree when parser exits from grammar
+ * rule (identityref).
+ *
+ * @param listener Listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processIdentityrefExit(TreeWalkListener listener,
+ GeneratedYangParser.IdentityrefSpecificationContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_CURRENT_HOLDER, IDENTITYREF_DATA, ctx.getText(), EXIT);
+
+ Parsable parsableType = listener.getParsedDataStack().pop();
+ if (!(parsableType instanceof YangIdentityRef)) {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITYREF_DATA,
+ ctx.getText(), EXIT));
+ }
+ }
+
+ /**
+ * Adds to resolution list.
+ *
+ * @param resolutionInfo resolution information
+ * @param ctx context object of the grammar rule
+ */
+ private static void addToResolutionList(YangResolutionInfoImpl<YangIdentityRef> resolutionInfo,
+ GeneratedYangParser.IdentityrefSpecificationContext ctx) {
+ try {
+ addResolutionInfo(resolutionInfo);
+ } catch (DataModelException e) {
+ throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
+ IDENTITYREF_DATA, ctx.getText(), ENTRY, e.getMessage()));
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
index ebf9d97..5b50ff9 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
@@ -130,6 +130,10 @@
.peek()).resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
((YangReferenceResolver) listener.getParsedDataStack()
.peek()).resolveSelfFileLinking(ResolvableType.YANG_LEAFREF);
+ ((YangReferenceResolver) listener.getParsedDataStack()
+ .peek()).resolveSelfFileLinking(ResolvableType.YANG_BASE);
+ ((YangReferenceResolver) listener.getParsedDataStack()
+ .peek()).resolveSelfFileLinking(ResolvableType.YANG_IDENTITYREF);
} catch (DataModelException e) {
LinkerException linkerException = new LinkerException(e.getMessage());
linkerException.setLine(e.getLineNumber());
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
index 2132324..d2c4f48 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
@@ -135,6 +135,10 @@
.resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
((YangReferenceResolver) listener.getParsedDataStack().peek())
.resolveSelfFileLinking(ResolvableType.YANG_LEAFREF);
+ ((YangReferenceResolver) listener.getParsedDataStack().peek())
+ .resolveSelfFileLinking(ResolvableType.YANG_BASE);
+ ((YangReferenceResolver) listener.getParsedDataStack().peek())
+ .resolveSelfFileLinking(ResolvableType.YANG_IDENTITYREF);
} catch (DataModelException e) {
LinkerException linkerException = new LinkerException(e.getMessage());
linkerException.setLine(e.getLineNumber());
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
index 32955d5..e108d14 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
@@ -310,7 +310,11 @@
parserException = new ParserException("YANG file error : a type leafref" +
" must have one path statement.");
break;
- // TODO : decimal64, identity ref
+ case IDENTITYREF:
+ parserException = new ParserException("YANG file error : a type identityref" +
+ " must have base statement.");
+ break;
+ // TODO : decimal64,
default:
return;
}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
index 2aaa563..48ac0de 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
@@ -48,10 +48,8 @@
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.COLON;
import static org.onosproject.yangutils.utils.UtilConstants.CURRENT;
-import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
-import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_SQUARE_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
@@ -341,7 +339,6 @@
String[] tmpData = tmpIdentifierString.split(Pattern.quote(COLON));
if (tmpData.length == 1) {
YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier();
- checkForUnsupportedTypes(tmpData[0], yangConstruct, ctx);
nodeIdentifier.setName(getValidIdentifier(tmpData[0], yangConstruct, ctx));
return nodeIdentifier;
} else if (tmpData.length == 2) {
@@ -375,7 +372,6 @@
String[] tmpData = tmpIdentifierString.split(Pattern.quote(COLON));
if (tmpData.length == 1) {
YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier();
- checkForUnsupportedTypes(tmpData[0], yangConstruct, ctx);
nodeIdentifier.setName(getValidIdentifierForLeafref(tmpData[0], yangConstruct, ctx, yangLeafRef));
return nodeIdentifier;
} else if (tmpData.length == 2) {
@@ -706,24 +702,6 @@
}
/**
- * Checks whether the type is an unsupported type.
- *
- * @param typeName name of the type
- * @param yangConstruct yang construct to check if it is type
- * @param ctx yang construct's context to get the line number and character position
- */
- private static void checkForUnsupportedTypes(String typeName,
- YangConstructType yangConstruct, ParserRuleContext ctx) {
-
- if (yangConstruct == YangConstructType.TYPE_DATA) {
- if (typeName.equalsIgnoreCase(IDENTITYREF)) {
- handleUnsupportedYangConstruct(YangConstructType.IDENTITYREF_DATA,
- ctx, CURRENTLY_UNSUPPORTED);
- }
- }
- }
-
- /**
* Checks and return valid absolute schema node id.
*
* @param argumentString string from yang file
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedJavaFileType.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedJavaFileType.java
index d4666c0c..1a2b9b8 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedJavaFileType.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedJavaFileType.java
@@ -89,6 +89,11 @@
public static final int GENERATE_EVENT_SUBJECT_CLASS = 1024;
/**
+ * Identity listener class.
+ */
+ public static final int GENERATE_IDENTITY_CLASS = 2048;
+
+ /**
* Creates an instance of generate java file type.
*/
private GeneratedJavaFileType() {
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangDataModelFactory.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangDataModelFactory.java
index 4d68fe2..9ba4068 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangDataModelFactory.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangDataModelFactory.java
@@ -20,6 +20,7 @@
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.YangGrouping;
+import org.onosproject.yangutils.datamodel.YangIdentity;
import org.onosproject.yangutils.datamodel.YangInput;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
@@ -41,6 +42,7 @@
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaContainer;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaIdentity;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInput;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeaf;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeafList;
@@ -163,6 +165,24 @@
* generated
* @return the corresponding inherited node based on the target language
*/
+ public static YangIdentity getYangIdentityNode(GeneratedLanguage targetLanguage) {
+ switch (targetLanguage) {
+ case JAVA_GENERATION: {
+ return new YangJavaIdentity();
+ }
+ default: {
+ throw new TranslatorException("Only YANG to Java is supported.");
+ }
+ }
+ }
+
+ /**
+ * Returns based on the target language generate the inherited data model node.
+ *
+ * @param targetLanguage target language in which YANG mapping needs to be
+ * generated
+ * @return the corresponding inherited node based on the target language
+ */
public static YangGrouping getYangGroupingNode(GeneratedLanguage targetLanguage) {
switch (targetLanguage) {
case JAVA_GENERATION: {
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java
index 6df66af..52595c7 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java
@@ -20,7 +20,9 @@
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
import org.onosproject.yangutils.datamodel.YangEnumeration;
+import org.onosproject.yangutils.datamodel.YangIdentity;
import org.onosproject.yangutils.datamodel.YangLeafRef;
+import org.onosproject.yangutils.datamodel.YangIdentityRef;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
@@ -161,8 +163,10 @@
YangType<?> referredType = getReferredTypeFromLeafref(yangType);
return getJavaImportClass(referredType, isListAttr, pluginConfig);
case IDENTITYREF:
- //TODO:IDENTITYREF
- break;
+ YangIdentityRef identityRef = (YangIdentityRef) yangType.getDataTypeExtendedInfo();
+ YangIdentity identity = identityRef.getReferredIdentity();
+ return getCapitalCase(getCamelCase(((YangJavaIdentity) identity).
+ getName(), pluginConfig));
case EMPTY:
return BOOLEAN_WRAPPER;
case UNION:
@@ -196,8 +200,9 @@
YangType<?> referredType = getReferredTypeFromLeafref(yangType);
return getJavaImportClass(referredType, isListAttr, pluginConfig);
case IDENTITYREF:
- //TODO:IDENTITYREF
- break;
+ YangIdentityRef identityRef = (YangIdentityRef) yangType.getDataTypeExtendedInfo();
+ YangIdentity identity = identityRef.getReferredIdentity();
+ return getCapitalCase(getCamelCase(((YangJavaIdentity) identity).getName(), pluginConfig));
case EMPTY:
return BOOLEAN_DATA_TYPE;
case UNION:
@@ -212,7 +217,6 @@
return null;
}
}
- return null;
}
/**
@@ -253,8 +257,7 @@
YangType<?> referredType = getReferredTypeFromLeafref(yangType);
return getJavaImportPackage(referredType, isListAttr, conflictResolver);
case IDENTITYREF:
- //TODO:IDENTITYREF
- break;
+ return getIdentityRefPackage(yangType, conflictResolver);
case UNION:
return getUnionPackage(yangType, conflictResolver);
case INSTANCE_IDENTIFIER:
@@ -280,8 +283,7 @@
YangType<?> referredType = getReferredTypeFromLeafref(yangType);
return getJavaImportPackage(referredType, isListAttr, conflictResolver);
case IDENTITYREF:
- //TODO:IDENTITYREF
- break;
+ return getIdentityRefPackage(yangType, conflictResolver);
case EMPTY:
return JAVA_LANG;
case UNION:
@@ -294,7 +296,6 @@
return null;
}
}
- return null;
}
/**
@@ -361,6 +362,25 @@
}
/**
+ * Returns YANG identity's java package.
+ *
+ * @param type YANG type
+ * @param conflictResolver object of YANG to java naming conflict util
+ * @return YANG identity's java package
+ */
+ private static String getIdentityRefPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) {
+
+ if (!(type.getDataTypeExtendedInfo() instanceof YangIdentityRef)) {
+ throw new TranslatorException("type should have been identityref.");
+ }
+ YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
+ YangJavaIdentity identity = (YangJavaIdentity) (identityRef.getReferredIdentity());
+ if (identity.getJavaFileInfo().getPackage() == null) {
+ return getPackageFromParent(identity.getParent(), conflictResolver);
+ }
+ return identity.getJavaFileInfo().getPackage();
+ }
+ /**
* Returns package from parent node.
*
* @param parent parent YANG node
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaIdentity.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaIdentity.java
new file mode 100644
index 0000000..ec0e637
--- /dev/null
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaIdentity.java
@@ -0,0 +1,168 @@
+/*
+ * 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.translator.tojava.javamodel;
+
+import org.onosproject.yangutils.datamodel.YangIdentity;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
+import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
+import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
+import org.onosproject.yangutils.translator.tojava.JavaImportData;
+import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
+import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
+import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_IDENTITY_CLASS;
+import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.updatePackageInfo;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
+import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
+
+/**
+ * Represents input information extended to support java code generation.
+ */
+public class YangJavaIdentity extends YangIdentity
+ implements JavaCodeGeneratorInfo, JavaCodeGenerator {
+
+ //File type extension for java classes.
+ private static final String JAVA_FILE_EXTENSION = ".java";
+
+
+ //Contains the information of the java file being generated.
+ private JavaFileInfo javaFileInfo;
+
+ //Contains the information of the importd.
+ private transient JavaImportData importData;
+
+ /**
+ * File handle to maintain temporary java code fragments as per the code
+ * snippet types.
+ */
+ private TempJavaCodeFragmentFiles tempFileHandle;
+
+ /**
+ * Creates YANG java container object.
+ */
+ public YangJavaIdentity() {
+ setJavaFileInfo(new JavaFileInfo());
+ getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
+ importData = new JavaImportData();
+ }
+
+ /**
+ * Returns the generated java file information.
+ *
+ * @return generated java file information
+ */
+ @Override
+ public JavaFileInfo getJavaFileInfo() {
+ if (javaFileInfo == null) {
+ throw new TranslatorException("Missing java info in java datamodel node");
+ }
+ return javaFileInfo;
+ }
+
+ /**
+ * Sets the java file info object.
+ *
+ * @param javaInfo java file info object
+ */
+ @Override
+ public void setJavaFileInfo(JavaFileInfo javaInfo) {
+ javaFileInfo = javaInfo;
+ }
+
+ /**
+ * Returns the temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ @Override
+ public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
+ return tempFileHandle;
+ }
+
+ /**
+ * Sets temporary file handle.
+ *
+ * @param fileHandle temporary file handle
+ */
+ @Override
+ public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
+ tempFileHandle = fileHandle;
+ }
+
+ /**
+ * Prepare the information for java code generation corresponding to YANG
+ * container info.
+ *
+ * @param yangPlugin YANG plugin config
+ * @throws TranslatorException translator operation fail
+ */
+ @Override
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ try {
+ updatePackageInfo(this, yangPlugin);
+ JavaQualifiedTypeInfo basePkgInfo = new JavaQualifiedTypeInfo();
+ String className = getCapitalCase(getJavaFileInfo().getJavaName());
+ String path = getJavaFileInfo().getPackageFilePath();
+ createPackage(this);
+ List<String> imports = null;
+ boolean isQualified = false;
+
+ if (getBaseNode() != null && getBaseNode().getReferredIdentity() != null) {
+ if (!(getBaseNode().getReferredIdentity() instanceof YangJavaIdentity)) {
+ throw new TranslatorException("Failed to prepare generate code entry for base node");
+ }
+ YangJavaIdentity baseIdentity = (YangJavaIdentity) getBaseNode().getReferredIdentity();
+ String baseClassName = getCapitalCase(baseIdentity.getJavaFileInfo().getJavaName());
+ String basePkg = baseIdentity.getJavaFileInfo().getPackage();
+ basePkgInfo.setClassInfo(baseClassName);
+ basePkgInfo.setPkgInfo(basePkg);
+ isQualified = importData.addImportInfo(basePkgInfo, className, getJavaFileInfo().getPackage());
+ if (!isQualified) {
+ imports = importData.getImports();
+ }
+ }
+
+ File file = getFileObject(path, className, JAVA_FILE_EXTENSION, getJavaFileInfo());
+
+ initiateJavaFileGeneration(file, GENERATE_IDENTITY_CLASS, imports, this, className);
+ closeFile(file, false);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for identity node " + this.getName());
+ }
+ }
+
+ /**
+ * Create a java file using the YANG container info.
+ *
+ * @throws TranslatorException translator operation fail
+ */
+ @Override
+ public void generateCodeExit() throws TranslatorException {
+ /* Do nothing, file is already generated in entry*/
+ }
+}
+
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
index 69f6d3e..ab8134f 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
@@ -16,10 +16,13 @@
package org.onosproject.yangutils.translator.tojava.utils;
+import org.onosproject.yangutils.datamodel.YangIdentity;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNotification;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaIdentity;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
@@ -27,6 +30,7 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_IDENTITY_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
@@ -57,6 +61,8 @@
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.SUBJECT;
+import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
/**
@@ -128,6 +134,8 @@
return getEventListenerDefinition(yangName);
case GENERATE_EVENT_SUBJECT_CLASS:
return getClassDefinition(yangName);
+ case GENERATE_IDENTITY_CLASS:
+ return getIdentityClassDefinition(yangName, curNode);
default:
return null;
}
@@ -214,6 +222,32 @@
}
/**
+ * Returns implementation file identity class definition.
+ *
+ * @param yangName file name
+ * @return identity class definition
+ */
+ private static String getIdentityClassDefinition(String yangName, YangNode curNode) {
+ if (!(curNode instanceof YangJavaIdentity)) {
+ throw new TranslatorException("Expected java identity instance node");
+ }
+ YangJavaIdentity identity = (YangJavaIdentity) curNode;
+ if (identity.getBaseNode() != null) {
+ YangIdentity baseIdentity = identity.getBaseNode().getReferredIdentity();
+ if (!(baseIdentity instanceof YangJavaIdentity)) {
+ throw new TranslatorException("Expected java identity instance node");
+ }
+
+ YangJavaIdentity baseJavaIdentity = (YangJavaIdentity) baseIdentity;
+ return PUBLIC + SPACE + ABSTRACT + SPACE + CLASS + SPACE + yangName + SPACE + EXTEND + SPACE
+ + getCapitalCase(baseJavaIdentity.getJavaFileInfo().getJavaName()) + SPACE +
+ OPEN_CURLY_BRACKET + NEW_LINE;
+ }
+
+ return PUBLIC + SPACE + ABSTRACT + SPACE + CLASS + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ }
+
+ /**
* Returns type file class definition.
*
* @param yangName file name
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
index fc24ff9..4a2b6f5 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
@@ -42,6 +42,7 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_IDENTITY_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
@@ -68,6 +69,7 @@
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getJavaPackageFromPackagePath;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
+import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT_ANNOTATION;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
@@ -294,6 +296,7 @@
}
file.createNewFile();
+
appendContents(file, genType, imports, curNode, className);
} catch (IOException e) {
throw new IOException("Failed to create " + file.getName() + " class file.");
@@ -348,6 +351,11 @@
appendHeaderContents(file, pkgString, importsList);
write(file, genType, EVENT_SUBJECT_CLASS, curNode, className);
break;
+ case GENERATE_IDENTITY_CLASS:
+ appendHeaderContents(file, pkgString, importsList);
+ write(file, genType, EVENT_SUBJECT_CLASS, curNode, className);
+ insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET);
+ break;
default:
break;
}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
index 032493c..d56a2ed 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -647,6 +647,11 @@
public static final String PUBLIC = "public";
/**
+ * Static attribute for abstract modifier.
+ */
+ public static final String ABSTRACT = "abstract";
+
+ /**
* Static attribute for protected modifier.
*/
public static final String PROTECTED = "protected";
@@ -1196,6 +1201,18 @@
+ "leaf/leaf-list for given leafref";
/**
+ * Static attribute for base linker error information.
+ */
+ public static final String BASE_LINKER_ERROR = "YANG file error: Unable to find base "
+ + "identity for given base";
+
+ /**
+ * Static attribute for identityref linker error information.
+ */
+ public static final String IDENTITYREF_LINKER_ERROR = "YANG file error: Unable to find base "
+ + "identity for given base";
+
+ /**
* Static attribute for reference.
*/
public static final String REFERENCE = "Reference";
diff --git a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/IdentityListenerTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/IdentityListenerTest.java
new file mode 100644
index 0000000..b0ae937
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/IdentityListenerTest.java
@@ -0,0 +1,220 @@
+/*
+ * 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.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onosproject.yangutils.datamodel.YangIdentity;
+import org.onosproject.yangutils.datamodel.YangIdentityRef;
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangLeafList;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeType;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.YangTypeDef;
+import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
+import org.onosproject.yangutils.datamodel.utils.builtindatatype.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.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+/**
+ * Test case for identity listener.
+ */
+public class IdentityListenerTest {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks for updating datamodel for identity/identityref.
+ */
+ @Test
+ public void processIdentityrefType() throws IOException, ParserException {
+
+ YangNode node = manager
+ .getDataModel("src/test/resources/IdentityListener.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("IdentityListener"));
+
+ YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
+ assertThat(yangIdentity.getName(), is("tunnel"));
+
+ yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling();
+ assertThat(yangIdentity.getName(), is("tunnel-type"));
+
+ yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling().getNextSibling();
+ assertThat(yangIdentity.getName(), is("ref-address-family"));
+
+ yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling().getNextSibling()
+ .getNextSibling();
+ assertThat(yangIdentity.getName(), is("ipv4-address-family"));
+ assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
+
+ yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling().getNextSibling()
+ .getNextSibling().getNextSibling();
+ assertThat(yangIdentity.getName(), is("ipv6-address-family"));
+ assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("tunnel"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
+ YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
+ assertThat(yangIdentityRef.getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+
+ ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
+ YangLeafList leafListInfo = leafListIterator.next();
+
+ // Check whether the information in the leaf is correct.
+ assertThat(leafListInfo.getName(), is("network-ref"));
+ assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref"));
+ assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
+ yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo());
+
+ // Check whether identityref type got resolved.
+ assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+ }
+
+ /**
+ * Checks for updating datamodel for intrafile resolution identity/identityref.
+ */
+ @Test
+ public void processIntraIdentityrefType() throws IOException, ParserException {
+
+ YangNode node = manager
+ .getDataModel("src/test/resources/IdentityIntraFile.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("IdentityIntraFile"));
+
+ YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
+ assertThat(yangIdentity.getName(), is("ipv4-address-family"));
+ assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.INTRA_FILE_RESOLVED));
+ }
+
+ /**
+ * Checks for updating datamodel for identityref used in tydedef.
+ */
+ @Test
+ public void processIdentityTypedefStatement() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/IdentityTypedef.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("Test"));
+
+ YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
+ assertThat(yangIdentity.getName(), is("tunnel"));
+
+ YangTypeDef typedef = (YangTypeDef) yangNode.getChild().getNextSibling();
+ assertThat(typedef.getName(), is("type15"));
+
+ YangType type = typedef.getTypeList().iterator().next();
+ assertThat(type.getDataType(), is(YangDataTypes.IDENTITYREF));
+ assertThat(type.getDataTypeName(), is("identityref"));
+
+ YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
+ assertThat(identityRef.getName(), is("tunnel"));
+ assertThat(identityRef.getBaseIdentity().getName(), is("tunnel"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("tunnel-value"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
+ YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
+ assertThat(yangIdentityRef.getName(), is("tunnel"));
+ assertThat(yangIdentityRef.getBaseIdentity().getName(), is("tunnel"));
+ assertThat(yangIdentityRef.getReferredIdentity().getName(), is("tunnel"));
+ assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+ }
+
+ /**
+ * Checks for updating datamodel for unresolved status of identityref used in tydedef.
+ */
+ @Test
+ public void processIdentityUnresolvedTypedefStatement() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/IdentityTypedefUnresolved.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("Test"));
+
+ YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
+ assertThat(yangIdentity.getName(), is("tunnel"));
+
+ YangTypeDef typedef = (YangTypeDef) yangNode.getChild().getNextSibling();
+ assertThat(typedef.getName(), is("type15"));
+
+ YangType type = typedef.getTypeList().iterator().next();
+ assertThat(type.getDataType(), is(YangDataTypes.IDENTITYREF));
+ assertThat(type.getDataTypeName(), is("identityref"));
+
+ YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
+ assertThat(identityRef.getName(), is("tunnel"));
+ assertThat(identityRef.getBaseIdentity().getName(), is("tunnel"));
+ assertThat(identityRef.getResolvableStatus(), is(ResolvableStatus.UNRESOLVED));
+
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/TypeListenerTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/TypeListenerTest.java
index 8891108..b6b497a 100644
--- a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/TypeListenerTest.java
+++ b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/TypeListenerTest.java
@@ -122,20 +122,6 @@
}
/**
- * Checks for unsupported type identityref.
- */
- @Test
- public void processIdentityrefType() throws IOException, ParserException {
-
- thrown.expect(ParserException.class);
- thrown.expectMessage("YANG file error : \"identityref\" is not supported in current version,"
- + " please check wiki for YANG utils road map.");
-
- YangNode node = manager
- .getDataModel("src/test/resources/IdentityrefInvalidIdentifier.yang");
- }
-
- /**
* Checks for type instance-identifier.
*/
@Test
diff --git a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/InterFileIdentityLinkingTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/InterFileIdentityLinkingTest.java
new file mode 100644
index 0000000..7805bf0
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/InterFileIdentityLinkingTest.java
@@ -0,0 +1,642 @@
+/*
+ * 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 org.apache.maven.plugin.MojoExecutionException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onosproject.yangutils.datamodel.YangIdentity;
+import org.onosproject.yangutils.datamodel.YangIdentityRef;
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangLeafList;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.YangTypeDef;
+import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
+import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
+import org.onosproject.yangutils.linker.exceptions.LinkerException;
+import org.onosproject.yangutils.linker.impl.YangLinkerManager;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
+
+import java.io.IOException;
+import java.util.ListIterator;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
+
+/**
+ * Test cases for testing inter file linking for identity.
+ */
+public class InterFileIdentityLinkingTest {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private final YangUtilManager utilManager = new YangUtilManager();
+ private final YangLinkerManager yangLinkerManager = new YangLinkerManager();
+
+ /**
+ * Checks inter file feature linking with imported file.
+ */
+ @Test
+ public void processIdentityInImportedFile()
+ throws IOException, ParserException, MojoExecutionException {
+
+ String searchDir = "src/test/resources/interfileidentityimport";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+
+ YangNode selfNode = null;
+ YangNode refNode1 = null;
+ YangNode refNode2 = null;
+
+ // Create YANG node set
+ yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
+
+ for (YangNode rootNode : utilManager.getYangNodeSet()) {
+ if (rootNode.getName().equals("IdentityIntraFile")) {
+ selfNode = rootNode;
+ } else if (rootNode.getName().equals("IdentityInModule")) {
+ refNode1 = rootNode;
+ } else {
+ refNode2 = rootNode;
+ }
+ }
+
+ // Check whether the data model tree returned is of type module.
+ assertThat(selfNode instanceof YangModule, is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("IdentityIntraFile"));
+
+ YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
+ assertThat(yangIdentity.getName(), is("ipv4-address-family"));
+ assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+
+ yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling();
+ assertThat(yangIdentity.getName(), is("ipv6-address-family"));
+ assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("tunnel"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
+ YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
+ assertThat(yangIdentityRef.getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+
+ ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
+ YangLeafList leafListInfo = leafListIterator.next();
+
+ // Check whether the information in the leaf is correct.
+ assertThat(leafListInfo.getName(), is("network-ref"));
+ assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref"));
+ assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
+ yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo());
+ assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+
+ }
+
+ /**
+ * Checks inter file feature linking with included file.
+ */
+ @Test
+ public void processIdentityInIncludedFile()
+ throws IOException, ParserException, MojoExecutionException {
+
+ String searchDir = "src/test/resources/interfileidentityinlude";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+
+ YangNode selfNode = null;
+ YangNode refNode1 = null;
+ YangNode refNode2 = null;
+
+ // Create YANG node set
+ yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+
+ // Carry out linking of sub module with module.
+ yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+
+ // Add references to include list.
+ yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
+
+ for (YangNode rootNode : utilManager.getYangNodeSet()) {
+ if (rootNode.getName().equals("syslog3")) {
+ selfNode = rootNode;
+ } else if (rootNode.getName().equals("syslog4")) {
+ refNode1 = rootNode;
+ } else {
+ refNode2 = rootNode;
+ }
+ }
+
+ // Check whether the data model tree returned is of type module.
+ assertThat(selfNode instanceof YangModule, is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("syslog3"));
+
+ YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
+ assertThat(yangIdentity.getName(), is("ipv4-address-family"));
+ assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+
+ yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling();
+ assertThat(yangIdentity.getName(), is("ipv6-address-family"));
+ assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("tunnel"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
+ YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
+ assertThat(yangIdentityRef.getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+
+ ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
+ YangLeafList leafListInfo = leafListIterator.next();
+
+ // Check whether the information in the leaf is correct.
+ assertThat(leafListInfo.getName(), is("network-ref"));
+ assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref"));
+ assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
+ yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo());
+ assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+ }
+
+ /**
+ * Checks inter file feature linking with imported file with dependency.
+ */
+ @Test
+ public void processIdentityInImportedFileWithDependency()
+ throws IOException, ParserException, MojoExecutionException {
+
+ String searchDir = "src/test/resources/interfileidentityimportdependency";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+
+ YangNode selfNode = null;
+ YangNode refNode1 = null;
+ YangNode refNode2 = null;
+
+ // Create YANG node set
+ yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
+
+ for (YangNode rootNode : utilManager.getYangNodeSet()) {
+ if (rootNode.getName().equals("syslog1")) {
+ selfNode = rootNode;
+ } else if (rootNode.getName().equals("syslog2")) {
+ refNode1 = rootNode;
+ } else {
+ refNode2 = rootNode;
+ }
+ }
+
+ // Check whether the data model tree returned is of type module.
+ assertThat(selfNode instanceof YangModule, is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("syslog1"));
+
+ YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
+ assertThat(yangIdentity.getName(), is("ipv4-address-family"));
+ assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+
+ yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling();
+ assertThat(yangIdentity.getName(), is("ipv6-address-family"));
+ assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("tunnel"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
+ YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
+ assertThat(yangIdentityRef.getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+
+ ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
+ YangLeafList leafListInfo = leafListIterator.next();
+
+ // Check whether the information in the leaf is correct.
+ assertThat(leafListInfo.getName(), is("network-ref"));
+ assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref"));
+ assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
+ yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo());
+ assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+ }
+
+ /**
+ * Checks inter file feature linking with included file with dependency.
+ */
+ @Test
+ public void processIdentityInIncludedFileWithDependency()
+ throws IOException, ParserException, MojoExecutionException {
+
+ String searchDir = "src/test/resources/interfileidentityincludedependency";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+
+ YangNode selfNode = null;
+ YangNode refNode1 = null;
+ YangNode refNode2 = null;
+
+ // Create YANG node set
+ yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+
+ // Carry out linking of sub module with module.
+ yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
+
+ // Add references to include list.
+ yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
+
+ for (YangNode rootNode : utilManager.getYangNodeSet()) {
+ if (rootNode.getName().equals("syslog1")) {
+ selfNode = rootNode;
+ } else if (rootNode.getName().equals("syslog2")) {
+ refNode1 = rootNode;
+ } else {
+ refNode2 = rootNode;
+ }
+ }
+
+ // Check whether the data model tree returned is of type module.
+ assertThat(selfNode instanceof YangModule, is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("syslog1"));
+
+ YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
+ assertThat(yangIdentity.getName(), is("ipv4-address-family"));
+ assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+
+ yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling();
+ assertThat(yangIdentity.getName(), is("ipv6-address-family"));
+ assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("tunnel"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
+ YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
+ assertThat(yangIdentityRef.getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+
+ ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
+ YangLeafList leafListInfo = leafListIterator.next();
+
+ // Check whether the information in the leaf is correct.
+ assertThat(leafListInfo.getName(), is("network-ref"));
+ assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref"));
+ assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
+ yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo());
+ assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+ }
+
+ /**
+ * Checks inter file feature linking with imported file with dependency
+ * feature undefined.
+ */
+ @Test
+ public void processIdentityInImportedFileWithDependencyUndefined()
+ throws IOException, LinkerException, MojoExecutionException {
+ thrown.expect(LinkerException.class);
+ thrown.expectMessage("YANG file error: Unable to find base identity for given base");
+
+ String searchDir = "src/test/resources/interfileidentityimportdependencyUndefined";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+
+ YangNode selfNode = null;
+ YangNode refNode1 = null;
+ YangNode refNode2 = null;
+
+ // Create YANG node set
+ yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
+ }
+
+ /**
+ * Checks inter file feature linking with included file with dependency
+ * feature undefined.
+ */
+ @Test
+ public void processIdentityInIncludedFileWithDependencyUndefined()
+ throws IOException, LinkerException, MojoExecutionException {
+ thrown.expect(LinkerException.class);
+ thrown.expectMessage("YANG file error: Unable to find base identity for given base");
+
+ String searchDir = "src/test/resources/interfileidentityincludedependencyUndefined";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+
+ YangNode selfNode = null;
+ YangNode refNode1 = null;
+ YangNode refNode2 = null;
+
+ // Create YANG node set
+ yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+
+ // Carry out linking of sub module with module.
+ yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+
+ // Add references to include list.
+ yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
+ }
+
+ /**
+ * Checks inter file feature linking with imported file.
+ */
+ @Test
+ public void processIdentityTypedefUnresolvedInImportedFile()
+ throws IOException, ParserException, MojoExecutionException {
+
+ String searchDir = "src/test/resources/interfileidentitytypedef";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+
+ YangNode selfNode = null;
+ YangNode refNode1 = null;
+ YangNode refNode2 = null;
+
+ // Create YANG node set
+ yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
+
+ for (YangNode rootNode : utilManager.getYangNodeSet()) {
+ if (rootNode.getName().equals("IdentityIntraFile")) {
+ selfNode = rootNode;
+ } else if (rootNode.getName().equals("IdentityInModule")) {
+ refNode1 = rootNode;
+ } else {
+ refNode2 = rootNode;
+ }
+ }
+ // Check whether the data model tree returned is of type module.
+ assertThat(selfNode instanceof YangModule, is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("IdentityIntraFile"));
+
+ YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
+ assertThat(yangIdentity.getName(), is("ipv4-address-family"));
+ assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+
+ yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling();
+ assertThat(yangIdentity.getName(), is("ipv6-address-family"));
+ assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("tunnel"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
+ YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
+ assertThat(yangIdentityRef.getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+
+ ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
+ YangLeafList leafListInfo = leafListIterator.next();
+
+ // Check whether the information in the leaf is correct.
+ assertThat(leafListInfo.getName(), is("network-ref"));
+ assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref"));
+ assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
+ yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo());
+ // Check whether leafref type got resolved.
+ assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+
+ YangTypeDef typedef = (YangTypeDef) yangNode.getChild().getNextSibling().getNextSibling();
+ assertThat(typedef.getName(), is("type15"));
+
+ YangType type = typedef.getTypeList().iterator().next();
+ assertThat(type.getDataType(), is(YangDataTypes.IDENTITYREF));
+ assertThat(type.getDataTypeName(), is("identityref"));
+
+ YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
+ assertThat(identityRef.getName(), is("ref-address-family"));
+ assertThat(identityRef.getBaseIdentity().getName(), is("ref-address-family"));
+ assertThat(identityRef.getResolvableStatus(), is(ResolvableStatus.UNRESOLVED));
+ }
+
+ /**
+ * Checks inter file feature linking with imported file.
+ */
+ @Test
+ public void processIdentityTypedefInImportedFile()
+ throws IOException, ParserException, MojoExecutionException {
+
+ String searchDir = "src/test/resources/interfileidentitytypedef";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+
+ YangNode selfNode = null;
+ YangNode refNode1 = null;
+ YangNode refNode2 = null;
+
+ // Create YANG node set
+ yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
+
+ for (YangNode rootNode : utilManager.getYangNodeSet()) {
+ if (rootNode.getName().equals("IdentityTypedef")) {
+ selfNode = rootNode;
+ } else if (rootNode.getName().equals("IdentityInModule")) {
+ refNode1 = rootNode;
+ } else {
+ refNode2 = rootNode;
+ }
+ }
+
+ // Check whether the data model tree returned is of type module.
+ assertThat(selfNode instanceof YangModule, is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("IdentityTypedef"));
+
+ YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
+ assertThat(yangIdentity.getName(), is("ipv4-address-family"));
+ assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+
+ yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling();
+ assertThat(yangIdentity.getName(), is("ipv6-address-family"));
+ assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+
+ YangTypeDef typedef = (YangTypeDef) yangNode.getChild().getNextSibling().getNextSibling();
+ assertThat(typedef.getName(), is("type15"));
+
+ YangType type = typedef.getTypeList().iterator().next();
+ assertThat(type.getDataType(), is(YangDataTypes.IDENTITYREF));
+ assertThat(type.getDataTypeName(), is("identityref"));
+
+ YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
+ assertThat(identityRef.getName(), is("ref-address-family"));
+ assertThat(identityRef.getBaseIdentity().getName(), is("ref-address-family"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("tunnel"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
+ YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
+ assertThat(yangIdentityRef.getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
+ assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+
+ ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
+ YangLeafList leafListInfo = leafListIterator.next();
+
+ // Check whether the information in the leaf is correct.
+ assertThat(leafListInfo.getName(), is("network-ref"));
+ assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref"));
+ assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
+ yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo());
+ // Check whether leafref type got resolved.
+ assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/IdentityInModule.yang b/utils/yangutils/plugin/src/test/resources/IdentityInModule.yang
new file mode 100644
index 0000000..5688615
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/IdentityInModule.yang
@@ -0,0 +1,14 @@
+module IdentityInModule{
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix IdentityInModule;
+
+ identity tunnel-type {
+ description
+ "Base identity from which specific tunnel types are derived.";
+ }
+
+ identity ref-address-family {
+ reference "http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml#address-family-numbers-2";
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/IdentityIntraFile.yang b/utils/yangutils/plugin/src/test/resources/IdentityIntraFile.yang
new file mode 100644
index 0000000..c61fcfb
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/IdentityIntraFile.yang
@@ -0,0 +1,23 @@
+module IdentityIntraFile {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix IdentityIntraFile;
+
+ import "IdentityInModule" {
+ prefix "IdentityInModule";
+ }
+
+ identity ipv4-address-family {
+ base IdentityInModule:ref-address-family;
+ }
+
+ identity ipv6-address-family {
+ base IdentityInModule:ref-address-family;
+ }
+
+ leaf tunnel {
+ type identityref {
+ base IdentityInModule:ref-address-family;
+ }
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/IdentityListener.yang b/utils/yangutils/plugin/src/test/resources/IdentityListener.yang
new file mode 100644
index 0000000..a7ef4d2
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/IdentityListener.yang
@@ -0,0 +1,39 @@
+module IdentityListener{
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix IdentityListener;
+
+ identity tunnel {
+ description
+ "Base identity from which specific tunnel types are derived.";
+ }
+
+ identity tunnel-type {
+ description
+ "Base identity from which specific tunnel types are derived.";
+ }
+
+ identity ref-address-family {
+ reference "http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml#address-family-numbers-2";
+ }
+
+ identity ipv4-address-family {
+ base ref-address-family;
+ }
+
+ identity ipv6-address-family {
+ base ref-address-family;
+ }
+
+ leaf tunnel {
+ type identityref {
+ base ref-address-family;
+ }
+ }
+
+ leaf-list network-ref {
+ type identityref {
+ base ref-address-family;
+ }
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/IdentityTypedef.yang b/utils/yangutils/plugin/src/test/resources/IdentityTypedef.yang
new file mode 100644
index 0000000..6e8f603
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/IdentityTypedef.yang
@@ -0,0 +1,20 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+
+ identity tunnel {
+ description
+ "Base identity from which specific tunnel types are derived.";
+ }
+
+ leaf tunnel-value {
+ type type15;
+ }
+
+ typedef type15 {
+ type identityref {
+ base tunnel;
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/IdentityTypedefUnresolved.yang b/utils/yangutils/plugin/src/test/resources/IdentityTypedefUnresolved.yang
new file mode 100644
index 0000000..d837fd1
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/IdentityTypedefUnresolved.yang
@@ -0,0 +1,16 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+
+ identity tunnel {
+ description
+ "Base identity from which specific tunnel types are derived.";
+ }
+
+ typedef type15 {
+ type identityref {
+ base tunnel;
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/IdentityrefInvalidIdentifier.yang b/utils/yangutils/plugin/src/test/resources/IdentityrefInvalidIdentifier.yang
deleted file mode 100644
index 99a8129..0000000
--- a/utils/yangutils/plugin/src/test/resources/IdentityrefInvalidIdentifier.yang
+++ /dev/null
@@ -1,11 +0,0 @@
-module Test {
- yang-version 1;
- namespace http://huawei.com;
- prefix Ant;
- grouping currentcheck {
- leaf invalid-interval {
- type identityref {
- }
- }
- }
-}
diff --git a/utils/yangutils/plugin/src/test/resources/identityRef/identityRef.yang b/utils/yangutils/plugin/src/test/resources/identityRef/identityRef.yang
new file mode 100644
index 0000000..a7389e7
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/identityRef/identityRef.yang
@@ -0,0 +1,19 @@
+module IdentityTest{
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix IdentityTest;
+
+ identity ref-address-family {
+ description "ref-address-family";
+ }
+
+ identity ipv4-address-family {
+ base ref-address-family;
+ }
+
+ leaf tunnel {
+ type identityref {
+ base ref-address-family;
+ }
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/interfileidentityimport/IdentityInModule.yang b/utils/yangutils/plugin/src/test/resources/interfileidentityimport/IdentityInModule.yang
new file mode 100644
index 0000000..efaadd6
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfileidentityimport/IdentityInModule.yang
@@ -0,0 +1,15 @@
+
+module IdentityInModule{
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix IdentityInModule;
+
+ identity tunnel-type {
+ description
+ "Base identity from which specific tunnel types are derived.";
+ }
+
+ identity ref-address-family {
+ reference "http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml#address-family-numbers-2";
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/interfileidentityimport/IdentityIntraFile.yang b/utils/yangutils/plugin/src/test/resources/interfileidentityimport/IdentityIntraFile.yang
new file mode 100644
index 0000000..4036e97
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfileidentityimport/IdentityIntraFile.yang
@@ -0,0 +1,29 @@
+module IdentityIntraFile {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix IdentityIntraFile;
+
+ import "IdentityInModule" {
+ prefix "IdentityInModule";
+ }
+
+ identity ipv4-address-family {
+ base IdentityInModule:ref-address-family;
+ }
+
+ identity ipv6-address-family {
+ base IdentityInModule:ref-address-family;
+ }
+
+ leaf tunnel {
+ type identityref {
+ base IdentityInModule:ref-address-family;
+ }
+ }
+
+ leaf-list network-ref {
+ type identityref {
+ base IdentityInModule:ref-address-family;
+ }
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/interfileidentityimportdependency/featurefile1.yang b/utils/yangutils/plugin/src/test/resources/interfileidentityimportdependency/featurefile1.yang
new file mode 100644
index 0000000..b808b11
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfileidentityimportdependency/featurefile1.yang
@@ -0,0 +1,30 @@
+module syslog1 {
+ yang-version 1;
+ namespace "http://huawei1.com";
+ prefix "sys1";
+
+ import "syslog2" {
+ prefix "sys2";
+ }
+
+ identity ipv4-address-family {
+ base sys2:ref-address-family;
+ }
+
+ identity ipv6-address-family {
+ base sys2:ref-address-family;
+ }
+
+ leaf tunnel {
+ type identityref {
+ base sys2:ref-address-family;
+ }
+ }
+
+ leaf-list network-ref {
+ type identityref {
+ base sys2:ref-address-family;
+ }
+ }
+
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfileidentityimportdependency/featurefile2.yang b/utils/yangutils/plugin/src/test/resources/interfileidentityimportdependency/featurefile2.yang
new file mode 100644
index 0000000..2469e24
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfileidentityimportdependency/featurefile2.yang
@@ -0,0 +1,17 @@
+module syslog2 {
+ yang-version 1;
+ namespace "http://huawei2.com";
+ prefix "sys2";
+
+ import "syslog3" {
+ prefix "sys3";
+ }
+
+ identity tunnel-type {
+ base sys3:final-address-family;
+ }
+
+ identity ref-address-family {
+ base sys3:final-address-family;
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfileidentityimportdependency/featurefile3.yang b/utils/yangutils/plugin/src/test/resources/interfileidentityimportdependency/featurefile3.yang
new file mode 100644
index 0000000..f460bd1
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfileidentityimportdependency/featurefile3.yang
@@ -0,0 +1,10 @@
+module syslog3 {
+ yang-version 1;
+ namespace "http://huawei3.com";
+ prefix "sys3";
+
+ identity final-address-family {
+ description
+ "Base identity from which specific tunnel types are derived.";
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfileidentityimportdependencyUndefined/featurefile1.yang b/utils/yangutils/plugin/src/test/resources/interfileidentityimportdependencyUndefined/featurefile1.yang
new file mode 100644
index 0000000..ec2e48c
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfileidentityimportdependencyUndefined/featurefile1.yang
@@ -0,0 +1,29 @@
+module syslog1 {
+ yang-version 1;
+ namespace "http://huawei1.com";
+ prefix "sys1";
+
+ import "syslog2" {
+ prefix "sys2";
+ }
+
+ identity ipv4-address-family {
+ base sys2:ref-address-family;
+ }
+
+ identity ipv6-address-family {
+ base sys2:ref-address-family;
+ }
+
+ leaf tunnel {
+ type identityref {
+ base sys2:ref-address-family;
+ }
+ }
+
+ leaf-list network-ref {
+ type identityref {
+ base sys2:ref-address-family;
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfileidentityimportdependencyUndefined/featurefile2.yang b/utils/yangutils/plugin/src/test/resources/interfileidentityimportdependencyUndefined/featurefile2.yang
new file mode 100644
index 0000000..25e66af
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfileidentityimportdependencyUndefined/featurefile2.yang
@@ -0,0 +1,18 @@
+module syslog2 {
+ yang-version 1;
+ namespace "http://huawei2.com";
+ prefix "sys2";
+
+ import "syslog3" {
+ prefix "sys3";
+ }
+
+ identity tunnel-type {
+ base sys3:final-address-family;
+ }
+
+ identity ref-address-family {
+ base sys3:final-address-family;
+ }
+}
+
diff --git a/utils/yangutils/plugin/src/test/resources/interfileidentityimportdependencyUndefined/featurefile3.yang b/utils/yangutils/plugin/src/test/resources/interfileidentityimportdependencyUndefined/featurefile3.yang
new file mode 100644
index 0000000..f638139
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfileidentityimportdependencyUndefined/featurefile3.yang
@@ -0,0 +1,5 @@
+module syslog3 {
+ yang-version 1;
+ namespace "http://huawei3.com";
+ prefix "sys3";
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfileidentityincludedependency/featurefile1.yang b/utils/yangutils/plugin/src/test/resources/interfileidentityincludedependency/featurefile1.yang
new file mode 100644
index 0000000..fe987ea
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfileidentityincludedependency/featurefile1.yang
@@ -0,0 +1,27 @@
+module syslog1 {
+ yang-version 1;
+ namespace "http://huawei3.com";
+ prefix "sys1";
+
+ include "syslog2";
+
+ identity ipv4-address-family {
+ base ref-address-family;
+ }
+
+ identity ipv6-address-family {
+ base ref-address-family;
+ }
+
+ leaf tunnel {
+ type identityref {
+ base ref-address-family;
+ }
+ }
+
+ leaf-list network-ref {
+ type identityref {
+ base ref-address-family;
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfileidentityincludedependency/featurefile2.yang b/utils/yangutils/plugin/src/test/resources/interfileidentityincludedependency/featurefile2.yang
new file mode 100644
index 0000000..14fd83c
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfileidentityincludedependency/featurefile2.yang
@@ -0,0 +1,19 @@
+submodule syslog2 {
+ yang-version 1;
+ belongs-to "syslog1" {
+ prefix "sys1";
+ }
+
+ import "syslog3" {
+ prefix "sys3";
+ }
+
+ identity tunnel-type {
+ base sys3:final-address-family;
+ }
+
+ identity ref-address-family {
+ base sys3:final-address-family;
+ }
+}
+
diff --git a/utils/yangutils/plugin/src/test/resources/interfileidentityincludedependency/featurefile3.yang b/utils/yangutils/plugin/src/test/resources/interfileidentityincludedependency/featurefile3.yang
new file mode 100644
index 0000000..aa056f0
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfileidentityincludedependency/featurefile3.yang
@@ -0,0 +1,10 @@
+module syslog3 {
+ yang-version 1;
+ namespace "http://huawei3.com";
+ prefix "sys3";
+
+ identity final-address-family {
+ description
+ "Base identity from which specific tunnel types are derived.";
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfileidentityincludedependencyUndefined/featurefile1.yang b/utils/yangutils/plugin/src/test/resources/interfileidentityincludedependencyUndefined/featurefile1.yang
new file mode 100644
index 0000000..bc4878f
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfileidentityincludedependencyUndefined/featurefile1.yang
@@ -0,0 +1,27 @@
+module syslog1 {
+ yang-version 1;
+ namespace "http://huawei3.com";
+ prefix "sys1";
+
+ include "syslog2";
+
+ identity ipv4-address-family {
+ base sys2:ref-address-family;
+ }
+
+ identity ipv6-address-family {
+ base sys2:ref-address-family;
+ }
+
+ leaf tunnel {
+ type identityref {
+ base sys2:ref-address-family;
+ }
+ }
+
+ leaf-list network-ref {
+ type identityref {
+ base sys2:ref-address-family;
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfileidentityincludedependencyUndefined/featurefile2.yang b/utils/yangutils/plugin/src/test/resources/interfileidentityincludedependencyUndefined/featurefile2.yang
new file mode 100644
index 0000000..14fd83c
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfileidentityincludedependencyUndefined/featurefile2.yang
@@ -0,0 +1,19 @@
+submodule syslog2 {
+ yang-version 1;
+ belongs-to "syslog1" {
+ prefix "sys1";
+ }
+
+ import "syslog3" {
+ prefix "sys3";
+ }
+
+ identity tunnel-type {
+ base sys3:final-address-family;
+ }
+
+ identity ref-address-family {
+ base sys3:final-address-family;
+ }
+}
+
diff --git a/utils/yangutils/plugin/src/test/resources/interfileidentityincludedependencyUndefined/featurefile3.yang b/utils/yangutils/plugin/src/test/resources/interfileidentityincludedependencyUndefined/featurefile3.yang
new file mode 100644
index 0000000..f638139
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfileidentityincludedependencyUndefined/featurefile3.yang
@@ -0,0 +1,5 @@
+module syslog3 {
+ yang-version 1;
+ namespace "http://huawei3.com";
+ prefix "sys3";
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfileidentityinlude/IdentityInModule.yang b/utils/yangutils/plugin/src/test/resources/interfileidentityinlude/IdentityInModule.yang
new file mode 100644
index 0000000..e42ad86
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfileidentityinlude/IdentityInModule.yang
@@ -0,0 +1,27 @@
+module syslog3 {
+ yang-version 1;
+ namespace "http://huawei3.com";
+ prefix "sys3";
+
+ include "syslog4";
+
+ identity ipv4-address-family {
+ base ref-address-family;
+ }
+
+ identity ipv6-address-family {
+ base ref-address-family;
+ }
+
+ leaf tunnel {
+ type identityref {
+ base ref-address-family;
+ }
+ }
+
+ leaf-list network-ref {
+ type identityref {
+ base ref-address-family;
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfileidentityinlude/IdentityIntraFile.yang b/utils/yangutils/plugin/src/test/resources/interfileidentityinlude/IdentityIntraFile.yang
new file mode 100644
index 0000000..ffa1a7d
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfileidentityinlude/IdentityIntraFile.yang
@@ -0,0 +1,15 @@
+submodule syslog4 {
+ yang-version 1;
+ belongs-to "syslog3" {
+ prefix "sys3";
+ }
+
+ identity tunnel-type {
+ description
+ "Base identity from which specific tunnel types are derived.";
+ }
+
+ identity ref-address-family {
+ reference "http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml#address-family-numbers-2";
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/interfileidentitytypedef/IdentityInModule.yang b/utils/yangutils/plugin/src/test/resources/interfileidentitytypedef/IdentityInModule.yang
new file mode 100644
index 0000000..5688615
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfileidentitytypedef/IdentityInModule.yang
@@ -0,0 +1,14 @@
+module IdentityInModule{
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix IdentityInModule;
+
+ identity tunnel-type {
+ description
+ "Base identity from which specific tunnel types are derived.";
+ }
+
+ identity ref-address-family {
+ reference "http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml#address-family-numbers-2";
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/interfileidentitytypedef/IdentityIntraFile.yang b/utils/yangutils/plugin/src/test/resources/interfileidentitytypedef/IdentityIntraFile.yang
new file mode 100644
index 0000000..fcb2984
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfileidentitytypedef/IdentityIntraFile.yang
@@ -0,0 +1,35 @@
+module IdentityIntraFile {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix IdentityIntraFile;
+
+ import "IdentityInModule" {
+ prefix "IdentityInModule";
+ }
+
+ identity ipv4-address-family {
+ base IdentityInModule:ref-address-family;
+ }
+
+ identity ipv6-address-family {
+ base IdentityInModule:ref-address-family;
+ }
+
+ leaf tunnel {
+ type identityref {
+ base IdentityInModule:ref-address-family;
+ }
+ }
+
+ leaf-list network-ref {
+ type identityref {
+ base IdentityInModule:ref-address-family;
+ }
+ }
+
+ typedef type15 {
+ type identityref {
+ base IdentityInModule:ref-address-family;
+ }
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/interfileidentitytypedef/IdentityTypedef.yang b/utils/yangutils/plugin/src/test/resources/interfileidentitytypedef/IdentityTypedef.yang
new file mode 100644
index 0000000..6a58976
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfileidentitytypedef/IdentityTypedef.yang
@@ -0,0 +1,31 @@
+module IdentityTypedef {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix IdentityTypedef;
+
+ import "IdentityInModule" {
+ prefix "IdentityInModule";
+ }
+
+ identity ipv4-address-family {
+ base IdentityInModule:ref-address-family;
+ }
+
+ identity ipv6-address-family {
+ base IdentityInModule:ref-address-family;
+ }
+
+ leaf tunnel {
+ type type15;
+ }
+
+ leaf-list network-ref {
+ type type15;
+ }
+
+ typedef type15 {
+ type identityref {
+ base IdentityInModule:ref-address-family;
+ }
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/interfileietf/ietf-te-types.yang b/utils/yangutils/plugin/src/test/resources/interfileietf/ietf-te-types.yang
index 6268832..ffa1984 100644
--- a/utils/yangutils/plugin/src/test/resources/interfileietf/ietf-te-types.yang
+++ b/utils/yangutils/plugin/src/test/resources/interfileietf/ietf-te-types.yang
@@ -56,7 +56,7 @@
reference "RFC3209";
}
- /*identity tunnel-type {
+ identity tunnel-type {
description
"Base identity from which specific tunnel types are
derived.";
@@ -254,7 +254,7 @@
base lsp-encoding-types;
description
"Line (e.g., 8B/10B) LSP encoding";
- }*/
+ }
/* TE basic features */
feature p2mp-te {
@@ -452,7 +452,7 @@
}
}
- /*identity route-usage-type {
+ identity route-usage-type {
description
"Base identity for route usage";
}
@@ -576,7 +576,7 @@
description
"The set of attribute filters associated with a
tunnel any of which renders a link unacceptable";
- }*/
+ }
typedef admin-group {
type binary {
@@ -605,7 +605,7 @@
description "SRLG type";
}
- /*identity path-computation-srlg-type {
+ identity path-computation-srlg-type {
description
"Base identity for SRLG path computation";
}
@@ -632,7 +632,7 @@
base path-computation-srlg-type;
description
"Include weighted SRLG check in path computation";
- }*/
+ }
typedef te-metric {
type uint32;