blob: 35998d4d4d73c5b5e21f485935656b022a8085af [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
18import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
19import org.onosproject.yangutils.parser.Parsable;
Vinod Kumar Sc4216002016-03-03 19:55:30 +053020import org.onosproject.yangutils.utils.YangConstructType;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053021
22/*-
23 * Reference RFC 6020.
24 *
25 * The "typedef" statement defines a new type that may be used locally in the
26 * module, in modules or submodules which include it, and by other modules that
27 * import from it. The new type is called the "derived type", and the type from
28 * which it was derived is called the "base type". All derived types can be
29 * traced back to a YANG built-in type.
30 *
31 * The "typedef" statement's argument is an identifier that is the name of the
32 * type to be defined, and MUST be followed by a block of sub-statements that
33 * holds detailed typedef information.
34 *
35 * The name of the type MUST NOT be one of the YANG built-in types. If the
36 * typedef is defined at the top level of a YANG module or submodule, the name
37 * of the type to be defined MUST be unique within the module.
38 * The typedef's sub-statements
39 *
40 * +--------------+---------+-------------+------------------+
41 * | substatement | section | cardinality |data model mapping|
42 * +--------------+---------+-------------+------------------+
43 * | default | 7.3.4 | 0..1 |-string |
44 * | description | 7.19.3 | 0..1 |-string |
45 * | reference | 7.19.4 | 0..1 |-string |
46 * | status | 7.19.2 | 0..1 |-YangStatus |
47 * | type | 7.3.2 | 1 |-yangType |
48 * | units | 7.3.3 | 0..1 |-string |
49 * +--------------+---------+-------------+------------------+
50 */
51/**
Bharat saraswald9822e92016-04-05 15:13:44 +053052 * Represents data model node to maintain information defined in YANG typedef.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053053 */
54public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
55
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053056 /**
57 * Default value in string, needs to be converted to the target object,
58 * based on the type.
59 */
60 private String defaultValueInString;
61
62 /**
63 * Description of new type.
64 */
65 private String description;
66
67 /**
68 * reference string.
69 */
70 private String reference;
71
72 /**
73 * Status of the data type.
74 */
75 private YangStatusType status;
76
77 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053078 * Name of the typedef.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053079 */
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053080 private String name;
81
82 /**
83 * Maintain the data type information.
84 */
85 private YangType<?> dataType;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053086
87 /**
88 * Units of the data type.
89 */
90 private String units;
91
92 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053093 * Creates a typedef node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053094 */
95 public YangTypeDef() {
96 super(YangNodeType.TYPEDEF_NODE);
97 }
98
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053099 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530100 * Returns the default value.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530101 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530102 * @return the default value
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530103 */
104 public String getDefaultValueInString() {
105 return defaultValueInString;
106 }
107
108 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530109 * Sets the default value.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530110 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530111 * @param defaultValueInString the default value
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530112 */
113 public void setDefaultValueInString(String defaultValueInString) {
114 this.defaultValueInString = defaultValueInString;
115 }
116
117 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530118 * Returns the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530119 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530120 * @return the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530121 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530122 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530123 public String getDescription() {
124 return description;
125 }
126
127 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530128 * Sets the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530129 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530130 * @param description set 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 void setDescription(String description) {
134 this.description = description;
135 }
136
137 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530138 * Returns the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530139 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530140 * @return the reference
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 String getReference() {
144 return reference;
145 }
146
147 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530148 * Sets the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530149 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530150 * @param reference the reference to set
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 void setReference(String reference) {
154 this.reference = reference;
155 }
156
157 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530158 * Returns the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530159 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530160 * @return the status
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 YangStatusType getStatus() {
164 return status;
165 }
166
167 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530168 * Sets the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530169 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530170 * @param status the status to set
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 void setStatus(YangStatusType status) {
174 this.status = status;
175 }
176
177 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530178 * Returns the data type.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530179 *
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530180 * @return the data type
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530181 */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530182 public YangType<?> getTypeDefBaseType() {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530183 return dataType;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530184 }
185
186 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530187 * Sets the data type.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530188 *
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530189 * @param dataType the data type
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530190 */
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530191 public void setDataType(YangType<?> dataType) {
192 this.dataType = dataType;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530193 }
194
195 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530196 * Returns the unit.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530197 *
198 * @return the units
199 */
200 public String getUnits() {
201 return units;
202 }
203
204 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530205 * Sets the unit.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530206 *
207 * @param units the units to set
208 */
209 public void setUnits(String units) {
210 this.units = units;
211 }
212
213 /**
214 * Returns the type of the data.
215 *
216 * @return returns TYPEDEF_DATA
217 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530218 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530219 public YangConstructType getYangConstructType() {
220 return YangConstructType.TYPEDEF_DATA;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530221 }
222
223 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530224 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530225 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530226 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530227 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530228 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530229 public void validateDataOnEntry() throws DataModelException {
230 // TODO auto-generated method stub, to be implemented by parser
231 }
232
233 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530234 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530235 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530236 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530237 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530238 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530239 public void validateDataOnExit() throws DataModelException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530240 // TODO auto-generated method stub, to be implemented by parser
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530241 }
242
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530243 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530244 * Returns the YANG name of the typedef.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530245 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530246 * @return YANG name of the typedef
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530247 */
248 @Override
249 public String getName() {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530250 return name;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530251 }
252
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530253 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530254 * Sets YANG name of the typedef.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530255 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530256 * @param name YANG name of the typedef
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530257 */
258 @Override
259 public void setName(String name) {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530260 this.name = name;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530261 }
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530262}