blob: 70869b28dafc7b891c62a90587192f68c5b479b6 [file] [log] [blame]
Bharat saraswal4bf8b152016-02-25 02:26:43 +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.translator.tojava.utils;
18
19import org.onosproject.yangutils.datamodel.YangDataTypes;
20import org.onosproject.yangutils.datamodel.YangType;
Bharat saraswal4bf8b152016-02-25 02:26:43 +053021import org.onosproject.yangutils.utils.UtilConstants;
22
23/**
24 * Provides java data types corresponding to YANG type.
25 */
26public final class AttributesJavaDataType {
27
28 /**
29 * Default constructor.
30 */
31 private AttributesJavaDataType() {
32 }
33
34 /**
Vinod Kumar Sc4216002016-03-03 19:55:30 +053035 * Returns java type.
Bharat saraswal4bf8b152016-02-25 02:26:43 +053036 *
37 * @param yangType YANG type
Vinod Kumar Sc4216002016-03-03 19:55:30 +053038 * @return java type
Bharat saraswal4bf8b152016-02-25 02:26:43 +053039 */
Vinod Kumar Sc4216002016-03-03 19:55:30 +053040 public static String getJavaDataType(YangType<?> yangType) {
41 YangDataTypes type = yangType.getDataType();
Bharat saraswal4bf8b152016-02-25 02:26:43 +053042
Bharat saraswal4bf8b152016-02-25 02:26:43 +053043 if (type.equals(YangDataTypes.INT8)) {
44 return UtilConstants.BYTE;
45 } else if (type.equals(YangDataTypes.INT16)) {
46 return UtilConstants.SHORT;
47 } else if (type.equals(YangDataTypes.INT32)) {
48 return UtilConstants.INT;
49 } else if (type.equals(YangDataTypes.INT64)) {
50 return UtilConstants.LONG;
51 } else if (type.equals(YangDataTypes.UINT8)) {
52 return UtilConstants.SHORT;
53 } else if (type.equals(YangDataTypes.UINT16)) {
54 return UtilConstants.INT;
55 } else if (type.equals(YangDataTypes.UINT32)) {
56 return UtilConstants.LONG;
57 } else if (type.equals(YangDataTypes.UINT64)) {
58 //TODO: BIGINTEGER.
59 } else if (type.equals(YangDataTypes.DECIMAL64)) {
60 //TODO: DECIMAL64.
61 } else if (type.equals(YangDataTypes.STRING)) {
62 return UtilConstants.STRING;
63 } else if (type.equals(YangDataTypes.BOOLEAN)) {
64 return UtilConstants.BOOLEAN;
65 } else if (type.equals(YangDataTypes.ENUMERATION)) {
66 //TODO: ENUMERATION.
67 } else if (type.equals(YangDataTypes.BITS)) {
68 //TODO:BITS
69 } else if (type.equals(YangDataTypes.BINARY)) {
70 //TODO:BINARY
71 } else if (type.equals(YangDataTypes.LEAFREF)) {
72 //TODO:LEAFREF
73 } else if (type.equals(YangDataTypes.IDENTITYREF)) {
74 //TODO:IDENTITYREF
75 } else if (type.equals(YangDataTypes.EMPTY)) {
76 //TODO:EMPTY
77 } else if (type.equals(YangDataTypes.UNION)) {
78 //TODO:UNION
79 } else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) {
80 //TODO:INSTANCE_IDENTIFIER
81 } else if (type.equals(YangDataTypes.DERIVED)) {
82 //TODO:DERIVED
83 }
84 return null;
85 }
Vinod Kumar Sc4216002016-03-03 19:55:30 +053086
87 /**
88 * Returns java import class.
89 *
90 * @param yangType YANG type
91 * @param isListAttr if the attribute need to be a list
92 * @return java import class
93 */
94 public static String getJavaImportClass(YangType<?> yangType, boolean isListAttr) {
95 YangDataTypes type = yangType.getDataType();
96
97 if (isListAttr) {
98 if (type.equals(YangDataTypes.INT8)) {
99 return UtilConstants.BYTE_WRAPPER;
100 } else if (type.equals(YangDataTypes.INT16)) {
101 return UtilConstants.SHORT_WRAPPER;
102 } else if (type.equals(YangDataTypes.INT32)) {
103 return UtilConstants.INTEGER_WRAPPER;
104 } else if (type.equals(YangDataTypes.INT64)) {
105 return UtilConstants.LONG_WRAPPER;
106 } else if (type.equals(YangDataTypes.UINT8)) {
107 return UtilConstants.SHORT_WRAPPER;
108 } else if (type.equals(YangDataTypes.UINT16)) {
109 return UtilConstants.INTEGER_WRAPPER;
110 } else if (type.equals(YangDataTypes.UINT32)) {
111 return UtilConstants.LONG_WRAPPER;
112 } else if (type.equals(YangDataTypes.UINT64)) {
113 //TODO: BIGINTEGER.
114 } else if (type.equals(YangDataTypes.DECIMAL64)) {
115 //TODO: DECIMAL64.
116 } else if (type.equals(YangDataTypes.STRING)) {
117 return UtilConstants.STRING;
118 } else if (type.equals(YangDataTypes.BOOLEAN)) {
119 return UtilConstants.BOOLEAN_WRAPPER;
120 } else if (type.equals(YangDataTypes.ENUMERATION)) {
121 //TODO: ENUMERATION.
122 } else if (type.equals(YangDataTypes.BITS)) {
123 //TODO:BITS
124 } else if (type.equals(YangDataTypes.BINARY)) {
125 //TODO:BINARY
126 } else if (type.equals(YangDataTypes.LEAFREF)) {
127 //TODO:LEAFREF
128 } else if (type.equals(YangDataTypes.IDENTITYREF)) {
129 //TODO:IDENTITYREF
130 } else if (type.equals(YangDataTypes.EMPTY)) {
131 //TODO:EMPTY
132 } else if (type.equals(YangDataTypes.UNION)) {
133 //TODO:UNION
134 } else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) {
135 //TODO:INSTANCE_IDENTIFIER
136 } else if (type.equals(YangDataTypes.DERIVED)) {
137 //TODO:DERIVED
138 }
139 } else {
140 if (type.equals(YangDataTypes.UINT64)) {
141 //TODO: BIGINTEGER.
142 } else if (type.equals(YangDataTypes.DECIMAL64)) {
143 //TODO: DECIMAL64.
144 } else if (type.equals(YangDataTypes.STRING)) {
145 return UtilConstants.STRING;
146 } else if (type.equals(YangDataTypes.ENUMERATION)) {
147 //TODO: ENUMERATION.
148 } else if (type.equals(YangDataTypes.BITS)) {
149 //TODO:BITS
150 } else if (type.equals(YangDataTypes.BINARY)) {
151 //TODO:BINARY
152 } else if (type.equals(YangDataTypes.LEAFREF)) {
153 //TODO:LEAFREF
154 } else if (type.equals(YangDataTypes.IDENTITYREF)) {
155 //TODO:IDENTITYREF
156 } else if (type.equals(YangDataTypes.EMPTY)) {
157 //TODO:EMPTY
158 } else if (type.equals(YangDataTypes.UNION)) {
159 //TODO:UNION
160 } else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) {
161 //TODO:INSTANCE_IDENTIFIER
162 } else if (type.equals(YangDataTypes.DERIVED)) {
163 //TODO:DERIVED
164 }
165 }
166 return null;
167 }
168
169 /**
170 * Returns java import package.
171 *
172 * @param yangType YANG type
173 * @param isListAttr if the attribute is of list type
174 * @return java import package
175 */
176 public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr) {
177 YangDataTypes type = yangType.getDataType();
178
179 if (isListAttr) {
180 if (type.equals(YangDataTypes.INT8)
181 || type.equals(YangDataTypes.INT16)
182 || type.equals(YangDataTypes.INT32)
183 || type.equals(YangDataTypes.INT64)
184 || type.equals(YangDataTypes.UINT8)
185 || type.equals(YangDataTypes.UINT16)
186 || type.equals(YangDataTypes.UINT32)
187 || type.equals(YangDataTypes.STRING)
188 || type.equals(YangDataTypes.BOOLEAN)) {
189 return UtilConstants.JAVA_LANG;
190 } else if (type.equals(YangDataTypes.UINT64)) {
191 //TODO: BIGINTEGER.
192 } else if (type.equals(YangDataTypes.DECIMAL64)) {
193 //TODO: DECIMAL64.
194 } else if (type.equals(YangDataTypes.ENUMERATION)) {
195 //TODO: ENUMERATION.
196 } else if (type.equals(YangDataTypes.BITS)) {
197 //TODO:BITS
198 } else if (type.equals(YangDataTypes.BINARY)) {
199 //TODO:BINARY
200 } else if (type.equals(YangDataTypes.LEAFREF)) {
201 //TODO:LEAFREF
202 } else if (type.equals(YangDataTypes.IDENTITYREF)) {
203 //TODO:IDENTITYREF
204 } else if (type.equals(YangDataTypes.EMPTY)) {
205 //TODO:EMPTY
206 } else if (type.equals(YangDataTypes.UNION)) {
207 //TODO:UNION
208 } else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) {
209 //TODO:INSTANCE_IDENTIFIER
210 } else if (type.equals(YangDataTypes.DERIVED)) {
211 //TODO:DERIVED
212 }
213 } else {
214
215 if (type.equals(YangDataTypes.UINT64)) {
216 //TODO: BIGINTEGER.
217 } else if (type.equals(YangDataTypes.DECIMAL64)) {
218 //TODO: DECIMAL64.
219 } else if (type.equals(YangDataTypes.STRING)) {
220 return UtilConstants.JAVA_LANG;
221 } else if (type.equals(YangDataTypes.ENUMERATION)) {
222 //TODO: ENUMERATION.
223 } else if (type.equals(YangDataTypes.BITS)) {
224 //TODO:BITS
225 } else if (type.equals(YangDataTypes.BINARY)) {
226 //TODO:BINARY
227 } else if (type.equals(YangDataTypes.LEAFREF)) {
228 //TODO:LEAFREF
229 } else if (type.equals(YangDataTypes.IDENTITYREF)) {
230 //TODO:IDENTITYREF
231 } else if (type.equals(YangDataTypes.EMPTY)) {
232 //TODO:EMPTY
233 } else if (type.equals(YangDataTypes.UNION)) {
234 //TODO:UNION
235 } else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) {
236 //TODO:INSTANCE_IDENTIFIER
237 } else if (type.equals(YangDataTypes.DERIVED)) {
238 //TODO:DERIVED
239 }
240 }
241 return null;
242 }
Bharat saraswal4bf8b152016-02-25 02:26:43 +0530243}