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