blob: 6dee3af5a56dbf2f2c8d375fdecf131d17fc715a [file] [log] [blame]
Vinod Kumar S38046502016-03-23 15:30:27 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Vinod Kumar S38046502016-03-23 15:30:27 +05303 *
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 */
16package org.onosproject.yangutils.translator.tojava.javamodel;
17
18import java.io.IOException;
Vinod Kumar S38046502016-03-23 15:30:27 +053019import org.onosproject.yangutils.datamodel.YangBelongsTo;
20import org.onosproject.yangutils.datamodel.YangSubModule;
Bharat saraswal6ef0b762016-04-05 12:45:45 +053021import org.onosproject.yangutils.translator.exception.TranslatorException;
Vinod Kumar S38046502016-03-23 15:30:27 +053022import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
23import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
24import org.onosproject.yangutils.translator.tojava.JavaImportData;
25import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053026import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils;
janani bde4ffab2016-04-15 16:18:30 +053027import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
Vinod Kumar S38046502016-03-23 15:30:27 +053028
29import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
Vinod Kumar S38046502016-03-23 15:30:27 +053030import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
Vinod Kumar S38046502016-03-23 15:30:27 +053031
32/**
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053033 * Represents sub module information extended to support java code generation.
Vinod Kumar S38046502016-03-23 15:30:27 +053034 */
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053035public class YangJavaSubModule extends YangSubModule implements JavaCodeGeneratorInfo, JavaCodeGenerator {
Vinod Kumar S38046502016-03-23 15:30:27 +053036
37 /**
38 * Contains the information of the java file being generated.
39 */
40 private JavaFileInfo javaFileInfo;
41
42 /**
43 * Contains information of the imports to be inserted in the java file
44 * generated.
45 */
46 private JavaImportData javaImportData;
47
48 /**
49 * File handle to maintain temporary java code fragments as per the code
50 * snippet types.
51 */
52 private TempJavaCodeFragmentFiles tempFileHandle;
53
54 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053055 * Creates YANG java sub module object.
Vinod Kumar S38046502016-03-23 15:30:27 +053056 */
57 public YangJavaSubModule() {
58 super();
59 setJavaFileInfo(new JavaFileInfo());
60 setJavaImportData(new JavaImportData());
61 getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
62 }
63
64 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053065 * Returns the generated java file information.
Vinod Kumar S38046502016-03-23 15:30:27 +053066 *
67 * @return generated java file information
68 */
69 @Override
70 public JavaFileInfo getJavaFileInfo() {
71 if (javaFileInfo == null) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +053072 throw new TranslatorException("Missing java info in java datamodel node");
Vinod Kumar S38046502016-03-23 15:30:27 +053073 }
74 return javaFileInfo;
75 }
76
77 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053078 * Sets the java file info object.
Vinod Kumar S38046502016-03-23 15:30:27 +053079 *
80 * @param javaInfo java file info object
81 */
82 @Override
83 public void setJavaFileInfo(JavaFileInfo javaInfo) {
84 javaFileInfo = javaInfo;
85 }
86
87 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053088 * Returns the data of java imports to be included in generated file.
Vinod Kumar S38046502016-03-23 15:30:27 +053089 *
90 * @return data of java imports to be included in generated file
91 */
92 @Override
93 public JavaImportData getJavaImportData() {
94 return javaImportData;
95 }
96
97 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053098 * Sets the data of java imports to be included in generated file.
Vinod Kumar S38046502016-03-23 15:30:27 +053099 *
100 * @param javaImportData data of java imports to be included in generated
101 * file
102 */
103 @Override
104 public void setJavaImportData(JavaImportData javaImportData) {
105 this.javaImportData = javaImportData;
106 }
107
108 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530109 * Returns the temporary file handle.
Vinod Kumar S38046502016-03-23 15:30:27 +0530110 *
111 * @return temporary file handle
112 */
113 @Override
114 public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530115 return tempFileHandle;
116 }
117
118 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530119 * Sets temporary file handle.
Vinod Kumar S38046502016-03-23 15:30:27 +0530120 *
121 * @param fileHandle temporary file handle
122 */
123 @Override
124 public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
125 tempFileHandle = fileHandle;
126 }
127
128 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530129 * Returns the name space of the module to which the sub module belongs to.
Vinod Kumar S38046502016-03-23 15:30:27 +0530130 *
131 * @param belongsToInfo Information of the module to which the sub module
132 * belongs
133 * @return the name space string of the module.
134 */
135 private String getNameSpaceFromModule(YangBelongsTo belongsToInfo) {
136 // TODO Auto-generated method stub
137 return "";
138 }
139
140 /**
141 * Prepare the information for java code generation corresponding to YANG
142 * container info.
143 *
janani bde4ffab2016-04-15 16:18:30 +0530144 * @param yangPlugin YANG plugin config
Vinod Kumar S38046502016-03-23 15:30:27 +0530145 * @throws IOException IO operation fail
146 */
147 @Override
janani bde4ffab2016-04-15 16:18:30 +0530148 public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530149 String subModulePkg = getRootPackage(getVersion(), getNameSpaceFromModule(getBelongsTo()),
150 getRevision().getRevDate());
janani bde4ffab2016-04-15 16:18:30 +0530151 YangJavaModelUtils.generateCodeOfRootNode(this, yangPlugin, subModulePkg);
Vinod Kumar S38046502016-03-23 15:30:27 +0530152 }
153
154 /**
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530155 * Creates a java file using the YANG grouping info.
Vinod Kumar S38046502016-03-23 15:30:27 +0530156 */
157 @Override
158 public void generateCodeExit() {
159 // TODO Auto-generated method stub
Vinod Kumar S38046502016-03-23 15:30:27 +0530160 }
161}