blob: 9bf924a7fb746d7a8ba92e41900ba6df86f80cb1 [file] [log] [blame]
Vinod Kumar S2ff139c2016-02-16 01:37:16 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Vinod Kumar S2ff139c2016-02-16 01:37:16 +05303 *
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
Vidyashree Rama210c01d2016-05-20 16:29:25 +053019import java.util.SortedSet;
20import java.util.TreeSet;
Vinod Kumar S71cba682016-02-25 15:52:16 +053021
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053022import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
23import org.onosproject.yangutils.parser.Parsable;
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053024import org.onosproject.yangutils.utils.YangConstructType;
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053025
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053026/*
27 * The enumeration built-in type represents values from a set of
28 * assigned names.
29 */
30
31/**
Bharat saraswald9822e92016-04-05 15:13:44 +053032 * Represents the enumeration data type information.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053033 */
janani bdd1314f2016-05-19 17:39:50 +053034public class YangEnumeration extends YangNode implements Parsable, CollisionDetector {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053035
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053036 // Enumeration info set.
Vidyashree Rama210c01d2016-05-20 16:29:25 +053037 private SortedSet<YangEnum> enumSet;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053038
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053039 // Enumeration name.
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053040 private String name;
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053041
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() {
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053046 super(YangNodeType.ENUMERATION_NODE);
Vidyashree Rama210c01d2016-05-20 16:29:25 +053047 setEnumSet(new TreeSet<YangEnum>());
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053048 }
49
50 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053051 * Returns the ENUM set.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053052 *
53 * @return the ENUM set
54 */
Vidyashree Rama210c01d2016-05-20 16:29:25 +053055 public SortedSet<YangEnum> getEnumSet() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053056 return enumSet;
57 }
58
59 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053060 * Sets the ENUM set.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053061 *
62 * @param enumSet the ENUM set to set
63 */
Vidyashree Rama210c01d2016-05-20 16:29:25 +053064 private void setEnumSet(SortedSet<YangEnum> enumSet) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053065 this.enumSet = enumSet;
66 }
67
68 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053069 * Adds ENUM information.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053070 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053071 * @param enumInfo the ENUM information to be added
72 * @throws DataModelException due to violation in data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053073 */
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053074 public void addEnumInfo(YangEnum enumInfo) throws DataModelException {
75 if (!getEnumSet().add(enumInfo)) {
76 throw new DataModelException("YANG ENUM already exists");
77 }
78 }
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053079
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053080 /**
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053081 * Returns enumeration name.
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053082 *
83 * @return the enumeration name
84 */
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053085 @Override
86 public String getName() {
87 return name;
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053088 }
89
90 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053091 * Sets the enumeration name.
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053092 *
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053093 * @param name enumeration name
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053094 */
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053095 @Override
96 public void setName(String name) {
97 this.name = name;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053098 }
99
100 /**
101 * Returns the type of the data.
102 *
103 * @return returns ENUMERATION_DATA
104 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530105 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530106 public YangConstructType getYangConstructType() {
107 return YangConstructType.ENUMERATION_DATA;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530108 }
109
110 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530111 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530112 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530113 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530114 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530115 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530116 public void validateDataOnEntry() throws DataModelException {
117 // TODO auto-generated method stub, to be implemented by parser
118 }
119
120 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530121 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530122 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530123 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530124 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530125 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530126 public void validateDataOnExit() throws DataModelException {
127 // TODO auto-generated method stub, to be implemented by parser
128 }
janani bdd1314f2016-05-19 17:39:50 +0530129
130 @Override
131 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
132 /*
133 Do nothing.The implementation for this is not required.
134 */
135 }
136
137 @Override
138 public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
139 /*
140 Do nothing.The implementation for this is not required.
141 */
142 }
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530143}