blob: 2a2ebf4eeecb8d6b8787f222dd2a2826038f3ec7 [file] [log] [blame]
Vinod Kumar Sc4216002016-03-03 19:55:30 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Vinod Kumar Sc4216002016-03-03 19:55:30 +05303 *
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 S0c330cd2016-02-23 22:36:57 +053016
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053017package org.onosproject.yangutils.datamodel;
18
Vidyashree Rama1db15562016-05-17 16:16:15 +053019import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
20import org.onosproject.yangutils.parser.Parsable;
21import org.onosproject.yangutils.utils.YangConstructType;
Vidyashree Ramaa2f73982016-04-12 23:33:33 +053022import org.onosproject.yangutils.utils.builtindatatype.YangUint64;
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053023
24/*-
25 * Reference RFC 6020.
26 *
27 * A string can be restricted with the "length" and "pattern" statements.
28 *
29 */
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053030
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053031/**
Bharat saraswald9822e92016-04-05 15:13:44 +053032 * Represents the restriction for string data type.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053033 */
Vidyashree Rama1db15562016-05-17 16:16:15 +053034public class YangStringRestriction implements YangDesc, YangReference, YangAppErrorInfo, Parsable {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053035
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 Ramaa2f73982016-04-12 23:33:33 +053071
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053072 /**
73 * Length restriction information.
74 */
Vidyashree Ramaa2f73982016-04-12 23:33:33 +053075 private YangRangeRestriction<YangUint64> lengthRestriction;
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053076
77 /**
78 * Effective pattern restriction for the type.
79 */
80 private YangPatternRestriction patternRestriction;
81
82 /**
Vidyashree Rama1db15562016-05-17 16:16:15 +053083 * 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 saraswald9822e92016-04-05 15:13:44 +0530103 * Creates a YANG string restriction object.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530104 */
105 public YangStringRestriction() {
106 }
107
108 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530109 * Returns the length restriction on the string data.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530110 *
Bharat saraswald9822e92016-04-05 15:13:44 +0530111 * @return length restriction on the string data
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530112 */
Vidyashree Ramaa2f73982016-04-12 23:33:33 +0530113 public YangRangeRestriction<YangUint64> getLengthRestriction() {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530114 return lengthRestriction;
115 }
116
117 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530118 * Sets the length restriction on the string data.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530119 *
Bharat saraswald9822e92016-04-05 15:13:44 +0530120 * @param lengthRestriction length restriction on the string data
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530121 */
Vidyashree Ramaa2f73982016-04-12 23:33:33 +0530122 public void setLengthRestriction(YangRangeRestriction<YangUint64> lengthRestriction) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530123 this.lengthRestriction = lengthRestriction;
124 }
125
126 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530127 * Returns the pattern restriction for the type.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530128 *
Bharat saraswald9822e92016-04-05 15:13:44 +0530129 * @return pattern restriction for the type
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530130 */
131 public YangPatternRestriction getPatternRestriction() {
132 return patternRestriction;
133 }
134
135 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530136 * Sets the pattern restriction for the type.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530137 *
Bharat saraswald9822e92016-04-05 15:13:44 +0530138 * @param patternRestriction pattern restriction for the type
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530139 */
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530140 public void setPatternRestriction(YangPatternRestriction patternRestriction) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530141 this.patternRestriction = patternRestriction;
142 }
Vinod Kumar S71cba682016-02-25 15:52:16 +0530143
144 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530145 * Adds a new pattern restriction for the type.
Vinod Kumar S71cba682016-02-25 15:52:16 +0530146 *
Bharat saraswald9822e92016-04-05 15:13:44 +0530147 * @param newPattern new pattern restriction for the type
Vinod Kumar S71cba682016-02-25 15:52:16 +0530148 */
149 public void addPattern(String newPattern) {
150 if (getPatternRestriction() == null) {
151 setPatternRestriction(new YangPatternRestriction());
152 }
153 getPatternRestriction().addPattern(newPattern);
154 }
Vidyashree Rama1db15562016-05-17 16:16:15 +0530155
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 S0c330cd2016-02-23 22:36:57 +0530252}