Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 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 | |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 19 | import java.io.Serializable; |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 20 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 21 | import org.onosproject.yangutils.datamodel.utils.Parsable; |
| 22 | import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; |
| 23 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
Gaurav Agrawal | 72cd1b7 | 2016-06-30 13:28:14 +0530 | [diff] [blame^] | 24 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 25 | |
Gaurav Agrawal | 72cd1b7 | 2016-06-30 13:28:14 +0530 | [diff] [blame^] | 26 | import static org.onosproject.yangutils.datamodel.BuiltInTypeObjectFactory.getDataObjectFromString; |
| 27 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypeUtils.isOfRangeRestrictedType; |
| 28 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED; |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 29 | |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 30 | /* |
| 31 | * Reference:RFC 6020. |
| 32 | * The "type" statement takes as an argument a string that is the name |
| 33 | * of a YANG built-in type or a derived type, followed by an optional |
| 34 | * block of sub-statements that are used to put further restrictions |
| 35 | * on the type. |
| 36 | * |
| 37 | * The restrictions that can be applied depend on the type being restricted. |
| 38 | * The type's sub-statements |
| 39 | * |
| 40 | * +------------------+---------+-------------+------------------------------------+ |
| 41 | * | substatement | section | cardinality | mapped data type | |
| 42 | * +------------------+---------+-------------+------------------------------------+ |
| 43 | * | bit | 9.7.4 | 0..n | - YangBit used in YangBits | |
| 44 | * | enum | 9.6.4 | 0..n | - YangEnum used in YangEnumeration | |
| 45 | * | length | 9.4.4 | 0..1 | - used for string | |
| 46 | * | path | 9.9.2 | 0..1 | - TODO leaf-ref | |
| 47 | * | pattern | 9.4.6 | 0..n | - used for string | |
| 48 | * | range | 9.2.4 | 0..1 | - used for integer data type | |
| 49 | * | require-instance | 9.13.2 | 0..1 | - TODO instance-identifier | |
| 50 | * | type | 7.4 | 0..n | - TODO union | |
| 51 | * +------------------+---------+-------------+------------------------------------+ |
| 52 | */ |
| 53 | |
| 54 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 55 | * Represents the data type information. |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 56 | * |
Bharat saraswal | 2f00b4b | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 57 | * @param <T> YANG data type info |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 58 | */ |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 59 | public class YangType<T> |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 60 | implements Parsable, Resolvable, Serializable { |
| 61 | |
| 62 | private static final long serialVersionUID = 8062016054L; |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 63 | |
| 64 | /** |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 65 | * YANG node identifier. |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 66 | */ |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 67 | private YangNodeIdentifier nodeIdentifier; |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 68 | |
| 69 | /** |
Bharat saraswal | 2f00b4b | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 70 | * Java package in which the Java type is defined. |
| 71 | */ |
| 72 | private String javaPackage; |
| 73 | |
| 74 | /** |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 75 | * YANG data type. |
| 76 | */ |
| 77 | private YangDataTypes dataType; |
| 78 | |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 79 | /** |
| 80 | * Additional information about data type, example restriction info, named |
| 81 | * values, etc. The extra information is based on the data type. Based on |
| 82 | * the data type, the extended info can vary. |
| 83 | */ |
| 84 | private T dataTypeExtendedInfo; |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 85 | |
| 86 | /** |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 87 | * Status of resolution. If completely resolved enum value is "RESOLVED", |
| 88 | * if not enum value is "UNRESOLVED", in case reference of grouping/typedef |
| 89 | * is added to uses/type but it's not resolved value of enum should be |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 90 | * "INTRA_FILE_RESOLVED". |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 91 | */ |
| 92 | private ResolvableStatus resolvableStatus; |
| 93 | |
| 94 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 95 | * Creates a YANG type object. |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 96 | */ |
| 97 | public YangType() { |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 98 | |
| 99 | nodeIdentifier = new YangNodeIdentifier(); |
| 100 | resolvableStatus = ResolvableStatus.UNRESOLVED; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Returns prefix associated with data type name. |
| 105 | * |
| 106 | * @return prefix associated with data type name |
| 107 | */ |
| 108 | public String getPrefix() { |
| 109 | return nodeIdentifier.getPrefix(); |
| 110 | } |
| 111 | |
| 112 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 113 | * Sets prefix associated with data type name. |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 114 | * |
| 115 | * @param prefix prefix associated with data type name |
| 116 | */ |
| 117 | public void setPrefix(String prefix) { |
| 118 | nodeIdentifier.setPrefix(prefix); |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 122 | * Returns the name of data type. |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 123 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 124 | * @return the name of data type |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 125 | */ |
| 126 | public String getDataTypeName() { |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 127 | return nodeIdentifier.getName(); |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 131 | * Sets the name of the data type. |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 132 | * |
| 133 | * @param typeName the name to set |
| 134 | */ |
| 135 | public void setDataTypeName(String typeName) { |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 136 | nodeIdentifier.setName(typeName); |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 140 | * Returns the Java package where the type is defined. |
Bharat saraswal | 2f00b4b | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 141 | * |
| 142 | * @return Java package where the type is defined |
| 143 | */ |
| 144 | public String getJavaPackage() { |
| 145 | return javaPackage; |
| 146 | } |
| 147 | |
| 148 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 149 | * Sets Java package where the type is defined. |
Bharat saraswal | 2f00b4b | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 150 | * |
| 151 | * @param javaPackage Java package where the type is defined |
| 152 | */ |
| 153 | public void setJavaPackage(String javaPackage) { |
| 154 | this.javaPackage = javaPackage; |
| 155 | } |
| 156 | |
| 157 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 158 | * Returns the type of data. |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 159 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 160 | * @return the data type |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 161 | */ |
| 162 | public YangDataTypes getDataType() { |
| 163 | return dataType; |
| 164 | } |
| 165 | |
| 166 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 167 | * Sets the type of data. |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 168 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 169 | * @param dataType data type |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 170 | */ |
| 171 | public void setDataType(YangDataTypes dataType) { |
| 172 | this.dataType = dataType; |
| 173 | } |
| 174 | |
| 175 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 176 | * Returns the data type meta data. |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 177 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 178 | * @return the data type meta data |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 179 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 180 | public T getDataTypeExtendedInfo() { |
| 181 | return dataTypeExtendedInfo; |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 185 | * Sets the data type meta data. |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 186 | * |
| 187 | * @param dataTypeInfo the meta data to set |
| 188 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 189 | public void setDataTypeExtendedInfo(T dataTypeInfo) { |
| 190 | this.dataTypeExtendedInfo = dataTypeInfo; |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | /** |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 194 | * Returns node identifier. |
| 195 | * |
| 196 | * @return node identifier |
| 197 | */ |
| 198 | public YangNodeIdentifier getNodeIdentifier() { |
| 199 | return nodeIdentifier; |
| 200 | } |
| 201 | |
| 202 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 203 | * Sets node identifier. |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 204 | * |
| 205 | * @param nodeIdentifier the node identifier |
| 206 | */ |
| 207 | public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) { |
| 208 | this.nodeIdentifier = nodeIdentifier; |
| 209 | } |
| 210 | |
| 211 | /** |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 212 | * Returns the type of the parsed data. |
| 213 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 214 | * @return returns TYPE_DATA |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 215 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 216 | @Override |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 217 | public YangConstructType getYangConstructType() { |
| 218 | return YangConstructType.TYPE_DATA; |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 222 | * Validates the data on entering the corresponding parse tree node. |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 223 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 224 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 225 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 226 | @Override |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 227 | public void validateDataOnEntry() |
| 228 | throws DataModelException { |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 229 | // TODO auto-generated method stub, to be implemented by parser |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 233 | * Validates the data on exiting the corresponding parse tree node. |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 234 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 235 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 236 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 237 | @Override |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 238 | public void validateDataOnExit() |
| 239 | throws DataModelException { |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 240 | // TODO auto-generated method stub, to be implemented by parser |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 241 | } |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 242 | |
| 243 | @Override |
| 244 | public ResolvableStatus getResolvableStatus() { |
| 245 | return resolvableStatus; |
| 246 | } |
| 247 | |
| 248 | @Override |
| 249 | public void setResolvableStatus(ResolvableStatus resolvableStatus) { |
| 250 | this.resolvableStatus = resolvableStatus; |
| 251 | } |
| 252 | |
| 253 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 254 | public void resolve() |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 255 | throws DataModelException { |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 256 | /* |
| 257 | * Check whether the data type is derived. |
| 258 | */ |
Vidyashree Rama | 7142d9c | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 259 | if (getDataType() != DERIVED) { |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 260 | throw new DataModelException("Linker Error: Resolve should only be called for derived data types."); |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 261 | } |
| 262 | |
Gaurav Agrawal | cfa1c41 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 263 | // Check if the derived info is present. |
| 264 | YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) getDataTypeExtendedInfo(); |
| 265 | if (derivedInfo == null) { |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 266 | throw new DataModelException("Linker Error: Derived information is missing."); |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 267 | } |
Gaurav Agrawal | cfa1c41 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 268 | |
| 269 | // Initiate the resolution |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 270 | try { |
| 271 | setResolvableStatus(derivedInfo.resolve()); |
| 272 | } catch (DataModelException e) { |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 273 | throw new DataModelException(e.getMessage()); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 274 | } |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 275 | } |
Gaurav Agrawal | 72cd1b7 | 2016-06-30 13:28:14 +0530 | [diff] [blame^] | 276 | |
| 277 | /** |
| 278 | * Validates the input data value against the permissible value for the |
| 279 | * type as per the YANG file. |
| 280 | * |
| 281 | * @param value input data value |
| 282 | * @return status of validation |
| 283 | */ |
| 284 | public boolean isValidValue(String value) { |
| 285 | switch (getDataType()) { |
| 286 | case INT8: |
| 287 | case INT16: |
| 288 | case INT32: |
| 289 | case INT64: |
| 290 | case UINT8: |
| 291 | case UINT16: |
| 292 | case UINT32: |
| 293 | case UINT64: { |
| 294 | isValidValueForRangeRestrictedType(value); |
| 295 | } |
| 296 | case DECIMAL64: { |
| 297 | // TODO |
| 298 | } |
| 299 | case STRING: { |
| 300 | // TODO implement in string restriction similar to range restriction |
| 301 | } |
| 302 | case ENUMERATION: { |
| 303 | // TODO validate using list of YANG enum of enumeration class in extended info. |
| 304 | } |
| 305 | case BINARY: { |
| 306 | // TODO validate based on extended info |
| 307 | } |
| 308 | case BITS: { |
| 309 | // TODO validate based on extended info |
| 310 | } |
| 311 | case BOOLEAN: { |
| 312 | // TODO true or false |
| 313 | } |
| 314 | case LEAFREF: { |
| 315 | // TODO validate based on extended info |
| 316 | } |
| 317 | case IDENTITYREF: { |
| 318 | // TODO TBD |
| 319 | } |
| 320 | case EMPTY: { |
| 321 | // TODO true or false |
| 322 | } |
| 323 | case UNION: { |
| 324 | // TODO validate based on extended info |
| 325 | } |
| 326 | case INSTANCE_IDENTIFIER: { |
| 327 | // TODO TBD |
| 328 | } |
| 329 | case DERIVED: { |
| 330 | if (isOfRangeRestrictedType(((YangDerivedInfo) getDataTypeExtendedInfo()).getEffectiveBuiltInType())) { |
| 331 | try { |
| 332 | if (((YangDerivedInfo) getDataTypeExtendedInfo()).getResolvedExtendedInfo() == null) { |
| 333 | getDataObjectFromString(value, |
| 334 | ((YangDerivedInfo) getDataTypeExtendedInfo()).getEffectiveBuiltInType()); |
| 335 | return true; |
| 336 | } else { |
| 337 | return ((YangRangeRestriction) ((YangDerivedInfo) getDataTypeExtendedInfo()) |
| 338 | .getResolvedExtendedInfo()).isValidValueString(value); |
| 339 | } |
| 340 | } catch (Exception e) { |
| 341 | return false; |
| 342 | } |
| 343 | } else { |
| 344 | // TODO |
| 345 | } |
| 346 | } |
| 347 | default: { |
| 348 | // TODO |
| 349 | } |
| 350 | } |
| 351 | return true; |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * Validates the input data value for range restricted types against the |
| 356 | * permissible value for the type as per the YANG file. |
| 357 | * |
| 358 | * @param value input data value |
| 359 | * @return status of validation |
| 360 | */ |
| 361 | private boolean isValidValueForRangeRestrictedType(String value) { |
| 362 | try { |
| 363 | if (getDataTypeExtendedInfo() == null) { |
| 364 | getDataObjectFromString(value, getDataType()); |
| 365 | return true; |
| 366 | } else { |
| 367 | return ((YangRangeRestriction) getDataTypeExtendedInfo()).isValidValueString(value); |
| 368 | } |
| 369 | } catch (Exception e) { |
| 370 | return false; |
| 371 | } |
| 372 | } |
Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 373 | } |