blob: fe995003bd3abf9727f668c1fbd47d14f3f39061 [file] [log] [blame]
Bharat saraswald72411a2016-04-19 01:00:16 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
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 */
16
17package org.onosproject.yangutils.translator.tojava.javamodel;
18
19import java.io.IOException;
20
21import org.onosproject.yangutils.datamodel.YangEnumeration;
22import org.onosproject.yangutils.translator.exception.TranslatorException;
23import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
24import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
25import org.onosproject.yangutils.translator.tojava.JavaImportData;
26import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
27import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
28
29import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
30import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfType;
31
32/**
33 * Represents YANG java enumeration information extended to support java code generation.
34 */
35public class YangJavaEnumeration extends YangEnumeration implements JavaCodeGenerator, JavaCodeGeneratorInfo {
36
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 /**
55 * Creates YANG java enumeration object.
56 */
57 public YangJavaEnumeration() {
58 super();
59 setJavaFileInfo(new JavaFileInfo());
60 setJavaImportData(new JavaImportData());
61 getJavaFileInfo().setGeneratedFileTypes(GENERATE_ENUM_CLASS);
62 }
63
64 /**
65 * Returns the generated java file information.
66 *
67 * @return generated java file information
68 */
69 @Override
70 public JavaFileInfo getJavaFileInfo() {
71
72 if (javaFileInfo == null) {
73 throw new TranslatorException("Missing java info in java datamodel node");
74 }
75 return javaFileInfo;
76 }
77
78 /**
79 * Sets the java file info object.
80 *
81 * @param javaInfo java file info object
82 */
83 @Override
84 public void setJavaFileInfo(JavaFileInfo javaInfo) {
85
86 javaFileInfo = javaInfo;
87 }
88
89 /**
90 * Returns the data of java imports to be included in generated file.
91 *
92 * @return data of java imports to be included in generated file
93 */
94 @Override
95 public JavaImportData getJavaImportData() {
96
97 return javaImportData;
98 }
99
100 /**
101 * Sets the data of java imports to be included in generated file.
102 *
103 * @param javaImportData data of java imports to be included in generated
104 * file
105 */
106 @Override
107 public void setJavaImportData(JavaImportData javaImportData) {
108
109 this.javaImportData = javaImportData;
110 }
111
112 /**
113 * Returns the temporary file handle.
114 *
115 * @return temporary file handle
116 */
117 @Override
118 public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
119
120 return tempFileHandle;
121 }
122
123 /**
124 * Sets temporary file handle.
125 *
126 * @param fileHandle temporary file handle
127 */
128 @Override
129 public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
130
131 tempFileHandle = fileHandle;
132 }
133
134 /**
135 * Prepare the information for java code generation corresponding to YANG
136 * enumeration info.
137 *
138 * @param yangPlugin YANG plugin config
139 * @throws IOException IO operations fails
140 */
141 @Override
142 public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
143 generateCodeOfType(this, yangPlugin, false);
144 }
145
146 /**
147 * Creates a java file using the YANG enumeration info.
148 *
149 * @throws IOException IO operation fail
150 */
151 @Override
152 public void generateCodeExit() throws IOException {
153 getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_ENUM_CLASS, this);
154 }
155
156}