[ONOS-7299] LeafType to specify effective built-in type and LeafObjectType to specify JAVA object type.
Change-Id: If4f41f8287fe334e87bcf79fbff8827e51f278d3
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeaf.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeaf.java
index 9864f31..c0474fe 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeaf.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeaf.java
@@ -21,9 +21,9 @@
import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.LeafContextUtil;
import org.onosproject.yang.model.DataNode.Type;
+import org.onosproject.yang.model.LeafObjectType;
import org.onosproject.yang.model.LeafRestriction;
import org.onosproject.yang.model.LeafSchemaContext;
-import org.onosproject.yang.model.LeafType;
import org.onosproject.yang.model.SchemaContext;
import org.onosproject.yang.model.SchemaId;
import org.onosproject.yang.model.YangNamespace;
@@ -661,7 +661,7 @@
@Override
- public LeafType getLeafType() {
+ public LeafObjectType getLeafObjectType() {
return getLeafTypeByDataType(dataType, dataType.getDataType());
}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeafList.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeafList.java
index dc9bbf5..4b9bd83 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeafList.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeafList.java
@@ -21,9 +21,9 @@
import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.LeafContextUtil;
import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.LeafObjectType;
import org.onosproject.yang.model.LeafRestriction;
import org.onosproject.yang.model.LeafSchemaContext;
-import org.onosproject.yang.model.LeafType;
import org.onosproject.yang.model.SchemaContext;
import org.onosproject.yang.model.SchemaId;
import org.onosproject.yang.model.YangNamespace;
@@ -655,7 +655,7 @@
}
@Override
- public LeafType getLeafType() {
+ public LeafObjectType getLeafObjectType() {
return getLeafTypeByDataType(dataType, dataType.getDataType());
}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/DataModelUtils.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/DataModelUtils.java
index b5aabd2..627910d 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/DataModelUtils.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/DataModelUtils.java
@@ -68,7 +68,7 @@
import org.onosproject.yang.compiler.datamodel.YangVersionHolder;
import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
-import org.onosproject.yang.model.LeafType;
+import org.onosproject.yang.model.LeafObjectType;
import org.onosproject.yang.model.SchemaId;
import java.io.File;
@@ -106,15 +106,15 @@
import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.ENUMERATION;
import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.UNION;
import static org.onosproject.yang.compiler.utils.UtilConstants.PERIOD;
-import static org.onosproject.yang.model.LeafType.BIG_DECIMAL;
-import static org.onosproject.yang.model.LeafType.BIG_INTEGER;
-import static org.onosproject.yang.model.LeafType.BOOLEAN;
-import static org.onosproject.yang.model.LeafType.BYTE;
-import static org.onosproject.yang.model.LeafType.BYTE_ARRAY;
-import static org.onosproject.yang.model.LeafType.INT;
-import static org.onosproject.yang.model.LeafType.LONG;
-import static org.onosproject.yang.model.LeafType.SHORT;
-import static org.onosproject.yang.model.LeafType.STRING;
+import static org.onosproject.yang.model.LeafObjectType.BIG_DECIMAL;
+import static org.onosproject.yang.model.LeafObjectType.BIG_INTEGER;
+import static org.onosproject.yang.model.LeafObjectType.BOOLEAN;
+import static org.onosproject.yang.model.LeafObjectType.BYTE;
+import static org.onosproject.yang.model.LeafObjectType.BYTE_ARRAY;
+import static org.onosproject.yang.model.LeafObjectType.INT;
+import static org.onosproject.yang.model.LeafObjectType.LONG;
+import static org.onosproject.yang.model.LeafObjectType.SHORT;
+import static org.onosproject.yang.model.LeafObjectType.STRING;
/**
* Represents utilities for data model tree.
@@ -124,20 +124,9 @@
public static final String FALSE = "false";
public static final String TYPEDEF = "Typedef";
public static final String IDENTITY = "Identity";
- private static final String SLASH = File.separator;
public static final String FMT_NOT_EXIST =
"Requested %s is not child in %s.";
- private static final String E_DATATYPE = "Data type not supported.";
public static final String E_ID = "Schema id should not be null.";
- private static final String DATE_FORMAT = "yyyy-MM-dd";
- private static final String E_INVALID_REF = "YANG file error: A leaf " +
- "reference, in unique, does not refer to a leaf under the list";
- private static final String E_UNIQUE = "YANG file error: Same leaf " +
- "cannot be mentioned more than one time in the unique statement";
- private static final String E_TARGET_NODE = "YANG file error: The target" +
- " node in unique reference path is invalid";
- private static final String E_DATATREE = "Internal datamodel error: Datam" +
- "odel tree is not correct";
public static final String E_NOT_ALLOWED =
"%s with the name %s in file %s at line %s is not allowed. Please" +
" avoid the %s extension in the name.";
@@ -148,6 +137,17 @@
public static final String DEFAULT = "Default";
public static final String INVAL_ANYDATA =
"Requested %s is not valid node for anydata.";
+ private static final String SLASH = File.separator;
+ private static final String E_DATATYPE = "Data type not supported.";
+ private static final String DATE_FORMAT = "yyyy-MM-dd";
+ private static final String E_INVALID_REF = "YANG file error: A leaf " +
+ "reference, in unique, does not refer to a leaf under the list";
+ private static final String E_UNIQUE = "YANG file error: Same leaf " +
+ "cannot be mentioned more than one time in the unique statement";
+ private static final String E_TARGET_NODE = "YANG file error: The target" +
+ " node in unique reference path is invalid";
+ private static final String E_DATATREE = "Internal datamodel error: Datam" +
+ "odel tree is not correct";
/**
* Creates a new data model tree utility.
@@ -1314,14 +1314,14 @@
}
/**
- * Returns the yang leaf type for corresponding supplied data type.
+ * Returns the yang leaf object type for corresponding supplied data type.
*
* @param type YANG type
* @param dataType YANG data type
* @return leaf type
*/
- public static LeafType getLeafTypeByDataType(YangType type,
- YangDataTypes dataType) {
+ public static LeafObjectType getLeafTypeByDataType(YangType type,
+ YangDataTypes dataType) {
switch (dataType) {
case BITS:
@@ -1359,7 +1359,7 @@
case INSTANCE_IDENTIFIER:
return STRING;
case UNION:
- return LeafType.UNION;
+ return LeafObjectType.UNION;
default:
throw new IllegalArgumentException(E_DATATYPE);
diff --git a/model/src/main/java/org/onosproject/yang/model/LeafNode.java b/model/src/main/java/org/onosproject/yang/model/LeafNode.java
index 2224750..4f2f526 100644
--- a/model/src/main/java/org/onosproject/yang/model/LeafNode.java
+++ b/model/src/main/java/org/onosproject/yang/model/LeafNode.java
@@ -79,11 +79,11 @@
@Override
public String toString() {
return "{" +
- "key=" + key() + ", " +
- "value=" + asString() +
- "valueNamespace=" + valueNamespace() +
- "leafType=" + String.valueOf(type) +
- "}";
+ "key=" + key() + ", " +
+ "value=" + asString() +
+ "valueNamespace=" + valueNamespace() +
+ "leafType=" + leafType.toString() +
+ "}";
}
/**
@@ -271,4 +271,4 @@
return new LeafNode(this);
}
}
-}
+}
\ No newline at end of file
diff --git a/model/src/main/java/org/onosproject/yang/model/LeafObjectType.java b/model/src/main/java/org/onosproject/yang/model/LeafObjectType.java
new file mode 100644
index 0000000..7a51ca1
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/LeafObjectType.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.yang.model;
+
+/**
+ * Represents mapping of java data types with corresponding yang leaf's data
+ * type.
+ */
+public enum LeafObjectType {
+
+ /**
+ * Represents YANG "int8" mapped to JAVA "byte".
+ */
+ BYTE,
+
+ /**
+ * Represents YANG "int16", "uint8" mapped to JAVA "short".
+ */
+ SHORT,
+
+ /**
+ * Represents YANG "uint16", "int32" mapped to JAVA "int".
+ */
+ INT,
+
+ /**
+ * Represents YANG "uint32", "int64" mapped to JAVA "long".
+ */
+ LONG,
+
+ /**
+ * Represents YANG "boolean", "empty" mapped to JAVA "boolean".
+ */
+ BOOLEAN,
+
+ /**
+ * Represents YANG "bits", "identityref", "enumeration", "string" mapped to
+ * JAVA "String".
+ */
+ STRING,
+
+ /**
+ * Represents YANG "uint64" mapped to JAVA "BigInteger".
+ */
+ BIG_INTEGER,
+
+ /**
+ * Represents YANG "binary" mapped to JAVA "byte[]".
+ */
+ BYTE_ARRAY,
+
+ /**
+ * Represents YANG decimal64 mapped to JAVA BigDecimal.
+ * 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 a negative power of ten, i.e., expressible as
+ * "i x 10^-n" where i is an integer64 and n is an integer between 1 and
+ * 18, inclusively.
+ */
+ BIG_DECIMAL,
+
+ /**
+ * Represents YANG union, in JAVA it's mapped to a custom generated
+ * class. LeafNode value would be of one among the other types
+ * listed in LeafType.
+ */
+ UNION
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/LeafSchemaContext.java b/model/src/main/java/org/onosproject/yang/model/LeafSchemaContext.java
index f42250c..300b2f0 100644
--- a/model/src/main/java/org/onosproject/yang/model/LeafSchemaContext.java
+++ b/model/src/main/java/org/onosproject/yang/model/LeafSchemaContext.java
@@ -23,11 +23,11 @@
public interface LeafSchemaContext extends SchemaContext {
/**
- * Returns type of the leaf.
+ * Returns type of the leaf object.
*
- * @return value of leaf in object
+ * @return type of leaf object
*/
- LeafType getLeafType();
+ LeafObjectType getLeafObjectType();
/**
* Returns the restrictions associated with leaf/leaf-list. Returns null
diff --git a/model/src/main/java/org/onosproject/yang/model/LeafType.java b/model/src/main/java/org/onosproject/yang/model/LeafType.java
index 7ae6dc9..d3a0c90 100644
--- a/model/src/main/java/org/onosproject/yang/model/LeafType.java
+++ b/model/src/main/java/org/onosproject/yang/model/LeafType.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016-present Open Networking Foundation
+ * Copyright 2017-present Open Networking Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,67 +17,158 @@
package org.onosproject.yang.model;
/**
- * Represents mapping of java data types with corresponding yang leaf's data
- * type.
+ * Represents ENUM to identify the effective built in data type.
*/
public enum LeafType {
/**
- * Represents YANG "int8" mapped to JAVA "byte".
+ * Reference:RFC 6020.
+ * <p>
+ * int8 represents integer values between -128 and 127, inclusively.
*/
- BYTE,
+ INT8,
/**
- * Represents YANG "int16", "uint8" mapped to JAVA "short".
+ * Reference:RFC 6020.
+ * <p>
+ * int16 represents integer values between -32768 and 32767, inclusively.
*/
- SHORT,
+ INT16,
/**
- * Represents YANG "uint16", "int32" mapped to JAVA "int".
+ * Reference:RFC 6020.
+ * <p>
+ * int32 represents integer values between -2147483648 and 2147483647,
+ * inclusively.
*/
- INT,
+ INT32,
/**
- * Represents YANG "uint32", "int64" mapped to JAVA "long".
+ * Reference:RFC 6020.
+ * <p>
+ * int64 represents integer values between -9223372036854775808 and
+ * 9223372036854775807, inclusively.
*/
- LONG,
+ INT64,
/**
- * Represents YANG "boolean", "empty" mapped to JAVA "boolean".
+ * Reference:RFC 6020.
+ * <p>
+ * uint8 represents integer values between 0 and 255, inclusively.
*/
- BOOLEAN,
+ UINT8,
/**
- * Represents YANG "bits", "identityref", "enumeration", "string" mapped to
- * JAVA "String".
+ * Reference:RFC 6020.
+ * <p>
+ * uint16 represents integer values between 0 and 65535, inclusively.
+ */
+ UINT16,
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * uint32 represents integer values between 0 and 4294967295, inclusively.
+ */
+ UINT32,
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * uint64 represents integer values between 0 and 18446744073709551615,
+ * inclusively.
+ */
+ UINT64,
+
+ /**
+ * 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
+ * a negative power of ten, i.e., expressible as "i x 10^-n" where i is an
+ * integer64 and n is an integer between 1 and 18, inclusively.
+ */
+ DECIMAL64,
+
+ /**
+ * 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
*/
STRING,
/**
- * Represents YANG "uint64" mapped to JAVA "BigInteger".
+ * Reference:RFC 6020.
+ * <p>
+ * The boolean built-in type represents a boolean value.
*/
- BIG_INTEGER,
+ BOOLEAN,
/**
- * Represents YANG "binary" mapped to JAVA "byte[]".
+ * Reference:RFC 6020.
+ * <p>
+ * The enumeration built-in type represents values from a set of assigned
+ * names.
*/
- BYTE_ARRAY,
+ ENUMERATION,
/**
- * Represents YANG decimal64 mapped to JAVA BigDecimal.
- * 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 a negative power of ten, i.e., expressible as
- * "i x 10^-n" where i is an integer64 and n is an integer between 1 and
- * 18, inclusively.
+ * 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.
*/
- BIG_DECIMAL,
+ BITS,
/**
- * Represents YANG union, in JAVA it's mapped to a custom generated
- * class. LeafNode value would be of one among the other types
- * listed in LeafType.
+ * Reference:RFC 6020.
+ * <p>
+ * The binary built-in type represents any binary data, i.e., a sequence of
+ * octets.
*/
- UNION
-}
+ BINARY,
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * The identityref type is used to reference an existing identity.
+ */
+ 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,
+
+ /**
+ * 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
+ * used only for specifying the values for the key nodes for list entries, a
+ * value of a leaf-list entry, or a positional index for a list without
+ * 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
+ * valid data. All such leaf nodes MUST reference existing nodes or leaf
+ * nodes with their default value in use for the data to be valid.
+ */
+ INSTANCE_IDENTIFIER,
+}
\ No newline at end of file