Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.yangutils.datamodel; |
| 18 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 19 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
| 20 | import org.onosproject.yangutils.datamodel.utils.Parsable; |
| 21 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
| 22 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangUint64; |
| 23 | |
Bharat saraswal | 94844d6 | 2016-10-13 13:28:03 +0530 | [diff] [blame] | 24 | import java.io.Serializable; |
| 25 | |
Bharat saraswal | 0663aff | 2016-10-18 23:16:14 +0530 | [diff] [blame] | 26 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.PATTERN_DATA; |
| 27 | |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 28 | /*- |
| 29 | * Reference RFC 6020. |
| 30 | * |
| 31 | * Binary can be restricted with "length" statements alone. |
| 32 | * |
| 33 | */ |
| 34 | |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 35 | /** |
| 36 | * Represents the restriction for length data type. |
| 37 | */ |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 38 | public class YangLengthRestriction extends DefaultLocationInfo |
| 39 | implements YangDesc, YangReference, Parsable, Serializable, YangAppErrorHolder { |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 40 | |
| 41 | /*- |
| 42 | * Reference RFC 6020. |
| 43 | * The length Statement |
| 44 | * |
| 45 | * The "length" statement, which is an optional sub-statement to the |
| 46 | * "type" statement, takes as an argument a length expression string. |
| 47 | * It is used to restrict the built-in type "string", or types derived |
| 48 | * from "string". |
| 49 | * A "length" statement restricts the number of unicode characters in |
| 50 | * the string. |
| 51 | * A length range consists of an explicit value, or a lower bound, two |
| 52 | * consecutive dots "..", and an upper bound. Multiple values or ranges |
| 53 | * can be given, separated by "|". Length-restricting values MUST NOT |
| 54 | * be negative. If multiple values or ranges are given, they all MUST |
| 55 | * be disjoint and MUST be in ascending order. If a length restriction |
| 56 | * is applied to an already length-restricted type, the new restriction |
| 57 | * MUST be equal or more limiting, that is, raising the lower bounds, |
| 58 | * reducing the upper bounds, removing explicit length values or ranges, |
| 59 | * or splitting ranges into multiple ranges with intermediate gaps. A |
| 60 | * length value is a non-negative integer, or one of the special values |
| 61 | * "min" or "max". "min" and "max" mean the minimum and maximum length |
| 62 | * accepted for the type being restricted, respectively. An |
| 63 | * implementation is not required to support a length value larger than |
| 64 | * 18446744073709551615. |
| 65 | * The length's sub-statements |
| 66 | * |
| 67 | * +---------------+---------+-------------+-----------------+ |
| 68 | * | substatement | section | cardinality | mapped data type| |
| 69 | * +---------------+---------+-------------+-----------------+ |
| 70 | * | description | 7.19.3 | 0..1 | string | |
| 71 | * | error-app-tag | 7.5.4.2 | 0..1 | string | |
| 72 | * | error-message | 7.5.4.1 | 0..1 | string | |
| 73 | * | reference | 7.19.4 | 0..1 | string | |
| 74 | * +---------------+---------+-------------+-----------------+ |
| 75 | */ |
| 76 | |
Bharat saraswal | c2d3be1 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 77 | private static final long serialVersionUID = 806201645L; |
| 78 | |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 79 | /** |
| 80 | * Length restriction information. |
| 81 | */ |
| 82 | private YangRangeRestriction<YangUint64> lengthRestriction; |
| 83 | |
| 84 | /** |
| 85 | * Textual reference. |
| 86 | */ |
| 87 | private String reference; |
| 88 | |
| 89 | /** |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 90 | * Textual description. |
| 91 | */ |
| 92 | private String description; |
| 93 | |
| 94 | /** |
rama-huawei | e37efa4 | 2016-07-11 14:48:12 +0530 | [diff] [blame] | 95 | * YANG application error information. |
| 96 | */ |
| 97 | private YangAppErrorInfo yangAppErrorInfo; |
| 98 | |
| 99 | /** |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 100 | * Creates a YANG length restriction object. |
| 101 | */ |
| 102 | public YangLengthRestriction() { |
Bharat saraswal | 94844d6 | 2016-10-13 13:28:03 +0530 | [diff] [blame] | 103 | setLengthRestriction(new YangRangeRestriction<>()); |
| 104 | yangAppErrorInfo = new YangAppErrorInfo(); |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Returns the length restriction on the string data. |
| 109 | * |
| 110 | * @return length restriction on the string data |
| 111 | */ |
| 112 | public YangRangeRestriction<YangUint64> getLengthRestriction() { |
| 113 | return lengthRestriction; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Sets the length restriction on the string data. |
| 118 | * |
| 119 | * @param lengthRestriction length restriction on the string data |
| 120 | */ |
| 121 | public void setLengthRestriction(YangRangeRestriction<YangUint64> lengthRestriction) { |
| 122 | this.lengthRestriction = lengthRestriction; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Returns the textual reference of the length restriction. |
| 127 | * |
| 128 | * @return textual reference of the length restriction |
| 129 | */ |
| 130 | @Override |
| 131 | public String getReference() { |
| 132 | return reference; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Sets the textual reference of the length restriction. |
| 137 | * |
| 138 | * @param ref textual reference of the length restriction |
| 139 | */ |
| 140 | @Override |
| 141 | public void setReference(String ref) { |
| 142 | reference = ref; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Returns the description of the length restriction. |
| 147 | * |
| 148 | * @return description of the length restriction |
| 149 | */ |
| 150 | @Override |
| 151 | public String getDescription() { |
| 152 | return description; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Sets the description of the length restriction. |
| 157 | * |
| 158 | * @param desc description of the length restriction |
| 159 | */ |
| 160 | @Override |
| 161 | public void setDescription(String desc) { |
| 162 | description = desc; |
| 163 | |
| 164 | } |
| 165 | |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 166 | @Override |
| 167 | public YangConstructType getYangConstructType() { |
Bharat saraswal | 0663aff | 2016-10-18 23:16:14 +0530 | [diff] [blame] | 168 | return PATTERN_DATA; |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | @Override |
| 172 | public void validateDataOnEntry() throws DataModelException { |
Bharat saraswal | c2d3be1 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 173 | // TODO: implement the method. |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | @Override |
| 177 | public void validateDataOnExit() throws DataModelException { |
Bharat saraswal | c2d3be1 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 178 | // TODO: implement the method. |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 179 | } |
rama-huawei | e37efa4 | 2016-07-11 14:48:12 +0530 | [diff] [blame] | 180 | |
| 181 | /** |
| 182 | * Sets the application's error information. |
| 183 | * |
| 184 | * @param yangAppErrorInfo the application's error information |
| 185 | */ |
| 186 | @Override |
| 187 | public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) { |
| 188 | this.yangAppErrorInfo = yangAppErrorInfo; |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Returns application's error information. |
| 193 | * |
| 194 | * @return application's error information |
| 195 | */ |
| 196 | @Override |
| 197 | public YangAppErrorInfo getAppErrorInfo() { |
| 198 | return yangAppErrorInfo; |
| 199 | } |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 200 | } |