blob: aa2181c4f84c61dd00d4af5655d1c5aa9e08393a [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 */
16package org.onosproject.yangutils.datamodel;
17
Gaurav Agrawal338735b2016-04-18 18:53:11 +053018import java.util.LinkedList;
19import java.util.List;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053020import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
21import org.onosproject.yangutils.parser.Parsable;
Vinod Kumar Sc4216002016-03-03 19:55:30 +053022import org.onosproject.yangutils.utils.YangConstructType;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053023
24/*-
25 * Reference RFC 6020.
26 *
27 * The "typedef" statement defines a new type that may be used locally in the
28 * module, in modules or submodules which include it, and by other modules that
29 * import from it. The new type is called the "derived type", and the type from
30 * which it was derived is called the "base type". All derived types can be
31 * traced back to a YANG built-in type.
32 *
33 * The "typedef" statement's argument is an identifier that is the name of the
34 * type to be defined, and MUST be followed by a block of sub-statements that
35 * holds detailed typedef information.
36 *
37 * The name of the type MUST NOT be one of the YANG built-in types. If the
38 * typedef is defined at the top level of a YANG module or submodule, the name
39 * of the type to be defined MUST be unique within the module.
40 * The typedef's sub-statements
41 *
42 * +--------------+---------+-------------+------------------+
43 * | substatement | section | cardinality |data model mapping|
44 * +--------------+---------+-------------+------------------+
45 * | default | 7.3.4 | 0..1 |-string |
46 * | description | 7.19.3 | 0..1 |-string |
47 * | reference | 7.19.4 | 0..1 |-string |
48 * | status | 7.19.2 | 0..1 |-YangStatus |
49 * | type | 7.3.2 | 1 |-yangType |
50 * | units | 7.3.3 | 0..1 |-string |
51 * +--------------+---------+-------------+------------------+
52 */
Gaurav Agrawal338735b2016-04-18 18:53:11 +053053
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053054/**
Bharat saraswald9822e92016-04-05 15:13:44 +053055 * Represents data model node to maintain information defined in YANG typedef.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053056 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053057public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, YangTypeContainer {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053058
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053059 /**
60 * Default value in string, needs to be converted to the target object,
61 * based on the type.
62 */
63 private String defaultValueInString;
64
65 /**
66 * Description of new type.
67 */
68 private String description;
69
70 /**
71 * reference string.
72 */
73 private String reference;
74
75 /**
76 * Status of the data type.
77 */
78 private YangStatusType status;
79
80 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053081 * Name of the typedef.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053082 */
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053083 private String name;
84
85 /**
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053086 * Units of the data type.
87 */
88 private String units;
89
90 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +053091 * List of YANG type, for typedef it will have single type.
92 * This is done to unify the code with union.
93 */
94 private List<YangType<?>> typeList;
95
96 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053097 * Creates a typedef node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053098 */
99 public YangTypeDef() {
100 super(YangNodeType.TYPEDEF_NODE);
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530101 typeList = new LinkedList<>();
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530102 }
103
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530104 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530105 * Returns the default value.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530106 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530107 * @return the default value
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530108 */
109 public String getDefaultValueInString() {
110 return defaultValueInString;
111 }
112
113 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530114 * Sets the default value.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530115 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530116 * @param defaultValueInString the default value
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530117 */
118 public void setDefaultValueInString(String defaultValueInString) {
119 this.defaultValueInString = defaultValueInString;
120 }
121
122 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530123 * Returns the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530124 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530125 * @return the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530126 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530127 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530128 public String getDescription() {
129 return description;
130 }
131
132 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530133 * Sets the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530134 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530135 * @param description set the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530136 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530137 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530138 public void setDescription(String description) {
139 this.description = description;
140 }
141
142 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530143 * Returns the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530144 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530145 * @return the reference
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530146 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530147 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530148 public String getReference() {
149 return reference;
150 }
151
152 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530153 * Sets the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530154 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530155 * @param reference the reference to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530156 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530157 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530158 public void setReference(String reference) {
159 this.reference = reference;
160 }
161
162 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530163 * Returns the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530164 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530165 * @return the status
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530166 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530167 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530168 public YangStatusType getStatus() {
169 return status;
170 }
171
172 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530173 * Sets the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530174 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530175 * @param status the status to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530176 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530177 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530178 public void setStatus(YangStatusType status) {
179 this.status = status;
180 }
181
182 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530183 * Returns the data type.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530184 *
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530185 * @return the data type
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530186 */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530187 public YangType<?> getTypeDefBaseType() {
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530188 if (!(getTypeList().isEmpty())) {
189 return getTypeList().get(0);
190 }
191 return null;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530192 }
193
194 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530195 * Sets the data type.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530196 *
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530197 * @param dataType the data type
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530198 */
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530199 public void setDataType(YangType<?> dataType) {
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530200 getTypeList().add(0, dataType);
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530201 }
202
203 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530204 * Returns the unit.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530205 *
206 * @return the units
207 */
208 public String getUnits() {
209 return units;
210 }
211
212 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530213 * Sets the unit.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530214 *
215 * @param units the units to set
216 */
217 public void setUnits(String units) {
218 this.units = units;
219 }
220
221 /**
222 * Returns the type of the data.
223 *
224 * @return returns TYPEDEF_DATA
225 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530226 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530227 public YangConstructType getYangConstructType() {
228 return YangConstructType.TYPEDEF_DATA;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530229 }
230
231 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530232 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530233 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530234 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530235 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530236 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530237 public void validateDataOnEntry() throws DataModelException {
238 // TODO auto-generated method stub, to be implemented by parser
239 }
240
241 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530242 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530243 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530244 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530245 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530246 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530247 public void validateDataOnExit() throws DataModelException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530248 // TODO auto-generated method stub, to be implemented by parser
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530249 }
250
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530251 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530252 * Returns the YANG name of the typedef.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530253 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530254 * @return YANG name of the typedef
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530255 */
256 @Override
257 public String getName() {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530258 return name;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530259 }
260
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530261 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530262 * Sets YANG name of the typedef.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530263 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530264 * @param name YANG name of the typedef
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530265 */
266 @Override
267 public void setName(String name) {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530268 this.name = name;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530269 }
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530270
271 @Override
272 public List<YangType<?>> getTypeList() {
273 return typeList;
274 }
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530275}