blob: f2d2ada4e117becdafca92bf2079df9b2d0c93eb [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
Bharat saraswalcad0e652016-05-26 23:48:38 +053018import java.io.IOException;
19
Vinod Kumar S38046502016-03-23 15:30:27 +053020import org.onosproject.yangutils.datamodel.YangUses;
Bharat saraswalcad0e652016-05-26 23:48:38 +053021import org.onosproject.yangutils.translator.exception.TranslatorException;
22import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
23import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
24import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
25import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
26
27import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
28import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile;
Vinod Kumar S38046502016-03-23 15:30:27 +053029
Vinod Kumar S38046502016-03-23 15:30:27 +053030/**
Bharat saraswald9822e92016-04-05 15:13:44 +053031 * Represents uses 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 YangJavaUses
Bharat saraswalcad0e652016-05-26 23:48:38 +053034 extends YangUses implements JavaCodeGeneratorInfo, JavaCodeGenerator {
35
36
37 /**
38 * Contains the information of the java file being generated.
39 */
40 private JavaFileInfo javaFileInfo;
41
42 /**
43 * File handle to maintain temporary java code fragments as per the code
44 * snippet types.
45 */
46 private TempJavaCodeFragmentFiles tempFileHandle;
Vinod Kumar S38046502016-03-23 15:30:27 +053047
48 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053049 * Creates YANG java uses object.
Vinod Kumar S38046502016-03-23 15:30:27 +053050 */
51 public YangJavaUses() {
52 super();
Bharat saraswalcad0e652016-05-26 23:48:38 +053053 setJavaFileInfo(new JavaFileInfo());
54 getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
Vinod Kumar S38046502016-03-23 15:30:27 +053055 }
Bharat saraswalcad0e652016-05-26 23:48:38 +053056
57 /**
58 * Returns the generated java file information.
59 *
60 * @return generated java file information
61 */
62 @Override
63 public JavaFileInfo getJavaFileInfo() {
64 if (javaFileInfo == null) {
65 throw new TranslatorException("Missing java info in java datamodel node");
66 }
67 return javaFileInfo;
68 }
69
70 /**
71 * Sets the java file info object.
72 *
73 * @param javaInfo java file info object
74 */
75 @Override
76 public void setJavaFileInfo(JavaFileInfo javaInfo) {
77 javaFileInfo = javaInfo;
78 }
79
80 /**
81 * Returns the temporary file handle.
82 *
83 * @return temporary file handle
84 */
85 @Override
86 public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
87 return tempFileHandle;
88 }
89
90 /**
91 * Sets temporary file handle.
92 *
93 * @param fileHandle temporary file handle
94 */
95 @Override
96 public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
97 tempFileHandle = fileHandle;
98 }
99
100 /**
101 * Prepare the information for java code generation corresponding to YANG
102 * uses info.
103 *
104 * @param yangPlugin YANG plugin config
105 * @throws TranslatorException translator operation fail
106 */
107 @Override
108 public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
109 try {
110 addCurNodeInfoInParentTempFile(this, false, yangPlugin);
111 } catch (IOException e) {
112 throw new TranslatorException(
113 "Failed to prepare generate code entry for container node " + this.getName());
114 }
115 }
116
117 /**
118 * Create a java file using the YANG uses info.
119 *
120 * @throws TranslatorException translator operation fail
121 */
122 @Override
123 public void generateCodeExit() throws TranslatorException {
124 // no code generation will be done for uses.
125 }
126
Vinod Kumar S38046502016-03-23 15:30:27 +0530127}