blob: b52a70eaa8b8cfe4e7c8d50b8782800dc379327e [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 */
rama-huawei6c728a92016-07-11 14:48:12 +053036public class YangStringRestriction implements YangDesc, YangReference, 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 /**
Vidyashree Rama1db15562016-05-17 16:16:15 +053092 * Textual description.
93 */
94 private String description;
95
96 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053097 * Creates a YANG string restriction object.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053098 */
99 public YangStringRestriction() {
100 }
101
102 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530103 * Returns the length restriction on the string data.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530104 *
Bharat saraswald9822e92016-04-05 15:13:44 +0530105 * @return length restriction on the string data
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530106 */
Vidyashree Ramaa2f73982016-04-12 23:33:33 +0530107 public YangRangeRestriction<YangUint64> getLengthRestriction() {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530108 return lengthRestriction;
109 }
110
111 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530112 * Sets the length restriction on the string data.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530113 *
Bharat saraswald9822e92016-04-05 15:13:44 +0530114 * @param lengthRestriction length restriction on the string data
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530115 */
Vidyashree Ramaa2f73982016-04-12 23:33:33 +0530116 public void setLengthRestriction(YangRangeRestriction<YangUint64> lengthRestriction) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530117 this.lengthRestriction = lengthRestriction;
118 }
119
120 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530121 * Returns the pattern restriction for the type.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530122 *
Bharat saraswald9822e92016-04-05 15:13:44 +0530123 * @return pattern restriction for the type
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530124 */
125 public YangPatternRestriction getPatternRestriction() {
126 return patternRestriction;
127 }
128
129 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530130 * Sets the pattern restriction for the type.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530131 *
Bharat saraswald9822e92016-04-05 15:13:44 +0530132 * @param patternRestriction pattern restriction for the type
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530133 */
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530134 public void setPatternRestriction(YangPatternRestriction patternRestriction) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530135 this.patternRestriction = patternRestriction;
136 }
Vinod Kumar S71cba682016-02-25 15:52:16 +0530137
138 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530139 * Adds a new pattern restriction for the type.
Vinod Kumar S71cba682016-02-25 15:52:16 +0530140 *
Bharat saraswald9822e92016-04-05 15:13:44 +0530141 * @param newPattern new pattern restriction for the type
Vinod Kumar S71cba682016-02-25 15:52:16 +0530142 */
143 public void addPattern(String newPattern) {
144 if (getPatternRestriction() == null) {
145 setPatternRestriction(new YangPatternRestriction());
146 }
147 getPatternRestriction().addPattern(newPattern);
148 }
Vidyashree Rama1db15562016-05-17 16:16:15 +0530149
150 /**
151 * Returns the textual reference of the string restriction.
152 *
153 * @return textual reference of the string restriction
154 */
155 @Override
156 public String getReference() {
157 return reference;
158 }
159
160 /**
161 * Sets the textual reference of the string restriction.
162 *
163 * @param ref textual reference of the string restriction
164 */
165 @Override
166 public void setReference(String ref) {
167 reference = ref;
168 }
169
170 /**
171 * Returns the description of the string restriction.
172 *
173 * @return description of the string restriction
174 */
175 @Override
176 public String getDescription() {
177 return description;
178 }
179
180 /**
181 * Sets the description of the string restriction.
182 *
183 * @param desc description of the string restriction
184 */
185 @Override
186 public void setDescription(String desc) {
187 description = desc;
188
189 }
190
Vidyashree Rama1db15562016-05-17 16:16:15 +0530191 @Override
192 public YangConstructType getYangConstructType() {
193 return YangConstructType.PATTERN_DATA;
194 }
195
196 @Override
197 public void validateDataOnEntry() throws DataModelException {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530198 // TODO: implement the method.
Vidyashree Rama1db15562016-05-17 16:16:15 +0530199 }
200
201 @Override
202 public void validateDataOnExit() throws DataModelException {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530203 // TODO: implement the method.
Vidyashree Rama1db15562016-05-17 16:16:15 +0530204 }
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530205}