Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 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 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 16 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 17 | package org.onosproject.yangutils.datamodel; |
| 18 | |
Vidyashree Rama | bc9611f | 2016-04-12 23:33:33 +0530 | [diff] [blame] | 19 | import org.onosproject.yangutils.utils.builtindatatype.YangUint64; |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 20 | |
| 21 | /*- |
| 22 | * Reference RFC 6020. |
| 23 | * |
| 24 | * A string can be restricted with the "length" and "pattern" statements. |
| 25 | * |
| 26 | */ |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 27 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 28 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 29 | * Represents the restriction for string data type. |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 30 | */ |
| 31 | public class YangStringRestriction { |
| 32 | |
| 33 | /*- |
| 34 | * Reference RFC 6020. |
| 35 | * The length Statement |
| 36 | * |
| 37 | * The "length" statement, which is an optional sub-statement to the |
| 38 | * "type" statement, takes as an argument a length expression string. |
| 39 | * It is used to restrict the built-in type "string", or types derived |
| 40 | * from "string". |
| 41 | * A "length" statement restricts the number of unicode characters in |
| 42 | * the string. |
| 43 | * A length range consists of an explicit value, or a lower bound, two |
| 44 | * consecutive dots "..", and an upper bound. Multiple values or ranges |
| 45 | * can be given, separated by "|". Length-restricting values MUST NOT |
| 46 | * be negative. If multiple values or ranges are given, they all MUST |
| 47 | * be disjoint and MUST be in ascending order. If a length restriction |
| 48 | * is applied to an already length-restricted type, the new restriction |
| 49 | * MUST be equal or more limiting, that is, raising the lower bounds, |
| 50 | * reducing the upper bounds, removing explicit length values or ranges, |
| 51 | * or splitting ranges into multiple ranges with intermediate gaps. A |
| 52 | * length value is a non-negative integer, or one of the special values |
| 53 | * "min" or "max". "min" and "max" mean the minimum and maximum length |
| 54 | * accepted for the type being restricted, respectively. An |
| 55 | * implementation is not required to support a length value larger than |
| 56 | * 18446744073709551615. |
| 57 | * The length's sub-statements |
| 58 | * |
| 59 | * +---------------+---------+-------------+-----------------+ |
| 60 | * | substatement | section | cardinality | mapped data type| |
| 61 | * +---------------+---------+-------------+-----------------+ |
| 62 | * | description | 7.19.3 | 0..1 | string | |
| 63 | * | error-app-tag | 7.5.4.2 | 0..1 | string | |
| 64 | * | error-message | 7.5.4.1 | 0..1 | string | |
| 65 | * | reference | 7.19.4 | 0..1 | string | |
| 66 | * +---------------+---------+-------------+-----------------+ |
| 67 | */ |
Vidyashree Rama | bc9611f | 2016-04-12 23:33:33 +0530 | [diff] [blame] | 68 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 69 | /** |
| 70 | * Length restriction information. |
| 71 | */ |
Vidyashree Rama | bc9611f | 2016-04-12 23:33:33 +0530 | [diff] [blame] | 72 | private YangRangeRestriction<YangUint64> lengthRestriction; |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 73 | |
| 74 | /** |
| 75 | * Effective pattern restriction for the type. |
| 76 | */ |
| 77 | private YangPatternRestriction patternRestriction; |
| 78 | |
| 79 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 80 | * Creates a YANG string restriction object. |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 81 | */ |
| 82 | public YangStringRestriction() { |
| 83 | } |
| 84 | |
| 85 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 86 | * Returns the length restriction on the string data. |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 87 | * |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 88 | * @return length restriction on the string data |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 89 | */ |
Vidyashree Rama | bc9611f | 2016-04-12 23:33:33 +0530 | [diff] [blame] | 90 | public YangRangeRestriction<YangUint64> getLengthRestriction() { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 91 | return lengthRestriction; |
| 92 | } |
| 93 | |
| 94 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 95 | * Sets the length restriction on the string data. |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 96 | * |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 97 | * @param lengthRestriction length restriction on the string data |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 98 | */ |
Vidyashree Rama | bc9611f | 2016-04-12 23:33:33 +0530 | [diff] [blame] | 99 | public void setLengthRestriction(YangRangeRestriction<YangUint64> lengthRestriction) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 100 | this.lengthRestriction = lengthRestriction; |
| 101 | } |
| 102 | |
| 103 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 104 | * Returns the pattern restriction for the type. |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 105 | * |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 106 | * @return pattern restriction for the type |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 107 | */ |
| 108 | public YangPatternRestriction getPatternRestriction() { |
| 109 | return patternRestriction; |
| 110 | } |
| 111 | |
| 112 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 113 | * Sets the pattern restriction for the type. |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 114 | * |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 115 | * @param patternRestriction pattern restriction for the type |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 116 | */ |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 117 | public void setPatternRestriction(YangPatternRestriction patternRestriction) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 118 | this.patternRestriction = patternRestriction; |
| 119 | } |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 120 | |
| 121 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 122 | * Adds a new pattern restriction for the type. |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 123 | * |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 124 | * @param newPattern new pattern restriction for the type |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 125 | */ |
| 126 | public void addPattern(String newPattern) { |
| 127 | if (getPatternRestriction() == null) { |
| 128 | setPatternRestriction(new YangPatternRestriction()); |
| 129 | } |
| 130 | getPatternRestriction().addPattern(newPattern); |
| 131 | } |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 132 | } |