blob: cf234648c26d57290e9aaf3ce880fc94bad470e2 [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;
Bharat saraswal96dfef02016-06-16 00:29:12 +053023import org.onosproject.yangutils.datamodel.utils.Parsable;
24import org.onosproject.yangutils.datamodel.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 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053034public class YangEnumeration
35 extends YangNode
36 implements Parsable, CollisionDetector {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053037
Bharat saraswal96dfef02016-06-16 00:29:12 +053038 private static final long serialVersionUID = 806201606L;
39
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053040 // Enumeration info set.
Vidyashree Rama210c01d2016-05-20 16:29:25 +053041 private SortedSet<YangEnum> enumSet;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053042
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053043 // Enumeration name.
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053044 private String name;
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053045
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053046 /**
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053047 * Creates an enumeration object.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053048 */
49 public YangEnumeration() {
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053050 super(YangNodeType.ENUMERATION_NODE);
Vidyashree Rama210c01d2016-05-20 16:29:25 +053051 setEnumSet(new TreeSet<YangEnum>());
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053052 }
53
54 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053055 * Returns the ENUM set.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053056 *
57 * @return the ENUM set
58 */
Vidyashree Rama210c01d2016-05-20 16:29:25 +053059 public SortedSet<YangEnum> getEnumSet() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053060 return enumSet;
61 }
62
63 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053064 * Sets the ENUM set.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053065 *
66 * @param enumSet the ENUM set to set
67 */
Vidyashree Rama210c01d2016-05-20 16:29:25 +053068 private void setEnumSet(SortedSet<YangEnum> enumSet) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053069 this.enumSet = enumSet;
70 }
71
72 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053073 * Adds ENUM information.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053074 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053075 * @param enumInfo the ENUM information to be added
76 * @throws DataModelException due to violation in data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053077 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053078 public void addEnumInfo(YangEnum enumInfo)
79 throws DataModelException {
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053080 if (!getEnumSet().add(enumInfo)) {
81 throw new DataModelException("YANG ENUM already exists");
82 }
83 }
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053084
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053085 /**
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053086 * Returns enumeration name.
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053087 *
88 * @return the enumeration name
89 */
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053090 @Override
91 public String getName() {
92 return name;
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053093 }
94
95 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053096 * Sets the enumeration name.
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053097 *
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053098 * @param name enumeration name
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053099 */
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530100 @Override
101 public void setName(String name) {
102 this.name = name;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530103 }
104
105 /**
106 * Returns the type of the data.
107 *
108 * @return returns ENUMERATION_DATA
109 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530110 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530111 public YangConstructType getYangConstructType() {
112 return YangConstructType.ENUMERATION_DATA;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530113 }
114
115 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530116 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530117 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530118 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530119 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530120 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530121 public void validateDataOnEntry()
122 throws DataModelException {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530123 // TODO auto-generated method stub, to be implemented by parser
124 }
125
126 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530127 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530128 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530129 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530130 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530131 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530132 public void validateDataOnExit()
133 throws DataModelException {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530134 // TODO auto-generated method stub, to be implemented by parser
135 }
janani bdd1314f2016-05-19 17:39:50 +0530136
137 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530138 public void detectCollidingChild(String identifierName, YangConstructType dataType)
139 throws DataModelException {
janani bdd1314f2016-05-19 17:39:50 +0530140 /*
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530141 Do nothing, since it is not part of the schema tree, it is only type of an existing node in schema tree.
janani bdd1314f2016-05-19 17:39:50 +0530142 */
143 }
144
145 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530146 public void detectSelfCollision(String identifierName, YangConstructType dataType)
147 throws DataModelException {
janani bdd1314f2016-05-19 17:39:50 +0530148 /*
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530149 Do nothing, since it is not part of the schema tree, it is only type of an existing node in schema tree.
janani bdd1314f2016-05-19 17:39:50 +0530150 */
151 }
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530152}