blob: 9e5d8ef2cd85d4b55665a31c21f65ef5517cc84a [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
Bharat saraswal96dfef02016-06-16 00:29:12 +053019import java.io.Serializable;
Vinod Kumar S71cba682016-02-25 15:52:16 +053020import java.util.LinkedList;
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053021import java.util.List;
22
23/*-
24 * Reference RFC 6020.
25 *
26 * The pattern Statement
27 *
28 * The "pattern" statement, which is an optional sub-statement to the
29 * "type" statement, takes as an argument a regular expression string.
30 * It is used to restrict the built-in type "string", or types derived
31 * from "string", to values that match the pattern.
32 *
33 * If the type has multiple "pattern" statements, the expressions are
34 * ANDed together, i.e., all such expressions have to match.
35 *
36 * If a pattern restriction is applied to an already pattern-restricted
37 * type, values must match all patterns in the base type, in addition to
38 * the new patterns.
39 * The pattern's sub-statements
40 *
41 * +---------------+---------+-------------+
42 * | substatement | section | cardinality |
43 * +---------------+---------+-------------+
44 * | description | 7.19.3 | 0..1 |
45 * | error-app-tag | 7.5.4.2 | 0..1 |
46 * | error-message | 7.5.4.1 | 0..1 |
47 * | reference | 7.19.4 | 0..1 |
48 * +---------------+---------+-------------+
49 */
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053050
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053051/**
Bharat saraswald9822e92016-04-05 15:13:44 +053052 * Represents pattern restriction information. The regular expression restriction on string
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053053 * data type.
54 */
rama-huawei6c728a92016-07-11 14:48:12 +053055public class YangPatternRestriction implements Serializable, YangAppErrorHolder {
Bharat saraswal96dfef02016-06-16 00:29:12 +053056
57 private static final long serialVersionUID = 806201649L;
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053058
59 /**
60 * Pattern restriction defined for the current type.
61 */
Vinod Kumar S71cba682016-02-25 15:52:16 +053062 private List<String> patternList;
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053063
64 /**
rama-huawei6c728a92016-07-11 14:48:12 +053065 * YANG application error information.
66 */
67 private YangAppErrorInfo yangAppErrorInfo;
68
69 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053070 * Creates a YANG pattern restriction object.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053071 */
72 public YangPatternRestriction() {
Vinod Kumar S71cba682016-02-25 15:52:16 +053073 setPatternList(new LinkedList<String>());
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053074 }
75
76 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053077 * Returns the pattern restriction defined for the current type.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053078 *
79 * @return pattern restriction defined for the current type.
80 */
Vinod Kumar S71cba682016-02-25 15:52:16 +053081 public List<String> getPatternList() {
82 return patternList;
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053083 }
84
85 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053086 * Sets the pattern restriction defined for the current type.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053087 *
88 * @param pattern pattern restriction defined for the current type..
89 */
Vinod Kumar S71cba682016-02-25 15:52:16 +053090 private void setPatternList(List<String> pattern) {
91 patternList = pattern;
92 }
93
94 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053095 * Adds a new pattern to the list of pattern restriction.
Vinod Kumar S71cba682016-02-25 15:52:16 +053096 *
97 * @param newPattern pattern restriction.
98 */
99 public void addPattern(String newPattern) {
100 getPatternList().add(newPattern);
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530101 }
rama-huawei6c728a92016-07-11 14:48:12 +0530102
103 @Override
104 public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
105 this.yangAppErrorInfo = yangAppErrorInfo;
106 }
107
108 @Override
109 public YangAppErrorInfo getAppErrorInfo() {
110 return yangAppErrorInfo;
111 }
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530112}