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