blob: 43780a6c2231cd613f83f3681fc6281acf723957 [file] [log] [blame]
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +05301/*
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
17package org.onosproject.yangutils.datamodel;
18
Bharat saraswal96dfef02016-06-16 00:29:12 +053019import java.io.Serializable;
20
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053021/*-
22 * Reference RFC 6020.
23 *
24 * Binary can be restricted with "length" statements alone.
25 *
26 */
27
28import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
Bharat saraswal96dfef02016-06-16 00:29:12 +053029import org.onosproject.yangutils.datamodel.utils.Parsable;
30import org.onosproject.yangutils.datamodel.utils.YangConstructType;
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053031import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangUint64;
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053032
33/**
34 * Represents the restriction for length data type.
35 */
rama-huawei6c728a92016-07-11 14:48:12 +053036public class YangLengthRestriction implements YangDesc, YangReference, Parsable, Serializable, YangAppErrorHolder {
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +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 */
73
Bharat saraswal96dfef02016-06-16 00:29:12 +053074 private static final long serialVersionUID = 806201645L;
75
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053076 /**
77 * Length restriction information.
78 */
79 private YangRangeRestriction<YangUint64> lengthRestriction;
80
81 /**
82 * Textual reference.
83 */
84 private String reference;
85
86 /**
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053087 * Textual description.
88 */
89 private String description;
90
91 /**
rama-huawei6c728a92016-07-11 14:48:12 +053092 * YANG application error information.
93 */
94 private YangAppErrorInfo yangAppErrorInfo;
95
96 /**
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053097 * Creates a YANG length restriction object.
98 */
99 public YangLengthRestriction() {
Mahesh Poojary Huawei46fb4db2016-07-14 12:38:17 +0530100 setLengthRestriction(new YangRangeRestriction<YangUint64>());
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530101 }
102
103 /**
104 * Returns the length restriction on the string data.
105 *
106 * @return length restriction on the string data
107 */
108 public YangRangeRestriction<YangUint64> getLengthRestriction() {
109 return lengthRestriction;
110 }
111
112 /**
113 * Sets the length restriction on the string data.
114 *
115 * @param lengthRestriction length restriction on the string data
116 */
117 public void setLengthRestriction(YangRangeRestriction<YangUint64> lengthRestriction) {
118 this.lengthRestriction = lengthRestriction;
119 }
120
121 /**
122 * Returns the textual reference of the length restriction.
123 *
124 * @return textual reference of the length restriction
125 */
126 @Override
127 public String getReference() {
128 return reference;
129 }
130
131 /**
132 * Sets the textual reference of the length restriction.
133 *
134 * @param ref textual reference of the length restriction
135 */
136 @Override
137 public void setReference(String ref) {
138 reference = ref;
139 }
140
141 /**
142 * Returns the description of the length restriction.
143 *
144 * @return description of the length restriction
145 */
146 @Override
147 public String getDescription() {
148 return description;
149 }
150
151 /**
152 * Sets the description of the length restriction.
153 *
154 * @param desc description of the length restriction
155 */
156 @Override
157 public void setDescription(String desc) {
158 description = desc;
159
160 }
161
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530162 @Override
163 public YangConstructType getYangConstructType() {
164 return YangConstructType.PATTERN_DATA;
165 }
166
167 @Override
168 public void validateDataOnEntry() throws DataModelException {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530169 // TODO: implement the method.
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530170 }
171
172 @Override
173 public void validateDataOnExit() throws DataModelException {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530174 // TODO: implement the method.
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530175 }
rama-huawei6c728a92016-07-11 14:48:12 +0530176
177 /**
178 * Sets the application's error information.
179 *
180 * @param yangAppErrorInfo the application's error information
181 */
182 @Override
183 public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
184 this.yangAppErrorInfo = yangAppErrorInfo;
185 }
186
187 /**
188 * Returns application's error information.
189 *
190 * @return application's error information
191 */
192 @Override
193 public YangAppErrorInfo getAppErrorInfo() {
194 return yangAppErrorInfo;
195 }
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530196}