blob: 89ff0c999354f471a38bbeb336a340b8f361b706 [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 Se4b9b0c2016-04-30 21:09:15 +053019
Vinod Kumar S38046502016-03-23 15:30:27 +053020import org.onosproject.yangutils.datamodel.YangBelongsTo;
21import org.onosproject.yangutils.datamodel.YangSubModule;
Bharat saraswal6ef0b762016-04-05 12:45:45 +053022import org.onosproject.yangutils.translator.exception.TranslatorException;
Vinod Kumar S38046502016-03-23 15:30:27 +053023import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
24import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
Vinod Kumar S38046502016-03-23 15:30:27 +053025import 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
Gaurav Agrawal56527662016-04-20 15:49:17 +053029import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_MANAGER_WITH_RPC;
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 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053035public class YangJavaSubModule
36 extends YangSubModule
37 implements JavaCodeGeneratorInfo, JavaCodeGenerator {
Vinod Kumar S38046502016-03-23 15:30:27 +053038
39 /**
40 * Contains the information of the java file being generated.
41 */
42 private JavaFileInfo javaFileInfo;
43
44 /**
Vinod Kumar S38046502016-03-23 15:30:27 +053045 * File handle to maintain temporary java code fragments as per the code
46 * snippet types.
47 */
48 private TempJavaCodeFragmentFiles tempFileHandle;
49
50 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053051 * Creates YANG java sub module object.
Vinod Kumar S38046502016-03-23 15:30:27 +053052 */
53 public YangJavaSubModule() {
54 super();
55 setJavaFileInfo(new JavaFileInfo());
Gaurav Agrawal56527662016-04-20 15:49:17 +053056 getJavaFileInfo().setGeneratedFileTypes(GENERATE_MANAGER_WITH_RPC);
Vinod Kumar S38046502016-03-23 15:30:27 +053057 }
58
59 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053060 * Returns the generated java file information.
Vinod Kumar S38046502016-03-23 15:30:27 +053061 *
62 * @return generated java file information
63 */
64 @Override
65 public JavaFileInfo getJavaFileInfo() {
66 if (javaFileInfo == null) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +053067 throw new TranslatorException("Missing java info in java datamodel node");
Vinod Kumar S38046502016-03-23 15:30:27 +053068 }
69 return javaFileInfo;
70 }
71
72 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053073 * Sets the java file info object.
Vinod Kumar S38046502016-03-23 15:30:27 +053074 *
75 * @param javaInfo java file info object
76 */
77 @Override
78 public void setJavaFileInfo(JavaFileInfo javaInfo) {
79 javaFileInfo = javaInfo;
80 }
81
82 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053083 * Returns the temporary file handle.
Vinod Kumar S38046502016-03-23 15:30:27 +053084 *
85 * @return temporary file handle
86 */
87 @Override
88 public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
Vinod Kumar S38046502016-03-23 15:30:27 +053089 return tempFileHandle;
90 }
91
92 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053093 * Sets temporary file handle.
Vinod Kumar S38046502016-03-23 15:30:27 +053094 *
95 * @param fileHandle temporary file handle
96 */
97 @Override
98 public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
99 tempFileHandle = fileHandle;
100 }
101
102 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530103 * Returns the name space of the module to which the sub module belongs to.
Vinod Kumar S38046502016-03-23 15:30:27 +0530104 *
105 * @param belongsToInfo Information of the module to which the sub module
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530106 * belongs
Vinod Kumar S38046502016-03-23 15:30:27 +0530107 * @return the name space string of the module.
108 */
109 private String getNameSpaceFromModule(YangBelongsTo belongsToInfo) {
110 // TODO Auto-generated method stub
111 return "";
112 }
113
114 /**
Gaurav Agrawal56527662016-04-20 15:49:17 +0530115 * Prepares the information for java code generation corresponding to YANG
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530116 * submodule info.
Vinod Kumar S38046502016-03-23 15:30:27 +0530117 *
janani bde4ffab2016-04-15 16:18:30 +0530118 * @param yangPlugin YANG plugin config
Vinod Kumar S38046502016-03-23 15:30:27 +0530119 * @throws IOException IO operation fail
120 */
121 @Override
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530122 public void generateCodeEntry(YangPluginConfig yangPlugin)
123 throws IOException {
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530124 String subModulePkg = getRootPackage(getVersion(), getNameSpaceFromModule(getBelongsTo()),
125 getRevision().getRevDate());
janani bde4ffab2016-04-15 16:18:30 +0530126 YangJavaModelUtils.generateCodeOfRootNode(this, yangPlugin, subModulePkg);
Vinod Kumar S38046502016-03-23 15:30:27 +0530127 }
128
129 /**
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530130 * Creates a java file using the YANG submodule info.
Vinod Kumar S38046502016-03-23 15:30:27 +0530131 */
132 @Override
133 public void generateCodeExit() {
134 // TODO Auto-generated method stub
Vinod Kumar S38046502016-03-23 15:30:27 +0530135 }
136}