[ONOS-4670] Removal of Data Model dependencies on Linker
Change-Id: I3f9c5af30198ea31d743e06cea1764dcb306ec32
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/ResolvableType.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/ResolvableType.java
new file mode 100644
index 0000000..9521f41
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/ResolvableType.java
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+/**
+ * Type of the resolvable info.
+ */
+public enum ResolvableType {
+
+ /**
+ * Identifies the derived data type.
+ */
+ YANG_DERIVED_DATA_TYPE,
+
+ /**
+ * Identifies the uses.
+ */
+ YANG_USES
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangBelongsTo.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangBelongsTo.java
index 694df32..adf23ba 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangBelongsTo.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangBelongsTo.java
@@ -18,7 +18,6 @@
import java.util.Set;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
-import org.onosproject.yangutils.plugin.manager.YangFileInfo;
import org.onosproject.yangutils.utils.YangConstructType;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.findReferredNode;
@@ -194,13 +193,13 @@
/**
* Links the belongs to with a module.
*
- * @param yangFileInfoSet YANG file information set
+ * @param yangNodeSet YANG file information set
* @throws DataModelException a violation in data model rule
*/
- public void linkWithModule(Set<YangFileInfo> yangFileInfoSet)
+ public void linkWithModule(Set<YangNode> yangNodeSet)
throws DataModelException {
String belongsToModuleName = getBelongsToModuleName();
- YangNode moduleNode = findReferredNode(yangFileInfoSet, belongsToModuleName);
+ YangNode moduleNode = findReferredNode(yangNodeSet, belongsToModuleName);
if (moduleNode != null) {
if (moduleNode instanceof YangModule) {
setModuleNode(moduleNode);
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
index 3cfdc38..0cfff23 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
@@ -33,9 +33,9 @@
import static org.onosproject.yangutils.datamodel.YangDataTypes.UNION;
import static org.onosproject.yangutils.linker.ResolvableStatus.INTRA_FILE_RESOLVED;
import static org.onosproject.yangutils.linker.ResolvableStatus.RESOLVED;
-import static org.onosproject.yangutils.utils.RestrictionResolver.isOfRangeRestrictedType;
-import static org.onosproject.yangutils.utils.RestrictionResolver.processLengthRestriction;
-import static org.onosproject.yangutils.utils.RestrictionResolver.processRangeRestriction;
+import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.isOfRangeRestrictedType;
+import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.processLengthRestriction;
+import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.processRangeRestriction;
/**
* Represents the derived information.
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangEntityToResolveInfo.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangEntityToResolveInfo.java
new file mode 100644
index 0000000..77323f1
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangEntityToResolveInfo.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+/**
+ * Abstraction of information about entity being resolved.
+ *
+ * @param <T> type of entity being resolved, uses / grouping
+ */
+public interface YangEntityToResolveInfo<T> {
+
+ /**
+ * Retrieves the entity to be resolved.
+ *
+ * @return entity to be resolved
+ */
+ T getEntityToResolve();
+
+ /**
+ * Sets entity to be resolved.
+ *
+ * @param entityToResolve entity to be resolved
+ */
+ void setEntityToResolve(T entityToResolve);
+
+ /**
+ * Retrieves the parent node which contains the entity to be resolved.
+ *
+ * @return parent node which contains the entity to be resolved
+ */
+ YangNode getHolderOfEntityToResolve();
+
+ /**
+ * Sets parent node which contains the entity to be resolved.
+ *
+ * @param holderOfEntityToResolve parent node which contains the entity to
+ * be resolved
+ */
+ void setHolderOfEntityToResolve(YangNode holderOfEntityToResolve);
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangImport.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangImport.java
index ef5d25a..73c5670 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangImport.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangImport.java
@@ -18,7 +18,6 @@
import java.util.Set;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
-import org.onosproject.yangutils.plugin.manager.YangFileInfo;
import org.onosproject.yangutils.utils.YangConstructType;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.findReferredNode;
@@ -237,10 +236,10 @@
/**
* Adds reference to an import.
*
- * @param yangFileInfoSet YANG file info set
+ * @param yangNodeSet YANG file info set
* @throws DataModelException a violation of data model rules
*/
- public void addReferenceToImport(Set<YangFileInfo> yangFileInfoSet) throws DataModelException {
+ public void addReferenceToImport(Set<YangNode> yangNodeSet) throws DataModelException {
String importedModuleName = getModuleName();
String importedModuleRevision = getRevision();
YangNode moduleNode = null;
@@ -250,7 +249,7 @@
*/
if (importedModuleRevision != null) {
String importedModuleNameWithRevision = importedModuleName + "@" + importedModuleRevision;
- moduleNode = findReferredNode(yangFileInfoSet, importedModuleNameWithRevision);
+ moduleNode = findReferredNode(yangNodeSet, importedModuleNameWithRevision);
}
/*
@@ -258,7 +257,7 @@
* without revision if can't find with revision.
*/
if (moduleNode == null) {
- moduleNode = findReferredNode(yangFileInfoSet, importedModuleName);
+ moduleNode = findReferredNode(yangNodeSet, importedModuleName);
}
if (moduleNode != null) {
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangInclude.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangInclude.java
index d331a72..c979469 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangInclude.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangInclude.java
@@ -18,7 +18,6 @@
import java.util.Set;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
-import org.onosproject.yangutils.plugin.manager.YangFileInfo;
import org.onosproject.yangutils.utils.YangConstructType;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.findReferredNode;
@@ -173,11 +172,11 @@
/**
* Adds reference to an include.
*
- * @param yangFileInfoSet YANG file info set
+ * @param yangNodeSet YANG node set
* @return YANG sub module node
* @throws DataModelException a violation of data model rules
*/
- public YangSubModule addReferenceToInclude(Set<YangFileInfo> yangFileInfoSet) throws DataModelException {
+ public YangSubModule addReferenceToInclude(Set<YangNode> yangNodeSet) throws DataModelException {
String includedSubModuleName = getSubModuleName();
String includedSubModuleRevision = getRevision();
YangNode subModuleNode = null;
@@ -188,7 +187,7 @@
*/
if (includedSubModuleRevision != null) {
String includedSubModuleNameWithRevision = includedSubModuleName + "@" + includedSubModuleRevision;
- subModuleNode = findReferredNode(yangFileInfoSet, includedSubModuleNameWithRevision);
+ subModuleNode = findReferredNode(yangNodeSet, includedSubModuleNameWithRevision);
}
/*
@@ -196,7 +195,7 @@
* without revision if can't find with revision.
*/
if (subModuleNode == null) {
- subModuleNode = findReferredNode(yangFileInfoSet, includedSubModuleName);
+ subModuleNode = findReferredNode(yangNodeSet, includedSubModuleName);
}
if (subModuleNode != null) {
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangLengthRestriction.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangLengthRestriction.java
index 8556445..fa50bf7 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangLengthRestriction.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangLengthRestriction.java
@@ -26,7 +26,7 @@
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
-import org.onosproject.yangutils.utils.builtindatatype.YangUint64;
+import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangUint64;
/**
* Represents the restriction for length data type.
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
index 11b089d..4eab4c3 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
@@ -19,14 +19,8 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
-
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.linker.exceptions.LinkerException;
-import org.onosproject.yangutils.linker.ResolvableType;
-import org.onosproject.yangutils.linker.YangReferenceResolver;
-import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
import org.onosproject.yangutils.parser.Parsable;
-import org.onosproject.yangutils.plugin.manager.YangFileInfo;
import org.onosproject.yangutils.utils.YangConstructType;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
@@ -88,7 +82,7 @@
/**
* Reference:RFC 6020.
- *
+ * <p>
* The "contact" statement provides contact information for the module. The
* argument is a string that is used to specify contact information for the
* person or persons to whom technical queries concerning this module should
@@ -99,7 +93,7 @@
/**
* Reference:RFC 6020.
- *
+ * <p>
* The "description" statement takes as an argument a string that contains a
* human-readable textual description of this definition. The text is
* provided in a language (or languages) chosen by the module developer; for
@@ -134,7 +128,7 @@
/**
* Reference:RFC 6020.
- *
+ * <p>
* The "organization" statement defines the party responsible for this
* module. The argument is a string that is used to specify a textual
* description of the organization(s) under whose auspices this module was
@@ -209,8 +203,8 @@
public YangModule() {
super(YangNodeType.MODULE_NODE);
- derivedTypeResolutionList = new LinkedList<YangResolutionInfo>();
- usesResolutionList = new LinkedList<YangResolutionInfo>();
+ derivedTypeResolutionList = new LinkedList<>();
+ usesResolutionList = new LinkedList<>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
@@ -569,7 +563,7 @@
@Override
public void addToResolutionList(YangResolutionInfo resolutionInfo,
- ResolvableType type) {
+ ResolvableType type) {
if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
derivedTypeResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_USES) {
@@ -579,7 +573,7 @@
@Override
public void setResolutionList(List<YangResolutionInfo> resolutionList,
- ResolvableType type) {
+ ResolvableType type) {
if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
derivedTypeResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_USES) {
@@ -589,40 +583,32 @@
}
@Override
- public void addReferencesToImportList(Set<YangFileInfo> yangFileInfoSet)
- throws LinkerException {
+ public void addReferencesToImportList(Set<YangNode> yangNodeSet)
+ throws DataModelException {
Iterator<YangImport> importInfoIterator = getImportList().iterator();
// Run through the imported list to add references.
while (importInfoIterator.hasNext()) {
YangImport yangImport = importInfoIterator.next();
- try {
- yangImport.addReferenceToImport(yangFileInfoSet);
- } catch (DataModelException e) {
- throw new LinkerException(e.getMessage());
- }
+ yangImport.addReferenceToImport(yangNodeSet);
}
}
@Override
- public void addReferencesToIncludeList(Set<YangFileInfo> yangFileInfoSet)
- throws LinkerException {
+ public void addReferencesToIncludeList(Set<YangNode> yangNodeSet)
+ throws DataModelException {
Iterator<YangInclude> includeInfoIterator = getIncludeList().iterator();
// Run through the included list to add references.
while (includeInfoIterator.hasNext()) {
YangInclude yangInclude = includeInfoIterator.next();
YangSubModule subModule = null;
try {
- subModule = yangInclude.addReferenceToInclude(yangFileInfoSet);
+ subModule = yangInclude.addReferenceToInclude(yangNodeSet);
} catch (DataModelException e) {
- throw new LinkerException(e.getMessage());
+ throw e;
}
// Check if the referred sub-modules parent is self
if (!(subModule.getBelongsTo().getModuleNode() == this)) {
- try {
- yangInclude.reportIncludeError();
- } catch (DataModelException e) {
- throw new LinkerException(e.getMessage());
- }
+ yangInclude.reportIncludeError();
}
}
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangRangeInterval.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangRangeInterval.java
index 9ccd5ff..9914a51 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangRangeInterval.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangRangeInterval.java
@@ -13,7 +13,7 @@
limitations under the License.*/
package org.onosproject.yangutils.datamodel;
-import org.onosproject.yangutils.utils.builtindatatype.YangBuiltInDataTypeInfo;
+import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangBuiltInDataTypeInfo;
/**
* Represents single interval information of a range.
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java
index d645010..c624623 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java
@@ -21,9 +21,9 @@
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
-import org.onosproject.yangutils.utils.builtindatatype.YangBuiltInDataTypeInfo;
+import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangBuiltInDataTypeInfo;
-import static org.onosproject.yangutils.utils.builtindatatype.BuiltInTypeObjectFactory.getDataObjectFromString;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.BuiltInTypeObjectFactory.getDataObjectFromString;
import static com.google.common.base.Preconditions.checkNotNull;
/*-
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangReferenceResolver.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangReferenceResolver.java
new file mode 100644
index 0000000..8be3242
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangReferenceResolver.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.util.List;
+import java.util.Set;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+
+/**
+ * Abstraction of YANG dependency resolution information. Abstracted to obtain the
+ * resolution information.
+ */
+public interface YangReferenceResolver {
+
+ /**
+ * Returns unresolved resolution list.
+ *
+ * @param type resolvable type
+ * @return list of resolution information objects
+ */
+ List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type);
+
+ /**
+ * Adds to the resolution list.
+ *
+ * @param resolutionInfo resolution information
+ * @param type resolvable type
+ */
+ void addToResolutionList(YangResolutionInfo resolutionInfo, ResolvableType type);
+
+ /**
+ * Creates resolution list.
+ *
+ * @param resolutionList resolution list
+ * @param type resolvable type
+ */
+ void setResolutionList(List<YangResolutionInfo> resolutionList, ResolvableType type);
+
+ /**
+ * Returns unresolved imported list.
+ *
+ * @return unresolved imported list
+ */
+ List<YangImport> getImportList();
+
+ /**
+ * Adds to the import list.
+ *
+ * @param yangImport import to be added
+ */
+ void addToImportList(YangImport yangImport);
+
+ /**
+ * Create import list.
+ *
+ * @param importList import list
+ */
+ void setImportList(List<YangImport> importList);
+
+ /**
+ * Returns unresolved include list.
+ *
+ * @return unresolved include list
+ */
+ List<YangInclude> getIncludeList();
+
+ /**
+ * Adds to the include list.
+ *
+ * @param yangInclude include to be added
+ */
+ void addToIncludeList(YangInclude yangInclude);
+
+ /**
+ * Creates include list.
+ *
+ * @param includeList include list
+ */
+ void setIncludeList(List<YangInclude> includeList);
+
+ /**
+ * Returns prefix of resolution root node.
+ *
+ * @return prefix resolution root node prefix
+ */
+ String getPrefix();
+
+ /**
+ * Sets prefix of resolution list root node.
+ *
+ * @param prefix resolution root node prefix
+ */
+ void setPrefix(String prefix);
+
+ /**
+ * Resolves self file linking.
+ *
+ * @param type resolvable type
+ * @throws DataModelException a violation in data model rule
+ */
+ void resolveSelfFileLinking(ResolvableType type)
+ throws DataModelException;
+
+ /**
+ * Resolves inter file linking.
+ *
+ * @param type resolvable type
+ * @throws DataModelException a violation in data model rule
+ */
+ void resolveInterFileLinking(ResolvableType type)
+ throws DataModelException;
+
+ /**
+ * Adds references to include.
+ *
+ * @param yangNodeSet YANG node info set
+ * @throws DataModelException a violation of data model rules
+ */
+ void addReferencesToIncludeList(Set<YangNode> yangNodeSet)
+ throws DataModelException;
+
+ /**
+ * Adds references to import.
+ *
+ * @param yangNodeSet YANG node info set
+ * @throws DataModelException a violation of data model rules
+ */
+ void addReferencesToImportList(Set<YangNode> yangNodeSet)
+ throws DataModelException;
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangResolutionInfo.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangResolutionInfo.java
new file mode 100644
index 0000000..c63e832
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangResolutionInfo.java
@@ -0,0 +1,54 @@
+/*
+ * 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;
+
+/**
+ * Abstraction of resolution object which will be resolved by linker.
+ *
+ * @param <T> type of resolution entity uses / type
+ */
+public interface YangResolutionInfo<T> extends LocationInfo {
+
+ /**
+ * Resolves linking with all the ancestors node for a resolution info.
+ *
+ * @param dataModelRootNode module/sub-module node
+ * @throws DataModelException DataModelException a violation of data model
+ * rules
+ */
+ void resolveLinkingForResolutionInfo(YangReferenceResolver dataModelRootNode)
+ throws DataModelException;
+
+ /**
+ * Retrieves information about the entity that needs to be resolved.
+ *
+ * @return information about the entity that needs to be resolved
+ */
+ YangEntityToResolveInfo<T> getEntityToResolveInfo();
+
+ /**
+ * Performs inter file linking of uses/type referring to typedef/grouping
+ * of other YANG file.
+ *
+ * @param dataModelRootNode module/sub-module node
+ * @throws DataModelException a violation in data model rule
+ */
+ void linkInterFile(YangReferenceResolver dataModelRootNode)
+ throws DataModelException;
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangStringRestriction.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangStringRestriction.java
index 2a2ebf4..a701b64 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangStringRestriction.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangStringRestriction.java
@@ -19,7 +19,7 @@
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
-import org.onosproject.yangutils.utils.builtindatatype.YangUint64;
+import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangUint64;
/*-
* Reference RFC 6020.
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
index 89c49dd..b7f9223 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
@@ -19,14 +19,8 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
-
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.linker.exceptions.LinkerException;
-import org.onosproject.yangutils.linker.ResolvableType;
-import org.onosproject.yangutils.linker.YangReferenceResolver;
-import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
import org.onosproject.yangutils.parser.Parsable;
-import org.onosproject.yangutils.plugin.manager.YangFileInfo;
import org.onosproject.yangutils.utils.YangConstructType;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
@@ -206,8 +200,8 @@
*/
public YangSubModule() {
super(YangNodeType.SUB_MODULE_NODE);
- derivedTypeResolutionList = new LinkedList<YangResolutionInfo>();
- usesResolutionList = new LinkedList<YangResolutionInfo>();
+ derivedTypeResolutionList = new LinkedList<>();
+ usesResolutionList = new LinkedList<>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
@@ -548,7 +542,7 @@
@Override
public void addToResolutionList(YangResolutionInfo resolutionInfo,
- ResolvableType type) {
+ ResolvableType type) {
if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
derivedTypeResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_USES) {
@@ -558,7 +552,7 @@
@Override
public void setResolutionList(List<YangResolutionInfo> resolutionList,
- ResolvableType type) {
+ ResolvableType type) {
if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
derivedTypeResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_USES) {
@@ -570,50 +564,38 @@
/**
* Links the sub-module with module.
*
- * @param yangFileInfoSet YANG file information set
+ * @param yangNodeSet YANG file information set
* @throws DataModelException a violation in data model rule
*/
- public void linkWithModule(Set<YangFileInfo> yangFileInfoSet)
+ public void linkWithModule(Set<YangNode> yangNodeSet)
throws DataModelException {
- getBelongsTo().linkWithModule(yangFileInfoSet);
+ getBelongsTo().linkWithModule(yangNodeSet);
}
@Override
- public void addReferencesToIncludeList(Set<YangFileInfo> yangFileInfoSet)
- throws LinkerException {
+ public void addReferencesToIncludeList(Set<YangNode> yangNodeSet)
+ throws DataModelException {
Iterator<YangInclude> includeInfoIterator = getIncludeList().iterator();
// Run through the included list to add references.
while (includeInfoIterator.hasNext()) {
YangInclude yangInclude = includeInfoIterator.next();
YangSubModule subModule = null;
- try {
- subModule = yangInclude.addReferenceToInclude(yangFileInfoSet);
- } catch (DataModelException e) {
- throw new LinkerException(e.getMessage());
- }
+ subModule = yangInclude.addReferenceToInclude(yangNodeSet);
// Check if the referred sub-modules parent is self
if (!(subModule.getBelongsTo().getModuleNode() == getBelongsTo().getModuleNode())) {
- try {
- yangInclude.reportIncludeError();
- } catch (DataModelException e) {
- throw new LinkerException(e.getMessage());
- }
+ yangInclude.reportIncludeError();
}
}
}
@Override
- public void addReferencesToImportList(Set<YangFileInfo> yangFileInfoSet)
- throws LinkerException {
+ public void addReferencesToImportList(Set<YangNode> yangNodeSet)
+ throws DataModelException {
Iterator<YangImport> importInfoIterator = getImportList().iterator();
// Run through the imported list to add references.
while (importInfoIterator.hasNext()) {
YangImport yangImport = importInfoIterator.next();
- try {
- yangImport.addReferenceToImport(yangFileInfoSet);
- } catch (DataModelException e) {
- throw new LinkerException(e.getMessage());
- }
+ yangImport.addReferenceToImport(yangNodeSet);
}
}
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangType.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangType.java
index 41e07e4..d5cc8ff 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangType.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangType.java
@@ -19,7 +19,6 @@
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.linker.Resolvable;
import org.onosproject.yangutils.linker.ResolvableStatus;
-import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
@@ -248,25 +247,25 @@
@Override
public void resolve()
- throws LinkerException {
+ throws DataModelException {
/*
* Check whether the data type is derived.
*/
if (getDataType() != DERIVED) {
- throw new LinkerException("Linker Error: Resolve should only be called for derived data types.");
+ throw new DataModelException("Linker Error: Resolve should only be called for derived data types.");
}
// Check if the derived info is present.
YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) getDataTypeExtendedInfo();
if (derivedInfo == null) {
- throw new LinkerException("Linker Error: Derived information is missing.");
+ throw new DataModelException("Linker Error: Derived information is missing.");
}
// Initiate the resolution
try {
setResolvableStatus(derivedInfo.resolve());
} catch (DataModelException e) {
- throw new LinkerException(e.getMessage());
+ throw new DataModelException(e.getMessage());
}
}
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
index d2d8bc2..c3bab5f 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
@@ -17,11 +17,9 @@
import java.util.LinkedList;
import java.util.List;
-
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.linker.Resolvable;
import org.onosproject.yangutils.linker.ResolvableStatus;
-import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
@@ -283,18 +281,18 @@
@Override
public void resolve()
- throws LinkerException {
+ throws DataModelException {
YangGrouping referredGrouping = getRefGroup();
if (referredGrouping == null) {
- throw new LinkerException("Linker Exception: YANG uses linker error, cannot resolve uses");
+ throw new DataModelException("YANG uses linker error, cannot resolve uses");
}
YangNode usesParentNode = getParentNodeInGenCode(this);
if (!(usesParentNode instanceof YangLeavesHolder)
|| !(usesParentNode instanceof CollisionDetector)) {
- throw new LinkerException("Linker Exception: YANG uses holder construct is wrong");
+ throw new DataModelException("YANG uses holder construct is wrong");
}
YangLeavesHolder usesParentLeavesHolder = (YangLeavesHolder) usesParentNode;
@@ -343,7 +341,7 @@
* @param usesHolder holder of uses
*/
private void addResolvedUsesInfoOfGrouping(YangUses usesInGrouping,
- YangLeavesHolder usesHolder) {
+ YangLeavesHolder usesHolder) throws DataModelException {
for (YangNode usesResolvedNode :
usesInGrouping.getUsesResolvedNodeList()) {
addNodeOfGrouping(usesResolvedNode);
@@ -367,11 +365,12 @@
* @param listOfLeaves list of leaves to be cloned
* @param usesParentNode parent of the cloned location
* @return cloned list of leaves
+ * @throws DataModelException a violation in data model rule
*/
private List<YangLeaf> cloneLeavesList(List<YangLeaf> listOfLeaves,
- YangLeavesHolder usesParentNode) {
+ YangLeavesHolder usesParentNode) throws DataModelException {
if ((listOfLeaves == null) || listOfLeaves.size() == 0) {
- throw new LinkerException("No leaves to clone");
+ throw new DataModelException("No leaves to clone");
}
List<YangLeaf> newLeavesList = new LinkedList<YangLeaf>();
@@ -382,7 +381,7 @@
YangConstructType.LEAF_DATA);
clonedLeaf = leaf.clone();
} catch (CloneNotSupportedException | DataModelException e) {
- throw new LinkerException(e.getMessage());
+ throw new DataModelException(e.getMessage());
}
clonedLeaf.setContainedIn(usesParentNode);
@@ -400,9 +399,9 @@
* @return cloned list of leaf list
*/
private List<YangLeafList> cloneListOfLeafList(List<YangLeafList> listOfLeafList,
- YangLeavesHolder usesParentNode) {
+ YangLeavesHolder usesParentNode) throws DataModelException {
if ((listOfLeafList == null) || listOfLeafList.size() == 0) {
- throw new LinkerException("No leaf lists to clone");
+ throw new DataModelException("No leaf lists to clone");
}
List<YangLeafList> newListOfLeafList = new LinkedList<YangLeafList>();
@@ -413,7 +412,7 @@
YangConstructType.LEAF_LIST_DATA);
clonedLeafList = leafList.clone();
} catch (CloneNotSupportedException | DataModelException e) {
- throw new LinkerException(e.getMessage());
+ throw new DataModelException(e.getMessage());
}
clonedLeafList.setContainedIn(usesParentNode);
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
index 29d384b..97c7327 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
@@ -18,20 +18,18 @@
import java.util.List;
import java.util.Set;
-
import org.onosproject.yangutils.datamodel.CollisionDetector;
+import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangReferenceResolver;
+import org.onosproject.yangutils.datamodel.YangResolutionInfo;
import org.onosproject.yangutils.datamodel.YangRpc;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.linker.ResolvableType;
-import org.onosproject.yangutils.linker.YangReferenceResolver;
-import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
import org.onosproject.yangutils.parser.Parsable;
-import org.onosproject.yangutils.plugin.manager.YangFileInfo;
import org.onosproject.yangutils.utils.YangConstructType;
/**
@@ -179,7 +177,7 @@
* @throws DataModelException a violation of data model rules
*/
public static void resolveLinkingForResolutionList(List<YangResolutionInfo> resolutionList,
- YangReferenceResolver dataModelRootNode)
+ YangReferenceResolver dataModelRootNode)
throws DataModelException {
for (YangResolutionInfo resolutionInfo : resolutionList) {
@@ -195,7 +193,7 @@
* @throws DataModelException a violation of data model rules
*/
public static void linkInterFileReferences(List<YangResolutionInfo> resolutionList,
- YangReferenceResolver dataModelRootNode)
+ YangReferenceResolver dataModelRootNode)
throws DataModelException {
/*
* Run through the resolution list, find type/uses referring to
@@ -226,19 +224,18 @@
/**
* Returns referred node in a given set.
*
- * @param yangFileInfoSet YANG file info set
- * @param refNodeName name of the node which is referred
+ * @param yangNodeSet YANG node set
+ * @param refNodeName name of the node which is referred
* @return referred node's reference
*/
- public static YangNode findReferredNode(Set<YangFileInfo> yangFileInfoSet, String refNodeName) {
+ public static YangNode findReferredNode(Set<YangNode> yangNodeSet, String refNodeName) {
/*
* Run through the YANG files to see which YANG file matches the
* referred node name.
*/
- for (YangFileInfo yangFileInfo : yangFileInfoSet) {
- YangNode yangNode = yangFileInfo.getRootNode();
+ for (YangNode yangNode : yangNodeSet) {
if (yangNode.getName().equals(refNodeName)) {
- return yangFileInfo.getRootNode();
+ return yangNode;
}
}
return null;
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/RestrictionResolver.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/RestrictionResolver.java
new file mode 100644
index 0000000..4148278
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/RestrictionResolver.java
@@ -0,0 +1,268 @@
+/*
+ * 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.utils;
+
+import java.util.regex.Pattern;
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+import org.onosproject.yangutils.datamodel.YangRangeInterval;
+import org.onosproject.yangutils.datamodel.YangRangeRestriction;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.utils.YangConstructType;
+import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangBuiltInDataTypeInfo;
+
+import static org.onosproject.yangutils.datamodel.YangDataTypes.DECIMAL64;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.INT16;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.INT64;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.INT8;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT16;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT32;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT64;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT8;
+import static org.onosproject.yangutils.utils.UtilConstants.ADD;
+import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
+import static org.onosproject.yangutils.utils.YangConstructType.LENGTH_DATA;
+import static org.onosproject.yangutils.utils.YangConstructType.RANGE_DATA;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.BuiltInTypeObjectFactory.getDataObjectFromString;
+
+/**
+ * Represents restriction resolver which provide common utility used by parser
+ * and during linking for restriction resolution.
+ */
+public final class RestrictionResolver {
+
+ private static final String PIPE = "|";
+ private static final String INTERVAL = "..";
+ private static final int MAX_RANGE_BOUNDARY = 2;
+ private static final int MIN_RANGE_BOUNDARY = 1;
+ private static final String MIN_KEYWORD = "min";
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Creates a restriction resolver.
+ */
+ private RestrictionResolver() {
+ }
+
+ /**
+ * Processes the range restriction for parser and linker.
+ *
+ * @param refRangeRestriction range restriction of referred typedef
+ * @param lineNumber error line number
+ * @param charPositionInLine error character position in line
+ * @param hasReferredRestriction whether has referred restriction
+ * @param curRangeString caller type's range string
+ * @param effectiveType effective type, when called from linker
+ * @return YANG range restriction
+ * @throws DataModelException a violation in data model rule
+ */
+ public static YangRangeRestriction processRangeRestriction(YangRangeRestriction refRangeRestriction,
+ int lineNumber, int charPositionInLine,
+ boolean hasReferredRestriction,
+ String curRangeString, YangDataTypes effectiveType)
+ throws DataModelException {
+ YangBuiltInDataTypeInfo<?> startValue;
+ YangBuiltInDataTypeInfo<?> endValue;
+ YangRangeRestriction rangeRestriction = new YangRangeRestriction();
+
+ String rangeArgument = removeQuotesAndHandleConcat(curRangeString);
+ String[] rangeArguments = rangeArgument.trim().split(Pattern.quote(PIPE));
+
+ for (String rangePart : rangeArguments) {
+ String startInterval;
+ String endInterval;
+ YangRangeInterval rangeInterval = new YangRangeInterval();
+ String[] rangeBoundary = rangePart.trim().split(Pattern.quote(INTERVAL));
+
+ if (rangeBoundary.length > MAX_RANGE_BOUNDARY) {
+ DataModelException dataModelException = new DataModelException("YANG file error : " +
+ YangConstructType.getYangConstructType(RANGE_DATA) + " " + rangeArgument +
+ " is not valid.");
+ dataModelException.setLine(lineNumber);
+ dataModelException.setCharPosition(charPositionInLine);
+ throw dataModelException;
+ }
+
+ if (rangeBoundary.length == MIN_RANGE_BOUNDARY) {
+ startInterval = rangeBoundary[0].trim();
+ endInterval = rangeBoundary[0].trim();
+ } else {
+ startInterval = rangeBoundary[0].trim();
+ endInterval = rangeBoundary[1].trim();
+ }
+
+ try {
+ if (hasReferredRestriction && startInterval.equals(MIN_KEYWORD)
+ && refRangeRestriction.getMinRestrictedvalue() != null) {
+ startValue = refRangeRestriction.getMinRestrictedvalue();
+ } else if (hasReferredRestriction && startInterval.equals(MAX_KEYWORD)
+ && refRangeRestriction.getMaxRestrictedvalue() != null) {
+ startValue = refRangeRestriction.getMaxRestrictedvalue();
+ } else {
+ startValue = getDataObjectFromString(startInterval, effectiveType);
+ }
+ if (hasReferredRestriction && endInterval.equals(MIN_KEYWORD)
+ && refRangeRestriction.getMinRestrictedvalue() != null) {
+ endValue = refRangeRestriction.getMinRestrictedvalue();
+ } else if (hasReferredRestriction && endInterval.equals(MAX_KEYWORD)
+ && refRangeRestriction.getMaxRestrictedvalue() != null) {
+ endValue = refRangeRestriction.getMaxRestrictedvalue();
+ } else {
+ endValue = getDataObjectFromString(endInterval, effectiveType);
+ }
+ } catch (Exception e) {
+ DataModelException dataModelException = new DataModelException(e.getMessage());
+ dataModelException.setLine(lineNumber);
+ dataModelException.setCharPosition(charPositionInLine);
+ throw dataModelException;
+ }
+
+ rangeInterval.setStartValue(startValue);
+ rangeInterval.setEndValue(endValue);
+
+ try {
+ rangeRestriction.addRangeRestrictionInterval(rangeInterval);
+ } catch (DataModelException dataModelException) {
+ dataModelException.setLine(lineNumber);
+ dataModelException.setCharPosition(charPositionInLine);
+ throw dataModelException;
+ }
+ }
+ return rangeRestriction;
+ }
+
+ /**
+ * Processes the length restriction for parser and linker.
+ *
+ * @param refLengthRestriction length restriction of referred typedef
+ * @param lineNumber error line number
+ * @param charPositionInLine error character position in line
+ * @param hasReferredRestriction whether has referred restriction
+ * @param curLengthString caller type's length string
+ * @return YANG range restriction
+ * @throws DataModelException a violation in data model rule
+ */
+ public static YangRangeRestriction processLengthRestriction(YangRangeRestriction refLengthRestriction,
+ int lineNumber, int charPositionInLine,
+ boolean hasReferredRestriction,
+ String curLengthString) throws DataModelException {
+
+ YangBuiltInDataTypeInfo<?> startValue;
+ YangBuiltInDataTypeInfo<?> endValue;
+ YangRangeRestriction lengthRestriction = new YangRangeRestriction<>();
+
+ String rangeArgument = removeQuotesAndHandleConcat(curLengthString);
+ String[] rangeArguments = rangeArgument.trim().split(Pattern.quote(PIPE));
+
+ for (String rangePart : rangeArguments) {
+ String startInterval;
+ String endInterval;
+ YangRangeInterval rangeInterval = new YangRangeInterval<>();
+ String[] rangeBoundary = rangePart.trim().split(Pattern.quote(INTERVAL));
+
+ if (rangeBoundary.length > MAX_RANGE_BOUNDARY) {
+ DataModelException dataModelException = new DataModelException("YANG file error : " +
+ YangConstructType.getYangConstructType(LENGTH_DATA) + " " + rangeArgument +
+ " is not valid.");
+ dataModelException.setLine(lineNumber);
+ dataModelException.setCharPosition(charPositionInLine);
+ throw dataModelException;
+ }
+
+ if (rangeBoundary.length == MIN_RANGE_BOUNDARY) {
+ startInterval = rangeBoundary[0].trim();
+ endInterval = rangeBoundary[0].trim();
+ } else {
+ startInterval = rangeBoundary[0].trim();
+ endInterval = rangeBoundary[1].trim();
+ }
+
+ try {
+ if (hasReferredRestriction && startInterval.equals(MIN_KEYWORD)
+ && refLengthRestriction.getMinRestrictedvalue() != null) {
+ startValue = refLengthRestriction.getMinRestrictedvalue();
+ } else if (hasReferredRestriction && startInterval.equals(MAX_KEYWORD)
+ && refLengthRestriction.getMaxRestrictedvalue() != null) {
+ startValue = refLengthRestriction.getMaxRestrictedvalue();
+ } else {
+ startValue = getDataObjectFromString(startInterval, YangDataTypes.UINT64);
+ }
+ if (hasReferredRestriction && endInterval.equals(MIN_KEYWORD)
+ && refLengthRestriction.getMinRestrictedvalue() != null) {
+ endValue = refLengthRestriction.getMinRestrictedvalue();
+ } else if (hasReferredRestriction && endInterval.equals(MAX_KEYWORD)
+ && refLengthRestriction.getMaxRestrictedvalue() != null) {
+ endValue = refLengthRestriction.getMaxRestrictedvalue();
+ } else {
+ endValue = getDataObjectFromString(endInterval, YangDataTypes.UINT64);
+ }
+ } catch (Exception e) {
+ DataModelException dataModelException = new DataModelException(e.getMessage());
+ dataModelException.setLine(lineNumber);
+ dataModelException.setCharPosition(charPositionInLine);
+ throw dataModelException;
+ }
+
+ rangeInterval.setStartValue(startValue);
+ rangeInterval.setEndValue(endValue);
+
+ try {
+ lengthRestriction.addRangeRestrictionInterval(rangeInterval);
+ } catch (DataModelException dataModelException) {
+ dataModelException.setLine(lineNumber);
+ dataModelException.setCharPosition(charPositionInLine);
+ throw dataModelException;
+ }
+ }
+ return lengthRestriction;
+ }
+
+ /**
+ * Returns whether the data type is of range restricted type.
+ *
+ * @param dataType data type to be checked
+ * @return true, if data type can have range restrictions, false otherwise
+ */
+ public static boolean isOfRangeRestrictedType(YangDataTypes dataType) {
+ return (dataType == INT8
+ || dataType == INT16
+ || dataType == INT32
+ || dataType == INT64
+ || dataType == UINT8
+ || dataType == UINT16
+ || dataType == UINT32
+ || dataType == UINT64
+ || dataType == DECIMAL64);
+ }
+
+ /**
+ * Removes doubles quotes and concatenates if string has plus symbol.
+ *
+ * @param yangStringData string from yang file
+ * @return concatenated string after removing double quotes
+ */
+ private static String removeQuotesAndHandleConcat(String yangStringData) {
+
+ yangStringData = yangStringData.replace("\"", EMPTY_STRING);
+ String[] tmpData = yangStringData.split(Pattern.quote(ADD));
+ StringBuilder builder = new StringBuilder();
+ for (String yangString : tmpData) {
+ builder.append(yangString);
+ }
+ return builder.toString();
+ }
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/BuiltInTypeObjectFactory.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/BuiltInTypeObjectFactory.java
new file mode 100644
index 0000000..4c2d79b
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/BuiltInTypeObjectFactory.java
@@ -0,0 +1,75 @@
+/*-
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Factory to create an object of required type.
+ */
+public final class BuiltInTypeObjectFactory {
+
+ /**
+ * Utility factory class, hence the object creation is forbidden.
+ */
+ private BuiltInTypeObjectFactory() {
+ }
+
+ /**
+ * Given the value represented in string return the corresponding types
+ * object with the value initialized.
+ *
+ * @param valueInStr value represented in string
+ * @param builtInType built in data type
+ * @param <T> the data type of the target object
+ * @return the target data type object with the value initialized
+ */
+ public static <T extends YangBuiltInDataTypeInfo<?>> T getDataObjectFromString(String valueInStr,
+ YangDataTypes builtInType) {
+
+ switch (builtInType) {
+ case INT8: {
+ return (T) new YangInt8(valueInStr);
+ }
+ case INT16: {
+ return (T) new YangInt16(valueInStr);
+ }
+ case INT32: {
+ return (T) new YangInt32(valueInStr);
+ }
+ case INT64: {
+ return (T) new YangInt64(valueInStr);
+ }
+ case UINT8: {
+ return (T) new YangUint8(valueInStr);
+ }
+ case UINT16: {
+ return (T) new YangUint16(valueInStr);
+ }
+ case UINT32: {
+ return (T) new YangUint32(valueInStr);
+ }
+ case UINT64: {
+ return (T) new YangUint64(valueInStr);
+ }
+ default: {
+ throw new DataTypeException("YANG file error : Unsupported data type");
+ }
+ }
+
+ }
+
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/DataTypeException.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/DataTypeException.java
new file mode 100644
index 0000000..8c24d6c
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/DataTypeException.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+/**
+ * Base class for exceptions in data type.
+ */
+public class DataTypeException extends RuntimeException {
+
+ private static final long serialVersionUID = 20160211L;
+
+ /**
+ * Create a new data type exception.
+ */
+ public DataTypeException() {
+ super();
+ }
+
+ /**
+ * Creates a new data type exception with given message.
+ *
+ * @param message the detail of exception in string
+ */
+ public DataTypeException(String message) {
+ super(message);
+ }
+
+ /**
+ * Creates a new data type exception from given message and cause.
+ *
+ * @param message the detail of exception in string
+ * @param cause underlying cause of the error
+ */
+ public DataTypeException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Creates a new data type exception from cause.
+ *
+ * @param cause underlying cause of the error
+ */
+ public DataTypeException(final Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBinary.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBinary.java
new file mode 100644
index 0000000..a93379b
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBinary.java
@@ -0,0 +1,103 @@
+/*
+ * 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.utils.builtindatatype;
+
+import java.util.Objects;
+import com.google.common.base.MoreObjects;
+
+/**
+ * Represents binary data type.
+ */
+public final class YangBinary {
+
+ private byte[] byteArray;
+
+ /**
+ * Creates an instance of YANG binary.
+ */
+ private YangBinary() {
+ }
+
+ /**
+ * Creates an instance of YANG binary.
+ *
+ * @param bytes byte array
+ */
+ public YangBinary(byte[] bytes) {
+ this.byteArray = bytes;
+ }
+
+ /**
+ * Returns object of YANG binary.
+ *
+ * @param bytes byte array
+ * @return object of YANG binary
+ */
+ public static YangBinary of(byte[] bytes) {
+ return new YangBinary(bytes);
+ }
+
+ /**
+ * Returns byte array.
+ *
+ * @return byte array
+ */
+ public byte[] byteArray() {
+ return byteArray;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(byteArray);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof YangBinary) {
+ YangBinary other = (YangBinary) obj;
+ return Objects.equals(byteArray, other.byteArray);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("byteArray", byteArray)
+ .toString();
+ }
+
+ /**
+ * Returns the object of YANG binary fromString input String.
+ *
+ * @param valInString input String
+ * @return Object of YANG binary
+ */
+ public static YangBinary fromString(String valInString) {
+ try {
+ byte[] tmpVal = valInString.getBytes();
+ return of(tmpVal);
+ } catch (Exception e) {
+ }
+ return null;
+ }
+
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBits.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBits.java
new file mode 100644
index 0000000..f2c05f7
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBits.java
@@ -0,0 +1,103 @@
+/*
+ * 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.utils.builtindatatype;
+
+import java.util.Objects;
+import com.google.common.base.MoreObjects;
+
+/**
+ * Represents bits data type.
+ */
+public class YangBits {
+
+ private byte[] byteArray;
+
+ /**
+ * Creates an instance of YANG bits.
+ */
+ private YangBits() {
+ }
+
+ /**
+ * Creates an instance of YANG bits.
+ *
+ * @param bytes byte array
+ */
+ public YangBits(byte[] bytes) {
+ this.byteArray = bytes;
+ }
+
+ /**
+ * Returns object of YANG bits.
+ *
+ * @param bytes byte array
+ * @return object of YANG bits
+ */
+ public static YangBits of(byte[] bytes) {
+ return new YangBits(bytes);
+ }
+
+ /**
+ * Returns byte array.
+ *
+ * @return byte array
+ */
+ public byte[] byteArray() {
+ return byteArray;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(byteArray);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof YangBits) {
+ YangBits other = (YangBits) obj;
+ return Objects.equals(byteArray, other.byteArray);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("byteArray", byteArray)
+ .toString();
+ }
+
+ /**
+ * Returns the object of YANG bits fromString input String.
+ *
+ * @param valInString input String
+ * @return Object of YANG bits
+ */
+ public static YangBits fromString(String valInString) {
+ try {
+ byte[] tmpVal = valInString.getBytes();
+ return of(tmpVal);
+ } catch (Exception e) {
+ }
+ return null;
+ }
+
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBuiltInDataTypeInfo.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBuiltInDataTypeInfo.java
new file mode 100644
index 0000000..b082c16
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBuiltInDataTypeInfo.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Represents the list of utility functions to be supported by YANG built in
+ * data type implementations.
+ *
+ * @param <T> The target data type
+ */
+public interface YangBuiltInDataTypeInfo<T> extends Comparable<T> {
+
+ /**
+ * Returns the YANG built in type.
+ *
+ * @return the YANG built in type
+ */
+ YangDataTypes getYangType();
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangDecimal64.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangDecimal64.java
new file mode 100644
index 0000000..ca45073
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangDecimal64.java
@@ -0,0 +1,111 @@
+/*
+ * 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.utils.builtindatatype;
+
+import java.util.Objects;
+import com.google.common.base.MoreObjects;
+
+/**
+ * Represents YANG decimal 64.
+ */
+public class YangDecimal64 {
+
+ private int fractionDigit;
+
+ /**
+ * Creates an instance of YANG decimal64.
+ */
+ public YangDecimal64() {
+ }
+
+ /**
+ * Creates an instance of of YANG decimal64.
+ *
+ * @param fractionDigit fraction digit
+ */
+ public YangDecimal64(int fractionDigit) {
+ this.setFractionDigit(fractionDigit);
+ }
+
+ /**
+ * Returns fraction digit.
+ *
+ * @return the fractionDigit
+ */
+ public int getFractionDigit() {
+ return fractionDigit;
+ }
+
+ /**
+ * Sets fraction digit.
+ *
+ * @param fractionDigit fraction digits.
+ */
+ public void setFractionDigit(int fractionDigit) {
+ this.fractionDigit = fractionDigit;
+ }
+
+ /**
+ * Returns object of YANG decimal64.
+ *
+ * @param value fraction digit
+ * @return YANG decimal64
+ */
+ public static YangDecimal64 of(int value) {
+ return new YangDecimal64(value);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(fractionDigit);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof YangDecimal64) {
+ YangDecimal64 other = (YangDecimal64) obj;
+ return Objects.equals(fractionDigit, other.fractionDigit);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("fractionDigit", fractionDigit)
+ .toString();
+ }
+
+ /**
+ * Returns the object of YANG decimal64 fromString input String.
+ *
+ * @param valInString input String
+ * @return Object of YANG decimal64
+ */
+ public static YangDecimal64 fromString(String valInString) {
+ try {
+ int tmpVal = Integer.parseInt(valInString);
+ return of(tmpVal);
+ } catch (Exception e) {
+ }
+ return null;
+ }
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt16.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt16.java
new file mode 100644
index 0000000..2a660c1
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt16.java
@@ -0,0 +1,95 @@
+/*
+ * 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.utils.builtindatatype;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+
+/**
+ * Handles the YANG's int16 data type processing.
+ *
+ * int16 represents integer values between -32768 and 32767, inclusively.
+ */
+public class YangInt16 implements YangBuiltInDataTypeInfo<YangInt16> {
+
+ /**
+ * YANG's min keyword.
+ */
+ private static final String MIN_KEYWORD = "min";
+
+ /**
+ * YANG's max keyword.
+ */
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Valid minimum value of YANG's int16.
+ */
+ public static final short MIN_VALUE = -32768;
+
+ /**
+ * Valid maximum value of YANG's int16.
+ */
+ public static final short MAX_VALUE = 32767;
+
+ /**
+ * The value of YANG's int16.
+ */
+ private final short value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ public YangInt16(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else {
+ try {
+ value = Short.parseShort(valueInString);
+ } catch (Exception e) {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "int16.");
+ }
+ }
+ }
+
+ /**
+ * Returns YANG's int16 value.
+ *
+ * @return value of YANG's int16
+ */
+ public short getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangInt16 anotherYangInt16) {
+ return Short.compare(value, anotherYangInt16.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.INT16;
+ }
+
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt32.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt32.java
new file mode 100644
index 0000000..6774b37
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt32.java
@@ -0,0 +1,95 @@
+/*
+ * 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.utils.builtindatatype;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Handles the YANG's int32 data type processing.
+ *
+ * int32 represents integer values between -2147483648 and 2147483647, inclusively.
+ */
+public class YangInt32 implements YangBuiltInDataTypeInfo<YangInt32> {
+
+ /**
+ * YANG's min keyword.
+ */
+ private static final String MIN_KEYWORD = "min";
+
+ /**
+ * YANG's max keyword.
+ */
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Valid minimum value of YANG's int32.
+ */
+ public static final int MIN_VALUE = -2147483648;
+
+ /**
+ * Valid maximum value of YANG's int32.
+ */
+ public static final int MAX_VALUE = 2147483647;
+
+ /**
+ * The value of YANG's int32.
+ */
+ private final int value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ public YangInt32(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else {
+ try {
+ value = Integer.parseInt(valueInString);
+ } catch (Exception e) {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "int32.");
+ }
+ }
+ }
+
+
+ /**
+ * Returns YANG's int32 value.
+ *
+ * @return value of YANG's int32
+ */
+ public int getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangInt32 anotherYangInt32) {
+ return Integer.compare(value, anotherYangInt32.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.INT32;
+ }
+
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt64.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt64.java
new file mode 100644
index 0000000..6a426d1
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt64.java
@@ -0,0 +1,95 @@
+/*
+ * 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.utils.builtindatatype;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Handles the YANG's int8 data type processing.
+ *
+ * int8 represents integer values between -9223372036854775808 and 9223372036854775807, inclusively.
+ */
+public class YangInt64 implements YangBuiltInDataTypeInfo<YangInt64> {
+
+ /**
+ * YANG's min keyword.
+ */
+ private static final String MIN_KEYWORD = "min";
+
+ /**
+ * YANG's max keyword.
+ */
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Valid minimum value of YANG's int64.
+ */
+ public static final Long MIN_VALUE = 0x8000000000000000L;
+
+ /**
+ * Valid maximum value of YANG's int64.
+ */
+ public static final long MAX_VALUE = 0x7fffffffffffffffL;
+
+ /**
+ * The value of YANG's int64.
+ */
+ private final long value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ public YangInt64(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else {
+ try {
+ value = Long.parseLong(valueInString);
+ } catch (Exception e) {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "int64.");
+ }
+ }
+ }
+
+
+ /**
+ * Returns YANG's int64 value.
+ *
+ * @return value of YANG's int64
+ */
+ public long getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangInt64 anotherYangInt64) {
+ return Long.compare(value, anotherYangInt64.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.INT64;
+ }
+
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt8.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt8.java
new file mode 100644
index 0000000..df3221d
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt8.java
@@ -0,0 +1,94 @@
+/*
+ * 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.utils.builtindatatype;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Handles the YANG's int8 data type processing.
+ *
+ * int8 represents integer values between -128 and 127, inclusively.
+ */
+public class YangInt8 implements YangBuiltInDataTypeInfo<YangInt8> {
+
+ /**
+ * YANG's min keyword.
+ */
+ private static final String MIN_KEYWORD = "min";
+
+ /**
+ * YANG's max keyword.
+ */
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Valid minimum value of YANG's int8.
+ */
+ public static final byte MIN_VALUE = -128;
+
+ /**
+ * Valid maximum value of YANG's int8.
+ */
+ public static final byte MAX_VALUE = 127;
+
+ /**
+ * The value of YANG's int8.
+ */
+ private final byte value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ public YangInt8(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else {
+ try {
+ value = Byte.parseByte(valueInString);
+ } catch (Exception e) {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "int8.");
+ }
+ }
+ }
+
+ /**
+ * Returns YANG's int8 value.
+ *
+ * @return value of YANG's int8
+ */
+ public byte getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangInt8 anotherYangInt8) {
+ return Byte.compare(value, anotherYangInt8.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.INT8;
+ }
+
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint16.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint16.java
new file mode 100644
index 0000000..8a4fa93
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint16.java
@@ -0,0 +1,103 @@
+/*
+ * 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.utils.builtindatatype;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Handles the YANG's Uint16 data type processing.
+ *
+ * Uint16 represents integer values between 0 and 65535, inclusively.
+ */
+public class YangUint16 implements YangBuiltInDataTypeInfo<YangUint16> {
+
+ /**
+ * YANG's min keyword.
+ */
+ private static final String MIN_KEYWORD = "min";
+
+ /**
+ * YANG's max keyword.
+ */
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Valid minimum value of YANG's Uint16.
+ */
+ public static final int MIN_VALUE = 0;
+
+ /**
+ * Valid maximum value of YANG's Uint16.
+ */
+ public static final int MAX_VALUE = 65535;
+
+ /**
+ * Value of the object.
+ */
+ private int value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ YangUint16(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else {
+ try {
+ value = Integer.parseInt(valueInString);
+ } catch (Exception e) {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "uint16.");
+ }
+ }
+
+ if (value < MIN_VALUE) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is lesser than minimum value "
+ + MIN_VALUE + ".");
+ } else if (value > MAX_VALUE) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is greater than maximum value "
+ + MAX_VALUE + ".");
+ }
+ }
+
+ /**
+ * Returns YANG's uint16 value.
+ *
+ * @return value of YANG's uint16
+ */
+ public int getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangUint16 another) {
+ return Integer.compare(value, another.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.UINT16;
+ }
+
+}
+
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint32.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint32.java
new file mode 100644
index 0000000..f3dc7ec
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint32.java
@@ -0,0 +1,95 @@
+/*
+ * 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.utils.builtindatatype;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Handles the YANG's Uint32 data type processing.
+ *
+ * Uint32 represents integer values between 0 and 4294967295, inclusively.
+ */
+public class YangUint32 implements YangBuiltInDataTypeInfo<YangUint32> {
+
+ private static final String MIN_KEYWORD = "min";
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Valid minimum value of YANG's Uint32.
+ */
+ public static final long MIN_VALUE = 0;
+
+ /**
+ * Valid maximum value of YANG's Uint32.
+ */
+ public static final long MAX_VALUE = 4294967295L;
+
+ /**
+ * Value of the object.
+ */
+ private long value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ YangUint32(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else {
+ try {
+ value = Long.parseLong(valueInString);
+ } catch (Exception e) {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "uint32.");
+ }
+ }
+
+ if (value < MIN_VALUE) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is lesser than minimum value "
+ + MIN_VALUE + ".");
+ } else if (value > MAX_VALUE) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is greater than maximum value "
+ + MAX_VALUE + ".");
+ }
+ }
+
+ /**
+ * Returns YANG's uint32 value.
+ *
+ * @return value of YANG's uint32
+ */
+ public long getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangUint32 another) {
+ return Long.compare(value, another.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.UINT32;
+ }
+
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint64.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint64.java
new file mode 100644
index 0000000..bc66d59
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint64.java
@@ -0,0 +1,107 @@
+/*
+ * 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.utils.builtindatatype;
+
+import java.math.BigInteger;
+import java.util.regex.Pattern;
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Handles the YANG's Uint16 data type processing.
+ *
+ * Uint64 represents integer values between 0 and 18446744073709551615, inclusively.
+ */
+public class YangUint64 implements YangBuiltInDataTypeInfo<YangUint64> {
+
+ /**
+ * YANG's min keyword.
+ */
+ private static final String MIN_KEYWORD = "min";
+
+ /**
+ * YANG's max keyword.
+ */
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * YANG's Integer value pattern.
+ */
+ private static final Pattern NON_NEGATIVE_INTEGER_PATTERN = Pattern.compile("[0-9]+");
+
+ /**
+ * Valid minimum value of YANG's Uint64.
+ */
+ public static final BigInteger MIN_VALUE = BigInteger.valueOf(0);
+
+ /**
+ * Valid maximum value of YANG's Uint64.
+ */
+ public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
+
+ /**
+ * Value of the object.
+ */
+ private BigInteger value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ YangUint64(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else if (NON_NEGATIVE_INTEGER_PATTERN.matcher(valueInString).matches()) {
+ value = new BigInteger(valueInString);
+ } else {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "uint64.");
+ }
+
+ if (value.compareTo(MIN_VALUE) < 0) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is lesser than minimum value "
+ + MIN_VALUE + ".");
+ } else if (value.compareTo(MAX_VALUE) > 0) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is greater than maximum value "
+ + MAX_VALUE + ".");
+ }
+ }
+
+ /**
+ * Returns YANG's uint64 value.
+ *
+ * @return value of YANG's uint64
+ */
+ public BigInteger getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangUint64 another) {
+ return value.compareTo(another.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.UINT64;
+ }
+
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint8.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint8.java
new file mode 100644
index 0000000..dd4901f
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint8.java
@@ -0,0 +1,102 @@
+/*
+ * 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.utils.builtindatatype;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Handles the YANG's Uint8 data type processing.
+ *
+ * Uint8 represents integer values between 0 and 255, inclusively.
+ */
+public class YangUint8 implements YangBuiltInDataTypeInfo<YangUint8> {
+
+ /**
+ * YANG's min keyword.
+ */
+ private static final String MIN_KEYWORD = "min";
+
+ /**
+ * YANG's max keyword.
+ */
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Valid minimum value of YANG's Uint8.
+ */
+ public static final short MIN_VALUE = 0;
+
+ /**
+ * Valid maximum value of YANG's Uint8.
+ */
+ public static final short MAX_VALUE = 255;
+
+ /**
+ * Value of the object.
+ */
+ private short value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ YangUint8(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else {
+ try {
+ value = Short.parseShort(valueInString);
+ } catch (Exception e) {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "uint8.");
+ }
+ }
+
+ if (value < MIN_VALUE) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is lesser than minimum value "
+ + MIN_VALUE + ".");
+ } else if (value > MAX_VALUE) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is greater than maximum value "
+ + MAX_VALUE + ".");
+ }
+ }
+
+ /**
+ * Returns YANG's uint8 value.
+ *
+ * @return value of YANG's uint8
+ */
+ public short getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangUint8 another) {
+ return Short.compare(value, another.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.UINT8;
+ }
+
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/package-info.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/package-info.java
new file mode 100644
index 0000000..d1ceae5
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/package-info.java
@@ -0,0 +1,20 @@
+/*-
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Utilities for YANG built in data types.
+ */
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;