[ONOS-5232] bits enum class generation modifications and code refactoring.
Change-Id: I67fb31c586802e9cf682aa6e707475ad8fdc096f
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/RpcNotificationContainer.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/RpcNotificationContainer.java
index 39a74fe..e202abc 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/RpcNotificationContainer.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/RpcNotificationContainer.java
@@ -51,4 +51,18 @@
* @return augment list
*/
List<YangAugment> getAugmentList();
+
+ /**
+ * Returns prefix.
+ *
+ * @return prefix
+ */
+ String getPrefix();
+
+ /**
+ * Returns list of notification nodes.
+ *
+ * @return list of notification nodes
+ */
+ List<YangNode> getNotificationNodes();
}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDecimal64.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDecimal64.java
index 83f3b89..58fd8ce 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDecimal64.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDecimal64.java
@@ -28,6 +28,10 @@
import java.math.BigDecimal;
import java.util.ListIterator;
+import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.getErrorMsg;
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DECIMAL64_DATA;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DECIMAL64;
+
/**
* Represents YANG decimal 64.
*/
@@ -60,13 +64,19 @@
/**
* Valid minimum value of YANG's decimal64.
*/
- private static final BigDecimal MIN_VALUE = BigDecimal.valueOf
- (-922337203685477580.8);
+ private static final BigDecimal MIN_VALUE =
+ BigDecimal.valueOf(-922337203685477580.8);
/**
* Valid maximum value of YANG's decimal64.
*/
- public static final BigDecimal MAX_VALUE = BigDecimal.valueOf(922337203685477580.7);
+ private static final BigDecimal MAX_VALUE =
+ BigDecimal.valueOf(922337203685477580.7);
+
+ private static final int MIN_FRACTION_DIGIT_RANGE = 1;
+ private static final int MAX_FRACTION_DIGIT_RANGE = 18;
+ private static final int ZERO = 0;
+
// Decimal64 value
private BigDecimal value;
@@ -108,16 +118,19 @@
try {
value = new BigDecimal(valueInString);
} catch (Exception e) {
- throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
- "decimal64.");
+ throw new DataTypeException(
+ "YANG file error : Input value \"" + valueInString + "\"" +
+ " is not a valid decimal64.");
}
}
if (value.doubleValue() < MIN_VALUE.doubleValue()) {
- throw new DataTypeException("YANG file error : " + valueInString + " is lesser than minimum value "
+ throw new DataTypeException("YANG file error : " + valueInString +
+ " is less than minimum value "
+ MIN_VALUE + ".");
} else if (value.doubleValue() > MAX_VALUE.doubleValue()) {
- throw new DataTypeException("YANG file error : " + valueInString + " is greater than maximum value "
+ throw new DataTypeException("YANG file error : " + valueInString +
+ " is greater than maximum value "
+ MAX_VALUE + ".");
}
}
@@ -173,7 +186,7 @@
* @param resolvedExtendedInfo resolved range restricted extended information
*/
public void setRangeRestrictedExtendedInfo(T resolvedExtendedInfo) {
- this.rangeRestrictedExtendedInfo = resolvedExtendedInfo;
+ rangeRestrictedExtendedInfo = resolvedExtendedInfo;
}
/**
@@ -188,12 +201,12 @@
@Override
public YangDataTypes getYangType() {
- return YangDataTypes.DECIMAL64;
+ return DECIMAL64;
}
@Override
public YangConstructType getYangConstructType() {
- return YangConstructType.DECIMAL64_DATA;
+ return DECIMAL64_DATA;
}
@Override
@@ -206,9 +219,8 @@
*
* @param valInString input String
* @return Object of YANG decimal64
- * @throws DataModelException a violation of data model rules
*/
- public static YangDecimal64 fromString(String valInString) throws DataModelException {
+ static YangDecimal64 fromString(String valInString) {
return new YangDecimal64(valInString);
}
@@ -218,10 +230,8 @@
* @return true if fraction-digit is in its range otherwise false
*/
public boolean isValidFractionDigit() {
- if ((fractionDigit >= 1) && (fractionDigit <= 18)) {
- return true;
- }
- return false;
+ return fractionDigit >= MIN_FRACTION_DIGIT_RANGE &&
+ fractionDigit <= MAX_FRACTION_DIGIT_RANGE;
}
@@ -231,11 +241,12 @@
* @throws DataModelException a violation of data model rules
*/
public void validateDecimal64() throws DataModelException {
- YangRangeRestriction rangeRestriction = (YangRangeRestriction) getRangeRestrictedExtendedInfo();
+ YangRangeRestriction rangeRestriction =
+ (YangRangeRestriction) getRangeRestrictedExtendedInfo();
if (rangeRestriction != null) {
// Check whether value is within provided range value
- ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals()
- .listIterator();
+ ListIterator<YangRangeInterval> rangeListIterator =
+ rangeRestriction.getAscendingRangeIntervals().listIterator();
boolean isMatched = false;
while (rangeListIterator.hasNext()) {
@@ -245,28 +256,24 @@
rangeInterval.setFileName(getFileName());
BigDecimal startValue = ((YangDecimal64) rangeInterval.getStartValue()).getValue();
BigDecimal endValue = ((YangDecimal64) rangeInterval.getEndValue()).getValue();
- if ((this.value.doubleValue() >= startValue.doubleValue()) &&
- (this.value.doubleValue() <= endValue.doubleValue())) {
+ if (value.compareTo(startValue) >= ZERO &&
+ value.compareTo(endValue) <= ZERO) {
isMatched = true;
break;
}
}
// If range is not matched then throw error
if (!isMatched) {
- throw new DataModelException("YANG file error : decimal64 validation failed. " +
- " in " +
- getLineNumber() + " at " +
- getCharPosition() +
- " in " + getFileName() + "\"");
+ throw new DataModelException(getErrorMsg(
+ "YANG file error : decimal64 validation failed.", "decimal64",
+ getLineNumber(), getCharPosition(), getFileName() + "\""));
}
} else {
// Check value is in fraction-digits decimal64 value range
- if (!FractionDigits.isValueInDecimal64Range(this.value, getFractionDigit())) {
- throw new DataModelException("YANG file error : decimal64 validation failed. " +
- " in " +
- getLineNumber() + " at " +
- getCharPosition() +
- " in " + getFileName() + "\"");
+ if (!FractionDigits.isValueInDecimal64Range(value, getFractionDigit())) {
+ throw new DataModelException(getErrorMsg(
+ "YANG file error : decimal64 validation failed.", "decimal64",
+ getLineNumber(), getCharPosition(), getFileName() + "\""));
}
}
@@ -278,35 +285,32 @@
* @throws DataModelException a violation of data model rules
*/
public void validateRange() throws DataModelException {
- YangRangeRestriction rangeRestriction = (YangRangeRestriction) getRangeRestrictedExtendedInfo();
+ YangRangeRestriction rangeRestriction =
+ (YangRangeRestriction) getRangeRestrictedExtendedInfo();
if (rangeRestriction == null) {
// No need to validate. Range is optional.
return;
}
-
- ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals()
- .listIterator();
+ ListIterator<YangRangeInterval> rangeListIterator =
+ rangeRestriction.getAscendingRangeIntervals().listIterator();
while (rangeListIterator.hasNext()) {
YangRangeInterval rangeInterval = rangeListIterator.next();
rangeInterval.setCharPosition(getCharPosition());
rangeInterval.setLineNumber(getLineNumber());
rangeInterval.setFileName(getFileName());
- if (!(FractionDigits.isValueInDecimal64Range(((YangDecimal64) rangeInterval.getStartValue()).getValue(),
- getFractionDigit()))) {
- throw new DataModelException("YANG file error : range validation failed. " +
- " in " +
- getLineNumber() + " at " +
- getCharPosition() +
- " in " + getFileName() + "\"");
+ if (!FractionDigits.isValueInDecimal64Range(
+ ((YangDecimal64) rangeInterval.getStartValue()).getValue(),
+ getFractionDigit())) {
+ throw new DataModelException(getErrorMsg(
+ "YANG file error : decimal64 validation failed.", "decimal64",
+ getLineNumber(), getCharPosition(), getFileName() + "\""));
}
-
- if (!(FractionDigits.isValueInDecimal64Range(((YangDecimal64) rangeInterval.getEndValue()).getValue(),
- getFractionDigit()))) {
- throw new DataModelException("YANG file error : range validation failed. " +
- " in " +
- getLineNumber() + " at " +
- getCharPosition() +
- " in " + getFileName() + "\"");
+ if (!FractionDigits.isValueInDecimal64Range(
+ ((YangDecimal64) rangeInterval.getEndValue()).getValue(),
+ getFractionDigit())) {
+ throw new DataModelException(getErrorMsg(
+ "YANG file error : decimal64 validation failed.", "decimal64",
+ getLineNumber(), getCharPosition(), getFileName() + "\""));
}
}
}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
index 9d9b686..d8de31a 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
@@ -16,29 +16,25 @@
package org.onosproject.yangutils.datamodel;
-import com.google.common.base.Strings;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import java.io.Serializable;
+import static com.google.common.base.Strings.isNullOrEmpty;
+import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.getErrorMsg;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.processLengthRestriction;
import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.processRangeRestriction;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypeUtils.isOfRangeRestrictedType;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BITS;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BOOLEAN;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DECIMAL64;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.EMPTY;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.ENUMERATION;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.IDENTITYREF;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.LEAFREF;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.STRING;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UNION;
/**
* Represents the derived information.
@@ -63,7 +59,7 @@
private T resolvedExtendedInfo;
/**
- * Effective built-in type, requried in case type of typedef is again a
+ * Effective built-in type, required in case type of typedef is again a
* derived type. This information is to be added during linking.
*/
private YangDataTypes effectiveBuiltInType;
@@ -114,15 +110,6 @@
}
/**
- * Sets resolved extended information after successful linking.
- *
- * @param resolvedExtendedInfo resolved extended information
- */
- public void setResolvedExtendedInfo(T resolvedExtendedInfo) {
- this.resolvedExtendedInfo = resolvedExtendedInfo;
- }
-
- /**
* Returns the length restriction string.
*
* @return the length restriction string
@@ -186,160 +173,44 @@
}
/**
- * Sets effective built-in type.
- *
- * @param effectiveBuiltInType effective built-in type
- */
- public void setEffectiveBuiltInType(YangDataTypes effectiveBuiltInType) {
- this.effectiveBuiltInType = effectiveBuiltInType;
- }
-
- /**
* Resolves the type derived info, by obtaining the effective built-in type
* and resolving the restrictions.
*
* @return resolution status
* @throws DataModelException a violation in data mode rule
*/
- public ResolvableStatus resolve()
- throws DataModelException {
-
+ public ResolvableStatus resolve() throws DataModelException {
YangType<?> baseType = getReferredTypeDef().getTypeDefBaseType();
+ YangDataTypes type = baseType.getDataType();
+ T extended = (T) baseType.getDataTypeExtendedInfo();
/*
* Checks the data type of the referred typedef, if it's derived, obtain
* effective built-in type and restrictions from it's derived info,
* otherwise take from the base type of type itself.
*/
- if (baseType.getDataType() == DERIVED) {
+ if (type == DERIVED) {
ResolvableStatus resolvableStatus = resolveTypeDerivedInfo(baseType);
if (resolvableStatus != null) {
return resolvableStatus;
}
- } else if ((baseType.getDataType() == LEAFREF) || (baseType.getDataType() == IDENTITYREF)) {
- setEffectiveBuiltInType(baseType.getDataType());
+ } else if (type == LEAFREF || type == IDENTITYREF) {
+ effectiveBuiltInType = type;
return RESOLVED;
} else {
- setEffectiveBuiltInType(baseType.getDataType());
+ effectiveBuiltInType = type;
/*
* Check whether the effective built-in type can have range
* restrictions, if yes call resolution of range.
*/
- if (isOfRangeRestrictedType(getEffectiveBuiltInType())) {
- if (baseType.getDataTypeExtendedInfo() == null) {
- resolveRangeRestriction(null);
- /*
- * Return the resolution status as resolved, if it's not
- * resolve range/string restriction will throw exception in
- * previous function.
- */
- return RESOLVED;
- } else {
- if (!(baseType.getDataTypeExtendedInfo() instanceof YangRangeRestriction)) {
- throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
- "type." + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
- }
- resolveRangeRestriction((YangRangeRestriction) baseType.getDataTypeExtendedInfo());
- /*
- * Return the resolution status as resolved, if it's not
- * resolve range/string restriction will throw exception in
- * previous function.
- */
- return RESOLVED;
- }
- /*
- * If the effective built-in type is of type string calls for
- * string resolution.
- */
- } else if (getEffectiveBuiltInType() == STRING) {
- if (baseType.getDataTypeExtendedInfo() == null) {
- resolveStringRestriction(null);
- /*
- * Return the resolution status as resolved, if it's not
- * resolve range/string restriction will throw exception in
- * previous function.
- */
- return RESOLVED;
- } else {
- if (!(baseType.getDataTypeExtendedInfo() instanceof YangStringRestriction)) {
- throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
- "type." + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
- }
- resolveStringRestriction((YangStringRestriction) baseType.getDataTypeExtendedInfo());
- /*
- * Return the resolution status as resolved, if it's not
- * resolve range/string restriction will throw exception in
- * previous function.
- */
- return RESOLVED;
- }
- } else if (getEffectiveBuiltInType() == BINARY) {
- if (baseType.getDataTypeExtendedInfo() == null) {
- resolveBinaryRestriction(null);
- /*
- * Return the resolution status as resolved, if it's not
- * resolve length restriction will throw exception in
- * previous function.
- */
- return RESOLVED;
- } else {
- if (!(baseType.getDataTypeExtendedInfo() instanceof YangRangeRestriction)) {
- throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
- "type." + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
- }
- resolveBinaryRestriction((YangRangeRestriction) baseType.getDataTypeExtendedInfo());
- /*
- * Return the resolution status as resolved, if it's not
- * resolve length restriction will throw exception in
- * previous function.
- */
- return RESOLVED;
- }
- } else if (getEffectiveBuiltInType() == DECIMAL64) {
- if (baseType.getDataTypeExtendedInfo() != null) {
- if (((YangDecimal64) baseType.getDataTypeExtendedInfo()).getRangeRestrictedExtendedInfo() == null) {
- resolveRangeRestriction(null);
- /*
- * Return the resolution status as resolved, if it's not;
- * resolve range restriction will throw exception in
- * previous function.
- */
- return RESOLVED;
- } else {
- if (!(((YangDecimal64) baseType.getDataTypeExtendedInfo())
- .getRangeRestrictedExtendedInfo() instanceof YangRangeRestriction)) {
- throw new DataModelException("Linker error: Referred typedef restriction info is" +
- " of invalid type." + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
- }
- resolveRangeRestriction((YangRangeRestriction) ((YangDecimal64) baseType
- .getDataTypeExtendedInfo()).getRangeRestrictedExtendedInfo());
- /*
- * Return the resolution status as resolved, if it's not
- * resolve range/string restriction will throw exception in
- * previous function.
- */
- return RESOLVED;
- }
-
- } else {
- throw new DataModelException("Linker error: Unable to find type extended info for decimal64." +
- "" + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
- }
+ if (isOfRangeRestrictedType(effectiveBuiltInType)) {
+ return getResolveStatusForRangeRestrictionType(extended);
+ } else if (effectiveBuiltInType == STRING) {
+ return getResolveStatusForString(extended);
+ } else if (effectiveBuiltInType == BINARY) {
+ return getResolveStatusForBinary(extended);
+ } else if (effectiveBuiltInType == DECIMAL64) {
+ return getResolveStatusForDecimal64(extended);
}
}
@@ -347,26 +218,138 @@
* Check if the data type is the one which can't be restricted, in this
* case check whether no self restrictions should be present.
*/
- if (isOfValidNonRestrictedType(getEffectiveBuiltInType())) {
- if (Strings.isNullOrEmpty(getLengthRestrictionString())
- && Strings.isNullOrEmpty(getRangeRestrictionString())
- && getPatternRestriction() == null) {
+ if (effectiveBuiltInType.isNonRestrictedType()) {
+ if (isNullOrEmpty(getLengthRestrictionString()) &&
+ isNullOrEmpty(getRangeRestrictionString()) &&
+ getPatternRestriction() == null) {
return RESOLVED;
} else {
- throw new DataModelException("YANG file error: Restrictions can't be applied to a given type "
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ throw new DataModelException(getErrorMsg(
+ "YANG file error: Restrictions can't be applied to a " +
+ "given type ", "type.", getLineNumber(),
+ getCharPosition(), getFileName() + "\""));
}
}
-
// Throw exception for unsupported types
- throw new DataModelException("Linker error: Unable to process the derived type. "
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ throw new DataModelException(getErrorMsg(
+ "Linker error: Unable to process the derived type. ", "type.",
+ getLineNumber(), getCharPosition(), getFileName() + "\""));
+ }
+
+ //Returns resolve status for range restrictions.
+ private ResolvableStatus getResolveStatusForRangeRestrictionType(T extended)
+ throws DataModelException {
+ if (extended == null) {
+ resolveRangeRestriction(null);
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve range/string restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ } else {
+ if (!(extended instanceof YangRangeRestriction)) {
+ throwError();
+ }
+ resolveRangeRestriction((YangRangeRestriction) extended);
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve range/string restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ }
+ }
+
+ //Returns resolve status for string.
+ private ResolvableStatus getResolveStatusForString(T extended)
+ throws DataModelException {
+ if (extended == null) {
+ resolveStringRestriction(null);
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve range/string restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ } else {
+ if (!(extended instanceof YangStringRestriction)) {
+ throwError();
+ }
+ resolveStringRestriction((YangStringRestriction) extended);
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve range/string restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ }
+ }
+
+ //Returns resolve status for binary type.
+ private ResolvableStatus getResolveStatusForBinary(T extended)
+ throws DataModelException {
+ if (extended == null) {
+ resolveBinaryRestriction(null);
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve length restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ } else {
+ if (!(extended instanceof YangRangeRestriction)) {
+ throwError();
+ }
+ resolveBinaryRestriction((YangRangeRestriction) extended);
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve length restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ }
+ }
+
+ //Returns resolve status for decimal64 type.
+ private ResolvableStatus getResolveStatusForDecimal64(T extended)
+ throws DataModelException {
+ if (extended != null) {
+ if (((YangDecimal64) extended).getRangeRestrictedExtendedInfo() == null) {
+ resolveRangeRestriction(null);
+ /*
+ * Return the resolution status as resolved, if it's not;
+ * resolve range restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ } else {
+ if (!(((YangDecimal64) extended)
+ .getRangeRestrictedExtendedInfo() instanceof YangRangeRestriction)) {
+ throwError();
+ }
+ resolveRangeRestriction((YangRangeRestriction) (
+ (YangDecimal64) extended).getRangeRestrictedExtendedInfo());
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve range/string restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ }
+
+ } else {
+ throw new DataModelException(getErrorMsg(
+ "Linker error: Unable to find type extended info " +
+ "for decimal64.", "type.", getLineNumber(),
+ getCharPosition(), getFileName() + "\""));
+ }
+ }
+
+ private void throwError() throws DataModelException {
+ throw new DataModelException(getErrorMsg(
+ "Linker error: Referred typedef restriction info is of invalid ",
+ "type.", getLineNumber(), getCharPosition(), getFileName() + "\""));
}
/**
@@ -377,113 +360,39 @@
* @return resolution status
* @throws DataModelException a violation in data mode rule
*/
- public ResolvableStatus resolveTypeDerivedInfo(YangType<?> baseType)
+ private ResolvableStatus resolveTypeDerivedInfo(YangType<?> baseType)
throws DataModelException {
//Check whether the referred typedef is resolved.
- if (baseType.getResolvableStatus() != INTRA_FILE_RESOLVED && baseType.getResolvableStatus() != RESOLVED) {
- throw new DataModelException("Linker Error: Referred typedef is not resolved for type."
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ if (baseType.getResolvableStatus() != INTRA_FILE_RESOLVED &&
+ baseType.getResolvableStatus() != RESOLVED) {
+ throwError();
}
/*
* Check if the referred typedef is intra file resolved, if yes sets
* current status also to intra file resolved .
*/
- if (getReferredTypeDef().getTypeDefBaseType().getResolvableStatus() == INTRA_FILE_RESOLVED) {
+ if (getReferredTypeDef().getTypeDefBaseType()
+ .getResolvableStatus() == INTRA_FILE_RESOLVED) {
return INTRA_FILE_RESOLVED;
}
- setEffectiveBuiltInType(((YangDerivedInfo<?>) baseType.getDataTypeExtendedInfo())
- .getEffectiveBuiltInType());
+ effectiveBuiltInType = ((YangDerivedInfo<?>) baseType
+ .getDataTypeExtendedInfo()).getEffectiveBuiltInType();
YangDerivedInfo refDerivedInfo = (YangDerivedInfo<?>) baseType.getDataTypeExtendedInfo();
+ T extendedInfo = (T) refDerivedInfo.getResolvedExtendedInfo();
/*
* Check whether the effective built-in type can have range
* restrictions, if yes call resolution of range.
*/
- if (isOfRangeRestrictedType(getEffectiveBuiltInType())) {
- if (refDerivedInfo.getResolvedExtendedInfo() == null) {
- resolveRangeRestriction(null);
- /*
- * Return the resolution status as resolved, if it's not
- * resolve range/string restriction will throw exception in
- * previous function.
- */
- return RESOLVED;
- } else {
- if (!(refDerivedInfo.getResolvedExtendedInfo() instanceof YangRangeRestriction)) {
- throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
- "type." + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
- }
- resolveRangeRestriction((YangRangeRestriction) refDerivedInfo.getResolvedExtendedInfo());
- /*
- * Return the resolution status as resolved, if it's not
- * resolve range/string restriction will throw exception in
- * previous function.
- */
- return RESOLVED;
- }
- /*
- * If the effective built-in type is of type string calls for
- * string resolution.
- */
- } else if (getEffectiveBuiltInType() == STRING) {
- if (refDerivedInfo.getResolvedExtendedInfo() == null) {
- resolveStringRestriction(null);
- /*
- * Return the resolution status as resolved, if it's not
- * resolve range/string restriction will throw exception in
- * previous function.
- */
- return RESOLVED;
- } else {
- if (!(refDerivedInfo.getResolvedExtendedInfo() instanceof YangStringRestriction)) {
- throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
- "type." + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
- }
- resolveStringRestriction((YangStringRestriction) refDerivedInfo.getResolvedExtendedInfo());
- /*
- * Return the resolution status as resolved, if it's not
- * resolve range/string restriction will throw exception in
- * previous function.
- */
- return RESOLVED;
- }
- } else if (getEffectiveBuiltInType() == BINARY) {
- if (refDerivedInfo.getResolvedExtendedInfo() == null) {
- resolveBinaryRestriction(null);
- /*
- * Return the resolution status as resolved, if it's not
- * resolve length restriction will throw exception in
- * previous function.
- */
- return RESOLVED;
- } else {
- if (!(refDerivedInfo.getResolvedExtendedInfo() instanceof YangRangeRestriction)) {
- throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
- "type." + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
- }
- resolveBinaryRestriction((YangRangeRestriction) refDerivedInfo.getResolvedExtendedInfo());
- /*
- * Return the resolution status as resolved, if it's not
- * resolve length restriction will throw exception in
- * previous function.
- */
- return RESOLVED;
- }
- } else if (getEffectiveBuiltInType() == DECIMAL64) {
- if (refDerivedInfo.getResolvedExtendedInfo() == null) {
+ if (isOfRangeRestrictedType(effectiveBuiltInType)) {
+ return getResolveStatusForRangeRestrictionType(extendedInfo);
+ } else if (effectiveBuiltInType == STRING) {
+ return getResolveStatusForString(extendedInfo);
+ } else if (effectiveBuiltInType == BINARY) {
+ return getResolveStatusForBinary(extendedInfo);
+ } else if (effectiveBuiltInType == DECIMAL64) {
+ if (extendedInfo == null) {
resolveRangeRestriction(null);
/*
* Return the resolution status as resolved, if it's not;
@@ -492,15 +401,10 @@
*/
return RESOLVED;
} else {
- if (!(refDerivedInfo.getResolvedExtendedInfo() instanceof YangRangeRestriction)) {
- throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
- "type." + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ if (!(extendedInfo instanceof YangRangeRestriction)) {
+ throwError();
}
- resolveRangeRestriction((YangRangeRestriction) refDerivedInfo
- .getResolvedExtendedInfo());
+ resolveRangeRestriction((YangRangeRestriction) extendedInfo);
/*
* Return the resolution status as resolved, if it's not
* resolve range/string restriction will throw exception in
@@ -509,41 +413,38 @@
return RESOLVED;
}
}
-
return null;
}
/**
* Resolves the string restrictions.
*
- * @param refStringRestriction referred string restriction of typedef
+ * @param refSr referred string restriction of typedef
* @throws DataModelException a violation in data model rule
*/
- private void resolveStringRestriction(YangStringRestriction refStringRestriction)
+ private void resolveStringRestriction(YangStringRestriction refSr)
throws DataModelException {
- YangStringRestriction curStringRestriction = null;
- YangRangeRestriction refRangeRestriction = null;
- YangPatternRestriction refPatternRestriction = null;
+ YangStringRestriction curSr = null;
+ YangRangeRestriction refRr = null;
+ YangPatternRestriction refPr = null;
/*
* Check that range restriction should be null when built-in type is
* string.
*/
- if (!Strings.isNullOrEmpty(getRangeRestrictionString())) {
- DataModelException dataModelException = new DataModelException("YANG file error: Range restriction " +
- "should't be present for string data type.");
- dataModelException.setLine(getLineNumber());
- dataModelException.setCharPosition(getCharPosition());
- dataModelException.setFileName(getFileName());
- throw dataModelException;
+ if (!isNullOrEmpty(getRangeRestrictionString())) {
+ throw new DataModelException(getErrorMsg(
+ "YANG file error: Range restriction should't be present for" +
+ " string data type.", ".", getLineNumber(),
+ getCharPosition(), getFileName()));
}
/*
* If referred restriction and self restriction both are null, no
* resolution is required.
*/
- if (refStringRestriction == null && Strings.isNullOrEmpty(getLengthRestrictionString())
- && getPatternRestriction() == null) {
+ if (refSr == null && isNullOrEmpty(getLengthRestrictionString()) &&
+ getPatternRestriction() == null) {
return;
}
@@ -551,66 +452,63 @@
* If referred string restriction is not null, take value of length and
* pattern restriction and assign.
*/
- if (refStringRestriction != null) {
- refRangeRestriction = refStringRestriction.getLengthRestriction();
- refPatternRestriction = refStringRestriction.getPatternRestriction();
+ if (refSr != null) {
+ refRr = refSr.getLengthRestriction();
+ refPr = refSr.getPatternRestriction();
}
- YangRangeRestriction lengthRestriction = resolveLengthRestriction(refRangeRestriction);
- YangPatternRestriction patternRestriction = resolvePatternRestriction(refPatternRestriction);
+ YangRangeRestriction lr = resolveLengthRestriction(refRr);
+ YangPatternRestriction pr = resolvePatternRestriction(refPr);
/*
* Check if either of length or pattern restriction is present, if yes
* create string restriction and assign value.
*/
- if (lengthRestriction != null || patternRestriction != null) {
- curStringRestriction = new YangStringRestriction();
- curStringRestriction.setCharPosition(getCharPosition());
- curStringRestriction.setFileName(getFileName());
- curStringRestriction.setLineNumber(getLineNumber());
- curStringRestriction.setLengthRestriction(lengthRestriction);
- curStringRestriction.setPatternRestriction(patternRestriction);
+ if (lr != null || pr != null) {
+ curSr = new YangStringRestriction();
+ curSr.setCharPosition(getCharPosition());
+ curSr.setFileName(getFileName());
+ curSr.setLineNumber(getLineNumber());
+ curSr.setLengthRestriction(lr);
+ curSr.setPatternRestriction(pr);
}
- setResolvedExtendedInfo((T) curStringRestriction);
+ resolvedExtendedInfo = (T) curSr;
}
/**
* Resolves the binary restrictions.
*
- * @param refLengthRestriction referred length restriction of typedef
+ * @param refLr referred length restriction of typedef
* @throws DataModelException a violation in data model rule
*/
- private void resolveBinaryRestriction(YangRangeRestriction refLengthRestriction)
+ private void resolveBinaryRestriction(YangRangeRestriction refLr)
throws DataModelException {
if (rangeRestrictionString != null || patternRestriction != null) {
- DataModelException dataModelException =
- new DataModelException("YANG file error: for binary " +
- "range restriction or pattern restriction is not allowed.");
- dataModelException.setLine(getLineNumber());
- dataModelException.setCharPosition(getCharPosition());
- dataModelException.setFileName(getFileName());
- throw dataModelException;
+ throw new DataModelException(getErrorMsg(
+ "YANG file error: for binary range restriction or pattern " +
+ "restriction is not allowed.", "type.",
+ getLineNumber(), getCharPosition(), getFileName()));
}
// Get the final resolved length restriction
- YangRangeRestriction lengthRestriction = resolveLengthRestriction(refLengthRestriction);
- // Set the lenght restriction.
- setResolvedExtendedInfo((T) lengthRestriction);
+ YangRangeRestriction lr = resolveLengthRestriction(refLr);
+ // Set the length restriction.
+ resolvedExtendedInfo = (T) lr;
}
/**
* Resolves pattern restriction.
*
- * @param refPatternRestriction referred pattern restriction of typedef
+ * @param refPr referred pattern restriction of typedef
* @return resolved pattern restriction
*/
- private YangPatternRestriction resolvePatternRestriction(YangPatternRestriction refPatternRestriction) {
+ private YangPatternRestriction resolvePatternRestriction(YangPatternRestriction refPr) {
/*
* If referred restriction and self restriction both are null, no
* resolution is required.
*/
- if (refPatternRestriction == null && getPatternRestriction() == null) {
+ if (refPr == null && getPatternRestriction() == null) {
return null;
}
@@ -619,14 +517,14 @@
* shallow copy the referred to self.
*/
if (getPatternRestriction() == null) {
- return refPatternRestriction;
+ return refPr;
}
/*
* If referred restriction is null, and self restriction is present
* carry out self resolution.
*/
- if (refPatternRestriction == null) {
+ if (refPr == null) {
return getPatternRestriction();
}
@@ -634,7 +532,7 @@
* Get patterns of referred type and add it to current pattern
* restrictions.
*/
- for (String pattern : refPatternRestriction.getPatternList()) {
+ for (String pattern : refPr.getPatternList()) {
getPatternRestriction().addPattern(pattern);
}
return getPatternRestriction();
@@ -643,18 +541,18 @@
/**
* Resolves the length restrictions.
*
- * @param refLengthRestriction referred length restriction of typedef
+ * @param refLenRestriction referred length restriction of typedef
* @return resolved length restriction
* @throws DataModelException a violation in data model rule
*/
- private YangRangeRestriction resolveLengthRestriction(YangRangeRestriction refLengthRestriction)
- throws DataModelException {
+ private YangRangeRestriction resolveLengthRestriction(
+ YangRangeRestriction refLenRestriction) throws DataModelException {
/*
* If referred restriction and self restriction both are null, no
* resolution is required.
*/
- if (refLengthRestriction == null && Strings.isNullOrEmpty(getLengthRestrictionString())) {
+ if (refLenRestriction == null && isNullOrEmpty(getLengthRestrictionString())) {
return null;
}
@@ -662,20 +560,18 @@
* If self restriction is null, and referred restriction is present
* shallow copy the referred to self.
*/
- if (Strings.isNullOrEmpty(getLengthRestrictionString())) {
- return refLengthRestriction;
+ if (isNullOrEmpty(getLengthRestrictionString())) {
+ return refLenRestriction;
}
/*
* If referred restriction is null, and self restriction is present
* carry out self resolution.
*/
- if (refLengthRestriction == null) {
- YangRangeRestriction curLengthRestriction =
- processLengthRestriction(null, getLineNumber(),
- getCharPosition(), false,
- getLengthRestrictionString(), getFileName());
- return curLengthRestriction;
+ if (refLenRestriction == null) {
+ return processLengthRestriction(
+ null, getLineNumber(), getCharPosition(), false,
+ getLengthRestrictionString(), getFileName());
}
/*
@@ -683,12 +579,12 @@
* and MIN/MAX values as per the referred typedef's values.
*/
YangRangeRestriction curLengthRestriction =
- processLengthRestriction(refLengthRestriction, getLineNumber(),
+ processLengthRestriction(refLenRestriction, getLineNumber(),
getCharPosition(), true,
getLengthRestrictionString(), getFileName());
// Resolve the range with referred typedef's restriction.
- resolveLengthAndRangeRestriction(refLengthRestriction, curLengthRestriction);
+ resolveLengthAndRangeRestriction(refLenRestriction, curLengthRestriction);
return curLengthRestriction;
}
@@ -705,20 +601,17 @@
throws DataModelException {
for (Object curInterval : curRestriction.getAscendingRangeIntervals()) {
if (!(curInterval instanceof YangRangeInterval)) {
- throw new DataModelException("Linker error: Current range intervals not processed correctly."
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ throw new DataModelException(getErrorMsg(
+ "Linker error: Current range intervals not processed correctly.",
+ "type.", getLineNumber(), getCharPosition(), getFileName()));
}
try {
- refRestriction.isValidInterval((YangRangeInterval) curInterval);
+ refRestriction.isValidInterval((YangRangeInterval)
+ curInterval, getFileName());
} catch (DataModelException e) {
- DataModelException dataModelException = new DataModelException(e);
- dataModelException.setLine(getLineNumber());
- dataModelException.setCharPosition(getCharPosition());
- dataModelException.setFileName(getFileName());
- throw dataModelException;
+ throw new DataModelException(getErrorMsg(
+ e.getMessage(), "type.", getLineNumber(), getCharPosition(),
+ getFileName()));
}
}
}
@@ -736,20 +629,19 @@
* Check that string restriction should be null when built-in type is of
* range type.
*/
- if (!Strings.isNullOrEmpty(getLengthRestrictionString()) || getPatternRestriction() != null) {
- DataModelException dataModelException = new DataModelException("YANG file error: Length/Pattern " +
- "restriction should't be present for int/uint/decimal data type.");
- dataModelException.setLine(getLineNumber());
- dataModelException.setCharPosition(getCharPosition());
- dataModelException.setFileName(getFileName());
- throw dataModelException;
+ if (!isNullOrEmpty(getLengthRestrictionString())
+ || getPatternRestriction() != null) {
+ throw new DataModelException(getErrorMsg(
+ "YANG file error: Length/Pattern restriction should't be present" +
+ " for int/uint/decimal data type.", "type.", getLineNumber(),
+ getCharPosition(), getFileName()));
}
/*
* If referred restriction and self restriction both are null, no
* resolution is required.
*/
- if (refRangeRestriction == null && Strings.isNullOrEmpty(getRangeRestrictionString())) {
+ if (refRangeRestriction == null && isNullOrEmpty(getRangeRestrictionString())) {
return;
}
@@ -757,8 +649,8 @@
* If self restriction is null, and referred restriction is present
* shallow copy the referred to self.
*/
- if (Strings.isNullOrEmpty(getRangeRestrictionString())) {
- setResolvedExtendedInfo((T) refRangeRestriction);
+ if (isNullOrEmpty(getRangeRestrictionString())) {
+ resolvedExtendedInfo = (T) refRangeRestriction;
return;
}
@@ -770,8 +662,8 @@
YangRangeRestriction curRangeRestriction =
processRangeRestriction(null, getLineNumber(),
getCharPosition(), false, getRangeRestrictionString(),
- getEffectiveBuiltInType(), getFileName());
- setResolvedExtendedInfo((T) curRangeRestriction);
+ effectiveBuiltInType, getFileName());
+ resolvedExtendedInfo = (T) curRangeRestriction;
return;
}
@@ -783,26 +675,10 @@
processRangeRestriction(refRangeRestriction, getLineNumber(),
getCharPosition(), true,
getRangeRestrictionString(),
- getEffectiveBuiltInType(), getFileName());
+ effectiveBuiltInType, getFileName());
// Resolve the range with referred typedef's restriction.
resolveLengthAndRangeRestriction(refRangeRestriction, curRangeRestriction);
- setResolvedExtendedInfo((T) curRangeRestriction);
- }
-
- /**
- * Returns whether the data type is of non restricted type.
- *
- * @param dataType data type to be checked
- * @return true, if data type can't be restricted, false otherwise
- */
- private boolean isOfValidNonRestrictedType(YangDataTypes dataType) {
- return dataType == BOOLEAN
- || dataType == ENUMERATION
- || dataType == BITS
- || dataType == EMPTY
- || dataType == UNION
- || dataType == IDENTITYREF
- || dataType == LEAFREF;
+ resolvedExtendedInfo = (T) curRangeRestriction;
}
}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLengthRestriction.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLengthRestriction.java
index ed75d01..ce8fb4f 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLengthRestriction.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLengthRestriction.java
@@ -23,6 +23,8 @@
import java.io.Serializable;
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.PATTERN_DATA;
+
/*-
* Reference RFC 6020.
*
@@ -163,7 +165,7 @@
@Override
public YangConstructType getYangConstructType() {
- return YangConstructType.PATTERN_DATA;
+ return PATTERN_DATA;
}
@Override
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMaxElement.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMaxElement.java
index 9ffd3a6..507f70e 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMaxElement.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMaxElement.java
@@ -18,6 +18,7 @@
import java.io.Serializable;
+import static java.lang.Integer.MAX_VALUE;
import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.OPERATION_FAILED_ERROR_TAG;
import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.TOO_MANY_ELEMENTS_ERROR_APP_TAG;
@@ -44,7 +45,7 @@
* <p>
* If no "max-elements" statement is present, it defaults to "unbounded".
*/
- private int maxElement = Integer.MAX_VALUE;
+ private int maxElement = MAX_VALUE;
/**
* Creates a YANG maximum element.
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMinElement.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMinElement.java
index a2b73d3..21b95d0 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMinElement.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMinElement.java
@@ -52,7 +52,7 @@
* <p>
* Otherwise, it is enforced if the ancestor node exists.
*/
- private int minElement = 0;
+ private int minElement;
/**
* Creates a YANG minimum element.
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangPatternRestriction.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangPatternRestriction.java
index c5376b0..693461b 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangPatternRestriction.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangPatternRestriction.java
@@ -20,6 +20,8 @@
import java.util.LinkedList;
import java.util.List;
+import static java.util.Collections.unmodifiableList;
+
/*-
* Reference RFC 6020.
*
@@ -60,7 +62,7 @@
/**
* Pattern restriction defined for the current type.
*/
- private List<String> patternList;
+ private final List<String> patternList;
/**
* YANG application error information.
@@ -71,7 +73,7 @@
* Creates a YANG pattern restriction object.
*/
public YangPatternRestriction() {
- setPatternList(new LinkedList<>());
+ patternList = new LinkedList<>();
yangAppErrorInfo = new YangAppErrorInfo();
}
@@ -81,16 +83,7 @@
* @return pattern restriction defined for the current type.
*/
public List<String> getPatternList() {
- return patternList;
- }
-
- /**
- * Sets the pattern restriction defined for the current type.
- *
- * @param pattern pattern restriction defined for the current type..
- */
- private void setPatternList(List<String> pattern) {
- patternList = pattern;
+ return unmodifiableList(patternList);
}
/**
@@ -99,7 +92,7 @@
* @param newPattern pattern restriction.
*/
public void addPattern(String newPattern) {
- getPatternList().add(newPattern);
+ patternList.add(newPattern);
}
@Override
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java
index 346b794..316c09c 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java
@@ -28,6 +28,8 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.yangutils.datamodel.BuiltInTypeObjectFactory.getDataObjectFromString;
+import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.getErrorMsg;
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.RANGE_DATA;
/*-
* Reference RFC 6020.
@@ -59,7 +61,8 @@
*
* @param <T> range type (data type)
*/
-public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>> extends DefaultLocationInfo
+public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>>
+ extends DefaultLocationInfo
implements YangDesc, YangReference, Parsable, Serializable, YangAppErrorHolder {
private static final long serialVersionUID = 8062016051L;
@@ -102,34 +105,21 @@
}
/**
- * Sets the list of range interval restriction in ascending order.
- *
- * @param rangeList list of range interval restriction in ascending order
- */
- private void setAscendingRangeIntervals(List<YangRangeInterval<T>> rangeList) {
- ascendingRangeIntervals = rangeList;
- }
-
- /**
* Returns the minimum valid value as per the restriction.
*
* @return minimum restricted value
* @throws DataModelException data model exception for minimum restriction
*/
- public T getMinRestrictedvalue() throws DataModelException {
+ public T getMinRestrictedValue() throws DataModelException {
if (getAscendingRangeIntervals() == null) {
- throw new DataModelException("No range restriction info "
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ throw new DataModelException(getErrorMsg(
+ "No range restriction info ",
+ "", getLineNumber(), getCharPosition(), getFileName() + "\""));
}
if (getAscendingRangeIntervals().isEmpty()) {
- throw new DataModelException("No range interval info "
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ throw new DataModelException(getErrorMsg(
+ "No range interval info ",
+ "", getLineNumber(), getCharPosition(), getFileName() + "\""));
}
return getAscendingRangeIntervals().get(0).getStartValue();
}
@@ -140,20 +130,16 @@
* @return minimum maximum value
* @throws DataModelException data model exception for maximum restriction
*/
- public T getMaxRestrictedvalue() throws DataModelException {
+ public T getMaxRestrictedValue() throws DataModelException {
if (getAscendingRangeIntervals() == null) {
- throw new DataModelException("No range restriction info "
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ throw new DataModelException(getErrorMsg(
+ "No range restriction info ",
+ "", getLineNumber(), getCharPosition(), getFileName() + "\""));
}
if (getAscendingRangeIntervals().isEmpty()) {
- throw new DataModelException("No range interval info "
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ throw new DataModelException(getErrorMsg(
+ "No range interval info ",
+ "", getLineNumber(), getCharPosition(), getFileName() + "\""));
}
return getAscendingRangeIntervals()
.get(getAscendingRangeIntervals().size() - 1).getEndValue();
@@ -166,34 +152,27 @@
* @param newInterval restricted length interval
* @throws DataModelException data model exception for range restriction
*/
- public void addRangeRestrictionInterval(YangRangeInterval<T> newInterval) throws DataModelException {
-
+ public void addRangeRestrictionInterval(YangRangeInterval<T> newInterval)
+ throws DataModelException {
checkNotNull(newInterval);
checkNotNull(newInterval.getStartValue());
-
- if (getAscendingRangeIntervals() == null) {
+ if (ascendingRangeIntervals == null) {
/*
* First interval that is being added, and it must be the smallest
* interval.
*/
- setAscendingRangeIntervals(new LinkedList<YangRangeInterval<T>>());
- getAscendingRangeIntervals().add(newInterval);
+ ascendingRangeIntervals = new LinkedList<>();
+ ascendingRangeIntervals.add(newInterval);
return;
}
- T curMaxvalue = getMaxRestrictedvalue();
-
+ T curMaxvalue = getMaxRestrictedValue();
if (newInterval.getStartValue().compareTo(curMaxvalue) < 1) {
- throw new DataModelException(
- "New added range interval is lesser than the old interval(s) "
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ throw new DataModelException(getErrorMsg(
+ "New added range interval is lesser than the old interval(s) ",
+ "", getLineNumber(), getCharPosition(), getFileName() + "\""));
}
-
- getAscendingRangeIntervals()
- .add(getAscendingRangeIntervals().size(), newInterval);
+ getAscendingRangeIntervals().add(getAscendingRangeIntervals().size(), newInterval);
}
/**
@@ -203,18 +182,15 @@
* @return true, if the value is confirming to restriction, false otherwise
* @throws DataModelException data model error
*/
- public boolean isValidValueString(String valueInString) throws DataModelException {
+ boolean isValidValueString(String valueInString) throws DataModelException {
if (getAscendingRangeIntervals() == null
|| getAscendingRangeIntervals().isEmpty()) {
// Throw exception, At least one default range needs to be set in
// constructor or in linker.
- throw new DataModelException("Range interval missing in range restriction. "
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
-
+ throw new DataModelException(getErrorMsg(
+ "Range interval missing in range restriction. ",
+ "", getLineNumber(), getCharPosition(), getFileName() + "\""));
}
YangDataTypes type = getAscendingRangeIntervals().get(0).getStartValue().getYangType();
@@ -235,20 +211,20 @@
* Validates if the given interval is correct as per the restriction.
*
* @param rangeInterval range interval
+ * @param fileName file name
* @return true, if the interval is confirming to restriction, false otherwise
* @throws DataModelException data model error
*/
- public boolean isValidInterval(YangRangeInterval rangeInterval) throws DataModelException {
+ boolean isValidInterval(YangRangeInterval rangeInterval, String fileName)
+ throws DataModelException {
if (getAscendingRangeIntervals() == null
|| getAscendingRangeIntervals().isEmpty()) {
// Throw exception, At least one default range needs to be set in
// constructor or in linker.
- throw new DataModelException("Range interval missing in range restriction. "
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ throw new DataModelException(getErrorMsg(
+ "Range interval missing in range restriction. ",
+ "restriction ranges.", getLineNumber(), getCharPosition(), fileName + "\""));
}
for (YangRangeInterval<T> interval : getAscendingRangeIntervals()) {
@@ -259,11 +235,9 @@
return true;
}
}
- throw new DataModelException("Range interval doesn't fall within the referred restriction ranges "
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ throw new DataModelException(getErrorMsg(
+ "Range interval doesn't fall within the referred restriction ranges ",
+ "restriction ranges.", getLineNumber(), getCharPosition(), fileName + "\""));
}
/**
@@ -309,7 +283,7 @@
@Override
public YangConstructType getYangConstructType() {
- return YangConstructType.RANGE_DATA;
+ return RANGE_DATA;
}
@Override
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSchemaNodeIdentifier.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSchemaNodeIdentifier.java
index 8067bda..59dcc62 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSchemaNodeIdentifier.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSchemaNodeIdentifier.java
@@ -88,8 +88,8 @@
if (!Objects.equals(name, other.name)) {
return false;
}
- final String name = namespace.getModuleName();
- final String otherName = other.getNameSpace().getModuleName();
+ String name = namespace.getModuleName();
+ String otherName = other.getNameSpace().getModuleName();
if (name != null && otherName != null) {
if (namespace.getModuleName()
.equals(other.getNameSpace().getModuleName())) {
@@ -97,10 +97,10 @@
}
}
- final String nspace = namespace.getModuleNamespace();
- final String otherNspace = other.getNameSpace().getModuleNamespace();
- if (nspace != null && otherNspace != null) {
- if (nspace.equals(otherNspace)) {
+ String nSpace = namespace.getModuleNamespace();
+ String otherNspace = other.getNameSpace().getModuleNamespace();
+ if (nSpace != null && otherNspace != null) {
+ if (nSpace.equals(otherNspace)) {
return true;
}
}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangStringRestriction.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangStringRestriction.java
index b099f78..329d2b1 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangStringRestriction.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangStringRestriction.java
@@ -16,15 +16,17 @@
package org.onosproject.yangutils.datamodel;
-import java.io.Serializable;
-import java.math.BigInteger;
-import java.util.ListIterator;
-
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangUint64;
+import java.io.Serializable;
+import java.math.BigInteger;
+import java.util.ListIterator;
+
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.PATTERN_DATA;
+
/*-
* Reference RFC 6020.
*
@@ -114,10 +116,10 @@
/**
* Sets the length restriction on the string data.
*
- * @param lengthRestriction length restriction on the string data
+ * @param rest length restriction on the string data
*/
- public void setLengthRestriction(YangRangeRestriction<YangUint64> lengthRestriction) {
- this.lengthRestriction = lengthRestriction;
+ public void setLengthRestriction(YangRangeRestriction<YangUint64> rest) {
+ lengthRestriction = rest;
}
/**
@@ -132,10 +134,10 @@
/**
* Sets the pattern restriction for the type.
*
- * @param patternRestriction pattern restriction for the type
+ * @param rest pattern restriction for the type
*/
- public void setPatternRestriction(YangPatternRestriction patternRestriction) {
- this.patternRestriction = patternRestriction;
+ void setPatternRestriction(YangPatternRestriction rest) {
+ patternRestriction = rest;
}
/**
@@ -144,10 +146,10 @@
* @param newPattern new pattern restriction for the type
*/
public void addPattern(String newPattern) {
- if (getPatternRestriction() == null) {
- setPatternRestriction(new YangPatternRestriction());
+ if (patternRestriction == null) {
+ patternRestriction = new YangPatternRestriction();
}
- getPatternRestriction().addPattern(newPattern);
+ patternRestriction.addPattern(newPattern);
}
/**
@@ -193,7 +195,7 @@
@Override
public YangConstructType getYangConstructType() {
- return YangConstructType.PATTERN_DATA;
+ return PATTERN_DATA;
}
/**
@@ -202,15 +204,15 @@
* @param valueInString value
* @return true, if the value is confirming to length restriction, false otherwise
*/
- public boolean isValidStringOnLengthRestriction(String valueInString) {
+ boolean isValidStringOnLengthRestriction(String valueInString) {
if (lengthRestriction == null || lengthRestriction.getAscendingRangeIntervals() == null
|| lengthRestriction.getAscendingRangeIntervals().isEmpty()) {
// Length restriction is optional
return true;
}
- ListIterator<YangRangeInterval<YangUint64>> rangeListIterator = lengthRestriction.getAscendingRangeIntervals()
- .listIterator();
+ ListIterator<YangRangeInterval<YangUint64>> rangeListIterator =
+ lengthRestriction.getAscendingRangeIntervals().listIterator();
boolean isMatched = false;
while (rangeListIterator.hasNext()) {
YangRangeInterval rangeInterval = rangeListIterator.next();
@@ -219,8 +221,8 @@
rangeInterval.setFileName(getFileName());
BigInteger startValue = ((YangUint64) rangeInterval.getStartValue()).getValue();
BigInteger endValue = ((YangUint64) rangeInterval.getEndValue()).getValue();
- if ((valueInString.length() >= startValue.intValue()) &&
- (valueInString.length() <= endValue.intValue())) {
+ if (valueInString.length() >= startValue.intValue() &&
+ valueInString.length() <= endValue.intValue()) {
isMatched = true;
break;
}
@@ -235,14 +237,15 @@
* @param valueInString value
* @return true, if the value is confirming to pattern restriction, false otherwise
*/
- public boolean isValidStringOnPatternRestriction(String valueInString) {
+ boolean isValidStringOnPatternRestriction(String valueInString) {
if (patternRestriction == null
|| patternRestriction.getPatternList().isEmpty()) {
// Pattern restriction is optional
return true;
}
- ListIterator<String> patternListIterator = patternRestriction.getPatternList().listIterator();
+ ListIterator<String> patternListIterator =
+ patternRestriction.getPatternList().listIterator();
boolean isMatched = false;
while (patternListIterator.hasNext()) {
if (valueInString.matches(patternListIterator.next())) {
@@ -250,7 +253,6 @@
break;
}
}
-
return isMatched;
}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/javadatamodel/YangJavaModule.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/javadatamodel/YangJavaModule.java
index 3a769d6..9a05ff1 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/javadatamodel/YangJavaModule.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/javadatamodel/YangJavaModule.java
@@ -17,6 +17,11 @@
package org.onosproject.yangutils.datamodel.javadatamodel;
import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+
+import java.util.List;
+
+import static java.util.Collections.unmodifiableList;
/**
* Represents YANG java module.
@@ -27,6 +32,7 @@
private static final long serialVersionUID = 208201609L;
protected JavaFileInfo javaFileInfo;
+ protected List<YangNode> notificationNodes;
/**
* Returns java file info.
@@ -51,4 +57,9 @@
public String getJavaAttributeName() {
throw new RuntimeException("Attribute name is not applicable ");
}
+
+ @Override
+ public List<YangNode> getNotificationNodes() {
+ return unmodifiableList(notificationNodes);
+ }
}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/javadatamodel/YangJavaSubModule.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/javadatamodel/YangJavaSubModule.java
index 435a182..03a56f7 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/javadatamodel/YangJavaSubModule.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/javadatamodel/YangJavaSubModule.java
@@ -16,8 +16,13 @@
package org.onosproject.yangutils.datamodel.javadatamodel;
+import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangSubModule;
+import java.util.List;
+
+import static java.util.Collections.unmodifiableList;
+
/**
* Represents YANG java submodule.
*/
@@ -27,6 +32,7 @@
private static final long serialVersionUID = 208201612L;
protected JavaFileInfo javaFileInfo;
+ protected List<YangNode> notificationNodes;
/**
* Returns java file info.
@@ -51,4 +57,9 @@
public String getJavaAttributeName() {
throw new RuntimeException("Attribute name is not applicable ");
}
+
+ @Override
+ public List<YangNode> getNotificationNodes() {
+ return unmodifiableList(notificationNodes);
+ }
}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/RestrictionResolver.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/RestrictionResolver.java
index 17c455e..8750e82 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/RestrictionResolver.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/RestrictionResolver.java
@@ -22,11 +22,12 @@
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangBuiltInDataTypeInfo;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
-import java.util.regex.Pattern;
-
+import static java.util.regex.Pattern.quote;
import static org.onosproject.yangutils.datamodel.BuiltInTypeObjectFactory.getDataObjectFromString;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.LENGTH_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.RANGE_DATA;
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.getYangConstructType;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT64;
/**
* Represents restriction resolver which provide common utility used by parser
@@ -42,6 +43,8 @@
private static final int MIN_RANGE_BOUNDARY = 1;
private static final String MIN_KEYWORD = "min";
private static final String MAX_KEYWORD = "max";
+ private static final String SPACE = " ";
+ private static final String QUOTE = "\"";
/**
* Creates a restriction resolver.
@@ -52,134 +55,86 @@
/**
* 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
- * @param fileName file name
+ * @param refRr range restriction of referred typedef
+ * @param line error line number
+ * @param position error character position in line
+ * @param hasRefR whether has referred restriction
+ * @param curRange caller type's range string
+ * @param type effective type, when called from linker
+ * @param fileName file name
* @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, String fileName)
+ public static YangRangeRestriction processRangeRestriction(
+ YangRangeRestriction refRr, int line, int position,
+ boolean hasRefR, String curRange, YangDataTypes type, String fileName)
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();
- rangeInterval.setCharPosition(charPositionInLine);
- rangeInterval.setLineNumber(lineNumber);
- rangeInterval.setFileName(fileName);
- 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;
+ return getRestriction(refRr, line, position, hasRefR, curRange, fileName,
+ type, RANGE_DATA);
}
/**
* 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
- * @param fileName file name
+ * @param refLr length restriction of referred typedef
+ * @param line error line number
+ * @param position error character position in line
+ * @param hasRefR whether has referred restriction
+ * @param curLenStr caller type's length string
+ * @param fileName file name
* @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, String fileName) throws DataModelException {
+ public static YangRangeRestriction processLengthRestriction(
+ YangRangeRestriction refLr, int line, int position, boolean hasRefR,
+ String curLenStr, String fileName) throws DataModelException {
+ return getRestriction(refLr, line, position, hasRefR, curLenStr, fileName,
+ UINT64, LENGTH_DATA);
+ }
+ /**
+ * Processes the range/length restriction for parser and linker.
+ *
+ * @param refR range/length restriction of referred typedef
+ * @param line error line number
+ * @param position error character position in line
+ * @param hasRefR whether has referred restriction
+ * @param curRange caller type's range string
+ * @param type effective type, when called from linker
+ * @param fileName file name
+ * @param conType construct type
+ * @return YANG range restriction
+ * @throws DataModelException a violation in data model rule
+ */
+ private static YangRangeRestriction getRestriction(
+ YangRangeRestriction refR, int line, int position, boolean hasRefR,
+ String curRange, String fileName, YangDataTypes type,
+ YangConstructType conType) throws
+ DataModelException {
YangBuiltInDataTypeInfo<?> startValue;
YangBuiltInDataTypeInfo<?> endValue;
- YangRangeRestriction lengthRestriction = new YangRangeRestriction<>();
+ YangRangeRestriction rr = new YangRangeRestriction();
- String rangeArgument = removeQuotesAndHandleConcat(curLengthString);
- String[] rangeArguments = rangeArgument.trim().split(Pattern.quote(PIPE));
+ String rangeArg = removeQuotesAndHandleConcat(curRange);
+ String[] rangeArguments = rangeArg.trim().split(quote(PIPE));
for (String rangePart : rangeArguments) {
String startInterval;
String endInterval;
- YangRangeInterval rangeInterval = new YangRangeInterval<>();
- rangeInterval.setCharPosition(charPositionInLine);
- rangeInterval.setLineNumber(lineNumber);
+ YangRangeInterval rangeInterval = new YangRangeInterval();
+ rangeInterval.setCharPosition(position);
+ rangeInterval.setLineNumber(line);
rangeInterval.setFileName(fileName);
- String[] rangeBoundary = rangePart.trim().split(Pattern.quote(INTERVAL));
+ String[] rangeBoundary = rangePart.trim().split(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;
+ DataModelException ex = new DataModelException(
+ "YANG file error : " + getYangConstructType(conType) +
+ SPACE + rangeArg + " is not valid.");
+ ex.setLine(line);
+ ex.setCharPosition(position);
+ ex.setFileName(fileName);
+ throw ex;
}
if (rangeBoundary.length == MIN_RANGE_BOUNDARY) {
@@ -191,43 +146,43 @@
}
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();
+ if (hasRefR && startInterval.equals(MIN_KEYWORD) &&
+ refR.getMinRestrictedValue() != null) {
+ startValue = refR.getMinRestrictedValue();
+ } else if (hasRefR && startInterval.equals(MAX_KEYWORD) &&
+ refR.getMaxRestrictedValue() != null) {
+ startValue = refR.getMaxRestrictedValue();
} else {
- startValue = getDataObjectFromString(startInterval, YangDataTypes.UINT64);
+ startValue = getDataObjectFromString(startInterval, type);
}
- 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();
+ if (hasRefR && endInterval.equals(MIN_KEYWORD) &&
+ refR.getMinRestrictedValue() != null) {
+ endValue = refR.getMinRestrictedValue();
+ } else if (hasRefR && endInterval.equals(MAX_KEYWORD) &&
+ refR.getMaxRestrictedValue() != null) {
+ endValue = refR.getMaxRestrictedValue();
} else {
- endValue = getDataObjectFromString(endInterval, YangDataTypes.UINT64);
+ endValue = getDataObjectFromString(endInterval, type);
}
} catch (Exception e) {
- DataModelException dataModelException = new DataModelException(e.getMessage());
- dataModelException.setLine(lineNumber);
- dataModelException.setCharPosition(charPositionInLine);
- throw dataModelException;
+ DataModelException ex = new DataModelException(e.getMessage());
+ ex.setLine(line);
+ ex.setCharPosition(position);
+ ex.setFileName(fileName);
+ throw ex;
}
-
rangeInterval.setStartValue(startValue);
rangeInterval.setEndValue(endValue);
-
try {
- lengthRestriction.addRangeRestrictionInterval(rangeInterval);
- } catch (DataModelException dataModelException) {
- dataModelException.setLine(lineNumber);
- dataModelException.setCharPosition(charPositionInLine);
- throw dataModelException;
+ rr.addRangeRestrictionInterval(rangeInterval);
+ } catch (DataModelException ex) {
+ ex.setLine(line);
+ ex.setCharPosition(position);
+ ex.setFileName(fileName);
+ throw ex;
}
}
- return lengthRestriction;
+ return rr;
}
/**
@@ -237,9 +192,8 @@
* @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));
+ yangStringData = yangStringData.replace(QUOTE, EMPTY_STRING);
+ String[] tmpData = yangStringData.split(quote(ADD));
StringBuilder builder = new StringBuilder();
for (String yangString : tmpData) {
builder.append(yangString);
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangDataTypes.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangDataTypes.java
index 3506c56..4b6e8bf 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangDataTypes.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangDataTypes.java
@@ -22,21 +22,21 @@
public enum YangDataTypes {
/**
* Reference:RFC 6020.
- *
+ * <p>
* int8 represents integer values between -128 and 127, inclusively.
*/
INT8("int8"),
/**
* Reference:RFC 6020.
- *
+ * <p>
* int16 represents integer values between -32768 and 32767, inclusively.
*/
INT16("int16"),
/**
* Reference:RFC 6020.
- *
+ * <p>
* int32 represents integer values between -2147483648 and 2147483647,
* inclusively.
*/
@@ -44,7 +44,7 @@
/**
* Reference:RFC 6020.
- *
+ * <p>
* int64 represents integer values between -9223372036854775808 and
* 9223372036854775807, inclusively.
*/
@@ -52,28 +52,28 @@
/**
* Reference:RFC 6020.
- *
+ * <p>
* uint8 represents integer values between 0 and 255, inclusively.
*/
UINT8("uint8"),
/**
* Reference:RFC 6020.
- *
+ * <p>
* uint16 represents integer values between 0 and 65535, inclusively.
*/
UINT16("uint16"),
/**
* Reference:RFC 6020.
- *
+ * <p>
* uint32 represents integer values between 0 and 4294967295, inclusively.
*/
UINT32("uint32"),
/**
* Reference:RFC 6020.
- *
+ * <p>
* uint64 represents integer values between 0 and 18446744073709551615,
* inclusively.
*/
@@ -81,7 +81,7 @@
/**
* Reference:RFC 6020.
- *
+ * <p>
* The decimal64 type represents a subset of the real numbers, which can be
* represented by decimal numerals. The value space of decimal64 is the set
* of numbers that can be obtained by multiplying a 64-bit signed integer by
@@ -92,7 +92,7 @@
/**
* Reference:RFC 6020.
- *
+ * <p>
* The string built-in type represents human-readable strings in YANG. Legal
* characters are tab, carriage return, line feed, and the legal characters
* of Unicode and ISO/IEC 10646
@@ -101,14 +101,14 @@
/**
* Reference:RFC 6020.
- *
+ * <p>
* The boolean built-in type represents a boolean value.
*/
BOOLEAN("boolean"),
/**
* Reference:RFC 6020.
- *
+ * <p>
* The enumeration built-in type represents values from a set of assigned
* names.
*/
@@ -116,7 +116,7 @@
/**
* Reference:RFC 6020.
- *
+ * <p>
* The bits built-in type represents a bit set. That is, a bits value is a
* set of flags identified by small integer position numbers starting at 0.
* Each bit number has an assigned name.
@@ -125,7 +125,7 @@
/**
* Reference:RFC 6020.
- *
+ * <p>
* The binary built-in type represents any binary data, i.e., a sequence of
* octets.
*/
@@ -133,19 +133,19 @@
/**
* Reference:RFC 6020.
- *
+ * <p>
* The leafref type is used to reference a particular leaf instance in the
* data tree. The "path" sub-statement (Section 9.9.2) selects a set of leaf
* instances, and the leafref value space is the set of values of these leaf
* instances.
- *
+ * <p>
* If the leaf with the leafref type represents configuration data, the leaf
* it refers to MUST also represent configuration. Such a leaf puts a
* constraint on valid data. All leafref nodes MUST reference existing leaf
* instances or leafs with default values in use for the data to be valid.
- *
+ * <p>
* There MUST NOT be any circular chains of leafrefs.
- *
+ * <p>
* If the leaf that the leafref refers to is conditional based on one or
* more features, then the leaf with the leafref type MUST also be
* conditional based on at least the same set of features.
@@ -154,38 +154,38 @@
/**
* Reference:RFC 6020.
- *
+ * <p>
* The identityref type is used to reference an existing identity.
*/
IDENTITYREF("identityref"),
/**
* Reference:RFC 6020.
- *
+ * <p>
* The empty built-in type represents a leaf that does not have any value,
* it conveys information by its presence or absence.
- *
+ * <p>
* An empty type cannot have a default value.
*/
EMPTY("empty"),
/**
* Reference:RFC 6020.
- *
+ * <p>
* The union built-in type represents a value that corresponds to one of its
* member types.
- *
+ * <p>
* When the type is "union", the "type" statement MUST be present. It is
* used to repeatedly specify each member type of the union. It takes as an
* argument a string that is the name of a member type.
- *
+ * <p>
* A member type can be of any built-in or derived type, except it MUST NOT
* be one of the built-in types "empty" or "leafref".
- *
+ * <p>
* When a string representing a union data type is validated, the string is
* validated against each member type, in the order they are specified in
* the "type" statement, until a match is found.
- *
+ * <p>
* Any default value or "units" property defined in the member types is not
* inherited by the union type.
*/
@@ -193,10 +193,10 @@
/**
* Reference:RFC 6020.
- *
+ * <p>
* The instance-identifier built-in type is used to uniquely identify a
* particular instance node in the data tree.
- *
+ * <p>
* The syntax for an instance-identifier is a subset of the XPath
* abbreviated syntax, formally defined by the rule "instance-identifier".
* It is used to uniquely identify a node in the data tree. Predicates are
@@ -205,7 +205,7 @@
* keys. For identifying list entries with keys, each predicate consists of
* one equality test per key, and each key MUST have a corresponding
* predicate.
- *
+ * <p>
* If the leaf with the instance-identifier type represents configuration
* data, and the "require-instance" property is "true", the node it refers
* to MUST also represent configuration. Such a leaf puts a constraint on
@@ -222,7 +222,7 @@
/**
* Defined type from the enum value.
*/
- private String definedType;
+ private final String definedType;
/**
* Constructs type value from enum.
@@ -248,4 +248,38 @@
}
return YangDataTypes.DERIVED;
}
+
+ /**
+ * Returns whether the data type is of primitive data type.
+ *
+ * @return true, if data type can have primitive data type, false otherwise
+ */
+ public boolean isPrimitiveDataType() {
+ return this == INT8 ||
+ this == INT16 ||
+ this == INT32 ||
+ this == INT64 ||
+ this == UINT8 ||
+ this == UINT16 ||
+ this == UINT32 ||
+ this == UINT64 ||
+ this == DECIMAL64 ||
+ this == BOOLEAN ||
+ this == EMPTY;
+ }
+
+ /**
+ * Returns whether the data type is of non restricted type.
+ *
+ * @return true, if data type can't be restricted, false otherwise
+ */
+ public boolean isNonRestrictedType() {
+ return this == BOOLEAN ||
+ this == ENUMERATION ||
+ this == BITS ||
+ this == EMPTY ||
+ this == UNION ||
+ this == IDENTITYREF ||
+ this == LEAFREF;
+ }
}