blob: dd3e2320cf1031353d88ff3872cfaea0cad78de3 [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 */
52public class YangType<T> implements Parsable {
53
54 /**
55 * YANG data type name.
56 */
57 private String dataTypeName;
58
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 /**
77 * Default constructor.
78 */
79 public YangType() {
80 }
81
82 /**
83 * Get the name of data type.
84 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053085 * @return the name of data type
Vinod Kumar Scf044422016-02-09 19:53:45 +053086 */
87 public String getDataTypeName() {
88 return dataTypeName;
89 }
90
91 /**
92 * Set the name of the data type.
93 *
94 * @param typeName the name to set
95 */
96 public void setDataTypeName(String typeName) {
97 dataTypeName = typeName;
98 }
99
100 /**
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530101 * Get the Java package where the type is defined.
102 *
103 * @return Java package where the type is defined
104 */
105 public String getJavaPackage() {
106 return javaPackage;
107 }
108
109 /**
110 * Set Java package where the type is defined.
111 *
112 * @param javaPackage Java package where the type is defined
113 */
114 public void setJavaPackage(String javaPackage) {
115 this.javaPackage = javaPackage;
116 }
117
118 /**
Vinod Kumar Scf044422016-02-09 19:53:45 +0530119 * Get the type of data.
120 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530121 * @return the data type
Vinod Kumar Scf044422016-02-09 19:53:45 +0530122 */
123 public YangDataTypes getDataType() {
124 return dataType;
125 }
126
127 /**
128 * Set the type of data.
129 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530130 * @param dataType data type
Vinod Kumar Scf044422016-02-09 19:53:45 +0530131 */
132 public void setDataType(YangDataTypes dataType) {
133 this.dataType = dataType;
134 }
135
136 /**
137 * Get the data type meta data.
138 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530139 * @return the data type meta data
Vinod Kumar Scf044422016-02-09 19:53:45 +0530140 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530141 public T getDataTypeExtendedInfo() {
142 return dataTypeExtendedInfo;
Vinod Kumar Scf044422016-02-09 19:53:45 +0530143 }
144
145 /**
146 * Set the data type meta data.
147 *
148 * @param dataTypeInfo the meta data to set
149 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530150 public void setDataTypeExtendedInfo(T dataTypeInfo) {
151 this.dataTypeExtendedInfo = dataTypeInfo;
Vinod Kumar Scf044422016-02-09 19:53:45 +0530152 }
153
154 /**
155 * Returns the type of the parsed data.
156 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530157 * @return returns TYPE_DATA
Vinod Kumar Scf044422016-02-09 19:53:45 +0530158 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530159 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530160 public YangConstructType getYangConstructType() {
161 return YangConstructType.TYPE_DATA;
Vinod Kumar Scf044422016-02-09 19:53:45 +0530162 }
163
164 /**
165 * Validate the data on entering the corresponding parse tree node.
166 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530167 * @throws DataModelException a violation of data model rules
Vinod Kumar Scf044422016-02-09 19:53:45 +0530168 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530169 @Override
Vinod Kumar Scf044422016-02-09 19:53:45 +0530170 public void validateDataOnEntry() throws DataModelException {
171 // TODO auto-generated method stub, to be implemented by parser
172
173 }
174
175 /**
176 * Validate the data on exiting the corresponding parse tree node.
177 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530178 * @throws DataModelException a violation of data model rules
Vinod Kumar Scf044422016-02-09 19:53:45 +0530179 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530180 @Override
Vinod Kumar Scf044422016-02-09 19:53:45 +0530181 public void validateDataOnExit() throws DataModelException {
182 // TODO auto-generated method stub, to be implemented by parser
183
184 }
185}