Vinod Kumar S
Committed by Gerrit Code Review

[ONOS-3895, ONOS-3896, ONOS-3897] Data type interfaces

Change-Id: I9cd9d80ce0accc017118a944dff96367bca89bde
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.datamodel;
/**
* ENUM to identify the YANG data type.
*/
public enum YangDataTypes {
/**
* Reference:RFC 6020.
* int8 represents integer values between -128 and 127, inclusively.
*/
INT8,
/**
* Reference:RFC 6020.
* int16 represents integer values between -32768 and 32767, inclusively.
*/
INT16,
/**
* Reference:RFC 6020.
* int32 represents integer values between -2147483648 and 2147483647,
* inclusively.
*/
INT32,
/**
* Reference:RFC 6020.
* int64 represents integer values between -9223372036854775808 and
* 9223372036854775807, inclusively.
*/
INT64,
/**
* Reference:RFC 6020.
* uint8 represents integer values between 0 and 255, inclusively.
*/
UINT8,
/**
* Reference:RFC 6020.
* uint16 represents integer values between 0 and 65535, inclusively.
*/
UINT16,
/**
* Reference:RFC 6020.
* uint32 represents integer values between 0 and 4294967295, inclusively.
*/
UINT32,
/**
* Reference:RFC 6020.
* uint64 represents integer values between 0 and 18446744073709551615,
* inclusively.
*/
UINT64,
/**
* Reference:RFC 6020.
* 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, // TODO: need to implement in type.
/**
* Reference:RFC 6020.
* 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,
/**
* Reference:RFC 6020.
* The boolean built-in type represents a boolean value.
*/
BOOLEAN,
/**
* Reference:RFC 6020.
* The enumeration built-in type represents values from a set of assigned
* names.
*/
ENUMERATION,
/**
* Reference:RFC 6020.
* 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.
*/
BITS,
/**
* Reference:RFC 6020.
* The binary built-in type represents any binary data, i.e., a sequence of
* octets.
*/
BINARY,
/**
* Reference:RFC 6020.
* 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.
*
* 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.
*
* There MUST NOT be any circular chains of leafrefs.
*
* 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.
*/
LEAFREF, // TODO: need to implement in type.
/**
* Reference:RFC 6020.
* The identityref type is used to reference an existing identity.
*/
IDENTITYREF,
/**
* Reference:RFC 6020.
* The empty built-in type represents a leaf that does not have any value,
* it conveys information by its presence or absence.
*
* An empty type cannot have a default value.
*/
EMPTY,
/**
* Reference:RFC 6020.
* The union built-in type represents a value that corresponds to one of its
* member types.
*
* 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.
*
* 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".
*
* 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.
*
* Any default value or "units" property defined in the member types is not
* inherited by the union type.
*/
UNION,
/**
* Reference:RFC 6020.
* The instance-identifier built-in type is used to uniquely identify a
* particular instance node in the data tree.
*
* 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.
*
* 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,
/**
* Derived Data type.
*/
DERIVED
}
......@@ -151,7 +151,7 @@ public abstract class YangNode {
* @param newChild refers to a child to be added
* @throws DataModelException due to violation in data model rules
*/
void addChild(YangNode newChild) throws DataModelException {
public void addChild(YangNode newChild) throws DataModelException {
if (newChild.getNodeType() == null) {
throw new DataModelException("Abstract node cannot be inserted into a tree");
}
......
/*Copyright 2016.year Open Networking Laboratory
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/
package org.onosproject.yangutils.datamodel;
/**
* Abstraction for status on a YANG entity. Abstracted to unify the parsing and
* translator processing of status.
*/
public interface YangStatus {
/**
* Get the status.
*
* @return the status
*/
YangStatusType getStatus();
/**
* Set the status.
*
* @param status the status to set
*/
void setStatus(YangStatusType status);
}
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.datamodel;
/*
* Reference:RFC 6020.
* The "status" statement takes as an argument one of the strings
* "current", "deprecated", or "obsolete". If no status is specified,
* the default is "current".
*/
/**
* ENUM to represent the status of YANG entities.
*/
public enum YangStatusType {
/**
* Reference:RFC 6020.
* "current" means that the definition is current and valid.
*/
CURRENT,
/**
* Reference:RFC 6020.
* "deprecated" indicates an obsolete definition, but it permits new/
* continued implementation in order to foster interoperability with
* older/existing implementations.
*/
DEPRECATED,
/**
* Reference:RFC 6020.
* "obsolete" means the definition is obsolete and SHOULD NOT be implemented
* and/or can be removed from implementations.
*/
OBSOLETE
}
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
/*
* Reference:RFC 6020.
* The "type" statement takes as an argument a string that is the name
* of a YANG built-in type or a derived type, followed by an optional
* block of sub-statements that are used to put further restrictions
* on the type.
*
* The restrictions that can be applied depend on the type being restricted.
* The type's sub-statements
*
* +------------------+---------+-------------+------------------------------------+
* | substatement | section | cardinality | mapped data type |
* +------------------+---------+-------------+------------------------------------+
* | bit | 9.7.4 | 0..n | - YangBit used in YangBits |
* | enum | 9.6.4 | 0..n | - YangEnum used in YangEnumeration |
* | length | 9.4.4 | 0..1 | - used for string |
* | path | 9.9.2 | 0..1 | - TODO leaf-ref |
* | pattern | 9.4.6 | 0..n | - used for string |
* | range | 9.2.4 | 0..1 | - used for integer data type |
* | require-instance | 9.13.2 | 0..1 | - TODO instance-identifier |
* | type | 7.4 | 0..n | - TODO union |
* +------------------+---------+-------------+------------------------------------+
*/
/**
* Maintains the data type information.
*
* @param <T> YANG data type info.
*/
public class YangType<T> implements Parsable {
/**
* YANG data type name.
*/
private String dataTypeName;
/**
* YANG data type.
*/
private YangDataTypes dataType;
private T dataTypeInfo;
/**
* Default constructor.
*/
public YangType() {
}
/**
* Get the name of data type.
*
* @return the name of data type.
*/
public String getDataTypeName() {
return dataTypeName;
}
/**
* Set the name of the data type.
*
* @param typeName the name to set
*/
public void setDataTypeName(String typeName) {
dataTypeName = typeName;
}
/**
* Get the type of data.
*
* @return the data type.
*/
public YangDataTypes getDataType() {
return dataType;
}
/**
* Set the type of data.
*
* @param dataType data type.
*/
public void setDataType(YangDataTypes dataType) {
this.dataType = dataType;
}
/**
* Get the data type meta data.
*
* @return the data type meta data.
*/
public T getDataTypeInfo() {
return dataTypeInfo;
}
/**
* Set the data type meta data.
*
* @param dataTypeInfo the meta data to set
*/
public void setDataTypeInfo(T dataTypeInfo) {
this.dataTypeInfo = dataTypeInfo;
}
/**
* Returns the type of the parsed data.
*
* @return returns TYPE_DATA.
*/
public ParsableDataType getParsableDataType() {
return ParsableDataType.TYPE_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
*/
public void validateDataOnEntry() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
*/
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
}