blob: c6b3bb73bbb0fd9577b0c2fb97db71fb4e8c7fff [file] [log] [blame]
Vinod Kumar S38046502016-03-23 15:30:27 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Vinod Kumar S38046502016-03-23 15:30:27 +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 */
16
17package org.onosproject.yangutils.translator.tojava;
18
Vinod Kumar S38046502016-03-23 15:30:27 +053019import org.onosproject.yangutils.datamodel.YangType;
Bharat saraswal6ef0b762016-04-05 12:45:45 +053020import org.onosproject.yangutils.translator.exception.TranslatorException;
Vinod Kumar S38046502016-03-23 15:30:27 +053021
Vinod Kumar S38046502016-03-23 15:30:27 +053022/**
Bharat saraswald9822e92016-04-05 15:13:44 +053023 * Represents the attribute info corresponding to class/interface generated.
Vinod Kumar S38046502016-03-23 15:30:27 +053024 */
25public final class JavaAttributeInfo {
26
27 /**
28 * The data type info of attribute.
29 */
30 private YangType<?> attrType;
31
32 /**
33 * Name of the attribute.
34 */
35 private String name;
36
37 /**
38 * If the added attribute is a list of info.
39 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053040 private boolean isListAttr;
Vinod Kumar S38046502016-03-23 15:30:27 +053041
42 /**
43 * If the added attribute has to be accessed in a fully qualified manner.
44 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053045 private boolean isQualifiedName;
Vinod Kumar S38046502016-03-23 15:30:27 +053046
47 /**
48 * The class info will be used to set the attribute type and package info
49 * will be use for qualified name.
50 */
51 private JavaQualifiedTypeInfo importInfo;
52
53 /**
Bharat saraswale707f032016-07-14 23:33:55 +053054 * If conflict occurs.
55 */
56 private boolean isIntConflict;
57
58 /**
59 * If conflict occurs.
60 */
61 private boolean isLongConflict;
62
63 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053064 * Creates a java attribute info object.
Vinod Kumar S38046502016-03-23 15:30:27 +053065 */
66 private JavaAttributeInfo() {
67 }
68
69 /**
Bharat saraswal6ef0b762016-04-05 12:45:45 +053070 * Creates object of java attribute info.
Bharat saraswald6f12412016-03-28 15:50:13 +053071 *
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053072 * @param attrType YANG type
73 * @param name attribute name
74 * @param isListAttr is list attribute
Bharat saraswald6f12412016-03-28 15:50:13 +053075 * @param isQualifiedName is qualified name
76 */
77 public JavaAttributeInfo(YangType<?> attrType, String name, boolean isListAttr, boolean isQualifiedName) {
78 this.attrType = attrType;
79 this.name = name;
80 this.isListAttr = isListAttr;
81 this.isQualifiedName = isQualifiedName;
82 }
83
84 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053085 * Returns the data type info of attribute.
Vinod Kumar S38046502016-03-23 15:30:27 +053086 *
87 * @return the data type info of attribute
88 */
89 public YangType<?> getAttributeType() {
90
91 if (attrType == null) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +053092 throw new TranslatorException("Expected java attribute type is null");
Vinod Kumar S38046502016-03-23 15:30:27 +053093 }
94 return attrType;
95 }
96
97 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053098 * Sets the data type info of attribute.
Vinod Kumar S38046502016-03-23 15:30:27 +053099 *
100 * @param type the data type info of attribute
101 */
102 public void setAttributeType(YangType<?> type) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530103 attrType = type;
104 }
105
106 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530107 * Returns name of the attribute.
Vinod Kumar S38046502016-03-23 15:30:27 +0530108 *
109 * @return name of the attribute
110 */
111 public String getAttributeName() {
112
113 if (name == null) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530114 throw new TranslatorException("Expected java attribute name is null");
Vinod Kumar S38046502016-03-23 15:30:27 +0530115 }
116 return name;
117 }
118
119 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530120 * Sets name of the attribute.
Vinod Kumar S38046502016-03-23 15:30:27 +0530121 *
122 * @param attrName name of the attribute
123 */
124 public void setAttributeName(String attrName) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530125 name = attrName;
126 }
127
128 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530129 * Returns if the added attribute is a list of info.
Vinod Kumar S38046502016-03-23 15:30:27 +0530130 *
131 * @return the if the added attribute is a list of info
132 */
133 public boolean isListAttr() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530134 return isListAttr;
135 }
136
137 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530138 * Sets if the added attribute is a list of info.
Vinod Kumar S38046502016-03-23 15:30:27 +0530139 *
140 * @param isList if the added attribute is a list of info
141 */
142 public void setListAttr(boolean isList) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530143 isListAttr = isList;
144 }
145
146 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530147 * Returns if the added attribute has to be accessed in a fully qualified
Vinod Kumar S38046502016-03-23 15:30:27 +0530148 * manner.
149 *
150 * @return the if the added attribute has to be accessed in a fully
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530151 * qualified manner.
Vinod Kumar S38046502016-03-23 15:30:27 +0530152 */
153 public boolean isQualifiedName() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530154 return isQualifiedName;
155 }
156
157 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530158 * Sets if the added attribute has to be accessed in a fully qualified
Vinod Kumar S38046502016-03-23 15:30:27 +0530159 * manner.
160 *
161 * @param isQualified if the added attribute has to be accessed in a fully
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530162 * qualified manner
Vinod Kumar S38046502016-03-23 15:30:27 +0530163 */
164 public void setIsQualifiedAccess(boolean isQualified) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530165 isQualifiedName = isQualified;
166 }
167
168 /**
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530169 * Returns the import info for the attribute type. It will be null, if the type
Vinod Kumar S38046502016-03-23 15:30:27 +0530170 * is basic built-in java type.
171 *
172 * @return import info
173 */
174 public JavaQualifiedTypeInfo getImportInfo() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530175 return importInfo;
176 }
177
178 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530179 * Sets the import info for the attribute type.
Vinod Kumar S38046502016-03-23 15:30:27 +0530180 *
181 * @param importInfo import info for the attribute type
182 */
183 public void setImportInfo(JavaQualifiedTypeInfo importInfo) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530184 this.importInfo = importInfo;
185 }
186
187 /**
Bharat saraswale707f032016-07-14 23:33:55 +0530188 * Returns true if conflict between int and uint.
189 *
190 * @return true if conflict between int and uint
191 */
192 public boolean isIntConflict() {
193 return isIntConflict;
194 }
195
196 /**
197 * Sets true if conflict between int and uint.
198 *
199 * @param intConflict true if conflict between int and uint
200 */
201 public void setIntConflict(boolean intConflict) {
202 isIntConflict = intConflict;
203 }
204
205 /**
206 * Returns true if conflict between long and ulong.
207 *
208 * @return true if conflict between long and ulong
209 */
210 public boolean isLongConflict() {
211 return isLongConflict;
212 }
213
214 /**
215 * Sets true if conflict between long and ulong.
216 *
217 * @param longConflict true if conflict between long and ulong
218 */
219 public void setLongConflict(boolean longConflict) {
220 isLongConflict = longConflict;
221 }
222
223 /**
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530224 * Returns java attribute info.
225 *
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530226 * @param importInfo java qualified type info
227 * @param attributeName attribute name
228 * @param attributeType attribute type
229 * @param isQualifiedAccess is the attribute a qualified access
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530230 * @param isListAttribute is list attribute
231 * @return java attribute info.
232 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530233 public static JavaAttributeInfo getAttributeInfoForTheData(JavaQualifiedTypeInfo importInfo, String attributeName,
234 YangType<?> attributeType, boolean isQualifiedAccess,
235 boolean isListAttribute) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530236
237 JavaAttributeInfo newAttr = new JavaAttributeInfo();
Bharat saraswale2d51d62016-03-23 19:40:35 +0530238 newAttr.setImportInfo(importInfo);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530239 newAttr.setAttributeName(attributeName);
Bharat saraswale2d51d62016-03-23 19:40:35 +0530240 newAttr.setAttributeType(attributeType);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530241 newAttr.setIsQualifiedAccess(isQualifiedAccess);
242 newAttr.setListAttr(isListAttribute);
Bharat saraswale2d51d62016-03-23 19:40:35 +0530243
244 return newAttr;
245 }
Vinod Kumar S38046502016-03-23 15:30:27 +0530246}