blob: 177fad8d2c461c968aebe134b27bf39a3d2e8d68 [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;
Vinod Kumar S38046502016-03-23 15:30:27 +053027
28import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
Vinod Kumar S38046502016-03-23 15:30:27 +053029import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
Vinod Kumar S38046502016-03-23 15:30:27 +053030
31/**
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053032 * Represents sub module information extended to support java code generation.
Vinod Kumar S38046502016-03-23 15:30:27 +053033 */
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053034public class YangJavaSubModule extends YangSubModule implements JavaCodeGeneratorInfo, JavaCodeGenerator {
Vinod Kumar S38046502016-03-23 15:30:27 +053035
36 /**
37 * Contains the information of the java file being generated.
38 */
39 private JavaFileInfo javaFileInfo;
40
41 /**
42 * Contains information of the imports to be inserted in the java file
43 * generated.
44 */
45 private JavaImportData javaImportData;
46
47 /**
48 * File handle to maintain temporary java code fragments as per the code
49 * snippet types.
50 */
51 private TempJavaCodeFragmentFiles tempFileHandle;
52
53 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053054 * Creates YANG java sub module object.
Vinod Kumar S38046502016-03-23 15:30:27 +053055 */
56 public YangJavaSubModule() {
57 super();
58 setJavaFileInfo(new JavaFileInfo());
59 setJavaImportData(new JavaImportData());
60 getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
61 }
62
63 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053064 * Returns the generated java file information.
Vinod Kumar S38046502016-03-23 15:30:27 +053065 *
66 * @return generated java file information
67 */
68 @Override
69 public JavaFileInfo getJavaFileInfo() {
70 if (javaFileInfo == null) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +053071 throw new TranslatorException("Missing java info in java datamodel node");
Vinod Kumar S38046502016-03-23 15:30:27 +053072 }
73 return javaFileInfo;
74 }
75
76 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053077 * Sets the java file info object.
Vinod Kumar S38046502016-03-23 15:30:27 +053078 *
79 * @param javaInfo java file info object
80 */
81 @Override
82 public void setJavaFileInfo(JavaFileInfo javaInfo) {
83 javaFileInfo = javaInfo;
84 }
85
86 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053087 * Returns the data of java imports to be included in generated file.
Vinod Kumar S38046502016-03-23 15:30:27 +053088 *
89 * @return data of java imports to be included in generated file
90 */
91 @Override
92 public JavaImportData getJavaImportData() {
93 return javaImportData;
94 }
95
96 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053097 * Sets the data of java imports to be included in generated file.
Vinod Kumar S38046502016-03-23 15:30:27 +053098 *
99 * @param javaImportData data of java imports to be included in generated
100 * file
101 */
102 @Override
103 public void setJavaImportData(JavaImportData javaImportData) {
104 this.javaImportData = javaImportData;
105 }
106
107 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530108 * Returns the temporary file handle.
Vinod Kumar S38046502016-03-23 15:30:27 +0530109 *
110 * @return temporary file handle
111 */
112 @Override
113 public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530114 return tempFileHandle;
115 }
116
117 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530118 * Sets temporary file handle.
Vinod Kumar S38046502016-03-23 15:30:27 +0530119 *
120 * @param fileHandle temporary file handle
121 */
122 @Override
123 public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
124 tempFileHandle = fileHandle;
125 }
126
127 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530128 * Returns the name space of the module to which the sub module belongs to.
Vinod Kumar S38046502016-03-23 15:30:27 +0530129 *
130 * @param belongsToInfo Information of the module to which the sub module
131 * belongs
132 * @return the name space string of the module.
133 */
134 private String getNameSpaceFromModule(YangBelongsTo belongsToInfo) {
135 // TODO Auto-generated method stub
136 return "";
137 }
138
139 /**
140 * Prepare the information for java code generation corresponding to YANG
141 * container info.
142 *
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530143 * @param baseCodeGenDir code generation directory
Vinod Kumar S38046502016-03-23 15:30:27 +0530144 * @throws IOException IO operation fail
145 */
146 @Override
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530147 public void generateCodeEntry(String baseCodeGenDir) throws IOException {
148 String subModulePkg = getRootPackage(getVersion(), getNameSpaceFromModule(getBelongsTo()),
149 getRevision().getRevDate());
150 YangJavaModelUtils.generateCodeOfRootNode(this, baseCodeGenDir, subModulePkg);
Vinod Kumar S38046502016-03-23 15:30:27 +0530151 }
152
153 /**
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530154 * Creates a java file using the YANG grouping info.
Vinod Kumar S38046502016-03-23 15:30:27 +0530155 */
156 @Override
157 public void generateCodeExit() {
158 // TODO Auto-generated method stub
Vinod Kumar S38046502016-03-23 15:30:27 +0530159 }
160}