Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Open Networking Laboratory |
| 3 | * |
| 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 S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 16 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 17 | package org.onosproject.yangutils.datamodel; |
| 18 | |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 19 | import java.util.LinkedList; |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 20 | import 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 | /** |
| 50 | * Pattern restriction information. The regular expression restriction on string |
| 51 | * data type. |
| 52 | */ |
| 53 | public class YangPatternRestriction { |
| 54 | |
| 55 | /** |
| 56 | * Pattern restriction defined for the current type. |
| 57 | */ |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 58 | private List<String> patternList; |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 59 | |
| 60 | /** |
| 61 | * Effective pattern restriction that needs inherited from base type. |
| 62 | */ |
| 63 | private List<String> basePattern; |
| 64 | |
| 65 | /** |
| 66 | * Default constructor. |
| 67 | */ |
| 68 | public YangPatternRestriction() { |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 69 | setPatternList(new LinkedList<String>()); |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Get the pattern restriction defined for the current type. |
| 74 | * |
| 75 | * @return pattern restriction defined for the current type. |
| 76 | */ |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 77 | public List<String> getPatternList() { |
| 78 | return patternList; |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Set the pattern restriction defined for the current type. |
| 83 | * |
| 84 | * @param pattern pattern restriction defined for the current type.. |
| 85 | */ |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 86 | private void setPatternList(List<String> pattern) { |
| 87 | patternList = pattern; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Add a new pattern to the list of pattern restriction. |
| 92 | * |
| 93 | * @param newPattern pattern restriction. |
| 94 | */ |
| 95 | public void addPattern(String newPattern) { |
| 96 | getPatternList().add(newPattern); |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Get the pattern restriction defined in base type. |
| 101 | * |
| 102 | * @return pattern restriction defined in base type. |
| 103 | */ |
| 104 | public List<String> getBasePattern() { |
| 105 | return basePattern; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Set the pattern restriction defined in base type. |
| 110 | * |
| 111 | * @param basePattern pattern restriction defined in base type. |
| 112 | */ |
| 113 | public void setBasePattern(List<String> basePattern) { |
| 114 | this.basePattern = basePattern; |
| 115 | } |
| 116 | } |