Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.yangutils.translator.tojava; |
| 18 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 19 | import org.onosproject.yangutils.datamodel.YangType; |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 20 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 21 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 22 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 23 | * Represents the attribute info corresponding to class/interface generated. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 24 | */ |
| 25 | public 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 S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 40 | private boolean isListAttr; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * If the added attribute has to be accessed in a fully qualified manner. |
| 44 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 45 | private boolean isQualifiedName; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * The class info will be used to set the attribute type and package info |
| 49 | * will be use for qualified name. |
| 50 | */ |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 51 | private JavaQualifiedTypeInfoTranslator importInfo; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 52 | |
| 53 | /** |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 54 | * If conflict occurs. |
| 55 | */ |
| 56 | private boolean isIntConflict; |
| 57 | |
| 58 | /** |
| 59 | * If conflict occurs. |
| 60 | */ |
| 61 | private boolean isLongConflict; |
| 62 | |
| 63 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 64 | * Creates a java attribute info object. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 65 | */ |
| 66 | private JavaAttributeInfo() { |
| 67 | } |
| 68 | |
| 69 | /** |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 70 | * Creates object of java attribute info. |
Bharat saraswal | c34b944 | 2016-03-28 15:50:13 +0530 | [diff] [blame] | 71 | * |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 72 | * @param attrType YANG type |
| 73 | * @param name attribute name |
| 74 | * @param isListAttr is list attribute |
Bharat saraswal | c34b944 | 2016-03-28 15:50:13 +0530 | [diff] [blame] | 75 | * @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 saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 85 | * Returns the data type info of attribute. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 86 | * |
| 87 | * @return the data type info of attribute |
| 88 | */ |
| 89 | public YangType<?> getAttributeType() { |
| 90 | |
| 91 | if (attrType == null) { |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 92 | throw new TranslatorException("Expected java attribute type is null"); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 93 | } |
| 94 | return attrType; |
| 95 | } |
| 96 | |
| 97 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 98 | * Sets the data type info of attribute. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 99 | * |
| 100 | * @param type the data type info of attribute |
| 101 | */ |
| 102 | public void setAttributeType(YangType<?> type) { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 103 | attrType = type; |
| 104 | } |
| 105 | |
| 106 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 107 | * Returns name of the attribute. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 108 | * |
| 109 | * @return name of the attribute |
| 110 | */ |
| 111 | public String getAttributeName() { |
| 112 | |
| 113 | if (name == null) { |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 114 | throw new TranslatorException("Expected java attribute name is null"); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 115 | } |
| 116 | return name; |
| 117 | } |
| 118 | |
| 119 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 120 | * Sets name of the attribute. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 121 | * |
| 122 | * @param attrName name of the attribute |
| 123 | */ |
| 124 | public void setAttributeName(String attrName) { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 125 | name = attrName; |
| 126 | } |
| 127 | |
| 128 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 129 | * Returns if the added attribute is a list of info. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 130 | * |
| 131 | * @return the if the added attribute is a list of info |
| 132 | */ |
| 133 | public boolean isListAttr() { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 134 | return isListAttr; |
| 135 | } |
| 136 | |
| 137 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 138 | * Sets if the added attribute is a list of info. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 139 | * |
| 140 | * @param isList if the added attribute is a list of info |
| 141 | */ |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 142 | private void setListAttr(boolean isList) { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 143 | isListAttr = isList; |
| 144 | } |
| 145 | |
| 146 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 147 | * Returns if the added attribute has to be accessed in a fully qualified |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 148 | * manner. |
| 149 | * |
| 150 | * @return the if the added attribute has to be accessed in a fully |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 151 | * qualified manner. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 152 | */ |
| 153 | public boolean isQualifiedName() { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 154 | return isQualifiedName; |
| 155 | } |
| 156 | |
| 157 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 158 | * Sets if the added attribute has to be accessed in a fully qualified |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 159 | * manner. |
| 160 | * |
| 161 | * @param isQualified if the added attribute has to be accessed in a fully |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 162 | * qualified manner |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 163 | */ |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 164 | private void setIsQualifiedAccess(boolean isQualified) { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 165 | isQualifiedName = isQualified; |
| 166 | } |
| 167 | |
| 168 | /** |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 169 | * Returns the import info for the attribute type. It will be null, if the type |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 170 | * is basic built-in java type. |
| 171 | * |
| 172 | * @return import info |
| 173 | */ |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 174 | public JavaQualifiedTypeInfoTranslator getImportInfo() { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 175 | return importInfo; |
| 176 | } |
| 177 | |
| 178 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 179 | * Sets the import info for the attribute type. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 180 | * |
| 181 | * @param importInfo import info for the attribute type |
| 182 | */ |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 183 | public void setImportInfo(JavaQualifiedTypeInfoTranslator importInfo) { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 184 | this.importInfo = importInfo; |
| 185 | } |
| 186 | |
| 187 | /** |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 188 | * Returns true if conflict between int and uInt. |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 189 | * |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 190 | * @return true if conflict between int and uInt |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 191 | */ |
| 192 | public boolean isIntConflict() { |
| 193 | return isIntConflict; |
| 194 | } |
| 195 | |
| 196 | /** |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 197 | * Sets true if conflict between int and uInt. |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 198 | * |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 199 | * @param intConflict true if conflict between int and uInt |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 200 | */ |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 201 | void setIntConflict(boolean intConflict) { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 202 | isIntConflict = intConflict; |
| 203 | } |
| 204 | |
| 205 | /** |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 206 | * Returns true if conflict between long and uLong. |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 207 | * |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 208 | * @return true if conflict between long and uLong |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 209 | */ |
| 210 | public boolean isLongConflict() { |
| 211 | return isLongConflict; |
| 212 | } |
| 213 | |
| 214 | /** |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 215 | * Sets true if conflict between long and uLong. |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 216 | * |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 217 | * @param longConflict true if conflict between long and uLong |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 218 | */ |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 219 | void setLongConflict(boolean longConflict) { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 220 | isLongConflict = longConflict; |
| 221 | } |
| 222 | |
| 223 | /** |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 224 | * Returns java attribute info. |
| 225 | * |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 226 | * @param importInfo java qualified type info |
| 227 | * @param attributeName attribute name |
| 228 | * @param attributeType attribute type |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 229 | * @param isQualifiedAccess is the attribute a qualified access |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 230 | * @param isListAttribute is list attribute |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 231 | * @return java attribute info. |
| 232 | */ |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 233 | public static JavaAttributeInfo getAttributeInfoForTheData(JavaQualifiedTypeInfoTranslator importInfo, |
| 234 | String attributeName, |
| 235 | YangType<?> attributeType, boolean isQualifiedAccess, |
| 236 | boolean isListAttribute) { |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 237 | |
| 238 | JavaAttributeInfo newAttr = new JavaAttributeInfo(); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 239 | newAttr.setImportInfo(importInfo); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 240 | newAttr.setAttributeName(attributeName); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 241 | newAttr.setAttributeType(attributeType); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 242 | newAttr.setIsQualifiedAccess(isQualifiedAccess); |
| 243 | newAttr.setListAttr(isListAttribute); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 244 | |
| 245 | return newAttr; |
| 246 | } |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 247 | } |