blob: 723319d1c61916451385a3d9fd4c376026e0e255 [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;
21import org.onosproject.yangutils.parser.ParsableDataType;
22
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 *
50 * @param <T> YANG data type info.
51 */
52public class YangType<T> implements Parsable {
53
54 /**
55 * YANG data type name.
56 */
57 private String dataTypeName;
58
59 /**
60 * YANG data type.
61 */
62 private YangDataTypes dataType;
63
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053064 /**
65 * Additional information about data type, example restriction info, named
66 * values, etc. The extra information is based on the data type. Based on
67 * the data type, the extended info can vary.
68 */
69 private T dataTypeExtendedInfo;
Vinod Kumar Scf044422016-02-09 19:53:45 +053070
71 /**
72 * Default constructor.
73 */
74 public YangType() {
75 }
76
77 /**
78 * Get the name of data type.
79 *
80 * @return the name of data type.
81 */
82 public String getDataTypeName() {
83 return dataTypeName;
84 }
85
86 /**
87 * Set the name of the data type.
88 *
89 * @param typeName the name to set
90 */
91 public void setDataTypeName(String typeName) {
92 dataTypeName = typeName;
93 }
94
95 /**
96 * Get the type of data.
97 *
98 * @return the data type.
99 */
100 public YangDataTypes getDataType() {
101 return dataType;
102 }
103
104 /**
105 * Set the type of data.
106 *
107 * @param dataType data type.
108 */
109 public void setDataType(YangDataTypes dataType) {
110 this.dataType = dataType;
111 }
112
113 /**
114 * Get the data type meta data.
115 *
116 * @return the data type meta data.
117 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530118 public T getDataTypeExtendedInfo() {
119 return dataTypeExtendedInfo;
Vinod Kumar Scf044422016-02-09 19:53:45 +0530120 }
121
122 /**
123 * Set the data type meta data.
124 *
125 * @param dataTypeInfo the meta data to set
126 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530127 public void setDataTypeExtendedInfo(T dataTypeInfo) {
128 this.dataTypeExtendedInfo = dataTypeInfo;
Vinod Kumar Scf044422016-02-09 19:53:45 +0530129 }
130
131 /**
132 * Returns the type of the parsed data.
133 *
134 * @return returns TYPE_DATA.
135 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530136 @Override
Vinod Kumar Scf044422016-02-09 19:53:45 +0530137 public ParsableDataType getParsableDataType() {
138 return ParsableDataType.TYPE_DATA;
139 }
140
141 /**
142 * Validate the data on entering the corresponding parse tree node.
143 *
144 * @throws DataModelException a violation of data model rules.
145 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530146 @Override
Vinod Kumar Scf044422016-02-09 19:53:45 +0530147 public void validateDataOnEntry() throws DataModelException {
148 // TODO auto-generated method stub, to be implemented by parser
149
150 }
151
152 /**
153 * Validate the data on exiting the corresponding parse tree node.
154 *
155 * @throws DataModelException a violation of data model rules.
156 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530157 @Override
Vinod Kumar Scf044422016-02-09 19:53:45 +0530158 public void validateDataOnExit() throws DataModelException {
159 // TODO auto-generated method stub, to be implemented by parser
160
161 }
162}