blob: 58a0896b49399f96a4f07a1817be232c3059f345 [file] [log] [blame]
Bharat saraswal870c56f2016-02-20 21:57:16 +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.translator.GeneratedFileType;
20import org.onosproject.yangutils.utils.UtilConstants;
21
22/**
23 * Generates class definition for generated files.
24 */
25public final class ClassDefinitionGenerator {
26
27 /**
28 * Default constructor.
29 */
30 private ClassDefinitionGenerator() {
31 }
32
33 /**
Vinod Kumar Sc4216002016-03-03 19:55:30 +053034 * Based on the file type and the YANG name of the file, generate the class
35 * / interface definition start.
Bharat saraswal870c56f2016-02-20 21:57:16 +053036 *
37 * @param genFileTypes generated file type
38 * @param yangName class name
39 * @return class definition
40 */
Vinod Kumar Sc4216002016-03-03 19:55:30 +053041 public static String generateClassDefinition(int genFileTypes, String yangName) {
Bharat saraswal870c56f2016-02-20 21:57:16 +053042
43 /**
Vinod Kumar Sc4216002016-03-03 19:55:30 +053044 * based on the file type and the YANG name of the file, generate the
45 * class / interface definition start.
Bharat saraswal870c56f2016-02-20 21:57:16 +053046 */
Vinod Kumar Sc4216002016-03-03 19:55:30 +053047 if ((genFileTypes & GeneratedFileType.INTERFACE_MASK) != 0) {
Bharat saraswal870c56f2016-02-20 21:57:16 +053048
49 return getInterfaceDefinition(yangName);
Vinod Kumar Sc4216002016-03-03 19:55:30 +053050 } else if ((genFileTypes & GeneratedFileType.BUILDER_CLASS_MASK) != 0) {
Bharat saraswal870c56f2016-02-20 21:57:16 +053051
52 return getBuilderClassDefinition(yangName);
Vinod Kumar Sc4216002016-03-03 19:55:30 +053053 } else if ((genFileTypes & GeneratedFileType.IMPL_CLASS_MASK) != 0) {
Bharat saraswal870c56f2016-02-20 21:57:16 +053054
55 return getImplClassDefinition(yangName);
Vinod Kumar Sc4216002016-03-03 19:55:30 +053056 } else if ((genFileTypes & GeneratedFileType.BUILDER_INTERFACE_MASK) != 0) {
Bharat saraswal870c56f2016-02-20 21:57:16 +053057
Vinod Kumar Sc4216002016-03-03 19:55:30 +053058 return getBuilderInterfaceDefinition(yangName);
Bharat saraswal2f00b4b2016-03-04 20:08:09 +053059 } else if ((genFileTypes & GeneratedFileType.GENERATE_TYPEDEF_CLASS) != 0) {
60
61 return getTypeDefClassDefinition(yangName);
Bharat saraswal870c56f2016-02-20 21:57:16 +053062 }
63 return null;
64 }
65
66 /**
67 * Returns interface file class definition.
68 *
69 * @param yangName file name
70 * @return definition
71 */
72 private static String getInterfaceDefinition(String yangName) {
73
74 return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.INTERFACE + UtilConstants.SPACE + yangName
75 + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE;
76 }
77
78 /**
79 * Returns builder interface file class definition.
80 *
Vinod Kumar Sc4216002016-03-03 19:55:30 +053081 * @param yangName java class name, corresponding to which the builder class
82 * is being generated
Bharat saraswal870c56f2016-02-20 21:57:16 +053083 * @return definition
84 */
Vinod Kumar Sc4216002016-03-03 19:55:30 +053085 private static String getBuilderInterfaceDefinition(String yangName) {
86 return UtilConstants.INTERFACE + UtilConstants.SPACE + yangName + UtilConstants.BUILDER + UtilConstants.SPACE
Bharat saraswal870c56f2016-02-20 21:57:16 +053087 + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE;
88 }
89
90 /**
91 * Returns builder file class definition.
92 *
93 * @param yangName file name
94 * @return definition
95 */
96 private static String getBuilderClassDefinition(String yangName) {
97
98 return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.CLASS + UtilConstants.SPACE + yangName
99 + UtilConstants.BUILDER + UtilConstants.SPACE + UtilConstants.IMPLEMENTS + UtilConstants.SPACE
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530100 + yangName + UtilConstants.PERIOD + yangName + UtilConstants.BUILDER + UtilConstants.SPACE
Bharat saraswal870c56f2016-02-20 21:57:16 +0530101 + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE;
102 }
103
104 /**
105 * Returns impl file class definition.
106 *
107 * @param yangName file name
108 * @return definition
109 */
110 private static String getImplClassDefinition(String yangName) {
111
112 return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.FINAL + UtilConstants.SPACE
113 + UtilConstants.CLASS + UtilConstants.SPACE + yangName + UtilConstants.IMPL + UtilConstants.SPACE
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530114 + UtilConstants.IMPLEMENTS + UtilConstants.SPACE + yangName + UtilConstants.SPACE
115 + UtilConstants.OPEN_CURLY_BRACKET
Bharat saraswal870c56f2016-02-20 21:57:16 +0530116 + UtilConstants.SPACE + UtilConstants.NEW_LINE;
117 }
118
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530119 /**
120 * Returns typeDef file class definition.
121 *
122 * @param yangName file name
123 * @return definition
124 */
125 private static String getTypeDefClassDefinition(String yangName) {
126
127 return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.FINAL + UtilConstants.SPACE
128 + UtilConstants.CLASS + UtilConstants.SPACE + yangName + UtilConstants.SPACE
129 + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.SPACE + UtilConstants.NEW_LINE;
130 }
131
Bharat saraswal870c56f2016-02-20 21:57:16 +0530132}