blob: dbe006c6d6b2b256f1c83385f496d45bc610106e [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;
Bharat saraswalcc1cdab2016-04-16 02:28:25 +053019
Vinod Kumar S38046502016-03-23 15:30:27 +053020import org.onosproject.yangutils.datamodel.YangAugment;
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;
Vinod Kumar S38046502016-03-23 15:30:27 +053024import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
janani bde4ffab2016-04-15 16:18:30 +053025import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
Vinod Kumar S38046502016-03-23 15:30:27 +053026
27import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053028import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfAugmentableNode;
Vinod Kumar S38046502016-03-23 15:30:27 +053029
30/**
Bharat saraswald9822e92016-04-05 15:13:44 +053031 * Represents augment information extended to support java code generation.
Vinod Kumar S38046502016-03-23 15:30:27 +053032 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053033public class YangJavaAugment
34 extends YangAugment
35 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 /**
Vinod Kumar S38046502016-03-23 15:30:27 +053043 * File handle to maintain temporary java code fragments as per the code
44 * snippet types.
45 */
46 private TempJavaCodeFragmentFiles tempFileHandle;
47
48 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053049 * Creates a YANG java augment object.
Vinod Kumar S38046502016-03-23 15:30:27 +053050 */
51 public YangJavaAugment() {
52 super();
53 setJavaFileInfo(new JavaFileInfo());
Vinod Kumar S38046502016-03-23 15:30:27 +053054 getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
55 }
56
57 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053058 * Returns the generated java file information.
Vinod Kumar S38046502016-03-23 15:30:27 +053059 *
60 * @return generated java file information
61 */
62 @Override
63 public JavaFileInfo getJavaFileInfo() {
64
65 if (javaFileInfo == null) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +053066 throw new TranslatorException("Missing java info in java datamodel node");
Vinod Kumar S38046502016-03-23 15:30:27 +053067 }
68 return javaFileInfo;
69 }
70
71 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053072 * Sets the java file info object.
Vinod Kumar S38046502016-03-23 15:30:27 +053073 *
74 * @param javaInfo java file info object
75 */
76 @Override
77 public void setJavaFileInfo(JavaFileInfo javaInfo) {
Vinod Kumar S38046502016-03-23 15:30:27 +053078 javaFileInfo = javaInfo;
79 }
80
81 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053082 * Returns the temporary file handle.
Vinod Kumar S38046502016-03-23 15:30:27 +053083 *
84 * @return temporary file handle
85 */
86 @Override
87 public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
Vinod Kumar S38046502016-03-23 15:30:27 +053088 return tempFileHandle;
89 }
90
91 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053092 * Sets temporary file handle.
Vinod Kumar S38046502016-03-23 15:30:27 +053093 *
94 * @param fileHandle temporary file handle
95 */
96 @Override
97 public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
Vinod Kumar S38046502016-03-23 15:30:27 +053098 tempFileHandle = fileHandle;
99 }
100
101 /**
102 * Prepare the information for java code generation corresponding to YANG
103 * augment info.
104 *
janani bde4ffab2016-04-15 16:18:30 +0530105 * @param yangPlugin YANG plugin config
Vinod Kumar S38046502016-03-23 15:30:27 +0530106 * @throws IOException IO operation fail
107 */
108 @Override
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530109 public void generateCodeEntry(YangPluginConfig yangPlugin)
110 throws IOException {
111 generateCodeOfAugmentableNode(this, yangPlugin);
Vinod Kumar S38046502016-03-23 15:30:27 +0530112 }
113
114 /**
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530115 * Create a java file using the YANG augment info.
116 *
117 * @throws IOException when failed to do IO operations
Vinod Kumar S38046502016-03-23 15:30:27 +0530118 */
119 @Override
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530120 public void generateCodeExit()
121 throws IOException {
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530122 getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
Vinod Kumar S38046502016-03-23 15:30:27 +0530123 }
124}