Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +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 | 2ff139c | 2016-02-16 01:37:16 +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 | */ |
| 16 | |
| 17 | package org.onosproject.yangutils.datamodel; |
| 18 | |
Vidyashree Rama | 210c01d | 2016-05-20 16:29:25 +0530 | [diff] [blame] | 19 | import java.util.SortedSet; |
| 20 | import java.util.TreeSet; |
Vinod Kumar S | 71cba68 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 21 | |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 22 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
| 23 | import org.onosproject.yangutils.parser.Parsable; |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.utils.YangConstructType; |
Gaurav Agrawal | 9c512e0 | 2016-02-25 04:37:05 +0530 | [diff] [blame] | 25 | |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 26 | /* |
| 27 | * The enumeration built-in type represents values from a set of |
| 28 | * assigned names. |
| 29 | */ |
| 30 | |
| 31 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 32 | * Represents the enumeration data type information. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 33 | */ |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame^] | 34 | public class YangEnumeration |
| 35 | extends YangNode |
| 36 | implements Parsable, CollisionDetector { |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 37 | |
Gaurav Agrawal | 9c512e0 | 2016-02-25 04:37:05 +0530 | [diff] [blame] | 38 | // Enumeration info set. |
Vidyashree Rama | 210c01d | 2016-05-20 16:29:25 +0530 | [diff] [blame] | 39 | private SortedSet<YangEnum> enumSet; |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 40 | |
Gaurav Agrawal | 9c512e0 | 2016-02-25 04:37:05 +0530 | [diff] [blame] | 41 | // Enumeration name. |
Gaurav Agrawal | 1c8f80c | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 42 | private String name; |
Gaurav Agrawal | 9c512e0 | 2016-02-25 04:37:05 +0530 | [diff] [blame] | 43 | |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 44 | /** |
Gaurav Agrawal | 9c512e0 | 2016-02-25 04:37:05 +0530 | [diff] [blame] | 45 | * Creates an enumeration object. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 46 | */ |
| 47 | public YangEnumeration() { |
Gaurav Agrawal | 1c8f80c | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 48 | super(YangNodeType.ENUMERATION_NODE); |
Vidyashree Rama | 210c01d | 2016-05-20 16:29:25 +0530 | [diff] [blame] | 49 | setEnumSet(new TreeSet<YangEnum>()); |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 53 | * Returns the ENUM set. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 54 | * |
| 55 | * @return the ENUM set |
| 56 | */ |
Vidyashree Rama | 210c01d | 2016-05-20 16:29:25 +0530 | [diff] [blame] | 57 | public SortedSet<YangEnum> getEnumSet() { |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 58 | return enumSet; |
| 59 | } |
| 60 | |
| 61 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 62 | * Sets the ENUM set. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 63 | * |
| 64 | * @param enumSet the ENUM set to set |
| 65 | */ |
Vidyashree Rama | 210c01d | 2016-05-20 16:29:25 +0530 | [diff] [blame] | 66 | private void setEnumSet(SortedSet<YangEnum> enumSet) { |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 67 | this.enumSet = enumSet; |
| 68 | } |
| 69 | |
| 70 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 71 | * Adds ENUM information. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 72 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 73 | * @param enumInfo the ENUM information to be added |
| 74 | * @throws DataModelException due to violation in data model rules |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 75 | */ |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame^] | 76 | public void addEnumInfo(YangEnum enumInfo) |
| 77 | throws DataModelException { |
Gaurav Agrawal | 9c512e0 | 2016-02-25 04:37:05 +0530 | [diff] [blame] | 78 | if (!getEnumSet().add(enumInfo)) { |
| 79 | throw new DataModelException("YANG ENUM already exists"); |
| 80 | } |
| 81 | } |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 82 | |
Gaurav Agrawal | 9c512e0 | 2016-02-25 04:37:05 +0530 | [diff] [blame] | 83 | /** |
Gaurav Agrawal | 1c8f80c | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 84 | * Returns enumeration name. |
Gaurav Agrawal | 9c512e0 | 2016-02-25 04:37:05 +0530 | [diff] [blame] | 85 | * |
| 86 | * @return the enumeration name |
| 87 | */ |
Gaurav Agrawal | 1c8f80c | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 88 | @Override |
| 89 | public String getName() { |
| 90 | return name; |
Gaurav Agrawal | 9c512e0 | 2016-02-25 04:37:05 +0530 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 94 | * Sets the enumeration name. |
Gaurav Agrawal | 9c512e0 | 2016-02-25 04:37:05 +0530 | [diff] [blame] | 95 | * |
Gaurav Agrawal | 1c8f80c | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 96 | * @param name enumeration name |
Gaurav Agrawal | 9c512e0 | 2016-02-25 04:37:05 +0530 | [diff] [blame] | 97 | */ |
Gaurav Agrawal | 1c8f80c | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 98 | @Override |
| 99 | public void setName(String name) { |
| 100 | this.name = name; |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Returns the type of the data. |
| 105 | * |
| 106 | * @return returns ENUMERATION_DATA |
| 107 | */ |
Bharat saraswal | 594bc6d | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 108 | @Override |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 109 | public YangConstructType getYangConstructType() { |
| 110 | return YangConstructType.ENUMERATION_DATA; |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 114 | * Validates the data on entering the corresponding parse tree node. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 115 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 116 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 117 | */ |
Bharat saraswal | 594bc6d | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 118 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame^] | 119 | public void validateDataOnEntry() |
| 120 | throws DataModelException { |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 121 | // TODO auto-generated method stub, to be implemented by parser |
| 122 | } |
| 123 | |
| 124 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 125 | * Validates the data on exiting the corresponding parse tree node. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 126 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 127 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 128 | */ |
Bharat saraswal | 594bc6d | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 129 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame^] | 130 | public void validateDataOnExit() |
| 131 | throws DataModelException { |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 132 | // TODO auto-generated method stub, to be implemented by parser |
| 133 | } |
janani b | dd1314f | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 134 | |
| 135 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame^] | 136 | public void detectCollidingChild(String identifierName, YangConstructType dataType) |
| 137 | throws DataModelException { |
janani b | dd1314f | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 138 | /* |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame^] | 139 | Do nothing, since it is not part of the schema tree, it is only type of an existing node in schema tree. |
janani b | dd1314f | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 140 | */ |
| 141 | } |
| 142 | |
| 143 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame^] | 144 | public void detectSelfCollision(String identifierName, YangConstructType dataType) |
| 145 | throws DataModelException { |
janani b | dd1314f | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 146 | /* |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame^] | 147 | Do nothing, since it is not part of the schema tree, it is only type of an existing node in schema tree. |
janani b | dd1314f | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 148 | */ |
| 149 | } |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 150 | } |