blob: ce626ed3deed98a222290b02eec13a03d9cda145 [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
Bharat saraswal96dfef02016-06-16 00:29:12 +053019import java.io.Serializable;
20
Vidyashree Rama1db15562016-05-17 16:16:15 +053021import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
Bharat saraswal96dfef02016-06-16 00:29:12 +053022import org.onosproject.yangutils.datamodel.utils.Parsable;
23import org.onosproject.yangutils.datamodel.utils.YangConstructType;
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053024import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangUint64;
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053025
26/*-
27 * Reference RFC 6020.
28 *
29 * A string can be restricted with the "length" and "pattern" statements.
30 *
31 */
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053032
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053033/**
Bharat saraswald9822e92016-04-05 15:13:44 +053034 * Represents the restriction for string data type.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053035 */
Bharat saraswal96dfef02016-06-16 00:29:12 +053036public class YangStringRestriction implements YangDesc, YangReference, YangAppErrorInfo, Parsable, Serializable {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053037
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 */
Vidyashree Ramaa2f73982016-04-12 23:33:33 +053073
Bharat saraswal96dfef02016-06-16 00:29:12 +053074 private static final long serialVersionUID = 8062016053L;
75
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053076 /**
77 * Length restriction information.
78 */
Vidyashree Ramaa2f73982016-04-12 23:33:33 +053079 private YangRangeRestriction<YangUint64> lengthRestriction;
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053080
81 /**
82 * Effective pattern restriction for the type.
83 */
84 private YangPatternRestriction patternRestriction;
85
86 /**
Vidyashree Rama1db15562016-05-17 16:16:15 +053087 * Textual reference.
88 */
89 private String reference;
90
91 /**
92 * Application's error message, to be used for data error.
93 */
94 private String errorMessage;
95
96 /**
97 * Application's error tag, to be filled in data validation error response.
98 */
99 private String errorAppTag;
100
101 /**
102 * Textual description.
103 */
104 private String description;
105
106 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530107 * Creates a YANG string restriction object.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530108 */
109 public YangStringRestriction() {
110 }
111
112 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530113 * Returns the length restriction on the string data.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530114 *
Bharat saraswald9822e92016-04-05 15:13:44 +0530115 * @return length restriction on the string data
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530116 */
Vidyashree Ramaa2f73982016-04-12 23:33:33 +0530117 public YangRangeRestriction<YangUint64> getLengthRestriction() {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530118 return lengthRestriction;
119 }
120
121 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530122 * Sets the length restriction on the string data.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530123 *
Bharat saraswald9822e92016-04-05 15:13:44 +0530124 * @param lengthRestriction length restriction on the string data
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530125 */
Vidyashree Ramaa2f73982016-04-12 23:33:33 +0530126 public void setLengthRestriction(YangRangeRestriction<YangUint64> lengthRestriction) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530127 this.lengthRestriction = lengthRestriction;
128 }
129
130 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530131 * Returns the pattern restriction for the type.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530132 *
Bharat saraswald9822e92016-04-05 15:13:44 +0530133 * @return pattern restriction for the type
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530134 */
135 public YangPatternRestriction getPatternRestriction() {
136 return patternRestriction;
137 }
138
139 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530140 * Sets the pattern restriction for the type.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530141 *
Bharat saraswald9822e92016-04-05 15:13:44 +0530142 * @param patternRestriction pattern restriction for the type
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530143 */
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530144 public void setPatternRestriction(YangPatternRestriction patternRestriction) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530145 this.patternRestriction = patternRestriction;
146 }
Vinod Kumar S71cba682016-02-25 15:52:16 +0530147
148 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530149 * Adds a new pattern restriction for the type.
Vinod Kumar S71cba682016-02-25 15:52:16 +0530150 *
Bharat saraswald9822e92016-04-05 15:13:44 +0530151 * @param newPattern new pattern restriction for the type
Vinod Kumar S71cba682016-02-25 15:52:16 +0530152 */
153 public void addPattern(String newPattern) {
154 if (getPatternRestriction() == null) {
155 setPatternRestriction(new YangPatternRestriction());
156 }
157 getPatternRestriction().addPattern(newPattern);
158 }
Vidyashree Rama1db15562016-05-17 16:16:15 +0530159
160 /**
161 * Returns the textual reference of the string restriction.
162 *
163 * @return textual reference of the string restriction
164 */
165 @Override
166 public String getReference() {
167 return reference;
168 }
169
170 /**
171 * Sets the textual reference of the string restriction.
172 *
173 * @param ref textual reference of the string restriction
174 */
175 @Override
176 public void setReference(String ref) {
177 reference = ref;
178 }
179
180 /**
181 * Returns the description of the string restriction.
182 *
183 * @return description of the string restriction
184 */
185 @Override
186 public String getDescription() {
187 return description;
188 }
189
190 /**
191 * Sets the description of the string restriction.
192 *
193 * @param desc description of the string restriction
194 */
195 @Override
196 public void setDescription(String desc) {
197 description = desc;
198
199 }
200
201 /**
202 * Returns application's error message, to be used for data error.
203 *
204 * @return Application's error message, to be used for data error
205 */
206 @Override
207 public String getGetErrorMessage() {
208 return errorMessage;
209 }
210
211 /**
212 * Sets Application's error message, to be used for data error.
213 *
214 * @param errMsg Application's error message, to be used for data error
215 */
216 @Override
217 public void setErrorMessage(String errMsg) {
218 errorMessage = errMsg;
219
220 }
221
222 /**
223 * Returns application's error tag, to be used for data error.
224 *
225 * @return application's error tag, to be used for data error
226 */
227 @Override
228 public String getGetErrorAppTag() {
229 return errorAppTag;
230 }
231
232 /**
233 * Sets application's error tag, to be used for data error.
234 *
235 * @param errTag application's error tag, to be used for data error.
236 */
237 @Override
238 public void setErrorAppTag(String errTag) {
239 errorAppTag = errTag;
240 }
241
242 @Override
243 public YangConstructType getYangConstructType() {
244 return YangConstructType.PATTERN_DATA;
245 }
246
247 @Override
248 public void validateDataOnEntry() throws DataModelException {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530249 // TODO: implement the method.
Vidyashree Rama1db15562016-05-17 16:16:15 +0530250 }
251
252 @Override
253 public void validateDataOnExit() throws DataModelException {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530254 // TODO: implement the method.
Vidyashree Rama1db15562016-05-17 16:16:15 +0530255 }
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530256}