blob: 41a31173f987a5c4cd146b87a743394e17ecd744 [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 saraswal870c56f2016-02-20 21:57:16 +053059 }
60 return null;
61 }
62
63 /**
64 * Returns interface file class definition.
65 *
66 * @param yangName file name
67 * @return definition
68 */
69 private static String getInterfaceDefinition(String yangName) {
70
71 return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.INTERFACE + UtilConstants.SPACE + yangName
72 + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE;
73 }
74
75 /**
76 * Returns builder interface file class definition.
77 *
Vinod Kumar Sc4216002016-03-03 19:55:30 +053078 * @param yangName java class name, corresponding to which the builder class
79 * is being generated
Bharat saraswal870c56f2016-02-20 21:57:16 +053080 * @return definition
81 */
Vinod Kumar Sc4216002016-03-03 19:55:30 +053082 private static String getBuilderInterfaceDefinition(String yangName) {
83 return UtilConstants.INTERFACE + UtilConstants.SPACE + yangName + UtilConstants.BUILDER + UtilConstants.SPACE
Bharat saraswal870c56f2016-02-20 21:57:16 +053084 + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE;
85 }
86
87 /**
88 * Returns builder file class definition.
89 *
90 * @param yangName file name
91 * @return definition
92 */
93 private static String getBuilderClassDefinition(String yangName) {
94
95 return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.CLASS + UtilConstants.SPACE + yangName
96 + UtilConstants.BUILDER + UtilConstants.SPACE + UtilConstants.IMPLEMENTS + UtilConstants.SPACE
97 + yangName + UtilConstants.PERIOD + UtilConstants.BUILDER + UtilConstants.SPACE
98 + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE;
99 }
100
101 /**
102 * Returns impl file class definition.
103 *
104 * @param yangName file name
105 * @return definition
106 */
107 private static String getImplClassDefinition(String yangName) {
108
109 return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.FINAL + UtilConstants.SPACE
110 + UtilConstants.CLASS + UtilConstants.SPACE + yangName + UtilConstants.IMPL + UtilConstants.SPACE
111 + UtilConstants.IMPLEMENTS + UtilConstants.SPACE + yangName + UtilConstants.OPEN_CURLY_BRACKET
112 + UtilConstants.SPACE + UtilConstants.NEW_LINE;
113 }
114
115}