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