Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.yangutils.translator.tojava.utils; |
| 18 | |
| 19 | import org.onosproject.yangutils.datamodel.YangDataTypes; |
| 20 | import org.onosproject.yangutils.datamodel.YangType; |
| 21 | import org.onosproject.yangutils.translator.tojava.AttributeInfo; |
| 22 | import org.onosproject.yangutils.utils.UtilConstants; |
| 23 | |
| 24 | /** |
| 25 | * Provides java data types corresponding to YANG type. |
| 26 | */ |
| 27 | public final class AttributesJavaDataType { |
| 28 | |
| 29 | /** |
| 30 | * Default constructor. |
| 31 | */ |
| 32 | private AttributesJavaDataType() { |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Returns YANG type. |
| 37 | * |
| 38 | * @param yangType YANG type |
| 39 | * @return YANG type |
| 40 | */ |
| 41 | public static YangType<?> getJavaDataType(YangType<?> yangType) { |
| 42 | yangType.setDataTypeName(yangType.getDataTypeName().replace("\"", "")); |
| 43 | if (yangType.getDataType() != null) { |
| 44 | yangType.setDataTypeName(parseYangDataType(yangType.getDataType())); |
| 45 | } |
| 46 | return yangType; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Returns list string as attribute name when attribute is a list. |
| 51 | * |
| 52 | * @param attr attribute info. |
| 53 | * @return list attribute |
| 54 | */ |
| 55 | @SuppressWarnings("rawtypes") |
| 56 | public static YangType<?> getListString(AttributeInfo attr) { |
| 57 | String listString = JavaCodeSnippetGen.getListAttribute(attr.getAttributeType().getDataTypeName()); |
| 58 | YangType<?> type = new YangType(); |
| 59 | type.setDataTypeName(listString); |
| 60 | attr.setAttributeType(type); |
| 61 | return type; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Parses YANG data type and returns corresponding java data type. |
| 66 | * |
| 67 | * @param type YANG data type |
| 68 | * @return java data type |
| 69 | */ |
| 70 | private static String parseYangDataType(YangDataTypes type) { |
| 71 | if (type.equals(YangDataTypes.INT8)) { |
| 72 | return UtilConstants.BYTE; |
| 73 | } else if (type.equals(YangDataTypes.INT16)) { |
| 74 | return UtilConstants.SHORT; |
| 75 | } else if (type.equals(YangDataTypes.INT32)) { |
| 76 | return UtilConstants.INT; |
| 77 | } else if (type.equals(YangDataTypes.INT64)) { |
| 78 | return UtilConstants.LONG; |
| 79 | } else if (type.equals(YangDataTypes.UINT8)) { |
| 80 | return UtilConstants.SHORT; |
| 81 | } else if (type.equals(YangDataTypes.UINT16)) { |
| 82 | return UtilConstants.INT; |
| 83 | } else if (type.equals(YangDataTypes.UINT32)) { |
| 84 | return UtilConstants.LONG; |
| 85 | } else if (type.equals(YangDataTypes.UINT64)) { |
| 86 | //TODO: BIGINTEGER. |
| 87 | } else if (type.equals(YangDataTypes.DECIMAL64)) { |
| 88 | //TODO: DECIMAL64. |
| 89 | } else if (type.equals(YangDataTypes.STRING)) { |
| 90 | return UtilConstants.STRING; |
| 91 | } else if (type.equals(YangDataTypes.BOOLEAN)) { |
| 92 | return UtilConstants.BOOLEAN; |
| 93 | } else if (type.equals(YangDataTypes.ENUMERATION)) { |
| 94 | //TODO: ENUMERATION. |
| 95 | } else if (type.equals(YangDataTypes.BITS)) { |
| 96 | //TODO:BITS |
| 97 | } else if (type.equals(YangDataTypes.BINARY)) { |
| 98 | //TODO:BINARY |
| 99 | } else if (type.equals(YangDataTypes.LEAFREF)) { |
| 100 | //TODO:LEAFREF |
| 101 | } else if (type.equals(YangDataTypes.IDENTITYREF)) { |
| 102 | //TODO:IDENTITYREF |
| 103 | } else if (type.equals(YangDataTypes.EMPTY)) { |
| 104 | //TODO:EMPTY |
| 105 | } else if (type.equals(YangDataTypes.UNION)) { |
| 106 | //TODO:UNION |
| 107 | } else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) { |
| 108 | //TODO:INSTANCE_IDENTIFIER |
| 109 | } else if (type.equals(YangDataTypes.DERIVED)) { |
| 110 | //TODO:DERIVED |
| 111 | } |
| 112 | return null; |
| 113 | } |
| 114 | } |