blob: 1233b088acb7ac69515fbf565db70b0ca885d7a4 [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
Vinod Kumar S71cba682016-02-25 15:52:16 +053019import java.util.LinkedList;
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053020import java.util.List;
21
22/*-
23 * Reference RFC 6020.
24 *
25 * The pattern Statement
26 *
27 * The "pattern" statement, which is an optional sub-statement to the
28 * "type" statement, takes as an argument a regular expression string.
29 * It is used to restrict the built-in type "string", or types derived
30 * from "string", to values that match the pattern.
31 *
32 * If the type has multiple "pattern" statements, the expressions are
33 * ANDed together, i.e., all such expressions have to match.
34 *
35 * If a pattern restriction is applied to an already pattern-restricted
36 * type, values must match all patterns in the base type, in addition to
37 * the new patterns.
38 * The pattern's sub-statements
39 *
40 * +---------------+---------+-------------+
41 * | substatement | section | cardinality |
42 * +---------------+---------+-------------+
43 * | description | 7.19.3 | 0..1 |
44 * | error-app-tag | 7.5.4.2 | 0..1 |
45 * | error-message | 7.5.4.1 | 0..1 |
46 * | reference | 7.19.4 | 0..1 |
47 * +---------------+---------+-------------+
48 */
49/**
Bharat saraswald9822e92016-04-05 15:13:44 +053050 * Represents pattern restriction information. The regular expression restriction on string
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053051 * data type.
52 */
53public class YangPatternRestriction {
54
55 /**
56 * Pattern restriction defined for the current type.
57 */
Vinod Kumar S71cba682016-02-25 15:52:16 +053058 private List<String> patternList;
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053059
60 /**
61 * Effective pattern restriction that needs inherited from base type.
62 */
63 private List<String> basePattern;
64
65 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053066 * Creates a YANG pattern restriction object.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053067 */
68 public YangPatternRestriction() {
Vinod Kumar S71cba682016-02-25 15:52:16 +053069 setPatternList(new LinkedList<String>());
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053070 }
71
72 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053073 * Returns the pattern restriction defined for the current type.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053074 *
75 * @return pattern restriction defined for the current type.
76 */
Vinod Kumar S71cba682016-02-25 15:52:16 +053077 public List<String> getPatternList() {
78 return patternList;
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053079 }
80
81 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053082 * Sets the pattern restriction defined for the current type.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053083 *
84 * @param pattern pattern restriction defined for the current type..
85 */
Vinod Kumar S71cba682016-02-25 15:52:16 +053086 private void setPatternList(List<String> pattern) {
87 patternList = pattern;
88 }
89
90 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053091 * Adds a new pattern to the list of pattern restriction.
Vinod Kumar S71cba682016-02-25 15:52:16 +053092 *
93 * @param newPattern pattern restriction.
94 */
95 public void addPattern(String newPattern) {
96 getPatternList().add(newPattern);
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053097 }
98
99 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530100 * Returns the pattern restriction defined in base type.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530101 *
102 * @return pattern restriction defined in base type.
103 */
104 public List<String> getBasePattern() {
105 return basePattern;
106 }
107
108 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530109 * Sets the pattern restriction defined in base type.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530110 *
111 * @param basePattern pattern restriction defined in base type.
112 */
113 public void setBasePattern(List<String> basePattern) {
114 this.basePattern = basePattern;
115 }
116}