Merge "[ONOS-7201][YRT]Defect: Post type is not same as get for union and for type empty is returning null."
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/ObjectProvider.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/ObjectProvider.java
index cea5549..f7bc8d1 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/ObjectProvider.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/ObjectProvider.java
@@ -29,6 +29,8 @@
// Object provider constant error string.
private static final String E_DATATYPE = "Data type not supported.";
+ private static final String T = "true";
+ private static final String F = "false";
private static final String E_NONEMPTY = "Value is of non Empty type";
/**
@@ -40,14 +42,13 @@
/**
* Returns object from string value.
*
- * @param typeInfo refers to YANG type information
- * @param leafValue leafValue argument is used to set the value
- * in method
- * @param dataType yang data type
+ * @param typeInfo refers to YANG type information
+ * @param v v argument is leaf value used to set the value in method
+ * @param dataType yang data type
* @return values object of corresponding given data type
* @throws IllegalArgumentException if input is not valid
*/
- public static Object getObject(YangType typeInfo, String leafValue,
+ public static Object getObject(YangType typeInfo, String v,
YangDataTypes dataType)
throws IllegalArgumentException {
YangDataTypes type;
@@ -58,49 +59,51 @@
}
switch (type) {
case INT8:
- return Byte.parseByte(leafValue);
+ return Byte.parseByte(v);
case UINT8:
case INT16:
- return Short.parseShort(leafValue);
+ return Short.parseShort(v);
case UINT16:
case INT32:
- return Integer.parseInt(leafValue);
+ return Integer.parseInt(v);
case UINT32:
case INT64:
- return Long.parseLong(leafValue);
+ return Long.parseLong(v);
case UINT64:
- return new BigInteger(leafValue);
+ return new BigInteger(v);
case EMPTY:
- if (leafValue == null || leafValue.equals("")) {
+ if (v == null || v.equals("")) {
return null;
- } else if (leafValue.equals("true") ||
- leafValue.equals("false")) {
- return Boolean.parseBoolean(leafValue);
+ } else if (v.equals(T) || v.equals(F)) {
+ return Boolean.parseBoolean(v);
}
case BOOLEAN:
- return Boolean.parseBoolean(leafValue);
+ if (v.equals(T) || v.equals(F)) {
+ return Boolean.parseBoolean(v);
+ }
+ throw new IllegalArgumentException(E_DATATYPE);
case BINARY:
case BITS:
case IDENTITYREF:
case ENUMERATION:
case STRING:
case INSTANCE_IDENTIFIER:
- return leafValue;
+ return v;
case DECIMAL64:
- return new BigDecimal(leafValue);
+ return new BigDecimal(v);
case LEAFREF:
YangType refType = ((YangLeafRef) typeInfo
.getDataTypeExtendedInfo()).getEffectiveDataType();
- return getObject(refType, leafValue, refType.getDataType());
+ return getObject(refType, v, refType.getDataType());
case DERIVED:
// referred typedef's list of type will always has only one type
YangType rt = ((YangDerivedInfo) typeInfo
.getDataTypeExtendedInfo()).getReferredTypeDef()
.getTypeList().get(0);
- return getObject(rt, leafValue, ((YangDerivedInfo)
+ return getObject(rt, v, ((YangDerivedInfo)
typeInfo.getDataTypeExtendedInfo()).getEffectiveBuiltInType());
case UNION:
- return parseUnionTypeInfo(typeInfo, leafValue);
+ return parseUnionTypeInfo(typeInfo, v);
default:
throw new IllegalArgumentException(E_DATATYPE);
}