blob: ec5374e4e8b754af8200c03cb88d8958f5e4448f [file] [log] [blame]
Vinod Kumar S2ff139c2016-02-16 01:37:16 +05301/*
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 */
16
17package org.onosproject.yangutils.datamodel;
18
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053019import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
20import org.onosproject.yangutils.parser.Parsable;
21import org.onosproject.yangutils.parser.ParsableDataType;
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053022
23import java.util.HashSet;
24import java.util.Set;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053025
26/*
27 * The enumeration built-in type represents values from a set of
28 * assigned names.
29 */
30
31/**
32 * Maintains the enumeration data type information.
33 */
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053034public class YangEnumeration implements Parsable {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053035
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053036 // Enumeration info set.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053037 private Set<YangEnum> enumSet;
38
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053039 // Enumeration name.
40 private String enumerationName;
41
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053042 /**
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053043 * Creates an enumeration object.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053044 */
45 public YangEnumeration() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053046 setEnumSet(new HashSet<YangEnum>());
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053047 }
48
49 /**
50 * Get the ENUM set.
51 *
52 * @return the ENUM set
53 */
54 public Set<YangEnum> getEnumSet() {
55 return enumSet;
56 }
57
58 /**
59 * Set the ENUM set.
60 *
61 * @param enumSet the ENUM set to set
62 */
63 private void setEnumSet(Set<YangEnum> enumSet) {
64 this.enumSet = enumSet;
65 }
66
67 /**
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053068 * Add ENUM information.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053069 *
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053070 * @param enumInfo the ENUM information to be added.
71 * @throws DataModelException due to violation in data model rules.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053072 */
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053073 public void addEnumInfo(YangEnum enumInfo) throws DataModelException {
74 if (!getEnumSet().add(enumInfo)) {
75 throw new DataModelException("YANG ENUM already exists");
76 }
77 }
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053078
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053079 /**
80 * Return enumeration name.
81 *
82 * @return the enumeration name
83 */
84 public String getEnumerationName() {
85 return enumerationName;
86 }
87
88 /**
89 * Set the enumeration name.
90 *
91 * @param enumerationName enumeration name
92 */
93 public void setEnumerationName(String enumerationName) {
94 this.enumerationName = enumerationName;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053095 }
96
97 /**
98 * Returns the type of the data.
99 *
100 * @return returns ENUMERATION_DATA
101 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530102 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530103 public ParsableDataType getParsableDataType() {
104 return ParsableDataType.ENUMERATION_DATA;
105 }
106
107 /**
108 * Validate the data on entering the corresponding parse tree node.
109 *
110 * @throws DataModelException a violation of data model rules.
111 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530112 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530113 public void validateDataOnEntry() throws DataModelException {
114 // TODO auto-generated method stub, to be implemented by parser
115 }
116
117 /**
118 * Validate the data on exiting the corresponding parse tree node.
119 *
120 * @throws DataModelException a violation of data model rules.
121 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530122 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530123 public void validateDataOnExit() throws DataModelException {
124 // TODO auto-generated method stub, to be implemented by parser
125 }
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530126}