Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 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 | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 16 | |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 17 | package org.onosproject.yangutils.datamodel; |
| 18 | |
Vinod Kumar S | 71cba68 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 19 | import java.util.LinkedList; |
Vinod Kumar S | 0c330cd | 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 | */ |
Gaurav Agrawal | cfa1c41 | 2016-05-03 00:41:48 +0530 | [diff] [blame^] | 49 | |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 50 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 51 | * Represents pattern restriction information. The regular expression restriction on string |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 52 | * data type. |
| 53 | */ |
| 54 | public class YangPatternRestriction { |
| 55 | |
| 56 | /** |
| 57 | * Pattern restriction defined for the current type. |
| 58 | */ |
Vinod Kumar S | 71cba68 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 59 | private List<String> patternList; |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 60 | |
| 61 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 62 | * Creates a YANG pattern restriction object. |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 63 | */ |
| 64 | public YangPatternRestriction() { |
Vinod Kumar S | 71cba68 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 65 | setPatternList(new LinkedList<String>()); |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 69 | * Returns the pattern restriction defined for the current type. |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 70 | * |
| 71 | * @return pattern restriction defined for the current type. |
| 72 | */ |
Vinod Kumar S | 71cba68 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 73 | public List<String> getPatternList() { |
| 74 | return patternList; |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 78 | * Sets the pattern restriction defined for the current type. |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 79 | * |
| 80 | * @param pattern pattern restriction defined for the current type.. |
| 81 | */ |
Vinod Kumar S | 71cba68 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 82 | private void setPatternList(List<String> pattern) { |
| 83 | patternList = pattern; |
| 84 | } |
| 85 | |
| 86 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 87 | * Adds a new pattern to the list of pattern restriction. |
Vinod Kumar S | 71cba68 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 88 | * |
| 89 | * @param newPattern pattern restriction. |
| 90 | */ |
| 91 | public void addPattern(String newPattern) { |
| 92 | getPatternList().add(newPattern); |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 93 | } |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 94 | } |