Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present 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 | |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 19 | import java.io.Serializable; |
| 20 | |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 21 | /*- |
| 22 | * Reference RFC 6020. |
| 23 | * |
| 24 | * Binary can be restricted with "length" statements alone. |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 29 | import org.onosproject.yangutils.datamodel.utils.Parsable; |
| 30 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 31 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangUint64; |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Represents the restriction for length data type. |
| 35 | */ |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 36 | public class YangLengthRestriction implements YangDesc, YangReference, YangAppErrorInfo, Parsable, Serializable { |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 37 | |
| 38 | /*- |
| 39 | * Reference RFC 6020. |
| 40 | * The length Statement |
| 41 | * |
| 42 | * The "length" statement, which is an optional sub-statement to the |
| 43 | * "type" statement, takes as an argument a length expression string. |
| 44 | * It is used to restrict the built-in type "string", or types derived |
| 45 | * from "string". |
| 46 | * A "length" statement restricts the number of unicode characters in |
| 47 | * the string. |
| 48 | * A length range consists of an explicit value, or a lower bound, two |
| 49 | * consecutive dots "..", and an upper bound. Multiple values or ranges |
| 50 | * can be given, separated by "|". Length-restricting values MUST NOT |
| 51 | * be negative. If multiple values or ranges are given, they all MUST |
| 52 | * be disjoint and MUST be in ascending order. If a length restriction |
| 53 | * is applied to an already length-restricted type, the new restriction |
| 54 | * MUST be equal or more limiting, that is, raising the lower bounds, |
| 55 | * reducing the upper bounds, removing explicit length values or ranges, |
| 56 | * or splitting ranges into multiple ranges with intermediate gaps. A |
| 57 | * length value is a non-negative integer, or one of the special values |
| 58 | * "min" or "max". "min" and "max" mean the minimum and maximum length |
| 59 | * accepted for the type being restricted, respectively. An |
| 60 | * implementation is not required to support a length value larger than |
| 61 | * 18446744073709551615. |
| 62 | * The length's sub-statements |
| 63 | * |
| 64 | * +---------------+---------+-------------+-----------------+ |
| 65 | * | substatement | section | cardinality | mapped data type| |
| 66 | * +---------------+---------+-------------+-----------------+ |
| 67 | * | description | 7.19.3 | 0..1 | string | |
| 68 | * | error-app-tag | 7.5.4.2 | 0..1 | string | |
| 69 | * | error-message | 7.5.4.1 | 0..1 | string | |
| 70 | * | reference | 7.19.4 | 0..1 | string | |
| 71 | * +---------------+---------+-------------+-----------------+ |
| 72 | */ |
| 73 | |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 74 | private static final long serialVersionUID = 806201645L; |
| 75 | |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 76 | /** |
| 77 | * Length restriction information. |
| 78 | */ |
| 79 | private YangRangeRestriction<YangUint64> lengthRestriction; |
| 80 | |
| 81 | /** |
| 82 | * Textual reference. |
| 83 | */ |
| 84 | private String reference; |
| 85 | |
| 86 | /** |
| 87 | * Application's error message, to be used for data error. |
| 88 | */ |
| 89 | private String errorMessage; |
| 90 | |
| 91 | /** |
| 92 | * Application's error tag, to be filled in data validation error response. |
| 93 | */ |
| 94 | private String errorAppTag; |
| 95 | |
| 96 | /** |
| 97 | * Textual description. |
| 98 | */ |
| 99 | private String description; |
| 100 | |
| 101 | /** |
| 102 | * Creates a YANG length restriction object. |
| 103 | */ |
| 104 | public YangLengthRestriction() { |
Mahesh Poojary Huawei | 46fb4db | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 105 | setLengthRestriction(new YangRangeRestriction<YangUint64>()); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Returns the length restriction on the string data. |
| 110 | * |
| 111 | * @return length restriction on the string data |
| 112 | */ |
| 113 | public YangRangeRestriction<YangUint64> getLengthRestriction() { |
| 114 | return lengthRestriction; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Sets the length restriction on the string data. |
| 119 | * |
| 120 | * @param lengthRestriction length restriction on the string data |
| 121 | */ |
| 122 | public void setLengthRestriction(YangRangeRestriction<YangUint64> lengthRestriction) { |
| 123 | this.lengthRestriction = lengthRestriction; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Returns the textual reference of the length restriction. |
| 128 | * |
| 129 | * @return textual reference of the length restriction |
| 130 | */ |
| 131 | @Override |
| 132 | public String getReference() { |
| 133 | return reference; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Sets the textual reference of the length restriction. |
| 138 | * |
| 139 | * @param ref textual reference of the length restriction |
| 140 | */ |
| 141 | @Override |
| 142 | public void setReference(String ref) { |
| 143 | reference = ref; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Returns the description of the length restriction. |
| 148 | * |
| 149 | * @return description of the length restriction |
| 150 | */ |
| 151 | @Override |
| 152 | public String getDescription() { |
| 153 | return description; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Sets the description of the length restriction. |
| 158 | * |
| 159 | * @param desc description of the length restriction |
| 160 | */ |
| 161 | @Override |
| 162 | public void setDescription(String desc) { |
| 163 | description = desc; |
| 164 | |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Returns application's error message, to be used for data error. |
| 169 | * |
| 170 | * @return Application's error message, to be used for data error |
| 171 | */ |
| 172 | @Override |
| 173 | public String getGetErrorMessage() { |
| 174 | return errorMessage; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Sets Application's error message, to be used for data error. |
| 179 | * |
| 180 | * @param errMsg Application's error message, to be used for data error |
| 181 | */ |
| 182 | @Override |
| 183 | public void setErrorMessage(String errMsg) { |
| 184 | errorMessage = errMsg; |
| 185 | |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Returns application's error tag, to be used for data error. |
| 190 | * |
| 191 | * @return application's error tag, to be used for data error |
| 192 | */ |
| 193 | @Override |
| 194 | public String getGetErrorAppTag() { |
| 195 | return errorAppTag; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Sets application's error tag, to be used for data error. |
| 200 | * |
| 201 | * @param errTag application's error tag, to be used for data error. |
| 202 | */ |
| 203 | @Override |
| 204 | public void setErrorAppTag(String errTag) { |
| 205 | errorAppTag = errTag; |
| 206 | } |
| 207 | |
| 208 | @Override |
| 209 | public YangConstructType getYangConstructType() { |
| 210 | return YangConstructType.PATTERN_DATA; |
| 211 | } |
| 212 | |
| 213 | @Override |
| 214 | public void validateDataOnEntry() throws DataModelException { |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 215 | // TODO: implement the method. |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | @Override |
| 219 | public void validateDataOnExit() throws DataModelException { |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 220 | // TODO: implement the method. |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 221 | } |
| 222 | } |