blob: a229b9c8cbceeba226367e30c4fffd789bd2cdbb [file] [log] [blame]
Vinod Kumar S0c330cd2016-02-23 22:36:57 +05301/*Copyright 2016.year Open Networking Laboratory
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.*/
14package org.onosproject.yangutils.datamodel;
15
Vinod Kumar S71cba682016-02-25 15:52:16 +053016import java.util.LinkedList;
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053017import java.util.List;
18
19/*-
20 * Reference RFC 6020.
21 *
22 * The pattern Statement
23 *
24 * The "pattern" statement, which is an optional sub-statement to the
25 * "type" statement, takes as an argument a regular expression string.
26 * It is used to restrict the built-in type "string", or types derived
27 * from "string", to values that match the pattern.
28 *
29 * If the type has multiple "pattern" statements, the expressions are
30 * ANDed together, i.e., all such expressions have to match.
31 *
32 * If a pattern restriction is applied to an already pattern-restricted
33 * type, values must match all patterns in the base type, in addition to
34 * the new patterns.
35 * The pattern's sub-statements
36 *
37 * +---------------+---------+-------------+
38 * | substatement | section | cardinality |
39 * +---------------+---------+-------------+
40 * | description | 7.19.3 | 0..1 |
41 * | error-app-tag | 7.5.4.2 | 0..1 |
42 * | error-message | 7.5.4.1 | 0..1 |
43 * | reference | 7.19.4 | 0..1 |
44 * +---------------+---------+-------------+
45 */
46/**
47 * Pattern restriction information. The regular expression restriction on string
48 * data type.
49 */
50public class YangPatternRestriction {
51
52 /**
53 * Pattern restriction defined for the current type.
54 */
Vinod Kumar S71cba682016-02-25 15:52:16 +053055 private List<String> patternList;
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053056
57 /**
58 * Effective pattern restriction that needs inherited from base type.
59 */
60 private List<String> basePattern;
61
62 /**
63 * Default constructor.
64 */
65 public YangPatternRestriction() {
Vinod Kumar S71cba682016-02-25 15:52:16 +053066 setPatternList(new LinkedList<String>());
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053067 }
68
69 /**
70 * Get the pattern restriction defined for the current type.
71 *
72 * @return pattern restriction defined for the current type.
73 */
Vinod Kumar S71cba682016-02-25 15:52:16 +053074 public List<String> getPatternList() {
75 return patternList;
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053076 }
77
78 /**
79 * Set the pattern restriction defined for the current type.
80 *
81 * @param pattern pattern restriction defined for the current type..
82 */
Vinod Kumar S71cba682016-02-25 15:52:16 +053083 private void setPatternList(List<String> pattern) {
84 patternList = pattern;
85 }
86
87 /**
88 * Add a new pattern to the list of pattern restriction.
89 *
90 * @param newPattern pattern restriction.
91 */
92 public void addPattern(String newPattern) {
93 getPatternList().add(newPattern);
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053094 }
95
96 /**
97 * Get the pattern restriction defined in base type.
98 *
99 * @return pattern restriction defined in base type.
100 */
101 public List<String> getBasePattern() {
102 return basePattern;
103 }
104
105 /**
106 * Set the pattern restriction defined in base type.
107 *
108 * @param basePattern pattern restriction defined in base type.
109 */
110 public void setBasePattern(List<String> basePattern) {
111 this.basePattern = basePattern;
112 }
113}