Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vinod Kumar S | 5a39e01 | 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 | |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 19 | import java.util.HashSet; |
| 20 | import java.util.Set; |
| 21 | |
Vinod Kumar S | 5a39e01 | 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 | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.utils.YangConstructType; |
Gaurav Agrawal | 4ce3acf | 2016-02-25 04:37:05 +0530 | [diff] [blame] | 25 | |
Vinod Kumar S | 5a39e01 | 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 | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 32 | * Represents the enumeration data type information. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 33 | */ |
Gaurav Agrawal | 4ce3acf | 2016-02-25 04:37:05 +0530 | [diff] [blame] | 34 | public class YangEnumeration implements Parsable { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 35 | |
Gaurav Agrawal | 4ce3acf | 2016-02-25 04:37:05 +0530 | [diff] [blame] | 36 | // Enumeration info set. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 37 | private Set<YangEnum> enumSet; |
| 38 | |
Gaurav Agrawal | 4ce3acf | 2016-02-25 04:37:05 +0530 | [diff] [blame] | 39 | // Enumeration name. |
| 40 | private String enumerationName; |
| 41 | |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 42 | /** |
Gaurav Agrawal | 4ce3acf | 2016-02-25 04:37:05 +0530 | [diff] [blame] | 43 | * Creates an enumeration object. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 44 | */ |
| 45 | public YangEnumeration() { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 46 | setEnumSet(new HashSet<YangEnum>()); |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 50 | * Returns the ENUM set. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 51 | * |
| 52 | * @return the ENUM set |
| 53 | */ |
| 54 | public Set<YangEnum> getEnumSet() { |
| 55 | return enumSet; |
| 56 | } |
| 57 | |
| 58 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 59 | * Sets the ENUM set. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 60 | * |
| 61 | * @param enumSet the ENUM set to set |
| 62 | */ |
| 63 | private void setEnumSet(Set<YangEnum> enumSet) { |
| 64 | this.enumSet = enumSet; |
| 65 | } |
| 66 | |
| 67 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 68 | * Adds ENUM information. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 69 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 70 | * @param enumInfo the ENUM information to be added |
| 71 | * @throws DataModelException due to violation in data model rules |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 72 | */ |
Gaurav Agrawal | 4ce3acf | 2016-02-25 04:37:05 +0530 | [diff] [blame] | 73 | public void addEnumInfo(YangEnum enumInfo) throws DataModelException { |
| 74 | if (!getEnumSet().add(enumInfo)) { |
| 75 | throw new DataModelException("YANG ENUM already exists"); |
| 76 | } |
| 77 | } |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 78 | |
Gaurav Agrawal | 4ce3acf | 2016-02-25 04:37:05 +0530 | [diff] [blame] | 79 | /** |
| 80 | * Return enumeration name. |
| 81 | * |
| 82 | * @return the enumeration name |
| 83 | */ |
| 84 | public String getEnumerationName() { |
| 85 | return enumerationName; |
| 86 | } |
| 87 | |
| 88 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 89 | * Sets the enumeration name. |
Gaurav Agrawal | 4ce3acf | 2016-02-25 04:37:05 +0530 | [diff] [blame] | 90 | * |
| 91 | * @param enumerationName enumeration name |
| 92 | */ |
| 93 | public void setEnumerationName(String enumerationName) { |
| 94 | this.enumerationName = enumerationName; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Returns the type of the data. |
| 99 | * |
| 100 | * @return returns ENUMERATION_DATA |
| 101 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 102 | @Override |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 103 | public YangConstructType getYangConstructType() { |
| 104 | return YangConstructType.ENUMERATION_DATA; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 108 | * Validates the data on entering the corresponding parse tree node. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 109 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 110 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 111 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 112 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 113 | public void validateDataOnEntry() throws DataModelException { |
| 114 | // TODO auto-generated method stub, to be implemented by parser |
| 115 | } |
| 116 | |
| 117 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 118 | * Validates the data on exiting the corresponding parse tree node. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 119 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 120 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 121 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 122 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 123 | public void validateDataOnExit() throws DataModelException { |
| 124 | // TODO auto-generated method stub, to be implemented by parser |
| 125 | } |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 126 | } |