blob: 997e4b63d77c0ce16759b1f4c669737244c3e6a3 [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 */
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053049
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053050/**
Bharat saraswald9822e92016-04-05 15:13:44 +053051 * Represents pattern restriction information. The regular expression restriction on string
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053052 * data type.
53 */
54public class YangPatternRestriction {
55
56 /**
57 * Pattern restriction defined for the current type.
58 */
Vinod Kumar S71cba682016-02-25 15:52:16 +053059 private List<String> patternList;
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053060
61 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053062 * Creates a YANG pattern restriction object.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053063 */
64 public YangPatternRestriction() {
Vinod Kumar S71cba682016-02-25 15:52:16 +053065 setPatternList(new LinkedList<String>());
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053066 }
67
68 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053069 * Returns the pattern restriction defined for the current type.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053070 *
71 * @return pattern restriction defined for the current type.
72 */
Vinod Kumar S71cba682016-02-25 15:52:16 +053073 public List<String> getPatternList() {
74 return patternList;
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053075 }
76
77 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053078 * Sets the pattern restriction defined for the current type.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053079 *
80 * @param pattern pattern restriction defined for the current type..
81 */
Vinod Kumar S71cba682016-02-25 15:52:16 +053082 private void setPatternList(List<String> pattern) {
83 patternList = pattern;
84 }
85
86 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053087 * Adds a new pattern to the list of pattern restriction.
Vinod Kumar S71cba682016-02-25 15:52:16 +053088 *
89 * @param newPattern pattern restriction.
90 */
91 public void addPattern(String newPattern) {
92 getPatternList().add(newPattern);
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053093 }
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053094}