blob: f2c67c3b421d8f7e224f9e973fd02e67f4a87b0e [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
Vidyashree Ramaa2f73982016-04-12 23:33:33 +053019import org.onosproject.yangutils.utils.builtindatatype.YangUint64;
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053020
21/*-
22 * Reference RFC 6020.
23 *
24 * A string can be restricted with the "length" and "pattern" statements.
25 *
26 */
27/**
Bharat saraswald9822e92016-04-05 15:13:44 +053028 * Represents the restriction for string data type.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053029 */
30public 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 */
Vidyashree Ramaa2f73982016-04-12 23:33:33 +053067
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053068 /**
69 * Length restriction information.
70 */
Vidyashree Ramaa2f73982016-04-12 23:33:33 +053071 private YangRangeRestriction<YangUint64> lengthRestriction;
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053072
73 /**
74 * Effective pattern restriction for the type.
75 */
76 private YangPatternRestriction patternRestriction;
77
78 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053079 * Creates a YANG string restriction object.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053080 */
81 public YangStringRestriction() {
82 }
83
84 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053085 * Returns the length restriction on the string data.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053086 *
Bharat saraswald9822e92016-04-05 15:13:44 +053087 * @return length restriction on the string data
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053088 */
Vidyashree Ramaa2f73982016-04-12 23:33:33 +053089 public YangRangeRestriction<YangUint64> getLengthRestriction() {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053090 return lengthRestriction;
91 }
92
93 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053094 * Sets the length restriction on the string data.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053095 *
Bharat saraswald9822e92016-04-05 15:13:44 +053096 * @param lengthRestriction length restriction on the string data
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053097 */
Vidyashree Ramaa2f73982016-04-12 23:33:33 +053098 public void setLengthRestriction(YangRangeRestriction<YangUint64> lengthRestriction) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053099 this.lengthRestriction = lengthRestriction;
100 }
101
102 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530103 * Returns the pattern restriction for the type.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530104 *
Bharat saraswald9822e92016-04-05 15:13:44 +0530105 * @return pattern restriction for the type
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530106 */
107 public YangPatternRestriction getPatternRestriction() {
108 return patternRestriction;
109 }
110
111 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530112 * Sets the pattern restriction for the type.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530113 *
Bharat saraswald9822e92016-04-05 15:13:44 +0530114 * @param patternRestriction pattern restriction for the type
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530115 */
Vinod Kumar S71cba682016-02-25 15:52:16 +0530116 private void setPatternRestriction(YangPatternRestriction patternRestriction) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530117 this.patternRestriction = patternRestriction;
118 }
Vinod Kumar S71cba682016-02-25 15:52:16 +0530119
120 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530121 * Adds a new pattern restriction for the type.
Vinod Kumar S71cba682016-02-25 15:52:16 +0530122 *
Bharat saraswald9822e92016-04-05 15:13:44 +0530123 * @param newPattern new pattern restriction for the type
Vinod Kumar S71cba682016-02-25 15:52:16 +0530124 */
125 public void addPattern(String newPattern) {
126 if (getPatternRestriction() == null) {
127 setPatternRestriction(new YangPatternRestriction());
128 }
129 getPatternRestriction().addPattern(newPattern);
130 }
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530131}