Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +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.translator.GeneratedFileType; |
| 20 | import org.onosproject.yangutils.utils.UtilConstants; |
| 21 | |
| 22 | /** |
| 23 | * Generates class definition for generated files. |
| 24 | */ |
| 25 | public final class ClassDefinitionGenerator { |
| 26 | |
| 27 | /** |
| 28 | * Default constructor. |
| 29 | */ |
| 30 | private ClassDefinitionGenerator() { |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Generate class definition for specific classes. |
| 35 | * |
| 36 | * @param genFileTypes generated file type |
| 37 | * @param yangName class name |
| 38 | * @return class definition |
| 39 | */ |
| 40 | public static String generateClassDefinition(GeneratedFileType genFileTypes, String yangName) { |
| 41 | |
| 42 | /** |
| 43 | * based on the file type and the YANG name of the file, generate |
| 44 | * the class / interface definition start. |
| 45 | */ |
| 46 | if (genFileTypes.equals(GeneratedFileType.INTERFACE)) { |
| 47 | |
| 48 | return getInterfaceDefinition(yangName); |
| 49 | } else if (genFileTypes.equals(GeneratedFileType.BUILDER_CLASS)) { |
| 50 | |
| 51 | return getBuilderClassDefinition(yangName); |
| 52 | } else if (genFileTypes.equals(GeneratedFileType.IMPL)) { |
| 53 | |
| 54 | return getImplClassDefinition(yangName); |
| 55 | } else if (genFileTypes.equals(GeneratedFileType.BUILDER_INTERFACE)) { |
| 56 | |
| 57 | return getBuilderInterfaceDefinition(); |
| 58 | } |
| 59 | return null; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Returns interface file class definition. |
| 64 | * |
| 65 | * @param yangName file name |
| 66 | * @return definition |
| 67 | */ |
| 68 | private static String getInterfaceDefinition(String yangName) { |
| 69 | |
| 70 | return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.INTERFACE + UtilConstants.SPACE + yangName |
| 71 | + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Returns builder interface file class definition. |
| 76 | * |
| 77 | * @return definition |
| 78 | */ |
| 79 | private static String getBuilderInterfaceDefinition() { |
| 80 | return UtilConstants.INTERFACE + UtilConstants.SPACE + UtilConstants.BUILDER + UtilConstants.SPACE |
| 81 | + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Returns builder file class definition. |
| 86 | * |
| 87 | * @param yangName file name |
| 88 | * @return definition |
| 89 | */ |
| 90 | private static String getBuilderClassDefinition(String yangName) { |
| 91 | |
| 92 | return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.CLASS + UtilConstants.SPACE + yangName |
| 93 | + UtilConstants.BUILDER + UtilConstants.SPACE + UtilConstants.IMPLEMENTS + UtilConstants.SPACE |
| 94 | + yangName + UtilConstants.PERIOD + UtilConstants.BUILDER + UtilConstants.SPACE |
| 95 | + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Returns impl file class definition. |
| 100 | * |
| 101 | * @param yangName file name |
| 102 | * @return definition |
| 103 | */ |
| 104 | private static String getImplClassDefinition(String yangName) { |
| 105 | |
| 106 | return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.FINAL + UtilConstants.SPACE |
| 107 | + UtilConstants.CLASS + UtilConstants.SPACE + yangName + UtilConstants.IMPL + UtilConstants.SPACE |
| 108 | + UtilConstants.IMPLEMENTS + UtilConstants.SPACE + yangName + UtilConstants.OPEN_CURLY_BRACKET |
| 109 | + UtilConstants.SPACE + UtilConstants.NEW_LINE; |
| 110 | } |
| 111 | |
| 112 | } |