blob: 49eafffbe521d50309fff1d97c37e2e63c11bd2d [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 */
Gaurav Agrawal338735b2016-04-18 18:53:11 +053057public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, HasType {
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 /**
86 * Maintain the data type information.
87 */
88 private YangType<?> dataType;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053089
90 /**
91 * Units of the data type.
92 */
93 private String units;
94
95 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +053096 * List of YANG type, for typedef it will have single type.
97 * This is done to unify the code with union.
98 */
99 private List<YangType<?>> typeList;
100
101 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530102 * Creates a typedef node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530103 */
104 public YangTypeDef() {
105 super(YangNodeType.TYPEDEF_NODE);
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530106 typeList = new LinkedList<>();
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530107 }
108
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530109 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530110 * Returns the default value.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530111 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530112 * @return the default value
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530113 */
114 public String getDefaultValueInString() {
115 return defaultValueInString;
116 }
117
118 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530119 * Sets the default value.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530120 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530121 * @param defaultValueInString the default value
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530122 */
123 public void setDefaultValueInString(String defaultValueInString) {
124 this.defaultValueInString = defaultValueInString;
125 }
126
127 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530128 * Returns the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530129 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530130 * @return the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530131 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530132 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530133 public String getDescription() {
134 return description;
135 }
136
137 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530138 * Sets the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530139 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530140 * @param description set the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530141 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530142 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530143 public void setDescription(String description) {
144 this.description = description;
145 }
146
147 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530148 * Returns the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530149 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530150 * @return the reference
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530151 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530152 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530153 public String getReference() {
154 return reference;
155 }
156
157 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530158 * Sets the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530159 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530160 * @param reference the reference to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530161 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530162 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530163 public void setReference(String reference) {
164 this.reference = reference;
165 }
166
167 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530168 * Returns the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530169 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530170 * @return the status
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530171 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530172 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530173 public YangStatusType getStatus() {
174 return status;
175 }
176
177 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530178 * Sets the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530179 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530180 * @param status the status to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530181 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530182 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530183 public void setStatus(YangStatusType status) {
184 this.status = status;
185 }
186
187 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530188 * Returns the data type.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530189 *
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530190 * @return the data type
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530191 */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530192 public YangType<?> getTypeDefBaseType() {
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530193 if (!(getTypeList().isEmpty())) {
194 return getTypeList().get(0);
195 }
196 return null;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530197 }
198
199 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530200 * Sets the data type.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530201 *
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530202 * @param dataType the data type
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530203 */
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530204 public void setDataType(YangType<?> dataType) {
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530205 getTypeList().add(0, dataType);
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530206 }
207
208 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530209 * Returns the unit.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530210 *
211 * @return the units
212 */
213 public String getUnits() {
214 return units;
215 }
216
217 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530218 * Sets the unit.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530219 *
220 * @param units the units to set
221 */
222 public void setUnits(String units) {
223 this.units = units;
224 }
225
226 /**
227 * Returns the type of the data.
228 *
229 * @return returns TYPEDEF_DATA
230 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530231 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530232 public YangConstructType getYangConstructType() {
233 return YangConstructType.TYPEDEF_DATA;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530234 }
235
236 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530237 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530238 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530239 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530240 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530241 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530242 public void validateDataOnEntry() throws DataModelException {
243 // TODO auto-generated method stub, to be implemented by parser
244 }
245
246 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530247 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530248 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530249 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530250 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530251 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530252 public void validateDataOnExit() throws DataModelException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530253 // TODO auto-generated method stub, to be implemented by parser
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530254 }
255
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530256 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530257 * Returns the YANG name of the typedef.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530258 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530259 * @return YANG name of the typedef
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530260 */
261 @Override
262 public String getName() {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530263 return name;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530264 }
265
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530266 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530267 * Sets YANG name of the typedef.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530268 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530269 * @param name YANG name of the typedef
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530270 */
271 @Override
272 public void setName(String name) {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530273 this.name = name;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530274 }
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530275
276 @Override
277 public List<YangType<?>> getTypeList() {
278 return typeList;
279 }
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530280}