blob: 74c7a06ee53b204d70d7399b155740b3d9415032 [file] [log] [blame]
Vinod Kumar Scf044422016-02-09 19:53:45 +05301/*
2 * Copyright 2016 Open Networking Laboratory
3 *
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
19import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
20import org.onosproject.yangutils.parser.Parsable;
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053021import org.onosproject.yangutils.utils.YangConstructType;
Vinod Kumar Scf044422016-02-09 19:53:45 +053022
23/*
24 * Reference:RFC 6020.
25 * The "type" statement takes as an argument a string that is the name
26 * of a YANG built-in type or a derived type, followed by an optional
27 * block of sub-statements that are used to put further restrictions
28 * on the type.
29 *
30 * The restrictions that can be applied depend on the type being restricted.
31 * The type's sub-statements
32 *
33 * +------------------+---------+-------------+------------------------------------+
34 * | substatement | section | cardinality | mapped data type |
35 * +------------------+---------+-------------+------------------------------------+
36 * | bit | 9.7.4 | 0..n | - YangBit used in YangBits |
37 * | enum | 9.6.4 | 0..n | - YangEnum used in YangEnumeration |
38 * | length | 9.4.4 | 0..1 | - used for string |
39 * | path | 9.9.2 | 0..1 | - TODO leaf-ref |
40 * | pattern | 9.4.6 | 0..n | - used for string |
41 * | range | 9.2.4 | 0..1 | - used for integer data type |
42 * | require-instance | 9.13.2 | 0..1 | - TODO instance-identifier |
43 * | type | 7.4 | 0..n | - TODO union |
44 * +------------------+---------+-------------+------------------------------------+
45 */
46
47/**
48 * Maintains the data type information.
49 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +053050 * @param <T> YANG data type info
Vinod Kumar Scf044422016-02-09 19:53:45 +053051 */
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053052public class YangType<T> implements Parsable, Resolvable {
Vinod Kumar Scf044422016-02-09 19:53:45 +053053
54 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053055 * YANG node identifier.
Vinod Kumar Scf044422016-02-09 19:53:45 +053056 */
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053057 private YangNodeIdentifier nodeIdentifier;
Vinod Kumar Scf044422016-02-09 19:53:45 +053058
59 /**
Bharat saraswal2f00b4b2016-03-04 20:08:09 +053060 * Java package in which the Java type is defined.
61 */
62 private String javaPackage;
63
64 /**
Vinod Kumar Scf044422016-02-09 19:53:45 +053065 * YANG data type.
66 */
67 private YangDataTypes dataType;
68
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053069 /**
70 * Additional information about data type, example restriction info, named
71 * values, etc. The extra information is based on the data type. Based on
72 * the data type, the extended info can vary.
73 */
74 private T dataTypeExtendedInfo;
Vinod Kumar Scf044422016-02-09 19:53:45 +053075
76 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053077 * Effective built-in type, requried in case type of typedef is again a
78 * derived type. This information is to be added during linking.
79 */
80 private YangDataTypes effectiveBuiltInType;
81
82 /**
83 * Effective pattern restriction, requried in case type of typedef is again
84 * a derived type. This information is to be added during linking.
85 */
86 private YangPatternRestriction effectivePatternRestriction;
87
88 /**
89 * Status of resolution. If completely resolved enum value is "RESOLVED",
90 * if not enum value is "UNRESOLVED", in case reference of grouping/typedef
91 * is added to uses/type but it's not resolved value of enum should be
92 * "PARTIALLY_RESOLVED".
93 */
94 private ResolvableStatus resolvableStatus;
95
96 /**
Vinod Kumar Scf044422016-02-09 19:53:45 +053097 * Default constructor.
98 */
99 public YangType() {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530100
101 nodeIdentifier = new YangNodeIdentifier();
102 resolvableStatus = ResolvableStatus.UNRESOLVED;
103 }
104
105 /**
106 * Returns prefix associated with data type name.
107 *
108 * @return prefix associated with data type name
109 */
110 public String getPrefix() {
111 return nodeIdentifier.getPrefix();
112 }
113
114 /**
115 * Set prefix associated with data type name.
116 *
117 * @param prefix prefix associated with data type name
118 */
119 public void setPrefix(String prefix) {
120 nodeIdentifier.setPrefix(prefix);
Vinod Kumar Scf044422016-02-09 19:53:45 +0530121 }
122
123 /**
124 * Get the name of data type.
125 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530126 * @return the name of data type
Vinod Kumar Scf044422016-02-09 19:53:45 +0530127 */
128 public String getDataTypeName() {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530129 return nodeIdentifier.getName();
Vinod Kumar Scf044422016-02-09 19:53:45 +0530130 }
131
132 /**
133 * Set the name of the data type.
134 *
135 * @param typeName the name to set
136 */
137 public void setDataTypeName(String typeName) {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530138 nodeIdentifier.setName(typeName);
Vinod Kumar Scf044422016-02-09 19:53:45 +0530139 }
140
141 /**
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530142 * Get the Java package where the type is defined.
143 *
144 * @return Java package where the type is defined
145 */
146 public String getJavaPackage() {
147 return javaPackage;
148 }
149
150 /**
151 * Set Java package where the type is defined.
152 *
153 * @param javaPackage Java package where the type is defined
154 */
155 public void setJavaPackage(String javaPackage) {
156 this.javaPackage = javaPackage;
157 }
158
159 /**
Vinod Kumar Scf044422016-02-09 19:53:45 +0530160 * Get the type of data.
161 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530162 * @return the data type
Vinod Kumar Scf044422016-02-09 19:53:45 +0530163 */
164 public YangDataTypes getDataType() {
165 return dataType;
166 }
167
168 /**
169 * Set the type of data.
170 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530171 * @param dataType data type
Vinod Kumar Scf044422016-02-09 19:53:45 +0530172 */
173 public void setDataType(YangDataTypes dataType) {
174 this.dataType = dataType;
175 }
176
177 /**
178 * Get the data type meta data.
179 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530180 * @return the data type meta data
Vinod Kumar Scf044422016-02-09 19:53:45 +0530181 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530182 public T getDataTypeExtendedInfo() {
183 return dataTypeExtendedInfo;
Vinod Kumar Scf044422016-02-09 19:53:45 +0530184 }
185
186 /**
187 * Set the data type meta data.
188 *
189 * @param dataTypeInfo the meta data to set
190 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530191 public void setDataTypeExtendedInfo(T dataTypeInfo) {
192 this.dataTypeExtendedInfo = dataTypeInfo;
Vinod Kumar Scf044422016-02-09 19:53:45 +0530193 }
194
195 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530196 * Returns node identifier.
197 *
198 * @return node identifier
199 */
200 public YangNodeIdentifier getNodeIdentifier() {
201 return nodeIdentifier;
202 }
203
204 /**
205 * Set node identifier.
206 *
207 * @param nodeIdentifier the node identifier
208 */
209 public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) {
210 this.nodeIdentifier = nodeIdentifier;
211 }
212
213 /**
214 * Return effective built-in type.
215 *
216 * @return effective built-in type
217 */
218 public YangDataTypes getEffectiveBuiltInType() {
219 return effectiveBuiltInType;
220 }
221
222 /**
223 * Set effective built-in type.
224 *
225 * @param effectiveBuiltInType effective built-in type
226 */
227 public void setEffectiveBuiltInType(YangDataTypes effectiveBuiltInType) {
228 this.effectiveBuiltInType = effectiveBuiltInType;
229 }
230
231 /**
232 * Returns effective pattern restriction.
233 *
234 * @return effective pattern restriction
235 */
236 public YangPatternRestriction getEffectivePatternRestriction() {
237 return effectivePatternRestriction;
238 }
239
240 /**
241 * Set effective pattern restriction.
242 *
243 * @param effectivePatternRestriction effective pattern restriction
244 */
245 public void setEffectivePatternRestriction(YangPatternRestriction effectivePatternRestriction) {
246 this.effectivePatternRestriction = effectivePatternRestriction;
247 }
248
249 /**
Vinod Kumar Scf044422016-02-09 19:53:45 +0530250 * Returns the type of the parsed data.
251 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530252 * @return returns TYPE_DATA
Vinod Kumar Scf044422016-02-09 19:53:45 +0530253 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530254 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530255 public YangConstructType getYangConstructType() {
256 return YangConstructType.TYPE_DATA;
Vinod Kumar Scf044422016-02-09 19:53:45 +0530257 }
258
259 /**
260 * Validate the data on entering the corresponding parse tree node.
261 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530262 * @throws DataModelException a violation of data model rules
Vinod Kumar Scf044422016-02-09 19:53:45 +0530263 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530264 @Override
Vinod Kumar Scf044422016-02-09 19:53:45 +0530265 public void validateDataOnEntry() throws DataModelException {
266 // TODO auto-generated method stub, to be implemented by parser
267
268 }
269
270 /**
271 * Validate the data on exiting the corresponding parse tree node.
272 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530273 * @throws DataModelException a violation of data model rules
Vinod Kumar Scf044422016-02-09 19:53:45 +0530274 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530275 @Override
Vinod Kumar Scf044422016-02-09 19:53:45 +0530276 public void validateDataOnExit() throws DataModelException {
277 // TODO auto-generated method stub, to be implemented by parser
278
279 }
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530280
281 @Override
282 public ResolvableStatus getResolvableStatus() {
283 return resolvableStatus;
284 }
285
286 @Override
287 public void setResolvableStatus(ResolvableStatus resolvableStatus) {
288 this.resolvableStatus = resolvableStatus;
289 }
290
291 @Override
292 public void resolve() {
293 //TODO: implement the method.
294 }
Vinod Kumar Scf044422016-02-09 19:53:45 +0530295}