Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.yangutils.datamodel; |
| 18 | |
| 19 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
| 20 | import org.onosproject.yangutils.parser.Parsable; |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 21 | import org.onosproject.yangutils.utils.YangConstructType; |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 22 | |
| 23 | /* |
| 24 | * Reference:RFC 6020. |
| 25 | * The "type" statement takes as an argument a string that is the name |
| 26 | * of a YANG built-in type or a derived type, followed by an optional |
| 27 | * block of sub-statements that are used to put further restrictions |
| 28 | * on the type. |
| 29 | * |
| 30 | * The restrictions that can be applied depend on the type being restricted. |
| 31 | * The type's sub-statements |
| 32 | * |
| 33 | * +------------------+---------+-------------+------------------------------------+ |
| 34 | * | substatement | section | cardinality | mapped data type | |
| 35 | * +------------------+---------+-------------+------------------------------------+ |
| 36 | * | bit | 9.7.4 | 0..n | - YangBit used in YangBits | |
| 37 | * | enum | 9.6.4 | 0..n | - YangEnum used in YangEnumeration | |
| 38 | * | length | 9.4.4 | 0..1 | - used for string | |
| 39 | * | path | 9.9.2 | 0..1 | - TODO leaf-ref | |
| 40 | * | pattern | 9.4.6 | 0..n | - used for string | |
| 41 | * | range | 9.2.4 | 0..1 | - used for integer data type | |
| 42 | * | require-instance | 9.13.2 | 0..1 | - TODO instance-identifier | |
| 43 | * | type | 7.4 | 0..n | - TODO union | |
| 44 | * +------------------+---------+-------------+------------------------------------+ |
| 45 | */ |
| 46 | |
| 47 | /** |
| 48 | * Maintains the data type information. |
| 49 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 50 | * @param <T> YANG data type info |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 51 | */ |
| 52 | public class YangType<T> implements Parsable { |
| 53 | |
| 54 | /** |
| 55 | * YANG data type name. |
| 56 | */ |
| 57 | private String dataTypeName; |
| 58 | |
| 59 | /** |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 60 | * Java package in which the Java type is defined. |
| 61 | */ |
| 62 | private String javaPackage; |
| 63 | |
| 64 | /** |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 65 | * YANG data type. |
| 66 | */ |
| 67 | private YangDataTypes dataType; |
| 68 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 69 | /** |
| 70 | * Additional information about data type, example restriction info, named |
| 71 | * values, etc. The extra information is based on the data type. Based on |
| 72 | * the data type, the extended info can vary. |
| 73 | */ |
| 74 | private T dataTypeExtendedInfo; |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 75 | |
| 76 | /** |
| 77 | * Default constructor. |
| 78 | */ |
| 79 | public YangType() { |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Get the name of data type. |
| 84 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 85 | * @return the name of data type |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 86 | */ |
| 87 | public String getDataTypeName() { |
| 88 | return dataTypeName; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Set the name of the data type. |
| 93 | * |
| 94 | * @param typeName the name to set |
| 95 | */ |
| 96 | public void setDataTypeName(String typeName) { |
| 97 | dataTypeName = typeName; |
| 98 | } |
| 99 | |
| 100 | /** |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 101 | * Get the Java package where the type is defined. |
| 102 | * |
| 103 | * @return Java package where the type is defined |
| 104 | */ |
| 105 | public String getJavaPackage() { |
| 106 | return javaPackage; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Set Java package where the type is defined. |
| 111 | * |
| 112 | * @param javaPackage Java package where the type is defined |
| 113 | */ |
| 114 | public void setJavaPackage(String javaPackage) { |
| 115 | this.javaPackage = javaPackage; |
| 116 | } |
| 117 | |
| 118 | /** |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 119 | * Get the type of data. |
| 120 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 121 | * @return the data type |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 122 | */ |
| 123 | public YangDataTypes getDataType() { |
| 124 | return dataType; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Set the type of data. |
| 129 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 130 | * @param dataType data type |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 131 | */ |
| 132 | public void setDataType(YangDataTypes dataType) { |
| 133 | this.dataType = dataType; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Get the data type meta data. |
| 138 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 139 | * @return the data type meta data |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 140 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 141 | public T getDataTypeExtendedInfo() { |
| 142 | return dataTypeExtendedInfo; |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Set the data type meta data. |
| 147 | * |
| 148 | * @param dataTypeInfo the meta data to set |
| 149 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 150 | public void setDataTypeExtendedInfo(T dataTypeInfo) { |
| 151 | this.dataTypeExtendedInfo = dataTypeInfo; |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Returns the type of the parsed data. |
| 156 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 157 | * @return returns TYPE_DATA |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 158 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 159 | @Override |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 160 | public YangConstructType getYangConstructType() { |
| 161 | return YangConstructType.TYPE_DATA; |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Validate the data on entering the corresponding parse tree node. |
| 166 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 167 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 168 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 169 | @Override |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 170 | public void validateDataOnEntry() throws DataModelException { |
| 171 | // TODO auto-generated method stub, to be implemented by parser |
| 172 | |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Validate the data on exiting the corresponding parse tree node. |
| 177 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 178 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 179 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 180 | @Override |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 181 | public void validateDataOnExit() throws DataModelException { |
| 182 | // TODO auto-generated method stub, to be implemented by parser |
| 183 | |
| 184 | } |
| 185 | } |